public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Robert Richter <rrichter@amd.com>,
	ming.li@zohomail.com, linux-kernel@vger.kernel.org,
	linux-cxl@vger.kernel.org
Subject: Re: [PATCH 4/4 v3] cxl/test: Simulate an x86 Low Memory Hole for tests
Date: Sat, 29 Mar 2025 23:01:28 +0100	[thread overview]
Message-ID: <6370300.Zfb76A358L@fdefranc-mobl3> (raw)
In-Reply-To: <3089527.UnXabflUDm@fdefranc-mobl3>

[-- Attachment #1: Type: text/plain, Size: 6027 bytes --]

On Saturday, March 29, 2025 11:16:09 AM Central European Standard Time Fabio M. De Francesco wrote:
> On Saturday, March 29, 2025 12:40:47 AM Central European Standard Time Dan Williams wrote:
> > Fabio M. De Francesco wrote:
> > > Simulate an x86 Low Memory Hole for the CXL tests by changing the first
> > > mock CFMWS range size to 768MB and the CXL Endpoint Decoder HPA range sizes
> > > to 1GB.
> > > 
> > > Since the auto-created region of cxl-test uses mock_cfmws[0], whose range
> > > base address is typically different from the one published by the BIOS on
> > > real hardware, the driver would fail to create and attach CXL Regions if
> > > it was run on the mock environment created by cxl-tests.
> > > 
> > > Therefore, save the mock_cfmsw[0] range base_hpa and reuse it to match CXL
> > > Root Decoders and Regions with Endpoint Decoders when the driver is run on
> > > mock devices.
> > > 
> > > Since the auto-created region of cxl-test uses mock_cfmws[0], the
> > > LMH path in the CXL Driver will be exercised every time the cxl-test
> > > module is loaded. Executing unit test: cxl-topology.sh, confirms the
> > > region created successfully with a LMH.
> > > 
> > > Cc: Alison Schofield <alison.schofield@intel.com>
> > > Cc: Dan Williams <dan.j.williams@intel.com>
> > > Cc: Ira Weiny <ira.weiny@intel.com>
> > > Signed-off-by: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com>
> > > ---
> > >  drivers/cxl/core/lmh.c               | 35 ++++++++++++++++++++++++----
> > >  drivers/cxl/core/lmh.h               |  2 ++
> > >  tools/testing/cxl/cxl_core_exports.c |  2 ++
> > >  tools/testing/cxl/test/cxl.c         | 10 ++++++++
> > >  4 files changed, 45 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/cxl/core/lmh.c b/drivers/cxl/core/lmh.c
> > > index 2e32f867eb94..9c55670c1c84 100644
> > > --- a/drivers/cxl/core/lmh.c
> > > +++ b/drivers/cxl/core/lmh.c
> > > @@ -1,11 +1,28 @@
> > >  // SPDX-License-Identifier: GPL-2.0-only
> > >  
> > >  #include <linux/range.h>
> > > +#include <linux/pci.h>
> > > +
> > >  #include "lmh.h"
> > >  
> > >  /* Start of CFMWS range that end before x86 Low Memory Holes */
> > >  #define LMH_CFMWS_RANGE_START 0x0ULL
> > >  
> > > +static u64 mock_cfmws0_range_start = ULLONG_MAX;
> > > +
> > > +void set_mock_cfmws0_range_start(const u64 start)
> > > +{
> > > +	mock_cfmws0_range_start = start;
> > > +}
> > > +
> > > +static u64 get_cfmws_range_start(const struct device *dev)
> > > +{
> > > +	if (dev_is_pci(dev))
> > > +		return LMH_CFMWS_RANGE_START;
> > > +
> > > +	return mock_cfmws0_range_start;
> > > +}
> > > +
> > 
> > cxl_test should never result in "mock" infrastructure appearing outside
> > of tools/testing/cxl/
> > 
> > >  /*
> > >   * Match CXL Root and Endpoint Decoders by comparing SPA and HPA ranges.
> > >   *
> > > @@ -19,14 +36,19 @@ bool arch_match_spa(const struct cxl_root_decoder *cxlrd,
> > >  		    const struct cxl_endpoint_decoder *cxled)
> > >  {
> > >  	const struct range *r1, *r2;
> > > +	u64 cfmws_range_start;
> > >  	int niw;
> > >  
> > > +	cfmws_range_start = get_cfmws_range_start(&cxled->cxld.dev);
> > > +	if (cfmws_range_start == ULLONG_MAX)
> > > +		return false;
> > > +
> > >  	r1 = &cxlrd->cxlsd.cxld.hpa_range;
> > >  	r2 = &cxled->cxld.hpa_range;
> > >  	niw = cxled->cxld.interleave_ways;
> > >  
> > > -	if (r1->start == LMH_CFMWS_RANGE_START && r1->start == r2->start &&
> > > -	    r1->end < (LMH_CFMWS_RANGE_START + SZ_4G) && r1->end < r2->end &&
> > > +	if (r1->start == cfmws_range_start && r1->start == r2->start &&
> > > +	    r1->end < (cfmws_range_start + SZ_4G) && r1->end < r2->end &&
> > >  	    IS_ALIGNED(range_len(r2), niw * SZ_256M))
> > >  		return true;
> > >  
> > > @@ -40,9 +62,14 @@ bool arch_match_region(const struct cxl_region_params *p,
> > >  	const struct range *r = &cxld->hpa_range;
> > >  	const struct resource *res = p->res;
> > >  	int niw = cxld->interleave_ways;
> > > +	u64 cfmws_range_start;
> > > +
> > > +	cfmws_range_start = get_cfmws_range_start(&cxld->dev);
> > > +	if (cfmws_range_start == ULLONG_MAX)
> > > +		return false;
> > >  
> > > -	if (res->start == LMH_CFMWS_RANGE_START && res->start == r->start &&
> > > -	    res->end < (LMH_CFMWS_RANGE_START + SZ_4G) && res->end < r->end &&
> > > +	if (res->start == cfmws_range_start && res->start == r->start &&
> > > +	    res->end < (cfmws_range_start + SZ_4G) && res->end < r->end &&
> > >  	    IS_ALIGNED(range_len(r), niw * SZ_256M))
> > >  		return true;
> > 
> > Someone should be able to read the straight line CXL driver code and
> > never know that an alternate implementation exists for changing these
> > details.
> > 
> > So, the mock interface for this stuff should intercept at the
> > arch_match_spa() and arch_match_region() level.
> > 
> > To me that looks like mark these implementations with the __mock
> > attribute, similar to to_cxl_host_bridge(). Then define strong versions
> > in tools/testing/cxl/mock_lmh.c.
> > 
> > The strong versions would apply memory hole semantics to both windows
> > starting at zero and whatever cxl_test window you choose.
> > 
> I thought the same and wanted to use the strong/weak mechanism, but then 
> I noticed that the strong version (in tools/testing/cxl/mock_lmh.c) was never
> called. I think it never happens because of the weak version is called from 
> cxl_core. I think that all functions called from cxl_core can't be override
> from cxl_test. 
> 
> Is that deduction unfounded? Am I missing something?
> 
> Thanks,
> 
> Fabio
> 
> P.S.: Please notice that to_cxl_host_bridge() is never used in cxl_core.
> 
I mistakenly thought you were suggesting something like the wrap approach
that is not possible if the caller of the wrapped function is internal to 
the CXL core.[1]

Fabio

[1] https://lore.kernel.org/all/6711b7c0c0b53_3ee2294a6@dwillia2-xfh.jf.intel.com.notmuch/

 

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2025-03-29 22:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 11:36 [PATCH 0/4 v3] cxl/core: Enable Region creation on x86 with Low Mem Hole Fabio M. De Francesco
2025-03-14 11:36 ` [PATCH 1/4 v3] cxl/core: Change match_*_by_range() calling convention Fabio M. De Francesco
2025-03-21 15:43   ` Dave Jiang
2025-03-14 11:36 ` [PATCH 2/4 v3] cxl/core: Add helpers to detect Low memory Holes on x86 Fabio M. De Francesco
2025-03-18 15:15   ` Ira Weiny
2025-03-21 10:21   ` Robert Richter
2025-03-26 16:47     ` Fabio M. De Francesco
2025-03-28 10:26       ` Robert Richter
2025-03-28 23:40   ` Dan Williams
2025-03-29 10:05     ` Fabio M. De Francesco
2025-03-14 11:36 ` [PATCH 3/4 v3] cxl/core: Enable Region creation on x86 with Low Memory Hole Fabio M. De Francesco
2025-03-18 20:35   ` Ira Weiny
2025-03-21 10:29   ` Robert Richter
2025-03-14 11:36 ` [PATCH 4/4 v3] cxl/test: Simulate an x86 Low Memory Hole for tests Fabio M. De Francesco
2025-03-18 21:16   ` Ira Weiny
2025-03-21 10:42   ` Robert Richter
2025-03-26 16:58     ` Fabio M. De Francesco
2025-03-28 10:52       ` Robert Richter
2025-03-28 23:40   ` Dan Williams
2025-03-29 10:16     ` Fabio M. De Francesco
2025-03-29 22:01       ` Fabio M. De Francesco [this message]
2025-04-03  4:00     ` Dan Williams
2025-03-20  1:46 ` [PATCH 0/4 v3] cxl/core: Enable Region creation on x86 with Low Mem Hole Alison Schofield
2025-03-26 16:23   ` Fabio M. De Francesco
2025-03-20 18:10 ` Alison Schofield
2025-03-26 16:24   ` Fabio M. De Francesco
2025-03-21 10:34 ` Robert Richter
2025-03-25 16:13   ` Fabio M. De Francesco
2025-03-28  9:02     ` Robert Richter
2025-03-28 21:10       ` Dave Jiang
2025-04-02 11:51         ` Robert Richter
2025-04-02 15:31           ` Dave Jiang

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=6370300.Zfb76A358L@fdefranc-mobl3 \
    --to=fabio.m.de.francesco@linux.intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --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=rrichter@amd.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