Linux CXL
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Alejandro Lucero Palau <alucerop@amd.com>,
	Dan Williams <dan.j.williams@intel.com>,
	<linux-cxl@vger.kernel.org>
Cc: Dave Jiang <dave.jiang@intel.com>,
	Ira Weiny <ira.weiny@intel.com>, <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH v2 2/5] cxl: Introduce to_{ram,pmem}_{res,perf}() helpers
Date: Fri, 24 Jan 2025 16:45:30 -0800	[thread overview]
Message-ID: <6794342a35629_20fa294bc@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <ecaa87d1-29d3-eb41-5a92-ecd74a9bae2c@amd.com>

Alejandro Lucero Palau wrote:
> 
> On 1/23/25 21:04, Dan Williams wrote:
> 
> <snip>
> 
> > xa_for_each(dsmas_xa, index, dent) {
> >>> -		if (resource_size(&cxlds->ram_res) &&
> >>> -		    range_contains(&ram_range, &dent->dpa_range))
> >>> -			update_perf_entry(dev, dent, &mds->ram_perf);
> >>> -		else if (resource_size(&cxlds->pmem_res) &&
> >>> -			 range_contains(&pmem_range, &dent->dpa_range))
> >>> -			update_perf_entry(dev, dent, &mds->pmem_perf);
> >>> -		else
> >>> -			dev_dbg(dev, "no partition for dsmas dpa: %pra\n",
> >>> -				&dent->dpa_range);
> >>> +		for (int i = 0; i < ARRAY_SIZE(partition); i++) {
> >>> +			const struct resource *res = partition[i];
> >>> +			struct range range = {
> >>> +				.start = res->start,
> >>> +				.end = res->end,
> >>> +			};
> >>> +
> >>> +			if (range_contains(&range, &dent->dpa_range))
> >>> +				update_perf_entry(dev, dent, perf[i]);
> >> This is checking if range contains dent->dpa_range.
> >>
> >> I think it is just the opposite.
> > This looks like an equivalent conversion to me, what am I missing?
> 
> 
> I guess I was confused with dpa_range in dent and assumed that was the 
> full device DPA. But now after studying the code in more detail, I see 
> it is right ... but confusing :-)
> 
> 
> If I'm not wrong again, that range_contains should really be ranges 
> being equal, what range_contains does also cover ...
> 
> 
> It would help some comment explaining what the function is doing with 
> the information coming from two different sources, one being the device 
> CDAT, with potentially performance numbers per partition, and the other 
> being the mailbox GET_PARTITION_INFO command.
> 
> 
> Anyway, apologies for the noise.

Not noise at all, a good review of this function's decisions after the
fact. Dave, do you want to follow on with some commentary for this
function?

I recall part of the motivation for range_contains() was the fact that
theoretically the CDAT DSMAS range could be less than a partition, or
cross a partition boundary. The policy here is about explicitly not
entertaining devices that want to get fancy with the CDAT. So, the
kernel just picks any DSMAS in the partition and uses that for the
performance information. If somebody screams and says the kernel needs
to be more precise (force mainline to carry more maintenance burden for
their use case) then we can revisit.

> 
> >>> @@ -567,6 +578,9 @@ static bool dpa_perf_contains(struct cxl_dpa_perf *perf,
> >>>    		.end = dpa_res->end,
> >>>    	};
> >>>    
> >>> +	if (!perf)
> >>> +		return false;
> >>> +
> >> This change seems to be an improvement or hardening. Not against doing
> >> it, but seizing the change, the function can be simplified using the
> >> parameter without any local variable.
> > No, it's not pure hardening, it is actively avoiding NULL pointer
> > de-references introduced by the new scheme to not track empty
> > partitions.
> >
> > I.e the new to_{ram,pmem}_perf() helpers return NULL when the partition
> > is zero-sized. Previously this code path would do range checks on empty
> > partitions.
> 
> 
> That's true.
> 
> 
> But I do not see the reason for using that local variable that I know is 
> not related with your change.

@perf was never NULL before this patch, it may be NULL afterwards, so I
am not understanding the "not related" charge?

I.e. previously, cxled_get_dpa_perf() would pass perf entries related to zero
ranges, but now to_ram_perf() returns NULL for those cases.

However, I could move that decision outside of dpa_perf_contains()
rather than deleting this NULL check in patch5. I'll do that.

[..]
> >>>    
> >>>    	if (!cxlds->media_ready) {
> >>>    		cxlds->dpa_res = DEFINE_RES_MEM(0, 0);
> >>> -		cxlds->ram_res = DEFINE_RES_MEM(0, 0);
> >>> -		cxlds->pmem_res = DEFINE_RES_MEM(0, 0);
> >>> +		*ram_res = DEFINE_RES_MEM(0, 0);
> >>> +		*pmem_res = DEFINE_RES_MEM(0, 0);
> >>
> >> This is a good example for the discussion about the  patch hardening
> >> resource_contains. The initialization seems fine but IORESOURCE_UNSET
> >> not used.
> > To the contrary, I think these changes are an example of "updating
> > resource_contains() to check for zero is a band-aid that does not fix
> > the root problem".
> >
> 
> I agree, but it does not preclude some resource initialization as you do 
> here not containing the IORESOURCE_UNSET flag and some other code 
> triggering the same problem I faced, so the hardening of 
> resource_contains still useful, IMO. But I'll tell Bjorn Helgaas that 
> patch is not required anymore for CXL leaving to him the decision to 
> apply it if he considers so, following the concerns you expressed there.
> 
> >> it could be argued the resource is set, but it is a zero-size resource
> >> leading to problems in current CXL code.
> > I challenge you to find problems in current CXL code after these
> > partition reworks.
> 
> That's an unfair challenge ... you removed resource_contains ... :-)
> 
> Let me think I got some credit for that after my heads-up ;-)

Oh definitely, you did.

That was part of my internal monologue / uneasiness with the Type-2
patches, something like => "why is CXL sending 0 sized resources to
resource_contains()... oh, no, this whole partition tracking
implementation needs a re-think".

  reply	other threads:[~2025-01-25  0:45 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22  8:59 [PATCH v2 0/5] cxl: DPA partition metadata is a mess Dan Williams
2025-01-22  8:59 ` [PATCH v2 1/5] cxl: Remove the CXL_DECODER_MIXED mistake Dan Williams
2025-01-22 14:11   ` Ira Weiny
2025-01-23 15:49   ` Jonathan Cameron
2025-01-23 15:58   ` Alejandro Lucero Palau
2025-01-23 16:03   ` Dave Jiang
2025-01-22  8:59 ` [PATCH v2 2/5] cxl: Introduce to_{ram,pmem}_{res,perf}() helpers Dan Williams
2025-01-22 14:18   ` Ira Weiny
2025-01-23 15:57   ` Jonathan Cameron
2025-01-23 20:01     ` Dan Williams
2025-01-23 16:13   ` Dave Jiang
2025-01-23 16:25   ` Alejandro Lucero Palau
2025-01-23 21:04     ` Dan Williams
2025-01-24 10:15       ` Alejandro Lucero Palau
2025-01-25  0:45         ` Dan Williams [this message]
2025-01-22  8:59 ` [PATCH v2 3/5] cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info' Dan Williams
2025-01-22 14:53   ` Ira Weiny
2025-01-22 22:24     ` Dan Williams
2025-01-23  3:10       ` Ira Weiny
2025-01-23 16:09   ` Jonathan Cameron
2025-01-23 20:24     ` Dan Williams
2025-01-23 16:57   ` Dave Jiang
2025-01-23 17:00   ` Alejandro Lucero Palau
2025-01-23 22:43     ` Dan Williams
2025-01-23 17:17   ` Alejandro Lucero Palau
2025-01-23 22:48     ` Dan Williams
2025-01-24 10:29       ` Alejandro Lucero Palau
2025-01-22  8:59 ` [PATCH v2 4/5] cxl: Make cxl_dpa_alloc() DPA partition number agnostic Dan Williams
2025-01-22 16:29   ` Ira Weiny
2025-01-22 22:35     ` Dan Williams
2025-01-23  3:14       ` Ira Weiny
2025-01-23  3:28         ` Dan Williams
2025-01-23 16:41   ` Jonathan Cameron
2025-01-23 21:34     ` Dan Williams
2025-01-23 17:21   ` Alejandro Lucero Palau
2025-01-23 20:52   ` Dave Jiang
2025-01-22  8:59 ` [PATCH v2 5/5] cxl: Kill enum cxl_decoder_mode Dan Williams
2025-01-22 17:42   ` Ira Weiny
2025-01-22 22:58     ` Dan Williams
2025-01-23  3:39       ` Ira Weiny
2025-01-23  4:11         ` Dan Williams
2025-01-23 21:30     ` Dave Jiang
2025-01-24 22:22       ` Ira Weiny
2025-01-23 16:51   ` Jonathan Cameron
2025-01-23 21:50     ` Dan Williams
2025-01-23 17:20   ` Alejandro Lucero Palau
2025-01-23 21:29   ` Dave Jiang
2025-01-23 17:23 ` [PATCH v2 0/5] cxl: DPA partition metadata is a mess Alejandro Lucero Palau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6794342a35629_20fa294bc@dwillia2-xfh.jf.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alucerop@amd.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox