On Mon, Jun 01, 2026 at 08:23:46AM -0700, Dave Jiang wrote:
> 
> 
> On 5/29/26 11:40 PM, Anisa Su wrote:
> > On Wed, May 27, 2026 at 03:28:56PM -0700, Dave Jiang wrote:
> >>
> >>
> >> On 5/23/26 2:42 AM, Anisa Su wrote:
[snip]
> >>> + struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) =
> >>> +                                 kmalloc(dc_resp_size, GFP_KERNEL);
> >>> + if (!dc_resp)
> >>> +         return -ENOMEM;
> >>> +
> >>> + /**
> >>
> >> /*
> >>
> >>> +  * Read and check all partition information for validity and potential
> >>> +  * debugging; see debug output in cxl_dc_check()
> >>> +  */
> >>> + start_partition = 0;
> >>> + num_partitions = 0;
> >>> + do {
> >>> +         int rc, i, j;
> >>> +
> >>> +         rc = cxl_get_dc_config(mbox, start_partition, dc_resp, 
> >>> dc_resp_size);
> >>> +         if (rc < 0) {
> >>> +                 dev_err(dev, "Failed to get DC config: %d\n", rc);
> >>> +                 return rc;
> >>> +         }
> >>> +
> >             if (rc == 0) {
> >                     dev_err(dev,
> >                             "Device reported %u partitions available but 
> > returned none at index %u\n",
> >                             dc_resp->avail_partition_count, 
> > start_partition);
> >                     return -EIO;
> >             }
> >>> +         num_partitions += rc;
> >>
> >> Would cxl_get_dc_config() keep returning 0 be a problem? Not likely to 
> >> happen unless device is malicious.
> >>
> > Not sure but I added a check anyway. ^ See above. It prohibits
> > cxl_get_dc_config() returning 0 at all though. But could be changed to
> > err only if 0 partitions are returned X amount of times...?
> 
> I think as long as we have a way to detect that we aren't moving forward in 
> this loop and need to get out at some point.
> 
> DJ
> 
I'll keep the check above then, and just prohibit returning 0 partitions
when the device reports that it has more partitions available, since I don't
think it makes sense for the device to transiently return 0 and for some
reason make progress on retry anyway...

But need to move it below this check

if (num_partitions < 1 || num_partitions > CXL_MAX_DC_PARTITIONS) {

so the no forward progress check is differentiated from returning 0
partitions.

Thanks,
Anisa
> >>> +
> >>> +         if (num_partitions < 1 || num_partitions > 
> >>> CXL_MAX_DC_PARTITIONS) {
> >>> +                 dev_err(dev, "Invalid num of dynamic capacity 
> >>> partitions %d\n",
> >>> +                         num_partitions);
> >>> +                 return -EINVAL;
> >>> +         }
> >>> +
> >>> +         for (i = start_partition, j = 0; i < num_partitions; i++, j++) {
> >>> +                 rc = cxl_dc_check(dev, partitions, i,
> >>> +                                   &dc_resp->partition[j]);
> >>> +                 if (rc)
> >>> +                         return rc;
> >>> +         }
> >>> +
> >>> +         start_partition = num_partitions;
> >>> +
> >>> + } while (num_partitions < dc_resp->avail_partition_count);
> >>> +
> >>> + /* Return 1st partition */
> >>> + dc_info->start = partitions[0].start;
> >>> + dc_info->size = partitions[0].size;
> >>> + dev_dbg(dev, "Returning partition 0 %zu size %zu\n",
> >>> +         dc_info->start, dc_info->size);
> >>> +
> >>> + return 0;
> >>> +}
> >>> +EXPORT_SYMBOL_NS_GPL(cxl_dev_dc_identify, "CXL");
> >>> +
>
[snip]

Reply via email to