[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <172834c6-0cc7-479b-be04-5ccd5cf8aae0@amd.com>
Date: Wed, 21 May 2025 11:50:50 +0100
From: Alejandro Lucero Palau <alucerop@....com>
To: dan.j.williams@...el.com, alejandro.lucero-palau@....com,
linux-cxl@...r.kernel.org, netdev@...r.kernel.org, edward.cree@....com,
davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
edumazet@...gle.com, dave.jiang@...el.com
Cc: Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Edward Cree <ecree.xilinx@...il.com>
Subject: Re: [PATCH v16 02/22] sfc: add cxl support
On 5/20/25 08:37, dan.j.williams@...el.com wrote:
> alejandro.lucero-palau@ wrote:
>> From: Alejandro Lucero <alucerop@....com>
>>
>> Add CXL initialization based on new CXL API for accel drivers and make
>> it dependent on kernel CXL configuration.
>>
>> Signed-off-by: Alejandro Lucero <alucerop@....com>
>> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
>> Acked-by: Edward Cree <ecree.xilinx@...il.com>
>> ---
>> drivers/net/ethernet/sfc/Kconfig | 9 +++++
>> drivers/net/ethernet/sfc/Makefile | 1 +
>> drivers/net/ethernet/sfc/efx.c | 15 +++++++-
>> drivers/net/ethernet/sfc/efx_cxl.c | 55 +++++++++++++++++++++++++++
>> drivers/net/ethernet/sfc/efx_cxl.h | 40 +++++++++++++++++++
>> drivers/net/ethernet/sfc/net_driver.h | 10 +++++
>> 6 files changed, 129 insertions(+), 1 deletion(-)
>> create mode 100644 drivers/net/ethernet/sfc/efx_cxl.c
>> create mode 100644 drivers/net/ethernet/sfc/efx_cxl.h
>>
> [..]
>> +int efx_cxl_init(struct efx_probe_data *probe_data)
>> +{
>> + struct efx_nic *efx = &probe_data->efx;
>> + struct pci_dev *pci_dev = efx->pci_dev;
>> + struct efx_cxl *cxl;
>> + u16 dvsec;
>> +
>> + probe_data->cxl_pio_initialised = false;
>> +
>> + dvsec = pci_find_dvsec_capability(pci_dev, PCI_VENDOR_ID_CXL,
>> + CXL_DVSEC_PCIE_DEVICE);
>> + if (!dvsec)
>> + return 0;
>> +
>> + pci_dbg(pci_dev, "CXL_DVSEC_PCIE_DEVICE capability found\n");
>> +
>> + /* Create a cxl_dev_state embedded in the cxl struct using cxl core api
>> + * specifying no mbox available.
>> + */
>> + cxl = cxl_dev_state_create(&pci_dev->dev, CXL_DEVTYPE_DEVMEM,
>> + pci_dev->dev.id, dvsec, struct efx_cxl,
>> + cxlds, false);
>> +
>> + if (!cxl)
>> + return -ENOMEM;
>> +
>> + probe_data->cxl = cxl;
>> +
>> + return 0;
>> +}
>> +
>> +void efx_cxl_exit(struct efx_probe_data *probe_data)
>> +{
> So this is empty which means it leaks the cxl_dev_state_create()
> allocation, right?
Yes, because I was wrongly relying on devres ...
Previous patchsets were doing the explicit release here.
Your suggestion below relies on adding more awareness of cxl into
generic efx code, what we want to avoid using the specific efx_cxl.* files.
As I mentioned in patch 1, I think the right thing to do is to add
devres for cxl_dev_state_create.
Before sending v17 with this change, are you ok with the rest of the
patches or you want to go through them as well?
Thanks
>
> The motivation for the cxl_dev_state_create() macro is so that
> you do not need to manage more independently allocated driver objects.
> For example, the existing kfree(probe_data) can also free the
> cxl_dev_state with a change like below (UNTESTED).
>
> Otherwise, something needs to responsible for freeing 'struct efx_cxl'
>
> -- 8< --
> diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
> index 112e55b98ed3..0135384c6fa1 100644
> --- a/drivers/net/ethernet/sfc/efx.c
> +++ b/drivers/net/ethernet/sfc/efx.c
> @@ -1149,13 +1149,22 @@ static int efx_pci_probe_post_io(struct efx_nic *efx)
> static int efx_pci_probe(struct pci_dev *pci_dev,
> const struct pci_device_id *entry)
> {
> - struct efx_probe_data *probe_data, **probe_ptr;
> + struct efx_probe_data *probe_data = NULL, **probe_ptr;
> struct net_device *net_dev;
> struct efx_nic *efx;
> int rc;
>
> /* Allocate probe data and struct efx_nic */
> - probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL);
> + dvsec = pci_find_dvsec_capability(pci_dev, PCI_VENDOR_ID_CXL,
> + CXL_DVSEC_PCIE_DEVICE);
> + if (dvsec) {
> + cxl = cxl_dev_state_create(&pci_dev->dev, CXL_DEVTYPE_DEVMEM,
> + pci_dev->dev.id, dvsec,
> + struct efx_probe_data, cxl.cxlds, false);
> + if (cxl)
> + probe_data = container_of(cxl, typeof(*probe_data), cxl.cxlds);
> + } else
> + probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL);
> if (!probe_data)
> return -ENOMEM;
> probe_data->pci_dev = pci_dev;
Powered by blists - more mailing lists