aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-19 12:45:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-19 12:45:58 -0400
commit249be8511b269495bc95cb8bdfdd5840b2ba73c0 (patch)
tree6920bde053faa0284b52b2a9c9695f5516520377
parent3bfe1fc46794631366faa3ef075e1b0ff7ba120a (diff)
parenteec4844fae7c033a0c1fc1eb3b8517aeb8b6cc49 (diff)
Merge branch 'akpm' (patches from Andrew)
Merge yet more updates from Andrew Morton: "The rest of MM and a kernel-wide procfs cleanup. Summary of the more significant patches: - Patch series "mm/memory_hotplug: Factor out memory block devicehandling", v3. David Hildenbrand. Some spring-cleaning of the memory hotplug code, notably in drivers/base/memory.c - "mm: thp: fix false negative of shmem vma's THP eligibility". Yang Shi. Fix /proc/pid/smaps output for THP pages used in shmem. - "resource: fix locking in find_next_iomem_res()" + 1. Nadav Amit. Bugfix and speedup for kernel/resource.c - Patch series "mm: Further memory block device cleanups", David Hildenbrand. More spring-cleaning of the memory hotplug code. - Patch series "mm: Sub-section memory hotplug support". Dan Williams. Generalise the memory hotplug code so that pmem can use it more completely. Then remove the hacks from the libnvdimm code which were there to work around the memory-hotplug code's constraints. - "proc/sysctl: add shared variables for range check", Matteo Croce. We have about 250 instances of int zero; ... .extra1 = &zero, in the tree. This is a tree-wide sweep to make all those private "zero"s and "one"s use global variables. Alas, it isn't practical to make those two global integers const" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (38 commits) proc/sysctl: add shared variables for range check mm: migrate: remove unused mode argument mm/sparsemem: cleanup 'section number' data types libnvdimm/pfn: stop padding pmem namespaces to section alignment libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields mm/devm_memremap_pages: enable sub-section remap mm: document ZONE_DEVICE memory-model implications mm/sparsemem: support sub-section hotplug mm/sparsemem: prepare for sub-section ranges mm: kill is_dev_zone() helper mm/hotplug: kill is_dev_zone() usage in __remove_pages() mm/sparsemem: convert kmalloc_section_memmap() to populate_section_memmap() mm/hotplug: prepare shrink_{zone, pgdat}_span for sub-section removal mm/sparsemem: add helpers track active portions of a section at boot mm/sparsemem: introduce a SECTION_IS_EARLY flag mm/sparsemem: introduce struct mem_section_usage drivers/base/memory.c: get rid of find_memory_block_hinted() mm/memory_hotplug: move and simplify walk_memory_blocks() mm/memory_hotplug: rename walk_memory_range() and pass start+size instead of pfns mm: make register_mem_sect_under_node() static ...
-rw-r--r--Documentation/filesystems/proc.txt4
-rw-r--r--Documentation/vm/memory-model.rst40
-rw-r--r--arch/arm64/mm/mmu.c17
-rw-r--r--arch/ia64/mm/init.c2
-rw-r--r--arch/powerpc/mm/mem.c2
-rw-r--r--arch/powerpc/platforms/powernv/memtrace.c23
-rw-r--r--arch/s390/appldata/appldata_base.c15
-rw-r--r--arch/s390/kernel/topology.c6
-rw-r--r--arch/s390/mm/init.c18
-rw-r--r--arch/sh/mm/init.c2
-rw-r--r--arch/x86/entry/vdso/vdso32-setup.c7
-rw-r--r--arch/x86/kernel/itmt.c6
-rw-r--r--arch/x86/mm/init_32.c2
-rw-r--r--arch/x86/mm/init_64.c6
-rw-r--r--drivers/acpi/acpi_memhotplug.c19
-rw-r--r--drivers/base/firmware_loader/fallback_table.c13
-rw-r--r--drivers/base/memory.c219
-rw-r--r--drivers/base/node.c35
-rw-r--r--drivers/gpu/drm/i915/i915_perf.c8
-rw-r--r--drivers/hv/vmbus_drv.c6
-rw-r--r--drivers/nvdimm/dax_devs.c2
-rw-r--r--drivers/nvdimm/pfn.h15
-rw-r--r--drivers/nvdimm/pfn_devs.c95
-rw-r--r--drivers/tty/tty_ldisc.c6
-rw-r--r--drivers/xen/balloon.c7
-rw-r--r--fs/aio.c2
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/iomap.c2
-rw-r--r--fs/notify/inotify/inotify_user.c8
-rw-r--r--fs/proc/proc_sysctl.c4
-rw-r--r--fs/proc/task_mmu.c3
-rw-r--r--fs/ubifs/file.c2
-rw-r--r--include/linux/huge_mm.h23
-rw-r--r--include/linux/memory.h11
-rw-r--r--include/linux/memory_hotplug.h19
-rw-r--r--include/linux/migrate.h3
-rw-r--r--include/linux/mm.h38
-rw-r--r--include/linux/mmzone.h88
-rw-r--r--include/linux/node.h14
-rw-r--r--include/linux/sysctl.h7
-rw-r--r--ipc/ipc_sysctl.c35
-rw-r--r--kernel/memremap.c57
-rw-r--r--kernel/pid_namespace.c3
-rw-r--r--kernel/resource.c49
-rw-r--r--kernel/sysctl.c197
-rw-r--r--kernel/ucount.c6
-rw-r--r--mm/huge_memory.c11
-rw-r--r--mm/memory.c13
-rw-r--r--mm/memory_hotplug.c275
-rw-r--r--mm/migrate.c7
-rw-r--r--mm/page_alloc.c16
-rw-r--r--mm/shmem.c3
-rw-r--r--mm/sparse-vmemmap.c21
-rw-r--r--mm/sparse.c355
-rw-r--r--net/core/neighbour.c20
-rw-r--r--net/core/sysctl_net_core.c34
-rw-r--r--net/dccp/sysctl.c16
-rw-r--r--net/ipv4/sysctl_net_ipv4.c60
-rw-r--r--net/ipv6/addrconf.c6
-rw-r--r--net/ipv6/route.c7
-rw-r--r--net/ipv6/sysctl_net_ipv6.c10
-rw-r--r--net/mpls/af_mpls.c10
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c3
-rw-r--r--net/rxrpc/sysctl.c9
-rw-r--r--net/sctp/sysctl.c35
-rw-r--r--net/sunrpc/xprtrdma/transport.c3
-rw-r--r--net/tipc/sysctl.c6
-rw-r--r--security/keys/sysctl.c26
-rw-r--r--security/loadpin/loadpin.c6
-rw-r--r--security/yama/yama_lsm.c3
71 files changed, 1087 insertions, 1020 deletions
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index fb4735fd73b0..99ca040e3f90 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -486,8 +486,8 @@ replaced by copy-on-write) part of the underlying shmem object out on swap.
486"SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this 486"SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this
487does not take into account swapped out page of underlying shmem objects. 487does not take into account swapped out page of underlying shmem objects.
488"Locked" indicates whether the mapping is locked in memory or not. 488"Locked" indicates whether the mapping is locked in memory or not.
489"THPeligible" indicates whether the mapping is eligible for THP pages - 1 if 489"THPeligible" indicates whether the mapping is eligible for allocating THP
490true, 0 otherwise. 490pages - 1 if true, 0 otherwise. It just shows the current status.
491 491
492"VmFlags" field deserves a separate description. This member represents the kernel 492"VmFlags" field deserves a separate description. This member represents the kernel
493flags associated with the particular virtual memory area in two letter encoded 493flags associated with the particular virtual memory area in two letter encoded
diff --git a/Documentation/vm/memory-model.rst b/Documentation/vm/memory-model.rst
index 382f72ace1fc..58a12376b7df 100644
--- a/Documentation/vm/memory-model.rst
+++ b/Documentation/vm/memory-model.rst
@@ -181,3 +181,43 @@ that is eventually passed to vmemmap_populate() through a long chain
181of function calls. The vmemmap_populate() implementation may use the 181of function calls. The vmemmap_populate() implementation may use the
182`vmem_altmap` along with :c:func:`altmap_alloc_block_buf` helper to 182`vmem_altmap` along with :c:func:`altmap_alloc_block_buf` helper to
183allocate memory map on the persistent memory device. 183allocate memory map on the persistent memory device.
184
185ZONE_DEVICE
186===========
187The `ZONE_DEVICE` facility builds upon `SPARSEMEM_VMEMMAP` to offer
188`struct page` `mem_map` services for device driver identified physical
189address ranges. The "device" aspect of `ZONE_DEVICE` relates to the fact
190that the page objects for these address ranges are never marked online,
191and that a reference must be taken against the device, not just the page
192to keep the memory pinned for active use. `ZONE_DEVICE`, via
193:c:func:`devm_memremap_pages`, performs just enough memory hotplug to
194turn on :c:func:`pfn_to_page`, :c:func:`page_to_pfn`, and
195:c:func:`get_user_pages` service for the given range of pfns. Since the
196page reference count never drops below 1 the page is never tracked as
197free memory and the page's `struct list_head lru` space is repurposed
198for back referencing to the host device / driver that mapped the memory.
199
200While `SPARSEMEM` presents memory as a collection of sections,
201optionally collected into memory blocks, `ZONE_DEVICE` users have a need
202for smaller granularity of populating the `mem_map`. Given that
203`ZONE_DEVICE` memory is never marked online it is subsequently never
204subject to its memory ranges being exposed through the sysfs memory
205hotplug api on memory block boundaries. The implementation relies on
206this lack of user-api constraint to allow sub-section sized memory
207ranges to be specified to :c:func:`arch_add_memory`, the top-half of
208memory hotplug. Sub-section support allows for 2MB as the cross-arch
209common alignment granularity for :c:func:`devm_memremap_pages`.
210
211The users of `ZONE_DEVICE` are:
212
213* pmem: Map platform persistent memory to be used as a direct-I/O target
214 via DAX mappings.
215
216* hmm: Extend `ZONE_DEVICE` with `->page_fault()` and `->page_free()`
217 event callbacks to allow a device-driver to coordinate memory management
218 events related to device-memory, typically GPU memory. See
219 Documentation/vm/hmm.rst.
220
221* p2pdma: Create `struct page` objects to allow peer devices in a
222 PCI/-E topology to coordinate direct-DMA operations between themselves,
223 i.e. bypass host memory.
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e661469cabdd..750a69dde39b 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1074,4 +1074,21 @@ int arch_add_memory(int nid, u64 start, u64 size,
1074 return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, 1074 return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT,
1075 restrictions); 1075 restrictions);
1076} 1076}
1077void arch_remove_memory(int nid, u64 start, u64 size,
1078 struct vmem_altmap *altmap)
1079{
1080 unsigned long start_pfn = start >> PAGE_SHIFT;
1081 unsigned long nr_pages = size >> PAGE_SHIFT;
1082 struct zone *zone;
1083
1084 /*
1085 * FIXME: Cleanup page tables (also in arch_add_memory() in case
1086 * adding fails). Until then, this function should only be used
1087 * during memory hotplug (adding memory), not for memory
1088 * unplug. ARCH_ENABLE_MEMORY_HOTREMOVE must not be
1089 * unlocked yet.
1090 */
1091 zone = page_zone(pfn_to_page(start_pfn));
1092 __remove_pages(zone, start_pfn, nr_pages, altmap);
1093}
1077#endif 1094#endif
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index d28e29103bdb..aae75fd7b810 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -681,7 +681,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
681 return ret; 681 return ret;
682} 682}
683 683
684#ifdef CONFIG_MEMORY_HOTREMOVE
685void arch_remove_memory(int nid, u64 start, u64 size, 684void arch_remove_memory(int nid, u64 start, u64 size,
686 struct vmem_altmap *altmap) 685 struct vmem_altmap *altmap)
687{ 686{
@@ -693,4 +692,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
693 __remove_pages(zone, start_pfn, nr_pages, altmap); 692 __remove_pages(zone, start_pfn, nr_pages, altmap);
694} 693}
695#endif 694#endif
696#endif
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 26a8da3723bb..9259337d7374 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -125,7 +125,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size,
125 return __add_pages(nid, start_pfn, nr_pages, restrictions); 125 return __add_pages(nid, start_pfn, nr_pages, restrictions);
126} 126}
127 127
128#ifdef CONFIG_MEMORY_HOTREMOVE
129void __ref arch_remove_memory(int nid, u64 start, u64 size, 128void __ref arch_remove_memory(int nid, u64 start, u64 size,
130 struct vmem_altmap *altmap) 129 struct vmem_altmap *altmap)
131{ 130{
@@ -151,7 +150,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
151 pr_warn("Hash collision while resizing HPT\n"); 150 pr_warn("Hash collision while resizing HPT\n");
152} 151}
153#endif 152#endif
154#endif /* CONFIG_MEMORY_HOTPLUG */
155 153
156#ifndef CONFIG_NEED_MULTIPLE_NODES 154#ifndef CONFIG_NEED_MULTIPLE_NODES
157void __init mem_topology_setup(void) 155void __init mem_topology_setup(void)
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c
index 5e53c1392d3b..eb2e75dac369 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -70,23 +70,23 @@ static int change_memblock_state(struct memory_block *mem, void *arg)
70/* called with device_hotplug_lock held */ 70/* called with device_hotplug_lock held */
71static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) 71static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
72{ 72{
73 u64 end_pfn = start_pfn + nr_pages - 1; 73 const unsigned long start = PFN_PHYS(start_pfn);
74 const unsigned long size = PFN_PHYS(nr_pages);
74 75
75 if (walk_memory_range(start_pfn, end_pfn, NULL, 76 if (walk_memory_blocks(start, size, NULL, check_memblock_online))
76 check_memblock_online))
77 return false; 77 return false;
78 78
79 walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE, 79 walk_memory_blocks(start, size, (void *)MEM_GOING_OFFLINE,
80 change_memblock_state); 80 change_memblock_state);
81 81
82 if (offline_pages(start_pfn, nr_pages)) { 82 if (offline_pages(start_pfn, nr_pages)) {
83 walk_memory_range(start_pfn, end_pfn, (void *)MEM_ONLINE, 83 walk_memory_blocks(start, size, (void *)MEM_ONLINE,
84 change_memblock_state); 84 change_memblock_state);
85 return false; 85 return false;
86 } 86 }
87 87
88 walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE, 88 walk_memory_blocks(start, size, (void *)MEM_OFFLINE,
89 change_memblock_state); 89 change_memblock_state);
90 90
91 91
92 return true; 92 return true;
@@ -242,9 +242,8 @@ static int memtrace_online(void)
242 */ 242 */
243 if (!memhp_auto_online) { 243 if (!memhp_auto_online) {
244 lock_device_hotplug(); 244 lock_device_hotplug();
245 walk_memory_range(PFN_DOWN(ent->start), 245 walk_memory_blocks(ent->start, ent->size, NULL,
246 PFN_UP(ent->start + ent->size - 1), 246 online_mem_block);
247 NULL, online_mem_block);
248 unlock_device_hotplug(); 247 unlock_device_hotplug();
249 } 248 }
250 249
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index e4b58240ec53..aa738cad1338 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -220,15 +220,13 @@ appldata_timer_handler(struct ctl_table *ctl, int write,
220 void __user *buffer, size_t *lenp, loff_t *ppos) 220 void __user *buffer, size_t *lenp, loff_t *ppos)
221{ 221{
222 int timer_active = appldata_timer_active; 222 int timer_active = appldata_timer_active;
223 int zero = 0;
224 int one = 1;
225 int rc; 223 int rc;
226 struct ctl_table ctl_entry = { 224 struct ctl_table ctl_entry = {
227 .procname = ctl->procname, 225 .procname = ctl->procname,
228 .data = &timer_active, 226 .data = &timer_active,
229 .maxlen = sizeof(int), 227 .maxlen = sizeof(int),
230 .extra1 = &zero, 228 .extra1 = SYSCTL_ZERO,
231 .extra2 = &one, 229 .extra2 = SYSCTL_ONE,
232 }; 230 };
233 231
234 rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos); 232 rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
@@ -255,13 +253,12 @@ appldata_interval_handler(struct ctl_table *ctl, int write,
255 void __user *buffer, size_t *lenp, loff_t *ppos) 253 void __user *buffer, size_t *lenp, loff_t *ppos)
256{ 254{
257 int interval = appldata_interval; 255 int interval = appldata_interval;
258 int one = 1;
259 int rc; 256 int rc;
260 struct ctl_table ctl_entry = { 257 struct ctl_table ctl_entry = {
261 .procname = ctl->procname, 258 .procname = ctl->procname,
262 .data = &interval, 259 .data = &interval,
263 .maxlen = sizeof(int), 260 .maxlen = sizeof(int),
264 .extra1 = &one, 261 .extra1 = SYSCTL_ONE,
265 }; 262 };
266 263
267 rc = proc_dointvec_minmax(&ctl_entry, write, buffer, lenp, ppos); 264 rc = proc_dointvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
@@ -289,13 +286,11 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
289 struct list_head *lh; 286 struct list_head *lh;
290 int rc, found; 287 int rc, found;
291 int active; 288 int active;
292 int zero = 0;
293 int one = 1;
294 struct ctl_table ctl_entry = { 289 struct ctl_table ctl_entry = {
295 .data = &active, 290 .data = &active,
296 .maxlen = sizeof(int), 291 .maxlen = sizeof(int),
297 .extra1 = &zero, 292 .extra1 = SYSCTL_ZERO,
298 .extra2 = &one, 293 .extra2 = SYSCTL_ONE,
299 }; 294 };
300 295
301 found = 0; 296 found = 0;
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 8964a3f60aad..2db6fb405a9a 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -587,15 +587,13 @@ static int topology_ctl_handler(struct ctl_table *ctl, int write,
587{ 587{
588 int enabled = topology_is_enabled(); 588 int enabled = topology_is_enabled();
589 int new_mode; 589 int new_mode;
590 int zero = 0;
591 int one = 1;
592 int rc; 590 int rc;
593 struct ctl_table ctl_entry = { 591 struct ctl_table ctl_entry = {
594 .procname = ctl->procname, 592 .procname = ctl->procname,
595 .data = &enabled, 593 .data = &enabled,
596 .maxlen = sizeof(int), 594 .maxlen = sizeof(int),
597 .extra1 = &zero, 595 .extra1 = SYSCTL_ZERO,
598 .extra2 = &one, 596 .extra2 = SYSCTL_ONE,
599 }; 597 };
600 598
601 rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos); 599 rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index f0bee6af3960..4e5bbe328594 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -273,6 +273,9 @@ int arch_add_memory(int nid, u64 start, u64 size,
273 unsigned long size_pages = PFN_DOWN(size); 273 unsigned long size_pages = PFN_DOWN(size);
274 int rc; 274 int rc;
275 275
276 if (WARN_ON_ONCE(restrictions->altmap))
277 return -EINVAL;
278
276 rc = vmem_add_mapping(start, size); 279 rc = vmem_add_mapping(start, size);
277 if (rc) 280 if (rc)
278 return rc; 281 return rc;
@@ -283,16 +286,15 @@ int arch_add_memory(int nid, u64 start, u64 size,
283 return rc; 286 return rc;
284} 287}
285 288
286#ifdef CONFIG_MEMORY_HOTREMOVE
287void arch_remove_memory(int nid, u64 start, u64 size, 289void arch_remove_memory(int nid, u64 start, u64 size,
288 struct vmem_altmap *altmap) 290 struct vmem_altmap *altmap)
289{ 291{
290 /* 292 unsigned long start_pfn = start >> PAGE_SHIFT;
291 * There is no hardware or firmware interface which could trigger a 293 unsigned long nr_pages = size >> PAGE_SHIFT;
292 * hot memory remove on s390. So there is nothing that needs to be 294 struct zone *zone;
293 * implemented. 295
294 */ 296 zone = page_zone(pfn_to_page(start_pfn));
295 BUG(); 297 __remove_pages(zone, start_pfn, nr_pages, altmap);
298 vmem_remove_mapping(start, size);
296} 299}
297#endif
298#endif /* CONFIG_MEMORY_HOTPLUG */ 300#endif /* CONFIG_MEMORY_HOTPLUG */
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 13c6a6bb5fd9..dfdbaa50946e 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -429,7 +429,6 @@ int memory_add_physaddr_to_nid(u64 addr)
429EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); 429EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
430#endif 430#endif
431 431
432#ifdef CONFIG_MEMORY_HOTREMOVE
433void arch_remove_memory(int nid, u64 start, u64 size, 432void arch_remove_memory(int nid, u64 start, u64 size,
434 struct vmem_altmap *altmap) 433 struct vmem_altmap *altmap)
435{ 434{
@@ -440,5 +439,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
440 zone = page_zone(pfn_to_page(start_pfn)); 439 zone = page_zone(pfn_to_page(start_pfn));
441 __remove_pages(zone, start_pfn, nr_pages, altmap); 440 __remove_pages(zone, start_pfn, nr_pages, altmap);
442} 441}
443#endif
444#endif /* CONFIG_MEMORY_HOTPLUG */ 442#endif /* CONFIG_MEMORY_HOTPLUG */
diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
index 42d4c89f990e..240626e7f55a 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -65,9 +65,6 @@ subsys_initcall(sysenter_setup);
65/* Register vsyscall32 into the ABI table */ 65/* Register vsyscall32 into the ABI table */
66#include <linux/sysctl.h> 66#include <linux/sysctl.h>
67 67
68static const int zero;
69static const int one = 1;
70
71static struct ctl_table abi_table2[] = { 68static struct ctl_table abi_table2[] = {
72 { 69 {
73 .procname = "vsyscall32", 70 .procname = "vsyscall32",
@@ -75,8 +72,8 @@ static struct ctl_table abi_table2[] = {
75 .maxlen = sizeof(int), 72 .maxlen = sizeof(int),
76 .mode = 0644, 73 .mode = 0644,
77 .proc_handler = proc_dointvec_minmax, 74 .proc_handler = proc_dointvec_minmax,
78 .extra1 = (int *)&zero, 75 .extra1 = SYSCTL_ZERO,
79 .extra2 = (int *)&one, 76 .extra2 = SYSCTL_ONE,
80 }, 77 },
81 {} 78 {}
82}; 79};
diff --git a/arch/x86/kernel/itmt.c b/arch/x86/kernel/itmt.c
index 838cf8a32c49..1cb3ca9bba49 100644
--- a/arch/x86/kernel/itmt.c
+++ b/arch/x86/kernel/itmt.c
@@ -65,8 +65,6 @@ static int sched_itmt_update_handler(struct ctl_table *table, int write,
65 return ret; 65 return ret;
66} 66}
67 67
68static unsigned int zero;
69static unsigned int one = 1;
70static struct ctl_table itmt_kern_table[] = { 68static struct ctl_table itmt_kern_table[] = {
71 { 69 {
72 .procname = "sched_itmt_enabled", 70 .procname = "sched_itmt_enabled",
@@ -74,8 +72,8 @@ static struct ctl_table itmt_kern_table[] = {
74 .maxlen = sizeof(unsigned int), 72 .maxlen = sizeof(unsigned int),
75 .mode = 0644, 73 .mode = 0644,
76 .proc_handler = sched_itmt_update_handler, 74 .proc_handler = sched_itmt_update_handler,
77 .extra1 = &zero, 75 .extra1 = SYSCTL_ZERO,
78 .extra2 = &one, 76 .extra2 = SYSCTL_ONE,
79 }, 77 },
80 {} 78 {}
81}; 79};
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index f265a4316179..4068abb9427f 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -860,7 +860,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
860 return __add_pages(nid, start_pfn, nr_pages, restrictions); 860 return __add_pages(nid, start_pfn, nr_pages, restrictions);
861} 861}
862 862
863#ifdef CONFIG_MEMORY_HOTREMOVE
864void arch_remove_memory(int nid, u64 start, u64 size, 863void arch_remove_memory(int nid, u64 start, u64 size,
865 struct vmem_altmap *altmap) 864 struct vmem_altmap *altmap)
866{ 865{
@@ -872,7 +871,6 @@ void arch_remove_memory(int nid, u64 start, u64 size,
872 __remove_pages(zone, start_pfn, nr_pages, altmap); 871 __remove_pages(zone, start_pfn, nr_pages, altmap);
873} 872}
874#endif 873#endif
875#endif
876 874
877int kernel_set_to_readonly __read_mostly; 875int kernel_set_to_readonly __read_mostly;
878 876
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 08bbf648827b..a6b5c653727b 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1198,7 +1198,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
1198 remove_pagetable(start, end, false, altmap); 1198 remove_pagetable(start, end, false, altmap);
1199} 1199}
1200 1200
1201#ifdef CONFIG_MEMORY_HOTREMOVE
1202static void __meminit 1201static void __meminit
1203kernel_physical_mapping_remove(unsigned long start, unsigned long end) 1202kernel_physical_mapping_remove(unsigned long start, unsigned long end)
1204{ 1203{
@@ -1219,7 +1218,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
1219 __remove_pages(zone, start_pfn, nr_pages, altmap); 1218 __remove_pages(zone, start_pfn, nr_pages, altmap);
1220 kernel_physical_mapping_remove(start, start + size); 1219 kernel_physical_mapping_remove(start, start + size);
1221} 1220}
1222#endif
1223#endif /* CONFIG_MEMORY_HOTPLUG */ 1221#endif /* CONFIG_MEMORY_HOTPLUG */
1224 1222
1225static struct kcore_list kcore_vsyscall; 1223static struct kcore_list kcore_vsyscall;
@@ -1520,7 +1518,9 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
1520{ 1518{
1521 int err; 1519 int err;
1522 1520
1523 if (boot_cpu_has(X86_FEATURE_PSE)) 1521 if (end - start < PAGES_PER_SECTION * sizeof(struct page))
1522 err = vmemmap_populate_basepages(start, end, node);
1523 else if (boot_cpu_has(X86_FEATURE_PSE))
1524 err = vmemmap_populate_hugepages(start, end, node, altmap); 1524 err = vmemmap_populate_hugepages(start, end, node, altmap);
1525 else if (altmap) { 1525 else if (altmap) {
1526 pr_err_once("%s: no cpu support for altmap allocations\n", 1526 pr_err_once("%s: no cpu support for altmap allocations\n",
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index db013dc21c02..e294f44a7850 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -155,16 +155,6 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
155 return 0; 155 return 0;
156} 156}
157 157
158static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info)
159{
160 return PFN_DOWN(info->start_addr);
161}
162
163static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info)
164{
165 return PFN_UP(info->start_addr + info->length-1);
166}
167
168static int acpi_bind_memblk(struct memory_block *mem, void *arg) 158static int acpi_bind_memblk(struct memory_block *mem, void *arg)
169{ 159{
170 return acpi_bind_one(&mem->dev, arg); 160 return acpi_bind_one(&mem->dev, arg);
@@ -173,9 +163,8 @@ static int acpi_bind_memblk(struct memory_block *mem, void *arg)
173static int acpi_bind_memory_blocks(struct acpi_memory_info *info, 163static int acpi_bind_memory_blocks(struct acpi_memory_info *info,
174 struct acpi_device *adev) 164 struct acpi_device *adev)
175{ 165{
176 return walk_memory_range(acpi_meminfo_start_pfn(info), 166 return walk_memory_blocks(info->start_addr, info->length, adev,
177 acpi_meminfo_end_pfn(info), adev, 167 acpi_bind_memblk);
178 acpi_bind_memblk);
179} 168}
180 169
181static int acpi_unbind_memblk(struct memory_block *mem, void *arg) 170static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
@@ -186,8 +175,8 @@ static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
186 175
187static void acpi_unbind_memory_blocks(struct acpi_memory_info *info) 176static void acpi_unbind_memory_blocks(struct acpi_memory_info *info)
188{ 177{
189 walk_memory_range(acpi_meminfo_start_pfn(info), 178 walk_memory_blocks(info->start_addr, info->length, NULL,
190 acpi_meminfo_end_pfn(info), NULL, acpi_unbind_memblk); 179 acpi_unbind_memblk);
191} 180}
192 181
193static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 182static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
diff --git a/drivers/base/firmware_loader/fallback_table.c b/drivers/base/firmware_loader/fallback_table.c
index 776dd69cf5be..ba9d30b28edc 100644
--- a/drivers/base/firmware_loader/fallback_table.c
+++ b/drivers/base/firmware_loader/fallback_table.c
@@ -16,9 +16,6 @@
16 * firmware fallback configuration table 16 * firmware fallback configuration table
17 */ 17 */
18 18
19static unsigned int zero;
20static unsigned int one = 1;
21
22struct firmware_fallback_config fw_fallback_config = { 19struct firmware_fallback_config fw_fallback_config = {
23 .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK), 20 .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK),
24 .loading_timeout = 60, 21 .loading_timeout = 60,
@@ -26,6 +23,7 @@ struct firmware_fallback_config fw_fallback_config = {
26}; 23};
27EXPORT_SYMBOL_GPL(fw_fallback_config); 24EXPORT_SYMBOL_GPL(fw_fallback_config);
28 25
26#ifdef CONFIG_SYSCTL
29struct ctl_table firmware_config_table[] = { 27struct ctl_table firmware_config_table[] = {
30 { 28 {
31 .procname = "force_sysfs_fallback", 29 .procname = "force_sysfs_fallback",
@@ -33,8 +31,8 @@ struct ctl_table firmware_config_table[] = {
33 .maxlen = sizeof(unsigned int), 31 .maxlen = sizeof(unsigned int),
34 .mode = 0644, 32 .mode = 0644,
35 .proc_handler = proc_douintvec_minmax, 33 .proc_handler = proc_douintvec_minmax,
36 .extra1 = &zero, 34 .extra1 = SYSCTL_ZERO,
37 .extra2 = &one, 35 .extra2 = SYSCTL_ONE,
38 }, 36 },
39 { 37 {
40 .procname = "ignore_sysfs_fallback", 38 .procname = "ignore_sysfs_fallback",
@@ -42,9 +40,10 @@ struct ctl_table firmware_config_table[] = {
42 .maxlen = sizeof(unsigned int), 40 .maxlen = sizeof(unsigned int),
43 .mode = 0644, 41 .mode = 0644,
44 .proc_handler = proc_douintvec_minmax, 42 .proc_handler = proc_douintvec_minmax,
45 .extra1 = &zero, 43 .extra1 = SYSCTL_ZERO,
46 .extra2 = &one, 44 .extra2 = SYSCTL_ONE,
47 }, 45 },
48 { } 46 { }
49}; 47};
50EXPORT_SYMBOL_GPL(firmware_config_table); 48EXPORT_SYMBOL_GPL(firmware_config_table);
49#endif
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index f180427e48f4..20c39d1bcef8 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -34,11 +34,21 @@ static DEFINE_MUTEX(mem_sysfs_mutex);
34 34
35static int sections_per_block; 35static int sections_per_block;
36 36
37static inline int base_memory_block_id(int section_nr) 37static inline unsigned long base_memory_block_id(unsigned long section_nr)
38{ 38{
39 return section_nr / sections_per_block; 39 return section_nr / sections_per_block;
40} 40}
41 41
42static inline unsigned long pfn_to_block_id(unsigned long pfn)
43{
44 return base_memory_block_id(pfn_to_section_nr(pfn));
45}
46
47static inline unsigned long phys_to_block_id(unsigned long phys)
48{
49 return pfn_to_block_id(PFN_DOWN(phys));
50}
51
42static int memory_subsys_online(struct device *dev); 52static int memory_subsys_online(struct device *dev);
43static int memory_subsys_offline(struct device *dev); 53static int memory_subsys_offline(struct device *dev);
44 54
@@ -126,9 +136,9 @@ static ssize_t phys_index_show(struct device *dev,
126static ssize_t removable_show(struct device *dev, struct device_attribute *attr, 136static ssize_t removable_show(struct device *dev, struct device_attribute *attr,
127 char *buf) 137 char *buf)
128{ 138{
129 unsigned long i, pfn;
130 int ret = 1;
131 struct memory_block *mem = to_memory_block(dev); 139 struct memory_block *mem = to_memory_block(dev);
140 unsigned long pfn;
141 int ret = 1, i;
132 142
133 if (mem->state != MEM_ONLINE) 143 if (mem->state != MEM_ONLINE)
134 goto out; 144 goto out;
@@ -578,23 +588,13 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn)
578 return 0; 588 return 0;
579} 589}
580 590
581/* 591/* A reference for the returned memory block device is acquired. */
582 * A reference for the returned object is held and the reference for the 592static struct memory_block *find_memory_block_by_id(unsigned long block_id)
583 * hinted object is released.
584 */
585struct memory_block *find_memory_block_hinted(struct mem_section *section,
586 struct memory_block *hint)
587{ 593{
588 int block_id = base_memory_block_id(__section_nr(section));
589 struct device *hintdev = hint ? &hint->dev : NULL;
590 struct device *dev; 594 struct device *dev;
591 595
592 dev = subsys_find_device_by_id(&memory_subsys, block_id, hintdev); 596 dev = subsys_find_device_by_id(&memory_subsys, block_id, NULL);
593 if (hint) 597 return dev ? to_memory_block(dev) : NULL;
594 put_device(&hint->dev);
595 if (!dev)
596 return NULL;
597 return to_memory_block(dev);
598} 598}
599 599
600/* 600/*
@@ -607,7 +607,9 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
607 */ 607 */
608struct memory_block *find_memory_block(struct mem_section *section) 608struct memory_block *find_memory_block(struct mem_section *section)
609{ 609{
610 return find_memory_block_hinted(section, NULL); 610 unsigned long block_id = base_memory_block_id(__section_nr(section));
611
612 return find_memory_block_by_id(block_id);
611} 613}
612 614
613static struct attribute *memory_memblk_attrs[] = { 615static struct attribute *memory_memblk_attrs[] = {
@@ -652,20 +654,22 @@ int register_memory(struct memory_block *memory)
652} 654}
653 655
654static int init_memory_block(struct memory_block **memory, 656static int init_memory_block(struct memory_block **memory,
655 struct mem_section *section, unsigned long state) 657 unsigned long block_id, unsigned long state)
656{ 658{
657 struct memory_block *mem; 659 struct memory_block *mem;
658 unsigned long start_pfn; 660 unsigned long start_pfn;
659 int scn_nr;
660 int ret = 0; 661 int ret = 0;
661 662
663 mem = find_memory_block_by_id(block_id);
664 if (mem) {
665 put_device(&mem->dev);
666 return -EEXIST;
667 }
662 mem = kzalloc(sizeof(*mem), GFP_KERNEL); 668 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
663 if (!mem) 669 if (!mem)
664 return -ENOMEM; 670 return -ENOMEM;
665 671
666 scn_nr = __section_nr(section); 672 mem->start_section_nr = block_id * sections_per_block;
667 mem->start_section_nr =
668 base_memory_block_id(scn_nr) * sections_per_block;
669 mem->end_section_nr = mem->start_section_nr + sections_per_block - 1; 673 mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
670 mem->state = state; 674 mem->state = state;
671 start_pfn = section_nr_to_pfn(mem->start_section_nr); 675 start_pfn = section_nr_to_pfn(mem->start_section_nr);
@@ -677,97 +681,101 @@ static int init_memory_block(struct memory_block **memory,
677 return ret; 681 return ret;
678} 682}
679 683
680static int add_memory_block(int base_section_nr) 684static int add_memory_block(unsigned long base_section_nr)
681{ 685{
686 int ret, section_count = 0;
682 struct memory_block *mem; 687 struct memory_block *mem;
683 int i, ret, section_count = 0, section_nr; 688 unsigned long nr;
684 689
685 for (i = base_section_nr; 690 for (nr = base_section_nr; nr < base_section_nr + sections_per_block;
686 i < base_section_nr + sections_per_block; 691 nr++)
687 i++) { 692 if (present_section_nr(nr))
688 if (!present_section_nr(i)) 693 section_count++;
689 continue;
690 if (section_count == 0)
691 section_nr = i;
692 section_count++;
693 }
694 694
695 if (section_count == 0) 695 if (section_count == 0)
696 return 0; 696 return 0;
697 ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE); 697 ret = init_memory_block(&mem, base_memory_block_id(base_section_nr),
698 MEM_ONLINE);
698 if (ret) 699 if (ret)
699 return ret; 700 return ret;
700 mem->section_count = section_count; 701 mem->section_count = section_count;
701 return 0; 702 return 0;
702} 703}
703 704
705static void unregister_memory(struct memory_block *memory)
706{
707 if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys))
708 return;
709
710 /* drop the ref. we got via find_memory_block() */
711 put_device(&memory->dev);
712 device_unregister(&memory->dev);
713}
714
704/* 715/*
705 * need an interface for the VM to add new memory regions, 716 * Create memory block devices for the given memory area. Start and size
706 * but without onlining it. 717 * have to be aligned to memory block granularity. Memory block devices
718 * will be initialized as offline.
707 */ 719 */
708int hotplug_memory_register(int nid, struct mem_section *section) 720int create_memory_block_devices(unsigned long start, unsigned long size)
709{ 721{
710 int ret = 0; 722 const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start));
723 unsigned long end_block_id = pfn_to_block_id(PFN_DOWN(start + size));
711 struct memory_block *mem; 724 struct memory_block *mem;
725 unsigned long block_id;
726 int ret = 0;
712 727
713 mutex_lock(&mem_sysfs_mutex); 728 if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) ||
729 !IS_ALIGNED(size, memory_block_size_bytes())))
730 return -EINVAL;
714 731
715 mem = find_memory_block(section); 732 mutex_lock(&mem_sysfs_mutex);
716 if (mem) { 733 for (block_id = start_block_id; block_id != end_block_id; block_id++) {
717 mem->section_count++; 734 ret = init_memory_block(&mem, block_id, MEM_OFFLINE);
718 put_device(&mem->dev);
719 } else {
720 ret = init_memory_block(&mem, section, MEM_OFFLINE);
721 if (ret) 735 if (ret)
722 goto out; 736 break;
723 mem->section_count++; 737 mem->section_count = sections_per_block;
738 }
739 if (ret) {
740 end_block_id = block_id;
741 for (block_id = start_block_id; block_id != end_block_id;
742 block_id++) {
743 mem = find_memory_block_by_id(block_id);
744 mem->section_count = 0;
745 unregister_memory(mem);
746 }
724 } 747 }
725
726out:
727 mutex_unlock(&mem_sysfs_mutex); 748 mutex_unlock(&mem_sysfs_mutex);
728 return ret; 749 return ret;
729} 750}
730 751
731#ifdef CONFIG_MEMORY_HOTREMOVE 752/*
732static void 753 * Remove memory block devices for the given memory area. Start and size
733unregister_memory(struct memory_block *memory) 754 * have to be aligned to memory block granularity. Memory block devices
734{ 755 * have to be offline.
735 BUG_ON(memory->dev.bus != &memory_subsys); 756 */
736 757void remove_memory_block_devices(unsigned long start, unsigned long size)
737 /* drop the ref. we got via find_memory_block() */
738 put_device(&memory->dev);
739 device_unregister(&memory->dev);
740}
741
742void unregister_memory_section(struct mem_section *section)
743{ 758{
759 const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start));
760 const unsigned long end_block_id = pfn_to_block_id(PFN_DOWN(start + size));
744 struct memory_block *mem; 761 struct memory_block *mem;
762 unsigned long block_id;
745 763
746 if (WARN_ON_ONCE(!present_section(section))) 764 if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) ||
765 !IS_ALIGNED(size, memory_block_size_bytes())))
747 return; 766 return;
748 767
749 mutex_lock(&mem_sysfs_mutex); 768 mutex_lock(&mem_sysfs_mutex);
750 769 for (block_id = start_block_id; block_id != end_block_id; block_id++) {
751 /* 770 mem = find_memory_block_by_id(block_id);
752 * Some users of the memory hotplug do not want/need memblock to 771 if (WARN_ON_ONCE(!mem))
753 * track all sections. Skip over those. 772 continue;
754 */ 773 mem->section_count = 0;
755 mem = find_memory_block(section); 774 unregister_memory_block_under_nodes(mem);
756 if (!mem)
757 goto out_unlock;
758
759 unregister_mem_sect_under_nodes(mem, __section_nr(section));
760
761 mem->section_count--;
762 if (mem->section_count == 0)
763 unregister_memory(mem); 775 unregister_memory(mem);
764 else 776 }
765 put_device(&mem->dev);
766
767out_unlock:
768 mutex_unlock(&mem_sysfs_mutex); 777 mutex_unlock(&mem_sysfs_mutex);
769} 778}
770#endif /* CONFIG_MEMORY_HOTREMOVE */
771 779
772/* return true if the memory block is offlined, otherwise, return false */ 780/* return true if the memory block is offlined, otherwise, return false */
773bool is_memblock_offlined(struct memory_block *mem) 781bool is_memblock_offlined(struct memory_block *mem)
@@ -804,10 +812,9 @@ static const struct attribute_group *memory_root_attr_groups[] = {
804 */ 812 */
805int __init memory_dev_init(void) 813int __init memory_dev_init(void)
806{ 814{
807 unsigned int i;
808 int ret; 815 int ret;
809 int err; 816 int err;
810 unsigned long block_sz; 817 unsigned long block_sz, nr;
811 818
812 ret = subsys_system_register(&memory_subsys, memory_root_attr_groups); 819 ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
813 if (ret) 820 if (ret)
@@ -821,9 +828,9 @@ int __init memory_dev_init(void)
821 * during boot and have been initialized 828 * during boot and have been initialized
822 */ 829 */
823 mutex_lock(&mem_sysfs_mutex); 830 mutex_lock(&mem_sysfs_mutex);
824 for (i = 0; i <= __highest_present_section_nr; 831 for (nr = 0; nr <= __highest_present_section_nr;
825 i += sections_per_block) { 832 nr += sections_per_block) {
826 err = add_memory_block(i); 833 err = add_memory_block(nr);
827 if (!ret) 834 if (!ret)
828 ret = err; 835 ret = err;
829 } 836 }
@@ -834,3 +841,43 @@ out:
834 printk(KERN_ERR "%s() failed: %d\n", __func__, ret); 841 printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
835 return ret; 842 return ret;
836} 843}
844
845/**
846 * walk_memory_blocks - walk through all present memory blocks overlapped
847 * by the range [start, start + size)
848 *
849 * @start: start address of the memory range
850 * @size: size of the memory range
851 * @arg: argument passed to func
852 * @func: callback for each memory section walked
853 *
854 * This function walks through all present memory blocks overlapped by the
855 * range [start, start + size), calling func on each memory block.
856 *
857 * In case func() returns an error, walking is aborted and the error is
858 * returned.
859 */
860int walk_memory_blocks(unsigned long start, unsigned long size,
861 void *arg, walk_memory_blocks_func_t func)
862{
863 const unsigned long start_block_id = phys_to_block_id(start);
864 const unsigned long end_block_id = phys_to_block_id(start + size - 1);
865 struct memory_block *mem;
866 unsigned long block_id;
867 int ret = 0;
868
869 if (!size)
870 return 0;
871
872 for (block_id = start_block_id; block_id <= end_block_id; block_id++) {
873 mem = find_memory_block_by_id(block_id);
874 if (!mem)
875 continue;
876
877 ret = func(mem, arg);
878 put_device(&mem->dev);
879 if (ret)
880 break;
881 }
882 return ret;
883}
diff --git a/drivers/base/node.c b/drivers/base/node.c
index aa878fbcf705..75b7e6f6535b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -753,7 +753,8 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
753} 753}
754 754
755/* register memory section under specified node if it spans that node */ 755/* register memory section under specified node if it spans that node */
756int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) 756static int register_mem_sect_under_node(struct memory_block *mem_blk,
757 void *arg)
757{ 758{
758 int ret, nid = *(int *)arg; 759 int ret, nid = *(int *)arg;
759 unsigned long pfn, sect_start_pfn, sect_end_pfn; 760 unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -802,23 +803,18 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
802 return 0; 803 return 0;
803} 804}
804 805
805/* unregister memory section under all nodes that it spans */ 806/*
806int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 807 * Unregister memory block device under all nodes that it spans.
807 unsigned long phys_index) 808 * Has to be called with mem_sysfs_mutex held (due to unlinked_nodes).
809 */
810void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
808{ 811{
809 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
810 unsigned long pfn, sect_start_pfn, sect_end_pfn; 812 unsigned long pfn, sect_start_pfn, sect_end_pfn;
813 static nodemask_t unlinked_nodes;
811 814
812 if (!mem_blk) { 815 nodes_clear(unlinked_nodes);
813 NODEMASK_FREE(unlinked_nodes); 816 sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
814 return -EFAULT; 817 sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
815 }
816 if (!unlinked_nodes)
817 return -ENOMEM;
818 nodes_clear(*unlinked_nodes);
819
820 sect_start_pfn = section_nr_to_pfn(phys_index);
821 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
822 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 818 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
823 int nid; 819 int nid;
824 820
@@ -827,21 +823,20 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
827 continue; 823 continue;
828 if (!node_online(nid)) 824 if (!node_online(nid))
829 continue; 825 continue;
830 if (node_test_and_set(nid, *unlinked_nodes)) 826 if (node_test_and_set(nid, unlinked_nodes))
831 continue; 827 continue;
832 sysfs_remove_link(&node_devices[nid]->dev.kobj, 828 sysfs_remove_link(&node_devices[nid]->dev.kobj,
833 kobject_name(&mem_blk->dev.kobj)); 829 kobject_name(&mem_blk->dev.kobj));
834 sysfs_remove_link(&mem_blk->dev.kobj, 830 sysfs_remove_link(&mem_blk->dev.kobj,
835 kobject_name(&node_devices[nid]->dev.kobj)); 831 kobject_name(&node_devices[nid]->dev.kobj));
836 } 832 }
837 NODEMASK_FREE(unlinked_nodes);
838 return 0;
839} 833}
840 834
841int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) 835int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
842{ 836{
843 return walk_memory_range(start_pfn, end_pfn, (void *)&nid, 837 return walk_memory_blocks(PFN_PHYS(start_pfn),
844 register_mem_sect_under_node); 838 PFN_PHYS(end_pfn - start_pfn), (void *)&nid,
839 register_mem_sect_under_node);
845} 840}
846 841
847#ifdef CONFIG_HUGETLBFS 842#ifdef CONFIG_HUGETLBFS
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 3d8162d28730..a700c5c3d167 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -274,8 +274,6 @@
274#define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY) 274#define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY)
275 275
276/* for sysctl proc_dointvec_minmax of dev.i915.perf_stream_paranoid */ 276/* for sysctl proc_dointvec_minmax of dev.i915.perf_stream_paranoid */
277static int zero;
278static int one = 1;
279static u32 i915_perf_stream_paranoid = true; 277static u32 i915_perf_stream_paranoid = true;
280 278
281/* The maximum exponent the hardware accepts is 63 (essentially it selects one 279/* The maximum exponent the hardware accepts is 63 (essentially it selects one
@@ -3366,8 +3364,8 @@ static struct ctl_table oa_table[] = {
3366 .maxlen = sizeof(i915_perf_stream_paranoid), 3364 .maxlen = sizeof(i915_perf_stream_paranoid),
3367 .mode = 0644, 3365 .mode = 0644,
3368 .proc_handler = proc_dointvec_minmax, 3366 .proc_handler = proc_dointvec_minmax,
3369 .extra1 = &zero, 3367 .extra1 = SYSCTL_ZERO,
3370 .extra2 = &one, 3368 .extra2 = SYSCTL_ONE,
3371 }, 3369 },
3372 { 3370 {
3373 .procname = "oa_max_sample_rate", 3371 .procname = "oa_max_sample_rate",
@@ -3375,7 +3373,7 @@ static struct ctl_table oa_table[] = {
3375 .maxlen = sizeof(i915_oa_max_sample_rate), 3373 .maxlen = sizeof(i915_oa_max_sample_rate),
3376 .mode = 0644, 3374 .mode = 0644,
3377 .proc_handler = proc_dointvec_minmax, 3375 .proc_handler = proc_dointvec_minmax,
3378 .extra1 = &zero, 3376 .extra1 = SYSCTL_ZERO,
3379 .extra2 = &oa_sample_rate_hard_limit, 3377 .extra2 = &oa_sample_rate_hard_limit,
3380 }, 3378 },
3381 {} 3379 {}
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 894da5abdc55..ebd35fc35290 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1197,8 +1197,6 @@ static struct kmsg_dumper hv_kmsg_dumper = {
1197}; 1197};
1198 1198
1199static struct ctl_table_header *hv_ctl_table_hdr; 1199static struct ctl_table_header *hv_ctl_table_hdr;
1200static int zero;
1201static int one = 1;
1202 1200
1203/* 1201/*
1204 * sysctl option to allow the user to control whether kmsg data should be 1202 * sysctl option to allow the user to control whether kmsg data should be
@@ -1211,8 +1209,8 @@ static struct ctl_table hv_ctl_table[] = {
1211 .maxlen = sizeof(int), 1209 .maxlen = sizeof(int),
1212 .mode = 0644, 1210 .mode = 0644,
1213 .proc_handler = proc_dointvec_minmax, 1211 .proc_handler = proc_dointvec_minmax,
1214 .extra1 = &zero, 1212 .extra1 = SYSCTL_ZERO,
1215 .extra2 = &one 1213 .extra2 = SYSCTL_ONE
1216 }, 1214 },
1217 {} 1215 {}
1218}; 1216};
diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
index 49fc18ee0565..6d22b0f83b3b 100644
--- a/drivers/nvdimm/dax_devs.c
+++ b/drivers/nvdimm/dax_devs.c
@@ -118,7 +118,7 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
118 nvdimm_bus_unlock(&ndns->dev); 118 nvdimm_bus_unlock(&ndns->dev);
119 if (!dax_dev) 119 if (!dax_dev)
120 return -ENOMEM; 120 return -ENOMEM;
121 pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); 121 pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
122 nd_pfn->pfn_sb = pfn_sb; 122 nd_pfn->pfn_sb = pfn_sb;
123 rc = nd_pfn_validate(nd_pfn, DAX_SIG); 123 rc = nd_pfn_validate(nd_pfn, DAX_SIG);
124 dev_dbg(dev, "dax: %s\n", rc == 0 ? dev_name(dax_dev) : "<none>"); 124 dev_dbg(dev, "dax: %s\n", rc == 0 ? dev_name(dax_dev) : "<none>");
diff --git a/drivers/nvdimm/pfn.h b/drivers/nvdimm/pfn.h
index f58b849e455b..7381673b7b70 100644
--- a/drivers/nvdimm/pfn.h
+++ b/drivers/nvdimm/pfn.h
@@ -28,22 +28,9 @@ struct nd_pfn_sb {
28 __le32 end_trunc; 28 __le32 end_trunc;
29 /* minor-version-2 record the base alignment of the mapping */ 29 /* minor-version-2 record the base alignment of the mapping */
30 __le32 align; 30 __le32 align;
31 /* minor-version-3 guarantee the padding and flags are zero */
31 u8 padding[4000]; 32 u8 padding[4000];
32 __le64 checksum; 33 __le64 checksum;
33}; 34};
34 35
35#ifdef CONFIG_SPARSEMEM
36#define PFN_SECTION_ALIGN_DOWN(x) SECTION_ALIGN_DOWN(x)
37#define PFN_SECTION_ALIGN_UP(x) SECTION_ALIGN_UP(x)
38#else
39/*
40 * In this case ZONE_DEVICE=n and we will disable 'pfn' device support,
41 * but we still want pmem to compile.
42 */
43#define PFN_SECTION_ALIGN_DOWN(x) (x)
44#define PFN_SECTION_ALIGN_UP(x) (x)
45#endif
46
47#define PHYS_SECTION_ALIGN_DOWN(x) PFN_PHYS(PFN_SECTION_ALIGN_DOWN(PHYS_PFN(x)))
48#define PHYS_SECTION_ALIGN_UP(x) PFN_PHYS(PFN_SECTION_ALIGN_UP(PHYS_PFN(x)))
49#endif /* __NVDIMM_PFN_H */ 36#endif /* __NVDIMM_PFN_H */
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index 55fb6b7433ed..df2bdbd22450 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -412,6 +412,15 @@ static int nd_pfn_clear_memmap_errors(struct nd_pfn *nd_pfn)
412 return 0; 412 return 0;
413} 413}
414 414
415/**
416 * nd_pfn_validate - read and validate info-block
417 * @nd_pfn: fsdax namespace runtime state / properties
418 * @sig: 'devdax' or 'fsdax' signature
419 *
420 * Upon return the info-block buffer contents (->pfn_sb) are
421 * indeterminate when validation fails, and a coherent info-block
422 * otherwise.
423 */
415int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) 424int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
416{ 425{
417 u64 checksum, offset; 426 u64 checksum, offset;
@@ -557,7 +566,7 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns)
557 nvdimm_bus_unlock(&ndns->dev); 566 nvdimm_bus_unlock(&ndns->dev);
558 if (!pfn_dev) 567 if (!pfn_dev)
559 return -ENOMEM; 568 return -ENOMEM;
560 pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); 569 pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
561 nd_pfn = to_nd_pfn(pfn_dev); 570 nd_pfn = to_nd_pfn(pfn_dev);
562 nd_pfn->pfn_sb = pfn_sb; 571 nd_pfn->pfn_sb = pfn_sb;
563 rc = nd_pfn_validate(nd_pfn, PFN_SIG); 572 rc = nd_pfn_validate(nd_pfn, PFN_SIG);
@@ -578,14 +587,14 @@ static u32 info_block_reserve(void)
578} 587}
579 588
580/* 589/*
581 * We hotplug memory at section granularity, pad the reserved area from 590 * We hotplug memory at sub-section granularity, pad the reserved area
582 * the previous section base to the namespace base address. 591 * from the previous section base to the namespace base address.
583 */ 592 */
584static unsigned long init_altmap_base(resource_size_t base) 593static unsigned long init_altmap_base(resource_size_t base)
585{ 594{
586 unsigned long base_pfn = PHYS_PFN(base); 595 unsigned long base_pfn = PHYS_PFN(base);
587 596
588 return PFN_SECTION_ALIGN_DOWN(base_pfn); 597 return SUBSECTION_ALIGN_DOWN(base_pfn);
589} 598}
590 599
591static unsigned long init_altmap_reserve(resource_size_t base) 600static unsigned long init_altmap_reserve(resource_size_t base)
@@ -593,7 +602,7 @@ static unsigned long init_altmap_reserve(resource_size_t base)
593 unsigned long reserve = info_block_reserve() >> PAGE_SHIFT; 602 unsigned long reserve = info_block_reserve() >> PAGE_SHIFT;
594 unsigned long base_pfn = PHYS_PFN(base); 603 unsigned long base_pfn = PHYS_PFN(base);
595 604
596 reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn); 605 reserve += base_pfn - SUBSECTION_ALIGN_DOWN(base_pfn);
597 return reserve; 606 return reserve;
598} 607}
599 608
@@ -623,8 +632,7 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap)
623 return -EINVAL; 632 return -EINVAL;
624 nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns); 633 nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns);
625 } else if (nd_pfn->mode == PFN_MODE_PMEM) { 634 } else if (nd_pfn->mode == PFN_MODE_PMEM) {
626 nd_pfn->npfns = PFN_SECTION_ALIGN_UP((resource_size(res) 635 nd_pfn->npfns = PHYS_PFN((resource_size(res) - offset));
627 - offset) / PAGE_SIZE);
628 if (le64_to_cpu(nd_pfn->pfn_sb->npfns) > nd_pfn->npfns) 636 if (le64_to_cpu(nd_pfn->pfn_sb->npfns) > nd_pfn->npfns)
629 dev_info(&nd_pfn->dev, 637 dev_info(&nd_pfn->dev,
630 "number of pfns truncated from %lld to %ld\n", 638 "number of pfns truncated from %lld to %ld\n",
@@ -640,60 +648,20 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap)
640 return 0; 648 return 0;
641} 649}
642 650
643static u64 phys_pmem_align_down(struct nd_pfn *nd_pfn, u64 phys)
644{
645 return min_t(u64, PHYS_SECTION_ALIGN_DOWN(phys),
646 ALIGN_DOWN(phys, nd_pfn->align));
647}
648
649/*
650 * Check if pmem collides with 'System RAM', or other regions when
651 * section aligned. Trim it accordingly.
652 */
653static void trim_pfn_device(struct nd_pfn *nd_pfn, u32 *start_pad, u32 *end_trunc)
654{
655 struct nd_namespace_common *ndns = nd_pfn->ndns;
656 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
657 struct nd_region *nd_region = to_nd_region(nd_pfn->dev.parent);
658 const resource_size_t start = nsio->res.start;
659 const resource_size_t end = start + resource_size(&nsio->res);
660 resource_size_t adjust, size;
661
662 *start_pad = 0;
663 *end_trunc = 0;
664
665 adjust = start - PHYS_SECTION_ALIGN_DOWN(start);
666 size = resource_size(&nsio->res) + adjust;
667 if (region_intersects(start - adjust, size, IORESOURCE_SYSTEM_RAM,
668 IORES_DESC_NONE) == REGION_MIXED
669 || nd_region_conflict(nd_region, start - adjust, size))
670 *start_pad = PHYS_SECTION_ALIGN_UP(start) - start;
671
672 /* Now check that end of the range does not collide. */
673 adjust = PHYS_SECTION_ALIGN_UP(end) - end;
674 size = resource_size(&nsio->res) + adjust;
675 if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM,
676 IORES_DESC_NONE) == REGION_MIXED
677 || !IS_ALIGNED(end, nd_pfn->align)
678 || nd_region_conflict(nd_region, start, size))
679 *end_trunc = end - phys_pmem_align_down(nd_pfn, end);
680}
681
682static int nd_pfn_init(struct nd_pfn *nd_pfn) 651static int nd_pfn_init(struct nd_pfn *nd_pfn)
683{ 652{
684 struct nd_namespace_common *ndns = nd_pfn->ndns; 653 struct nd_namespace_common *ndns = nd_pfn->ndns;
685 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev); 654 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
686 u32 start_pad, end_trunc, reserve = info_block_reserve();
687 resource_size_t start, size; 655 resource_size_t start, size;
688 struct nd_region *nd_region; 656 struct nd_region *nd_region;
657 unsigned long npfns, align;
689 struct nd_pfn_sb *pfn_sb; 658 struct nd_pfn_sb *pfn_sb;
690 unsigned long npfns;
691 phys_addr_t offset; 659 phys_addr_t offset;
692 const char *sig; 660 const char *sig;
693 u64 checksum; 661 u64 checksum;
694 int rc; 662 int rc;
695 663
696 pfn_sb = devm_kzalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL); 664 pfn_sb = devm_kmalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL);
697 if (!pfn_sb) 665 if (!pfn_sb)
698 return -ENOMEM; 666 return -ENOMEM;
699 667
@@ -702,11 +670,14 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
702 sig = DAX_SIG; 670 sig = DAX_SIG;
703 else 671 else
704 sig = PFN_SIG; 672 sig = PFN_SIG;
673
705 rc = nd_pfn_validate(nd_pfn, sig); 674 rc = nd_pfn_validate(nd_pfn, sig);
706 if (rc != -ENODEV) 675 if (rc != -ENODEV)
707 return rc; 676 return rc;
708 677
709 /* no info block, do init */; 678 /* no info block, do init */;
679 memset(pfn_sb, 0, sizeof(*pfn_sb));
680
710 nd_region = to_nd_region(nd_pfn->dev.parent); 681 nd_region = to_nd_region(nd_pfn->dev.parent);
711 if (nd_region->ro) { 682 if (nd_region->ro) {
712 dev_info(&nd_pfn->dev, 683 dev_info(&nd_pfn->dev,
@@ -715,43 +686,35 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
715 return -ENXIO; 686 return -ENXIO;
716 } 687 }
717 688
718 memset(pfn_sb, 0, sizeof(*pfn_sb));
719
720 trim_pfn_device(nd_pfn, &start_pad, &end_trunc);
721 if (start_pad + end_trunc)
722 dev_info(&nd_pfn->dev, "%s alignment collision, truncate %d bytes\n",
723 dev_name(&ndns->dev), start_pad + end_trunc);
724
725 /* 689 /*
726 * Note, we use 64 here for the standard size of struct page, 690 * Note, we use 64 here for the standard size of struct page,
727 * debugging options may cause it to be larger in which case the 691 * debugging options may cause it to be larger in which case the
728 * implementation will limit the pfns advertised through 692 * implementation will limit the pfns advertised through
729 * ->direct_access() to those that are included in the memmap. 693 * ->direct_access() to those that are included in the memmap.
730 */ 694 */
731 start = nsio->res.start + start_pad; 695 start = nsio->res.start;
732 size = resource_size(&nsio->res); 696 size = resource_size(&nsio->res);
733 npfns = PFN_SECTION_ALIGN_UP((size - start_pad - end_trunc - reserve) 697 npfns = PHYS_PFN(size - SZ_8K);
734 / PAGE_SIZE); 698 align = max(nd_pfn->align, (1UL << SUBSECTION_SHIFT));
735 if (nd_pfn->mode == PFN_MODE_PMEM) { 699 if (nd_pfn->mode == PFN_MODE_PMEM) {
736 /* 700 /*
737 * The altmap should be padded out to the block size used 701 * The altmap should be padded out to the block size used
738 * when populating the vmemmap. This *should* be equal to 702 * when populating the vmemmap. This *should* be equal to
739 * PMD_SIZE for most architectures. 703 * PMD_SIZE for most architectures.
740 */ 704 */
741 offset = ALIGN(start + reserve + 64 * npfns, 705 offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
742 max(nd_pfn->align, PMD_SIZE)) - start;
743 } else if (nd_pfn->mode == PFN_MODE_RAM) 706 } else if (nd_pfn->mode == PFN_MODE_RAM)
744 offset = ALIGN(start + reserve, nd_pfn->align) - start; 707 offset = ALIGN(start + SZ_8K, align) - start;
745 else 708 else
746 return -ENXIO; 709 return -ENXIO;
747 710
748 if (offset + start_pad + end_trunc >= size) { 711 if (offset >= size) {
749 dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n", 712 dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n",
750 dev_name(&ndns->dev)); 713 dev_name(&ndns->dev));
751 return -ENXIO; 714 return -ENXIO;
752 } 715 }
753 716
754 npfns = (size - offset - start_pad - end_trunc) / SZ_4K; 717 npfns = PHYS_PFN(size - offset);
755 pfn_sb->mode = cpu_to_le32(nd_pfn->mode); 718 pfn_sb->mode = cpu_to_le32(nd_pfn->mode);
756 pfn_sb->dataoff = cpu_to_le64(offset); 719 pfn_sb->dataoff = cpu_to_le64(offset);
757 pfn_sb->npfns = cpu_to_le64(npfns); 720 pfn_sb->npfns = cpu_to_le64(npfns);
@@ -759,9 +722,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
759 memcpy(pfn_sb->uuid, nd_pfn->uuid, 16); 722 memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
760 memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16); 723 memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
761 pfn_sb->version_major = cpu_to_le16(1); 724 pfn_sb->version_major = cpu_to_le16(1);
762 pfn_sb->version_minor = cpu_to_le16(2); 725 pfn_sb->version_minor = cpu_to_le16(3);
763 pfn_sb->start_pad = cpu_to_le32(start_pad);
764 pfn_sb->end_trunc = cpu_to_le32(end_trunc);
765 pfn_sb->align = cpu_to_le32(nd_pfn->align); 726 pfn_sb->align = cpu_to_le32(nd_pfn->align);
766 checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb); 727 checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
767 pfn_sb->checksum = cpu_to_le64(checksum); 728 pfn_sb->checksum = cpu_to_le64(checksum);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index fde8d4073e74..4c49f53afa3e 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -855,8 +855,6 @@ void tty_ldisc_deinit(struct tty_struct *tty)
855 tty->ldisc = NULL; 855 tty->ldisc = NULL;
856} 856}
857 857
858static int zero;
859static int one = 1;
860static struct ctl_table tty_table[] = { 858static struct ctl_table tty_table[] = {
861 { 859 {
862 .procname = "ldisc_autoload", 860 .procname = "ldisc_autoload",
@@ -864,8 +862,8 @@ static struct ctl_table tty_table[] = {
864 .maxlen = sizeof(tty_ldisc_autoload), 862 .maxlen = sizeof(tty_ldisc_autoload),
865 .mode = 0644, 863 .mode = 0644,
866 .proc_handler = proc_dointvec, 864 .proc_handler = proc_dointvec,
867 .extra1 = &zero, 865 .extra1 = SYSCTL_ZERO,
868 .extra2 = &one, 866 .extra2 = SYSCTL_ONE,
869 }, 867 },
870 { } 868 { }
871}; 869};
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index d37dd5bb7a8f..37a36c6b9f93 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -77,9 +77,6 @@ static int xen_hotplug_unpopulated;
77 77
78#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG 78#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
79 79
80static int zero;
81static int one = 1;
82
83static struct ctl_table balloon_table[] = { 80static struct ctl_table balloon_table[] = {
84 { 81 {
85 .procname = "hotplug_unpopulated", 82 .procname = "hotplug_unpopulated",
@@ -87,8 +84,8 @@ static struct ctl_table balloon_table[] = {
87 .maxlen = sizeof(int), 84 .maxlen = sizeof(int),
88 .mode = 0644, 85 .mode = 0644,
89 .proc_handler = proc_dointvec_minmax, 86 .proc_handler = proc_dointvec_minmax,
90 .extra1 = &zero, 87 .extra1 = SYSCTL_ZERO,
91 .extra2 = &one, 88 .extra2 = SYSCTL_ONE,
92 }, 89 },
93 { } 90 { }
94}; 91};
diff --git a/fs/aio.c b/fs/aio.c
index 8327db0c8e08..8b3aa2739906 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -425,7 +425,7 @@ static int aio_migratepage(struct address_space *mapping, struct page *new,
425 BUG_ON(PageWriteback(old)); 425 BUG_ON(PageWriteback(old));
426 get_page(new); 426 get_page(new);
427 427
428 rc = migrate_page_move_mapping(mapping, new, old, mode, 1); 428 rc = migrate_page_move_mapping(mapping, new, old, 1);
429 if (rc != MIGRATEPAGE_SUCCESS) { 429 if (rc != MIGRATEPAGE_SUCCESS) {
430 put_page(new); 430 put_page(new);
431 goto out_unlock; 431 goto out_unlock;
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 0f9c073d78d5..d7f1f5011fac 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -291,7 +291,7 @@ static LIST_HEAD(tfile_check_list);
291 291
292#include <linux/sysctl.h> 292#include <linux/sysctl.h>
293 293
294static long zero; 294static long long_zero;
295static long long_max = LONG_MAX; 295static long long_max = LONG_MAX;
296 296
297struct ctl_table epoll_table[] = { 297struct ctl_table epoll_table[] = {
@@ -301,7 +301,7 @@ struct ctl_table epoll_table[] = {
301 .maxlen = sizeof(max_user_watches), 301 .maxlen = sizeof(max_user_watches),
302 .mode = 0644, 302 .mode = 0644,
303 .proc_handler = proc_doulongvec_minmax, 303 .proc_handler = proc_doulongvec_minmax,
304 .extra1 = &zero, 304 .extra1 = &long_zero,
305 .extra2 = &long_max, 305 .extra2 = &long_max,
306 }, 306 },
307 { } 307 { }
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 4eb2f3920140..abbf14e9bd72 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2919,7 +2919,7 @@ int f2fs_migrate_page(struct address_space *mapping,
2919 /* one extra reference was held for atomic_write page */ 2919 /* one extra reference was held for atomic_write page */
2920 extra_count = atomic_written ? 1 : 0; 2920 extra_count = atomic_written ? 1 : 0;
2921 rc = migrate_page_move_mapping(mapping, newpage, 2921 rc = migrate_page_move_mapping(mapping, newpage,
2922 page, mode, extra_count); 2922 page, extra_count);
2923 if (rc != MIGRATEPAGE_SUCCESS) { 2923 if (rc != MIGRATEPAGE_SUCCESS) {
2924 if (atomic_written) 2924 if (atomic_written)
2925 mutex_unlock(&fi->inmem_lock); 2925 mutex_unlock(&fi->inmem_lock);
diff --git a/fs/iomap.c b/fs/iomap.c
index 217c3e5a13d6..3e7f16a05653 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -566,7 +566,7 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,
566{ 566{
567 int ret; 567 int ret;
568 568
569 ret = migrate_page_move_mapping(mapping, newpage, page, mode, 0); 569 ret = migrate_page_move_mapping(mapping, newpage, page, 0);
570 if (ret != MIGRATEPAGE_SUCCESS) 570 if (ret != MIGRATEPAGE_SUCCESS)
571 return ret; 571 return ret;
572 572
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index cce8de32779f..0b815178126e 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -45,8 +45,6 @@ struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
45 45
46#include <linux/sysctl.h> 46#include <linux/sysctl.h>
47 47
48static int zero;
49
50struct ctl_table inotify_table[] = { 48struct ctl_table inotify_table[] = {
51 { 49 {
52 .procname = "max_user_instances", 50 .procname = "max_user_instances",
@@ -54,7 +52,7 @@ struct ctl_table inotify_table[] = {
54 .maxlen = sizeof(int), 52 .maxlen = sizeof(int),
55 .mode = 0644, 53 .mode = 0644,
56 .proc_handler = proc_dointvec_minmax, 54 .proc_handler = proc_dointvec_minmax,
57 .extra1 = &zero, 55 .extra1 = SYSCTL_ZERO,
58 }, 56 },
59 { 57 {
60 .procname = "max_user_watches", 58 .procname = "max_user_watches",
@@ -62,7 +60,7 @@ struct ctl_table inotify_table[] = {
62 .maxlen = sizeof(int), 60 .maxlen = sizeof(int),
63 .mode = 0644, 61 .mode = 0644,
64 .proc_handler = proc_dointvec_minmax, 62 .proc_handler = proc_dointvec_minmax,
65 .extra1 = &zero, 63 .extra1 = SYSCTL_ZERO,
66 }, 64 },
67 { 65 {
68 .procname = "max_queued_events", 66 .procname = "max_queued_events",
@@ -70,7 +68,7 @@ struct ctl_table inotify_table[] = {
70 .maxlen = sizeof(int), 68 .maxlen = sizeof(int),
71 .mode = 0644, 69 .mode = 0644,
72 .proc_handler = proc_dointvec_minmax, 70 .proc_handler = proc_dointvec_minmax,
73 .extra1 = &zero 71 .extra1 = SYSCTL_ZERO
74 }, 72 },
75 { } 73 { }
76}; 74};
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 36ad1b0d6259..d80989b6c344 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -22,6 +22,10 @@ static const struct inode_operations proc_sys_inode_operations;
22static const struct file_operations proc_sys_dir_file_operations; 22static const struct file_operations proc_sys_dir_file_operations;
23static const struct inode_operations proc_sys_dir_operations; 23static const struct inode_operations proc_sys_dir_operations;
24 24
25/* shared constants to be used in various sysctls */
26const int sysctl_vals[] = { 0, 1, INT_MAX };
27EXPORT_SYMBOL(sysctl_vals);
28
25/* Support for permanently empty directories */ 29/* Support for permanently empty directories */
26 30
27struct ctl_table sysctl_mount_point[] = { 31struct ctl_table sysctl_mount_point[] = {
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 818cedbed95f..731642e0f5a0 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -832,7 +832,8 @@ static int show_smap(struct seq_file *m, void *v)
832 832
833 __show_smap(m, &mss, false); 833 __show_smap(m, &mss, false);
834 834
835 seq_printf(m, "THPeligible: %d\n", transparent_hugepage_enabled(vma)); 835 seq_printf(m, "THPeligible: %d\n",
836 transparent_hugepage_enabled(vma));
836 837
837 if (arch_pkeys_enabled()) 838 if (arch_pkeys_enabled())
838 seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); 839 seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index e5f8de62fc51..400970d740bb 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1470,7 +1470,7 @@ static int ubifs_migrate_page(struct address_space *mapping,
1470{ 1470{
1471 int rc; 1471 int rc;
1472 1472
1473 rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); 1473 rc = migrate_page_move_mapping(mapping, newpage, page, 0);
1474 if (rc != MIGRATEPAGE_SUCCESS) 1474 if (rc != MIGRATEPAGE_SUCCESS)
1475 return rc; 1475 return rc;
1476 1476
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c150c21d..45ede62aa85b 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -121,6 +121,23 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
121 121
122bool transparent_hugepage_enabled(struct vm_area_struct *vma); 122bool transparent_hugepage_enabled(struct vm_area_struct *vma);
123 123
124#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1)
125
126static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
127 unsigned long haddr)
128{
129 /* Don't have to check pgoff for anonymous vma */
130 if (!vma_is_anonymous(vma)) {
131 if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) !=
132 (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK))
133 return false;
134 }
135
136 if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end)
137 return false;
138 return true;
139}
140
124#define transparent_hugepage_use_zero_page() \ 141#define transparent_hugepage_use_zero_page() \
125 (transparent_hugepage_flags & \ 142 (transparent_hugepage_flags & \
126 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) 143 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
@@ -271,6 +288,12 @@ static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma)
271 return false; 288 return false;
272} 289}
273 290
291static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
292 unsigned long haddr)
293{
294 return false;
295}
296
274static inline void prep_transhuge_page(struct page *page) {} 297static inline void prep_transhuge_page(struct page *page) {}
275 298
276#define transparent_hugepage_flags 0UL 299#define transparent_hugepage_flags 0UL
diff --git a/include/linux/memory.h b/include/linux/memory.h
index e1dc1bb2b787..02e633f3ede0 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -111,16 +111,15 @@ extern int register_memory_notifier(struct notifier_block *nb);
111extern void unregister_memory_notifier(struct notifier_block *nb); 111extern void unregister_memory_notifier(struct notifier_block *nb);
112extern int register_memory_isolate_notifier(struct notifier_block *nb); 112extern int register_memory_isolate_notifier(struct notifier_block *nb);
113extern void unregister_memory_isolate_notifier(struct notifier_block *nb); 113extern void unregister_memory_isolate_notifier(struct notifier_block *nb);
114int hotplug_memory_register(int nid, struct mem_section *section); 114int create_memory_block_devices(unsigned long start, unsigned long size);
115#ifdef CONFIG_MEMORY_HOTREMOVE 115void remove_memory_block_devices(unsigned long start, unsigned long size);
116extern void unregister_memory_section(struct mem_section *);
117#endif
118extern int memory_dev_init(void); 116extern int memory_dev_init(void);
119extern int memory_notify(unsigned long val, void *v); 117extern int memory_notify(unsigned long val, void *v);
120extern int memory_isolate_notify(unsigned long val, void *v); 118extern int memory_isolate_notify(unsigned long val, void *v);
121extern struct memory_block *find_memory_block_hinted(struct mem_section *,
122 struct memory_block *);
123extern struct memory_block *find_memory_block(struct mem_section *); 119extern struct memory_block *find_memory_block(struct mem_section *);
120typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
121extern int walk_memory_blocks(unsigned long start, unsigned long size,
122 void *arg, walk_memory_blocks_func_t func);
124#define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<<PAGE_SHIFT) 123#define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<<PAGE_SHIFT)
125#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ 124#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
126 125
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 988fde33cd7f..f46ea71b4ffd 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -123,20 +123,10 @@ static inline bool movable_node_is_enabled(void)
123 return movable_node_enabled; 123 return movable_node_enabled;
124} 124}
125 125
126#ifdef CONFIG_MEMORY_HOTREMOVE
127extern void arch_remove_memory(int nid, u64 start, u64 size, 126extern void arch_remove_memory(int nid, u64 start, u64 size,
128 struct vmem_altmap *altmap); 127 struct vmem_altmap *altmap);
129extern void __remove_pages(struct zone *zone, unsigned long start_pfn, 128extern void __remove_pages(struct zone *zone, unsigned long start_pfn,
130 unsigned long nr_pages, struct vmem_altmap *altmap); 129 unsigned long nr_pages, struct vmem_altmap *altmap);
131#endif /* CONFIG_MEMORY_HOTREMOVE */
132
133/*
134 * Do we want sysfs memblock files created. This will allow userspace to online
135 * and offline memory explicitly. Lack of this bit means that the caller has to
136 * call move_pfn_range_to_zone to finish the initialization.
137 */
138
139#define MHP_MEMBLOCK_API (1<<0)
140 130
141/* reasonably generic interface to expand the physical pages */ 131/* reasonably generic interface to expand the physical pages */
142extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, 132extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
@@ -350,17 +340,16 @@ static inline void __remove_memory(int nid, u64 start, u64 size) {}
350#endif /* CONFIG_MEMORY_HOTREMOVE */ 340#endif /* CONFIG_MEMORY_HOTREMOVE */
351 341
352extern void __ref free_area_init_core_hotplug(int nid); 342extern void __ref free_area_init_core_hotplug(int nid);
353extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
354 void *arg, int (*func)(struct memory_block *, void *));
355extern int __add_memory(int nid, u64 start, u64 size); 343extern int __add_memory(int nid, u64 start, u64 size);
356extern int add_memory(int nid, u64 start, u64 size); 344extern int add_memory(int nid, u64 start, u64 size);
357extern int add_memory_resource(int nid, struct resource *resource); 345extern int add_memory_resource(int nid, struct resource *resource);
358extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, 346extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
359 unsigned long nr_pages, struct vmem_altmap *altmap); 347 unsigned long nr_pages, struct vmem_altmap *altmap);
360extern bool is_memblock_offlined(struct memory_block *mem); 348extern bool is_memblock_offlined(struct memory_block *mem);
361extern int sparse_add_one_section(int nid, unsigned long start_pfn, 349extern int sparse_add_section(int nid, unsigned long pfn,
362 struct vmem_altmap *altmap); 350 unsigned long nr_pages, struct vmem_altmap *altmap);
363extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, 351extern void sparse_remove_section(struct mem_section *ms,
352 unsigned long pfn, unsigned long nr_pages,
364 unsigned long map_offset, struct vmem_altmap *altmap); 353 unsigned long map_offset, struct vmem_altmap *altmap);
365extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, 354extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
366 unsigned long pnum); 355 unsigned long pnum);
diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index e13d9bf2f9a5..7f04754c7f2b 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -77,8 +77,7 @@ extern void migrate_page_copy(struct page *newpage, struct page *page);
77extern int migrate_huge_page_move_mapping(struct address_space *mapping, 77extern int migrate_huge_page_move_mapping(struct address_space *mapping,
78 struct page *newpage, struct page *page); 78 struct page *newpage, struct page *page);
79extern int migrate_page_move_mapping(struct address_space *mapping, 79extern int migrate_page_move_mapping(struct address_space *mapping,
80 struct page *newpage, struct page *page, enum migrate_mode mode, 80 struct page *newpage, struct page *page, int extra_count);
81 int extra_count);
82#else 81#else
83 82
84static inline void putback_movable_pages(struct list_head *l) {} 83static inline void putback_movable_pages(struct list_head *l) {}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index bd6512559bed..0334ca97c584 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -541,6 +541,23 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma)
541 vma->vm_ops = NULL; 541 vma->vm_ops = NULL;
542} 542}
543 543
544static inline bool vma_is_anonymous(struct vm_area_struct *vma)
545{
546 return !vma->vm_ops;
547}
548
549#ifdef CONFIG_SHMEM
550/*
551 * The vma_is_shmem is not inline because it is used only by slow
552 * paths in userfault.
553 */
554bool vma_is_shmem(struct vm_area_struct *vma);
555#else
556static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
557#endif
558
559int vma_is_stack_for_current(struct vm_area_struct *vma);
560
544/* flush_tlb_range() takes a vma, not a mm, and can care about flags */ 561/* flush_tlb_range() takes a vma, not a mm, and can care about flags */
545#define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) } 562#define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) }
546 563
@@ -1620,23 +1637,6 @@ int clear_page_dirty_for_io(struct page *page);
1620 1637
1621int get_cmdline(struct task_struct *task, char *buffer, int buflen); 1638int get_cmdline(struct task_struct *task, char *buffer, int buflen);
1622 1639
1623static inline bool vma_is_anonymous(struct vm_area_struct *vma)
1624{
1625 return !vma->vm_ops;
1626}
1627
1628#ifdef CONFIG_SHMEM
1629/*
1630 * The vma_is_shmem is not inline because it is used only by slow
1631 * paths in userfault.
1632 */
1633bool vma_is_shmem(struct vm_area_struct *vma);
1634#else
1635static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
1636#endif
1637
1638int vma_is_stack_for_current(struct vm_area_struct *vma);
1639
1640extern unsigned long move_page_tables(struct vm_area_struct *vma, 1640extern unsigned long move_page_tables(struct vm_area_struct *vma,
1641 unsigned long old_addr, struct vm_area_struct *new_vma, 1641 unsigned long old_addr, struct vm_area_struct *new_vma,
1642 unsigned long new_addr, unsigned long len, 1642 unsigned long new_addr, unsigned long len,
@@ -2767,8 +2767,8 @@ static inline void print_vma_addr(char *prefix, unsigned long rip)
2767#endif 2767#endif
2768 2768
2769void *sparse_buffer_alloc(unsigned long size); 2769void *sparse_buffer_alloc(unsigned long size);
2770struct page *sparse_mem_map_populate(unsigned long pnum, int nid, 2770struct page * __populate_section_memmap(unsigned long pfn,
2771 struct vmem_altmap *altmap); 2771 unsigned long nr_pages, int nid, struct vmem_altmap *altmap);
2772pgd_t *vmemmap_pgd_populate(unsigned long addr, int node); 2772pgd_t *vmemmap_pgd_populate(unsigned long addr, int node);
2773p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node); 2773p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node);
2774pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node); 2774pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node);
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 70394cabaf4e..d77d717c620c 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -855,18 +855,6 @@ static inline int local_memory_node(int node_id) { return node_id; };
855 */ 855 */
856#define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones) 856#define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones)
857 857
858#ifdef CONFIG_ZONE_DEVICE
859static inline bool is_dev_zone(const struct zone *zone)
860{
861 return zone_idx(zone) == ZONE_DEVICE;
862}
863#else
864static inline bool is_dev_zone(const struct zone *zone)
865{
866 return false;
867}
868#endif
869
870/* 858/*
871 * Returns true if a zone has pages managed by the buddy allocator. 859 * Returns true if a zone has pages managed by the buddy allocator.
872 * All the reclaim decisions have to use this function rather than 860 * All the reclaim decisions have to use this function rather than
@@ -1160,6 +1148,29 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec)
1160#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK) 1148#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
1161#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK) 1149#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
1162 1150
1151#define SUBSECTION_SHIFT 21
1152
1153#define PFN_SUBSECTION_SHIFT (SUBSECTION_SHIFT - PAGE_SHIFT)
1154#define PAGES_PER_SUBSECTION (1UL << PFN_SUBSECTION_SHIFT)
1155#define PAGE_SUBSECTION_MASK (~(PAGES_PER_SUBSECTION-1))
1156
1157#if SUBSECTION_SHIFT > SECTION_SIZE_BITS
1158#error Subsection size exceeds section size
1159#else
1160#define SUBSECTIONS_PER_SECTION (1UL << (SECTION_SIZE_BITS - SUBSECTION_SHIFT))
1161#endif
1162
1163#define SUBSECTION_ALIGN_UP(pfn) ALIGN((pfn), PAGES_PER_SUBSECTION)
1164#define SUBSECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SUBSECTION_MASK)
1165
1166struct mem_section_usage {
1167 DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION);
1168 /* See declaration of similar field in struct zone */
1169 unsigned long pageblock_flags[0];
1170};
1171
1172void subsection_map_init(unsigned long pfn, unsigned long nr_pages);
1173
1163struct page; 1174struct page;
1164struct page_ext; 1175struct page_ext;
1165struct mem_section { 1176struct mem_section {
@@ -1177,8 +1188,7 @@ struct mem_section {
1177 */ 1188 */
1178 unsigned long section_mem_map; 1189 unsigned long section_mem_map;
1179 1190
1180 /* See declaration of similar field in struct zone */ 1191 struct mem_section_usage *usage;
1181 unsigned long *pageblock_flags;
1182#ifdef CONFIG_PAGE_EXTENSION 1192#ifdef CONFIG_PAGE_EXTENSION
1183 /* 1193 /*
1184 * If SPARSEMEM, pgdat doesn't have page_ext pointer. We use 1194 * If SPARSEMEM, pgdat doesn't have page_ext pointer. We use
@@ -1209,6 +1219,11 @@ extern struct mem_section **mem_section;
1209extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; 1219extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT];
1210#endif 1220#endif
1211 1221
1222static inline unsigned long *section_to_usemap(struct mem_section *ms)
1223{
1224 return ms->usage->pageblock_flags;
1225}
1226
1212static inline struct mem_section *__nr_to_section(unsigned long nr) 1227static inline struct mem_section *__nr_to_section(unsigned long nr)
1213{ 1228{
1214#ifdef CONFIG_SPARSEMEM_EXTREME 1229#ifdef CONFIG_SPARSEMEM_EXTREME
@@ -1219,8 +1234,8 @@ static inline struct mem_section *__nr_to_section(unsigned long nr)
1219 return NULL; 1234 return NULL;
1220 return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; 1235 return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
1221} 1236}
1222extern int __section_nr(struct mem_section* ms); 1237extern unsigned long __section_nr(struct mem_section *ms);
1223extern unsigned long usemap_size(void); 1238extern size_t mem_section_usage_size(void);
1224 1239
1225/* 1240/*
1226 * We use the lower bits of the mem_map pointer to store 1241 * We use the lower bits of the mem_map pointer to store
@@ -1238,7 +1253,8 @@ extern unsigned long usemap_size(void);
1238#define SECTION_MARKED_PRESENT (1UL<<0) 1253#define SECTION_MARKED_PRESENT (1UL<<0)
1239#define SECTION_HAS_MEM_MAP (1UL<<1) 1254#define SECTION_HAS_MEM_MAP (1UL<<1)
1240#define SECTION_IS_ONLINE (1UL<<2) 1255#define SECTION_IS_ONLINE (1UL<<2)
1241#define SECTION_MAP_LAST_BIT (1UL<<3) 1256#define SECTION_IS_EARLY (1UL<<3)
1257#define SECTION_MAP_LAST_BIT (1UL<<4)
1242#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) 1258#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1))
1243#define SECTION_NID_SHIFT 3 1259#define SECTION_NID_SHIFT 3
1244 1260
@@ -1264,6 +1280,11 @@ static inline int valid_section(struct mem_section *section)
1264 return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP)); 1280 return (section && (section->section_mem_map & SECTION_HAS_MEM_MAP));
1265} 1281}
1266 1282
1283static inline int early_section(struct mem_section *section)
1284{
1285 return (section && (section->section_mem_map & SECTION_IS_EARLY));
1286}
1287
1267static inline int valid_section_nr(unsigned long nr) 1288static inline int valid_section_nr(unsigned long nr)
1268{ 1289{
1269 return valid_section(__nr_to_section(nr)); 1290 return valid_section(__nr_to_section(nr));
@@ -1291,14 +1312,42 @@ static inline struct mem_section *__pfn_to_section(unsigned long pfn)
1291 return __nr_to_section(pfn_to_section_nr(pfn)); 1312 return __nr_to_section(pfn_to_section_nr(pfn));
1292} 1313}
1293 1314
1294extern int __highest_present_section_nr; 1315extern unsigned long __highest_present_section_nr;
1316
1317static inline int subsection_map_index(unsigned long pfn)
1318{
1319 return (pfn & ~(PAGE_SECTION_MASK)) / PAGES_PER_SUBSECTION;
1320}
1321
1322#ifdef CONFIG_SPARSEMEM_VMEMMAP
1323static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
1324{
1325 int idx = subsection_map_index(pfn);
1326
1327 return test_bit(idx, ms->usage->subsection_map);
1328}
1329#else
1330static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
1331{
1332 return 1;
1333}
1334#endif
1295 1335
1296#ifndef CONFIG_HAVE_ARCH_PFN_VALID 1336#ifndef CONFIG_HAVE_ARCH_PFN_VALID
1297static inline int pfn_valid(unsigned long pfn) 1337static inline int pfn_valid(unsigned long pfn)
1298{ 1338{
1339 struct mem_section *ms;
1340
1299 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) 1341 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
1300 return 0; 1342 return 0;
1301 return valid_section(__nr_to_section(pfn_to_section_nr(pfn))); 1343 ms = __nr_to_section(pfn_to_section_nr(pfn));
1344 if (!valid_section(ms))
1345 return 0;
1346 /*
1347 * Traditionally early sections always returned pfn_valid() for
1348 * the entire section-sized span.
1349 */
1350 return early_section(ms) || pfn_section_valid(ms, pfn);
1302} 1351}
1303#endif 1352#endif
1304 1353
@@ -1330,6 +1379,7 @@ void sparse_init(void);
1330#define sparse_init() do {} while (0) 1379#define sparse_init() do {} while (0)
1331#define sparse_index_init(_sec, _nid) do {} while (0) 1380#define sparse_index_init(_sec, _nid) do {} while (0)
1332#define pfn_present pfn_valid 1381#define pfn_present pfn_valid
1382#define subsection_map_init(_pfn, _nr_pages) do {} while (0)
1333#endif /* CONFIG_SPARSEMEM */ 1383#endif /* CONFIG_SPARSEMEM */
1334 1384
1335/* 1385/*
diff --git a/include/linux/node.h b/include/linux/node.h
index 1a557c589ecb..4866f32a02d8 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -137,10 +137,7 @@ static inline int register_one_node(int nid)
137extern void unregister_one_node(int nid); 137extern void unregister_one_node(int nid);
138extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 138extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
139extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 139extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
140extern int register_mem_sect_under_node(struct memory_block *mem_blk, 140extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
141 void *arg);
142extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
143 unsigned long phys_index);
144 141
145extern int register_memory_node_under_compute_node(unsigned int mem_nid, 142extern int register_memory_node_under_compute_node(unsigned int mem_nid,
146 unsigned int cpu_nid, 143 unsigned int cpu_nid,
@@ -171,15 +168,8 @@ static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
171{ 168{
172 return 0; 169 return 0;
173} 170}
174static inline int register_mem_sect_under_node(struct memory_block *mem_blk, 171static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
175 void *arg)
176{ 172{
177 return 0;
178}
179static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
180 unsigned long phys_index)
181{
182 return 0;
183} 173}
184 174
185static inline void register_hugetlbfs_with_node(node_registration_func_t reg, 175static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index aadd310769d0..6df477329b76 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -37,6 +37,13 @@ struct ctl_table_root;
37struct ctl_table_header; 37struct ctl_table_header;
38struct ctl_dir; 38struct ctl_dir;
39 39
40/* Keep the same order as in fs/proc/proc_sysctl.c */
41#define SYSCTL_ZERO ((void *)&sysctl_vals[0])
42#define SYSCTL_ONE ((void *)&sysctl_vals[1])
43#define SYSCTL_INT_MAX ((void *)&sysctl_vals[2])
44
45extern const int sysctl_vals[];
46
40typedef int proc_handler (struct ctl_table *ctl, int write, 47typedef int proc_handler (struct ctl_table *ctl, int write,
41 void __user *buffer, size_t *lenp, loff_t *ppos); 48 void __user *buffer, size_t *lenp, loff_t *ppos);
42 49
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 2b14ce8ce73f..affd66537e87 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -113,9 +113,6 @@ static int proc_ipc_sem_dointvec(struct ctl_table *table, int write,
113#define proc_ipc_sem_dointvec NULL 113#define proc_ipc_sem_dointvec NULL
114#endif 114#endif
115 115
116static int zero;
117static int one = 1;
118static int int_max = INT_MAX;
119int ipc_mni = IPCMNI; 116int ipc_mni = IPCMNI;
120int ipc_mni_shift = IPCMNI_SHIFT; 117int ipc_mni_shift = IPCMNI_SHIFT;
121int ipc_min_cycle = RADIX_TREE_MAP_SIZE; 118int ipc_min_cycle = RADIX_TREE_MAP_SIZE;
@@ -141,7 +138,7 @@ static struct ctl_table ipc_kern_table[] = {
141 .maxlen = sizeof(init_ipc_ns.shm_ctlmni), 138 .maxlen = sizeof(init_ipc_ns.shm_ctlmni),
142 .mode = 0644, 139 .mode = 0644,
143 .proc_handler = proc_ipc_dointvec_minmax, 140 .proc_handler = proc_ipc_dointvec_minmax,
144 .extra1 = &zero, 141 .extra1 = SYSCTL_ZERO,
145 .extra2 = &ipc_mni, 142 .extra2 = &ipc_mni,
146 }, 143 },
147 { 144 {
@@ -150,8 +147,8 @@ static struct ctl_table ipc_kern_table[] = {
150 .maxlen = sizeof(init_ipc_ns.shm_rmid_forced), 147 .maxlen = sizeof(init_ipc_ns.shm_rmid_forced),
151 .mode = 0644, 148 .mode = 0644,
152 .proc_handler = proc_ipc_dointvec_minmax_orphans, 149 .proc_handler = proc_ipc_dointvec_minmax_orphans,
153 .extra1 = &zero, 150 .extra1 = SYSCTL_ZERO,
154 .extra2 = &one, 151 .extra2 = SYSCTL_ONE,
155 }, 152 },
156 { 153 {
157 .procname = "msgmax", 154 .procname = "msgmax",
@@ -159,8 +156,8 @@ static struct ctl_table ipc_kern_table[] = {
159 .maxlen = sizeof(init_ipc_ns.msg_ctlmax), 156 .maxlen = sizeof(init_ipc_ns.msg_ctlmax),
160 .mode = 0644, 157 .mode = 0644,
161 .proc_handler = proc_ipc_dointvec_minmax, 158 .proc_handler = proc_ipc_dointvec_minmax,
162 .extra1 = &zero, 159 .extra1 = SYSCTL_ZERO,
163 .extra2 = &int_max, 160 .extra2 = SYSCTL_INT_MAX,
164 }, 161 },
165 { 162 {
166 .procname = "msgmni", 163 .procname = "msgmni",
@@ -168,7 +165,7 @@ static struct ctl_table ipc_kern_table[] = {
168 .maxlen = sizeof(init_ipc_ns.msg_ctlmni), 165 .maxlen = sizeof(init_ipc_ns.msg_ctlmni),
169 .mode = 0644, 166 .mode = 0644,
170 .proc_handler = proc_ipc_dointvec_minmax, 167 .proc_handler = proc_ipc_dointvec_minmax,
171 .extra1 = &zero, 168 .extra1 = SYSCTL_ZERO,
172 .extra2 = &ipc_mni, 169 .extra2 = &ipc_mni,
173 }, 170 },
174 { 171 {
@@ -177,8 +174,8 @@ static struct ctl_table ipc_kern_table[] = {
177 .maxlen = sizeof(int), 174 .maxlen = sizeof(int),
178 .mode = 0644, 175 .mode = 0644,
179 .proc_handler = proc_ipc_auto_msgmni, 176 .proc_handler = proc_ipc_auto_msgmni,
180 .extra1 = &zero, 177 .extra1 = SYSCTL_ZERO,
181 .extra2 = &one, 178 .extra2 = SYSCTL_ONE,
182 }, 179 },
183 { 180 {
184 .procname = "msgmnb", 181 .procname = "msgmnb",
@@ -186,8 +183,8 @@ static struct ctl_table ipc_kern_table[] = {
186 .maxlen = sizeof(init_ipc_ns.msg_ctlmnb), 183 .maxlen = sizeof(init_ipc_ns.msg_ctlmnb),
187 .mode = 0644, 184 .mode = 0644,
188 .proc_handler = proc_ipc_dointvec_minmax, 185 .proc_handler = proc_ipc_dointvec_minmax,
189 .extra1 = &zero, 186 .extra1 = SYSCTL_ZERO,
190 .extra2 = &int_max, 187 .extra2 = SYSCTL_INT_MAX,
191 }, 188 },
192 { 189 {
193 .procname = "sem", 190 .procname = "sem",
@@ -203,8 +200,8 @@ static struct ctl_table ipc_kern_table[] = {
203 .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id), 200 .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
204 .mode = 0644, 201 .mode = 0644,
205 .proc_handler = proc_ipc_dointvec_minmax, 202 .proc_handler = proc_ipc_dointvec_minmax,
206 .extra1 = &zero, 203 .extra1 = SYSCTL_ZERO,
207 .extra2 = &int_max, 204 .extra2 = SYSCTL_INT_MAX,
208 }, 205 },
209 { 206 {
210 .procname = "msg_next_id", 207 .procname = "msg_next_id",
@@ -212,8 +209,8 @@ static struct ctl_table ipc_kern_table[] = {
212 .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id), 209 .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
213 .mode = 0644, 210 .mode = 0644,
214 .proc_handler = proc_ipc_dointvec_minmax, 211 .proc_handler = proc_ipc_dointvec_minmax,
215 .extra1 = &zero, 212 .extra1 = SYSCTL_ZERO,
216 .extra2 = &int_max, 213 .extra2 = SYSCTL_INT_MAX,
217 }, 214 },
218 { 215 {
219 .procname = "shm_next_id", 216 .procname = "shm_next_id",
@@ -221,8 +218,8 @@ static struct ctl_table ipc_kern_table[] = {
221 .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id), 218 .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
222 .mode = 0644, 219 .mode = 0644,
223 .proc_handler = proc_ipc_dointvec_minmax, 220 .proc_handler = proc_ipc_dointvec_minmax,
224 .extra1 = &zero, 221 .extra1 = SYSCTL_ZERO,
225 .extra2 = &int_max, 222 .extra2 = SYSCTL_INT_MAX,
226 }, 223 },
227#endif 224#endif
228 {} 225 {}
diff --git a/kernel/memremap.c b/kernel/memremap.c
index bea6f887adad..6ee03a816d67 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -54,7 +54,7 @@ static void pgmap_array_delete(struct resource *res)
54 54
55static unsigned long pfn_first(struct dev_pagemap *pgmap) 55static unsigned long pfn_first(struct dev_pagemap *pgmap)
56{ 56{
57 return (pgmap->res.start >> PAGE_SHIFT) + 57 return PHYS_PFN(pgmap->res.start) +
58 vmem_altmap_offset(pgmap_altmap(pgmap)); 58 vmem_altmap_offset(pgmap_altmap(pgmap));
59} 59}
60 60
@@ -98,7 +98,6 @@ static void devm_memremap_pages_release(void *data)
98 struct dev_pagemap *pgmap = data; 98 struct dev_pagemap *pgmap = data;
99 struct device *dev = pgmap->dev; 99 struct device *dev = pgmap->dev;
100 struct resource *res = &pgmap->res; 100 struct resource *res = &pgmap->res;
101 resource_size_t align_start, align_size;
102 unsigned long pfn; 101 unsigned long pfn;
103 int nid; 102 int nid;
104 103
@@ -108,25 +107,21 @@ static void devm_memremap_pages_release(void *data)
108 dev_pagemap_cleanup(pgmap); 107 dev_pagemap_cleanup(pgmap);
109 108
110 /* pages are dead and unused, undo the arch mapping */ 109 /* pages are dead and unused, undo the arch mapping */
111 align_start = res->start & ~(SECTION_SIZE - 1); 110 nid = page_to_nid(pfn_to_page(PHYS_PFN(res->start)));
112 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
113 - align_start;
114
115 nid = page_to_nid(pfn_to_page(align_start >> PAGE_SHIFT));
116 111
117 mem_hotplug_begin(); 112 mem_hotplug_begin();
118 if (pgmap->type == MEMORY_DEVICE_PRIVATE) { 113 if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
119 pfn = align_start >> PAGE_SHIFT; 114 pfn = PHYS_PFN(res->start);
120 __remove_pages(page_zone(pfn_to_page(pfn)), pfn, 115 __remove_pages(page_zone(pfn_to_page(pfn)), pfn,
121 align_size >> PAGE_SHIFT, NULL); 116 PHYS_PFN(resource_size(res)), NULL);
122 } else { 117 } else {
123 arch_remove_memory(nid, align_start, align_size, 118 arch_remove_memory(nid, res->start, resource_size(res),
124 pgmap_altmap(pgmap)); 119 pgmap_altmap(pgmap));
125 kasan_remove_zero_shadow(__va(align_start), align_size); 120 kasan_remove_zero_shadow(__va(res->start), resource_size(res));
126 } 121 }
127 mem_hotplug_done(); 122 mem_hotplug_done();
128 123
129 untrack_pfn(NULL, PHYS_PFN(align_start), align_size); 124 untrack_pfn(NULL, PHYS_PFN(res->start), resource_size(res));
130 pgmap_array_delete(res); 125 pgmap_array_delete(res);
131 dev_WARN_ONCE(dev, pgmap->altmap.alloc, 126 dev_WARN_ONCE(dev, pgmap->altmap.alloc,
132 "%s: failed to free all reserved pages\n", __func__); 127 "%s: failed to free all reserved pages\n", __func__);
@@ -162,13 +157,12 @@ static void dev_pagemap_percpu_release(struct percpu_ref *ref)
162 */ 157 */
163void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) 158void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
164{ 159{
165 resource_size_t align_start, align_size, align_end;
166 struct resource *res = &pgmap->res; 160 struct resource *res = &pgmap->res;
167 struct dev_pagemap *conflict_pgmap; 161 struct dev_pagemap *conflict_pgmap;
168 struct mhp_restrictions restrictions = { 162 struct mhp_restrictions restrictions = {
169 /* 163 /*
170 * We do not want any optional features only our own memmap 164 * We do not want any optional features only our own memmap
171 */ 165 */
172 .altmap = pgmap_altmap(pgmap), 166 .altmap = pgmap_altmap(pgmap),
173 }; 167 };
174 pgprot_t pgprot = PAGE_KERNEL; 168 pgprot_t pgprot = PAGE_KERNEL;
@@ -225,12 +219,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
225 return ERR_PTR(error); 219 return ERR_PTR(error);
226 } 220 }
227 221
228 align_start = res->start & ~(SECTION_SIZE - 1); 222 conflict_pgmap = get_dev_pagemap(PHYS_PFN(res->start), NULL);
229 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
230 - align_start;
231 align_end = align_start + align_size - 1;
232
233 conflict_pgmap = get_dev_pagemap(PHYS_PFN(align_start), NULL);
234 if (conflict_pgmap) { 223 if (conflict_pgmap) {
235 dev_WARN(dev, "Conflicting mapping in same section\n"); 224 dev_WARN(dev, "Conflicting mapping in same section\n");
236 put_dev_pagemap(conflict_pgmap); 225 put_dev_pagemap(conflict_pgmap);
@@ -238,7 +227,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
238 goto err_array; 227 goto err_array;
239 } 228 }
240 229
241 conflict_pgmap = get_dev_pagemap(PHYS_PFN(align_end), NULL); 230 conflict_pgmap = get_dev_pagemap(PHYS_PFN(res->end), NULL);
242 if (conflict_pgmap) { 231 if (conflict_pgmap) {
243 dev_WARN(dev, "Conflicting mapping in same section\n"); 232 dev_WARN(dev, "Conflicting mapping in same section\n");
244 put_dev_pagemap(conflict_pgmap); 233 put_dev_pagemap(conflict_pgmap);
@@ -246,7 +235,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
246 goto err_array; 235 goto err_array;
247 } 236 }
248 237
249 is_ram = region_intersects(align_start, align_size, 238 is_ram = region_intersects(res->start, resource_size(res),
250 IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE); 239 IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
251 240
252 if (is_ram != REGION_DISJOINT) { 241 if (is_ram != REGION_DISJOINT) {
@@ -267,8 +256,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
267 if (nid < 0) 256 if (nid < 0)
268 nid = numa_mem_id(); 257 nid = numa_mem_id();
269 258
270 error = track_pfn_remap(NULL, &pgprot, PHYS_PFN(align_start), 0, 259 error = track_pfn_remap(NULL, &pgprot, PHYS_PFN(res->start), 0,
271 align_size); 260 resource_size(res));
272 if (error) 261 if (error)
273 goto err_pfn_remap; 262 goto err_pfn_remap;
274 263
@@ -286,16 +275,16 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
286 * arch_add_memory(). 275 * arch_add_memory().
287 */ 276 */
288 if (pgmap->type == MEMORY_DEVICE_PRIVATE) { 277 if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
289 error = add_pages(nid, align_start >> PAGE_SHIFT, 278 error = add_pages(nid, PHYS_PFN(res->start),
290 align_size >> PAGE_SHIFT, &restrictions); 279 PHYS_PFN(resource_size(res)), &restrictions);
291 } else { 280 } else {
292 error = kasan_add_zero_shadow(__va(align_start), align_size); 281 error = kasan_add_zero_shadow(__va(res->start), resource_size(res));
293 if (error) { 282 if (error) {
294 mem_hotplug_done(); 283 mem_hotplug_done();
295 goto err_kasan; 284 goto err_kasan;
296 } 285 }
297 286
298 error = arch_add_memory(nid, align_start, align_size, 287 error = arch_add_memory(nid, res->start, resource_size(res),
299 &restrictions); 288 &restrictions);
300 } 289 }
301 290
@@ -303,8 +292,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
303 struct zone *zone; 292 struct zone *zone;
304 293
305 zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; 294 zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE];
306 move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT, 295 move_pfn_range_to_zone(zone, PHYS_PFN(res->start),
307 align_size >> PAGE_SHIFT, pgmap_altmap(pgmap)); 296 PHYS_PFN(resource_size(res)), restrictions.altmap);
308 } 297 }
309 298
310 mem_hotplug_done(); 299 mem_hotplug_done();
@@ -316,8 +305,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
316 * to allow us to do the work while not holding the hotplug lock. 305 * to allow us to do the work while not holding the hotplug lock.
317 */ 306 */
318 memmap_init_zone_device(&NODE_DATA(nid)->node_zones[ZONE_DEVICE], 307 memmap_init_zone_device(&NODE_DATA(nid)->node_zones[ZONE_DEVICE],
319 align_start >> PAGE_SHIFT, 308 PHYS_PFN(res->start),
320 align_size >> PAGE_SHIFT, pgmap); 309 PHYS_PFN(resource_size(res)), pgmap);
321 percpu_ref_get_many(pgmap->ref, pfn_end(pgmap) - pfn_first(pgmap)); 310 percpu_ref_get_many(pgmap->ref, pfn_end(pgmap) - pfn_first(pgmap));
322 311
323 error = devm_add_action_or_reset(dev, devm_memremap_pages_release, 312 error = devm_add_action_or_reset(dev, devm_memremap_pages_release,
@@ -328,9 +317,9 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
328 return __va(res->start); 317 return __va(res->start);
329 318
330 err_add_memory: 319 err_add_memory:
331 kasan_remove_zero_shadow(__va(align_start), align_size); 320 kasan_remove_zero_shadow(__va(res->start), resource_size(res));
332 err_kasan: 321 err_kasan:
333 untrack_pfn(NULL, PHYS_PFN(align_start), align_size); 322 untrack_pfn(NULL, PHYS_PFN(res->start), resource_size(res));
334 err_pfn_remap: 323 err_pfn_remap:
335 pgmap_array_delete(res); 324 pgmap_array_delete(res);
336 err_array: 325 err_array:
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 6d726cef241c..a6a79f85c81a 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -291,14 +291,13 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
291} 291}
292 292
293extern int pid_max; 293extern int pid_max;
294static int zero = 0;
295static struct ctl_table pid_ns_ctl_table[] = { 294static struct ctl_table pid_ns_ctl_table[] = {
296 { 295 {
297 .procname = "ns_last_pid", 296 .procname = "ns_last_pid",
298 .maxlen = sizeof(int), 297 .maxlen = sizeof(int),
299 .mode = 0666, /* permissions are checked in the handler */ 298 .mode = 0666, /* permissions are checked in the handler */
300 .proc_handler = pid_ns_ctl_handler, 299 .proc_handler = pid_ns_ctl_handler,
301 .extra1 = &zero, 300 .extra1 = SYSCTL_ZERO,
302 .extra2 = &pid_max, 301 .extra2 = &pid_max,
303 }, 302 },
304 { } 303 { }
diff --git a/kernel/resource.c b/kernel/resource.c
index d22423e85cf8..7ea4306503c5 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -326,7 +326,7 @@ EXPORT_SYMBOL(release_resource);
326 * 326 *
327 * If a resource is found, returns 0 and @*res is overwritten with the part 327 * If a resource is found, returns 0 and @*res is overwritten with the part
328 * of the resource that's within [@start..@end]; if none is found, returns 328 * of the resource that's within [@start..@end]; if none is found, returns
329 * -1 or -EINVAL for other invalid parameters. 329 * -ENODEV. Returns -EINVAL for invalid parameters.
330 * 330 *
331 * This function walks the whole tree and not just first level children 331 * This function walks the whole tree and not just first level children
332 * unless @first_lvl is true. 332 * unless @first_lvl is true.
@@ -342,6 +342,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
342 unsigned long flags, unsigned long desc, 342 unsigned long flags, unsigned long desc,
343 bool first_lvl, struct resource *res) 343 bool first_lvl, struct resource *res)
344{ 344{
345 bool siblings_only = true;
345 struct resource *p; 346 struct resource *p;
346 347
347 if (!res) 348 if (!res)
@@ -352,29 +353,43 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
352 353
353 read_lock(&resource_lock); 354 read_lock(&resource_lock);
354 355
355 for (p = iomem_resource.child; p; p = next_resource(p, first_lvl)) { 356 for (p = iomem_resource.child; p; p = next_resource(p, siblings_only)) {
356 if ((p->flags & flags) != flags) 357 /* If we passed the resource we are looking for, stop */
357 continue;
358 if ((desc != IORES_DESC_NONE) && (desc != p->desc))
359 continue;
360 if (p->start > end) { 358 if (p->start > end) {
361 p = NULL; 359 p = NULL;
362 break; 360 break;
363 } 361 }
364 if ((p->end >= start) && (p->start <= end)) 362
365 break; 363 /* Skip until we find a range that matches what we look for */
364 if (p->end < start)
365 continue;
366
367 /*
368 * Now that we found a range that matches what we look for,
369 * check the flags and the descriptor. If we were not asked to
370 * use only the first level, start looking at children as well.
371 */
372 siblings_only = first_lvl;
373
374 if ((p->flags & flags) != flags)
375 continue;
376 if ((desc != IORES_DESC_NONE) && (desc != p->desc))
377 continue;
378
379 /* Found a match, break */
380 break;
381 }
382
383 if (p) {
384 /* copy data */
385 res->start = max(start, p->start);
386 res->end = min(end, p->end);
387 res->flags = p->flags;
388 res->desc = p->desc;
366 } 389 }
367 390
368 read_unlock(&resource_lock); 391 read_unlock(&resource_lock);
369 if (!p) 392 return p ? 0 : -ENODEV;
370 return -1;
371
372 /* copy data */
373 res->start = max(start, p->start);
374 res->end = min(end, p->end);
375 res->flags = p->flags;
376 res->desc = p->desc;
377 return 0;
378} 393}
379 394
380static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, 395static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 43186ccfa139..078950d9605b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -125,9 +125,6 @@ static int sixty = 60;
125#endif 125#endif
126 126
127static int __maybe_unused neg_one = -1; 127static int __maybe_unused neg_one = -1;
128
129static int zero;
130static int __maybe_unused one = 1;
131static int __maybe_unused two = 2; 128static int __maybe_unused two = 2;
132static int __maybe_unused four = 4; 129static int __maybe_unused four = 4;
133static unsigned long zero_ul; 130static unsigned long zero_ul;
@@ -385,8 +382,8 @@ static struct ctl_table kern_table[] = {
385 .maxlen = sizeof(unsigned int), 382 .maxlen = sizeof(unsigned int),
386 .mode = 0644, 383 .mode = 0644,
387 .proc_handler = sysctl_schedstats, 384 .proc_handler = sysctl_schedstats,
388 .extra1 = &zero, 385 .extra1 = SYSCTL_ZERO,
389 .extra2 = &one, 386 .extra2 = SYSCTL_ONE,
390 }, 387 },
391#endif /* CONFIG_SCHEDSTATS */ 388#endif /* CONFIG_SCHEDSTATS */
392#endif /* CONFIG_SMP */ 389#endif /* CONFIG_SMP */
@@ -418,7 +415,7 @@ static struct ctl_table kern_table[] = {
418 .maxlen = sizeof(unsigned int), 415 .maxlen = sizeof(unsigned int),
419 .mode = 0644, 416 .mode = 0644,
420 .proc_handler = proc_dointvec_minmax, 417 .proc_handler = proc_dointvec_minmax,
421 .extra1 = &one, 418 .extra1 = SYSCTL_ONE,
422 }, 419 },
423 { 420 {
424 .procname = "numa_balancing", 421 .procname = "numa_balancing",
@@ -426,8 +423,8 @@ static struct ctl_table kern_table[] = {
426 .maxlen = sizeof(unsigned int), 423 .maxlen = sizeof(unsigned int),
427 .mode = 0644, 424 .mode = 0644,
428 .proc_handler = sysctl_numa_balancing, 425 .proc_handler = sysctl_numa_balancing,
429 .extra1 = &zero, 426 .extra1 = SYSCTL_ZERO,
430 .extra2 = &one, 427 .extra2 = SYSCTL_ONE,
431 }, 428 },
432#endif /* CONFIG_NUMA_BALANCING */ 429#endif /* CONFIG_NUMA_BALANCING */
433#endif /* CONFIG_SCHED_DEBUG */ 430#endif /* CONFIG_SCHED_DEBUG */
@@ -475,8 +472,8 @@ static struct ctl_table kern_table[] = {
475 .maxlen = sizeof(unsigned int), 472 .maxlen = sizeof(unsigned int),
476 .mode = 0644, 473 .mode = 0644,
477 .proc_handler = proc_dointvec_minmax, 474 .proc_handler = proc_dointvec_minmax,
478 .extra1 = &zero, 475 .extra1 = SYSCTL_ZERO,
479 .extra2 = &one, 476 .extra2 = SYSCTL_ONE,
480 }, 477 },
481#endif 478#endif
482#ifdef CONFIG_CFS_BANDWIDTH 479#ifdef CONFIG_CFS_BANDWIDTH
@@ -486,7 +483,7 @@ static struct ctl_table kern_table[] = {
486 .maxlen = sizeof(unsigned int), 483 .maxlen = sizeof(unsigned int),
487 .mode = 0644, 484 .mode = 0644,
488 .proc_handler = proc_dointvec_minmax, 485 .proc_handler = proc_dointvec_minmax,
489 .extra1 = &one, 486 .extra1 = SYSCTL_ONE,
490 }, 487 },
491#endif 488#endif
492#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) 489#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
@@ -496,8 +493,8 @@ static struct ctl_table kern_table[] = {
496 .maxlen = sizeof(unsigned int), 493 .maxlen = sizeof(unsigned int),
497 .mode = 0644, 494 .mode = 0644,
498 .proc_handler = sched_energy_aware_handler, 495 .proc_handler = sched_energy_aware_handler,
499 .extra1 = &zero, 496 .extra1 = SYSCTL_ZERO,
500 .extra2 = &one, 497 .extra2 = SYSCTL_ONE,
501 }, 498 },
502#endif 499#endif
503#ifdef CONFIG_PROVE_LOCKING 500#ifdef CONFIG_PROVE_LOCKING
@@ -562,7 +559,7 @@ static struct ctl_table kern_table[] = {
562 .mode = 0644, 559 .mode = 0644,
563 .proc_handler = proc_dointvec_minmax, 560 .proc_handler = proc_dointvec_minmax,
564 .extra1 = &neg_one, 561 .extra1 = &neg_one,
565 .extra2 = &one, 562 .extra2 = SYSCTL_ONE,
566 }, 563 },
567#endif 564#endif
568#ifdef CONFIG_LATENCYTOP 565#ifdef CONFIG_LATENCYTOP
@@ -696,8 +693,8 @@ static struct ctl_table kern_table[] = {
696 .mode = 0644, 693 .mode = 0644,
697 /* only handle a transition from default "0" to "1" */ 694 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax, 695 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &one, 696 .extra1 = SYSCTL_ONE,
700 .extra2 = &one, 697 .extra2 = SYSCTL_ONE,
701 }, 698 },
702#endif 699#endif
703#ifdef CONFIG_MODULES 700#ifdef CONFIG_MODULES
@@ -715,8 +712,8 @@ static struct ctl_table kern_table[] = {
715 .mode = 0644, 712 .mode = 0644,
716 /* only handle a transition from default "0" to "1" */ 713 /* only handle a transition from default "0" to "1" */
717 .proc_handler = proc_dointvec_minmax, 714 .proc_handler = proc_dointvec_minmax,
718 .extra1 = &one, 715 .extra1 = SYSCTL_ONE,
719 .extra2 = &one, 716 .extra2 = SYSCTL_ONE,
720 }, 717 },
721#endif 718#endif
722#ifdef CONFIG_UEVENT_HELPER 719#ifdef CONFIG_UEVENT_HELPER
@@ -875,7 +872,7 @@ static struct ctl_table kern_table[] = {
875 .maxlen = sizeof(int), 872 .maxlen = sizeof(int),
876 .mode = 0644, 873 .mode = 0644,
877 .proc_handler = proc_dointvec_minmax, 874 .proc_handler = proc_dointvec_minmax,
878 .extra1 = &zero, 875 .extra1 = SYSCTL_ZERO,
879 .extra2 = &ten_thousand, 876 .extra2 = &ten_thousand,
880 }, 877 },
881 { 878 {
@@ -891,8 +888,8 @@ static struct ctl_table kern_table[] = {
891 .maxlen = sizeof(int), 888 .maxlen = sizeof(int),
892 .mode = 0644, 889 .mode = 0644,
893 .proc_handler = proc_dointvec_minmax_sysadmin, 890 .proc_handler = proc_dointvec_minmax_sysadmin,
894 .extra1 = &zero, 891 .extra1 = SYSCTL_ZERO,
895 .extra2 = &one, 892 .extra2 = SYSCTL_ONE,
896 }, 893 },
897 { 894 {
898 .procname = "kptr_restrict", 895 .procname = "kptr_restrict",
@@ -900,7 +897,7 @@ static struct ctl_table kern_table[] = {
900 .maxlen = sizeof(int), 897 .maxlen = sizeof(int),
901 .mode = 0644, 898 .mode = 0644,
902 .proc_handler = proc_dointvec_minmax_sysadmin, 899 .proc_handler = proc_dointvec_minmax_sysadmin,
903 .extra1 = &zero, 900 .extra1 = SYSCTL_ZERO,
904 .extra2 = &two, 901 .extra2 = &two,
905 }, 902 },
906#endif 903#endif
@@ -925,8 +922,8 @@ static struct ctl_table kern_table[] = {
925 .maxlen = sizeof(int), 922 .maxlen = sizeof(int),
926 .mode = 0644, 923 .mode = 0644,
927 .proc_handler = proc_watchdog, 924 .proc_handler = proc_watchdog,
928 .extra1 = &zero, 925 .extra1 = SYSCTL_ZERO,
929 .extra2 = &one, 926 .extra2 = SYSCTL_ONE,
930 }, 927 },
931 { 928 {
932 .procname = "watchdog_thresh", 929 .procname = "watchdog_thresh",
@@ -934,7 +931,7 @@ static struct ctl_table kern_table[] = {
934 .maxlen = sizeof(int), 931 .maxlen = sizeof(int),
935 .mode = 0644, 932 .mode = 0644,
936 .proc_handler = proc_watchdog_thresh, 933 .proc_handler = proc_watchdog_thresh,
937 .extra1 = &zero, 934 .extra1 = SYSCTL_ZERO,
938 .extra2 = &sixty, 935 .extra2 = &sixty,
939 }, 936 },
940 { 937 {
@@ -943,8 +940,8 @@ static struct ctl_table kern_table[] = {
943 .maxlen = sizeof(int), 940 .maxlen = sizeof(int),
944 .mode = NMI_WATCHDOG_SYSCTL_PERM, 941 .mode = NMI_WATCHDOG_SYSCTL_PERM,
945 .proc_handler = proc_nmi_watchdog, 942 .proc_handler = proc_nmi_watchdog,
946 .extra1 = &zero, 943 .extra1 = SYSCTL_ZERO,
947 .extra2 = &one, 944 .extra2 = SYSCTL_ONE,
948 }, 945 },
949 { 946 {
950 .procname = "watchdog_cpumask", 947 .procname = "watchdog_cpumask",
@@ -960,8 +957,8 @@ static struct ctl_table kern_table[] = {
960 .maxlen = sizeof(int), 957 .maxlen = sizeof(int),
961 .mode = 0644, 958 .mode = 0644,
962 .proc_handler = proc_soft_watchdog, 959 .proc_handler = proc_soft_watchdog,
963 .extra1 = &zero, 960 .extra1 = SYSCTL_ZERO,
964 .extra2 = &one, 961 .extra2 = SYSCTL_ONE,
965 }, 962 },
966 { 963 {
967 .procname = "softlockup_panic", 964 .procname = "softlockup_panic",
@@ -969,8 +966,8 @@ static struct ctl_table kern_table[] = {
969 .maxlen = sizeof(int), 966 .maxlen = sizeof(int),
970 .mode = 0644, 967 .mode = 0644,
971 .proc_handler = proc_dointvec_minmax, 968 .proc_handler = proc_dointvec_minmax,
972 .extra1 = &zero, 969 .extra1 = SYSCTL_ZERO,
973 .extra2 = &one, 970 .extra2 = SYSCTL_ONE,
974 }, 971 },
975#ifdef CONFIG_SMP 972#ifdef CONFIG_SMP
976 { 973 {
@@ -979,8 +976,8 @@ static struct ctl_table kern_table[] = {
979 .maxlen = sizeof(int), 976 .maxlen = sizeof(int),
980 .mode = 0644, 977 .mode = 0644,
981 .proc_handler = proc_dointvec_minmax, 978 .proc_handler = proc_dointvec_minmax,
982 .extra1 = &zero, 979 .extra1 = SYSCTL_ZERO,
983 .extra2 = &one, 980 .extra2 = SYSCTL_ONE,
984 }, 981 },
985#endif /* CONFIG_SMP */ 982#endif /* CONFIG_SMP */
986#endif 983#endif
@@ -991,8 +988,8 @@ static struct ctl_table kern_table[] = {
991 .maxlen = sizeof(int), 988 .maxlen = sizeof(int),
992 .mode = 0644, 989 .mode = 0644,
993 .proc_handler = proc_dointvec_minmax, 990 .proc_handler = proc_dointvec_minmax,
994 .extra1 = &zero, 991 .extra1 = SYSCTL_ZERO,
995 .extra2 = &one, 992 .extra2 = SYSCTL_ONE,
996 }, 993 },
997#ifdef CONFIG_SMP 994#ifdef CONFIG_SMP
998 { 995 {
@@ -1001,8 +998,8 @@ static struct ctl_table kern_table[] = {
1001 .maxlen = sizeof(int), 998 .maxlen = sizeof(int),
1002 .mode = 0644, 999 .mode = 0644,
1003 .proc_handler = proc_dointvec_minmax, 1000 .proc_handler = proc_dointvec_minmax,
1004 .extra1 = &zero, 1001 .extra1 = SYSCTL_ZERO,
1005 .extra2 = &one, 1002 .extra2 = SYSCTL_ONE,
1006 }, 1003 },
1007#endif /* CONFIG_SMP */ 1004#endif /* CONFIG_SMP */
1008#endif 1005#endif
@@ -1115,8 +1112,8 @@ static struct ctl_table kern_table[] = {
1115 .maxlen = sizeof(int), 1112 .maxlen = sizeof(int),
1116 .mode = 0644, 1113 .mode = 0644,
1117 .proc_handler = proc_dointvec_minmax, 1114 .proc_handler = proc_dointvec_minmax,
1118 .extra1 = &zero, 1115 .extra1 = SYSCTL_ZERO,
1119 .extra2 = &one, 1116 .extra2 = SYSCTL_ONE,
1120 }, 1117 },
1121 { 1118 {
1122 .procname = "hung_task_check_count", 1119 .procname = "hung_task_check_count",
@@ -1124,7 +1121,7 @@ static struct ctl_table kern_table[] = {
1124 .maxlen = sizeof(int), 1121 .maxlen = sizeof(int),
1125 .mode = 0644, 1122 .mode = 0644,
1126 .proc_handler = proc_dointvec_minmax, 1123 .proc_handler = proc_dointvec_minmax,
1127 .extra1 = &zero, 1124 .extra1 = SYSCTL_ZERO,
1128 }, 1125 },
1129 { 1126 {
1130 .procname = "hung_task_timeout_secs", 1127 .procname = "hung_task_timeout_secs",
@@ -1201,7 +1198,7 @@ static struct ctl_table kern_table[] = {
1201 .maxlen = sizeof(sysctl_perf_event_sample_rate), 1198 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1202 .mode = 0644, 1199 .mode = 0644,
1203 .proc_handler = perf_proc_update_handler, 1200 .proc_handler = perf_proc_update_handler,
1204 .extra1 = &one, 1201 .extra1 = SYSCTL_ONE,
1205 }, 1202 },
1206 { 1203 {
1207 .procname = "perf_cpu_time_max_percent", 1204 .procname = "perf_cpu_time_max_percent",
@@ -1209,7 +1206,7 @@ static struct ctl_table kern_table[] = {
1209 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), 1206 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1210 .mode = 0644, 1207 .mode = 0644,
1211 .proc_handler = perf_cpu_time_max_percent_handler, 1208 .proc_handler = perf_cpu_time_max_percent_handler,
1212 .extra1 = &zero, 1209 .extra1 = SYSCTL_ZERO,
1213 .extra2 = &one_hundred, 1210 .extra2 = &one_hundred,
1214 }, 1211 },
1215 { 1212 {
@@ -1218,7 +1215,7 @@ static struct ctl_table kern_table[] = {
1218 .maxlen = sizeof(sysctl_perf_event_max_stack), 1215 .maxlen = sizeof(sysctl_perf_event_max_stack),
1219 .mode = 0644, 1216 .mode = 0644,
1220 .proc_handler = perf_event_max_stack_handler, 1217 .proc_handler = perf_event_max_stack_handler,
1221 .extra1 = &zero, 1218 .extra1 = SYSCTL_ZERO,
1222 .extra2 = &six_hundred_forty_kb, 1219 .extra2 = &six_hundred_forty_kb,
1223 }, 1220 },
1224 { 1221 {
@@ -1227,7 +1224,7 @@ static struct ctl_table kern_table[] = {
1227 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), 1224 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1228 .mode = 0644, 1225 .mode = 0644,
1229 .proc_handler = perf_event_max_stack_handler, 1226 .proc_handler = perf_event_max_stack_handler,
1230 .extra1 = &zero, 1227 .extra1 = SYSCTL_ZERO,
1231 .extra2 = &one_thousand, 1228 .extra2 = &one_thousand,
1232 }, 1229 },
1233#endif 1230#endif
@@ -1237,8 +1234,8 @@ static struct ctl_table kern_table[] = {
1237 .maxlen = sizeof(int), 1234 .maxlen = sizeof(int),
1238 .mode = 0644, 1235 .mode = 0644,
1239 .proc_handler = proc_dointvec_minmax, 1236 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = &zero, 1237 .extra1 = SYSCTL_ZERO,
1241 .extra2 = &one, 1238 .extra2 = SYSCTL_ONE,
1242 }, 1239 },
1243#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) 1240#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1244 { 1241 {
@@ -1247,8 +1244,8 @@ static struct ctl_table kern_table[] = {
1247 .maxlen = sizeof(unsigned int), 1244 .maxlen = sizeof(unsigned int),
1248 .mode = 0644, 1245 .mode = 0644,
1249 .proc_handler = timer_migration_handler, 1246 .proc_handler = timer_migration_handler,
1250 .extra1 = &zero, 1247 .extra1 = SYSCTL_ZERO,
1251 .extra2 = &one, 1248 .extra2 = SYSCTL_ONE,
1252 }, 1249 },
1253#endif 1250#endif
1254#ifdef CONFIG_BPF_SYSCALL 1251#ifdef CONFIG_BPF_SYSCALL
@@ -1259,8 +1256,8 @@ static struct ctl_table kern_table[] = {
1259 .mode = 0644, 1256 .mode = 0644,
1260 /* only handle a transition from default "0" to "1" */ 1257 /* only handle a transition from default "0" to "1" */
1261 .proc_handler = proc_dointvec_minmax, 1258 .proc_handler = proc_dointvec_minmax,
1262 .extra1 = &one, 1259 .extra1 = SYSCTL_ONE,
1263 .extra2 = &one, 1260 .extra2 = SYSCTL_ONE,
1264 }, 1261 },
1265 { 1262 {
1266 .procname = "bpf_stats_enabled", 1263 .procname = "bpf_stats_enabled",
@@ -1277,8 +1274,8 @@ static struct ctl_table kern_table[] = {
1277 .maxlen = sizeof(sysctl_panic_on_rcu_stall), 1274 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1278 .mode = 0644, 1275 .mode = 0644,
1279 .proc_handler = proc_dointvec_minmax, 1276 .proc_handler = proc_dointvec_minmax,
1280 .extra1 = &zero, 1277 .extra1 = SYSCTL_ZERO,
1281 .extra2 = &one, 1278 .extra2 = SYSCTL_ONE,
1282 }, 1279 },
1283#endif 1280#endif
1284#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE 1281#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
@@ -1288,8 +1285,8 @@ static struct ctl_table kern_table[] = {
1288 .maxlen = sizeof(int), 1285 .maxlen = sizeof(int),
1289 .mode = 0600, 1286 .mode = 0600,
1290 .proc_handler = stack_erasing_sysctl, 1287 .proc_handler = stack_erasing_sysctl,
1291 .extra1 = &zero, 1288 .extra1 = SYSCTL_ZERO,
1292 .extra2 = &one, 1289 .extra2 = SYSCTL_ONE,
1293 }, 1290 },
1294#endif 1291#endif
1295 { } 1292 { }
@@ -1302,7 +1299,7 @@ static struct ctl_table vm_table[] = {
1302 .maxlen = sizeof(sysctl_overcommit_memory), 1299 .maxlen = sizeof(sysctl_overcommit_memory),
1303 .mode = 0644, 1300 .mode = 0644,
1304 .proc_handler = proc_dointvec_minmax, 1301 .proc_handler = proc_dointvec_minmax,
1305 .extra1 = &zero, 1302 .extra1 = SYSCTL_ZERO,
1306 .extra2 = &two, 1303 .extra2 = &two,
1307 }, 1304 },
1308 { 1305 {
@@ -1311,7 +1308,7 @@ static struct ctl_table vm_table[] = {
1311 .maxlen = sizeof(sysctl_panic_on_oom), 1308 .maxlen = sizeof(sysctl_panic_on_oom),
1312 .mode = 0644, 1309 .mode = 0644,
1313 .proc_handler = proc_dointvec_minmax, 1310 .proc_handler = proc_dointvec_minmax,
1314 .extra1 = &zero, 1311 .extra1 = SYSCTL_ZERO,
1315 .extra2 = &two, 1312 .extra2 = &two,
1316 }, 1313 },
1317 { 1314 {
@@ -1348,7 +1345,7 @@ static struct ctl_table vm_table[] = {
1348 .maxlen = sizeof(int), 1345 .maxlen = sizeof(int),
1349 .mode = 0644, 1346 .mode = 0644,
1350 .proc_handler = proc_dointvec_minmax, 1347 .proc_handler = proc_dointvec_minmax,
1351 .extra1 = &zero, 1348 .extra1 = SYSCTL_ZERO,
1352 }, 1349 },
1353 { 1350 {
1354 .procname = "dirty_background_ratio", 1351 .procname = "dirty_background_ratio",
@@ -1356,7 +1353,7 @@ static struct ctl_table vm_table[] = {
1356 .maxlen = sizeof(dirty_background_ratio), 1353 .maxlen = sizeof(dirty_background_ratio),
1357 .mode = 0644, 1354 .mode = 0644,
1358 .proc_handler = dirty_background_ratio_handler, 1355 .proc_handler = dirty_background_ratio_handler,
1359 .extra1 = &zero, 1356 .extra1 = SYSCTL_ZERO,
1360 .extra2 = &one_hundred, 1357 .extra2 = &one_hundred,
1361 }, 1358 },
1362 { 1359 {
@@ -1373,7 +1370,7 @@ static struct ctl_table vm_table[] = {
1373 .maxlen = sizeof(vm_dirty_ratio), 1370 .maxlen = sizeof(vm_dirty_ratio),
1374 .mode = 0644, 1371 .mode = 0644,
1375 .proc_handler = dirty_ratio_handler, 1372 .proc_handler = dirty_ratio_handler,
1376 .extra1 = &zero, 1373 .extra1 = SYSCTL_ZERO,
1377 .extra2 = &one_hundred, 1374 .extra2 = &one_hundred,
1378 }, 1375 },
1379 { 1376 {
@@ -1397,7 +1394,7 @@ static struct ctl_table vm_table[] = {
1397 .maxlen = sizeof(dirty_expire_interval), 1394 .maxlen = sizeof(dirty_expire_interval),
1398 .mode = 0644, 1395 .mode = 0644,
1399 .proc_handler = proc_dointvec_minmax, 1396 .proc_handler = proc_dointvec_minmax,
1400 .extra1 = &zero, 1397 .extra1 = SYSCTL_ZERO,
1401 }, 1398 },
1402 { 1399 {
1403 .procname = "dirtytime_expire_seconds", 1400 .procname = "dirtytime_expire_seconds",
@@ -1405,7 +1402,7 @@ static struct ctl_table vm_table[] = {
1405 .maxlen = sizeof(dirtytime_expire_interval), 1402 .maxlen = sizeof(dirtytime_expire_interval),
1406 .mode = 0644, 1403 .mode = 0644,
1407 .proc_handler = dirtytime_interval_handler, 1404 .proc_handler = dirtytime_interval_handler,
1408 .extra1 = &zero, 1405 .extra1 = SYSCTL_ZERO,
1409 }, 1406 },
1410 { 1407 {
1411 .procname = "swappiness", 1408 .procname = "swappiness",
@@ -1413,7 +1410,7 @@ static struct ctl_table vm_table[] = {
1413 .maxlen = sizeof(vm_swappiness), 1410 .maxlen = sizeof(vm_swappiness),
1414 .mode = 0644, 1411 .mode = 0644,
1415 .proc_handler = proc_dointvec_minmax, 1412 .proc_handler = proc_dointvec_minmax,
1416 .extra1 = &zero, 1413 .extra1 = SYSCTL_ZERO,
1417 .extra2 = &one_hundred, 1414 .extra2 = &one_hundred,
1418 }, 1415 },
1419#ifdef CONFIG_HUGETLB_PAGE 1416#ifdef CONFIG_HUGETLB_PAGE
@@ -1438,8 +1435,8 @@ static struct ctl_table vm_table[] = {
1438 .maxlen = sizeof(int), 1435 .maxlen = sizeof(int),
1439 .mode = 0644, 1436 .mode = 0644,
1440 .proc_handler = sysctl_vm_numa_stat_handler, 1437 .proc_handler = sysctl_vm_numa_stat_handler,
1441 .extra1 = &zero, 1438 .extra1 = SYSCTL_ZERO,
1442 .extra2 = &one, 1439 .extra2 = SYSCTL_ONE,
1443 }, 1440 },
1444#endif 1441#endif
1445 { 1442 {
@@ -1470,7 +1467,7 @@ static struct ctl_table vm_table[] = {
1470 .maxlen = sizeof(int), 1467 .maxlen = sizeof(int),
1471 .mode = 0644, 1468 .mode = 0644,
1472 .proc_handler = drop_caches_sysctl_handler, 1469 .proc_handler = drop_caches_sysctl_handler,
1473 .extra1 = &one, 1470 .extra1 = SYSCTL_ONE,
1474 .extra2 = &four, 1471 .extra2 = &four,
1475 }, 1472 },
1476#ifdef CONFIG_COMPACTION 1473#ifdef CONFIG_COMPACTION
@@ -1496,8 +1493,8 @@ static struct ctl_table vm_table[] = {
1496 .maxlen = sizeof(int), 1493 .maxlen = sizeof(int),
1497 .mode = 0644, 1494 .mode = 0644,
1498 .proc_handler = proc_dointvec, 1495 .proc_handler = proc_dointvec,
1499 .extra1 = &zero, 1496 .extra1 = SYSCTL_ZERO,
1500 .extra2 = &one, 1497 .extra2 = SYSCTL_ONE,
1501 }, 1498 },
1502 1499
1503#endif /* CONFIG_COMPACTION */ 1500#endif /* CONFIG_COMPACTION */
@@ -1507,7 +1504,7 @@ static struct ctl_table vm_table[] = {
1507 .maxlen = sizeof(min_free_kbytes), 1504 .maxlen = sizeof(min_free_kbytes),
1508 .mode = 0644, 1505 .mode = 0644,
1509 .proc_handler = min_free_kbytes_sysctl_handler, 1506 .proc_handler = min_free_kbytes_sysctl_handler,
1510 .extra1 = &zero, 1507 .extra1 = SYSCTL_ZERO,
1511 }, 1508 },
1512 { 1509 {
1513 .procname = "watermark_boost_factor", 1510 .procname = "watermark_boost_factor",
@@ -1515,7 +1512,7 @@ static struct ctl_table vm_table[] = {
1515 .maxlen = sizeof(watermark_boost_factor), 1512 .maxlen = sizeof(watermark_boost_factor),
1516 .mode = 0644, 1513 .mode = 0644,
1517 .proc_handler = watermark_boost_factor_sysctl_handler, 1514 .proc_handler = watermark_boost_factor_sysctl_handler,
1518 .extra1 = &zero, 1515 .extra1 = SYSCTL_ZERO,
1519 }, 1516 },
1520 { 1517 {
1521 .procname = "watermark_scale_factor", 1518 .procname = "watermark_scale_factor",
@@ -1523,7 +1520,7 @@ static struct ctl_table vm_table[] = {
1523 .maxlen = sizeof(watermark_scale_factor), 1520 .maxlen = sizeof(watermark_scale_factor),
1524 .mode = 0644, 1521 .mode = 0644,
1525 .proc_handler = watermark_scale_factor_sysctl_handler, 1522 .proc_handler = watermark_scale_factor_sysctl_handler,
1526 .extra1 = &one, 1523 .extra1 = SYSCTL_ONE,
1527 .extra2 = &one_thousand, 1524 .extra2 = &one_thousand,
1528 }, 1525 },
1529 { 1526 {
@@ -1532,7 +1529,7 @@ static struct ctl_table vm_table[] = {
1532 .maxlen = sizeof(percpu_pagelist_fraction), 1529 .maxlen = sizeof(percpu_pagelist_fraction),
1533 .mode = 0644, 1530 .mode = 0644,
1534 .proc_handler = percpu_pagelist_fraction_sysctl_handler, 1531 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1535 .extra1 = &zero, 1532 .extra1 = SYSCTL_ZERO,
1536 }, 1533 },
1537#ifdef CONFIG_MMU 1534#ifdef CONFIG_MMU
1538 { 1535 {
@@ -1541,7 +1538,7 @@ static struct ctl_table vm_table[] = {
1541 .maxlen = sizeof(sysctl_max_map_count), 1538 .maxlen = sizeof(sysctl_max_map_count),
1542 .mode = 0644, 1539 .mode = 0644,
1543 .proc_handler = proc_dointvec_minmax, 1540 .proc_handler = proc_dointvec_minmax,
1544 .extra1 = &zero, 1541 .extra1 = SYSCTL_ZERO,
1545 }, 1542 },
1546#else 1543#else
1547 { 1544 {
@@ -1550,7 +1547,7 @@ static struct ctl_table vm_table[] = {
1550 .maxlen = sizeof(sysctl_nr_trim_pages), 1547 .maxlen = sizeof(sysctl_nr_trim_pages),
1551 .mode = 0644, 1548 .mode = 0644,
1552 .proc_handler = proc_dointvec_minmax, 1549 .proc_handler = proc_dointvec_minmax,
1553 .extra1 = &zero, 1550 .extra1 = SYSCTL_ZERO,
1554 }, 1551 },
1555#endif 1552#endif
1556 { 1553 {
@@ -1566,7 +1563,7 @@ static struct ctl_table vm_table[] = {
1566 .maxlen = sizeof(block_dump), 1563 .maxlen = sizeof(block_dump),
1567 .mode = 0644, 1564 .mode = 0644,
1568 .proc_handler = proc_dointvec, 1565 .proc_handler = proc_dointvec,
1569 .extra1 = &zero, 1566 .extra1 = SYSCTL_ZERO,
1570 }, 1567 },
1571 { 1568 {
1572 .procname = "vfs_cache_pressure", 1569 .procname = "vfs_cache_pressure",
@@ -1574,7 +1571,7 @@ static struct ctl_table vm_table[] = {
1574 .maxlen = sizeof(sysctl_vfs_cache_pressure), 1571 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1575 .mode = 0644, 1572 .mode = 0644,
1576 .proc_handler = proc_dointvec, 1573 .proc_handler = proc_dointvec,
1577 .extra1 = &zero, 1574 .extra1 = SYSCTL_ZERO,
1578 }, 1575 },
1579#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 1576#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1580 { 1577 {
@@ -1583,7 +1580,7 @@ static struct ctl_table vm_table[] = {
1583 .maxlen = sizeof(sysctl_legacy_va_layout), 1580 .maxlen = sizeof(sysctl_legacy_va_layout),
1584 .mode = 0644, 1581 .mode = 0644,
1585 .proc_handler = proc_dointvec, 1582 .proc_handler = proc_dointvec,
1586 .extra1 = &zero, 1583 .extra1 = SYSCTL_ZERO,
1587 }, 1584 },
1588#endif 1585#endif
1589#ifdef CONFIG_NUMA 1586#ifdef CONFIG_NUMA
@@ -1593,7 +1590,7 @@ static struct ctl_table vm_table[] = {
1593 .maxlen = sizeof(node_reclaim_mode), 1590 .maxlen = sizeof(node_reclaim_mode),
1594 .mode = 0644, 1591 .mode = 0644,
1595 .proc_handler = proc_dointvec, 1592 .proc_handler = proc_dointvec,
1596 .extra1 = &zero, 1593 .extra1 = SYSCTL_ZERO,
1597 }, 1594 },
1598 { 1595 {
1599 .procname = "min_unmapped_ratio", 1596 .procname = "min_unmapped_ratio",
@@ -1601,7 +1598,7 @@ static struct ctl_table vm_table[] = {
1601 .maxlen = sizeof(sysctl_min_unmapped_ratio), 1598 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1602 .mode = 0644, 1599 .mode = 0644,
1603 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 1600 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1604 .extra1 = &zero, 1601 .extra1 = SYSCTL_ZERO,
1605 .extra2 = &one_hundred, 1602 .extra2 = &one_hundred,
1606 }, 1603 },
1607 { 1604 {
@@ -1610,7 +1607,7 @@ static struct ctl_table vm_table[] = {
1610 .maxlen = sizeof(sysctl_min_slab_ratio), 1607 .maxlen = sizeof(sysctl_min_slab_ratio),
1611 .mode = 0644, 1608 .mode = 0644,
1612 .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 1609 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1613 .extra1 = &zero, 1610 .extra1 = SYSCTL_ZERO,
1614 .extra2 = &one_hundred, 1611 .extra2 = &one_hundred,
1615 }, 1612 },
1616#endif 1613#endif
@@ -1661,7 +1658,7 @@ static struct ctl_table vm_table[] = {
1661#endif 1658#endif
1662 .mode = 0644, 1659 .mode = 0644,
1663 .proc_handler = proc_dointvec, 1660 .proc_handler = proc_dointvec,
1664 .extra1 = &zero, 1661 .extra1 = SYSCTL_ZERO,
1665 }, 1662 },
1666#endif 1663#endif
1667#ifdef CONFIG_HIGHMEM 1664#ifdef CONFIG_HIGHMEM
@@ -1671,8 +1668,8 @@ static struct ctl_table vm_table[] = {
1671 .maxlen = sizeof(vm_highmem_is_dirtyable), 1668 .maxlen = sizeof(vm_highmem_is_dirtyable),
1672 .mode = 0644, 1669 .mode = 0644,
1673 .proc_handler = proc_dointvec_minmax, 1670 .proc_handler = proc_dointvec_minmax,
1674 .extra1 = &zero, 1671 .extra1 = SYSCTL_ZERO,
1675 .extra2 = &one, 1672 .extra2 = SYSCTL_ONE,
1676 }, 1673 },
1677#endif 1674#endif
1678#ifdef CONFIG_MEMORY_FAILURE 1675#ifdef CONFIG_MEMORY_FAILURE
@@ -1682,8 +1679,8 @@ static struct ctl_table vm_table[] = {
1682 .maxlen = sizeof(sysctl_memory_failure_early_kill), 1679 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1683 .mode = 0644, 1680 .mode = 0644,
1684 .proc_handler = proc_dointvec_minmax, 1681 .proc_handler = proc_dointvec_minmax,
1685 .extra1 = &zero, 1682 .extra1 = SYSCTL_ZERO,
1686 .extra2 = &one, 1683 .extra2 = SYSCTL_ONE,
1687 }, 1684 },
1688 { 1685 {
1689 .procname = "memory_failure_recovery", 1686 .procname = "memory_failure_recovery",
@@ -1691,8 +1688,8 @@ static struct ctl_table vm_table[] = {
1691 .maxlen = sizeof(sysctl_memory_failure_recovery), 1688 .maxlen = sizeof(sysctl_memory_failure_recovery),
1692 .mode = 0644, 1689 .mode = 0644,
1693 .proc_handler = proc_dointvec_minmax, 1690 .proc_handler = proc_dointvec_minmax,
1694 .extra1 = &zero, 1691 .extra1 = SYSCTL_ZERO,
1695 .extra2 = &one, 1692 .extra2 = SYSCTL_ONE,
1696 }, 1693 },
1697#endif 1694#endif
1698 { 1695 {
@@ -1738,8 +1735,8 @@ static struct ctl_table vm_table[] = {
1738 .maxlen = sizeof(sysctl_unprivileged_userfaultfd), 1735 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1739 .mode = 0644, 1736 .mode = 0644,
1740 .proc_handler = proc_dointvec_minmax, 1737 .proc_handler = proc_dointvec_minmax,
1741 .extra1 = &zero, 1738 .extra1 = SYSCTL_ZERO,
1742 .extra2 = &one, 1739 .extra2 = SYSCTL_ONE,
1743 }, 1740 },
1744#endif 1741#endif
1745 { } 1742 { }
@@ -1875,8 +1872,8 @@ static struct ctl_table fs_table[] = {
1875 .maxlen = sizeof(int), 1872 .maxlen = sizeof(int),
1876 .mode = 0600, 1873 .mode = 0600,
1877 .proc_handler = proc_dointvec_minmax, 1874 .proc_handler = proc_dointvec_minmax,
1878 .extra1 = &zero, 1875 .extra1 = SYSCTL_ZERO,
1879 .extra2 = &one, 1876 .extra2 = SYSCTL_ONE,
1880 }, 1877 },
1881 { 1878 {
1882 .procname = "protected_hardlinks", 1879 .procname = "protected_hardlinks",
@@ -1884,8 +1881,8 @@ static struct ctl_table fs_table[] = {
1884 .maxlen = sizeof(int), 1881 .maxlen = sizeof(int),
1885 .mode = 0600, 1882 .mode = 0600,
1886 .proc_handler = proc_dointvec_minmax, 1883 .proc_handler = proc_dointvec_minmax,
1887 .extra1 = &zero, 1884 .extra1 = SYSCTL_ZERO,
1888 .extra2 = &one, 1885 .extra2 = SYSCTL_ONE,
1889 }, 1886 },
1890 { 1887 {
1891 .procname = "protected_fifos", 1888 .procname = "protected_fifos",
@@ -1893,7 +1890,7 @@ static struct ctl_table fs_table[] = {
1893 .maxlen = sizeof(int), 1890 .maxlen = sizeof(int),
1894 .mode = 0600, 1891 .mode = 0600,
1895 .proc_handler = proc_dointvec_minmax, 1892 .proc_handler = proc_dointvec_minmax,
1896 .extra1 = &zero, 1893 .extra1 = SYSCTL_ZERO,
1897 .extra2 = &two, 1894 .extra2 = &two,
1898 }, 1895 },
1899 { 1896 {
@@ -1902,7 +1899,7 @@ static struct ctl_table fs_table[] = {
1902 .maxlen = sizeof(int), 1899 .maxlen = sizeof(int),
1903 .mode = 0600, 1900 .mode = 0600,
1904 .proc_handler = proc_dointvec_minmax, 1901 .proc_handler = proc_dointvec_minmax,
1905 .extra1 = &zero, 1902 .extra1 = SYSCTL_ZERO,
1906 .extra2 = &two, 1903 .extra2 = &two,
1907 }, 1904 },
1908 { 1905 {
@@ -1911,7 +1908,7 @@ static struct ctl_table fs_table[] = {
1911 .maxlen = sizeof(int), 1908 .maxlen = sizeof(int),
1912 .mode = 0644, 1909 .mode = 0644,
1913 .proc_handler = proc_dointvec_minmax_coredump, 1910 .proc_handler = proc_dointvec_minmax_coredump,
1914 .extra1 = &zero, 1911 .extra1 = SYSCTL_ZERO,
1915 .extra2 = &two, 1912 .extra2 = &two,
1916 }, 1913 },
1917#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1914#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
@@ -1948,7 +1945,7 @@ static struct ctl_table fs_table[] = {
1948 .maxlen = sizeof(unsigned int), 1945 .maxlen = sizeof(unsigned int),
1949 .mode = 0644, 1946 .mode = 0644,
1950 .proc_handler = proc_dointvec_minmax, 1947 .proc_handler = proc_dointvec_minmax,
1951 .extra1 = &one, 1948 .extra1 = SYSCTL_ONE,
1952 }, 1949 },
1953 { } 1950 { }
1954}; 1951};
@@ -1970,8 +1967,8 @@ static struct ctl_table debug_table[] = {
1970 .maxlen = sizeof(int), 1967 .maxlen = sizeof(int),
1971 .mode = 0644, 1968 .mode = 0644,
1972 .proc_handler = proc_kprobes_optimization_handler, 1969 .proc_handler = proc_kprobes_optimization_handler,
1973 .extra1 = &zero, 1970 .extra1 = SYSCTL_ZERO,
1974 .extra2 = &one, 1971 .extra2 = SYSCTL_ONE,
1975 }, 1972 },
1976#endif 1973#endif
1977 { } 1974 { }
@@ -3395,8 +3392,8 @@ int proc_do_static_key(struct ctl_table *table, int write,
3395 .data = &val, 3392 .data = &val,
3396 .maxlen = sizeof(val), 3393 .maxlen = sizeof(val),
3397 .mode = table->mode, 3394 .mode = table->mode,
3398 .extra1 = &zero, 3395 .extra1 = SYSCTL_ZERO,
3399 .extra2 = &one, 3396 .extra2 = SYSCTL_ONE,
3400 }; 3397 };
3401 3398
3402 if (write && !capable(CAP_SYS_ADMIN)) 3399 if (write && !capable(CAP_SYS_ADMIN))
diff --git a/kernel/ucount.c b/kernel/ucount.c
index feb128c7b5d9..a53cc2b4179c 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -52,16 +52,14 @@ static struct ctl_table_root set_root = {
52 .permissions = set_permissions, 52 .permissions = set_permissions,
53}; 53};
54 54
55static int zero = 0;
56static int int_max = INT_MAX;
57#define UCOUNT_ENTRY(name) \ 55#define UCOUNT_ENTRY(name) \
58 { \ 56 { \
59 .procname = name, \ 57 .procname = name, \
60 .maxlen = sizeof(int), \ 58 .maxlen = sizeof(int), \
61 .mode = 0644, \ 59 .mode = 0644, \
62 .proc_handler = proc_dointvec_minmax, \ 60 .proc_handler = proc_dointvec_minmax, \
63 .extra1 = &zero, \ 61 .extra1 = SYSCTL_ZERO, \
64 .extra2 = &int_max, \ 62 .extra2 = SYSCTL_INT_MAX, \
65 } 63 }
66static struct ctl_table user_table[] = { 64static struct ctl_table user_table[] = {
67 UCOUNT_ENTRY("max_user_namespaces"), 65 UCOUNT_ENTRY("max_user_namespaces"),
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 885642c82aaa..1334ede667a8 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -63,10 +63,15 @@ struct page *huge_zero_page __read_mostly;
63 63
64bool transparent_hugepage_enabled(struct vm_area_struct *vma) 64bool transparent_hugepage_enabled(struct vm_area_struct *vma)
65{ 65{
66 /* The addr is used to check if the vma size fits */
67 unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE;
68
69 if (!transhuge_vma_suitable(vma, addr))
70 return false;
66 if (vma_is_anonymous(vma)) 71 if (vma_is_anonymous(vma))
67 return __transparent_hugepage_enabled(vma); 72 return __transparent_hugepage_enabled(vma);
68 if (vma_is_shmem(vma) && shmem_huge_enabled(vma)) 73 if (vma_is_shmem(vma))
69 return __transparent_hugepage_enabled(vma); 74 return shmem_huge_enabled(vma);
70 75
71 return false; 76 return false;
72} 77}
@@ -689,7 +694,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
689 struct page *page; 694 struct page *page;
690 unsigned long haddr = vmf->address & HPAGE_PMD_MASK; 695 unsigned long haddr = vmf->address & HPAGE_PMD_MASK;
691 696
692 if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) 697 if (!transhuge_vma_suitable(vma, haddr))
693 return VM_FAULT_FALLBACK; 698 return VM_FAULT_FALLBACK;
694 if (unlikely(anon_vma_prepare(vma))) 699 if (unlikely(anon_vma_prepare(vma)))
695 return VM_FAULT_OOM; 700 return VM_FAULT_OOM;
diff --git a/mm/memory.c b/mm/memory.c
index 89325f9c6173..e2bb51b6242e 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3162,19 +3162,6 @@ map_pte:
3162} 3162}
3163 3163
3164#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE 3164#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
3165
3166#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1)
3167static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
3168 unsigned long haddr)
3169{
3170 if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) !=
3171 (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK))
3172 return false;
3173 if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end)
3174 return false;
3175 return true;
3176}
3177
3178static void deposit_prealloc_pte(struct vm_fault *vmf) 3165static void deposit_prealloc_pte(struct vm_fault *vmf)
3179{ 3166{
3180 struct vm_area_struct *vma = vmf->vma; 3167 struct vm_area_struct *vma = vmf->vma;
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 4ebe696138e8..2a9bbddb0e55 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -166,9 +166,10 @@ void put_page_bootmem(struct page *page)
166#ifndef CONFIG_SPARSEMEM_VMEMMAP 166#ifndef CONFIG_SPARSEMEM_VMEMMAP
167static void register_page_bootmem_info_section(unsigned long start_pfn) 167static void register_page_bootmem_info_section(unsigned long start_pfn)
168{ 168{
169 unsigned long *usemap, mapsize, section_nr, i; 169 unsigned long mapsize, section_nr, i;
170 struct mem_section *ms; 170 struct mem_section *ms;
171 struct page *page, *memmap; 171 struct page *page, *memmap;
172 struct mem_section_usage *usage;
172 173
173 section_nr = pfn_to_section_nr(start_pfn); 174 section_nr = pfn_to_section_nr(start_pfn);
174 ms = __nr_to_section(section_nr); 175 ms = __nr_to_section(section_nr);
@@ -188,10 +189,10 @@ static void register_page_bootmem_info_section(unsigned long start_pfn)
188 for (i = 0; i < mapsize; i++, page++) 189 for (i = 0; i < mapsize; i++, page++)
189 get_page_bootmem(section_nr, page, SECTION_INFO); 190 get_page_bootmem(section_nr, page, SECTION_INFO);
190 191
191 usemap = ms->pageblock_flags; 192 usage = ms->usage;
192 page = virt_to_page(usemap); 193 page = virt_to_page(usage);
193 194
194 mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; 195 mapsize = PAGE_ALIGN(mem_section_usage_size()) >> PAGE_SHIFT;
195 196
196 for (i = 0; i < mapsize; i++, page++) 197 for (i = 0; i < mapsize; i++, page++)
197 get_page_bootmem(section_nr, page, MIX_SECTION_INFO); 198 get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
@@ -200,9 +201,10 @@ static void register_page_bootmem_info_section(unsigned long start_pfn)
200#else /* CONFIG_SPARSEMEM_VMEMMAP */ 201#else /* CONFIG_SPARSEMEM_VMEMMAP */
201static void register_page_bootmem_info_section(unsigned long start_pfn) 202static void register_page_bootmem_info_section(unsigned long start_pfn)
202{ 203{
203 unsigned long *usemap, mapsize, section_nr, i; 204 unsigned long mapsize, section_nr, i;
204 struct mem_section *ms; 205 struct mem_section *ms;
205 struct page *page, *memmap; 206 struct page *page, *memmap;
207 struct mem_section_usage *usage;
206 208
207 section_nr = pfn_to_section_nr(start_pfn); 209 section_nr = pfn_to_section_nr(start_pfn);
208 ms = __nr_to_section(section_nr); 210 ms = __nr_to_section(section_nr);
@@ -211,10 +213,10 @@ static void register_page_bootmem_info_section(unsigned long start_pfn)
211 213
212 register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); 214 register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION);
213 215
214 usemap = ms->pageblock_flags; 216 usage = ms->usage;
215 page = virt_to_page(usemap); 217 page = virt_to_page(usage);
216 218
217 mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; 219 mapsize = PAGE_ALIGN(mem_section_usage_size()) >> PAGE_SHIFT;
218 220
219 for (i = 0; i < mapsize; i++, page++) 221 for (i = 0; i < mapsize; i++, page++)
220 get_page_bootmem(section_nr, page, MIX_SECTION_INFO); 222 get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
@@ -250,22 +252,31 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
250} 252}
251#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */ 253#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */
252 254
253static int __meminit __add_section(int nid, unsigned long phys_start_pfn, 255static int check_pfn_span(unsigned long pfn, unsigned long nr_pages,
254 struct vmem_altmap *altmap, bool want_memblock) 256 const char *reason)
255{ 257{
256 int ret; 258 /*
257 259 * Disallow all operations smaller than a sub-section and only
258 if (pfn_valid(phys_start_pfn)) 260 * allow operations smaller than a section for
259 return -EEXIST; 261 * SPARSEMEM_VMEMMAP. Note that check_hotplug_memory_range()
260 262 * enforces a larger memory_block_size_bytes() granularity for
261 ret = sparse_add_one_section(nid, phys_start_pfn, altmap); 263 * memory that will be marked online, so this check should only
262 if (ret < 0) 264 * fire for direct arch_{add,remove}_memory() users outside of
263 return ret; 265 * add_memory_resource().
264 266 */
265 if (!want_memblock) 267 unsigned long min_align;
266 return 0; 268
267 269 if (IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP))
268 return hotplug_memory_register(nid, __pfn_to_section(phys_start_pfn)); 270 min_align = PAGES_PER_SUBSECTION;
271 else
272 min_align = PAGES_PER_SECTION;
273 if (!IS_ALIGNED(pfn, min_align)
274 || !IS_ALIGNED(nr_pages, min_align)) {
275 WARN(1, "Misaligned __%s_pages start: %#lx end: #%lx\n",
276 reason, pfn, pfn + nr_pages - 1);
277 return -EINVAL;
278 }
279 return 0;
269} 280}
270 281
271/* 282/*
@@ -274,62 +285,54 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn,
274 * call this function after deciding the zone to which to 285 * call this function after deciding the zone to which to
275 * add the new pages. 286 * add the new pages.
276 */ 287 */
277int __ref __add_pages(int nid, unsigned long phys_start_pfn, 288int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,
278 unsigned long nr_pages, struct mhp_restrictions *restrictions) 289 struct mhp_restrictions *restrictions)
279{ 290{
280 unsigned long i; 291 int err;
281 int err = 0; 292 unsigned long nr, start_sec, end_sec;
282 int start_sec, end_sec;
283 struct vmem_altmap *altmap = restrictions->altmap; 293 struct vmem_altmap *altmap = restrictions->altmap;
284 294
285 /* during initialize mem_map, align hot-added range to section */
286 start_sec = pfn_to_section_nr(phys_start_pfn);
287 end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1);
288
289 if (altmap) { 295 if (altmap) {
290 /* 296 /*
291 * Validate altmap is within bounds of the total request 297 * Validate altmap is within bounds of the total request
292 */ 298 */
293 if (altmap->base_pfn != phys_start_pfn 299 if (altmap->base_pfn != pfn
294 || vmem_altmap_offset(altmap) > nr_pages) { 300 || vmem_altmap_offset(altmap) > nr_pages) {
295 pr_warn_once("memory add fail, invalid altmap\n"); 301 pr_warn_once("memory add fail, invalid altmap\n");
296 err = -EINVAL; 302 return -EINVAL;
297 goto out;
298 } 303 }
299 altmap->alloc = 0; 304 altmap->alloc = 0;
300 } 305 }
301 306
302 for (i = start_sec; i <= end_sec; i++) { 307 err = check_pfn_span(pfn, nr_pages, "add");
303 err = __add_section(nid, section_nr_to_pfn(i), altmap, 308 if (err)
304 restrictions->flags & MHP_MEMBLOCK_API); 309 return err;
305 310
306 /* 311 start_sec = pfn_to_section_nr(pfn);
307 * EEXIST is finally dealt with by ioresource collision 312 end_sec = pfn_to_section_nr(pfn + nr_pages - 1);
308 * check. see add_memory() => register_memory_resource() 313 for (nr = start_sec; nr <= end_sec; nr++) {
309 * Warning will be printed if there is collision. 314 unsigned long pfns;
310 */ 315
311 if (err && (err != -EEXIST)) 316 pfns = min(nr_pages, PAGES_PER_SECTION
317 - (pfn & ~PAGE_SECTION_MASK));
318 err = sparse_add_section(nid, pfn, pfns, altmap);
319 if (err)
312 break; 320 break;
313 err = 0; 321 pfn += pfns;
322 nr_pages -= pfns;
314 cond_resched(); 323 cond_resched();
315 } 324 }
316 vmemmap_populate_print_last(); 325 vmemmap_populate_print_last();
317out:
318 return err; 326 return err;
319} 327}
320 328
321#ifdef CONFIG_MEMORY_HOTREMOVE
322/* find the smallest valid pfn in the range [start_pfn, end_pfn) */ 329/* find the smallest valid pfn in the range [start_pfn, end_pfn) */
323static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, 330static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
324 unsigned long start_pfn, 331 unsigned long start_pfn,
325 unsigned long end_pfn) 332 unsigned long end_pfn)
326{ 333{
327 struct mem_section *ms; 334 for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SUBSECTION) {
328 335 if (unlikely(!pfn_valid(start_pfn)))
329 for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) {
330 ms = __pfn_to_section(start_pfn);
331
332 if (unlikely(!valid_section(ms)))
333 continue; 336 continue;
334 337
335 if (unlikely(pfn_to_nid(start_pfn) != nid)) 338 if (unlikely(pfn_to_nid(start_pfn) != nid))
@@ -349,15 +352,12 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
349 unsigned long start_pfn, 352 unsigned long start_pfn,
350 unsigned long end_pfn) 353 unsigned long end_pfn)
351{ 354{
352 struct mem_section *ms;
353 unsigned long pfn; 355 unsigned long pfn;
354 356
355 /* pfn is the end pfn of a memory section. */ 357 /* pfn is the end pfn of a memory section. */
356 pfn = end_pfn - 1; 358 pfn = end_pfn - 1;
357 for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) { 359 for (; pfn >= start_pfn; pfn -= PAGES_PER_SUBSECTION) {
358 ms = __pfn_to_section(pfn); 360 if (unlikely(!pfn_valid(pfn)))
359
360 if (unlikely(!valid_section(ms)))
361 continue; 361 continue;
362 362
363 if (unlikely(pfn_to_nid(pfn) != nid)) 363 if (unlikely(pfn_to_nid(pfn) != nid))
@@ -379,7 +379,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
379 unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */ 379 unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */
380 unsigned long zone_end_pfn = z; 380 unsigned long zone_end_pfn = z;
381 unsigned long pfn; 381 unsigned long pfn;
382 struct mem_section *ms;
383 int nid = zone_to_nid(zone); 382 int nid = zone_to_nid(zone);
384 383
385 zone_span_writelock(zone); 384 zone_span_writelock(zone);
@@ -416,17 +415,15 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
416 * it check the zone has only hole or not. 415 * it check the zone has only hole or not.
417 */ 416 */
418 pfn = zone_start_pfn; 417 pfn = zone_start_pfn;
419 for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { 418 for (; pfn < zone_end_pfn; pfn += PAGES_PER_SUBSECTION) {
420 ms = __pfn_to_section(pfn); 419 if (unlikely(!pfn_valid(pfn)))
421
422 if (unlikely(!valid_section(ms)))
423 continue; 420 continue;
424 421
425 if (page_zone(pfn_to_page(pfn)) != zone) 422 if (page_zone(pfn_to_page(pfn)) != zone)
426 continue; 423 continue;
427 424
428 /* If the section is current section, it continues the loop */ 425 /* Skip range to be removed */
429 if (start_pfn == pfn) 426 if (pfn >= start_pfn && pfn < end_pfn)
430 continue; 427 continue;
431 428
432 /* If we find valid section, we have nothing to do */ 429 /* If we find valid section, we have nothing to do */
@@ -447,7 +444,6 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
447 unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */ 444 unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */
448 unsigned long pgdat_end_pfn = p; 445 unsigned long pgdat_end_pfn = p;
449 unsigned long pfn; 446 unsigned long pfn;
450 struct mem_section *ms;
451 int nid = pgdat->node_id; 447 int nid = pgdat->node_id;
452 448
453 if (pgdat_start_pfn == start_pfn) { 449 if (pgdat_start_pfn == start_pfn) {
@@ -484,17 +480,15 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
484 * has only hole or not. 480 * has only hole or not.
485 */ 481 */
486 pfn = pgdat_start_pfn; 482 pfn = pgdat_start_pfn;
487 for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) { 483 for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SUBSECTION) {
488 ms = __pfn_to_section(pfn); 484 if (unlikely(!pfn_valid(pfn)))
489
490 if (unlikely(!valid_section(ms)))
491 continue; 485 continue;
492 486
493 if (pfn_to_nid(pfn) != nid) 487 if (pfn_to_nid(pfn) != nid)
494 continue; 488 continue;
495 489
496 /* If the section is current section, it continues the loop */ 490 /* Skip range to be removed */
497 if (start_pfn == pfn) 491 if (pfn >= start_pfn && pfn < end_pfn)
498 continue; 492 continue;
499 493
500 /* If we find valid section, we have nothing to do */ 494 /* If we find valid section, we have nothing to do */
@@ -506,10 +500,10 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
506 pgdat->node_spanned_pages = 0; 500 pgdat->node_spanned_pages = 0;
507} 501}
508 502
509static void __remove_zone(struct zone *zone, unsigned long start_pfn) 503static void __remove_zone(struct zone *zone, unsigned long start_pfn,
504 unsigned long nr_pages)
510{ 505{
511 struct pglist_data *pgdat = zone->zone_pgdat; 506 struct pglist_data *pgdat = zone->zone_pgdat;
512 int nr_pages = PAGES_PER_SECTION;
513 unsigned long flags; 507 unsigned long flags;
514 508
515 pgdat_resize_lock(zone->zone_pgdat, &flags); 509 pgdat_resize_lock(zone->zone_pgdat, &flags);
@@ -518,29 +512,23 @@ static void __remove_zone(struct zone *zone, unsigned long start_pfn)
518 pgdat_resize_unlock(zone->zone_pgdat, &flags); 512 pgdat_resize_unlock(zone->zone_pgdat, &flags);
519} 513}
520 514
521static void __remove_section(struct zone *zone, struct mem_section *ms, 515static void __remove_section(struct zone *zone, unsigned long pfn,
522 unsigned long map_offset, 516 unsigned long nr_pages, unsigned long map_offset,
523 struct vmem_altmap *altmap) 517 struct vmem_altmap *altmap)
524{ 518{
525 unsigned long start_pfn; 519 struct mem_section *ms = __nr_to_section(pfn_to_section_nr(pfn));
526 int scn_nr;
527 520
528 if (WARN_ON_ONCE(!valid_section(ms))) 521 if (WARN_ON_ONCE(!valid_section(ms)))
529 return; 522 return;
530 523
531 unregister_memory_section(ms); 524 __remove_zone(zone, pfn, nr_pages);
532 525 sparse_remove_section(ms, pfn, nr_pages, map_offset, altmap);
533 scn_nr = __section_nr(ms);
534 start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
535 __remove_zone(zone, start_pfn);
536
537 sparse_remove_one_section(zone, ms, map_offset, altmap);
538} 526}
539 527
540/** 528/**
541 * __remove_pages() - remove sections of pages from a zone 529 * __remove_pages() - remove sections of pages from a zone
542 * @zone: zone from which pages need to be removed 530 * @zone: zone from which pages need to be removed
543 * @phys_start_pfn: starting pageframe (must be aligned to start of a section) 531 * @pfn: starting pageframe (must be aligned to start of a section)
544 * @nr_pages: number of pages to remove (must be multiple of section size) 532 * @nr_pages: number of pages to remove (must be multiple of section size)
545 * @altmap: alternative device page map or %NULL if default memmap is used 533 * @altmap: alternative device page map or %NULL if default memmap is used
546 * 534 *
@@ -549,38 +537,35 @@ static void __remove_section(struct zone *zone, struct mem_section *ms,
549 * sure that pages are marked reserved and zones are adjust properly by 537 * sure that pages are marked reserved and zones are adjust properly by
550 * calling offline_pages(). 538 * calling offline_pages().
551 */ 539 */
552void __remove_pages(struct zone *zone, unsigned long phys_start_pfn, 540void __remove_pages(struct zone *zone, unsigned long pfn,
553 unsigned long nr_pages, struct vmem_altmap *altmap) 541 unsigned long nr_pages, struct vmem_altmap *altmap)
554{ 542{
555 unsigned long i;
556 unsigned long map_offset = 0; 543 unsigned long map_offset = 0;
557 int sections_to_remove; 544 unsigned long nr, start_sec, end_sec;
558 545
559 /* In the ZONE_DEVICE case device driver owns the memory region */ 546 map_offset = vmem_altmap_offset(altmap);
560 if (is_dev_zone(zone))
561 map_offset = vmem_altmap_offset(altmap);
562 547
563 clear_zone_contiguous(zone); 548 clear_zone_contiguous(zone);
564 549
565 /* 550 if (check_pfn_span(pfn, nr_pages, "remove"))
566 * We can only remove entire sections 551 return;
567 */
568 BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
569 BUG_ON(nr_pages % PAGES_PER_SECTION);
570 552
571 sections_to_remove = nr_pages / PAGES_PER_SECTION; 553 start_sec = pfn_to_section_nr(pfn);
572 for (i = 0; i < sections_to_remove; i++) { 554 end_sec = pfn_to_section_nr(pfn + nr_pages - 1);
573 unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; 555 for (nr = start_sec; nr <= end_sec; nr++) {
556 unsigned long pfns;
574 557
575 cond_resched(); 558 cond_resched();
576 __remove_section(zone, __pfn_to_section(pfn), map_offset, 559 pfns = min(nr_pages, PAGES_PER_SECTION
577 altmap); 560 - (pfn & ~PAGE_SECTION_MASK));
561 __remove_section(zone, pfn, pfns, map_offset, altmap);
562 pfn += pfns;
563 nr_pages -= pfns;
578 map_offset = 0; 564 map_offset = 0;
579 } 565 }
580 566
581 set_zone_contiguous(zone); 567 set_zone_contiguous(zone);
582} 568}
583#endif /* CONFIG_MEMORY_HOTREMOVE */
584 569
585int set_online_page_callback(online_page_callback_t callback) 570int set_online_page_callback(online_page_callback_t callback)
586{ 571{
@@ -1049,16 +1034,11 @@ int try_online_node(int nid)
1049 1034
1050static int check_hotplug_memory_range(u64 start, u64 size) 1035static int check_hotplug_memory_range(u64 start, u64 size)
1051{ 1036{
1052 unsigned long block_sz = memory_block_size_bytes();
1053 u64 block_nr_pages = block_sz >> PAGE_SHIFT;
1054 u64 nr_pages = size >> PAGE_SHIFT;
1055 u64 start_pfn = PFN_DOWN(start);
1056
1057 /* memory range must be block size aligned */ 1037 /* memory range must be block size aligned */
1058 if (!nr_pages || !IS_ALIGNED(start_pfn, block_nr_pages) || 1038 if (!size || !IS_ALIGNED(start, memory_block_size_bytes()) ||
1059 !IS_ALIGNED(nr_pages, block_nr_pages)) { 1039 !IS_ALIGNED(size, memory_block_size_bytes())) {
1060 pr_err("Block size [%#lx] unaligned hotplug range: start %#llx, size %#llx", 1040 pr_err("Block size [%#lx] unaligned hotplug range: start %#llx, size %#llx",
1061 block_sz, start, size); 1041 memory_block_size_bytes(), start, size);
1062 return -EINVAL; 1042 return -EINVAL;
1063 } 1043 }
1064 1044
@@ -1078,9 +1058,7 @@ static int online_memory_block(struct memory_block *mem, void *arg)
1078 */ 1058 */
1079int __ref add_memory_resource(int nid, struct resource *res) 1059int __ref add_memory_resource(int nid, struct resource *res)
1080{ 1060{
1081 struct mhp_restrictions restrictions = { 1061 struct mhp_restrictions restrictions = {};
1082 .flags = MHP_MEMBLOCK_API,
1083 };
1084 u64 start, size; 1062 u64 start, size;
1085 bool new_node = false; 1063 bool new_node = false;
1086 int ret; 1064 int ret;
@@ -1112,6 +1090,13 @@ int __ref add_memory_resource(int nid, struct resource *res)
1112 if (ret < 0) 1090 if (ret < 0)
1113 goto error; 1091 goto error;
1114 1092
1093 /* create memory block devices after memory was added */
1094 ret = create_memory_block_devices(start, size);
1095 if (ret) {
1096 arch_remove_memory(nid, start, size, NULL);
1097 goto error;
1098 }
1099
1115 if (new_node) { 1100 if (new_node) {
1116 /* If sysfs file of new node can't be created, cpu on the node 1101 /* If sysfs file of new node can't be created, cpu on the node
1117 * can't be hot-added. There is no rollback way now. 1102 * can't be hot-added. There is no rollback way now.
@@ -1135,8 +1120,7 @@ int __ref add_memory_resource(int nid, struct resource *res)
1135 1120
1136 /* online pages if requested */ 1121 /* online pages if requested */
1137 if (memhp_auto_online) 1122 if (memhp_auto_online)
1138 walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), 1123 walk_memory_blocks(start, size, NULL, online_memory_block);
1139 NULL, online_memory_block);
1140 1124
1141 return ret; 1125 return ret;
1142error: 1126error:
@@ -1671,58 +1655,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
1671{ 1655{
1672 return __offline_pages(start_pfn, start_pfn + nr_pages); 1656 return __offline_pages(start_pfn, start_pfn + nr_pages);
1673} 1657}
1674#endif /* CONFIG_MEMORY_HOTREMOVE */
1675 1658
1676/**
1677 * walk_memory_range - walks through all mem sections in [start_pfn, end_pfn)
1678 * @start_pfn: start pfn of the memory range
1679 * @end_pfn: end pfn of the memory range
1680 * @arg: argument passed to func
1681 * @func: callback for each memory section walked
1682 *
1683 * This function walks through all present mem sections in range
1684 * [start_pfn, end_pfn) and call func on each mem section.
1685 *
1686 * Returns the return value of func.
1687 */
1688int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
1689 void *arg, int (*func)(struct memory_block *, void *))
1690{
1691 struct memory_block *mem = NULL;
1692 struct mem_section *section;
1693 unsigned long pfn, section_nr;
1694 int ret;
1695
1696 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
1697 section_nr = pfn_to_section_nr(pfn);
1698 if (!present_section_nr(section_nr))
1699 continue;
1700
1701 section = __nr_to_section(section_nr);
1702 /* same memblock? */
1703 if (mem)
1704 if ((section_nr >= mem->start_section_nr) &&
1705 (section_nr <= mem->end_section_nr))
1706 continue;
1707
1708 mem = find_memory_block_hinted(section, mem);
1709 if (!mem)
1710 continue;
1711
1712 ret = func(mem, arg);
1713 if (ret) {
1714 kobject_put(&mem->dev.kobj);
1715 return ret;
1716 }
1717 }
1718
1719 if (mem)
1720 kobject_put(&mem->dev.kobj);
1721
1722 return 0;
1723}
1724
1725#ifdef CONFIG_MEMORY_HOTREMOVE
1726static int check_memblock_offlined_cb(struct memory_block *mem, void *arg) 1659static int check_memblock_offlined_cb(struct memory_block *mem, void *arg)
1727{ 1660{
1728 int ret = !is_memblock_offlined(mem); 1661 int ret = !is_memblock_offlined(mem);
@@ -1833,8 +1766,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
1833 * whether all memory blocks in question are offline and return error 1766 * whether all memory blocks in question are offline and return error
1834 * if this is not the case. 1767 * if this is not the case.
1835 */ 1768 */
1836 rc = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL, 1769 rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
1837 check_memblock_offlined_cb);
1838 if (rc) 1770 if (rc)
1839 goto done; 1771 goto done;
1840 1772
@@ -1843,6 +1775,9 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
1843 memblock_free(start, size); 1775 memblock_free(start, size);
1844 memblock_remove(start, size); 1776 memblock_remove(start, size);
1845 1777
1778 /* remove memory block devices before removing memory */
1779 remove_memory_block_devices(start, size);
1780
1846 arch_remove_memory(nid, start, size, NULL); 1781 arch_remove_memory(nid, start, size, NULL);
1847 __release_memory_resource(start, size); 1782 __release_memory_resource(start, size);
1848 1783
diff --git a/mm/migrate.c b/mm/migrate.c
index 3445747e229d..8992741f10aa 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -394,8 +394,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page)
394 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set. 394 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set.
395 */ 395 */
396int migrate_page_move_mapping(struct address_space *mapping, 396int migrate_page_move_mapping(struct address_space *mapping,
397 struct page *newpage, struct page *page, enum migrate_mode mode, 397 struct page *newpage, struct page *page, int extra_count)
398 int extra_count)
399{ 398{
400 XA_STATE(xas, &mapping->i_pages, page_index(page)); 399 XA_STATE(xas, &mapping->i_pages, page_index(page));
401 struct zone *oldzone, *newzone; 400 struct zone *oldzone, *newzone;
@@ -681,7 +680,7 @@ int migrate_page(struct address_space *mapping,
681 680
682 BUG_ON(PageWriteback(page)); /* Writeback must be complete */ 681 BUG_ON(PageWriteback(page)); /* Writeback must be complete */
683 682
684 rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); 683 rc = migrate_page_move_mapping(mapping, newpage, page, 0);
685 684
686 if (rc != MIGRATEPAGE_SUCCESS) 685 if (rc != MIGRATEPAGE_SUCCESS)
687 return rc; 686 return rc;
@@ -780,7 +779,7 @@ recheck_buffers:
780 } 779 }
781 } 780 }
782 781
783 rc = migrate_page_move_mapping(mapping, newpage, page, mode, 0); 782 rc = migrate_page_move_mapping(mapping, newpage, page, 0);
784 if (rc != MIGRATEPAGE_SUCCESS) 783 if (rc != MIGRATEPAGE_SUCCESS)
785 goto unlock_buffers; 784 goto unlock_buffers;
786 785
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e515bfcf7f28..272c6de1bf4e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -450,7 +450,7 @@ static inline unsigned long *get_pageblock_bitmap(struct page *page,
450 unsigned long pfn) 450 unsigned long pfn)
451{ 451{
452#ifdef CONFIG_SPARSEMEM 452#ifdef CONFIG_SPARSEMEM
453 return __pfn_to_section(pfn)->pageblock_flags; 453 return section_to_usemap(__pfn_to_section(pfn));
454#else 454#else
455 return page_zone(page)->pageblock_flags; 455 return page_zone(page)->pageblock_flags;
456#endif /* CONFIG_SPARSEMEM */ 456#endif /* CONFIG_SPARSEMEM */
@@ -5926,7 +5926,7 @@ void __ref memmap_init_zone_device(struct zone *zone,
5926 unsigned long start = jiffies; 5926 unsigned long start = jiffies;
5927 int nid = pgdat->node_id; 5927 int nid = pgdat->node_id;
5928 5928
5929 if (WARN_ON_ONCE(!pgmap || !is_dev_zone(zone))) 5929 if (WARN_ON_ONCE(!pgmap || zone_idx(zone) != ZONE_DEVICE))
5930 return; 5930 return;
5931 5931
5932 /* 5932 /*
@@ -5974,7 +5974,7 @@ void __ref memmap_init_zone_device(struct zone *zone,
5974 * pfn out of zone. 5974 * pfn out of zone.
5975 * 5975 *
5976 * Please note that MEMMAP_HOTPLUG path doesn't clear memmap 5976 * Please note that MEMMAP_HOTPLUG path doesn't clear memmap
5977 * because this is done early in sparse_add_one_section 5977 * because this is done early in section_activate()
5978 */ 5978 */
5979 if (!(pfn & (pageblock_nr_pages - 1))) { 5979 if (!(pfn & (pageblock_nr_pages - 1))) {
5980 set_pageblock_migratetype(page, MIGRATE_MOVABLE); 5980 set_pageblock_migratetype(page, MIGRATE_MOVABLE);
@@ -7351,12 +7351,18 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
7351 (u64)zone_movable_pfn[i] << PAGE_SHIFT); 7351 (u64)zone_movable_pfn[i] << PAGE_SHIFT);
7352 } 7352 }
7353 7353
7354 /* Print out the early node map */ 7354 /*
7355 * Print out the early node map, and initialize the
7356 * subsection-map relative to active online memory ranges to
7357 * enable future "sub-section" extensions of the memory map.
7358 */
7355 pr_info("Early memory node ranges\n"); 7359 pr_info("Early memory node ranges\n");
7356 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) 7360 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
7357 pr_info(" node %3d: [mem %#018Lx-%#018Lx]\n", nid, 7361 pr_info(" node %3d: [mem %#018Lx-%#018Lx]\n", nid,
7358 (u64)start_pfn << PAGE_SHIFT, 7362 (u64)start_pfn << PAGE_SHIFT,
7359 ((u64)end_pfn << PAGE_SHIFT) - 1); 7363 ((u64)end_pfn << PAGE_SHIFT) - 1);
7364 subsection_map_init(start_pfn, end_pfn - start_pfn);
7365 }
7360 7366
7361 /* Initialise every node */ 7367 /* Initialise every node */
7362 mminit_verify_pageflags_layout(); 7368 mminit_verify_pageflags_layout();
diff --git a/mm/shmem.c b/mm/shmem.c
index 99497cb32e71..c88a30919ae5 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3874,6 +3874,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)
3874 loff_t i_size; 3874 loff_t i_size;
3875 pgoff_t off; 3875 pgoff_t off;
3876 3876
3877 if ((vma->vm_flags & VM_NOHUGEPAGE) ||
3878 test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
3879 return false;
3877 if (shmem_huge == SHMEM_HUGE_FORCE) 3880 if (shmem_huge == SHMEM_HUGE_FORCE)
3878 return true; 3881 return true;
3879 if (shmem_huge == SHMEM_HUGE_DENY) 3882 if (shmem_huge == SHMEM_HUGE_DENY)
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 7fec05796796..200aef686722 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -245,19 +245,26 @@ int __meminit vmemmap_populate_basepages(unsigned long start,
245 return 0; 245 return 0;
246} 246}
247 247
248struct page * __meminit sparse_mem_map_populate(unsigned long pnum, int nid, 248struct page * __meminit __populate_section_memmap(unsigned long pfn,
249 struct vmem_altmap *altmap) 249 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
250{ 250{
251 unsigned long start; 251 unsigned long start;
252 unsigned long end; 252 unsigned long end;
253 struct page *map;
254 253
255 map = pfn_to_page(pnum * PAGES_PER_SECTION); 254 /*
256 start = (unsigned long)map; 255 * The minimum granularity of memmap extensions is
257 end = (unsigned long)(map + PAGES_PER_SECTION); 256 * PAGES_PER_SUBSECTION as allocations are tracked in the
257 * 'subsection_map' bitmap of the section.
258 */
259 end = ALIGN(pfn + nr_pages, PAGES_PER_SUBSECTION);
260 pfn &= PAGE_SUBSECTION_MASK;
261 nr_pages = end - pfn;
262
263 start = (unsigned long) pfn_to_page(pfn);
264 end = start + nr_pages * sizeof(struct page);
258 265
259 if (vmemmap_populate(start, end, nid, altmap)) 266 if (vmemmap_populate(start, end, nid, altmap))
260 return NULL; 267 return NULL;
261 268
262 return map; 269 return pfn_to_page(pfn);
263} 270}
diff --git a/mm/sparse.c b/mm/sparse.c
index fd13166949b5..72f010d9bff5 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -83,8 +83,15 @@ static int __meminit sparse_index_init(unsigned long section_nr, int nid)
83 unsigned long root = SECTION_NR_TO_ROOT(section_nr); 83 unsigned long root = SECTION_NR_TO_ROOT(section_nr);
84 struct mem_section *section; 84 struct mem_section *section;
85 85
86 /*
87 * An existing section is possible in the sub-section hotplug
88 * case. First hot-add instantiates, follow-on hot-add reuses
89 * the existing section.
90 *
91 * The mem_hotplug_lock resolves the apparent race below.
92 */
86 if (mem_section[root]) 93 if (mem_section[root])
87 return -EEXIST; 94 return 0;
88 95
89 section = sparse_index_alloc(nid); 96 section = sparse_index_alloc(nid);
90 if (!section) 97 if (!section)
@@ -102,7 +109,7 @@ static inline int sparse_index_init(unsigned long section_nr, int nid)
102#endif 109#endif
103 110
104#ifdef CONFIG_SPARSEMEM_EXTREME 111#ifdef CONFIG_SPARSEMEM_EXTREME
105int __section_nr(struct mem_section* ms) 112unsigned long __section_nr(struct mem_section *ms)
106{ 113{
107 unsigned long root_nr; 114 unsigned long root_nr;
108 struct mem_section *root = NULL; 115 struct mem_section *root = NULL;
@@ -121,9 +128,9 @@ int __section_nr(struct mem_section* ms)
121 return (root_nr * SECTIONS_PER_ROOT) + (ms - root); 128 return (root_nr * SECTIONS_PER_ROOT) + (ms - root);
122} 129}
123#else 130#else
124int __section_nr(struct mem_section* ms) 131unsigned long __section_nr(struct mem_section *ms)
125{ 132{
126 return (int)(ms - mem_section[0]); 133 return (unsigned long)(ms - mem_section[0]);
127} 134}
128#endif 135#endif
129 136
@@ -178,10 +185,10 @@ void __meminit mminit_validate_memmodel_limits(unsigned long *start_pfn,
178 * Keeping track of this gives us an easy way to break out of 185 * Keeping track of this gives us an easy way to break out of
179 * those loops early. 186 * those loops early.
180 */ 187 */
181int __highest_present_section_nr; 188unsigned long __highest_present_section_nr;
182static void section_mark_present(struct mem_section *ms) 189static void section_mark_present(struct mem_section *ms)
183{ 190{
184 int section_nr = __section_nr(ms); 191 unsigned long section_nr = __section_nr(ms);
185 192
186 if (section_nr > __highest_present_section_nr) 193 if (section_nr > __highest_present_section_nr)
187 __highest_present_section_nr = section_nr; 194 __highest_present_section_nr = section_nr;
@@ -189,7 +196,7 @@ static void section_mark_present(struct mem_section *ms)
189 ms->section_mem_map |= SECTION_MARKED_PRESENT; 196 ms->section_mem_map |= SECTION_MARKED_PRESENT;
190} 197}
191 198
192static inline int next_present_section_nr(int section_nr) 199static inline unsigned long next_present_section_nr(unsigned long section_nr)
193{ 200{
194 do { 201 do {
195 section_nr++; 202 section_nr++;
@@ -210,6 +217,41 @@ static inline unsigned long first_present_section_nr(void)
210 return next_present_section_nr(-1); 217 return next_present_section_nr(-1);
211} 218}
212 219
220void subsection_mask_set(unsigned long *map, unsigned long pfn,
221 unsigned long nr_pages)
222{
223 int idx = subsection_map_index(pfn);
224 int end = subsection_map_index(pfn + nr_pages - 1);
225
226 bitmap_set(map, idx, end - idx + 1);
227}
228
229void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages)
230{
231 int end_sec = pfn_to_section_nr(pfn + nr_pages - 1);
232 unsigned long nr, start_sec = pfn_to_section_nr(pfn);
233
234 if (!nr_pages)
235 return;
236
237 for (nr = start_sec; nr <= end_sec; nr++) {
238 struct mem_section *ms;
239 unsigned long pfns;
240
241 pfns = min(nr_pages, PAGES_PER_SECTION
242 - (pfn & ~PAGE_SECTION_MASK));
243 ms = __nr_to_section(nr);
244 subsection_mask_set(ms->usage->subsection_map, pfn, pfns);
245
246 pr_debug("%s: sec: %lu pfns: %lu set(%d, %d)\n", __func__, nr,
247 pfns, subsection_map_index(pfn),
248 subsection_map_index(pfn + pfns - 1));
249
250 pfn += pfns;
251 nr_pages -= pfns;
252 }
253}
254
213/* Record a memory area against a node. */ 255/* Record a memory area against a node. */
214void __init memory_present(int nid, unsigned long start, unsigned long end) 256void __init memory_present(int nid, unsigned long start, unsigned long end)
215{ 257{
@@ -288,33 +330,31 @@ struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pn
288 330
289static void __meminit sparse_init_one_section(struct mem_section *ms, 331static void __meminit sparse_init_one_section(struct mem_section *ms,
290 unsigned long pnum, struct page *mem_map, 332 unsigned long pnum, struct page *mem_map,
291 unsigned long *pageblock_bitmap) 333 struct mem_section_usage *usage, unsigned long flags)
292{ 334{
293 ms->section_mem_map &= ~SECTION_MAP_MASK; 335 ms->section_mem_map &= ~SECTION_MAP_MASK;
294 ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum) | 336 ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum)
295 SECTION_HAS_MEM_MAP; 337 | SECTION_HAS_MEM_MAP | flags;
296 ms->pageblock_flags = pageblock_bitmap; 338 ms->usage = usage;
297} 339}
298 340
299unsigned long usemap_size(void) 341static unsigned long usemap_size(void)
300{ 342{
301 return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long); 343 return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long);
302} 344}
303 345
304#ifdef CONFIG_MEMORY_HOTPLUG 346size_t mem_section_usage_size(void)
305static unsigned long *__kmalloc_section_usemap(void)
306{ 347{
307 return kmalloc(usemap_size(), GFP_KERNEL); 348 return sizeof(struct mem_section_usage) + usemap_size();
308} 349}
309#endif /* CONFIG_MEMORY_HOTPLUG */
310 350
311#ifdef CONFIG_MEMORY_HOTREMOVE 351#ifdef CONFIG_MEMORY_HOTREMOVE
312static unsigned long * __init 352static struct mem_section_usage * __init
313sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, 353sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
314 unsigned long size) 354 unsigned long size)
315{ 355{
356 struct mem_section_usage *usage;
316 unsigned long goal, limit; 357 unsigned long goal, limit;
317 unsigned long *p;
318 int nid; 358 int nid;
319 /* 359 /*
320 * A page may contain usemaps for other sections preventing the 360 * A page may contain usemaps for other sections preventing the
@@ -330,15 +370,16 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
330 limit = goal + (1UL << PA_SECTION_SHIFT); 370 limit = goal + (1UL << PA_SECTION_SHIFT);
331 nid = early_pfn_to_nid(goal >> PAGE_SHIFT); 371 nid = early_pfn_to_nid(goal >> PAGE_SHIFT);
332again: 372again:
333 p = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, goal, limit, nid); 373 usage = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, goal, limit, nid);
334 if (!p && limit) { 374 if (!usage && limit) {
335 limit = 0; 375 limit = 0;
336 goto again; 376 goto again;
337 } 377 }
338 return p; 378 return usage;
339} 379}
340 380
341static void __init check_usemap_section_nr(int nid, unsigned long *usemap) 381static void __init check_usemap_section_nr(int nid,
382 struct mem_section_usage *usage)
342{ 383{
343 unsigned long usemap_snr, pgdat_snr; 384 unsigned long usemap_snr, pgdat_snr;
344 static unsigned long old_usemap_snr; 385 static unsigned long old_usemap_snr;
@@ -352,7 +393,7 @@ static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
352 old_pgdat_snr = NR_MEM_SECTIONS; 393 old_pgdat_snr = NR_MEM_SECTIONS;
353 } 394 }
354 395
355 usemap_snr = pfn_to_section_nr(__pa(usemap) >> PAGE_SHIFT); 396 usemap_snr = pfn_to_section_nr(__pa(usage) >> PAGE_SHIFT);
356 pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT); 397 pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT);
357 if (usemap_snr == pgdat_snr) 398 if (usemap_snr == pgdat_snr)
358 return; 399 return;
@@ -380,14 +421,15 @@ static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
380 usemap_snr, pgdat_snr, nid); 421 usemap_snr, pgdat_snr, nid);
381} 422}
382#else 423#else
383static unsigned long * __init 424static struct mem_section_usage * __init
384sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, 425sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
385 unsigned long size) 426 unsigned long size)
386{ 427{
387 return memblock_alloc_node(size, SMP_CACHE_BYTES, pgdat->node_id); 428 return memblock_alloc_node(size, SMP_CACHE_BYTES, pgdat->node_id);
388} 429}
389 430
390static void __init check_usemap_section_nr(int nid, unsigned long *usemap) 431static void __init check_usemap_section_nr(int nid,
432 struct mem_section_usage *usage)
391{ 433{
392} 434}
393#endif /* CONFIG_MEMORY_HOTREMOVE */ 435#endif /* CONFIG_MEMORY_HOTREMOVE */
@@ -404,8 +446,8 @@ static unsigned long __init section_map_size(void)
404 return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION); 446 return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION);
405} 447}
406 448
407struct page __init *sparse_mem_map_populate(unsigned long pnum, int nid, 449struct page __init *__populate_section_memmap(unsigned long pfn,
408 struct vmem_altmap *altmap) 450 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
409{ 451{
410 unsigned long size = section_map_size(); 452 unsigned long size = section_map_size();
411 struct page *map = sparse_buffer_alloc(size); 453 struct page *map = sparse_buffer_alloc(size);
@@ -474,32 +516,35 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin,
474 unsigned long pnum_end, 516 unsigned long pnum_end,
475 unsigned long map_count) 517 unsigned long map_count)
476{ 518{
477 unsigned long pnum, usemap_longs, *usemap; 519 struct mem_section_usage *usage;
520 unsigned long pnum;
478 struct page *map; 521 struct page *map;
479 522
480 usemap_longs = BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS); 523 usage = sparse_early_usemaps_alloc_pgdat_section(NODE_DATA(nid),
481 usemap = sparse_early_usemaps_alloc_pgdat_section(NODE_DATA(nid), 524 mem_section_usage_size() * map_count);
482 usemap_size() * 525 if (!usage) {
483 map_count);
484 if (!usemap) {
485 pr_err("%s: node[%d] usemap allocation failed", __func__, nid); 526 pr_err("%s: node[%d] usemap allocation failed", __func__, nid);
486 goto failed; 527 goto failed;
487 } 528 }
488 sparse_buffer_init(map_count * section_map_size(), nid); 529 sparse_buffer_init(map_count * section_map_size(), nid);
489 for_each_present_section_nr(pnum_begin, pnum) { 530 for_each_present_section_nr(pnum_begin, pnum) {
531 unsigned long pfn = section_nr_to_pfn(pnum);
532
490 if (pnum >= pnum_end) 533 if (pnum >= pnum_end)
491 break; 534 break;
492 535
493 map = sparse_mem_map_populate(pnum, nid, NULL); 536 map = __populate_section_memmap(pfn, PAGES_PER_SECTION,
537 nid, NULL);
494 if (!map) { 538 if (!map) {
495 pr_err("%s: node[%d] memory map backing failed. Some memory will not be available.", 539 pr_err("%s: node[%d] memory map backing failed. Some memory will not be available.",
496 __func__, nid); 540 __func__, nid);
497 pnum_begin = pnum; 541 pnum_begin = pnum;
498 goto failed; 542 goto failed;
499 } 543 }
500 check_usemap_section_nr(nid, usemap); 544 check_usemap_section_nr(nid, usage);
501 sparse_init_one_section(__nr_to_section(pnum), pnum, map, usemap); 545 sparse_init_one_section(__nr_to_section(pnum), pnum, map, usage,
502 usemap += usemap_longs; 546 SECTION_IS_EARLY);
547 usage = (void *) usage + mem_section_usage_size();
503 } 548 }
504 sparse_buffer_fini(); 549 sparse_buffer_fini();
505 return; 550 return;
@@ -590,21 +635,20 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
590#endif 635#endif
591 636
592#ifdef CONFIG_SPARSEMEM_VMEMMAP 637#ifdef CONFIG_SPARSEMEM_VMEMMAP
593static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 638static struct page *populate_section_memmap(unsigned long pfn,
594 struct vmem_altmap *altmap) 639 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
595{ 640{
596 /* This will make the necessary allocations eventually. */ 641 return __populate_section_memmap(pfn, nr_pages, nid, altmap);
597 return sparse_mem_map_populate(pnum, nid, altmap);
598} 642}
599static void __kfree_section_memmap(struct page *memmap, 643
644static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
600 struct vmem_altmap *altmap) 645 struct vmem_altmap *altmap)
601{ 646{
602 unsigned long start = (unsigned long)memmap; 647 unsigned long start = (unsigned long) pfn_to_page(pfn);
603 unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION); 648 unsigned long end = start + nr_pages * sizeof(struct page);
604 649
605 vmemmap_free(start, end, altmap); 650 vmemmap_free(start, end, altmap);
606} 651}
607#ifdef CONFIG_MEMORY_HOTREMOVE
608static void free_map_bootmem(struct page *memmap) 652static void free_map_bootmem(struct page *memmap)
609{ 653{
610 unsigned long start = (unsigned long)memmap; 654 unsigned long start = (unsigned long)memmap;
@@ -612,9 +656,9 @@ static void free_map_bootmem(struct page *memmap)
612 656
613 vmemmap_free(start, end, NULL); 657 vmemmap_free(start, end, NULL);
614} 658}
615#endif /* CONFIG_MEMORY_HOTREMOVE */
616#else 659#else
617static struct page *__kmalloc_section_memmap(void) 660struct page *populate_section_memmap(unsigned long pfn,
661 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
618{ 662{
619 struct page *page, *ret; 663 struct page *page, *ret;
620 unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION; 664 unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
@@ -635,15 +679,11 @@ got_map_ptr:
635 return ret; 679 return ret;
636} 680}
637 681
638static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 682static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
639 struct vmem_altmap *altmap) 683 struct vmem_altmap *altmap)
640{ 684{
641 return __kmalloc_section_memmap(); 685 struct page *memmap = pfn_to_page(pfn);
642}
643 686
644static void __kfree_section_memmap(struct page *memmap,
645 struct vmem_altmap *altmap)
646{
647 if (is_vmalloc_addr(memmap)) 687 if (is_vmalloc_addr(memmap))
648 vfree(memmap); 688 vfree(memmap);
649 else 689 else
@@ -651,7 +691,6 @@ static void __kfree_section_memmap(struct page *memmap,
651 get_order(sizeof(struct page) * PAGES_PER_SECTION)); 691 get_order(sizeof(struct page) * PAGES_PER_SECTION));
652} 692}
653 693
654#ifdef CONFIG_MEMORY_HOTREMOVE
655static void free_map_bootmem(struct page *memmap) 694static void free_map_bootmem(struct page *memmap)
656{ 695{
657 unsigned long maps_section_nr, removing_section_nr, i; 696 unsigned long maps_section_nr, removing_section_nr, i;
@@ -681,13 +720,122 @@ static void free_map_bootmem(struct page *memmap)
681 put_page_bootmem(page); 720 put_page_bootmem(page);
682 } 721 }
683} 722}
684#endif /* CONFIG_MEMORY_HOTREMOVE */
685#endif /* CONFIG_SPARSEMEM_VMEMMAP */ 723#endif /* CONFIG_SPARSEMEM_VMEMMAP */
686 724
725static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
726 struct vmem_altmap *altmap)
727{
728 DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 };
729 DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 };
730 struct mem_section *ms = __pfn_to_section(pfn);
731 bool section_is_early = early_section(ms);
732 struct page *memmap = NULL;
733 unsigned long *subsection_map = ms->usage
734 ? &ms->usage->subsection_map[0] : NULL;
735
736 subsection_mask_set(map, pfn, nr_pages);
737 if (subsection_map)
738 bitmap_and(tmp, map, subsection_map, SUBSECTIONS_PER_SECTION);
739
740 if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION),
741 "section already deactivated (%#lx + %ld)\n",
742 pfn, nr_pages))
743 return;
744
745 /*
746 * There are 3 cases to handle across two configurations
747 * (SPARSEMEM_VMEMMAP={y,n}):
748 *
749 * 1/ deactivation of a partial hot-added section (only possible
750 * in the SPARSEMEM_VMEMMAP=y case).
751 * a/ section was present at memory init
752 * b/ section was hot-added post memory init
753 * 2/ deactivation of a complete hot-added section
754 * 3/ deactivation of a complete section from memory init
755 *
756 * For 1/, when subsection_map does not empty we will not be
757 * freeing the usage map, but still need to free the vmemmap
758 * range.
759 *
760 * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified
761 */
762 bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION);
763 if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) {
764 unsigned long section_nr = pfn_to_section_nr(pfn);
765
766 if (!section_is_early) {
767 kfree(ms->usage);
768 ms->usage = NULL;
769 }
770 memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
771 ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
772 }
773
774 if (section_is_early && memmap)
775 free_map_bootmem(memmap);
776 else
777 depopulate_section_memmap(pfn, nr_pages, altmap);
778}
779
780static struct page * __meminit section_activate(int nid, unsigned long pfn,
781 unsigned long nr_pages, struct vmem_altmap *altmap)
782{
783 DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 };
784 struct mem_section *ms = __pfn_to_section(pfn);
785 struct mem_section_usage *usage = NULL;
786 unsigned long *subsection_map;
787 struct page *memmap;
788 int rc = 0;
789
790 subsection_mask_set(map, pfn, nr_pages);
791
792 if (!ms->usage) {
793 usage = kzalloc(mem_section_usage_size(), GFP_KERNEL);
794 if (!usage)
795 return ERR_PTR(-ENOMEM);
796 ms->usage = usage;
797 }
798 subsection_map = &ms->usage->subsection_map[0];
799
800 if (bitmap_empty(map, SUBSECTIONS_PER_SECTION))
801 rc = -EINVAL;
802 else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION))
803 rc = -EEXIST;
804 else
805 bitmap_or(subsection_map, map, subsection_map,
806 SUBSECTIONS_PER_SECTION);
807
808 if (rc) {
809 if (usage)
810 ms->usage = NULL;
811 kfree(usage);
812 return ERR_PTR(rc);
813 }
814
815 /*
816 * The early init code does not consider partially populated
817 * initial sections, it simply assumes that memory will never be
818 * referenced. If we hot-add memory into such a section then we
819 * do not need to populate the memmap and can simply reuse what
820 * is already there.
821 */
822 if (nr_pages < PAGES_PER_SECTION && early_section(ms))
823 return pfn_to_page(pfn);
824
825 memmap = populate_section_memmap(pfn, nr_pages, nid, altmap);
826 if (!memmap) {
827 section_deactivate(pfn, nr_pages, altmap);
828 return ERR_PTR(-ENOMEM);
829 }
830
831 return memmap;
832}
833
687/** 834/**
688 * sparse_add_one_section - add a memory section 835 * sparse_add_section - add a memory section, or populate an existing one
689 * @nid: The node to add section on 836 * @nid: The node to add section on
690 * @start_pfn: start pfn of the memory range 837 * @start_pfn: start pfn of the memory range
838 * @nr_pages: number of pfns to add in the section
691 * @altmap: device page map 839 * @altmap: device page map
692 * 840 *
693 * This is only intended for hotplug. 841 * This is only intended for hotplug.
@@ -697,56 +845,40 @@ static void free_map_bootmem(struct page *memmap)
697 * * -EEXIST - Section has been present. 845 * * -EEXIST - Section has been present.
698 * * -ENOMEM - Out of memory. 846 * * -ENOMEM - Out of memory.
699 */ 847 */
700int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, 848int __meminit sparse_add_section(int nid, unsigned long start_pfn,
701 struct vmem_altmap *altmap) 849 unsigned long nr_pages, struct vmem_altmap *altmap)
702{ 850{
703 unsigned long section_nr = pfn_to_section_nr(start_pfn); 851 unsigned long section_nr = pfn_to_section_nr(start_pfn);
704 struct mem_section *ms; 852 struct mem_section *ms;
705 struct page *memmap; 853 struct page *memmap;
706 unsigned long *usemap;
707 int ret; 854 int ret;
708 855
709 /*
710 * no locking for this, because it does its own
711 * plus, it does a kmalloc
712 */
713 ret = sparse_index_init(section_nr, nid); 856 ret = sparse_index_init(section_nr, nid);
714 if (ret < 0 && ret != -EEXIST) 857 if (ret < 0)
715 return ret; 858 return ret;
716 ret = 0;
717 memmap = kmalloc_section_memmap(section_nr, nid, altmap);
718 if (!memmap)
719 return -ENOMEM;
720 usemap = __kmalloc_section_usemap();
721 if (!usemap) {
722 __kfree_section_memmap(memmap, altmap);
723 return -ENOMEM;
724 }
725 859
726 ms = __pfn_to_section(start_pfn); 860 memmap = section_activate(nid, start_pfn, nr_pages, altmap);
727 if (ms->section_mem_map & SECTION_MARKED_PRESENT) { 861 if (IS_ERR(memmap))
728 ret = -EEXIST; 862 return PTR_ERR(memmap);
729 goto out;
730 }
731 863
732 /* 864 /*
733 * Poison uninitialized struct pages in order to catch invalid flags 865 * Poison uninitialized struct pages in order to catch invalid flags
734 * combinations. 866 * combinations.
735 */ 867 */
736 page_init_poison(memmap, sizeof(struct page) * PAGES_PER_SECTION); 868 page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
737 869
870 ms = __pfn_to_section(start_pfn);
871 set_section_nid(section_nr, nid);
738 section_mark_present(ms); 872 section_mark_present(ms);
739 sparse_init_one_section(ms, section_nr, memmap, usemap);
740 873
741out: 874 /* Align memmap to section boundary in the subsection case */
742 if (ret < 0) { 875 if (section_nr_to_pfn(section_nr) != start_pfn)
743 kfree(usemap); 876 memmap = pfn_to_kaddr(section_nr_to_pfn(section_nr));
744 __kfree_section_memmap(memmap, altmap); 877 sparse_init_one_section(ms, section_nr, memmap, ms->usage, 0);
745 } 878
746 return ret; 879 return 0;
747} 880}
748 881
749#ifdef CONFIG_MEMORY_HOTREMOVE
750#ifdef CONFIG_MEMORY_FAILURE 882#ifdef CONFIG_MEMORY_FAILURE
751static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) 883static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
752{ 884{
@@ -777,51 +909,12 @@ static inline void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
777} 909}
778#endif 910#endif
779 911
780static void free_section_usemap(struct page *memmap, unsigned long *usemap, 912void sparse_remove_section(struct mem_section *ms, unsigned long pfn,
913 unsigned long nr_pages, unsigned long map_offset,
781 struct vmem_altmap *altmap) 914 struct vmem_altmap *altmap)
782{ 915{
783 struct page *usemap_page; 916 clear_hwpoisoned_pages(pfn_to_page(pfn) + map_offset,
784 917 nr_pages - map_offset);
785 if (!usemap) 918 section_deactivate(pfn, nr_pages, altmap);
786 return;
787
788 usemap_page = virt_to_page(usemap);
789 /*
790 * Check to see if allocation came from hot-plug-add
791 */
792 if (PageSlab(usemap_page) || PageCompound(usemap_page)) {
793 kfree(usemap);
794 if (memmap)
795 __kfree_section_memmap(memmap, altmap);
796 return;
797 }
798
799 /*
800 * The usemap came from bootmem. This is packed with other usemaps
801 * on the section which has pgdat at boot time. Just keep it as is now.
802 */
803
804 if (memmap)
805 free_map_bootmem(memmap);
806}
807
808void sparse_remove_one_section(struct zone *zone, struct mem_section *ms,
809 unsigned long map_offset, struct vmem_altmap *altmap)
810{
811 struct page *memmap = NULL;
812 unsigned long *usemap = NULL;
813
814 if (ms->section_mem_map) {
815 usemap = ms->pageblock_flags;
816 memmap = sparse_decode_mem_map(ms->section_mem_map,
817 __section_nr(ms));
818 ms->section_mem_map = 0;
819 ms->pageblock_flags = NULL;
820 }
821
822 clear_hwpoisoned_pages(memmap + map_offset,
823 PAGES_PER_SECTION - map_offset);
824 free_section_usemap(memmap, usemap, altmap);
825} 919}
826#endif /* CONFIG_MEMORY_HOTREMOVE */
827#endif /* CONFIG_MEMORY_HOTPLUG */ 920#endif /* CONFIG_MEMORY_HOTPLUG */
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 742cea4ce72e..26da97359d5b 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -3374,8 +3374,6 @@ void neigh_app_ns(struct neighbour *n)
3374EXPORT_SYMBOL(neigh_app_ns); 3374EXPORT_SYMBOL(neigh_app_ns);
3375 3375
3376#ifdef CONFIG_SYSCTL 3376#ifdef CONFIG_SYSCTL
3377static int zero;
3378static int int_max = INT_MAX;
3379static int unres_qlen_max = INT_MAX / SKB_TRUESIZE(ETH_FRAME_LEN); 3377static int unres_qlen_max = INT_MAX / SKB_TRUESIZE(ETH_FRAME_LEN);
3380 3378
3381static int proc_unres_qlen(struct ctl_table *ctl, int write, 3379static int proc_unres_qlen(struct ctl_table *ctl, int write,
@@ -3384,7 +3382,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
3384 int size, ret; 3382 int size, ret;
3385 struct ctl_table tmp = *ctl; 3383 struct ctl_table tmp = *ctl;
3386 3384
3387 tmp.extra1 = &zero; 3385 tmp.extra1 = SYSCTL_ZERO;
3388 tmp.extra2 = &unres_qlen_max; 3386 tmp.extra2 = &unres_qlen_max;
3389 tmp.data = &size; 3387 tmp.data = &size;
3390 3388
@@ -3449,8 +3447,8 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
3449 struct ctl_table tmp = *ctl; 3447 struct ctl_table tmp = *ctl;
3450 int ret; 3448 int ret;
3451 3449
3452 tmp.extra1 = &zero; 3450 tmp.extra1 = SYSCTL_ZERO;
3453 tmp.extra2 = &int_max; 3451 tmp.extra2 = SYSCTL_INT_MAX;
3454 3452
3455 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 3453 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3456 neigh_proc_update(ctl, write); 3454 neigh_proc_update(ctl, write);
@@ -3595,24 +3593,24 @@ static struct neigh_sysctl_table {
3595 .procname = "gc_thresh1", 3593 .procname = "gc_thresh1",
3596 .maxlen = sizeof(int), 3594 .maxlen = sizeof(int),
3597 .mode = 0644, 3595 .mode = 0644,
3598 .extra1 = &zero, 3596 .extra1 = SYSCTL_ZERO,
3599 .extra2 = &int_max, 3597 .extra2 = SYSCTL_INT_MAX,
3600 .proc_handler = proc_dointvec_minmax, 3598 .proc_handler = proc_dointvec_minmax,
3601 }, 3599 },
3602 [NEIGH_VAR_GC_THRESH2] = { 3600 [NEIGH_VAR_GC_THRESH2] = {
3603 .procname = "gc_thresh2", 3601 .procname = "gc_thresh2",
3604 .maxlen = sizeof(int), 3602 .maxlen = sizeof(int),
3605 .mode = 0644, 3603 .mode = 0644,
3606 .extra1 = &zero, 3604 .extra1 = SYSCTL_ZERO,
3607 .extra2 = &int_max, 3605 .extra2 = SYSCTL_INT_MAX,
3608 .proc_handler = proc_dointvec_minmax, 3606 .proc_handler = proc_dointvec_minmax,
3609 }, 3607 },
3610 [NEIGH_VAR_GC_THRESH3] = { 3608 [NEIGH_VAR_GC_THRESH3] = {
3611 .procname = "gc_thresh3", 3609 .procname = "gc_thresh3",
3612 .maxlen = sizeof(int), 3610 .maxlen = sizeof(int),
3613 .mode = 0644, 3611 .mode = 0644,
3614 .extra1 = &zero, 3612 .extra1 = SYSCTL_ZERO,
3615 .extra2 = &int_max, 3613 .extra2 = SYSCTL_INT_MAX,
3616 .proc_handler = proc_dointvec_minmax, 3614 .proc_handler = proc_dointvec_minmax,
3617 }, 3615 },
3618 {}, 3616 {},
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index f9204719aeee..8da5b3a54dac 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -22,8 +22,6 @@
22#include <net/busy_poll.h> 22#include <net/busy_poll.h>
23#include <net/pkt_sched.h> 23#include <net/pkt_sched.h>
24 24
25static int zero = 0;
26static int one = 1;
27static int two __maybe_unused = 2; 25static int two __maybe_unused = 2;
28static int min_sndbuf = SOCK_MIN_SNDBUF; 26static int min_sndbuf = SOCK_MIN_SNDBUF;
29static int min_rcvbuf = SOCK_MIN_RCVBUF; 27static int min_rcvbuf = SOCK_MIN_RCVBUF;
@@ -390,10 +388,10 @@ static struct ctl_table net_core_table[] = {
390 .mode = 0644, 388 .mode = 0644,
391 .proc_handler = proc_dointvec_minmax_bpf_enable, 389 .proc_handler = proc_dointvec_minmax_bpf_enable,
392# ifdef CONFIG_BPF_JIT_ALWAYS_ON 390# ifdef CONFIG_BPF_JIT_ALWAYS_ON
393 .extra1 = &one, 391 .extra1 = SYSCTL_ONE,
394 .extra2 = &one, 392 .extra2 = SYSCTL_ONE,
395# else 393# else
396 .extra1 = &zero, 394 .extra1 = SYSCTL_ZERO,
397 .extra2 = &two, 395 .extra2 = &two,
398# endif 396# endif
399 }, 397 },
@@ -404,7 +402,7 @@ static struct ctl_table net_core_table[] = {
404 .maxlen = sizeof(int), 402 .maxlen = sizeof(int),
405 .mode = 0600, 403 .mode = 0600,
406 .proc_handler = proc_dointvec_minmax_bpf_restricted, 404 .proc_handler = proc_dointvec_minmax_bpf_restricted,
407 .extra1 = &zero, 405 .extra1 = SYSCTL_ZERO,
408 .extra2 = &two, 406 .extra2 = &two,
409 }, 407 },
410 { 408 {
@@ -413,8 +411,8 @@ static struct ctl_table net_core_table[] = {
413 .maxlen = sizeof(int), 411 .maxlen = sizeof(int),
414 .mode = 0600, 412 .mode = 0600,
415 .proc_handler = proc_dointvec_minmax_bpf_restricted, 413 .proc_handler = proc_dointvec_minmax_bpf_restricted,
416 .extra1 = &zero, 414 .extra1 = SYSCTL_ZERO,
417 .extra2 = &one, 415 .extra2 = SYSCTL_ONE,
418 }, 416 },
419# endif 417# endif
420 { 418 {
@@ -461,8 +459,8 @@ static struct ctl_table net_core_table[] = {
461 .maxlen = sizeof(int), 459 .maxlen = sizeof(int),
462 .mode = 0644, 460 .mode = 0644,
463 .proc_handler = proc_dointvec_minmax, 461 .proc_handler = proc_dointvec_minmax,
464 .extra1 = &zero, 462 .extra1 = SYSCTL_ZERO,
465 .extra2 = &one 463 .extra2 = SYSCTL_ONE
466 }, 464 },
467#ifdef CONFIG_RPS 465#ifdef CONFIG_RPS
468 { 466 {
@@ -493,7 +491,7 @@ static struct ctl_table net_core_table[] = {
493 .maxlen = sizeof(unsigned int), 491 .maxlen = sizeof(unsigned int),
494 .mode = 0644, 492 .mode = 0644,
495 .proc_handler = proc_dointvec_minmax, 493 .proc_handler = proc_dointvec_minmax,
496 .extra1 = &zero, 494 .extra1 = SYSCTL_ZERO,
497 }, 495 },
498 { 496 {
499 .procname = "busy_read", 497 .procname = "busy_read",
@@ -501,7 +499,7 @@ static struct ctl_table net_core_table[] = {
501 .maxlen = sizeof(unsigned int), 499 .maxlen = sizeof(unsigned int),
502 .mode = 0644, 500 .mode = 0644,
503 .proc_handler = proc_dointvec_minmax, 501 .proc_handler = proc_dointvec_minmax,
504 .extra1 = &zero, 502 .extra1 = SYSCTL_ZERO,
505 }, 503 },
506#endif 504#endif
507#ifdef CONFIG_NET_SCHED 505#ifdef CONFIG_NET_SCHED
@@ -533,7 +531,7 @@ static struct ctl_table net_core_table[] = {
533 .maxlen = sizeof(int), 531 .maxlen = sizeof(int),
534 .mode = 0644, 532 .mode = 0644,
535 .proc_handler = proc_dointvec_minmax, 533 .proc_handler = proc_dointvec_minmax,
536 .extra1 = &one, 534 .extra1 = SYSCTL_ONE,
537 .extra2 = &max_skb_frags, 535 .extra2 = &max_skb_frags,
538 }, 536 },
539 { 537 {
@@ -542,7 +540,7 @@ static struct ctl_table net_core_table[] = {
542 .maxlen = sizeof(unsigned int), 540 .maxlen = sizeof(unsigned int),
543 .mode = 0644, 541 .mode = 0644,
544 .proc_handler = proc_dointvec_minmax, 542 .proc_handler = proc_dointvec_minmax,
545 .extra1 = &zero, 543 .extra1 = SYSCTL_ZERO,
546 }, 544 },
547 { 545 {
548 .procname = "fb_tunnels_only_for_init_net", 546 .procname = "fb_tunnels_only_for_init_net",
@@ -550,8 +548,8 @@ static struct ctl_table net_core_table[] = {
550 .maxlen = sizeof(int), 548 .maxlen = sizeof(int),
551 .mode = 0644, 549 .mode = 0644,
552 .proc_handler = proc_dointvec_minmax, 550 .proc_handler = proc_dointvec_minmax,
553 .extra1 = &zero, 551 .extra1 = SYSCTL_ZERO,
554 .extra2 = &one, 552 .extra2 = SYSCTL_ONE,
555 }, 553 },
556 { 554 {
557 .procname = "devconf_inherit_init_net", 555 .procname = "devconf_inherit_init_net",
@@ -559,7 +557,7 @@ static struct ctl_table net_core_table[] = {
559 .maxlen = sizeof(int), 557 .maxlen = sizeof(int),
560 .mode = 0644, 558 .mode = 0644,
561 .proc_handler = proc_dointvec_minmax, 559 .proc_handler = proc_dointvec_minmax,
562 .extra1 = &zero, 560 .extra1 = SYSCTL_ZERO,
563 .extra2 = &two, 561 .extra2 = &two,
564 }, 562 },
565 { 563 {
@@ -578,7 +576,7 @@ static struct ctl_table netns_core_table[] = {
578 .data = &init_net.core.sysctl_somaxconn, 576 .data = &init_net.core.sysctl_somaxconn,
579 .maxlen = sizeof(int), 577 .maxlen = sizeof(int),
580 .mode = 0644, 578 .mode = 0644,
581 .extra1 = &zero, 579 .extra1 = SYSCTL_ZERO,
582 .proc_handler = proc_dointvec_minmax 580 .proc_handler = proc_dointvec_minmax
583 }, 581 },
584 { } 582 { }
diff --git a/net/dccp/sysctl.c b/net/dccp/sysctl.c
index b59040f268a9..ee8d4f5afa72 100644
--- a/net/dccp/sysctl.c
+++ b/net/dccp/sysctl.c
@@ -16,9 +16,7 @@
16#endif 16#endif
17 17
18/* Boundary values */ 18/* Boundary values */
19static int zero = 0, 19static int u8_max = 0xFF;
20 one = 1,
21 u8_max = 0xFF;
22static unsigned long seqw_min = DCCPF_SEQ_WMIN, 20static unsigned long seqw_min = DCCPF_SEQ_WMIN,
23 seqw_max = 0xFFFFFFFF; /* maximum on 32 bit */ 21 seqw_max = 0xFFFFFFFF; /* maximum on 32 bit */
24 22
@@ -38,7 +36,7 @@ static struct ctl_table dccp_default_table[] = {
38 .maxlen = sizeof(sysctl_dccp_rx_ccid), 36 .maxlen = sizeof(sysctl_dccp_rx_ccid),
39 .mode = 0644, 37 .mode = 0644,
40 .proc_handler = proc_dointvec_minmax, 38 .proc_handler = proc_dointvec_minmax,
41 .extra1 = &zero, 39 .extra1 = SYSCTL_ZERO,
42 .extra2 = &u8_max, /* RFC 4340, 10. */ 40 .extra2 = &u8_max, /* RFC 4340, 10. */
43 }, 41 },
44 { 42 {
@@ -47,7 +45,7 @@ static struct ctl_table dccp_default_table[] = {
47 .maxlen = sizeof(sysctl_dccp_tx_ccid), 45 .maxlen = sizeof(sysctl_dccp_tx_ccid),
48 .mode = 0644, 46 .mode = 0644,
49 .proc_handler = proc_dointvec_minmax, 47 .proc_handler = proc_dointvec_minmax,
50 .extra1 = &zero, 48 .extra1 = SYSCTL_ZERO,
51 .extra2 = &u8_max, /* RFC 4340, 10. */ 49 .extra2 = &u8_max, /* RFC 4340, 10. */
52 }, 50 },
53 { 51 {
@@ -56,7 +54,7 @@ static struct ctl_table dccp_default_table[] = {
56 .maxlen = sizeof(sysctl_dccp_request_retries), 54 .maxlen = sizeof(sysctl_dccp_request_retries),
57 .mode = 0644, 55 .mode = 0644,
58 .proc_handler = proc_dointvec_minmax, 56 .proc_handler = proc_dointvec_minmax,
59 .extra1 = &one, 57 .extra1 = SYSCTL_ONE,
60 .extra2 = &u8_max, 58 .extra2 = &u8_max,
61 }, 59 },
62 { 60 {
@@ -65,7 +63,7 @@ static struct ctl_table dccp_default_table[] = {
65 .maxlen = sizeof(sysctl_dccp_retries1), 63 .maxlen = sizeof(sysctl_dccp_retries1),
66 .mode = 0644, 64 .mode = 0644,
67 .proc_handler = proc_dointvec_minmax, 65 .proc_handler = proc_dointvec_minmax,
68 .extra1 = &zero, 66 .extra1 = SYSCTL_ZERO,
69 .extra2 = &u8_max, 67 .extra2 = &u8_max,
70 }, 68 },
71 { 69 {
@@ -74,7 +72,7 @@ static struct ctl_table dccp_default_table[] = {
74 .maxlen = sizeof(sysctl_dccp_retries2), 72 .maxlen = sizeof(sysctl_dccp_retries2),
75 .mode = 0644, 73 .mode = 0644,
76 .proc_handler = proc_dointvec_minmax, 74 .proc_handler = proc_dointvec_minmax,
77 .extra1 = &zero, 75 .extra1 = SYSCTL_ZERO,
78 .extra2 = &u8_max, 76 .extra2 = &u8_max,
79 }, 77 },
80 { 78 {
@@ -83,7 +81,7 @@ static struct ctl_table dccp_default_table[] = {
83 .maxlen = sizeof(sysctl_dccp_tx_qlen), 81 .maxlen = sizeof(sysctl_dccp_tx_qlen),
84 .mode = 0644, 82 .mode = 0644,
85 .proc_handler = proc_dointvec_minmax, 83 .proc_handler = proc_dointvec_minmax,
86 .extra1 = &zero, 84 .extra1 = SYSCTL_ZERO,
87 }, 85 },
88 { 86 {
89 .procname = "sync_ratelimit", 87 .procname = "sync_ratelimit",
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 7d66306b5f39..0b980e841927 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -28,8 +28,6 @@
28#include <net/protocol.h> 28#include <net/protocol.h>
29#include <net/netevent.h> 29#include <net/netevent.h>
30 30
31static int zero;
32static int one = 1;
33static int two = 2; 31static int two = 2;
34static int four = 4; 32static int four = 4;
35static int thousand = 1000; 33static int thousand = 1000;
@@ -576,7 +574,7 @@ static struct ctl_table ipv4_table[] = {
576 .maxlen = sizeof(int), 574 .maxlen = sizeof(int),
577 .mode = 0644, 575 .mode = 0644,
578 .proc_handler = proc_dointvec_minmax, 576 .proc_handler = proc_dointvec_minmax,
579 .extra1 = &zero, 577 .extra1 = SYSCTL_ZERO,
580 }, 578 },
581 { 579 {
582 .procname = "icmp_msgs_burst", 580 .procname = "icmp_msgs_burst",
@@ -584,7 +582,7 @@ static struct ctl_table ipv4_table[] = {
584 .maxlen = sizeof(int), 582 .maxlen = sizeof(int),
585 .mode = 0644, 583 .mode = 0644,
586 .proc_handler = proc_dointvec_minmax, 584 .proc_handler = proc_dointvec_minmax,
587 .extra1 = &zero, 585 .extra1 = SYSCTL_ZERO,
588 }, 586 },
589 { 587 {
590 .procname = "udp_mem", 588 .procname = "udp_mem",
@@ -674,8 +672,8 @@ static struct ctl_table ipv4_net_table[] = {
674 .maxlen = sizeof(int), 672 .maxlen = sizeof(int),
675 .mode = 0644, 673 .mode = 0644,
676 .proc_handler = proc_dointvec_minmax, 674 .proc_handler = proc_dointvec_minmax,
677 .extra1 = &zero, 675 .extra1 = SYSCTL_ZERO,
678 .extra2 = &one, 676 .extra2 = SYSCTL_ONE,
679 }, 677 },
680#endif 678#endif
681 { 679 {
@@ -763,8 +761,8 @@ static struct ctl_table ipv4_net_table[] = {
763 .maxlen = sizeof(int), 761 .maxlen = sizeof(int),
764 .mode = 0644, 762 .mode = 0644,
765 .proc_handler = ipv4_fwd_update_priority, 763 .proc_handler = ipv4_fwd_update_priority,
766 .extra1 = &zero, 764 .extra1 = SYSCTL_ZERO,
767 .extra2 = &one, 765 .extra2 = SYSCTL_ONE,
768 }, 766 },
769 { 767 {
770 .procname = "ip_nonlocal_bind", 768 .procname = "ip_nonlocal_bind",
@@ -794,8 +792,8 @@ static struct ctl_table ipv4_net_table[] = {
794 .maxlen = sizeof(int), 792 .maxlen = sizeof(int),
795 .mode = 0644, 793 .mode = 0644,
796 .proc_handler = proc_dointvec_minmax, 794 .proc_handler = proc_dointvec_minmax,
797 .extra1 = &zero, 795 .extra1 = SYSCTL_ZERO,
798 .extra2 = &one, 796 .extra2 = SYSCTL_ONE,
799 }, 797 },
800#endif 798#endif
801 { 799 {
@@ -864,7 +862,7 @@ static struct ctl_table ipv4_net_table[] = {
864 .maxlen = sizeof(int), 862 .maxlen = sizeof(int),
865 .mode = 0644, 863 .mode = 0644,
866 .proc_handler = proc_dointvec_minmax, 864 .proc_handler = proc_dointvec_minmax,
867 .extra1 = &one 865 .extra1 = SYSCTL_ONE
868 }, 866 },
869#endif 867#endif
870 { 868 {
@@ -969,7 +967,7 @@ static struct ctl_table ipv4_net_table[] = {
969 .maxlen = sizeof(int), 967 .maxlen = sizeof(int),
970 .mode = 0644, 968 .mode = 0644,
971 .proc_handler = proc_dointvec_minmax, 969 .proc_handler = proc_dointvec_minmax,
972 .extra1 = &zero, 970 .extra1 = SYSCTL_ZERO,
973 .extra2 = &two, 971 .extra2 = &two,
974 }, 972 },
975 { 973 {
@@ -1011,7 +1009,7 @@ static struct ctl_table ipv4_net_table[] = {
1011 .maxlen = sizeof(int), 1009 .maxlen = sizeof(int),
1012 .mode = 0644, 1010 .mode = 0644,
1013 .proc_handler = proc_tfo_blackhole_detect_timeout, 1011 .proc_handler = proc_tfo_blackhole_detect_timeout,
1014 .extra1 = &zero, 1012 .extra1 = SYSCTL_ZERO,
1015 }, 1013 },
1016#ifdef CONFIG_IP_ROUTE_MULTIPATH 1014#ifdef CONFIG_IP_ROUTE_MULTIPATH
1017 { 1015 {
@@ -1020,8 +1018,8 @@ static struct ctl_table ipv4_net_table[] = {
1020 .maxlen = sizeof(int), 1018 .maxlen = sizeof(int),
1021 .mode = 0644, 1019 .mode = 0644,
1022 .proc_handler = proc_dointvec_minmax, 1020 .proc_handler = proc_dointvec_minmax,
1023 .extra1 = &zero, 1021 .extra1 = SYSCTL_ZERO,
1024 .extra2 = &one, 1022 .extra2 = SYSCTL_ONE,
1025 }, 1023 },
1026 { 1024 {
1027 .procname = "fib_multipath_hash_policy", 1025 .procname = "fib_multipath_hash_policy",
@@ -1029,8 +1027,8 @@ static struct ctl_table ipv4_net_table[] = {
1029 .maxlen = sizeof(int), 1027 .maxlen = sizeof(int),
1030 .mode = 0644, 1028 .mode = 0644,
1031 .proc_handler = proc_fib_multipath_hash_policy, 1029 .proc_handler = proc_fib_multipath_hash_policy,
1032 .extra1 = &zero, 1030 .extra1 = SYSCTL_ZERO,
1033 .extra2 = &two, 1031 .extra2 = SYSCTL_ONE,
1034 }, 1032 },
1035#endif 1033#endif
1036 { 1034 {
@@ -1047,8 +1045,8 @@ static struct ctl_table ipv4_net_table[] = {
1047 .maxlen = sizeof(int), 1045 .maxlen = sizeof(int),
1048 .mode = 0644, 1046 .mode = 0644,
1049 .proc_handler = proc_dointvec_minmax, 1047 .proc_handler = proc_dointvec_minmax,
1050 .extra1 = &zero, 1048 .extra1 = SYSCTL_ZERO,
1051 .extra2 = &one, 1049 .extra2 = SYSCTL_ONE,
1052 }, 1050 },
1053#endif 1051#endif
1054 { 1052 {
@@ -1078,7 +1076,7 @@ static struct ctl_table ipv4_net_table[] = {
1078 .maxlen = sizeof(int), 1076 .maxlen = sizeof(int),
1079 .mode = 0644, 1077 .mode = 0644,
1080 .proc_handler = proc_dointvec_minmax, 1078 .proc_handler = proc_dointvec_minmax,
1081 .extra1 = &zero, 1079 .extra1 = SYSCTL_ZERO,
1082 .extra2 = &four, 1080 .extra2 = &four,
1083 }, 1081 },
1084 { 1082 {
@@ -1222,7 +1220,7 @@ static struct ctl_table ipv4_net_table[] = {
1222 .maxlen = sizeof(int), 1220 .maxlen = sizeof(int),
1223 .mode = 0644, 1221 .mode = 0644,
1224 .proc_handler = proc_dointvec_minmax, 1222 .proc_handler = proc_dointvec_minmax,
1225 .extra1 = &one, 1223 .extra1 = SYSCTL_ONE,
1226 .extra2 = &gso_max_segs, 1224 .extra2 = &gso_max_segs,
1227 }, 1225 },
1228 { 1226 {
@@ -1231,7 +1229,7 @@ static struct ctl_table ipv4_net_table[] = {
1231 .maxlen = sizeof(int), 1229 .maxlen = sizeof(int),
1232 .mode = 0644, 1230 .mode = 0644,
1233 .proc_handler = proc_dointvec_minmax, 1231 .proc_handler = proc_dointvec_minmax,
1234 .extra1 = &zero, 1232 .extra1 = SYSCTL_ZERO,
1235 .extra2 = &one_day_secs 1233 .extra2 = &one_day_secs
1236 }, 1234 },
1237 { 1235 {
@@ -1240,8 +1238,8 @@ static struct ctl_table ipv4_net_table[] = {
1240 .maxlen = sizeof(int), 1238 .maxlen = sizeof(int),
1241 .mode = 0644, 1239 .mode = 0644,
1242 .proc_handler = proc_dointvec_minmax, 1240 .proc_handler = proc_dointvec_minmax,
1243 .extra1 = &zero, 1241 .extra1 = SYSCTL_ZERO,
1244 .extra2 = &one, 1242 .extra2 = SYSCTL_ONE,
1245 }, 1243 },
1246 { 1244 {
1247 .procname = "tcp_invalid_ratelimit", 1245 .procname = "tcp_invalid_ratelimit",
@@ -1256,7 +1254,7 @@ static struct ctl_table ipv4_net_table[] = {
1256 .maxlen = sizeof(int), 1254 .maxlen = sizeof(int),
1257 .mode = 0644, 1255 .mode = 0644,
1258 .proc_handler = proc_dointvec_minmax, 1256 .proc_handler = proc_dointvec_minmax,
1259 .extra1 = &zero, 1257 .extra1 = SYSCTL_ZERO,
1260 .extra2 = &thousand, 1258 .extra2 = &thousand,
1261 }, 1259 },
1262 { 1260 {
@@ -1265,7 +1263,7 @@ static struct ctl_table ipv4_net_table[] = {
1265 .maxlen = sizeof(int), 1263 .maxlen = sizeof(int),
1266 .mode = 0644, 1264 .mode = 0644,
1267 .proc_handler = proc_dointvec_minmax, 1265 .proc_handler = proc_dointvec_minmax,
1268 .extra1 = &zero, 1266 .extra1 = SYSCTL_ZERO,
1269 .extra2 = &thousand, 1267 .extra2 = &thousand,
1270 }, 1268 },
1271 { 1269 {
@@ -1274,7 +1272,7 @@ static struct ctl_table ipv4_net_table[] = {
1274 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem), 1272 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1275 .mode = 0644, 1273 .mode = 0644,
1276 .proc_handler = proc_dointvec_minmax, 1274 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = &one, 1275 .extra1 = SYSCTL_ONE,
1278 }, 1276 },
1279 { 1277 {
1280 .procname = "tcp_rmem", 1278 .procname = "tcp_rmem",
@@ -1282,7 +1280,7 @@ static struct ctl_table ipv4_net_table[] = {
1282 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem), 1280 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1283 .mode = 0644, 1281 .mode = 0644,
1284 .proc_handler = proc_dointvec_minmax, 1282 .proc_handler = proc_dointvec_minmax,
1285 .extra1 = &one, 1283 .extra1 = SYSCTL_ONE,
1286 }, 1284 },
1287 { 1285 {
1288 .procname = "tcp_comp_sack_delay_ns", 1286 .procname = "tcp_comp_sack_delay_ns",
@@ -1297,7 +1295,7 @@ static struct ctl_table ipv4_net_table[] = {
1297 .maxlen = sizeof(int), 1295 .maxlen = sizeof(int),
1298 .mode = 0644, 1296 .mode = 0644,
1299 .proc_handler = proc_dointvec_minmax, 1297 .proc_handler = proc_dointvec_minmax,
1300 .extra1 = &zero, 1298 .extra1 = SYSCTL_ZERO,
1301 .extra2 = &comp_sack_nr_max, 1299 .extra2 = &comp_sack_nr_max,
1302 }, 1300 },
1303 { 1301 {
@@ -1306,7 +1304,7 @@ static struct ctl_table ipv4_net_table[] = {
1306 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min), 1304 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1307 .mode = 0644, 1305 .mode = 0644,
1308 .proc_handler = proc_dointvec_minmax, 1306 .proc_handler = proc_dointvec_minmax,
1309 .extra1 = &one 1307 .extra1 = SYSCTL_ONE
1310 }, 1308 },
1311 { 1309 {
1312 .procname = "udp_wmem_min", 1310 .procname = "udp_wmem_min",
@@ -1314,7 +1312,7 @@ static struct ctl_table ipv4_net_table[] = {
1314 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min), 1312 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1315 .mode = 0644, 1313 .mode = 0644,
1316 .proc_handler = proc_dointvec_minmax, 1314 .proc_handler = proc_dointvec_minmax,
1317 .extra1 = &one 1315 .extra1 = SYSCTL_ONE
1318 }, 1316 },
1319 { } 1317 { }
1320}; 1318};
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 521e3203e83a..dc73888c7859 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -6432,8 +6432,6 @@ int addrconf_sysctl_disable_policy(struct ctl_table *ctl, int write,
6432} 6432}
6433 6433
6434static int minus_one = -1; 6434static int minus_one = -1;
6435static const int zero = 0;
6436static const int one = 1;
6437static const int two_five_five = 255; 6435static const int two_five_five = 255;
6438 6436
6439static const struct ctl_table addrconf_sysctl[] = { 6437static const struct ctl_table addrconf_sysctl[] = {
@@ -6450,7 +6448,7 @@ static const struct ctl_table addrconf_sysctl[] = {
6450 .maxlen = sizeof(int), 6448 .maxlen = sizeof(int),
6451 .mode = 0644, 6449 .mode = 0644,
6452 .proc_handler = proc_dointvec_minmax, 6450 .proc_handler = proc_dointvec_minmax,
6453 .extra1 = (void *)&one, 6451 .extra1 = (void *)SYSCTL_ONE,
6454 .extra2 = (void *)&two_five_five, 6452 .extra2 = (void *)&two_five_five,
6455 }, 6453 },
6456 { 6454 {
@@ -6809,7 +6807,7 @@ static const struct ctl_table addrconf_sysctl[] = {
6809 .maxlen = sizeof(int), 6807 .maxlen = sizeof(int),
6810 .mode = 0644, 6808 .mode = 0644,
6811 .proc_handler = proc_dointvec_minmax, 6809 .proc_handler = proc_dointvec_minmax,
6812 .extra1 = (void *)&zero, 6810 .extra1 = (void *)SYSCTL_ZERO,
6813 .extra2 = (void *)&two_five_five, 6811 .extra2 = (void *)&two_five_five,
6814 }, 6812 },
6815 { 6813 {
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4d2e6b31a8d6..8b0c33fb19a2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -6031,9 +6031,6 @@ int ipv6_sysctl_rtcache_flush(struct ctl_table *ctl, int write,
6031 return 0; 6031 return 0;
6032} 6032}
6033 6033
6034static int zero;
6035static int one = 1;
6036
6037static struct ctl_table ipv6_route_table_template[] = { 6034static struct ctl_table ipv6_route_table_template[] = {
6038 { 6035 {
6039 .procname = "flush", 6036 .procname = "flush",
@@ -6111,8 +6108,8 @@ static struct ctl_table ipv6_route_table_template[] = {
6111 .maxlen = sizeof(int), 6108 .maxlen = sizeof(int),
6112 .mode = 0644, 6109 .mode = 0644,
6113 .proc_handler = proc_dointvec_minmax, 6110 .proc_handler = proc_dointvec_minmax,
6114 .extra1 = &zero, 6111 .extra1 = SYSCTL_ZERO,
6115 .extra2 = &one, 6112 .extra2 = SYSCTL_ONE,
6116 }, 6113 },
6117 { } 6114 { }
6118}; 6115};
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index dc4c91e0bfb8..ec8fcfc60a27 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -21,8 +21,6 @@
21#include <net/calipso.h> 21#include <net/calipso.h>
22#endif 22#endif
23 23
24static int zero;
25static int one = 1;
26static int flowlabel_reflect_max = 0x7; 24static int flowlabel_reflect_max = 0x7;
27static int auto_flowlabels_min; 25static int auto_flowlabels_min;
28static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX; 26static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
@@ -115,7 +113,7 @@ static struct ctl_table ipv6_table_template[] = {
115 .maxlen = sizeof(int), 113 .maxlen = sizeof(int),
116 .mode = 0644, 114 .mode = 0644,
117 .proc_handler = proc_dointvec_minmax, 115 .proc_handler = proc_dointvec_minmax,
118 .extra1 = &zero, 116 .extra1 = SYSCTL_ZERO,
119 .extra2 = &flowlabel_reflect_max, 117 .extra2 = &flowlabel_reflect_max,
120 }, 118 },
121 { 119 {
@@ -152,8 +150,8 @@ static struct ctl_table ipv6_table_template[] = {
152 .maxlen = sizeof(int), 150 .maxlen = sizeof(int),
153 .mode = 0644, 151 .mode = 0644,
154 .proc_handler = proc_rt6_multipath_hash_policy, 152 .proc_handler = proc_rt6_multipath_hash_policy,
155 .extra1 = &zero, 153 .extra1 = SYSCTL_ZERO,
156 .extra2 = &one, 154 .extra2 = SYSCTL_ONE,
157 }, 155 },
158 { 156 {
159 .procname = "seg6_flowlabel", 157 .procname = "seg6_flowlabel",
@@ -179,7 +177,7 @@ static struct ctl_table ipv6_rotable[] = {
179 .maxlen = sizeof(int), 177 .maxlen = sizeof(int),
180 .mode = 0644, 178 .mode = 0644,
181 .proc_handler = proc_dointvec_minmax, 179 .proc_handler = proc_dointvec_minmax,
182 .extra1 = &one 180 .extra1 = SYSCTL_ONE
183 }, 181 },
184#ifdef CONFIG_NETLABEL 182#ifdef CONFIG_NETLABEL
185 { 183 {
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 198ec4fe4148..c312741df2ce 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -37,8 +37,6 @@
37 37
38#define MPLS_NEIGH_TABLE_UNSPEC (NEIGH_LINK_TABLE + 1) 38#define MPLS_NEIGH_TABLE_UNSPEC (NEIGH_LINK_TABLE + 1)
39 39
40static int zero = 0;
41static int one = 1;
42static int label_limit = (1 << 20) - 1; 40static int label_limit = (1 << 20) - 1;
43static int ttl_max = 255; 41static int ttl_max = 255;
44 42
@@ -2607,7 +2605,7 @@ static int mpls_platform_labels(struct ctl_table *table, int write,
2607 .data = &platform_labels, 2605 .data = &platform_labels,
2608 .maxlen = sizeof(int), 2606 .maxlen = sizeof(int),
2609 .mode = table->mode, 2607 .mode = table->mode,
2610 .extra1 = &zero, 2608 .extra1 = SYSCTL_ZERO,
2611 .extra2 = &label_limit, 2609 .extra2 = &label_limit,
2612 }; 2610 };
2613 2611
@@ -2636,8 +2634,8 @@ static const struct ctl_table mpls_table[] = {
2636 .maxlen = sizeof(int), 2634 .maxlen = sizeof(int),
2637 .mode = 0644, 2635 .mode = 0644,
2638 .proc_handler = proc_dointvec_minmax, 2636 .proc_handler = proc_dointvec_minmax,
2639 .extra1 = &zero, 2637 .extra1 = SYSCTL_ZERO,
2640 .extra2 = &one, 2638 .extra2 = SYSCTL_ONE,
2641 }, 2639 },
2642 { 2640 {
2643 .procname = "default_ttl", 2641 .procname = "default_ttl",
@@ -2645,7 +2643,7 @@ static const struct ctl_table mpls_table[] = {
2645 .maxlen = sizeof(int), 2643 .maxlen = sizeof(int),
2646 .mode = 0644, 2644 .mode = 0644,
2647 .proc_handler = proc_dointvec_minmax, 2645 .proc_handler = proc_dointvec_minmax,
2648 .extra1 = &one, 2646 .extra1 = SYSCTL_ONE,
2649 .extra2 = &ttl_max, 2647 .extra2 = &ttl_max,
2650 }, 2648 },
2651 { } 2649 { }
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 07e0967bf129..060565e7d227 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1726,7 +1726,6 @@ static int ip_vs_zero_all(struct netns_ipvs *ipvs)
1726 1726
1727#ifdef CONFIG_SYSCTL 1727#ifdef CONFIG_SYSCTL
1728 1728
1729static int zero;
1730static int three = 3; 1729static int three = 3;
1731 1730
1732static int 1731static int
@@ -1935,7 +1934,7 @@ static struct ctl_table vs_vars[] = {
1935 .maxlen = sizeof(int), 1934 .maxlen = sizeof(int),
1936 .mode = 0644, 1935 .mode = 0644,
1937 .proc_handler = proc_dointvec_minmax, 1936 .proc_handler = proc_dointvec_minmax,
1938 .extra1 = &zero, 1937 .extra1 = SYSCTL_ZERO,
1939 .extra2 = &three, 1938 .extra2 = &three,
1940 }, 1939 },
1941 { 1940 {
diff --git a/net/rxrpc/sysctl.c b/net/rxrpc/sysctl.c
index 1e3fa67d91aa..2bbb38161851 100644
--- a/net/rxrpc/sysctl.c
+++ b/net/rxrpc/sysctl.c
@@ -11,7 +11,6 @@
11#include "ar-internal.h" 11#include "ar-internal.h"
12 12
13static struct ctl_table_header *rxrpc_sysctl_reg_table; 13static struct ctl_table_header *rxrpc_sysctl_reg_table;
14static const unsigned int one = 1;
15static const unsigned int four = 4; 14static const unsigned int four = 4;
16static const unsigned int thirtytwo = 32; 15static const unsigned int thirtytwo = 32;
17static const unsigned int n_65535 = 65535; 16static const unsigned int n_65535 = 65535;
@@ -97,7 +96,7 @@ static struct ctl_table rxrpc_sysctl_table[] = {
97 .maxlen = sizeof(unsigned int), 96 .maxlen = sizeof(unsigned int),
98 .mode = 0644, 97 .mode = 0644,
99 .proc_handler = proc_dointvec_minmax, 98 .proc_handler = proc_dointvec_minmax,
100 .extra1 = (void *)&one, 99 .extra1 = (void *)SYSCTL_ONE,
101 .extra2 = (void *)&rxrpc_max_client_connections, 100 .extra2 = (void *)&rxrpc_max_client_connections,
102 }, 101 },
103 { 102 {
@@ -115,7 +114,7 @@ static struct ctl_table rxrpc_sysctl_table[] = {
115 .maxlen = sizeof(unsigned int), 114 .maxlen = sizeof(unsigned int),
116 .mode = 0644, 115 .mode = 0644,
117 .proc_handler = proc_dointvec_minmax, 116 .proc_handler = proc_dointvec_minmax,
118 .extra1 = (void *)&one, 117 .extra1 = (void *)SYSCTL_ONE,
119 .extra2 = (void *)&n_max_acks, 118 .extra2 = (void *)&n_max_acks,
120 }, 119 },
121 { 120 {
@@ -124,7 +123,7 @@ static struct ctl_table rxrpc_sysctl_table[] = {
124 .maxlen = sizeof(unsigned int), 123 .maxlen = sizeof(unsigned int),
125 .mode = 0644, 124 .mode = 0644,
126 .proc_handler = proc_dointvec_minmax, 125 .proc_handler = proc_dointvec_minmax,
127 .extra1 = (void *)&one, 126 .extra1 = (void *)SYSCTL_ONE,
128 .extra2 = (void *)&n_65535, 127 .extra2 = (void *)&n_65535,
129 }, 128 },
130 { 129 {
@@ -133,7 +132,7 @@ static struct ctl_table rxrpc_sysctl_table[] = {
133 .maxlen = sizeof(unsigned int), 132 .maxlen = sizeof(unsigned int),
134 .mode = 0644, 133 .mode = 0644,
135 .proc_handler = proc_dointvec_minmax, 134 .proc_handler = proc_dointvec_minmax,
136 .extra1 = (void *)&one, 135 .extra1 = (void *)SYSCTL_ONE,
137 .extra2 = (void *)&four, 136 .extra2 = (void *)&four,
138 }, 137 },
139 138
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 9a19147902f1..1250751bca1b 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -25,10 +25,7 @@
25#include <net/sctp/sctp.h> 25#include <net/sctp/sctp.h>
26#include <linux/sysctl.h> 26#include <linux/sysctl.h>
27 27
28static int zero = 0;
29static int one = 1;
30static int timer_max = 86400000; /* ms in one day */ 28static int timer_max = 86400000; /* ms in one day */
31static int int_max = INT_MAX;
32static int sack_timer_min = 1; 29static int sack_timer_min = 1;
33static int sack_timer_max = 500; 30static int sack_timer_max = 500;
34static int addr_scope_max = SCTP_SCOPE_POLICY_MAX; 31static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
@@ -92,7 +89,7 @@ static struct ctl_table sctp_net_table[] = {
92 .maxlen = sizeof(unsigned int), 89 .maxlen = sizeof(unsigned int),
93 .mode = 0644, 90 .mode = 0644,
94 .proc_handler = proc_dointvec_minmax, 91 .proc_handler = proc_dointvec_minmax,
95 .extra1 = &one, 92 .extra1 = SYSCTL_ONE,
96 .extra2 = &timer_max 93 .extra2 = &timer_max
97 }, 94 },
98 { 95 {
@@ -101,7 +98,7 @@ static struct ctl_table sctp_net_table[] = {
101 .maxlen = sizeof(unsigned int), 98 .maxlen = sizeof(unsigned int),
102 .mode = 0644, 99 .mode = 0644,
103 .proc_handler = proc_sctp_do_rto_min, 100 .proc_handler = proc_sctp_do_rto_min,
104 .extra1 = &one, 101 .extra1 = SYSCTL_ONE,
105 .extra2 = &init_net.sctp.rto_max 102 .extra2 = &init_net.sctp.rto_max
106 }, 103 },
107 { 104 {
@@ -137,8 +134,8 @@ static struct ctl_table sctp_net_table[] = {
137 .maxlen = sizeof(int), 134 .maxlen = sizeof(int),
138 .mode = 0644, 135 .mode = 0644,
139 .proc_handler = proc_dointvec_minmax, 136 .proc_handler = proc_dointvec_minmax,
140 .extra1 = &zero, 137 .extra1 = SYSCTL_ZERO,
141 .extra2 = &int_max 138 .extra2 = SYSCTL_INT_MAX,
142 }, 139 },
143 { 140 {
144 .procname = "cookie_preserve_enable", 141 .procname = "cookie_preserve_enable",
@@ -160,7 +157,7 @@ static struct ctl_table sctp_net_table[] = {
160 .maxlen = sizeof(unsigned int), 157 .maxlen = sizeof(unsigned int),
161 .mode = 0644, 158 .mode = 0644,
162 .proc_handler = proc_dointvec_minmax, 159 .proc_handler = proc_dointvec_minmax,
163 .extra1 = &one, 160 .extra1 = SYSCTL_ONE,
164 .extra2 = &timer_max 161 .extra2 = &timer_max
165 }, 162 },
166 { 163 {
@@ -178,7 +175,7 @@ static struct ctl_table sctp_net_table[] = {
178 .maxlen = sizeof(unsigned int), 175 .maxlen = sizeof(unsigned int),
179 .mode = 0644, 176 .mode = 0644,
180 .proc_handler = proc_dointvec_minmax, 177 .proc_handler = proc_dointvec_minmax,
181 .extra1 = &one, 178 .extra1 = SYSCTL_ONE,
182 .extra2 = &timer_max 179 .extra2 = &timer_max
183 }, 180 },
184 { 181 {
@@ -187,8 +184,8 @@ static struct ctl_table sctp_net_table[] = {
187 .maxlen = sizeof(int), 184 .maxlen = sizeof(int),
188 .mode = 0644, 185 .mode = 0644,
189 .proc_handler = proc_dointvec_minmax, 186 .proc_handler = proc_dointvec_minmax,
190 .extra1 = &one, 187 .extra1 = SYSCTL_ONE,
191 .extra2 = &int_max 188 .extra2 = SYSCTL_INT_MAX,
192 }, 189 },
193 { 190 {
194 .procname = "path_max_retrans", 191 .procname = "path_max_retrans",
@@ -196,8 +193,8 @@ static struct ctl_table sctp_net_table[] = {
196 .maxlen = sizeof(int), 193 .maxlen = sizeof(int),
197 .mode = 0644, 194 .mode = 0644,
198 .proc_handler = proc_dointvec_minmax, 195 .proc_handler = proc_dointvec_minmax,
199 .extra1 = &one, 196 .extra1 = SYSCTL_ONE,
200 .extra2 = &int_max 197 .extra2 = SYSCTL_INT_MAX,
201 }, 198 },
202 { 199 {
203 .procname = "max_init_retransmits", 200 .procname = "max_init_retransmits",
@@ -205,8 +202,8 @@ static struct ctl_table sctp_net_table[] = {
205 .maxlen = sizeof(int), 202 .maxlen = sizeof(int),
206 .mode = 0644, 203 .mode = 0644,
207 .proc_handler = proc_dointvec_minmax, 204 .proc_handler = proc_dointvec_minmax,
208 .extra1 = &one, 205 .extra1 = SYSCTL_ONE,
209 .extra2 = &int_max 206 .extra2 = SYSCTL_INT_MAX,
210 }, 207 },
211 { 208 {
212 .procname = "pf_retrans", 209 .procname = "pf_retrans",
@@ -214,8 +211,8 @@ static struct ctl_table sctp_net_table[] = {
214 .maxlen = sizeof(int), 211 .maxlen = sizeof(int),
215 .mode = 0644, 212 .mode = 0644,
216 .proc_handler = proc_dointvec_minmax, 213 .proc_handler = proc_dointvec_minmax,
217 .extra1 = &zero, 214 .extra1 = SYSCTL_ZERO,
218 .extra2 = &int_max 215 .extra2 = SYSCTL_INT_MAX,
219 }, 216 },
220 { 217 {
221 .procname = "sndbuf_policy", 218 .procname = "sndbuf_policy",
@@ -286,7 +283,7 @@ static struct ctl_table sctp_net_table[] = {
286 .maxlen = sizeof(int), 283 .maxlen = sizeof(int),
287 .mode = 0644, 284 .mode = 0644,
288 .proc_handler = proc_dointvec_minmax, 285 .proc_handler = proc_dointvec_minmax,
289 .extra1 = &zero, 286 .extra1 = SYSCTL_ZERO,
290 .extra2 = &addr_scope_max, 287 .extra2 = &addr_scope_max,
291 }, 288 },
292 { 289 {
@@ -295,7 +292,7 @@ static struct ctl_table sctp_net_table[] = {
295 .maxlen = sizeof(int), 292 .maxlen = sizeof(int),
296 .mode = 0644, 293 .mode = 0644,
297 .proc_handler = &proc_dointvec_minmax, 294 .proc_handler = &proc_dointvec_minmax,
298 .extra1 = &one, 295 .extra1 = SYSCTL_ONE,
299 .extra2 = &rwnd_scale_max, 296 .extra2 = &rwnd_scale_max,
300 }, 297 },
301 { 298 {
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 52abddac19e5..2ec349ed4770 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -80,7 +80,6 @@ static unsigned int min_slot_table_size = RPCRDMA_MIN_SLOT_TABLE;
80static unsigned int max_slot_table_size = RPCRDMA_MAX_SLOT_TABLE; 80static unsigned int max_slot_table_size = RPCRDMA_MAX_SLOT_TABLE;
81static unsigned int min_inline_size = RPCRDMA_MIN_INLINE; 81static unsigned int min_inline_size = RPCRDMA_MIN_INLINE;
82static unsigned int max_inline_size = RPCRDMA_MAX_INLINE; 82static unsigned int max_inline_size = RPCRDMA_MAX_INLINE;
83static unsigned int zero;
84static unsigned int max_padding = PAGE_SIZE; 83static unsigned int max_padding = PAGE_SIZE;
85static unsigned int min_memreg = RPCRDMA_BOUNCEBUFFERS; 84static unsigned int min_memreg = RPCRDMA_BOUNCEBUFFERS;
86static unsigned int max_memreg = RPCRDMA_LAST - 1; 85static unsigned int max_memreg = RPCRDMA_LAST - 1;
@@ -122,7 +121,7 @@ static struct ctl_table xr_tunables_table[] = {
122 .maxlen = sizeof(unsigned int), 121 .maxlen = sizeof(unsigned int),
123 .mode = 0644, 122 .mode = 0644,
124 .proc_handler = proc_dointvec_minmax, 123 .proc_handler = proc_dointvec_minmax,
125 .extra1 = &zero, 124 .extra1 = SYSCTL_ZERO,
126 .extra2 = &max_padding, 125 .extra2 = &max_padding,
127 }, 126 },
128 { 127 {
diff --git a/net/tipc/sysctl.c b/net/tipc/sysctl.c
index 9df82a573aa7..6159d327db76 100644
--- a/net/tipc/sysctl.c
+++ b/net/tipc/sysctl.c
@@ -38,8 +38,6 @@
38 38
39#include <linux/sysctl.h> 39#include <linux/sysctl.h>
40 40
41static int zero;
42static int one = 1;
43static struct ctl_table_header *tipc_ctl_hdr; 41static struct ctl_table_header *tipc_ctl_hdr;
44 42
45static struct ctl_table tipc_table[] = { 43static struct ctl_table tipc_table[] = {
@@ -49,7 +47,7 @@ static struct ctl_table tipc_table[] = {
49 .maxlen = sizeof(sysctl_tipc_rmem), 47 .maxlen = sizeof(sysctl_tipc_rmem),
50 .mode = 0644, 48 .mode = 0644,
51 .proc_handler = proc_dointvec_minmax, 49 .proc_handler = proc_dointvec_minmax,
52 .extra1 = &one, 50 .extra1 = SYSCTL_ONE,
53 }, 51 },
54 { 52 {
55 .procname = "named_timeout", 53 .procname = "named_timeout",
@@ -57,7 +55,7 @@ static struct ctl_table tipc_table[] = {
57 .maxlen = sizeof(sysctl_tipc_named_timeout), 55 .maxlen = sizeof(sysctl_tipc_named_timeout),
58 .mode = 0644, 56 .mode = 0644,
59 .proc_handler = proc_dointvec_minmax, 57 .proc_handler = proc_dointvec_minmax,
60 .extra1 = &zero, 58 .extra1 = SYSCTL_ZERO,
61 }, 59 },
62 { 60 {
63 .procname = "sk_filter", 61 .procname = "sk_filter",
diff --git a/security/keys/sysctl.c b/security/keys/sysctl.c
index dd1e21fab827..b46b651b3c4c 100644
--- a/security/keys/sysctl.c
+++ b/security/keys/sysctl.c
@@ -9,8 +9,6 @@
9#include <linux/sysctl.h> 9#include <linux/sysctl.h>
10#include "internal.h" 10#include "internal.h"
11 11
12static const int zero, one = 1, max = INT_MAX;
13
14struct ctl_table key_sysctls[] = { 12struct ctl_table key_sysctls[] = {
15 { 13 {
16 .procname = "maxkeys", 14 .procname = "maxkeys",
@@ -18,8 +16,8 @@ struct ctl_table key_sysctls[] = {
18 .maxlen = sizeof(unsigned), 16 .maxlen = sizeof(unsigned),
19 .mode = 0644, 17 .mode = 0644,
20 .proc_handler = proc_dointvec_minmax, 18 .proc_handler = proc_dointvec_minmax,
21 .extra1 = (void *) &one, 19 .extra1 = (void *) SYSCTL_ONE,
22 .extra2 = (void *) &max, 20 .extra2 = (void *) SYSCTL_INT_MAX,
23 }, 21 },
24 { 22 {
25 .procname = "maxbytes", 23 .procname = "maxbytes",
@@ -27,8 +25,8 @@ struct ctl_table key_sysctls[] = {
27 .maxlen = sizeof(unsigned), 25 .maxlen = sizeof(unsigned),
28 .mode = 0644, 26 .mode = 0644,
29 .proc_handler = proc_dointvec_minmax, 27 .proc_handler = proc_dointvec_minmax,
30 .extra1 = (void *) &one, 28 .extra1 = (void *) SYSCTL_ONE,
31 .extra2 = (void *) &max, 29 .extra2 = (void *) SYSCTL_INT_MAX,
32 }, 30 },
33 { 31 {
34 .procname = "root_maxkeys", 32 .procname = "root_maxkeys",
@@ -36,8 +34,8 @@ struct ctl_table key_sysctls[] = {
36 .maxlen = sizeof(unsigned), 34 .maxlen = sizeof(unsigned),
37 .mode = 0644, 35 .mode = 0644,
38 .proc_handler = proc_dointvec_minmax, 36 .proc_handler = proc_dointvec_minmax,
39 .extra1 = (void *) &one, 37 .extra1 = (void *) SYSCTL_ONE,
40 .extra2 = (void *) &max, 38 .extra2 = (void *) SYSCTL_INT_MAX,
41 }, 39 },
42 { 40 {
43 .procname = "root_maxbytes", 41 .procname = "root_maxbytes",
@@ -45,8 +43,8 @@ struct ctl_table key_sysctls[] = {
45 .maxlen = sizeof(unsigned), 43 .maxlen = sizeof(unsigned),
46 .mode = 0644, 44 .mode = 0644,
47 .proc_handler = proc_dointvec_minmax, 45 .proc_handler = proc_dointvec_minmax,
48 .extra1 = (void *) &one, 46 .extra1 = (void *) SYSCTL_ONE,
49 .extra2 = (void *) &max, 47 .extra2 = (void *) SYSCTL_INT_MAX,
50 }, 48 },
51 { 49 {
52 .procname = "gc_delay", 50 .procname = "gc_delay",
@@ -54,8 +52,8 @@ struct ctl_table key_sysctls[] = {
54 .maxlen = sizeof(unsigned), 52 .maxlen = sizeof(unsigned),
55 .mode = 0644, 53 .mode = 0644,
56 .proc_handler = proc_dointvec_minmax, 54 .proc_handler = proc_dointvec_minmax,
57 .extra1 = (void *) &zero, 55 .extra1 = (void *) SYSCTL_ZERO,
58 .extra2 = (void *) &max, 56 .extra2 = (void *) SYSCTL_INT_MAX,
59 }, 57 },
60#ifdef CONFIG_PERSISTENT_KEYRINGS 58#ifdef CONFIG_PERSISTENT_KEYRINGS
61 { 59 {
@@ -64,8 +62,8 @@ struct ctl_table key_sysctls[] = {
64 .maxlen = sizeof(unsigned), 62 .maxlen = sizeof(unsigned),
65 .mode = 0644, 63 .mode = 0644,
66 .proc_handler = proc_dointvec_minmax, 64 .proc_handler = proc_dointvec_minmax,
67 .extra1 = (void *) &zero, 65 .extra1 = (void *) SYSCTL_ZERO,
68 .extra2 = (void *) &max, 66 .extra2 = (void *) SYSCTL_INT_MAX,
69 }, 67 },
70#endif 68#endif
71 { } 69 { }
diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index 81519c804888..ee5cb944f4ad 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -43,8 +43,6 @@ static struct super_block *pinned_root;
43static DEFINE_SPINLOCK(pinned_root_spinlock); 43static DEFINE_SPINLOCK(pinned_root_spinlock);
44 44
45#ifdef CONFIG_SYSCTL 45#ifdef CONFIG_SYSCTL
46static int zero;
47static int one = 1;
48 46
49static struct ctl_path loadpin_sysctl_path[] = { 47static struct ctl_path loadpin_sysctl_path[] = {
50 { .procname = "kernel", }, 48 { .procname = "kernel", },
@@ -59,8 +57,8 @@ static struct ctl_table loadpin_sysctl_table[] = {
59 .maxlen = sizeof(int), 57 .maxlen = sizeof(int),
60 .mode = 0644, 58 .mode = 0644,
61 .proc_handler = proc_dointvec_minmax, 59 .proc_handler = proc_dointvec_minmax,
62 .extra1 = &zero, 60 .extra1 = SYSCTL_ZERO,
63 .extra2 = &one, 61 .extra2 = SYSCTL_ONE,
64 }, 62 },
65 { } 63 { }
66}; 64};
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index 01c6239c4493..94dc346370b1 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -445,7 +445,6 @@ static int yama_dointvec_minmax(struct ctl_table *table, int write,
445 return proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos); 445 return proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos);
446} 446}
447 447
448static int zero;
449static int max_scope = YAMA_SCOPE_NO_ATTACH; 448static int max_scope = YAMA_SCOPE_NO_ATTACH;
450 449
451static struct ctl_path yama_sysctl_path[] = { 450static struct ctl_path yama_sysctl_path[] = {
@@ -461,7 +460,7 @@ static struct ctl_table yama_sysctl_table[] = {
461 .maxlen = sizeof(int), 460 .maxlen = sizeof(int),
462 .mode = 0644, 461 .mode = 0644,
463 .proc_handler = yama_dointvec_minmax, 462 .proc_handler = yama_dointvec_minmax,
464 .extra1 = &zero, 463 .extra1 = SYSCTL_ZERO,
465 .extra2 = &max_scope, 464 .extra2 = &max_scope,
466 }, 465 },
467 { } 466 { }