Re: [PATCH v6 1/9] cxl/hdm: Add helpers to restore and commit memdev decoders

From: Dave Jiang

Date: Tue Jun 02 2026 - 14:15:15 EST




On 5/28/26 4:06 AM, Richard Cheng wrote:
> On Thu, May 28, 2026 at 08:31:46AM +0800, Srirangan Madhavan wrote:

<-- snip -->

>> +static int cxl_restore_dvsec_range(struct cxl_memdev *cxlmd,
>> + struct cxl_endpoint_decoder *cxled)
>> +{
>> + struct cxl_dev_state *cxlds = cxlmd->cxlds;
>> + struct cxl_decoder *cxld = &cxled->cxld;
>> + struct pci_dev *pdev = to_pci_dev(cxlds->dev);
>> + u64 base = cxld->hpa_range.start;
>> + u64 size = range_len(&cxld->hpa_range);
>> + u32 lo;
>> + int dvsec = cxlds->cxl_dvsec;
>> + int id = cxld->id;
>> + int rc;
>> +
>> + if (!dvsec)
>> + return 0;
>> +
>> + if (id >= CXL_DVSEC_RANGE_MAX)
>> + return 0;
>> +
>> + rc = pci_write_config_dword(pdev, dvsec + PCI_DVSEC_CXL_RANGE_BASE_HIGH(id),
>> + upper_32_bits(base));
>> + if (rc)
>> + return rc;
>> +
>> + rc = pci_read_config_dword(pdev, dvsec + PCI_DVSEC_CXL_RANGE_BASE_LOW(id),
>> + &lo);
>> + if (rc)
>> + return rc;
>
> Here pci_read/write* returns positive values on failure, and you pass the value up.
> Eventually surfacing through cxl_reset_store to userspace where sysfs thinks positive
> values as "bytes written".
>
> I think this might need a fix ?
Great catch! Not something I ever thought about before WRT pci_read/write*. I think to get errno it needs pcibios_err_to_errno() wrapper called. The sysfs exposure definitely needs to be audited.