mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: Alison Schofield <alison.schofield@intel.com>
Cc: Muchun Song <songmuchun@bytedance.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Joao Martins <joao.m.martins@oracle.com>,
	Ritesh Harjani <ritesh.list@gmail.com>,
	stable@vger.kernel.org, nvdimm@lists.linux.dev,
	linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dax/pmem: fix unaligned compound devmap initialization
Date: Fri, 6 Nov 2026 11:22:49 +0800	[thread overview]
Message-ID: <75814BF9-8CC1-44BC-AB72-94EC5985A39D@linux.dev> (raw)
In-Reply-To: <au0KLseDt4S6b1ME@aschofie-mobl2.lan>



> On Nov 6, 2026, at 06:58, Alison Schofield <alison.schofield@intel.com> wrote:
> 
> On Fri, Oct 16, 2026 at 01:49:14PM +0800, Muchun Song wrote:
>> Static pmem Device DAX namespaces reserve space for namespace metadata
>> before the user-visible data range, and may also include padding needed
>> to satisfy the Device DAX alignment. __dax_pmem_probe() adjusts the
>> dax_region range to start at the data range, but the dev_pagemap range
>> still starts at the beginning of the namespace.
>> 
>> That is not valid for compound devmap mappings whose memmap is stored in
>> system RAM. Compound page initialization requires the start PFN to be
>> naturally aligned to the compound page size, because the head and tail
>> struct pages are initialized according to that geometry. If the pgmap
>> starts before the aligned data range, memmap_init_zone_device() can build
>> compound page metadata from an unaligned PFN.
>> 
>> The resulting struct page layout is inconsistent with the Device DAX
>> mapping. A later mmap fault can then resolve the user-visible PFN through
>> invalid compound page metadata and hit a kernel panic while inserting the
>> DAX folio.
>> 
>> Fix this by advancing the pgmap start to the aligned Device DAX data
>> range for non-altmap compound mappings. Leave base-page namespaces
>> unchanged, and leave the altmap path unchanged because
>> memmap_init_zone_device() already skips the altmap reservation itself.
>> 
>> Fixes: 14606001efb4 ("device-dax: compound devmap support")
>> Cc: <stable@vger.kernel.org>
>> Reported-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>> Closes: https://lore.kernel.org/r/wlrkqqvg.ritesh.list@gmail.com
>> Assisted-by: LLM
>> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>> ---
>> drivers/dax/pmem.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>> 
>> diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
>> index bee93066a849..d3a9b85107b0 100644
>> --- a/drivers/dax/pmem.c
>> +++ b/drivers/dax/pmem.c
>> @@ -51,6 +51,13 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
>> 	/* adjust the dax_region range to the start of data */
>> 	range = pgmap.range;
>> 	range.start += offset;
>> +	/*
>> +	 * When the memmap is stored in RAM, exclude metadata and alignment
>> +	 * padding from compound page initialization.  Otherwise, the pgmap
>> +	 * may start before the naturally aligned Device DAX data range.
>> +	 */
>> +	if (!pgmap_altmap(&pgmap) && le32_to_cpu(pfn_sb->align) > PAGE_SIZE)
>> +	pgmap.range.start = range.start;
> 
> 
> Hi Muchun,

Hi,

> 
> Does moving the start here lose vmemmap savings when the old start
> was already aligned? ie. on x86_64 with -M mem and 2M alignment, a
> namespace starting on a 128M section boundary has its data at +2M. The
> first section then becomes a partial add, which 2ef77f4a7d5a
> ("mm/sparse-vmemmap: set compound page order for device DAX") doesn't
> optimize. Would that cost about 1.7 MiB of extra vmemmap?
> 
> Can you round the original pgmap start up to the alignment to avoid
> that loss, and still fix the crash?

Yes, you are right. Rounding up the original pgmap start still fixes
the crash without losing the vmemmap savings. I'll use the following
change for v2.

diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index d3a9b85107b0..d54d23f1cc58 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -52,12 +52,11 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
        range = pgmap.range;
        range.start += offset;
        /*
-        * When the memmap is stored in RAM, exclude metadata and alignment
-        * padding from compound page initialization.  Otherwise, the pgmap
-        * may start before the naturally aligned Device DAX data range.
+        * When the memmap is stored in RAM, compound page initialization
+        * must start at a naturally aligned address.
         */
-       if (!pgmap_altmap(&pgmap) && le32_to_cpu(pfn_sb->align) > PAGE_SIZE)
-               pgmap.range.start = range.start;
+       if (!pgmap_altmap(&pgmap))
+               pgmap.range.start = ALIGN(pgmap.range.start, nd_pfn->align);
        dax_region = alloc_dax_region(dev, region_id, &range,
                        nd_region->target_node, le32_to_cpu(pfn_sb->align),
                        IORESOURCE_DAX_STATIC);

Thanks,
Muchun

> 
> -- Alison
> 
> 
> 
>> 	dax_region = alloc_dax_region(dev, region_id, &range,
>> 			nd_region->target_node, le32_to_cpu(pfn_sb->align),
>> 			IORESOURCE_DAX_STATIC);
>> 
>> base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
>> -- 
>> 2.54.0



      reply	other threads:[~2026-11-06  3:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  5:49 Muchun Song
2026-10-16 10:00 ` Joao Martins
2026-10-16 14:06   ` Muchun Song
2026-10-30 10:53     ` Joao Martins
2026-10-22  3:37 ` Ritesh Harjani
2026-10-22  7:21   ` Muchun Song
2026-10-30 10:33 ` Pavithra
2026-11-05 22:58 ` Alison Schofield
2026-11-06  3:22   ` Muchun Song [this message]

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=75814BF9-8CC1-44BC-AB72-94EC5985A39D@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=joao.m.martins@oracle.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=ritesh.list@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=stable@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

all inboxes | Powered by JetHome®