Re: [RESEND v13 17/25] cxl: Introduce cxl_pci_drv_bound() to check for bound driver

Alison Schofield
2025-11-13T21:42:45Z

On Tue, Nov 11, 2025 at 12:33:53AM -0800, Alison Schofield wrote:
> On Tue, Nov 04, 2025 at 11:02:57AM -0600, Terry Bowman wrote:
> > CXL devices handle protocol errors via driver-specific callbacks rather
> > than the generic pci_driver::err_handlers by default. The callbacks are
> > implemented in the cxl_pci driver and are not part of struct pci_driver, so
> > cxl_core must verify that a device is actually bound to the cxl_pci
> > module's driver before invoking the callbacks (the device could be bound
> > to another driver, e.g. VFIO).
> >
> > However, cxl_core can not reference symbols in the cxl_pci module because
> > it creates a circular dependency. This prevents cxl_core from checking the
> > EP's bound driver and calling the callbacks.
> >
> > To fix this, move drivers/cxl/pci.c into drivers/cxl/core/pci_drv.c and
> > build it as part of the cxl_core module. Compile into cxl_core using
> > CXL_PCI and CXL_CORE Kconfig dependencies. This removes the standalone
> > cxl_pci module, consolidates the cxl_pci driver code into cxl_core, and
> > eliminates the circular dependency so cxl_core can safely perform
> > bound-driver checks and invoke the CXL PCI callbacks.
> >
> > Introduce cxl_pci_drv_bound() to return boolean depending on if the PCI EP
> > parameter is bound to a CXL driver instance. This will be used in future
> > patch when dequeuing work from the kfifo.
>
> This one was troublesome in cxl-test, more circular dependencies.
> I noticed you and GregP chatting about it, so I simply remove it from
> the set for now (made all callsites true).
>
> With it gone, the set builds cxl-test and passes the test suite.
> I'll watch what happens with this one, and can take another look at
> the cxl-test issues if they persist.

Hi Terry -

I took another look, suspecting the circle issue started with the
move of pci.c into the core, and not necessarily your new additions.
There are two functions that are wrapped in cxl-test and now with
this move are being called from the core and creating the 'circle':

cxl_await_media_ready()
cxl_rcd_component_reg_phys()

Both those need the 'restrict' method, like for Patch 14.

Once that is resolved, the new function cxl_pci_drv_bound()
seems like it needs mocking and will require the same treatment.

Suggest doing it in separate patches. First patch does the move
and the cxl-test work. Then a second patch adds the new function
and it's cxl-test support.

--Alison

>
> A bit below...
>
> snip
>
> > diff --git a/drivers/cxl/pci.c b/drivers/cxl/core/pci_drv.c
> > similarity index 99%
> > rename from drivers/cxl/pci.c
> > rename to drivers/cxl/core/pci_drv.c
> > index bd95be1f3d5c..06f2fd993cb0 100644
> > --- a/drivers/cxl/pci.c
> > +++ b/drivers/cxl/core/pci_drv.c
>
> Needs:
> +#include "core.h"
>
> Compiler is warning: no previous prototypes.
>
> snip
>