Skip to content

Commit 59fc453

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton: - the rest of MM - lib/bitmap updates - hfs updates - fatfs updates - various other misc things * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (94 commits) mm/gup.c: fix __get_user_pages_fast() comment mm: Fix warning in insert_pfn() memory-hotplug.rst: add some details about locking internals powerpc/powernv: hold device_hotplug_lock when calling memtrace_offline_pages() powerpc/powernv: hold device_hotplug_lock when calling device_online() mm/memory_hotplug: fix online/offline_pages called w.o. mem_hotplug_lock mm/memory_hotplug: make add_memory() take the device_hotplug_lock mm/memory_hotplug: make remove_memory() take the device_hotplug_lock mm/memblock.c: warn if zero alignment was requested memblock: stop using implicit alignment to SMP_CACHE_BYTES docs/boot-time-mm: remove bootmem documentation mm: remove include/linux/bootmem.h memblock: replace BOOTMEM_ALLOC_* with MEMBLOCK variants mm: remove nobootmem memblock: rename __free_pages_bootmem to memblock_free_pages memblock: rename free_all_bootmem to memblock_free_all memblock: replace free_bootmem_late with memblock_free_late memblock: replace free_bootmem{_node} with memblock_free mm: nobootmem: remove bootmem allocation APIs memblock: replace alloc_bootmem with memblock_alloc ...
2 parents 310c758 + 2ebe822 commit 59fc453

File tree

423 files changed

+1918
-3094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

423 files changed

+1918
-3094
lines changed

.mailmap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ Peter Oruba <peter.oruba@amd.com>
160160
Pratyush Anand <pratyush.anand@gmail.com> <pratyush.anand@st.com>
161161
Praveen BP <praveenbp@ti.com>
162162
Qais Yousef <qsyousef@gmail.com> <qais.yousef@imgtec.com>
163+
Oleksij Rempel <linux@rempel-privat.de> <bug-track@fisher-privat.net>
164+
Oleksij Rempel <linux@rempel-privat.de> <external.Oleksij.Rempel@de.bosch.com>
165+
Oleksij Rempel <linux@rempel-privat.de> <fixed-term.Oleksij.Rempel@de.bosch.com>
166+
Oleksij Rempel <linux@rempel-privat.de> <o.rempel@pengutronix.de>
167+
Oleksij Rempel <linux@rempel-privat.de> <ore@pengutronix.de>
163168
Rajesh Shah <rajesh.shah@intel.com>
164169
Ralf Baechle <ralf@linux-mips.org>
165170
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>

Documentation/admin-guide/mm/memory-hotplug.rst

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Memory Hotplug
55
==============
66

77
:Created: Jul 28 2007
8-
:Updated: Add description of notifier of memory hotplug: Oct 11 2007
8+
:Updated: Add some details about locking internals: Aug 20 2018
99

1010
This document is about memory hotplug including how-to-use and current status.
1111
Because Memory Hotplug is still under development, contents of this text will
@@ -392,6 +392,46 @@ Need more implementation yet....
392392
- Notification completion of remove works by OS to firmware.
393393
- Guard from remove if not yet.
394394

395+
396+
Locking Internals
397+
=================
398+
399+
When adding/removing memory that uses memory block devices (i.e. ordinary RAM),
400+
the device_hotplug_lock should be held to:
401+
402+
- synchronize against online/offline requests (e.g. via sysfs). This way, memory
403+
block devices can only be accessed (.online/.state attributes) by user
404+
space once memory has been fully added. And when removing memory, we
405+
know nobody is in critical sections.
406+
- synchronize against CPU hotplug and similar (e.g. relevant for ACPI and PPC)
407+
408+
Especially, there is a possible lock inversion that is avoided using
409+
device_hotplug_lock when adding memory and user space tries to online that
410+
memory faster than expected:
411+
412+
- device_online() will first take the device_lock(), followed by
413+
mem_hotplug_lock
414+
- add_memory_resource() will first take the mem_hotplug_lock, followed by
415+
the device_lock() (while creating the devices, during bus_add_device()).
416+
417+
As the device is visible to user space before taking the device_lock(), this
418+
can result in a lock inversion.
419+
420+
onlining/offlining of memory should be done via device_online()/
421+
device_offline() - to make sure it is properly synchronized to actions
422+
via sysfs. Holding device_hotplug_lock is advised (to e.g. protect online_type)
423+
424+
When adding/removing/onlining/offlining memory or adding/removing
425+
heterogeneous/device memory, we should always hold the mem_hotplug_lock in
426+
write mode to serialise memory hotplug (e.g. access to global/zone
427+
variables).
428+
429+
In addition, mem_hotplug_lock (in contrast to device_hotplug_lock) in read
430+
mode allows for a quite efficient get_online_mems/put_online_mems
431+
implementation, so code accessing memory can protect from that memory
432+
vanishing.
433+
434+
395435
Future Work
396436
===========
397437

