Message ID | 20210712124052.26491-2-david@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v1,1/4] mm/memory_hotplug: use "unsigned long" for PFN in zone_for_pfn_range() | expand |
On Mon, Jul 12, 2021 at 02:40:49PM +0200, David Hildenbrand wrote: > Checkpatch complained on a follow-up patch that we are using "unsigned" > here, which defaults to "unsigned int" and checkpatch is correct. > > Use "unsigned long" instead, just as we do in other places when handling > PFNs. This can bite us once we have physical addresses in the range of > multiple TB. > > Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > include/linux/memory_hotplug.h | 4 ++-- > mm/memory_hotplug.c | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) I'd propose to add Cc: <stable@vger.kernel.org> since I actually had the fun to try to debug something like this a couple of years ago: 6cdb18ad98a4 ("mm/vmstat: fix overflow in mod_zone_page_state()")
> Checkpatch complained on a follow-up patch that we are using "unsigned" > here, which defaults to "unsigned int" and checkpatch is correct. > > Use "unsigned long" instead, just as we do in other places when handling > PFNs. This can bite us once we have physical addresses in the range of > multiple TB. > > Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > include/linux/memory_hotplug.h | 4 ++-- > mm/memory_hotplug.c | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index a7fd2c3ccb77..d01b504ce06f 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -339,8 +339,8 @@ extern void sparse_remove_section(struct mem_section *ms, > unsigned long map_offset, struct vmem_altmap *altmap); > extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, > unsigned long pnum); > -extern struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, > - unsigned long nr_pages); > +extern struct zone *zone_for_pfn_range(int online_type, int nid, > + unsigned long start_pfn, unsigned long nr_pages); > extern int arch_create_linear_mapping(int nid, u64 start, u64 size, > struct mhp_params *params); > void arch_remove_linear_mapping(u64 start, u64 size); > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 8cb75b26ea4f..93b3abaf9828 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -708,8 +708,8 @@ static inline struct zone *default_zone_for_pfn(int nid, unsigned long start_pfn > return movable_node_enabled ? movable_zone : kernel_zone; > } > > -struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, > - unsigned long nr_pages) > +struct zone *zone_for_pfn_range(int online_type, int nid, > + unsigned long start_pfn, unsigned long nr_pages) > { > if (online_type == MMOP_ONLINE_KERNEL) > return default_kernel_zone_for_pfn(nid, start_pfn, nr_pages); Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com>
On Mon, Jul 12, 2021 at 02:40:49PM +0200, David Hildenbrand wrote: > Checkpatch complained on a follow-up patch that we are using "unsigned" > here, which defaults to "unsigned int" and checkpatch is correct. > > Use "unsigned long" instead, just as we do in other places when handling > PFNs. This can bite us once we have physical addresses in the range of > multiple TB. > > Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") > Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Oscar Salvador <osalvador@suse.de>
On Mon, Jul 12, 2021 at 8:42 PM David Hildenbrand <david@redhat.com> wrote: > > Checkpatch complained on a follow-up patch that we are using "unsigned" > here, which defaults to "unsigned int" and checkpatch is correct. > > Use "unsigned long" instead, just as we do in other places when handling > PFNs. This can bite us once we have physical addresses in the range of > multiple TB. > > Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") > Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com>
On 14.07.21 22:13, Heiko Carstens wrote: > On Mon, Jul 12, 2021 at 02:40:49PM +0200, David Hildenbrand wrote: >> Checkpatch complained on a follow-up patch that we are using "unsigned" >> here, which defaults to "unsigned int" and checkpatch is correct. >> >> Use "unsigned long" instead, just as we do in other places when handling >> PFNs. This can bite us once we have physical addresses in the range of >> multiple TB. >> >> Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") >> Signed-off-by: David Hildenbrand <david@redhat.com> >> --- >> include/linux/memory_hotplug.h | 4 ++-- >> mm/memory_hotplug.c | 4 ++-- >> 2 files changed, 4 insertions(+), 4 deletions(-) > > I'd propose to add Cc: <stable@vger.kernel.org> since I actually had > the fun to try to debug something like this a couple of years ago: > 6cdb18ad98a4 ("mm/vmstat: fix overflow in mod_zone_page_state()") > Good point, and thinking again what can go wrong, I tend to agree. We are trying to keep zones contiguous and it could happen that we end up with something like ZONE_DMA here (via default_kernel_zone_for_pfn()) and would consequently online something to ZONE_DMA that doesn't belong there, resulting in crashes. @Andrew can you add Cc: <stable@vger.kernel.org> and "As we will search for a fitting zone using the wrong pfn, we might end up onlining memory to one of the special kernel zones, such as ZONE_DMA, which can end badly as the onlined memory does not satisfy properties of these zones." Thanks Heiko!
On Thu, 15 Jul 2021 11:42:21 +0200 David Hildenbrand <david@redhat.com> wrote: > > I'd propose to add Cc: <stable@vger.kernel.org> since I actually had > > the fun to try to debug something like this a couple of years ago: > > 6cdb18ad98a4 ("mm/vmstat: fix overflow in mod_zone_page_state()") > > > > Good point, and thinking again what can go wrong, I tend to agree. We > are trying to keep zones contiguous and it could happen that we end up > with something like ZONE_DMA here (via default_kernel_zone_for_pfn()) > and would consequently online something to ZONE_DMA that doesn't belong > there, resulting in crashes. > > @Andrew can you add Cc: <stable@vger.kernel.org> and > > "As we will search for a fitting zone using the wrong pfn, we might end > up onlining memory to one of the special kernel zones, such as ZONE_DMA, > which can end badly as the onlined memory does not satisfy properties of > these zones." Yep, all done.
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index a7fd2c3ccb77..d01b504ce06f 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -339,8 +339,8 @@ extern void sparse_remove_section(struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap); extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pnum); -extern struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, - unsigned long nr_pages); +extern struct zone *zone_for_pfn_range(int online_type, int nid, + unsigned long start_pfn, unsigned long nr_pages); extern int arch_create_linear_mapping(int nid, u64 start, u64 size, struct mhp_params *params); void arch_remove_linear_mapping(u64 start, u64 size); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 8cb75b26ea4f..93b3abaf9828 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -708,8 +708,8 @@ static inline struct zone *default_zone_for_pfn(int nid, unsigned long start_pfn return movable_node_enabled ? movable_zone : kernel_zone; } -struct zone *zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, - unsigned long nr_pages) +struct zone *zone_for_pfn_range(int online_type, int nid, + unsigned long start_pfn, unsigned long nr_pages) { if (online_type == MMOP_ONLINE_KERNEL) return default_kernel_zone_for_pfn(nid, start_pfn, nr_pages);
Checkpatch complained on a follow-up patch that we are using "unsigned" here, which defaults to "unsigned int" and checkpatch is correct. Use "unsigned long" instead, just as we do in other places when handling PFNs. This can bite us once we have physical addresses in the range of multiple TB. Fixes: e5e689302633 ("mm, memory_hotplug: display allowed zones in the preferred ordering") Signed-off-by: David Hildenbrand <david@redhat.com> --- include/linux/memory_hotplug.h | 4 ++-- mm/memory_hotplug.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)