Skip to content

Commit

Permalink
linuxkpi: Restore the KBI for struct pci_driver
Browse files Browse the repository at this point in the history
The size of the 13.0 version of struct pci_driver was 92 or 184 bytes on
32- or 64-bit systems respectively. We recently added bsd_probe_return
at the end of this struct, breaking the KBI on the stable/13 branch.

Fix this by removing the isdrm member. We don't need it because we can
do a strcmp in the few places that need it as they aren't performance
critical. Move the newly added bsd_probe_return to that slot. It's the
same size in all our supported KBIs as bool and fits into that slot due
to padding rules.

Direct commit to stable/13 because this is not relevant to main.

Approved by:		re@ (gjb)
Sponsored by:		Netflix
Reviewed by:		bz
Differential Revision:	https://reviews.freebsd.org/D34754

(cherry picked from commit aa61c28)
  • Loading branch information
bsdimp committed Apr 6, 2022
1 parent 568f805 commit 6615aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions sys/compat/linuxkpi/common/include/linux/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,12 @@ struct pci_driver {
devclass_t bsdclass;
struct device_driver driver;
const struct pci_error_handlers *err_handler;
bool isdrm;
int bsd_probe_return;
int (*bsd_iov_init)(device_t dev, uint16_t num_vfs,
const nvlist_t *pf_config);
void (*bsd_iov_uninit)(device_t dev);
int (*bsd_iov_add_vf)(device_t dev, uint16_t vfnum,
const nvlist_t *vf_config);
int bsd_probe_return;
};

struct pci_bus {
Expand Down
14 changes: 9 additions & 5 deletions sys/compat/linuxkpi/common/src/linux_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ struct linux_dma_priv {
#define DMA_PRIV_LOCK(priv) mtx_lock(&(priv)->lock)
#define DMA_PRIV_UNLOCK(priv) mtx_unlock(&(priv)->lock)

static bool
linux_is_drm(struct pci_driver *pdrv)
{
return (pdrv->name != NULL && strcmp(pdrv->name, "drmn") == 0);
}

static int
linux_pdev_dma_uninit(struct pci_dev *pdev)
{
Expand Down Expand Up @@ -405,7 +411,7 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
linux_set_current(curthread);

parent = device_get_parent(dev);
isdrm = pdrv != NULL && pdrv->isdrm;
isdrm = pdrv != NULL && linux_is_drm(pdrv);

if (isdrm) {
struct pci_devinfo *dinfo;
Expand Down Expand Up @@ -674,7 +680,6 @@ linux_pci_register_driver(struct pci_driver *pdrv)
dc = devclass_find("pci");
if (dc == NULL)
return (-ENXIO);
pdrv->isdrm = false;
return (_linux_pci_register_driver(pdrv, dc));
}

Expand All @@ -688,7 +693,7 @@ linux_pci_reserve_bar(struct pci_dev *pdev, struct resource_list *rl,
KASSERT(type == SYS_RES_IOPORT || type == SYS_RES_MEMORY,
("trying to reserve non-BAR type %d", type));

dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
dev = pdev->pdrv != NULL && linux_is_drm(pdev->pdrv) ?
device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
res = pci_reserve_map(device_get_parent(dev), dev, type, &rid, 0, ~0,
1, 1, 0);
Expand All @@ -706,7 +711,7 @@ pci_resource_start(struct pci_dev *pdev, int bar)

if ((rle = linux_pci_get_bar(pdev, bar, true)) == NULL)
return (0);
dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
dev = pdev->pdrv != NULL && linux_is_drm(pdev->pdrv) ?
device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
if (BUS_TRANSLATE_RESOURCE(dev, rle->type, rle->start, &newstart)) {
device_printf(pdev->dev.bsddev, "translate of %#jx failed\n",
Expand Down Expand Up @@ -734,7 +739,6 @@ linux_pci_register_drm_driver(struct pci_driver *pdrv)
dc = devclass_create("vgapci");
if (dc == NULL)
return (-ENXIO);
pdrv->isdrm = true;
pdrv->name = "drmn";
return (_linux_pci_register_driver(pdrv, dc));
}
Expand Down

0 comments on commit 6615aa8

Please sign in to comment.