From: Alison Schofield <alison.schofield@intel.com>
To: Muchun Song <songmuchun@bytedance.com>
Cc: Dan Williams <djbw@kernel.org>,
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>,
<nvdimm@lists.linux.dev>, <linux-cxl@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <muchun.song@linux.dev>
Subject: Re: [PATCH v3 2/2] dax/bus: fix Device DAX range alignment validation
Date: Mon, 12 Oct 2026 17:20:31 -0700 [thread overview]
Message-ID: <as15T35oOudDM64C@aschofie-mobl2.lan> (raw)
In-Reply-To: <20260924025035.1265035-3-songmuchun@bytedance.com>
On Thu, Sep 24, 2026 at 10:50:35AM +0800, Muchun Song wrote:
> dev_dax->align describes the page size used by a Device DAX mapping.
> Both the start and size of every range must therefore be aligned to it;
> otherwise the starting PFN cannot represent a naturally aligned page of
> that size.
>
> Only range sizes are currently validated. A dynamic device can therefore
> select a large-page alignment and allocate a range whose start is not
> naturally aligned to that page size. The device binds successfully, but a
> subsequent write to a userspace mapping may trigger a kernel panic.
>
> The automatic resize path can also split a size-aligned request across
> arbitrary free gaps. When devices with different alignments fragment a
> region, this can extend a range by less than its alignment. A later
> allocation then fails, leaving the failed resize partially applied.
>
> Validate both the start and size of allocated and adjusted ranges. Make
> the resize path account only for usable aligned space before changing any
> ranges, and skip gaps that cannot satisfy the device alignment. Initialize
> the device alignment before allocating its initial range so that all
> allocations use the same validation. Perform size validation under the
> same locks as alignment updates so the alignment cannot change before
> resizing begins.
>
> A mapping with an unaligned start is now rejected with -EINVAL, while a
> naturally aligned mapping still binds successfully.
Hi Muchun,
The commit message could be condensed. I think the two failure scenarios and
the changes needed to address them are sufficient.Implementation details
are excessive.
But before that, need to address something else, see below-
>
> Fixes: 6d82120f4156 ("device-dax: add an 'align' attribute")
> Assisted-by: LLM
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> v3:
> - Serialize size alignment validation with alignment updates to avoid a
> partial shrink after a concurrent alignment change (reported by Sashiko)
> - Document the size validation serialization in the commit message
>
> v2:
> - Keep the alloc_is_aligned() name to avoid unrelated helper renaming
> (suggested by Dave Jiang)
> - Move this patch after the mapping error reporting fix for independent
> backports (suggested by Dave Jiang)
> ---
> drivers/dax/bus.c | 144 +++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 109 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
snip
> @@ -1468,6 +1542,7 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data)
> return ERR_PTR(-ENOMEM);
>
> dev_dax->region = dax_region;
> + dev_dax->align = dax_region->align;
Moving this assignment means that initial allocations for static
pmem regions now go through the new range_is_aligned() check.
I'm concerned this may reject existing namespaces with 4K alignment.
nd_pfn_validate() doesn't require the data offset to be aligned to
memremap_compat_align(), and older namespace formats may have offsets
that don't meet that requirement.
Can you check whether an existing namespace with such an offset
would still probe successfully after this change?
I'm also wondering whether the initial range needs to satisfy
memremap_compat_align(), or whether checking dev_dax->align is
sufficient here.
Have you also tested the static pmem Device DAX path, particularly
with namespaces created by older kernels? The reproducer described
in the cover letter addresses the alignment failure, but I'd like
to make sure we aren't introducing a regression for existing
namespaces.
-- Alison
> if (is_static(dax_region)) {
> if (dev_WARN_ONCE(parent, data->id < 0,
> "dynamic id specified to static region\n")) {
> @@ -1526,7 +1601,6 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data)
>
> dev_dax->dax_dev = dax_dev;
> dev_dax->target_node = dax_region->target_node;
> - dev_dax->align = dax_region->align;
> ida_init(&dev_dax->ida);
>
> dev_dax->memmap_on_memory = data->memmap_on_memory;
> --
> 2.54.0
>
next prev parent reply other threads:[~2026-10-13 0:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 2:50 [PATCH v3 0/2] dax: Fix Device DAX range allocation validation Muchun Song
2026-09-24 2:50 ` [PATCH v3 1/2] dax/bus: fix mapping attribute error reporting Muchun Song
2026-10-13 0:13 ` Alison Schofield
2026-10-13 6:27 ` Muchun Song
2026-10-13 2:31 ` jianyungao89
2026-09-24 2:50 ` [PATCH v3 2/2] dax/bus: fix Device DAX range alignment validation Muchun Song
2026-10-13 0:20 ` Alison Schofield [this message]
2026-10-13 8:45 ` Muchun Song
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=as15T35oOudDM64C@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=akpm@linux-foundation.org \
--cc=dave.jiang@intel.com \
--cc=djbw@kernel.org \
--cc=joao.m.martins@oracle.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=nvdimm@lists.linux.dev \
--cc=songmuchun@bytedance.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
all inboxes | Powered by JetHome®