All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Price" <gourry@gourry.net>
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: Re: [PATCH v7 01/10] mm/memory: add memory_block_aligned_range() helper
Date: Sun, 12 Jul 2026 15:52:21 +0000	[thread overview]
Message-ID: <20260712155222.623051F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260712154505.3564379-2-gourry@gourry.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Integer overflow in `memory_block_aligned_range` when `range->end == U64_MAX` incorrectly truncates valid memory ranges.
--

--- Patch [1]: [PATCH v7 01/10] mm/memory: add memory_block_aligned_range() helper ---
commit 1d936debbb2e5198011a220a96cf6a3dc9882748
Author: Gregory Price <gourry@gourry.net>

mm/memory: add memory_block_aligned_range() helper

This commit introduces memory_block_aligned_range() in <linux/memory.h> to
align ranges to memory block boundaries for memory hotplug operations. It also
updates the dax/kmem driver to use this new generic helper.

> diff --git a/include/linux/memory.h b/include/linux/memory.h
> index 463dc02f6cff0..1783299073e47 100644
> --- a/include/linux/memory.h
> +++ b/include/linux/memory.h
[ ... ]
> @@ -100,6 +101,32 @@ int arch_get_memory_phys_device(unsigned long start_pfn);
>  unsigned long memory_block_size_bytes(void);
>  int set_memory_block_size_order(unsigned int order);
>  
> +/**
> + * memory_block_aligned_range - align a physical address range to memory blocks
> + * @range: the input range to align
> + *
> + * Aligns the start address up and the end address down to memory block
> + * boundaries. This is required for memory hotplug operations which must
> + * operate on memory-block aligned ranges.
> + *
> + * Returns the aligned range. Callers should check that the returned
> + * range is valid (aligned.start < aligned.end) before using it.
> + */
> +static inline struct range memory_block_aligned_range(const struct range *range)
> +{
> +	struct range aligned;
> +
> +	aligned.start = ALIGN(range->start, memory_block_size_bytes());
> +	aligned.end = ALIGN_DOWN(range->end + 1, memory_block_size_bytes());
> +	/* No whole block fits (e.g. range below the first boundary): empty. */
> +	if (aligned.end <= aligned.start)
> +		aligned.start = aligned.end;

[Severity: Medium]
Does this overflow if range->end is U64_MAX?

If range->end is U64_MAX, range->end + 1 will wrap around to 0. This makes
ALIGN_DOWN(0, ...) return 0.

Since aligned.end is now 0, the condition aligned.end <= aligned.start
evaluates to true. This would incorrectly report a valid range spanning to
the end of the 64-bit address space as an empty range.

Is there a way to handle the U64_MAX upper bound safely to avoid truncating
the range?

> +	else
> +		aligned.end -= 1;
> +
> +	return aligned;
> +}
> +
>  struct memory_notify {
>  	unsigned long start_pfn;
>  	unsigned long nr_pages;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260712154505.3564379-1-gourry@gourry.net?part=1

  reply	other threads:[~2026-07-12 15:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 15:44 [PATCH v7 00/10] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price
2026-07-12 15:44 ` [PATCH v7 01/10] mm/memory: add memory_block_aligned_range() helper Gregory Price
2026-07-12 15:52   ` sashiko-bot [this message]
2026-07-12 15:44 ` [PATCH v7 02/10] mm/memory_hotplug: add mhp_online_type_to_str() and export string helpers Gregory Price
2026-07-12 15:44 ` [PATCH v7 03/10] mm/memory_hotplug: pass online_type to online_memory_block() via arg Gregory Price
2026-07-12 15:53   ` sashiko-bot
2026-07-12 15:44 ` [PATCH v7 04/10] mm/memory_hotplug: export mhp_get_default_online_type Gregory Price
2026-07-12 15:56   ` sashiko-bot
2026-07-12 15:44 ` [PATCH v7 05/10] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg Gregory Price
2026-07-12 15:45 ` [PATCH v7 06/10] mm/memory_hotplug: add offline_and_remove_memory_ranges() Gregory Price
2026-07-12 15:53   ` sashiko-bot
2026-07-12 15:45 ` [PATCH v7 07/10] dax/kmem: resolve default online type at probe time Gregory Price
2026-07-12 15:56   ` sashiko-bot
2026-07-12 15:45 ` [PATCH v7 08/10] dax/kmem: extract hotplug/hotremove helper functions Gregory Price
2026-07-12 15:54   ` sashiko-bot
2026-07-12 15:45 ` [PATCH v7 09/10] dax/kmem: add sysfs interface for atomic whole-device hotplug Gregory Price
2026-07-12 15:45 ` [PATCH v7 10/10] selftests/dax: add dax/kmem hotplug sysfs regression test Gregory Price
2026-07-12 16:48 ` [PATCH v7 00/10] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price

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=20260712155222.623051F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gourry@gourry.net \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.