mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: Dave Jiang <dave.jiang@intel.com>
Cc: Muchun Song <songmuchun@bytedance.com>,
	Dan Williams <djbw@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Alison Schofield <alison.schofield@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
Subject: Re: [PATCH 1/2] dax/bus: fix Device DAX range alignment validation
Date: Tue, 22 Sep 2026 10:21:50 +0800	[thread overview]
Message-ID: <D5FDE914-C12B-4E34-B481-56BDEAE84118@linux.dev> (raw)
In-Reply-To: <8a90ff33-97e4-4796-a8a6-f484760557ca@intel.com>



> On Sep 22, 2026, at 05:01, Dave Jiang <dave.jiang@intel.com> wrote:
> 
> 
> 
> On 9/15/26 2:56 AM, 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.
>> 
>> A mapping with an unaligned start is now rejected with -EINVAL, while a
>> naturally aligned mapping still binds successfully.
>> 
>> Fixes: 6d82120f4156 ("device-dax: add an 'align' attribute")
>> Assisted-by: LLM
>> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>> ---
>> drivers/dax/bus.c | 143 +++++++++++++++++++++++++++++++++++-----------
>> 1 file changed, 109 insertions(+), 34 deletions(-)
>> 
>> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
>> index b809e1a264af..54e4bbc98218 100644
>> --- a/drivers/dax/bus.c
>> +++ b/drivers/dax/bus.c
>> @@ -848,6 +848,44 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id)
>> return 0;
>> }
>> 
>> +static inline unsigned long dev_dax_min_align(struct dev_dax *dev_dax)
>> +{
>> + 	return max_t(unsigned long, dev_dax->align, memremap_compat_align());
>> +}
>> +
>> +static inline bool size_is_aligned(struct dev_dax *dev_dax, resource_size_t size)
> 
> Leave the name alloc_is_aligned() may generate less churn in this patch
> 

Yes, I initially thought that `alloc_is_aligned` was doing a size check,
in order to keep it clearly consistent with `range_is_aligned`. But this
did indeed introduce unnecessary churn, and it might be more suitable for
a separate cleanup later, rather than being squeezed into this series.

Thanks for your review.

Muchun

  reply	other threads:[~2026-09-22  2:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  9:56 [PATCH 0/2] dax: Fix Device DAX range allocation validation Muchun Song
2026-09-15  9:56 ` [PATCH 1/2] dax/bus: fix Device DAX range alignment validation Muchun Song
2026-09-21 21:01   ` Dave Jiang
2026-09-22  2:21     ` Muchun Song [this message]
2026-09-15  9:56 ` [PATCH 2/2] dax/bus: fix mapping attribute error reporting Muchun Song
2026-09-21 19:23   ` Dave Jiang
2026-09-22  2:27     ` Muchun Song
2026-09-18 17:02 ` [PATCH 0/2] dax: Fix Device DAX range allocation validation Dave Jiang
2026-09-19  5:03   ` Muchun Song
2026-09-21 18:58     ` Dave Jiang
2026-09-22  2:25       ` 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=D5FDE914-C12B-4E34-B481-56BDEAE84118@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=alison.schofield@intel.com \
    --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=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®