Skip to content

Commit 318222a

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc updates from Andrew Morton: - a few misc things and hotfixes - ocfs2 - almost all of MM * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (139 commits) kernel/memremap.c: remove the unused device_private_entry_fault() export mm: delete find_get_entries_tag mm/huge_memory.c: make __thp_get_unmapped_area static mm/mprotect.c: fix compilation warning because of unused 'mm' variable mm/page-writeback: introduce tracepoint for wait_on_page_writeback() mm/vmscan: simplify trace_reclaim_flags and trace_shrink_flags mm/Kconfig: update "Memory Model" help text mm/vmscan.c: don't disable irq again when count pgrefill for memcg mm: memblock: make keeping memblock memory opt-in rather than opt-out hugetlbfs: always use address space in inode for resv_map pointer mm/z3fold.c: support page migration mm/z3fold.c: add structure for buddy handles mm/z3fold.c: improve compression by extending search mm/z3fold.c: introduce helper functions mm/page_alloc.c: remove unnecessary parameter in rmqueue_pcplist mm/hmm: add ARCH_HAS_HMM_MIRROR ARCH_HAS_HMM_DEVICE Kconfig mm/vmscan.c: simplify shrink_inactive_list() fs/sync.c: sync_file_range(2) may use WB_SYNC_ALL writeback xen/privcmd-buf.c: convert to use vm_map_pages_zero() xen/gntdev.c: convert to use vm_map_pages() ...
2 parents 7e9890a + 640be2d commit 318222a

189 files changed

Lines changed: 3646 additions & 2332 deletions

File tree

Some content is hidden

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

‎Documentation/sysctl/vm.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Currently, these files are in /proc/sys/vm:
6161
- stat_refresh
6262
- numa_stat
6363
- swappiness
64+
- unprivileged_userfaultfd
6465
- user_reserve_kbytes
6566
- vfs_cache_pressure
6667
- watermark_boost_factor
@@ -818,6 +819,17 @@ The default value is 60.
818819

819820
==============================================================
820821

822+
unprivileged_userfaultfd
823+
824+
This flag controls whether unprivileged users can use the userfaultfd
825+
system calls. Set this to 1 to allow unprivileged users to use the
826+
userfaultfd system calls, or set this to 0 to restrict userfaultfd to only
827+
privileged users (with SYS_CAP_PTRACE capability).
828+
829+
The default value is 1.
830+
831+
==============================================================
832+
821833
- user_reserve_kbytes
822834

823835
When overcommit_memory is set to 2, "never overcommit" mode, reserve

