> On Sep 22, 2026, at 05:01, Dave Jiang <[email protected]> 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 <[email protected]>
>> ---
>> 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