Documentation/core-api/boot-time-mm.rst

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,23 @@ Boot time memory management
55
Early system initialization cannot use "normal" memory management
66
simply because it is not set up yet. But there is still need to
77
allocate memory for various data structures, for instance for the
8-
physical page allocator. To address this, a specialized allocator
9-
called the :ref:`Boot Memory Allocator <bootmem>`, or bootmem, was
10-
introduced. Several years later PowerPC developers added a "Logical
11-
Memory Blocks" allocator, which was later adopted by other
12-
architectures and renamed to :ref:`memblock <memblock>`. There is also
13-
a compatibility layer called `nobootmem` that translates bootmem
14-
allocation interfaces to memblock calls.
8+
physical page allocator.
159

16-
The selection of the early allocator is done using
17-
``CONFIG_NO_BOOTMEM`` and ``CONFIG_HAVE_MEMBLOCK`` kernel
18-
configuration options. These options are enabled or disabled
19-
statically by the architectures' Kconfig files.
20-
21-
* Architectures that rely only on bootmem select
22-
``CONFIG_NO_BOOTMEM=n && CONFIG_HAVE_MEMBLOCK=n``.
23-
* The users of memblock with the nobootmem compatibility layer set
24-
``CONFIG_NO_BOOTMEM=y && CONFIG_HAVE_MEMBLOCK=y``.
25-
* And for those that use both memblock and bootmem the configuration
26-
includes ``CONFIG_NO_BOOTMEM=n && CONFIG_HAVE_MEMBLOCK=y``.
27-
28-
Whichever allocator is used, it is the responsibility of the
29-
architecture specific initialization to set it up in
30-
:c:func:`setup_arch` and tear it down in :c:func:`mem_init` functions.
10+
A specialized allocator called ``memblock`` performs the
11+
boot time memory management. The architecture specific initialization
12+
must set it up in :c:func:`setup_arch` and tear it down in
13+
:c:func:`mem_init` functions.
3114

3215
Once the early memory management is available it offers a variety of
3316
functions and macros for memory allocations. The allocation request
3417
may be directed to the first (and probably the only) node or to a
3518
particular node in a NUMA system. There are API variants that panic
36-
when an allocation fails and those that don't. And more recent and
37-
advanced memblock even allows controlling its own behaviour.
38-
39-
.. _bootmem:
40-
41-
Bootmem
42-
=======
19+
when an allocation fails and those that don't.
4320

44-
(mostly stolen from Mel Gorman's "Understanding the Linux Virtual
45-
Memory Manager" `book`_)
21+
Memblock also offers a variety of APIs that control its own behaviour.
4622

47-
.. _book: https://www.kernel.org/doc/gorman/
48-
49-
.. kernel-doc:: mm/bootmem.c
50-
:doc: bootmem overview
51-
52-
.. _memblock:
53-
54-
Memblock
55-
========
23+
Memblock Overview
24+
=================
5625

5726
.. kernel-doc:: mm/memblock.c
5827
:doc: memblock overview
@@ -61,26 +30,6 @@ Memblock
6130
Functions and structures
6231
========================
6332

64-
Common API
65-
----------
66-
67-
The functions that are described in this section are available
68-
regardless of what early memory manager is enabled.
69-
70-
.. kernel-doc:: mm/nobootmem.c
71-
72-
Bootmem specific API
73-
--------------------
74-
75-
These interfaces available only with bootmem, i.e when ``CONFIG_NO_BOOTMEM=n``
76-
77-
.. kernel-doc:: include/linux/bootmem.h
78-
.. kernel-doc:: mm/bootmem.c
79-
:functions:
80-
81-
Memblock specific API
82-
---------------------
83-
8433
Here is the description of memblock data structures, functions and
8534
macros. Some of them are actually internal, but since they are
8635
documented it would be silly to omit them. Besides, reading the

arch/alpha/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ config ALPHA
3131
select ODD_RT_SIGACTION
3232
select OLD_SIGSUSPEND
3333
select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
34-
select HAVE_MEMBLOCK
35-
select NO_BOOTMEM
3634
help
3735
The Alpha is a 64-bit general-purpose processor designed and
3836
marketed by the Digital Equipment Corporation of blessed memory,

arch/alpha/include/asm/processor.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010

1111
#include <linux/personality.h> /* for ADDR_LIMIT_32BIT */
1212

13-
/*
14-
* Returns current instruction pointer ("program counter").
15-
*/
16-
#define current_text_addr() \
17-
({ void *__pc; __asm__ ("br %0,.+4" : "=r"(__pc)); __pc; })
18-
1913
/*
2014
* We have a 42-bit user address space: 4TB user VM...
2115
*/

arch/alpha/kernel/core_apecs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ apecs_init_arch(void)
346346
* Window 1 is direct access 1GB at 1GB
347347
* Window 2 is scatter-gather 8MB at 8MB (for isa)
348348
*/
349-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
349+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
350+
SMP_CACHE_BYTES);
350351
hose->sg_pci = NULL;
351352
__direct_map_base = 0x40000000;
352353
__direct_map_size = 0x40000000;

