From: Alison Schofield <alison.schofield@intel.com>
To: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
Cc: <linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<nvdimm@lists.linux.dev>, <linux-fsdevel@vger.kernel.org>,
<linux-pm@vger.kernel.org>, Davidlohr Bueso <dave@stgolabs.net>,
"Jonathan Cameron" <jonathan.cameron@huawei.com>,
Dave Jiang <dave.jiang@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Dan Williams" <dan.j.williams@intel.com>,
Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Len Brown <len.brown@intel.com>, Pavel Machek <pavel@kernel.org>,
Li Ming <ming.li@zohomail.com>,
Jeff Johnson <jeff.johnson@oss.qualcomm.com>,
"Ying Huang" <huang.ying.caritas@gmail.com>,
Yao Xingtao <yaoxt.fnst@fujitsu.com>,
Peter Zijlstra <peterz@infradead.org>,
Greg KH <gregkh@linuxfoundation.org>,
Nathan Fontenot <nathan.fontenot@amd.com>,
Terry Bowman <terry.bowman@amd.com>,
Robert Richter <rrichter@amd.com>,
Benjamin Cheatham <benjamin.cheatham@amd.com>,
PradeepVineshReddy Kodamati <PradeepVineshReddy.Kodamati@amd.com>,
Zhijian Li <lizhijian@fujitsu.com>
Subject: Re: [PATCH v4 7/7] cxl/dax: Defer DAX consumption of SOFT RESERVED resources until after CXL region creation
Date: Tue, 15 Jul 2025 09:27:34 -0700 [thread overview]
Message-ID: <aHaBdj0QrEe_gymR@aschofie-mobl2.lan> (raw)
In-Reply-To: <20250603221949.53272-8-Smita.KoralahalliChannabasappa@amd.com>
On Tue, Jun 03, 2025 at 10:19:49PM +0000, Smita Koralahalli wrote:
> From: Nathan Fontenot <nathan.fontenot@amd.com>
>
> The DAX HMEM driver currently consumes all SOFT RESERVED iomem resources
> during initialization. This interferes with the CXL driver’s ability to
> create regions and trim overlapping SOFT RESERVED ranges before DAX uses
> them.
>
> To resolve this, defer the DAX driver's resource consumption if the
> cxl_acpi driver is enabled. The DAX HMEM initialization skips walking the
> iomem resource tree in this case. After CXL region creation completes,
> any remaining SOFT RESERVED resources are explicitly registered with the
> DAX driver by the CXL driver.
>
> This sequencing ensures proper handling of overlaps and fixes hotplug
> failures.
Hi Smita,
About the issue I first mentioned here [1]. The HMEM driver is not
waiting for region probe to finish. By the time region probe attempts
to hand off the memory to DAX, the memory is already marked as System RAM.
See 'case CXL_PARTMODE_RAM:' in cxl_region_probe(). The is_system_ram()
test fails so devm_cxl_add_dax_region() not possible.
This means that in appearance, just looking at /proc/iomem/, this
seems to have worked. There is no soft reserved and the dax and
kmem resources are child resources of the region resource. But they
were not set up by the region driver, hence no unregister callback
is triggered when the region is disabled.
It appears like this:
c080000000-17dbfffffff : CXL Window 0
c080000000-c47fffffff : region2
c080000000-c47fffffff : dax0.0
c080000000-c47fffffff : System RAM (kmem)
Now, to make the memory available for reuse, need to do:
# daxctl offline-memory dax0.0
# daxctl destroy-device --force dax0.0
# cxl disable-region 2
# cxl destroy-region 2
Whereas previously, did this:
# daxctl offline-memory dax0.0
# cxl disable-region 2
After disabling region, dax device unregistered.
# cxl destroy-region 2
I do see that __cxl_region_softreserv_update() is not called until
after cxl_region_probe() completes, so that is waiting properly to
pick up the scraps. I'm actually not sure there would be any scraps
though, if the HMEM driver has already done it's thing. In my case
the Soft Reserved size is same as region, so I cannot tell what
would happen if that Soft Reserved had more capacity than the region.
If I do this: # CONFIG_DEV_DAX_HMEM is not set, works same as before,
which is as expected.
Let me know if I can try anything else out or collect more info.
--Alison
[1] https://lore.kernel.org/nvdimm/20250603221949.53272-1-Smita.KoralahalliChannabasappa@amd.com/T/#m10c0eb7b258af7cd0c84c7ee2c417c055724f921
>
> Co-developed-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
> Signed-off-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
> Co-developed-by: Terry Bowman <terry.bowman@amd.com>
> Signed-off-by: Terry Bowman <terry.bowman@amd.com>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
> ---
> drivers/cxl/core/region.c | 10 +++++++++
> drivers/dax/hmem/device.c | 43 ++++++++++++++++++++-------------------
> drivers/dax/hmem/hmem.c | 3 ++-
> include/linux/dax.h | 6 ++++++
> 4 files changed, 40 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 3a5ca44d65f3..c6c0c7ba3b20 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -10,6 +10,7 @@
> #include <linux/sort.h>
> #include <linux/idr.h>
> #include <linux/memory-tiers.h>
> +#include <linux/dax.h>
> #include <cxlmem.h>
> #include <cxl.h>
> #include "core.h"
> @@ -3553,6 +3554,11 @@ static struct resource *normalize_resource(struct resource *res)
> return NULL;
> }
>
> +static int cxl_softreserv_mem_register(struct resource *res, void *unused)
> +{
> + return hmem_register_device(phys_to_target_node(res->start), res);
> +}
> +
> static int __cxl_region_softreserv_update(struct resource *soft,
> void *_cxlr)
> {
> @@ -3590,6 +3596,10 @@ int cxl_region_softreserv_update(void)
> __cxl_region_softreserv_update);
> }
>
> + /* Now register any remaining SOFT RESERVES with DAX */
> + walk_iomem_res_desc(IORES_DESC_SOFT_RESERVED, IORESOURCE_MEM,
> + 0, -1, NULL, cxl_softreserv_mem_register);
> +
> return 0;
> }
> EXPORT_SYMBOL_NS_GPL(cxl_region_softreserv_update, "CXL");
> diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c
> index 59ad44761191..cc1ed7bbdb1a 100644
> --- a/drivers/dax/hmem/device.c
> +++ b/drivers/dax/hmem/device.c
> @@ -8,7 +8,6 @@
> static bool nohmem;
> module_param_named(disable, nohmem, bool, 0444);
>
> -static bool platform_initialized;
> static DEFINE_MUTEX(hmem_resource_lock);
> static struct resource hmem_active = {
> .name = "HMEM devices",
> @@ -35,9 +34,7 @@ EXPORT_SYMBOL_GPL(walk_hmem_resources);
>
> static void __hmem_register_resource(int target_nid, struct resource *res)
> {
> - struct platform_device *pdev;
> struct resource *new;
> - int rc;
>
> new = __request_region(&hmem_active, res->start, resource_size(res), "",
> 0);
> @@ -47,21 +44,6 @@ static void __hmem_register_resource(int target_nid, struct resource *res)
> }
>
> new->desc = target_nid;
> -
> - if (platform_initialized)
> - return;
> -
> - pdev = platform_device_alloc("hmem_platform", 0);
> - if (!pdev) {
> - pr_err_once("failed to register device-dax hmem_platform device\n");
> - return;
> - }
> -
> - rc = platform_device_add(pdev);
> - if (rc)
> - platform_device_put(pdev);
> - else
> - platform_initialized = true;
> }
>
> void hmem_register_resource(int target_nid, struct resource *res)
> @@ -83,9 +65,28 @@ static __init int hmem_register_one(struct resource *res, void *data)
>
> static __init int hmem_init(void)
> {
> - walk_iomem_res_desc(IORES_DESC_SOFT_RESERVED,
> - IORESOURCE_MEM, 0, -1, NULL, hmem_register_one);
> - return 0;
> + struct platform_device *pdev;
> + int rc;
> +
> + if (!IS_ENABLED(CONFIG_CXL_ACPI)) {
> + walk_iomem_res_desc(IORES_DESC_SOFT_RESERVED,
> + IORESOURCE_MEM, 0, -1, NULL,
> + hmem_register_one);
> + }
> +
> + pdev = platform_device_alloc("hmem_platform", 0);
> + if (!pdev) {
> + pr_err("failed to register device-dax hmem_platform device\n");
> + return -1;
> + }
> +
> + rc = platform_device_add(pdev);
> + if (rc) {
> + pr_err("failed to add device-dax hmem_platform device\n");
> + platform_device_put(pdev);
> + }
> +
> + return rc;
> }
>
> /*
> diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
> index 3aedef5f1be1..a206b9b383e4 100644
> --- a/drivers/dax/hmem/hmem.c
> +++ b/drivers/dax/hmem/hmem.c
> @@ -61,7 +61,7 @@ static void release_hmem(void *pdev)
> platform_device_unregister(pdev);
> }
>
> -static int hmem_register_device(int target_nid, const struct resource *res)
> +int hmem_register_device(int target_nid, const struct resource *res)
> {
> struct device *host = &dax_hmem_pdev->dev;
> struct platform_device *pdev;
> @@ -124,6 +124,7 @@ static int hmem_register_device(int target_nid, const struct resource *res)
> platform_device_put(pdev);
> return rc;
> }
> +EXPORT_SYMBOL_GPL(hmem_register_device);
>
> static int dax_hmem_platform_probe(struct platform_device *pdev)
> {
> diff --git a/include/linux/dax.h b/include/linux/dax.h
> index a4ad3708ea35..5052dca8b3bc 100644
> --- a/include/linux/dax.h
> +++ b/include/linux/dax.h
> @@ -299,10 +299,16 @@ static inline int dax_mem2blk_err(int err)
>
> #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
> void hmem_register_resource(int target_nid, struct resource *r);
> +int hmem_register_device(int target_nid, const struct resource *res);
> #else
> static inline void hmem_register_resource(int target_nid, struct resource *r)
> {
> }
> +
> +static inline int hmem_register_device(int target_nid, const struct resource *res)
> +{
> + return 0;
> +}
> #endif
>
> typedef int (*walk_hmem_fn)(int target_nid, const struct resource *res);
> --
> 2.17.1
>
next prev parent reply other threads:[~2025-07-15 16:28 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 22:19 [PATCH v4 0/7] Add managed SOFT RESERVE resource handling Smita Koralahalli
2025-06-03 22:19 ` [PATCH v4 1/7] cxl/region: Avoid null pointer dereference in is_cxl_region() Smita Koralahalli
2025-06-03 23:49 ` Dave Jiang
2025-06-04 19:56 ` Nathan Fontenot
2025-06-25 15:23 ` Robert Richter
2025-06-03 22:19 ` [PATCH v4 2/7] cxl/core: Remove CONFIG_CXL_SUSPEND and always build suspend.o Smita Koralahalli
2025-06-09 11:02 ` Jonathan Cameron
2025-06-09 23:25 ` Koralahalli Channabasappa, Smita
2025-06-10 9:38 ` Jonathan Cameron
2025-06-03 22:19 ` [PATCH v4 3/7] cxl/pci: Add pci_loaded tracking to mark PCI driver readiness Smita Koralahalli
2025-06-04 9:29 ` Zhijian Li (Fujitsu)
2025-06-03 22:19 ` [PATCH v4 4/7] cxl/acpi: Add background worker to wait for cxl_pci and cxl_mem probe Smita Koralahalli
2025-06-03 23:45 ` Dave Jiang
2025-06-04 18:31 ` Koralahalli Channabasappa, Smita
2025-06-04 9:40 ` Zhijian Li (Fujitsu)
2025-06-04 14:35 ` Dave Jiang
2025-06-05 2:18 ` Zhijian Li (Fujitsu)
2025-06-03 22:19 ` [PATCH v4 5/7] cxl/region: Introduce SOFT RESERVED resource removal on region teardown Smita Koralahalli
2025-06-06 4:16 ` Zhijian Li (Fujitsu)
2025-06-06 17:53 ` Koralahalli Channabasappa, Smita
2025-06-09 12:54 ` Jonathan Cameron
2025-06-10 1:25 ` Koralahalli Channabasappa, Smita
2025-06-10 9:37 ` Jonathan Cameron
2025-06-25 15:20 ` Robert Richter
2025-07-09 1:14 ` Alison Schofield
2025-06-03 22:19 ` [PATCH v4 6/7] dax/hmem: Save the DAX HMEM platform device pointer Smita Koralahalli
2025-06-05 16:54 ` Dave Jiang
2025-06-06 8:11 ` Zhijian Li (Fujitsu)
2025-06-06 20:09 ` Nathan Fontenot
2025-06-03 22:19 ` [PATCH v4 7/7] cxl/dax: Defer DAX consumption of SOFT RESERVED resources until after CXL region creation Smita Koralahalli
2025-06-09 13:01 ` Jonathan Cameron
2025-06-13 2:12 ` Zhijian Li (Fujitsu)
2025-07-10 4:22 ` Koralahalli Channabasappa, Smita
2025-07-10 8:18 ` Zhijian Li (Fujitsu)
2025-07-15 16:27 ` Alison Schofield [this message]
2025-07-15 18:19 ` Koralahalli Channabasappa, Smita
2025-07-15 18:45 ` Alison Schofield
2025-06-04 8:43 ` [PATCH v4 0/7] Add managed SOFT RESERVE resource handling Zhijian Li (Fujitsu)
2025-06-04 18:59 ` Koralahalli Channabasappa, Smita
2025-06-16 1:00 ` Zhijian Li (Fujitsu)
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=aHaBdj0QrEe_gymR@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=PradeepVineshReddy.Kodamati@amd.com \
--cc=Smita.KoralahalliChannabasappa@amd.com \
--cc=benjamin.cheatham@amd.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=gregkh@linuxfoundation.org \
--cc=huang.ying.caritas@gmail.com \
--cc=ira.weiny@intel.com \
--cc=jack@suse.cz \
--cc=jeff.johnson@oss.qualcomm.com \
--cc=jonathan.cameron@huawei.com \
--cc=len.brown@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lizhijian@fujitsu.com \
--cc=ming.li@zohomail.com \
--cc=nathan.fontenot@amd.com \
--cc=nvdimm@lists.linux.dev \
--cc=pavel@kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rrichter@amd.com \
--cc=terry.bowman@amd.com \
--cc=vishal.l.verma@intel.com \
--cc=willy@infradead.org \
--cc=yaoxt.fnst@fujitsu.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
all inboxes | Powered by JetHome®