‎Documentation/trace/postprocess/trace-vmscan-postprocess.pl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ sub sigint_handler {
113113
my $regex_kswapd_sleep_default = 'nid=([0-9]*)';
114114
my $regex_wakeup_kswapd_default = 'nid=([0-9]*) zid=([0-9]*) order=([0-9]*) gfp_flags=([A-Z_|]*)';
115115
my $regex_lru_isolate_default = 'isolate_mode=([0-9]*) classzone_idx=([0-9]*) order=([0-9]*) nr_requested=([0-9]*) nr_scanned=([0-9]*) nr_skipped=([0-9]*) nr_taken=([0-9]*) lru=([a-z_]*)';
116-
my $regex_lru_shrink_inactive_default = 'nid=([0-9]*) nr_scanned=([0-9]*) nr_reclaimed=([0-9]*) nr_dirty=([0-9]*) nr_writeback=([0-9]*) nr_congested=([0-9]*) nr_immediate=([0-9]*) nr_activate=([0-9]*) nr_ref_keep=([0-9]*) nr_unmap_fail=([0-9]*) priority=([0-9]*) flags=([A-Z_|]*)';
116+
my $regex_lru_shrink_inactive_default = 'nid=([0-9]*) nr_scanned=([0-9]*) nr_reclaimed=([0-9]*) nr_dirty=([0-9]*) nr_writeback=([0-9]*) nr_congested=([0-9]*) nr_immediate=([0-9]*) nr_activate_anon=([0-9]*) nr_activate_file=([0-9]*) nr_ref_keep=([0-9]*) nr_unmap_fail=([0-9]*) priority=([0-9]*) flags=([A-Z_|]*)';
117117
my $regex_lru_shrink_active_default = 'lru=([A-Z_]*) nr_scanned=([0-9]*) nr_rotated=([0-9]*) priority=([0-9]*)';
118118
my $regex_writepage_default = 'page=([0-9a-f]*) pfn=([0-9]*) flags=([A-Z_|]*)';
119119

@@ -212,7 +212,8 @@ sub generate_traceevent_regex {
212212
"vmscan/mm_vmscan_lru_shrink_inactive",
213213
$regex_lru_shrink_inactive_default,
214214
"nid", "nr_scanned", "nr_reclaimed", "nr_dirty", "nr_writeback",
215-
"nr_congested", "nr_immediate", "nr_activate", "nr_ref_keep",
215+
"nr_congested", "nr_immediate", "nr_activate_anon",
216+
"nr_activate_file", "nr_ref_keep",
216217
"nr_unmap_fail", "priority", "flags");
217218
$regex_lru_shrink_active = generate_traceevent_regex(
218219
"vmscan/mm_vmscan_lru_shrink_active",
@@ -407,7 +408,7 @@ sub process_events {
407408
}
408409

409410
my $nr_reclaimed = $3;
410-
my $flags = $12;
411+
my $flags = $13;
411412
my $file = 0;
412413
if ($flags =~ /RECLAIM_WB_FILE/) {
413414
$file = 1;

‎Documentation/vm/hmm.rst‎

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,10 @@ the driver callback returns.
189189
When the device driver wants to populate a range of virtual addresses, it can
190190
use either::
191191

192-
int hmm_vma_get_pfns(struct vm_area_struct *vma,
193-
struct hmm_range *range,
194-
unsigned long start,
195-
unsigned long end,
196-
hmm_pfn_t *pfns);
197-
int hmm_vma_fault(struct vm_area_struct *vma,
198-
struct hmm_range *range,
199-
unsigned long start,
200-
unsigned long end,
201-
hmm_pfn_t *pfns,
202-
bool write,
203-
bool block);
204-
205-
The first one (hmm_vma_get_pfns()) will only fetch present CPU page table
192+
long hmm_range_snapshot(struct hmm_range *range);
193+
long hmm_range_fault(struct hmm_range *range, bool block);
194+
195+
The first one (hmm_range_snapshot()) will only fetch present CPU page table
206196
entries and will not trigger a page fault on missing or non-present entries.
207197
The second one does trigger a page fault on missing or read-only entry if the
208198
write parameter is true. Page faults use the generic mm page fault code path
@@ -220,25 +210,56 @@ respect in order to keep things properly synchronized. The usage pattern is::
220210
{
221211
struct hmm_range range;
222212
...
213+
214+
range.start = ...;
215+
range.end = ...;
216+
range.pfns = ...;
217+
range.flags = ...;
218+
range.values = ...;
219+
range.pfn_shift = ...;
220+
hmm_range_register(&range);
221+
222+
/*
223+
* Just wait for range to be valid, safe to ignore return value as we
224+
* will use the return value of hmm_range_snapshot() below under the
225+
* mmap_sem to ascertain the validity of the range.
226+
*/
227+
hmm_range_wait_until_valid(&range, TIMEOUT_IN_MSEC);
228+
223229
again:
224-
ret = hmm_vma_get_pfns(vma, &range, start, end, pfns);
225-
if (ret)
230+
down_read(&mm->mmap_sem);
231+
ret = hmm_range_snapshot(&range);
232+
if (ret) {
233+
up_read(&mm->mmap_sem);
234+
if (ret == -EAGAIN) {
235+
/*
236+
* No need to check hmm_range_wait_until_valid() return value
237+
* on retry we will get proper error with hmm_range_snapshot()
238+
*/
239+
hmm_range_wait_until_valid(&range, TIMEOUT_IN_MSEC);
240+
goto again;
241+
}
242+
hmm_mirror_unregister(&range);
226243
return ret;
244+
}
227245
take_lock(driver->update);
228-
if (!hmm_vma_range_done(vma, &range)) {
246+
if (!range.valid) {
229247
release_lock(driver->update);
248+
up_read(&mm->mmap_sem);
230249
goto again;
231250
}
232251

233252
// Use pfns array content to update device page table
234253

254+
hmm_mirror_unregister(&range);
235255
release_lock(driver->update);
256+
up_read(&mm->mmap_sem);
236257
return 0;
237258
}
238259

239260
The driver->update lock is the same lock that the driver takes inside its
240-
update() callback. That lock must be held before hmm_vma_range_done() to avoid
241-
any race with a concurrent CPU page table update.
261+
update() callback. That lock must be held before checking the range.valid
262+
field to avoid any race with a concurrent CPU page table update.
242263

243264
HMM implements all this on top of the mmu_notifier API because we wanted a
244265
simpler API and also to be able to perform optimizations latter on like doing
@@ -255,6 +276,41 @@ report commands as executed is serialized (there is no point in doing this
255276
concurrently).
256277

257278

279+
Leverage default_flags and pfn_flags_mask
280+
=========================================
281+
282+
The hmm_range struct has 2 fields default_flags and pfn_flags_mask that allows
283+
to set fault or snapshot policy for a whole range instead of having to set them
284+
for each entries in the range.
285+
286+
For instance if the device flags for device entries are:
287+
VALID (1 << 63)
288+
WRITE (1 << 62)
289+
290+
Now let say that device driver wants to fault with at least read a range then
291+
it does set:
292+
range->default_flags = (1 << 63)
293+
range->pfn_flags_mask = 0;
294+
295+
and calls hmm_range_fault() as described above. This will fill fault all page
296+
in the range with at least read permission.
297+
298+
Now let say driver wants to do the same except for one page in the range for
299+
which its want to have write. Now driver set:
300+
range->default_flags = (1 << 63);
301+
range->pfn_flags_mask = (1 << 62);
302+
range->pfns[index_of_write] = (1 << 62);
303+
304+
With this HMM will fault in all page with at least read (ie valid) and for the
305+
address == range->start + (index_of_write << PAGE_SHIFT) it will fault with
306+
write permission ie if the CPU pte does not have write permission set then HMM
307+
will call handle_mm_fault().
308+
309+
Note that HMM will populate the pfns array with write permission for any entry
310+
that have write permission within the CPU pte no matter what are the values set
311+
in default_flags or pfn_flags_mask.
312+
313+
258314
Represent and manage device memory from core kernel point of view
259315
=================================================================
260316

‎MAINTAINERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11746,6 +11746,7 @@ F: include/linux/oprofile.h
1174611746
ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
1174711747
M: Mark Fasheh <mark@fasheh.com>
1174811748
M: Joel Becker <jlbec@evilplan.org>
11749+
M: Joseph Qi <joseph.qi@linux.alibaba.com>
1174911750
L: ocfs2-devel@oss.oracle.com (moderated for non-subscribers)
1175011751
W: http://ocfs2.wiki.kernel.org
1175111752
S: Supported

‎arch/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ config ARCH_HAS_FORTIFY_SOURCE
245245
An architecture should select this when it can successfully
246246
build and run with CONFIG_FORTIFY_SOURCE.
247247

248+
#
249+
# Select if the arch provides a historic keepinit alias for the retain_initrd
250+
# command line option
251+
#
252+
config ARCH_HAS_KEEPINITRD
253+
bool
254+
248255
# Select if arch has all set_memory_ro/rw/x/nx() functions in asm/cacheflush.h
249256
config ARCH_HAS_SET_MEMORY
250257
bool

‎arch/alpha/mm/init.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,3 @@ mem_init(void)
285285
memblock_free_all();
286286
mem_init_print_info(NULL);
287287
}
288-
289-
void
290-
free_initmem(void)
291-
{
292-
free_initmem_default(-1);
293-
}
294-
295-
#ifdef CONFIG_BLK_DEV_INITRD
296-
void
297-
free_initrd_mem(unsigned long start, unsigned long end)
298-
{
299-
free_reserved_area((void *)start, (void *)end, -1, "initrd");
300-
}
301-
#endif

‎arch/arc/mm/init.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,3 @@ void __init mem_init(void)
206206
memblock_free_all();
207207
mem_init_print_info(NULL);
208208
}
209-
210-
/*
211-
* free_initmem: Free all the __init memory.
212-
*/
213-
void __ref free_initmem(void)
214-
{
215-
free_initmem_default(-1);
216-
}
217-
218-
#ifdef CONFIG_BLK_DEV_INITRD
219-
void __init free_initrd_mem(unsigned long start, unsigned long end)
220-
{
221-
free_reserved_area((void *)start, (void *)end, -1, "initrd");
222-
}
223-
#endif

‎arch/arm/Kconfig‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ config ARM
44
default y
55
select ARCH_32BIT_OFF_T
66
select ARCH_CLOCKSOURCE_DATA
7-
select ARCH_DISCARD_MEMBLOCK if !HAVE_ARCH_PFN_VALID && !KEXEC
87
select ARCH_HAS_DEBUG_VIRTUAL if MMU
98
select ARCH_HAS_DEVMEM_IS_ALLOWED
109
select ARCH_HAS_ELF_RANDOMIZE
1110
select ARCH_HAS_FORTIFY_SOURCE
11+
select ARCH_HAS_KEEPINITRD
1212
select ARCH_HAS_KCOV
1313
select ARCH_HAS_MEMBARRIER_SYNC_CORE
1414
select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
@@ -21,6 +21,7 @@ config ARM
2121
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
2222
select ARCH_HAVE_CUSTOM_GPIO_H
2323
select ARCH_HAS_GCOV_PROFILE_ALL
24+
select ARCH_KEEP_MEMBLOCK if HAVE_ARCH_PFN_VALID || KEXEC
2425
select ARCH_MIGHT_HAVE_PC_PARPORT
2526
select ARCH_NO_SG_CHAIN if !ARM_HAS_SG_CHAIN
2627
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX

‎arch/arm/mm/dma-mapping.c‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,31 +1577,21 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma
15771577
void *cpu_addr, dma_addr_t dma_addr, size_t size,
15781578
unsigned long attrs)
15791579
{
1580-
unsigned long uaddr = vma->vm_start;
1581-
unsigned long usize = vma->vm_end - vma->vm_start;
15821580
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
15831581
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
1584-
unsigned long off = vma->vm_pgoff;
1582+
int err;
15851583

15861584
if (!pages)
15871585
return -ENXIO;
15881586

1589-
if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
1587+
if (vma->vm_pgoff >= nr_pages)
15901588
return -ENXIO;
15911589

1592-
pages += off;
1593-
1594-
do {
1595-
int ret = vm_insert_page(vma, uaddr, *pages++);
1596-
if (ret) {
1597-
pr_err("Remapping memory failed: %d\n", ret);
1598-
return ret;
1599-
}
1600-
uaddr += PAGE_SIZE;
1601-
usize -= PAGE_SIZE;
1602-
} while (usize > 0);
1590+
err = vm_map_pages(vma, pages, nr_pages);
1591+
if (err)
1592+
pr_err("Remapping memory failed: %d\n", err);
16031593

1604-
return 0;
1594+
return err;
16051595
}
16061596
static int arm_iommu_mmap_attrs(struct device *dev,
16071597
struct vm_area_struct *vma, void *cpu_addr,

‎arch/arm/mm/init.c‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -695,27 +695,14 @@ void free_initmem(void)
695695
}
696696

697697
#ifdef CONFIG_BLK_DEV_INITRD
698-
699-
static int keep_initrd;
700-
701698
void free_initrd_mem(unsigned long start, unsigned long end)
702699
{
703-
if (!keep_initrd) {
704-
if (start == initrd_start)
705-
start = round_down(start, PAGE_SIZE);
706-
if (end == initrd_end)
707-
end = round_up(end, PAGE_SIZE);
700+
if (start == initrd_start)
701+
start = round_down(start, PAGE_SIZE);
702+
if (end == initrd_end)
703+
end = round_up(end, PAGE_SIZE);
708704

709-
poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
710-
free_reserved_area((void *)start, (void *)end, -1, "initrd");
711-
}
705+
poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
706+
free_reserved_area((void *)start, (void *)end, -1, "initrd");
712707
}
713-
714-
static int __init keepinitrd_setup(char *__unused)
715-
{
716-
keep_initrd = 1;
717-
return 1;
718-
}
719-
720-
__setup("keepinitrd", keepinitrd_setup);
721708
#endif

0 commit comments

Comments
 (0)