arch/alpha/kernel/core_cia.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <linux/pci.h>
2222
#include <linux/sched.h>
2323
#include <linux/init.h>
24-
#include <linux/bootmem.h>
24+
#include <linux/memblock.h>
2525

2626
#include <asm/ptrace.h>
2727
#include <asm/mce.h>
@@ -331,7 +331,7 @@ cia_prepare_tbia_workaround(int window)
331331
long i;
332332

333333
/* Use minimal 1K map. */
334-
ppte = __alloc_bootmem(CIA_BROKEN_TBIA_SIZE, 32768, 0);
334+
ppte = memblock_alloc_from(CIA_BROKEN_TBIA_SIZE, 32768, 0);
335335
pte = (virt_to_phys(ppte) >> (PAGE_SHIFT - 1)) | 1;
336336

337337
for (i = 0; i < CIA_BROKEN_TBIA_SIZE / sizeof(unsigned long); ++i)

arch/alpha/kernel/core_irongate.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/sched.h>
2121
#include <linux/init.h>
2222
#include <linux/initrd.h>
23-
#include <linux/bootmem.h>
2423
#include <linux/memblock.h>
2524

2625
#include <asm/ptrace.h>
@@ -234,8 +233,7 @@ albacore_init_arch(void)
234233
unsigned long size;
235234

236235
size = initrd_end - initrd_start;
237-
free_bootmem_node(NODE_DATA(0), __pa(initrd_start),
238-
PAGE_ALIGN(size));
236+
memblock_free(__pa(initrd_start), PAGE_ALIGN(size));
239237
if (!move_initrd(pci_mem))
240238
printk("irongate_init_arch: initrd too big "
241239
"(%ldK)\ndisabling initrd\n",

arch/alpha/kernel/core_lca.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ lca_init_arch(void)
275275
* Note that we do not try to save any of the DMA window CSRs
276276
* before setting them, since we cannot read those CSRs on LCA.
277277
*/
278-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
278+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
279+
SMP_CACHE_BYTES);
279280
hose->sg_pci = NULL;
280281
__direct_map_base = 0x40000000;
281282
__direct_map_size = 0x40000000;

arch/alpha/kernel/core_marvel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <linux/mc146818rtc.h>
1919
#include <linux/rtc.h>
2020
#include <linux/module.h>
21-
#include <linux/bootmem.h>
21+
#include <linux/memblock.h>
2222

2323
#include <asm/ptrace.h>
2424
#include <asm/smp.h>
@@ -82,7 +82,7 @@ mk_resource_name(int pe, int port, char *str)
8282
char *name;
8383

8484
sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port);
85-
name = alloc_bootmem(strlen(tmp) + 1);
85+
name = memblock_alloc(strlen(tmp) + 1, SMP_CACHE_BYTES);
8686
strcpy(name, tmp);
8787

8888
return name;
@@ -117,7 +117,7 @@ alloc_io7(unsigned int pe)
117117
return NULL;
118118
}
119119

120-
io7 = alloc_bootmem(sizeof(*io7));
120+
io7 = memblock_alloc(sizeof(*io7), SMP_CACHE_BYTES);
121121
io7->pe = pe;
122122
raw_spin_lock_init(&io7->irq_lock);
123123

arch/alpha/kernel/core_mcpcia.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,11 @@ mcpcia_startup_hose(struct pci_controller *hose)
364364
* Window 1 is scatter-gather (up to) 1GB at 1GB (for pci)
365365
* Window 2 is direct access 2GB at 2GB
366366
*/
367-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
367+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
368+
SMP_CACHE_BYTES);
368369
hose->sg_pci = iommu_arena_new(hose, 0x40000000,
369-
size_for_memory(0x40000000), 0);
370+
size_for_memory(0x40000000),
371+
SMP_CACHE_BYTES);
370372

