Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1601973

[PATCH v4 01/13] mm: fix type width of section to/from pfn conversion macros

From Dan Williams <dan.j.williams@intel.com>
Newsgroups linux.kernel
Subject [PATCH v4 01/13] mm: fix type width of section to/from pfn conversion macros
Date 2017-03-16 07:20 +0100
Message-ID <tlwVs-2BJ-23@gated-at.bofh.it> (permalink)
References <tlwVr-2BJ-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


section_nr_to_pfn() will silently accept an argument that is too small
to contain a pfn. Cast the argument to an unsigned long, similar to
PFN_PHYS(). Fix up pfn_to_section_nr() in the same way.

This was discovered in __add_pages() when converting it to use an
signed integer for the loop variable.

Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Stephen Bates <stephen.bates@microsemi.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 include/linux/mmzone.h |    4 ++--
 mm/memory_hotplug.c    |    4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 8e02b3750fe0..ffa9503d5be5 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1064,8 +1064,8 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
 #error Allocator MAX_ORDER exceeds SECTION_SIZE
 #endif
 
-#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
-#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
+#define pfn_to_section_nr(pfn) ((unsigned long)(pfn) >> PFN_SECTION_SHIFT)
+#define section_nr_to_pfn(sec) ((unsigned long)(sec) << PFN_SECTION_SHIFT)
 
 #define SECTION_ALIGN_UP(pfn)	(((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
 #define SECTION_ALIGN_DOWN(pfn)	((pfn) & PAGE_SECTION_MASK)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 6fa7208bcd56..e1751ca002fa 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -536,9 +536,7 @@ static int __meminit __add_section(int nid, struct zone *zone,
 int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
 			unsigned long nr_pages)
 {
-	unsigned long i;
-	int err = 0;
-	int start_sec, end_sec;
+	int err = 0, i, start_sec, end_sec;
 	struct vmem_altmap *altmap;
 
 	clear_zone_contiguous(zone);

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/13] mm: sub-section memory hotplug support Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 07/13] mm: fix register_new_memory() zone type detection Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 10/13] mm: prepare for hot-{add,  remove} of sub-section ranges Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 06/13] mm: track active portions of a section at boot Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 12/13] mm: enable section-unaligned devm_memremap_pages() Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 11/13] mm: support section-unaligned ZONE_DEVICE memory  ranges Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 05/13] mm: cleanup sparse_init_one_section() return value Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 01/13] mm: fix type width of section to/from pfn  conversion macros Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 09/13] mm: convert kmalloc_section_memmap() to  populate_section_memmap() Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 02/13] mm,  devm_memremap_pages: use multi-order radix for ZONE_DEVICE lookups Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 03/13] mm: introduce struct mem_section_usage to track  partial population of a section Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 04/13] mm: introduce common definitions for the size and  mask of a section Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 13/13] libnvdimm, pfn,  dax: stop padding pmem namespaces to section alignment Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  [PATCH v4 08/13] x86,  kasan: clarify kasan's dependency on vmemmap_populate_hugepages() Dan Williams <dan.j.williams@intel.com> - 2017-03-16 07:20 +0100
  Re: [PATCH v4 00/13] mm: sub-section memory hotplug support Michal Hocko <mhocko@kernel.org> - 2017-03-16 18:50 +0100
    Re: [PATCH v4 00/13] mm: sub-section memory hotplug support Dan Williams <dan.j.williams@intel.com> - 2017-03-16 20:10 +0100
      Re: [PATCH v4 00/13] mm: sub-section memory hotplug support Michal Hocko <mhocko@kernel.org> - 2017-03-19 18:00 +0100

csiph-web