From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Alison Schofield <alison.schofield@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Li Ming <ming.li@zohomail.com>,
akpm@linux-foundation.org, bhelgaas@google.com,
ilpo.jarvinen@linux.intel.com, dave@stgolabs.net,
jonathan.cameron@huawei.com, dave.jiang@intel.com,
vishal.l.verma@intel.com, ira.weiny@intel.com,
dan.j.williams@intel.com, shiju.jose@huawei.com,
linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] resource: Introduce a new helper resource_contains_addr()
Date: Thu, 3 Jul 2025 12:31:20 +0300 [thread overview]
Message-ID: <aGZN6EFMLp-pL6JB@surfacebook.localdomain> (raw)
In-Reply-To: <aGWFdwla54b-98-x@aschofie-mobl2.lan>
Wed, Jul 02, 2025 at 12:16:07PM -0700, Alison Schofield kirjoitti:
> On Wed, Jul 02, 2025 at 11:16:36AM +0300, Andy Shevchenko wrote:
> > On Wed, Jul 02, 2025 at 03:20:06PM +0800, Li Ming wrote:
> > > In CXL subsystem, many functions need to check an address availability
> > > by checking if the resource range contains the address. Providing a new
> > > helper function resource_contains_addr() to check if the resource range
> > > contains the input address.
> >
> > resources are about ranges and not addresses. At bare minimum naming #####
> > here. Also there is no symmetry with the intersection API. But I would argue
> > to use resource_contains() and just provide necessary parameter with both
> > start and end to be set at the same value.
> >
> > struct resource r = DEFINE_RES...(addr);
> >
> > if (resource_contains, res, &r)
> > ...do stuff...
(1) ^^^
> Thanks for the review. Two alternative approaches were considered:
>
> 1) A CXL-only helper with direct comparison:
> This duplicates range checking logic that's already common in the
> resource API. We'd end up with CXL specific when the resource API
> already provides the semantic framework for containment checks.
> 2) A CXL helper using temporary resource + resource_contains():
> While this maintains API consistency, it's unnecessarily heavyweight.
How is it? It's mostly matter of stack usage. Do I miss anything?
> Creating a temporary resource struct just to check if a single address
> falls within a range feels like overengineering.
> (This is your suggestion above.)
I don' think so. This won't create anything, it will declare the resource
data on a stack.
...
> This patch proposes, a new helper in ioport.h, provides a clean, reusable
> API that follows the existing resource_contains() pattern while being
> optimized for the single address case. I guess I can agree with the lack
> of symmetry with the existing API, but that's only if one thinks an API
> cannot be extended. The new helper actually complements resource_contains()
> nicely: one checks resource vs resource containment, the other checks
> address vs resource containment.
The point is _there is no address_ in the resources! There is a _range_.
> Revisited the name, I can see how extending an existing name, like
> resource_contains() is a poor choice because then one might expect the
> pair to be resource_contains_resource() and resource_contains_addr()
> which it is not.
>
> Do either of these fit better, or something else?
> - resource_includes_addr()
> - resource_has_addr()
That's why (see above) naming sucks. Doing it local to CXL makes it clearer as
CXL knows the semantic of the range, struct resource doesn't and shouldn't.
(Yeah, I know that we have something there that relies on the range being an
address range, but those APIs provide more and TBH I would rather split them
to a separate header)
> The new helper would immediately be used 7 times in the CXL subsystem.
> What are you thinking the bar is for adding to ioport.h?
It's only a single subsystem, find 3+ more outside and we can reconsider.
Also for the symmetrical API,
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-07-03 9:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 7:20 [PATCH v2 1/3] resource: Introduce a new helper resource_contains_addr() Li Ming
2025-07-02 7:20 ` [PATCH v2 2/3] cxl/edac: Fix wrong dpa checking for PPR operation Li Ming
2025-07-02 8:24 ` Andy Shevchenko
2025-07-02 19:38 ` Alison Schofield
2025-07-03 9:57 ` Li Ming
2025-07-03 9:52 ` Shiju Jose
2025-07-02 7:20 ` [PATCH v2 3/3] cxl/core: Using resource_contains_addr() to check address availability Li Ming
2025-07-02 8:16 ` [PATCH v2 1/3] resource: Introduce a new helper resource_contains_addr() Andy Shevchenko
2025-07-02 8:18 ` Andy Shevchenko
2025-07-02 19:16 ` Alison Schofield
2025-07-03 9:31 ` Andy Shevchenko [this message]
2025-07-07 4:19 ` Li Ming
2025-07-02 8:21 ` Andy Shevchenko
2025-07-03 5:33 ` Li Ming
2025-07-03 9:52 ` Shiju Jose
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=aGZN6EFMLp-pL6JB@surfacebook.localdomain \
--to=andy.shevchenko@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alison.schofield@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=shiju.jose@huawei.com \
--cc=vishal.l.verma@intel.com \
/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