> -----Original Message-----
> From: Dave Jiang <[email protected]>
> Sent: Friday, August 28, 2026 9:30 PM
> To: Manish Honap <[email protected]>; [email protected]; [email protected];
> Ankit Agrawal <[email protected]>; [email protected]; alejandro.lucero-
> [email protected]; Srirangan Madhavan <[email protected]>;
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Yishai Hadas <[email protected]>; Shameer
> Kolothum Thodi <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]
> Cc: Neo Jia <[email protected]>; Krishnakant Jaju <[email protected]>; Vikram
> Sethi <[email protected]>; Zhi Wang <[email protected]>; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v4 04/27] cxl: Establish media readiness in
> cxl_mem_probe()
> 
> External email: Use caution opening links or attachments
> 
> 
> On 8/13/26 2:36 AM, [email protected] wrote:
> > From: Manish Honap <[email protected]>
> >
> > media_ready was only ever set by cxl_pci, in advance of registering a
> > memdev and with CXL Memory Device register assumptions. A consumer
> > that creates a memdev without cxl_pci, such as a mailbox-less Type-2
> > accelerator brought up through devm_cxl_probe_mem(), therefore handed
> > cxl_mem a device with media_ready still false, and cxl_mem_probe()
> > rejected it with -EBUSY. __devm_cxl_add_memdev() turns that into
> > -ENXIO back to the caller and the bind fails.
> >
> > Move the readiness wait into cxl_mem_probe() so every memdev consumer
> > gets a ready resource regardless of how the memdev was created. When
> > media_ready is not already set, wait on the device's DVSEC
> > Mem_Info_Valid and Mem_Active bits and mark it ready. cxl_pci keeps
> > setting media_ready before it registers its memdev, so that path skips
> > the wait.
> >
> > The CXL Memory Device register group is optional and many Type-2
> > devices do not implement it, so cxl_await_media_ready() must not read
> > the Memdev Status register unless the group is mapped. Reading
> > regs.memdev on a device that lacks it would fault. Gate that read on
> > regs.memdev; the DVSEC bits already prove readiness for such devices.
> >
> > Signed-off-by: Manish Honap <[email protected]>
> 
> Agree with Alex's review. First part needs to be a separate patch. And second
> part, please see drivers/net/ethernet/sfc/efx_cxl.c:efx_cxl_init() on media
> ready for CXL type2. That should be handled before devm_cxl_probe_mem()
> gets called. And with that, maybe the first chunk is not even needed?
> 
> DJ

okay, I will follow this according to efx_cxl_init().

Media readiness will be established in the vfio-cxl bind path:
- Create the no-mailbox cxl_dev_state
- Validate the component/HDM registers
- Set media_ready directly, before devm_cxl_probe_mem().

No cxl_mem_probe()/cxl_await_media_ready() change, so the suggested split
will not be necessary.

> > ---
> >  drivers/cxl/core/pci.c | 15 +++++++++++----
> >  drivers/cxl/mem.c      |  9 +++++++--
> >  2 files changed, 18 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index
> > 08d4c955137d..9b372d5a1aa4 100644
> > --- a/drivers/cxl/core/pci.c
> > +++ b/drivers/cxl/core/pci.c
> > @@ -151,7 +151,6 @@ int cxl_await_media_ready(struct cxl_dev_state
> *cxlds)
> >       struct pci_dev *pdev = to_pci_dev(cxlds->dev);
> >       int d = cxlds->cxl_dvsec;
> >       int rc, i, hdm_count;
> > -     u64 md_status;
> >       u16 cap;
> >
> >       rc = pci_read_config_word(pdev,
> > @@ -172,9 +171,17 @@ int cxl_await_media_ready(struct cxl_dev_state
> *cxlds)
> >                       return rc;
> >       }
> >
> > -     md_status = readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
> > -     if (!CXLMDEV_READY(md_status))
> > -             return -EIO;
> > +     /*
> > +      * It is possible some Type-2 devices (CXL_DEVTYPE_DEVMEM) do not
> > +      * implement regs.memdev; only consult the Memdev Status register
> when
> > +      * the group is actually present.
> > +      */
> > +     if (cxlds->regs.memdev) {
> > +             u64 md_status = readq(cxlds->regs.memdev +
> > + CXLMDEV_STATUS_OFFSET);
> > +
> > +             if (!CXLMDEV_READY(md_status))
> > +                     return -EIO;
> > +     }
> 
> You probably get less code churn if you just returned here:
> 
> if (!cxlds->regs.memdev)
>         return 0;
> 

Okay, I will resolve this.

Manish

> DJ
> 
> >
> >       return 0;
> >  }
> > diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index
> > 798e5c369cfc..9c6e99b9124c 100644
> > --- a/drivers/cxl/mem.c
> > +++ b/drivers/cxl/mem.c
> > @@ -105,8 +105,13 @@ static int cxl_mem_probe(struct device *dev)
> >       struct dentry *dentry;
> >       int rc;
> >
> > -     if (!cxlds->media_ready)
> > -             return -EBUSY;
> > +     if (!cxlds->media_ready) {
> > +             rc = cxl_await_media_ready(cxlds);
> > +             if (rc)
> > +                     return rc;
> > +             cxlds->media_ready = true;
> > +             dev_dbg(dev, "CXL media ready\n");
> > +     }
> >
> >       /*
> >        * Someone is trying to reattach this device after it lost its
> > port

Reply via email to