git: 4f6f4aacaf97 - main - pci_user: Add compatibility padding
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 04 Sep 2025 02:45:34 UTC
The branch main has been updated by jfree:
URL: https://cgit.FreeBSD.org/src/commit/?id=4f6f4aacaf97f301e5c5646649a1217ca8099349
commit 4f6f4aacaf97f301e5c5646649a1217ca8099349
Author: Jake Freeland <jfree@FreeBSD.org>
AuthorDate: 2025-09-04 02:42:48 +0000
Commit: Jake Freeland <jfree@FreeBSD.org>
CommitDate: 2025-09-04 02:42:48 +0000
pci_user: Add compatibility padding
Avoid future compatibility churn when adding new members to struct
pci_conf by introducing some padding.
An additional member, pc_reported_len, has also been added to report the
length of the valid portion of an encompassing pci_conf. This allows
users to verify that their definition of pci_conf matches the kernel's,
preventing the use of invalid data.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D52313
---
share/man/man4/pci.4 | 11 ++++++++++-
sys/dev/pci/pci_user.c | 10 +++++++++-
sys/sys/pciio.h | 2 ++
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/share/man/man4/pci.4 b/share/man/man4/pci.4
index 5237b6bc7adc..b99747969035 100644
--- a/share/man/man4/pci.4
+++ b/share/man/man4/pci.4
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 20, 2025
+.Dd August 31, 2025
.Dt PCI 4
.Os
.Sh NAME
@@ -237,6 +237,15 @@ Driver name.
Driver unit number.
.It pd_numa_domain
Driver NUMA domain.
+.It pc_reported_len
+Length of the valid portion of the encompassing
+.Vt pci_conf
+structure.
+This should always be equivalent to the offset of the
+.Va pc_spare
+member.
+.It pc_spare
+Reserved for future use.
.El
.It offset
The offset is passed in by the user to tell the kernel where it should
diff --git a/sys/dev/pci/pci_user.c b/sys/dev/pci/pci_user.c
index 5090ecb3dd7c..9768030995e7 100644
--- a/sys/dev/pci/pci_user.c
+++ b/sys/dev/pci/pci_user.c
@@ -80,6 +80,8 @@ struct pci_conf32 {
char pd_name[PCI_MAXNAMELEN + 1]; /* device name */
u_int32_t pd_unit; /* device unit number */
int pd_numa_domain; /* device NUMA domain */
+ u_int32_t pc_reported_len;/* length of PCI data reported */
+ char pc_spare[64]; /* space for future fields */
};
struct pci_match_conf32 {
@@ -885,8 +887,11 @@ pci_conf_for_copyout(const struct pci_conf *pcp, union pci_conf_union *pcup,
strlcpy(pcup->pc32.pd_name, pcp->pd_name,
sizeof(pcup->pc32.pd_name));
pcup->pc32.pd_unit = (uint32_t)pcp->pd_unit;
- if (cmd == PCIOCGETCONF32)
+ if (cmd == PCIOCGETCONF32) {
pcup->pc32.pd_numa_domain = pcp->pd_numa_domain;
+ pcup->pc32.pc_reported_len =
+ (uint32_t)offsetof(struct pci_conf32, pc_spare);
+ }
return;
#endif /* COMPAT_FREEBSD32 */
@@ -1326,6 +1331,9 @@ pci_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *t
break;
}
+ dinfo->conf.pc_reported_len =
+ offsetof(struct pci_conf, pc_spare);
+
pci_conf_for_copyout(&dinfo->conf, &pcu, cmd);
error = copyout(&pcu,
(caddr_t)cio->matches +
diff --git a/sys/sys/pciio.h b/sys/sys/pciio.h
index 351397ab9d9b..64c0b32cb8e2 100644
--- a/sys/sys/pciio.h
+++ b/sys/sys/pciio.h
@@ -78,6 +78,8 @@ struct pci_conf {
char pd_name[PCI_MAXNAMELEN + 1]; /* device name */
u_long pd_unit; /* device unit number */
int pd_numa_domain; /* device NUMA domain */
+ size_t pc_reported_len;/* length of PCI data reported */
+ char pc_spare[64]; /* space for future fields */
};
struct pci_match_conf {