Linux CXL
 help / color / mirror / Atom feed
From: nifan.cxl@gmail.com
To: dave.jiang@intel.com, alison.schofield@intel.com,
	vishal.l.verma@intel.com, ira.weiny@intel.com,
	dan.j.williams@intel.com, Jonathan.Cameron@huawei.com
Cc: linux-cxl@vger.kernel.org, a.manzanares@samsung.com,
	dave@stgolabs.net, linux-kernel@vger.kernel.org,
	nifan.cxl@gmail.com, anisa.su887@gmail.com,
	Fan Ni <fan.ni@samsung.com>
Subject: [RFC] cxl/region: set numa node for target memdevs when a region is committed
Date: Fri, 14 Mar 2025 09:40:19 -0700	[thread overview]
Message-ID: <20250314164629.6937-1-nifan.cxl@gmail.com> (raw)

From: Fan Ni <fan.ni@samsung.com>

There is a sysfs attribute named "numa_node" for cxl memory device.
however, it is never set so -1 is returned whenever it is read.

With this change, the numa_node of each target memdev is set based on the
start address of the hpa_range of the endpoint decoder it associated when a
cxl region is created; and it is reset when the region decoders are
reset.

Open qeustion: do we need to set the numa_node when the memdev is
probed instead of waiting until a region is created?

Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
 drivers/cxl/core/region.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index e8d11a988fd9..935ee0b1dd26 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -242,6 +242,13 @@ static int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
 	return 0;
 }
 
+static void cxl_mem_reset_numa_node(struct cxl_endpoint_decoder *cxled)
+{
+	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
+
+	cxlmd->dev.numa_node = NUMA_NO_NODE;
+}
+
 static void cxl_region_decode_reset(struct cxl_region *cxlr, int count)
 {
 	struct cxl_region_params *p = &cxlr->params;
@@ -264,6 +271,7 @@ static void cxl_region_decode_reset(struct cxl_region *cxlr, int count)
 		if (cxlds->rcd)
 			goto endpoint_reset;
 
+		cxl_mem_reset_numa_node(cxled);
 		while (!is_cxl_root(to_cxl_port(iter->dev.parent)))
 			iter = to_cxl_port(iter->dev.parent);
 
@@ -304,6 +312,15 @@ static int commit_decoder(struct cxl_decoder *cxld)
 	return 0;
 }
 
+static void cxl_mem_set_numa_node(struct cxl_endpoint_decoder *cxled)
+{
+	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
+	u64 addr = cxled->cxld.hpa_range.start;
+
+	cxlmd->dev.numa_node = phys_to_target_node(addr);
+	dev_dbg(&cxlmd->dev, "set numa node: %d\n", phys_to_target_node(addr));
+}
+
 static int cxl_region_decode_commit(struct cxl_region *cxlr)
 {
 	struct cxl_region_params *p = &cxlr->params;
@@ -340,6 +357,7 @@ static int cxl_region_decode_commit(struct cxl_region *cxlr)
 			cxled->cxld.reset(&cxled->cxld);
 			goto err;
 		}
+		cxl_mem_set_numa_node(cxled);
 	}
 
 	return 0;
-- 
2.47.2


             reply	other threads:[~2025-03-14 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 16:40 nifan.cxl [this message]
2025-03-18 21:00 ` [RFC] cxl/region: set numa node for target memdevs when a region is committed Dave Jiang
2025-03-18 21:25   ` Dan Williams
2025-03-18 23:11     ` Fan Ni
2025-03-19  0:16       ` Dan Williams
2025-03-21 12:22         ` Jonathan Cameron

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=20250314164629.6937-1-nifan.cxl@gmail.com \
    --to=nifan.cxl@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=a.manzanares@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=anisa.su887@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=fan.ni@samsung.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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