371373
__direct_map_base = 0x80000000;
372374
__direct_map_size = 0x80000000;

arch/alpha/kernel/core_t2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ t2_sg_map_window2(struct pci_controller *hose,
351351

352352
/* Note we can only do 1 SG window, as the other is for direct, so
353353
do an ISA SG area, especially for the floppy. */
354-
hose->sg_isa = iommu_arena_new(hose, base, length, 0);
354+
hose->sg_isa = iommu_arena_new(hose, base, length, SMP_CACHE_BYTES);
355355
hose->sg_pci = NULL;
356356

357357
temp = (base & 0xfff00000UL) | ((base + length - 1) >> 20);

arch/alpha/kernel/core_titan.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/sched.h>
1717
#include <linux/init.h>
1818
#include <linux/vmalloc.h>
19-
#include <linux/bootmem.h>
19+
#include <linux/memblock.h>
2020

2121
#include <asm/ptrace.h>
2222
#include <asm/smp.h>
@@ -316,10 +316,12 @@ titan_init_one_pachip_port(titan_pachip_port *port, int index)
316316
* Window 1 is direct access 1GB at 2GB
317317
* Window 2 is scatter-gather 1GB at 3GB
318318
*/
319-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
319+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
320+
SMP_CACHE_BYTES);
320321
hose->sg_isa->align_entry = 8; /* 64KB for ISA */
321322

322-
hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x40000000, 0);
323+
hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x40000000,
324+
SMP_CACHE_BYTES);
323325
hose->sg_pci->align_entry = 4; /* Titan caches 4 PTEs at a time */
324326

325327
port->wsba[0].csr = hose->sg_isa->dma_base | 3;

arch/alpha/kernel/core_tsunami.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/pci.h>
1818
#include <linux/sched.h>
1919
#include <linux/init.h>
20-
#include <linux/bootmem.h>
20+
#include <linux/memblock.h>
2121

2222
#include <asm/ptrace.h>
2323
#include <asm/smp.h>
@@ -319,12 +319,14 @@ tsunami_init_one_pchip(tsunami_pchip *pchip, int index)
319319
* NOTE: we need the align_entry settings for Acer devices on ES40,
320320
* specifically floppy and IDE when memory is larger than 2GB.
321321
*/
322-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
322+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
323+
SMP_CACHE_BYTES);
323324
/* Initially set for 4 PTEs, but will be overridden to 64K for ISA. */
324325
hose->sg_isa->align_entry = 4;
325326

326327
hose->sg_pci = iommu_arena_new(hose, 0x40000000,
327-
size_for_memory(0x40000000), 0);
328+
size_for_memory(0x40000000),
329+
SMP_CACHE_BYTES);
328330
hose->sg_pci->align_entry = 4; /* Tsunami caches 4 PTEs at a time */
329331

330332
__direct_map_base = 0x80000000;

arch/alpha/kernel/core_wildfire.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ wildfire_init_hose(int qbbno, int hoseno)
111111
* ??? We ought to scale window 3 memory.
112112
*
113113
*/
114-
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
115-
hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x08000000, 0);
114+
hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000,
115+
SMP_CACHE_BYTES);
116+
hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x08000000,
117+
SMP_CACHE_BYTES);
116118

117119
pci = WILDFIRE_pci(qbbno, hoseno);
118120

arch/alpha/kernel/pci-noop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <linux/pci.h>
99
#include <linux/init.h>
10-
#include <linux/bootmem.h>
10+
#include <linux/memblock.h>
1111
#include <linux/gfp.h>
1212
#include <linux/capability.h>
1313
#include <linux/mm.h>
@@ -33,7 +33,7 @@ alloc_pci_controller(void)
3333
{
3434
struct pci_controller *hose;
3535

36-
hose = alloc_bootmem(sizeof(*hose));
36+
hose = memblock_alloc(sizeof(*hose), SMP_CACHE_BYTES);
3737

3838
*hose_tail = hose;
3939
hose_tail = &hose->next;
@@ -44,7 +44,7 @@ alloc_pci_controller(void)
4444
struct resource * __init
4545
alloc_resource(void)
4646
{
47-
return alloc_bootmem(sizeof(struct resource));
47+
return memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
4848
}
4949

5050
SYSCALL_DEFINE3(pciconfig_iobase, long, which, unsigned long, bus,

0 commit comments

Comments
 (0)