incoming
Subsystems (10)
Andrew Morton
maintainer7 fixes, based on 9f65ed5fe41ce08ed1cb1f6a950f9ec694c142ad:
Mel Gorman <[email protected]>:
mm, numa: fix bad pmd by atomically check for pmd_trans_huge when marking page tables prot_numa
Huang Ying <[email protected]>:
mm: fix possible PMD dirty bit lost in set_pmd_migration_entry()
"Kirill A. Shutemov" <[email protected]>:
mm: avoid data corruption on CoW fault into PFN-mapped VMA
OGAWA Hirofumi <[email protected]>:
fat: fix uninit-memory access for partial initialized inode
Sebastian Andrzej Siewior <[email protected]>:
mm/z3fold.c: do not include rwlock.h directly
Vlastimil Babka <[email protected]>:
mm, hotplug: fix page online with DEBUG_PAGEALLOC compiled but not enabled
Miroslav Benes <[email protected]>:
arch/Kconfig: update HAVE_RELIABLE_STACKTRACE description
arch/Kconfig | 5 +++-- fs/fat/inode.c | 19 +++++++------------ include/linux/mm.h | 4 ++++ mm/huge_memory.c | 3 +-- mm/memory.c | 35 +++++++++++++++++++++++++++-------- mm/memory_hotplug.c | 8 +++++++- mm/mprotect.c | 38 ++++++++++++++++++++++++++++++++++++-- mm/z3fold.c | 1 - 8 files changed, 85 insertions(+), 28 deletions(-)
Andrew Morton
maintainerPATCH 1/7 mm, numa: fix bad pmd by atomically check for pmd_trans_huge when marking page tables prot_numa
From: Mel Gorman <[email protected]>
Subject: mm, numa: fix bad pmd by atomically check for pmd_trans_huge when marking page tables prot_numa
: A user reported a bug against a distribution kernel while running a : proprietary workload described as "memory intensive that is not swapping" : that is expected to apply to mainline kernels. The workload is : read/write/modifying ranges of memory and checking the contents. They : reported that within a few hours that a bad PMD would be reported followed : by a memory corruption where expected data was all zeros. A partial : report of the bad PMD looked like
:
: [ 5195.338482] ../mm/pgtable-generic.c:33: bad pmd ffff8888157ba008(000002e0396009e2) : [ 5195.341184] ------------[ cut here ]------------ : [ 5195.356880] kernel BUG at ../mm/pgtable-generic.c:35! : .... : [ 5195.410033] Call Trace: : [ 5195.410471] [<ffffffff811bc75d>] change_protection_range+0x7dd/0x930 : [ 5195.410716] [<ffffffff811d4be8>] change_prot_numa+0x18/0x30 : [ 5195.410918] [<ffffffff810adefe>] task_numa_work+0x1fe/0x310 : [ 5195.411200] [<ffffffff81098322>] task_work_run+0x72/0x90 : [ 5195.411246] [<ffffffff81077139>] exit_to_usermode_loop+0x91/0xc2 : [ 5195.411494] [<ffffffff81003a51>] prepare_exit_to_usermode+0x31/0x40 : [ 5195.411739] [<ffffffff815e56af>] retint_user+0x8/0x10
:
: Decoding revealed that the PMD was a valid prot_numa PMD and the bad PMD : was a false detection. The bug does not trigger if automatic NUMA : balancing or transparent huge pages is disabled.
:
: The bug is due a race in change_pmd_range between a pmd_trans_huge and : pmd_nond_or_clear_bad check without any locks held. During the : pmd_trans_huge check, a parallel protection update under lock can have : cleared the PMD and filled it with a prot_numa entry between the transhuge : check and the pmd_none_or_clear_bad check.
:
: While this could be fixed with heavy locking, it's only necessary to make : a copy of the PMD on the stack during change_pmd_range and avoid races. A : new helper is created for this as the check if quite subtle and the : existing similar helpful is not suitable. This passed 154 hours of : testing (usually triggers between 20 minutes and 24 hours) without : detecting bad PMDs or corruption. A basic test of an autonuma-intensive : workload showed no significant change in behaviour.
Although Mel withdrew the patch on the face of LKML comment
https://lkml.org/lkml/2017/4/10/922 the race window aforementioned is still open, and we have reports of Linpack test reporting bad residuals after the bad PMD warning is observed. In addition to that, bad rss-counter and non-zero pgtables assertions are triggered on mm teardown for the task hitting the bad PMD.
host kernel: mm/pgtable-generic.c:40: bad pmd 00000000b3152f68(8000000d2d2008e7)
....
host kernel: BUG: Bad rss-counter state mm:00000000b583043d idx:1 val:512 host kernel: BUG: non-zero pgtables_bytes on freeing mm: 4096
The issue is observed on a v4.18-based distribution kernel, but the race window is expected to be applicable to mainline kernels, as well.
---
mm/mprotect.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
mm/mprotect.c renamed from mm/mprotect.c~mm-numa-fix-bad-pmd-by-atomically-check-for-pmd_trans_huge-when-marking-page-tables-prot_numa +36 -2
@@ -161,6 +161,31 @@ static unsigned long change_pte_range(streturn pages; } +/* +* Used when setting automatic NUMA hinting protection where it is +* critical that a numa hinting PMD is not confused with a bad PMD. +*/ +static inline int pmd_none_or_clear_bad_unless_trans_huge (pmd_t *pmd) +{ +pmd_t pmdval =pmd_read_atomic (pmd); + +/* See pmd_none_or_trans_huge_or_clear_bad for info on barrier */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +barrier (); +#endif + +if (pmd_none (pmdval)) +return 1 ; +if (pmd_trans_huge (pmdval)) +return 0 ; +if (unlikely (pmd_bad (pmdval))) { +pmd_clear_bad (pmd); +return 1 ; + } + +return 0 ; +} +static inline unsigned long change_pmd_range (struct vm_area_struct *vma,pud_t *pud,unsigned long addr,unsigned long end,pgprot_t newprot,int dirty_accountable,int prot_numa)
@@ -178,8 +203,17 @@ static inline unsigned long change_pmd_runsigned long this_pages; next =pmd_addr_end (addr, end); -if (!is_swap_pmd (*pmd) && !pmd_trans_huge (*pmd) && !pmd_devmap (*pmd) - &&pmd_none_or_clear_bad (pmd)) + +/* +* Automatic NUMA balancing walks the tables with mmap_sem +* held for read. It's possible a parallel update to occur +* between pmd_trans_huge() and a pmd_none_or_clear_bad() +* check leading to a false positive and clearing. +* Hence, it's necessary to atomically read the PMD value +* for all the checks. +*/ +if (!is_swap_pmd (*pmd) && !pmd_devmap (*pmd) && +pmd_none_or_clear_bad_unless_trans_huge (pmd)) goto next;/* invoke the mmu notifier if the pmd is populated */
_
Andrew Morton
maintainerPATCH 2/7 mm: fix possible PMD dirty bit lost in set_pmd_migration_entry()
In reply to Andrew MortonFrom: Huang Ying <[email protected]>
Subject: mm: fix possible PMD dirty bit lost in set_pmd_migration_entry()
In set_pmd_migration_entry(), pmdp_invalidate() is used to change PMD atomically. But the PMD is read before that with an ordinary memory reading. If the THP (transparent huge page) is written between the PMD reading and pmdp_invalidate(), the PMD dirty bit may be lost, and cause data corruption. The race window is quite small, but still possible in theory, so need to be fixed.
The race is fixed via using the return value of pmdp_invalidate() to get the original content of PMD, which is a read/modify/write atomic operation. So no THP writing can occur in between.
The race has been introduced when the THP migration support is added in the commit 616b8371539a ("mm: thp: enable thp migration in generic path"). But this fix depends on the commit d52605d7cb30 ("mm: do not lose dirty and accessed bits in pmdp_invalidate()"). So it's easy to be backported after v4.16. But the race window is really small, so it may be fine not to backport the fix at all.
---
mm/huge_memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/huge_memory.c renamed from mm/huge_memory.c~mm-fix-possible-pmd-dirty-bit-lost-in-set_pmd_migration_entry +1 -2
@@ -3043,8 +3043,7 @@ void set_pmd_migration_entry(struct pagereturn ;flush_cache_range (vma, address, address +HPAGE_PMD_SIZE ); - pmdval = *pvmw->pmd; -pmdp_invalidate (vma, address, pvmw->pmd); + pmdval =pmdp_invalidate (vma, address, pvmw->pmd);if (pmd_dirty (pmdval))set_page_dirty (page); entry =make_migration_entry (page,pmd_write (pmdval));
_
Andrew Morton
maintainerPATCH 3/7 mm: avoid data corruption on CoW fault into PFN-mapped VMA
In reply to Andrew MortonFrom: "Kirill A. Shutemov" <[email protected]>
Subject: mm: avoid data corruption on CoW fault into PFN-mapped VMA
Jeff Moyer has reported that one of xfstests triggers a warning when run on DAX-enabled filesystem:
WARNING: CPU: 76 PID: 51024 at mm/memory.c:2317 wp_page_copy+0xc40/0xd50 ... wp_page_copy+0x98c/0xd50 (unreliable) do_wp_page+0xd8/0xad0 __handle_mm_fault+0x748/0x1b90 handle_mm_fault+0x120/0x1f0 __do_page_fault+0x240/0xd70 do_page_fault+0x38/0xd0 handle_page_fault+0x10/0x30
The warning happens on failed __copy_from_user_inatomic() which tries to copy data into a CoW page.
This happens because of race between MADV_DONTNEED and CoW page fault:
CPU0 CPU1
handle_mm_fault()
do_wp_page()
wp_page_copy()
do_wp_page()
madvise(MADV_DONTNEED)
zap_page_range()
zap_pte_range()
ptep_get_and_clear_full()
<TLB flush>
__copy_from_user_inatomic()
sees empty PTE and fails
WARN_ON_ONCE(1)
clear_page()The solution is to re-try __copy_from_user_inatomic() under PTL after checking that PTE is matches the orig_pte.
The second copy attempt can still fail, like due to non-readable PTE, but there's nothing reasonable we can do about, except clearing the CoW page.
---
mm/memory.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-avoid-data-corruption-on-cow-fault-into-pfn-mapped-vma +27 -8
@@ -2257,7 +2257,7 @@ static inline bool cow_user_page(structbool ret;void *kaddr;void __user *uaddr; -bool force_mkyoung; +bool locked = false;struct vm_area_struct *vma = vmf->vma;struct mm_struct *mm = vma->vm_mm;unsigned long addr = vmf->address;
@@ -2282,11 +2282,11 @@ static inline bool cow_user_page(struct* On architectures with software "accessed" bits, we would * take a double page fault, so mark it accessed here. */ - force_mkyoung =arch_faults_on_old_pte () && !pte_young (vmf->orig_pte); -if (force_mkyoung) { +if (arch_faults_on_old_pte () && !pte_young (vmf->orig_pte)) {pte_t entry; vmf->pte =pte_offset_map_lock (mm, vmf->pmd, addr, &vmf->ptl); + locked = true;if (!likely (pte_same (*vmf->pte, vmf->orig_pte))) {/* * Other thread has already handled the fault
@@ -2310,18 +2310,37 @@ static inline bool cow_user_page(struct* zeroes. */ if (__copy_from_user_inatomic (kaddr, uaddr,PAGE_SIZE )) { +if (locked) + goto warn; + +/* Re-validate under PTL if the page is still mapped */ + vmf->pte =pte_offset_map_lock (mm, vmf->pmd, addr, &vmf->ptl); + locked = true; +if (!likely (pte_same (*vmf->pte, vmf->orig_pte))) { +/* The PTE changed under us. Retry page fault. */ + ret = false; + goto pte_unlock; + } +/* -* Give a warn in case there can be some obscure -* use-case +* The same page can be mapped back since last copy attampt. +* Try to copy again under PTL. */ -WARN_ON_ONCE (1 ); -clear_page (kaddr); +if (__copy_from_user_inatomic (kaddr, uaddr,PAGE_SIZE )) { +/* +* Give a warn in case there can be some obscure +* use-case +*/ +warn: +WARN_ON_ONCE (1 ); +clear_page (kaddr); + } } ret = true; pte_unlock: -if (force_mkyoung) +if (locked)pte_unmap_unlock (vmf->pte, vmf->ptl);kunmap_atomic (kaddr);flush_dcache_page (dst);
_
Andrew Morton
maintainerPATCH 4/7 fat: fix uninit-memory access for partial initialized inode
In reply to Andrew MortonFrom: OGAWA Hirofumi <[email protected]>
Subject: fat: fix uninit-memory access for partial initialized inode
When get an error in the middle of reading an inode, some fields in the inode might be still not initialized. And then the evict_inode path may access those fields via iput().
To fix, this makes sure that inode fields are initialized.
---
fs/fat/inode.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
fs/fat/inode.c renamed from fs/fat/inode.c~fat-fix-uninit-memory-access-for-partial-initialized-inode +7 -9
@@ -750,6 +750,13 @@ static struct inode *fat_alloc_inode(strreturn NULL ;init_rwsem (&ei->truncate_lock); +/* Zeroing to allow iput() even if partial initialized inode. */ + ei->mmu_private =0 ; + ei->i_start =0 ; + ei->i_logstart =0 ; + ei->i_attrs =0 ; + ei->i_pos =0 ; +return &ei->vfs_inode; }
@@ -1374,16 +1381,6 @@ out:return 0 ; } -static void fat_dummy_inode_init (struct inode *inode) -{ -/* Initialize this dummy inode to work as no-op. */ -MSDOS_I (inode)->mmu_private =0 ; -MSDOS_I (inode)->i_start =0 ; -MSDOS_I (inode)->i_logstart =0 ; -MSDOS_I (inode)->i_attrs =0 ; -MSDOS_I (inode)->i_pos =0 ; -}
Andrew Morton
maintainerPATCH 5/7 mm/z3fold.c: do not include rwlock.h directly
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: mm/z3fold.c: do not include rwlock.h directly
rwlock.h should not be included directly. Instead linux/splinlock.h should be included. One thing it does is to break the RT build.
---
mm/z3fold.c | 1 - 1 file changed, 1 deletion(-)
mm/z3fold.c renamed from mm/z3fold.c~mm-z3fold-do-not-include-rwlockh-directly +0 -1
@@ -41,7 +41,6 @@#include <linux/workqueue.h> #include <linux/slab.h> #include <linux/spinlock.h> -#include <linux/rwlock.h> #include <linux/zpool.h> #include <linux/magic.h>
_
Andrew Morton
maintainerPATCH 6/7 mm, hotplug: fix page online with DEBUG_PAGEALLOC compiled but not enabled
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, hotplug: fix page online with DEBUG_PAGEALLOC compiled but not enabled
Commit cd02cf1aceea ("mm/hotplug: fix an imbalance with DEBUG_PAGEALLOC") fixed memory hotplug with debug_pagealloc enabled, where onlining a page goes through page freeing, which removes the direct mapping. Some arches don't like when the page is not mapped in the first place, so generic_online_page() maps it first. This is somewhat wasteful, but better than special casing page freeing fast paths.
The commit however missed that DEBUG_PAGEALLOC configured doesn't mean it's actually enabled. One has to test debug_pagealloc_enabled() since 031bc5743f15 ("mm/debug-pagealloc: make debug-pagealloc boottime configurable"), or alternatively debug_pagealloc_enabled_static() since 8e57f8acbbd1 ("mm, debug_pagealloc: don't rely on static keys too early"), but this is not done.
As a result, a s390 kernel with DEBUG_PAGEALLOC configured but not enabled will crash:
Unable to handle kernel pointer dereference in virtual kernel address space Failing address: 0000000000000000 TEID: 0000000000000483 Fault in home space mode while using kernel ASCE. AS:0000001ece13400b R2:000003fff7fd000b R3:000003fff7fcc007 S:000003fff7fd7000 P:000000000000013d Oops: 0004 ilc:2 [#1] SMP CPU: 1 PID: 26015 Comm: chmem Kdump: loaded Tainted: GX 5.3.18-5-default #1 SLE15-SP2 (unreleased) Krnl PSW : 0704e00180000000 0000001ecd281b9e (__kernel_map_pages+0x166/0x188)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
Krnl GPRS: 0000000000000000 0000000000000800 0000400b00000000 0000000000000100 0000000000000001 0000000000000000 0000000000000002 0000000000000100 0000001ece139230 0000001ecdd98d40 0000400b00000100 0000000000000000 000003ffa17e4000 001fffe0114f7d08 0000001ecd4d93ea 001fffe0114f7b20 Krnl Code: 0000001ecd281b8e: ec17ffff00d8 ahik %r1,%r7,-1 0000001ecd281b94: ec111dbc0355 risbg %r1,%r1,29,188,3
Quoted 1 line
0000001ecd281b9e:94fb5006ni 6(%r5),251
0000001ecd281ba2: 41505008 la %r5,8(%r5) 0000001ecd281ba6: ec51fffc6064 cgrj %r5,%r1,6,1ecd281b9e 0000001ecd281bac: 1a07 ar %r0,%r7 0000001ecd281bae: ec03ff584076 crj %r0,%r3,4,1ecd281a5e
Call Trace: [<0000001ecd281b9e>] __kernel_map_pages+0x166/0x188 [<0000001ecd4d9516>] online_pages_range+0xf6/0x128 [<0000001ecd2a8186>] walk_system_ram_range+0x7e/0xd8 [<0000001ecda28aae>] online_pages+0x2fe/0x3f0 [<0000001ecd7d02a6>] memory_subsys_online+0x8e/0xc0 [<0000001ecd7add42>] device_online+0x5a/0xc8 [<0000001ecd7d0430>] state_store+0x88/0x118 [<0000001ecd5b9f62>] kernfs_fop_write+0xc2/0x200 [<0000001ecd5064b6>] vfs_write+0x176/0x1e0 [<0000001ecd50676a>] ksys_write+0xa2/0x100 [<0000001ecda315d4>] system_call+0xd8/0x2c8
Fix this by checking debug_pagealloc_enabled_static() before calling kernel_map_pages(). Backports for kernel before 5.5 should use debug_pagealloc_enabled() instead. Also add comments.
---
include/linux/mm.h | 4 ++++ mm/memory_hotplug.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-hotplug-fix-page-online-with-debug_pagealloc-compiled-but-not-enabled +4 -0
@@ -2715,6 +2715,10 @@ static inline bool debug_pagealloc_enabl#if defined(CONFIG_DEBUG_PAGEALLOC ) || defined(CONFIG_ARCH_HAS_SET_DIRECT_MAP )extern void __kernel_map_pages (struct page *page,int numpages,int enable); +/* +* When called in DEBUG_PAGEALLOC context, the call should most likely be +* guarded by debug_pagealloc_enabled() or debug_pagealloc_enabled_static() +*/ static inline void kernel_map_pages (struct page *page,int numpages,int enable) {
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-hotplug-fix-page-online-with-debug_pagealloc-compiled-but-not-enabled +7 -1
@@ -574,7 +574,13 @@ EXPORT_SYMBOL_GPL(restore_online_page_cavoid generic_online_page (struct page *page,unsigned int order) { -kernel_map_pages (page,1 << order,1 ); +/* +* Freeing the page with debug_pagealloc enabled will try to unmap it, +* so we should map it first. This is better than introducing a special +* case in page freeing fast path. +*/ +if (debug_pagealloc_enabled_static ()) +kernel_map_pages (page,1 << order,1 );__free_pages_core (page, order);totalram_pages_add (1UL << order);#ifdef CONFIG_HIGHMEM
_
Andrew Morton
maintainerPATCH 7/7 arch/Kconfig: update HAVE_RELIABLE_STACKTRACE description
In reply to Andrew MortonFrom: Miroslav Benes <[email protected]>
Subject: arch/Kconfig: update HAVE_RELIABLE_STACKTRACE description
save_stack_trace_tsk_reliable() is not the only function providing the reliable stack traces anymore. Architecture might define ARCH_STACKWALK which provides a newer stack walking interface and has arch_stack_walk_reliable() function. Update the description accordingly.
---
arch/Kconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/Kconfig renamed from arch/Kconfig~arch-kconfig-update-have_reliable_stacktrace-description +3 -2
@@ -738,8 +738,9 @@ config HAVE_STACK_VALIDATION config HAVE_RELIABLE_STACKTRACE bool help - Architecture has a save_stack_trace_tsk_reliable() function which - only returns a stack trace if it can guarantee the trace is reliable. + Architecture has either save_stack_trace_tsk_reliable() or + arch_stack_walk_reliable() function which only returns a stack trace + if it can guarantee the trace is reliable. config HAVE_ARCH_HASH bool
_
+ proc-speed-up-proc-statm.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: proc: speed up /proc/*/statm has been added to the -mm tree. Its filename is proc-speed-up-proc-statm.patch
The patch titled
Subject: proc: speed up /proc/*/statm
has been added to the -mm tree. Its filename is
proc-speed-up-proc-statm.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/proc-speed-up-proc-statm.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/proc-speed-up-proc-statm.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Alexey Dobriyan <[email protected]>
Subject: proc: speed up /proc/*/statm
top(1) reads all /proc/*/statm files but kernel threads will always have zeros. Print those zeroes directly without going through seq_put_decimal_ull().
Speed up reading /proc/2/statm (which is kthreadd) is like 3%.
My system has more kernel threads than normal processes after booting KDE.
---
fs/proc/array.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-)
fs/proc/array.c renamed from fs/proc/array.c~proc-speed-up-proc-statm +23 -16
@@ -635,28 +635,35 @@ int proc_tgid_stat(struct seq_file *m, sint proc_pid_statm (struct seq_file *m,struct pid_namespace *ns,struct pid *pid,struct task_struct *task) { -unsigned long size =0 , resident =0 , shared =0 , text =0 , data =0 ;struct mm_struct *mm =get_task_mm (task);if (mm) { +unsigned long size; +unsigned long resident =0 ; +unsigned long shared =0 ; +unsigned long text =0 ; +unsigned long data =0 ; + size =task_statm (mm, &shared, &text, &data, &resident);mmput (mm); - } -/* -* For quick read, open code by putting numbers directly -* expected format is -* seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n", -* size, resident, shared, text, data); -*/ -seq_put_decimal_ull (m,"" , size); -seq_put_decimal_ull (m," " , resident); -seq_put_decimal_ull (m," " , shared); -seq_put_decimal_ull (m," " , text); -seq_put_decimal_ull (m," " ,0 ); -seq_put_decimal_ull (m," " , data); -seq_put_decimal_ull (m," " ,0 ); -seq_putc (m,'\n' ); +/* +* For quick read, open code by putting numbers directly +* expected format is +* seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n", +* size, resident, shared, text, data); +*/ +seq_put_decimal_ull (m,"" , size); +seq_put_decimal_ull (m," " , resident); +seq_put_decimal_ull (m," " , shared); +seq_put_decimal_ull (m," " , text); +seq_put_decimal_ull (m," " ,0 ); +seq_put_decimal_ull (m," " , data); +seq_put_decimal_ull (m," " ,0 ); +seq_putc (m,'\n' ); + }else { +seq_write (m,"0 0 0 0 0 0 0\n" ,14 ); + }return 0 ; }
_
Patches currently in -mm which might be from [email protected] are
ramfs-support-o_tmpfile.patch proc-faster-open-read-close-with-permanent-files.patch proc-speed-up-proc-statm.patch elf-delete-loc-variable.patch elf-allocate-less-for-static-executable.patch elf-dont-free-interpreters-elf-pheaders-on-common-path.patch
+ mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/hotplug: fix hot remove failure in SPARSEMEM|!VMEMMAP case has been added to the -mm tree. Its filename is mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch
The patch titled
Subject: mm/hotplug: fix hot remove failure in SPARSEMEM|!VMEMMAP case
has been added to the -mm tree. Its filename is
mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Baoquan He <[email protected]>
Subject: mm/hotplug: fix hot remove failure in SPARSEMEM|!VMEMMAP case
In section_deactivate(), pfn_to_page() doesn't work any more after ms->section_mem_map is resetting to NULL in SPARSEMEM|!VMEMMAP case. It caused hot remove failure:
kernel BUG at mm/page_alloc.c:4806!
invalid opcode: 0000 [#1] SMP PTI
CPU: 3 PID: 8 Comm: kworker/u16:0 Tainted: G W 5.5.0-next-20200205+ #340 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 Workqueue: kacpi_hotplug acpi_hotplug_work_fn RIP: 0010:free_pages+0x85/0xa0 Call Trace: __remove_pages+0x99/0xc0 arch_remove_memory+0x23/0x4d try_remove_memory+0xc8/0x130 ? walk_memory_blocks+0x72/0xa0 __remove_memory+0xa/0x11 acpi_memory_device_remove+0x72/0x100 acpi_bus_trim+0x55/0x90 acpi_device_hotplug+0x2eb/0x3d0 acpi_hotplug_work_fn+0x1a/0x30 process_one_work+0x1a7/0x370 worker_thread+0x30/0x380 ? flush_rcu_work+0x30/0x30 kthread+0x112/0x130 ? kthread_create_on_node+0x60/0x60 ret_from_fork+0x35/0x40
Let's move the ->section_mem_map resetting afterdepopulate_section_memmap() to fix it.
---
mm/sparse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/sparse.c renamed from mm/sparse.c~mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case +6 -2
@@ -734,6 +734,7 @@ static void section_deactivate(unsignedstruct mem_section *ms =__pfn_to_section (pfn);bool section_is_early =early_section (ms);struct page *memmap =NULL ; +bool empty = false;unsigned long *subsection_map = ms->usage ? &ms->usage->subsection_map[0 ] :NULL ;
@@ -764,7 +765,8 @@ static void section_deactivate(unsigned* For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified */ bitmap_xor (subsection_map, map, subsection_map,SUBSECTIONS_PER_SECTION ); -if (bitmap_empty (subsection_map,SUBSECTIONS_PER_SECTION )) { + empty =bitmap_empty (subsection_map,SUBSECTIONS_PER_SECTION ); +if (empty) {unsigned long section_nr =pfn_to_section_nr (pfn);/*
@@ -779,13 +781,15 @@ static void section_deactivate(unsigned ms->usage =NULL ; } memmap =sparse_decode_mem_map (ms->section_mem_map, section_nr); - ms->section_mem_map = (unsigned long )NULL ; }if (section_is_early && memmap)free_map_bootmem (memmap);else depopulate_section_memmap (pfn, nr_pages, altmap); + +if (empty) + ms->section_mem_map = (unsigned long )NULL ; } static struct page * __meminit section_activate(int nid, unsigned long pfn,
_
Patches currently in -mm which might be from [email protected] are
mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case.patch mm-hotplug-only-respect-mem=-parameter-during-boot-stage.patch
+ mm-use-fallthrough.patch added to -mm tree
In reply to Andrew MortonThe patch titled
The patch titled
Subject: mm: use fallthrough;
has been added to the -mm tree. Its filename is
mm-use-fallthrough.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-use-fallthrough.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-use-fallthrough.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Joe Perches <[email protected]>
Subject: mm: use fallthrough;
Convert the various /* fallthrough */ comments to the pseudo-keyword fallthrough;
Done via script:
https://lore.kernel.org/lkml/b56602fcf79f849e733e7b521bb0e17895d390fa.1582230379.git.joe@perches.com/
---
mm/gup.c | 2 +- mm/hugetlb_cgroup.c | 6 +++--- mm/ksm.c | 3 +-- mm/list_lru.c | 2 +- mm/memcontrol.c | 2 +- mm/mempolicy.c | 3 --- mm/mmap.c | 5 ++--- mm/shmem.c | 2 +- mm/zsmalloc.c | 2 +- 9 files changed, 11 insertions(+), 16 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-use-fallthrough +1 -1
@@ -1072,7 +1072,7 @@ retry: goto retry;case -EBUSY : ret =0 ; -/* FALLTHRU */ + fallthrough;case -EFAULT :case -ENOMEM :case -EHWPOISON :
mm/hugetlb_cgroup.c renamed from mm/hugetlb_cgroup.c~mm-use-fallthrough +3 -3
@@ -468,14 +468,14 @@ static int hugetlb_cgroup_read_u64_max(sswitch (MEMFILE_ATTR (cft->private)) {case RES_RSVD_USAGE : counter = &h_cg->rsvd_hugepage[idx]; -/* Fall through. */ + fallthrough;case RES_USAGE : val = (u64 )page_counter_read (counter);seq_printf (seq,"%llu\n" , val *PAGE_SIZE );break ;case RES_RSVD_LIMIT : counter = &h_cg->rsvd_hugepage[idx]; -/* Fall through. */ + fallthrough;case RES_LIMIT : val = (u64 )counter->max;if (val == limit)
@@ -515,7 +515,7 @@ static ssize_t hugetlb_cgroup_write(struswitch (MEMFILE_ATTR (of_cft (of)->private)) {case RES_RSVD_LIMIT : rsvd = true; -/* Fall through. */ + fallthrough;case RES_LIMIT :mutex_lock (&hugetlb_limit_mutex); ret = page_counter_set_max(
mm/ksm.c renamed from mm/ksm.c~mm-use-fallthrough +1 -2
@@ -2813,8 +2813,7 @@ static int ksm_memory_callback(struct no*/ ksm_check_stable_tree (mn->start_pfn, mn->start_pfn + mn->nr_pages); -/* fallthrough */ - + fallthrough;case MEM_CANCEL_OFFLINE :mutex_lock (&ksm_thread_mutex); ksm_run &= ~KSM_RUN_OFFLINE ;
mm/list_lru.c renamed from mm/list_lru.c~mm-use-fallthrough +1 -1
@@ -223,7 +223,7 @@ restart:switch (ret) {case LRU_REMOVED_RETRY :assert_spin_locked (&nlru->lock); -/* fall through */ + fallthrough;case LRU_REMOVED : isolated++; nlru->nr_items--;
mm/memcontrol.c renamed from mm/memcontrol.c~mm-use-fallthrough +1 -1
@@ -5781,7 +5781,7 @@ retry:switch (get_mctgt_type (vma, addr, ptent, &target)) {case MC_TARGET_DEVICE : device = true; -/* fall through */ + fallthrough;case MC_TARGET_PAGE : page = target.page;/*
mm/mempolicy.c renamed from mm/mempolicy.c~mm-use-fallthrough +0 -3
@@ -881,7 +881,6 @@ static void get_policy_nodemask(struct mswitch (p->mode) {case MPOL_BIND : -/* Fall through */ case MPOL_INTERLEAVE : *nodes = p->v.nodes;break ;
@@ -2066,7 +2065,6 @@ bool init_nodemask_of_mempolicy(nodemaskbreak ;case MPOL_BIND : -/* Fall through */ case MPOL_INTERLEAVE : *mask = mempolicy->v.nodes;break ;
@@ -2333,7 +2331,6 @@ bool __mpol_equal(struct mempolicy *a, sswitch (a->mode) {case MPOL_BIND : -/* Fall through */ case MPOL_INTERLEAVE :return !!nodes_equal (a->v.nodes, b->v.nodes);case MPOL_PREFERRED :
mm/mmap.c renamed from mm/mmap.c~mm-use-fallthrough +2 -3
@@ -1457,7 +1457,7 @@ unsigned long do_mmap(struct file *file,* with MAP_SHARED to preserve backward compatibility. */ flags &=LEGACY_MAP_MASK ; -/* fall through */ + fallthrough;case MAP_SHARED_VALIDATE :if (flags & ~flags_mask)return -EOPNOTSUPP ;
@@ -1484,8 +1484,7 @@ unsigned long do_mmap(struct file *file, vm_flags |=VM_SHARED |VM_MAYSHARE ;if (!(file->f_mode &FMODE_WRITE )) vm_flags &= ~(VM_MAYWRITE |VM_SHARED ); - -/* fall through */ + fallthrough;case MAP_PRIVATE :if (!(file->f_mode &FMODE_READ ))return -EACCES ;
mm/shmem.c renamed from mm/shmem.c~mm-use-fallthrough +1 -1
@@ -3992,7 +3992,7 @@ bool shmem_huge_enabled(struct vm_area_sif (i_size >=HPAGE_PMD_SIZE && i_size >>PAGE_SHIFT >= off)return true; -/* fall through */ + fallthrough;case SHMEM_HUGE_ADVISE :/* TODO: implement fadvise() hints */ return (vma->vm_flags &VM_HUGEPAGE );
mm/zsmalloc.c renamed from mm/zsmalloc.c~mm-use-fallthrough +1 -1
@@ -424,7 +424,7 @@ static void *zs_zpool_map(void *pool, uncase ZPOOL_MM_WO : zs_mm =ZS_MM_WO ;break ; -case ZPOOL_MM_RW :/* fall through */ +case ZPOOL_MM_RW :default : zs_mm =ZS_MM_RW ;break ;
_
Patches currently in -mm which might be from [email protected] are
mm-use-fallthrough.patch string-add-stracpy-and-stracpy_pad-mechanisms.patch checkpatch-remove-email-address-comment-from-email-address-comparisons.patch checkpatch-prefer-fallthrough-over-fallthrough-comments.patch checkpatch-improve-gerrit-change-id-test.patch
+ mm-gup-track-foll_pin-pages-fix.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup: fixup for ce35133be382 mm/gup: track FOLL_PIN pages has been added to the -mm tree. Its filename is mm-gup-track-foll_pin-pages-fix.patch
The patch titled
Subject: mm/gup: fixup for ce35133be382 mm/gup: track FOLL_PIN pages
has been added to the -mm tree. Its filename is
mm-gup-track-foll_pin-pages-fix.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-track-foll_pin-pages-fix.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-track-foll_pin-pages-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: John Hubbard <[email protected]>
Subject: mm/gup: fixup for ce35133be382 mm/gup: track FOLL_PIN pages
This is a fixup for the mmotm commit ce35133be382
("mm/gup: track FOLL_PIN pages").
Add kerneldoc comments for pin_user_pages*() routines, in order to get rid of "make -W1" warnings when building mm/gup.o.
This just adds @param documentation of:
pin_user_pages()
pin_user_pages_fast()
pin_user_pages_remote()
The param documentation was stolen from other gup.c functions, because it looks reasonable enough.
---
mm/gup.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
mm/gup.c renamed from mm/gup.c~mm-gup-track-foll_pin-pages-fix +30 -0
@@ -2690,6 +2690,12 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);/** * pin_user_pages_fast() - pin user pages in memory without taking locks * +* @start: starting user address +* @nr_pages: number of pages from start to pin +* @gup_flags: flags modifying pin behaviour +* @pages: array that receives pointers to the pages pinned. +* Should be at least nr_pages long. +* * Nearly the same as get_user_pages_fast(), except that FOLL_PIN is set. See * get_user_pages_fast() for documentation on the function arguments, because * the arguments here are identical.
@@ -2715,6 +2721,21 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast);/** * pin_user_pages_remote() - pin pages of a remote process (task != current) * +* @tsk: the task_struct to use for page fault accounting, or +* NULL if faults are not to be recorded. +* @mm: mm_struct of target mm +* @start: starting user address +* @nr_pages: number of pages from start to pin +* @gup_flags: flags modifying lookup behaviour +* @pages: array that receives pointers to the pages pinned. +* Should be at least nr_pages long. Or NULL, if caller +* only intends to ensure the pages are faulted in. +* @vmas: array of pointers to vmas corresponding to each page. +* Or NULL if the caller does not require them. +* @locked: pointer to lock flag indicating whether lock is held and +* subsequently whether VM_FAULT_RETRY functionality can be +* utilised. Lock must initially be held. +* * Nearly the same as get_user_pages_remote(), except that FOLL_PIN is set. See * get_user_pages_remote() for documentation on the function arguments, because * the arguments here are identical.
@@ -2743,6 +2764,15 @@ EXPORT_SYMBOL(pin_user_pages_remote);/** * pin_user_pages() - pin user pages in memory for use by other devices * +* @start: starting user address +* @nr_pages: number of pages from start to pin +* @gup_flags: flags modifying lookup behaviour +* @pages: array that receives pointers to the pages pinned. +* Should be at least nr_pages long. Or NULL, if caller +* only intends to ensure the pages are faulted in. +* @vmas: array of pointers to vmas corresponding to each page. +* Or NULL if the caller does not require them. +* * Nearly the same as get_user_pages(), except that FOLL_TOUCH is not set, and * FOLL_PIN is set. *
_
Patches currently in -mm which might be from [email protected] are
mm-gup-split-get_user_pages_remote-into-two-routines.patch mm-gup-pass-a-flags-arg-to-__gup_device_-functions.patch mm-introduce-page_ref_sub_return.patch mm-gup-pass-gup-flags-to-two-more-routines.patch mm-gup-require-foll_get-for-get_user_pages_fast.patch mm-gup-track-foll_pin-pages.patch mm-gup-track-foll_pin-pages-fix.patch mm-gup-page-hpage_pinned_refcount-exact-pin-counts-for-huge-pages.patch mm-gup-proc-vmstat-pin_user_pages-foll_pin-reporting.patch mm-gup_benchmark-support-pin_user_pages-and-related-calls.patch selftests-vm-run_vmtests-invoke-gup_benchmark-with-basic-foll_pin-coverage.patch mm-dump_page-additional-diagnostics-for-huge-pinned-pages.patch checkpatch-support-base-commit-format.patch
+ mm-shmem-add-vmstat-for-hugepage-fallback.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm, shmem: add vmstat for hugepage fallback has been added to the -mm tree. Its filename is mm-shmem-add-vmstat-for-hugepage-fallback.patch
The patch titled
Subject: mm, shmem: add vmstat for hugepage fallback
has been added to the -mm tree. Its filename is
mm-shmem-add-vmstat-for-hugepage-fallback.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-shmem-add-vmstat-for-hugepage-fallback.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-shmem-add-vmstat-for-hugepage-fallback.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: David Rientjes <[email protected]>
Subject: mm, shmem: add vmstat for hugepage fallback
The existing thp_fault_fallback indicates when thp attempts to allocate a hugepage but fails, or if the hugepage cannot be charged to the mem cgroup hierarchy.
Extend this to shmem as well. Adds a new thp_file_fallback to complement thp_file_alloc that gets incremented when a hugepage is attempted to be allocated but fails, or if it cannot be charged to the mem cgroup hierarchy.
Additionally, remove the check for CONFIG_TRANSPARENT_HUGE_PAGECACHE from shmem_alloc_hugepage() since it is only called with this configuration option.
---
Documentation/admin-guide/mm/transhuge.rst | 4 ++++ include/linux/vm_event_item.h | 2 ++ mm/shmem.c | 10 ++++++---- mm/vmstat.c | 1 + 4 files changed, 13 insertions(+), 4 deletions(-)
Documentation/admin-guide/mm/transhuge.rst renamed from Documentation/admin-guide/mm/transhuge.rst~mm-shmem-add-vmstat-for-hugepage-fallback +4 -0
@@ -319,6 +319,10 @@ thp_file_alloc is incremented every time a file huge page is successfully allocated. +thp_file_fallback + is incremented if a file huge page is attempted to be allocated + but fails and instead falls back to using small pages. + thp_file_mapped is incremented every time a file huge page is mapped into user address space.
include/linux/vm_event_item.h renamed from include/linux/vm_event_item.h~mm-shmem-add-vmstat-for-hugepage-fallback +2 -0
@@ -76,6 +76,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSTHP_COLLAPSE_ALLOC ,THP_COLLAPSE_ALLOC_FAILED ,THP_FILE_ALLOC , +THP_FILE_FALLBACK ,THP_FILE_MAPPED ,THP_SPLIT_PAGE , THP_SPLIT_PAGE_FAILED,
@@ -115,6 +116,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PS#ifndef CONFIG_TRANSPARENT_HUGEPAGE #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; }) +#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })#define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })#endif
mm/shmem.c renamed from mm/shmem.c~mm-shmem-add-vmstat-for-hugepage-fallback +6 -4
@@ -1472,9 +1472,6 @@ static struct page *shmem_alloc_hugepagepgoff_t hindex;struct page *page; -if (!IS_ENABLED (CONFIG_TRANSPARENT_HUGE_PAGECACHE )) -return NULL ; - hindex =round_down (index,HPAGE_PMD_NR );if (xa_find (&mapping->i_pages, &hindex, hindex +HPAGE_PMD_NR -1 ,XA_PRESENT ))
@@ -1486,6 +1483,8 @@ static struct page *shmem_alloc_hugepageshmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page); +else +count_vm_event (THP_FILE_FALLBACK );return page; }
@@ -1871,8 +1870,11 @@ alloc_nohuge: error =mem_cgroup_try_charge_delay (page, charge_mm, gfp, &memcg,PageTransHuge (page)); -if (error) +if (error) { +if (PageTransHuge (page)) +count_vm_event (THP_FILE_FALLBACK ); goto unacct; + } error =shmem_add_to_page_cache (page, mapping, hindex,NULL , gfp &GFP_RECLAIM_MASK );if (error) {
mm/vmstat.c renamed from mm/vmstat.c~mm-shmem-add-vmstat-for-hugepage-fallback +1 -0
@@ -1259,6 +1259,7 @@ const char * const vmstat_text[] = {"thp_collapse_alloc" ,"thp_collapse_alloc_failed" ,"thp_file_alloc" , +"thp_file_fallback" ,"thp_file_mapped" ,"thp_split_page" , "thp_split_page_failed",
_
Patches currently in -mm which might be from [email protected] are
mm-shmem-add-vmstat-for-hugepage-fallback.patch mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch
+ mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm, thp: track fallbacks due to failed memcg charges separately has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm, thp: track fallbacks due to failed memcg charges separately
has been added to the -mm tree. Its filename is
mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: David Rientjes <[email protected]>
Subject: mm, thp: track fallbacks due to failed memcg charges separately
The thp_fault_fallback and thp_file_fallback vmstats are incremented if either the hugepage allocation fails through the page allocator or the hugepage charge fails through mem cgroup.
This patch leaves this field untouched but adds two new fields, thp_{fault,file}_fallback_charge, which is incremented only when the mem cgroup charge fails.
This distinguishes between attempted hugepage allocations that fail due to fragmentation (or low memory conditions) and those that fail due to mem cgroup limits. That can be used to determine the impact of fragmentation on the system by excluding faults that failed due to memcg usage.
---
Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ include/linux/vm_event_item.h | 3 +++ mm/huge_memory.c | 2 ++ mm/shmem.c | 4 +++- mm/vmstat.c | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-)
Documentation/admin-guide/mm/transhuge.rst renamed from Documentation/admin-guide/mm/transhuge.rst~mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately +10 -0
@@ -310,6 +310,11 @@ thp_fault_fallback is incremented if a page fault fails to allocate a huge page and instead falls back to using small pages. +thp_fault_fallback_charge + is incremented if a page fault fails to charge a huge page and + instead falls back to using small pages even though the + allocation was successful. + thp_collapse_alloc_failed is incremented if khugepaged found a range of pages that should be collapsed into one huge page but failed
@@ -323,6 +328,11 @@ thp_file_fallback is incremented if a file huge page is attempted to be allocated but fails and instead falls back to using small pages. +thp_file_fallback_charge + is incremented if a file huge page cannot be charged and instead + falls back to using small pages even though the allocation was + successful. + thp_file_mapped is incremented every time a file huge page is mapped into user address space.
include/linux/vm_event_item.h renamed from include/linux/vm_event_item.h~mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately +3 -0
@@ -73,10 +73,12 @@ enum vm_event_item { PGPGIN, PGPGOUT, PS#ifdef CONFIG_TRANSPARENT_HUGEPAGE THP_FAULT_ALLOC ,THP_FAULT_FALLBACK , +THP_FAULT_FALLBACK_CHARGE ,THP_COLLAPSE_ALLOC ,THP_COLLAPSE_ALLOC_FAILED ,THP_FILE_ALLOC ,THP_FILE_FALLBACK , +THP_FILE_FALLBACK_CHARGE ,THP_FILE_MAPPED ,THP_SPLIT_PAGE , THP_SPLIT_PAGE_FAILED,
@@ -117,6 +119,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PS#ifndef CONFIG_TRANSPARENT_HUGEPAGE #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; }) +#define THP_FILE_FALLBACK_CHARGE ({ BUILD_BUG(); 0; })#define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })#endif
mm/huge_memory.c renamed from mm/huge_memory.c~mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately +2 -0
@@ -597,6 +597,7 @@ static vm_fault_t __do_huge_pmd_anonymouif (mem_cgroup_try_charge_delay (page, vma->vm_mm, gfp, &memcg, true)) {put_page (page);count_vm_event (THP_FAULT_FALLBACK ); +count_vm_event (THP_FAULT_FALLBACK_CHARGE );return VM_FAULT_FALLBACK ; }
@@ -1420,6 +1421,7 @@ alloc:put_page (page); ret |=VM_FAULT_FALLBACK ;count_vm_event (THP_FAULT_FALLBACK ); +count_vm_event (THP_FAULT_FALLBACK_CHARGE ); goto out; }
mm/shmem.c renamed from mm/shmem.c~mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately +3 -1
@@ -1871,8 +1871,10 @@ alloc_nohuge: error =mem_cgroup_try_charge_delay (page, charge_mm, gfp, &memcg,PageTransHuge (page));if (error) { -if (PageTransHuge (page)) +if (PageTransHuge (page)) {count_vm_event (THP_FILE_FALLBACK ); +count_vm_event (THP_FILE_FALLBACK_CHARGE ); + } goto unacct; } error = shmem_add_to_page_cache(page, mapping, hindex,
mm/vmstat.c renamed from mm/vmstat.c~mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately +2 -0
@@ -1256,10 +1256,12 @@ const char * const vmstat_text[] = {#ifdef CONFIG_TRANSPARENT_HUGEPAGE "thp_fault_alloc" ,"thp_fault_fallback" , +"thp_fault_fallback_charge" ,"thp_collapse_alloc" ,"thp_collapse_alloc_failed" ,"thp_file_alloc" ,"thp_file_fallback" , +"thp_file_fallback_charge" ,"thp_file_mapped" ,"thp_split_page" , "thp_split_page_failed",
_
Patches currently in -mm which might be from [email protected] are
mm-shmem-add-vmstat-for-hugepage-fallback.patch mm-thp-track-fallbacks-due-to-failed-memcg-charges-separately.patch
+ mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm,page_alloc,cma: conditionally prefer cma pageblocks for movable allocations has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm,page_alloc,cma: conditionally prefer cma pageblocks for movable allocations
has been added to the -mm tree. Its filename is
mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Roman Gushchin <[email protected]>
Subject: mm,page_alloc,cma: conditionally prefer cma pageblocks for movable allocations
Currently a cma area is barely used by the page allocator because it's used only as a fallback from movable, however kswapd tries hard to make sure that the fallback path isn't used.
This results in a system evicting memory and pushing data into swap, while lots of CMA memory is still available. This happens despite the fact that alloc_contig_range is perfectly capable of moving any movable allocations out of the way of an allocation.
To effectively use the cma area let's alter the rules: if the zone has more free cma pages than the half of total free pages in the zone, use cma pageblocks first and fallback to movable blocks in the case of failure.
---
mm/page_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
mm/page_alloc.c renamed from mm/page_alloc.c~mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations +12 -0
@@ -2713,6 +2713,18 @@ __rmqueue(struct zone *zone, unsigned in {struct page *page; +/* +* Balance movable allocations between regular and CMA areas by +* allocating from CMA when over half of the zone's free memory +* is in the CMA area. +*/ +if (migratetype ==MIGRATE_MOVABLE && +zone_page_state (zone,NR_FREE_CMA_PAGES ) > +zone_page_state (zone,NR_FREE_PAGES ) /2 ) { + page =__rmqueue_cma_fallback (zone, order); +if (page) +return page; + } retry: page =__rmqueue_smallest (zone, order, migratetype);if (unlikely (!page)) {
_
Patches currently in -mm which might be from [email protected] are
mm-fork-fix-kernel_stack-memcg-stats-for-various-stack-implementations.patch mm-memcg-slab-introduce-mem_cgroup_from_obj.patch mm-memcg-slab-introduce-mem_cgroup_from_obj-v2.patch mm-kmem-cleanup-__memcg_kmem_charge_memcg-arguments.patch mm-kmem-cleanup-memcg_kmem_uncharge_memcg-arguments.patch mm-kmem-rename-memcg_kmem_uncharge-into-memcg_kmem_uncharge_page.patch mm-kmem-switch-to-nr_pages-in-__memcg_kmem_charge_memcg.patch mm-memcg-slab-cache-page-number-in-memcg_uncharge_slab.patch mm-kmem-rename-__memcg_kmem_uncharge_memcg-to-__memcg_kmem_uncharge.patch mmpage_alloccma-conditionally-prefer-cma-pageblocks-for-movable-allocations.patch
+ mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/memory_hotplug: drop the flags field from struct mhp_restrictions has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm/memory_hotplug: drop the flags field from struct mhp_restrictions
has been added to the -mm tree. Its filename is
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: mm/memory_hotplug: drop the flags field from struct mhp_restrictions
Patch series "Allow setting caching mode in arch_add_memory() for P2PDMA", v4.
Currently, the page tables created using memremap_pages() are always created with the PAGE_KERNEL cacheing mode. However, the P2PDMA code is creating pages for PCI BAR memory which should never be accessed through the cache and instead use either WC or UC. This still works in most cases, on x86, because the MTRR registers typically override the caching settings in the page tables for all of the IO memory to be UC-. However, this tends not to work so well on other arches or some rare x86 machines that have firmware which does not setup the MTRR registers in this way.
Instead of this, this series proposes a change to arch_add_memory() to take the pgprot required by the mapping which allows us to explicitly set pagetable entries for P2PDMA memory to UC.
This changes is pretty routine for most of the arches: x86_64, arm64 and powerpc simply need to thread the pgprot through to where the page tables are setup. x86_32 unfortunately sets up the page tables at boot so must use _set_memory_prot() to change their caching mode. ia64, s390 and sh don't appear to have an easy way to change the page tables so, for now at least, we just return -EINVAL on such mappings and thus they will not support P2PDMA memory until the work for this is done. This should be fine as they don't yet support ZONE_DEVICE.
This patch (of 7):
This variable is not used anywhere and should therefore be removed from the structure.
---
include/linux/memory_hotplug.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/memory_hotplug.h renamed from include/linux/memory_hotplug.h~mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions +0 -2
@@ -55,11 +55,9 @@ enum {/* * Restrictions for the memory hotplug: -* flags: MHP_ flags * altmap: alternative allocator for memmap array */ struct mhp_restrictions { -unsigned long flags;struct vmem_altmap *altmap; };
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/memory_hotplug: rename mhp_restrictions to mhp_params has been added to the -mm tree. Its filename is mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch
The patch titled
Subject: mm/memory_hotplug: rename mhp_restrictions to mhp_params
has been added to the -mm tree. Its filename is
mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: mm/memory_hotplug: rename mhp_restrictions to mhp_params
The mhp_restrictions struct really doesn't specify anything resembling a restriction anymore so rename it to be mhp_params as it is a list of extended parameters.
---
arch/arm64/mm/mmu.c | 4 ++-- arch/ia64/mm/init.c | 4 ++-- arch/powerpc/mm/mem.c | 4 ++-- arch/s390/mm/init.c | 6 +++--- arch/sh/mm/init.c | 4 ++-- arch/x86/mm/init_32.c | 4 ++-- arch/x86/mm/init_64.c | 8 ++++---- include/linux/memory_hotplug.h | 16 ++++++++-------- mm/memory_hotplug.c | 8 ++++---- mm/memremap.c | 8 ++++---- 10 files changed, 33 insertions(+), 33 deletions(-)
arch/arm64/mm/mmu.c renamed from arch/arm64/mm/mmu.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +2 -2
@@ -1374,7 +1374,7 @@ static void __remove_pgd_mapping(pgd_t * }int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {int ret, flags =0 ;
@@ -1387,7 +1387,7 @@ int arch_add_memory(int nid, u64 start,memblock_clear_nomap (start, size); ret =__add_pages (nid, start >>PAGE_SHIFT , size >>PAGE_SHIFT , - restrictions); + params);if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size);
arch/ia64/mm/init.c renamed from arch/ia64/mm/init.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +2 -2
@@ -670,13 +670,13 @@ mem_init (void)#ifdef CONFIG_MEMORY_HOTPLUG int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ;int ret; - ret =__add_pages (nid, start_pfn, nr_pages, restrictions); + ret =__add_pages (nid, start_pfn, nr_pages, params);if (ret)printk ("%s: Problem encountered in __add_pages() as ret=%d\n" , __func__, ret);
arch/powerpc/mm/mem.c renamed from arch/powerpc/mm/mem.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +2 -2
@@ -122,7 +122,7 @@ static void flush_dcache_range_chunked(u }int __ref arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ;
@@ -138,7 +138,7 @@ int __ref arch_add_memory(int nid, u64 sreturn -EFAULT ; } -return __add_pages (nid, start_pfn, nr_pages, restrictions); +return __add_pages (nid, start_pfn, nr_pages, params); } void __ref arch_remove_memory(int nid, u64 start, u64 size,
arch/s390/mm/init.c renamed from arch/s390/mm/init.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +3 -3
@@ -268,20 +268,20 @@ device_initcall(s390_cma_mem_init);#endif /* CONFIG_CMA */ int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn =PFN_DOWN (start);unsigned long size_pages =PFN_DOWN (size);int rc; -if (WARN_ON_ONCE (restrictions->altmap)) +if (WARN_ON_ONCE (params->altmap))return -EINVAL ; rc =vmem_add_mapping (start, size);if (rc)return rc; - rc =__add_pages (nid, start_pfn, size_pages, restrictions); + rc =__add_pages (nid, start_pfn, size_pages, params);if (rc)vmem_remove_mapping (start, size);return rc;
arch/sh/mm/init.c renamed from arch/sh/mm/init.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +2 -2
@@ -406,14 +406,14 @@ void __init mem_init(void)#ifdef CONFIG_MEMORY_HOTPLUG int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn =PFN_DOWN (start);unsigned long nr_pages = size >>PAGE_SHIFT ;int ret;/* We only have ZONE_NORMAL, so this is easy.. */ - ret =__add_pages (nid, start_pfn, nr_pages, restrictions); + ret =__add_pages (nid, start_pfn, nr_pages, params);if (unlikely (ret))printk ("%s: Failed, __add_pages() == %d\n" , __func__, ret);
arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +2 -2
@@ -853,12 +853,12 @@ void __init mem_init(void)#ifdef CONFIG_MEMORY_HOTPLUG int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ; -return __add_pages (nid, start_pfn, nr_pages, restrictions); +return __add_pages (nid, start_pfn, nr_pages, params); } void arch_remove_memory(int nid, u64 start, u64 size,
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +4 -4
@@ -844,11 +844,11 @@ static void update_end_of_memory_vars(u6 }int add_pages (int nid,unsigned long start_pfn,unsigned long nr_pages, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {int ret; - ret =__add_pages (nid, start_pfn, nr_pages, restrictions); + ret =__add_pages (nid, start_pfn, nr_pages, params);WARN_ON_ONCE (ret);/* update max_pfn, max_low_pfn and high_memory */
@@ -859,14 +859,14 @@ int add_pages(int nid, unsigned long sta }int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ;init_memory_mapping (start, start + size); -return add_pages (nid, start_pfn, nr_pages, restrictions); +return add_pages (nid, start_pfn, nr_pages, params); }#define PAGE_INUSE 0xFD
include/linux/memory_hotplug.h renamed from include/linux/memory_hotplug.h~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +8 -8
@@ -54,10 +54,10 @@ enum { };/* -* Restrictions for the memory hotplug: -* altmap: alternative allocator for memmap array +* Extended parameters for memory hotplug: +* altmap: alternative allocator for memmap array (optional) */ -struct mhp_restrictions { +struct mhp_params {struct vmem_altmap *altmap; };
@@ -108,7 +108,7 @@ extern int restore_online_page_callback(extern int try_online_node (int nid);extern int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_restrictions *restrictions); +struct mhp_params *params);extern u64 max_mem_size;extern bool memhp_auto_online;
@@ -126,17 +126,17 @@ extern void __remove_pages(unsigned long/* reasonably generic interface to expand the physical pages */ extern int __add_pages (int nid,unsigned long start_pfn,unsigned long nr_pages, -struct mhp_restrictions *restrictions); +struct mhp_params *params);#ifndef CONFIG_ARCH_HAS_ADD_PAGES static inline int add_pages (int nid,unsigned long start_pfn, -unsigned long nr_pages,struct mhp_restrictions *restrictions) +unsigned long nr_pages,struct mhp_params *params) { -return __add_pages (nid, start_pfn, nr_pages, restrictions); +return __add_pages (nid, start_pfn, nr_pages, params); }#else /* ARCH_HAS_ADD_PAGES */ int add_pages (int nid,unsigned long start_pfn,unsigned long nr_pages, -struct mhp_restrictions *restrictions); +struct mhp_params *params);#endif /* ARCH_HAS_ADD_PAGES */ #ifdef CONFIG_NUMA
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +4 -4
@@ -305,12 +305,12 @@ static int check_hotplug_memory_addressa* add the new pages. */ int __ref __add_pages (int nid,unsigned long pfn,unsigned long nr_pages, -struct mhp_restrictions *restrictions) +struct mhp_params *params) {const unsigned long end_pfn = pfn + nr_pages;unsigned long cur_nr_pages;int err; -struct vmem_altmap *altmap = restrictions->altmap; +struct vmem_altmap *altmap = params->altmap; err =check_hotplug_memory_addressable (pfn, nr_pages);if (err)
@@ -1002,7 +1002,7 @@ static int online_memory_block(struct me*/ int __ref add_memory_resource (int nid,struct resource *res) { -struct mhp_restrictions restrictions = {}; +struct mhp_params params = {};u64 start, size;bool new_node = false;int ret;
@@ -1030,7 +1030,7 @@ int __ref add_memory_resource(int nid, s new_node = ret;/* call arch's memory hotadd */ - ret =arch_add_memory (nid, start, size, &restrictions); + ret =arch_add_memory (nid, start, size, ¶ms);if (ret <0 ) goto error;
mm/memremap.c renamed from mm/memremap.c~mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params +4 -4
@@ -181,7 +181,7 @@ void *memremap_pages(struct dev_pagemap {struct resource *res = &pgmap->res;struct dev_pagemap *conflict_pgmap; -struct mhp_restrictions restrictions = { +struct mhp_params params = {/* * We do not want any optional features only our own memmap */
@@ -295,7 +295,7 @@ void *memremap_pages(struct dev_pagemap*/ if (pgmap->type ==MEMORY_DEVICE_PRIVATE ) { error =add_pages (nid,PHYS_PFN (res->start), -PHYS_PFN (resource_size (res)), &restrictions); +PHYS_PFN (resource_size (res)), ¶ms); }else { error =kasan_add_zero_shadow (__va (res->start),resource_size (res));if (error) {
@@ -304,7 +304,7 @@ void *memremap_pages(struct dev_pagemap } error =arch_add_memory (nid, res->start,resource_size (res), - &restrictions); + ¶ms); }if (!error) {
@@ -312,7 +312,7 @@ void *memremap_pages(struct dev_pagemap zone = &NODE_DATA (nid)->node_zones[ZONE_DEVICE ];move_pfn_range_to_zone (zone,PHYS_PFN (res->start), -PHYS_PFN (resource_size (res)), restrictions.altmap); +PHYS_PFN (resource_size (res)), params.altmap); }mem_hotplug_done ();
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ x86-mm-thread-pgprot_t-through-init_memory_mapping.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: x86/mm: thread pgprot_t through init_memory_mapping() has been added to the -mm tree. Its filename is x86-mm-thread-pgprot_t-through-init_memory_mapping.patch
The patch titled
Subject: x86/mm: thread pgprot_t through init_memory_mapping()
has been added to the -mm tree. Its filename is
x86-mm-thread-pgprot_t-through-init_memory_mapping.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/x86-mm-thread-pgprot_t-through-init_memory_mapping.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/x86-mm-thread-pgprot_t-through-init_memory_mapping.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: x86/mm: thread pgprot_t through init_memory_mapping()
In preparation to support a pgprot_t argument for arch_add_memory().
It's required to move the prototype of init_memory_mapping() seeing the original location came before the definition of pgprot_t.
---
arch/x86/include/asm/page_types.h | 3 -- arch/x86/include/asm/pgtable.h | 3 ++ arch/x86/kernel/amd_gart_64.c | 3 +- arch/x86/mm/init.c | 9 ++++--- arch/x86/mm/init_32.c | 3 +- arch/x86/mm/init_64.c | 32 +++++++++++++++------------- arch/x86/mm/mm_internal.h | 3 +- arch/x86/platform/uv/bios_uv.c | 3 +- 8 files changed, 34 insertions(+), 25 deletions(-)
arch/x86/include/asm/page_types.h renamed from arch/x86/include/asm/page_types.h~x86-mm-thread-pgprot_t-through-init_memory_mapping +0 -3
@@ -71,9 +71,6 @@ static inline phys_addr_t get_max_mappedbool pfn_range_is_mapped (unsigned long start_pfn,unsigned long end_pfn); -extern unsigned long init_memory_mapping (unsigned long start, -unsigned long end); -extern void initmem_init (void );#endif /* !__ASSEMBLY__ */
arch/x86/include/asm/pgtable.h renamed from arch/x86/include/asm/pgtable.h~x86-mm-thread-pgprot_t-through-init_memory_mapping +3 -0
@@ -1049,6 +1049,9 @@ static inline void __meminit init_trampovoid __init poking_init (void ); +unsigned long init_memory_mapping (unsigned long start, +unsigned long end,pgprot_t prot); +# ifdef CONFIG_RANDOMIZE_MEMORY void __meminit init_trampoline (void );# else
arch/x86/kernel/amd_gart_64.c renamed from arch/x86/kernel/amd_gart_64.c~x86-mm-thread-pgprot_t-through-init_memory_mapping +2 -1
@@ -744,7 +744,8 @@ int __init gart_iommu_init(void) start_pfn =PFN_DOWN (aper_base);if (!pfn_range_is_mapped (start_pfn, end_pfn)) -init_memory_mapping (start_pfn<<PAGE_SHIFT , end_pfn<<PAGE_SHIFT ); +init_memory_mapping (start_pfn<<PAGE_SHIFT , end_pfn<<PAGE_SHIFT , +PAGE_KERNEL );pr_info ("PCI-DMA: using GART IOMMU.\n" ); iommu_size =check_iommu_size (info.aper_base, aper_size);
arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c~x86-mm-thread-pgprot_t-through-init_memory_mapping +2 -1
@@ -253,7 +253,8 @@ static inline int is_kernel_text(unsigneunsigned long __init kernel_physical_mapping_init (unsigned long start,unsigned long end, -unsigned long page_size_mask) +unsigned long page_size_mask, +pgprot_t prot) {int use_pse = page_size_mask == (1 <<PG_LEVEL_2M );unsigned long last_map_addr = end;
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~x86-mm-thread-pgprot_t-through-init_memory_mapping +18 -14
@@ -585,7 +585,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned*/ static unsigned long __meminit phys_pud_init (pud_t *pud_page,unsigned long paddr,unsigned long paddr_end, -unsigned long page_size_mask,bool init) +unsigned long page_size_mask,pgprot_t _prot,bool init) {unsigned long pages =0 , paddr_next;unsigned long paddr_last = paddr_end;
@@ -595,7 +595,7 @@ phys_pud_init(pud_t *pud_page, unsignedfor (; i <PTRS_PER_PUD ; i++, paddr = paddr_next) {pud_t *pud;pmd_t *pmd; -pgprot_t prot =PAGE_KERNEL ; +pgprot_t prot = _prot; vaddr = (unsigned long )__va (paddr); pud = pud_page +pud_index (vaddr);
@@ -644,9 +644,12 @@ phys_pud_init(pud_t *pud_page, unsignedif (page_size_mask & (1 <<PG_LEVEL_1G )) { pages++;spin_lock (&init_mm.page_table_lock); + + prot =__pgprot (pgprot_val (prot) | __PAGE_KERNEL_LARGE); +set_pte_init ((pte_t *)pud,pfn_pte ((paddr &PUD_MASK ) >>PAGE_SHIFT , -PAGE_KERNEL_LARGE ), + prot), init);spin_unlock (&init_mm.page_table_lock); paddr_last = paddr_next;
@@ -669,7 +672,7 @@ phys_pud_init(pud_t *pud_page, unsignedstatic unsigned long __meminit phys_p4d_init (p4d_t *p4d_page,unsigned long paddr,unsigned long paddr_end, -unsigned long page_size_mask,bool init) +unsigned long page_size_mask,pgprot_t prot,bool init) {unsigned long vaddr, vaddr_end, vaddr_next, paddr_next, paddr_last;
@@ -679,7 +682,7 @@ phys_p4d_init(p4d_t *p4d_page, unsignedif (!pgtable_l5_enabled ())return phys_pud_init ((pud_t *) p4d_page, paddr, paddr_end, - page_size_mask, init); + page_size_mask, prot, init);for (; vaddr < vaddr_end; vaddr = vaddr_next) {p4d_t *p4d = p4d_page +p4d_index (vaddr);
@@ -702,13 +705,13 @@ phys_p4d_init(p4d_t *p4d_page, unsignedif (!p4d_none (*p4d)) { pud =pud_offset (p4d,0 ); paddr_last =phys_pud_init (pud, paddr,__pa (vaddr_end), - page_size_mask, init); + page_size_mask, prot, init);continue ; } pud =alloc_low_page (); paddr_last =phys_pud_init (pud, paddr,__pa (vaddr_end), - page_size_mask, init); + page_size_mask, prot, init);spin_lock (&init_mm.page_table_lock);p4d_populate_init (&init_mm, p4d, pud, init);
@@ -722,7 +725,7 @@ static unsigned long __meminit __kernel_physical_mapping_init(unsigned long paddr_start, unsigned long paddr_end, unsigned long page_size_mask, - bool init) + pgprot_t prot, bool init) { bool pgd_changed = false;unsigned long vaddr, vaddr_start, vaddr_end, vaddr_next, paddr_last;
@@ -743,13 +746,13 @@ __kernel_physical_mapping_init(unsigned paddr_last =phys_p4d_init (p4d,__pa (vaddr),__pa (vaddr_end), page_size_mask, - init); + prot, init);continue ; } p4d =alloc_low_page (); paddr_last =phys_p4d_init (p4d,__pa (vaddr),__pa (vaddr_end), - page_size_mask, init); + page_size_mask, prot, init);spin_lock (&init_mm.page_table_lock);if (pgtable_l5_enabled ())
@@ -778,10 +781,10 @@ __kernel_physical_mapping_init(unsignedunsigned long __meminit kernel_physical_mapping_init (unsigned long paddr_start,unsigned long paddr_end, -unsigned long page_size_mask) +unsigned long page_size_mask,pgprot_t prot) {return __kernel_physical_mapping_init (paddr_start, paddr_end, - page_size_mask, true); + page_size_mask, prot, true); }/*
@@ -796,7 +799,8 @@ kernel_physical_mapping_change(unsigned unsigned long page_size_mask) {return __kernel_physical_mapping_init (paddr_start, paddr_end, - page_size_mask, false); + page_size_mask,PAGE_KERNEL , + false); }#ifndef CONFIG_NUMA
@@ -864,7 +868,7 @@ int arch_add_memory(int nid, u64 start,unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ; -init_memory_mapping (start, start + size); +init_memory_mapping (start, start + size,PAGE_KERNEL );return add_pages (nid, start_pfn, nr_pages, params); }
arch/x86/mm/init.c renamed from arch/x86/mm/init.c~x86-mm-thread-pgprot_t-through-init_memory_mapping +5 -4
@@ -467,7 +467,7 @@ bool pfn_range_is_mapped(unsigned long s* the physical memory. To access them they are temporarily mapped. */ unsigned long __ref init_memory_mapping (unsigned long start, -unsigned long end) +unsigned long end,pgprot_t prot) {struct map_range mr[NR_RANGE_MR ];unsigned long ret =0 ;
@@ -481,7 +481,8 @@ unsigned long __ref init_memory_mapping(for (i =0 ; i < nr_range; i++) ret =kernel_physical_mapping_init (mr[i].start, mr[i].end, - mr[i].page_size_mask); + mr[i].page_size_mask, + prot);add_pfn_range_mapped (start >>PAGE_SHIFT , ret >>PAGE_SHIFT );
@@ -521,7 +522,7 @@ static unsigned long __init init_range_m*/ can_use_brk_pgt =max (start, (u64 )pgt_buf_end<<PAGE_SHIFT ) >=min (end, (u64 )pgt_buf_top<<PAGE_SHIFT ); -init_memory_mapping (start, end); +init_memory_mapping (start, end,PAGE_KERNEL ); mapped_ram_size += end - start; can_use_brk_pgt = true; }
@@ -661,7 +662,7 @@ void __init init_mem_mapping(void)#endif /* the ISA range is always mapped regardless of memory holes */ -init_memory_mapping (0 ,ISA_END_ADDRESS ); +init_memory_mapping (0 ,ISA_END_ADDRESS ,PAGE_KERNEL );/* Init the trampoline, possibly with KASLR memory offset */ init_trampoline ();
arch/x86/mm/mm_internal.h renamed from arch/x86/mm/mm_internal.h~x86-mm-thread-pgprot_t-through-init_memory_mapping +2 -1
@@ -12,7 +12,8 @@ void early_ioremap_page_table_range_initunsigned long kernel_physical_mapping_init (unsigned long start,unsigned long end, -unsigned long page_size_mask); +unsigned long page_size_mask, +pgprot_t prot);unsigned long kernel_physical_mapping_change (unsigned long start,unsigned long end,unsigned long page_size_mask);
arch/x86/platform/uv/bios_uv.c renamed from arch/x86/platform/uv/bios_uv.c~x86-mm-thread-pgprot_t-through-init_memory_mapping +2 -1
@@ -352,7 +352,8 @@ void __iomem *__init efi_ioremap(unsigneif (type ==EFI_MEMORY_MAPPED_IO )return ioremap (phys_addr, size); - last_map_pfn =init_memory_mapping (phys_addr, phys_addr + size); + last_map_pfn =init_memory_mapping (phys_addr, phys_addr + size, +PAGE_KERNEL );if ((last_map_pfn <<PAGE_SHIFT ) < phys_addr + size) {unsigned long top = last_map_pfn <<PAGE_SHIFT ;efi_ioremap (top, size - (top - phys_addr), type, attribute);
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ x86-mm-introduce-__set_memory_prot.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: x86/mm: introduce __set_memory_prot() has been added to the -mm tree. Its filename is x86-mm-introduce-__set_memory_prot.patch
The patch titled
Subject: x86/mm: introduce __set_memory_prot()
has been added to the -mm tree. Its filename is
x86-mm-introduce-__set_memory_prot.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/x86-mm-introduce-__set_memory_prot.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/x86-mm-introduce-__set_memory_prot.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: x86/mm: introduce __set_memory_prot()
For use in the 32bit arch_add_memory() to set the pgprot type of the memory to add.
---
arch/x86/include/asm/set_memory.h | 1 + arch/x86/mm/pat/set_memory.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
arch/x86/include/asm/set_memory.h renamed from arch/x86/include/asm/set_memory.h~x86-mm-introduce-__set_memory_prot +1 -0
@@ -34,6 +34,7 @@* The caller is required to take care of these. */ +int __set_memory_prot (unsigned long addr,int numpages,pgprot_t prot);int _set_memory_uc (unsigned long addr,int numpages);int _set_memory_wc (unsigned long addr,int numpages);int _set_memory_wt (unsigned long addr,int numpages);
arch/x86/mm/pat/set_memory.c renamed from arch/x86/mm/pat/set_memory.c~x86-mm-introduce-__set_memory_prot +13 -0
@@ -1792,6 +1792,19 @@ static inline int cpa_clear_pages_array( CPA_PAGES_ARRAY, pages); } +/* +* _set_memory_prot is an internal helper for callers that have been passed +* a pgprot_t value from upper layers and a reservation has already been taken. +* If you want to set the pgprot to a specific page protocol, use the +* set_memory_xx() functions. +*/ +int __set_memory_prot (unsigned long addr,int numpages,pgprot_t prot) +{ +return change_page_attr_set_clr (&addr, numpages, prot, +__pgprot (~pgprot_val (prot)),0 ,0 , +NULL ); +} +int _set_memory_uc (unsigned long addr,int numpages) {/*
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: powerpc/mm: thread pgprot_t through create_section_mapping() has been added to the -mm tree. Its filename is powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch
The patch titled
Subject: powerpc/mm: thread pgprot_t through create_section_mapping()
has been added to the -mm tree. Its filename is
powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: powerpc/mm: thread pgprot_t through create_section_mapping()
In prepartion to support a pgprot_t argument for arch_add_memory().
---
arch/powerpc/include/asm/book3s/64/hash.h | 3 ++- arch/powerpc/include/asm/book3s/64/radix.h | 3 ++- arch/powerpc/include/asm/sparsemem.h | 3 ++- arch/powerpc/mm/book3s64/hash_utils.c | 5 +++-- arch/powerpc/mm/book3s64/pgtable.c | 7 ++++--- arch/powerpc/mm/book3s64/radix_pgtable.c | 18 +++++++++++------- arch/powerpc/mm/mem.c | 5 +++-- 7 files changed, 27 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h renamed from arch/powerpc/include/asm/book3s/64/hash.h~powerpc-mm-thread-pgprot_t-through-create_section_mapping +2 -1
@@ -251,7 +251,8 @@ extern int __meminit hash__vmemmap_creatextern void hash__vmemmap_remove_mapping (unsigned long start,unsigned long page_size); -int hash__create_section_mapping (unsigned long start,unsigned long end,int nid); +int hash__create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot);int hash__remove_section_mapping (unsigned long start,unsigned long end);#endif /* !__ASSEMBLY__ */
arch/powerpc/include/asm/book3s/64/radix.h renamed from arch/powerpc/include/asm/book3s/64/radix.h~powerpc-mm-thread-pgprot_t-through-create_section_mapping +2 -1
@@ -289,7 +289,8 @@ static inline unsigned long radix__get_t }#ifdef CONFIG_MEMORY_HOTPLUG -int radix__create_section_mapping (unsigned long start,unsigned long end,int nid); +int radix__create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot);int radix__remove_section_mapping (unsigned long start,unsigned long end);#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __ASSEMBLY__ */
arch/powerpc/include/asm/sparsemem.h renamed from arch/powerpc/include/asm/sparsemem.h~powerpc-mm-thread-pgprot_t-through-create_section_mapping +2 -1
@@ -13,7 +13,8 @@#endif /* CONFIG_SPARSEMEM */ #ifdef CONFIG_MEMORY_HOTPLUG -extern int create_section_mapping (unsigned long start,unsigned long end,int nid); +extern int create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot);extern int remove_section_mapping (unsigned long start,unsigned long end);#ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/mm/book3s64/hash_utils.c renamed from arch/powerpc/mm/book3s64/hash_utils.c~powerpc-mm-thread-pgprot_t-through-create_section_mapping +3 -2
@@ -809,7 +809,8 @@ int resize_hpt_for_hotplug(unsigned longreturn 0 ; } -int hash__create_section_mapping (unsigned long start,unsigned long end,int nid) +int hash__create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot) {int rc;
@@ -819,7 +820,7 @@ int hash__create_section_mapping(unsigne } rc =htab_bolt_mapping (start, end,__pa (start), -pgprot_val (PAGE_KERNEL ), mmu_linear_psize, +pgprot_val (prot), mmu_linear_psize, mmu_kernel_ssize);if (rc <0 ) {
arch/powerpc/mm/book3s64/pgtable.c renamed from arch/powerpc/mm/book3s64/pgtable.c~powerpc-mm-thread-pgprot_t-through-create_section_mapping +4 -3
@@ -171,12 +171,13 @@ void mmu_cleanup_all(void) }#ifdef CONFIG_MEMORY_HOTPLUG -int __meminit create_section_mapping (unsigned long start,unsigned long end,int nid) +int __meminit create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot) {if (radix_enabled ()) -return radix__create_section_mapping (start, end, nid); +return radix__create_section_mapping (start, end, nid, prot); -return hash__create_section_mapping (start, end, nid); +return hash__create_section_mapping (start, end, nid, prot); }int __meminit remove_section_mapping (unsigned long start,unsigned long end)
arch/powerpc/mm/book3s64/radix_pgtable.c renamed from arch/powerpc/mm/book3s64/radix_pgtable.c~powerpc-mm-thread-pgprot_t-through-create_section_mapping +11 -7
@@ -253,7 +253,7 @@ static unsigned long next_boundary(unsigstatic int __meminit create_physical_mapping (unsigned long start,unsigned long end, -int nid) +int nid,pgprot_t _prot) {unsigned long vaddr, addr, mapping_size =0 ;bool prev_exec, exec = false;
@@ -289,7 +289,7 @@ static int __meminit create_physical_map prot =PAGE_KERNEL_X ; exec = true; }else { - prot =PAGE_KERNEL ; + prot = _prot; exec = false; }
@@ -333,7 +333,7 @@ static void __init radix_init_pgtable(voWARN_ON (create_physical_mapping (reg->base, reg->base + reg->size, --1 )); +-1 ,PAGE_KERNEL )); }/* Find out how many PID bits are supported */
@@ -712,8 +712,10 @@ static int __meminit stop_machine_changespin_unlock (&init_mm.page_table_lock);pte_clear (&init_mm, params->aligned_start, params->pte); -create_physical_mapping (__pa (params->aligned_start),__pa (params->start),-1 ); -create_physical_mapping (__pa (params->end),__pa (params->aligned_end),-1 ); +create_physical_mapping (__pa (params->aligned_start), +__pa (params->start),-1 ,PAGE_KERNEL ); +create_physical_mapping (__pa (params->end),__pa (params->aligned_end), +-1 ,PAGE_KERNEL );spin_lock (&init_mm.page_table_lock);return 0 ; }
@@ -870,14 +872,16 @@ static void __meminit remove_pagetable(uradix__flush_tlb_kernel_range (start, end); } -int __meminit radix__create_section_mapping (unsigned long start,unsigned long end,int nid) +int __meminit radix__create_section_mapping (unsigned long start, +unsigned long end,int nid, +pgprot_t prot) {if (end >=RADIX_VMALLOC_START ) {pr_warn ("Outside the supported range\n" );return -1 ; } -return create_physical_mapping (__pa (start),__pa (end), nid); +return create_physical_mapping (__pa (start),__pa (end), nid, prot); }int __meminit radix__remove_section_mapping (unsigned long start,unsigned long end)
arch/powerpc/mm/mem.c renamed from arch/powerpc/mm/mem.c~powerpc-mm-thread-pgprot_t-through-create_section_mapping +3 -2
@@ -90,7 +90,8 @@ int memory_add_physaddr_to_nid(u64 start }#endif -int __weak create_section_mapping (unsigned long start,unsigned long end,int nid) +int __weak create_section_mapping (unsigned long start,unsigned long end, +int nid,pgprot_t prot) {return -ENODEV ; }
@@ -131,7 +132,7 @@ int __ref arch_add_memory(int nid, u64 sresize_hpt_for_hotplug (memblock_phys_mem_size ()); start = (unsigned long )__va (start); - rc =create_section_mapping (start, start + size, nid); + rc =create_section_mapping (start, start + size, nid,PAGE_KERNEL );if (rc) {pr_warn ("Unable to create mapping for hot added memory 0x%llx..0x%llx: %d\n" , start, start + size, rc);
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/memory_hotplug: add pgprot_t to mhp_params has been added to the -mm tree. Its filename is mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch
The patch titled
Subject: mm/memory_hotplug: add pgprot_t to mhp_params
has been added to the -mm tree. Its filename is
mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: mm/memory_hotplug: add pgprot_t to mhp_params
devm_memremap_pages() is currently used by the PCI P2PDMA code to create struct page mappings for IO memory. At present, these mappings are created with PAGE_KERNEL which implies setting the PAT bits to be WB. However, on x86, an mtrr register will typically override this and force the cache type to be UC-. In the case firmware doesn't set this register it is effectively WB and will typically result in a machine check exception when it's accessed.
Other arches are not currently likely to function correctly seeing they don't have any MTRR registers to fall back on.
To solve this, provide a way to specify the pgprot value explicitly to arch_add_memory().
Of the arches that support MEMORY_HOTPLUG: x86_64, and arm64 need a simple change to pass the pgprot_t down to their respective functions which set up the page tables. For x86_32, set the page tables explicitly using _set_memory_prot() (seeing they are already mapped). For ia64, s390 and sh, reject anything but PAGE_KERNEL settings -- this should be fine, for now, seeing these architectures don't support ZONE_DEVICE.
A check in __add_pages() is also added to ensure the pgprot parameter was set for all arches.
---
arch/arm64/mm/mmu.c | 3 ++- arch/ia64/mm/init.c | 3 +++ arch/powerpc/mm/mem.c | 3 ++- arch/s390/mm/init.c | 3 +++ arch/sh/mm/init.c | 3 +++ arch/x86/mm/init_32.c | 12 ++++++++++++ arch/x86/mm/init_64.c | 2 +- include/linux/memory_hotplug.h | 3 +++ mm/memory_hotplug.c | 5 ++++- mm/memremap.c | 6 +++--- 10 files changed, 36 insertions(+), 7 deletions(-)
arch/arm64/mm/mmu.c renamed from arch/arm64/mm/mmu.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +2 -1
@@ -1382,7 +1382,8 @@ int arch_add_memory(int nid, u64 start, flags =NO_BLOCK_MAPPINGS |NO_CONT_MAPPINGS ;__create_pgd_mapping (swapper_pg_dir, start,__phys_to_virt (start), - size,PAGE_KERNEL , __pgd_pgtable_alloc, flags); + size, params->pgprot, __pgd_pgtable_alloc, + flags);memblock_clear_nomap (start, size);
arch/ia64/mm/init.c renamed from arch/ia64/mm/init.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +3 -0
@@ -676,6 +676,9 @@ int arch_add_memory(int nid, u64 start,unsigned long nr_pages = size >>PAGE_SHIFT ;int ret; +if (WARN_ON_ONCE (params->pgprot.pgprot !=PAGE_KERNEL .pgprot)) +return -EINVAL ; + ret =__add_pages (nid, start_pfn, nr_pages, params);if (ret) printk("%s: Problem encountered in __add_pages() as ret=%d\n",
arch/powerpc/mm/mem.c renamed from arch/powerpc/mm/mem.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +2 -1
@@ -132,7 +132,8 @@ int __ref arch_add_memory(int nid, u64 sresize_hpt_for_hotplug (memblock_phys_mem_size ()); start = (unsigned long )__va (start); - rc =create_section_mapping (start, start + size, nid,PAGE_KERNEL ); + rc =create_section_mapping (start, start + size, nid, + params->pgprot);if (rc) {pr_warn ("Unable to create mapping for hot added memory 0x%llx..0x%llx: %d\n" , start, start + size, rc);
arch/s390/mm/init.c renamed from arch/s390/mm/init.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +3 -0
@@ -277,6 +277,9 @@ int arch_add_memory(int nid, u64 start,if (WARN_ON_ONCE (params->altmap))return -EINVAL ; +if (WARN_ON_ONCE (params->pgprot.pgprot !=PAGE_KERNEL .pgprot)) +return -EINVAL ; + rc =vmem_add_mapping (start, size);if (rc)return rc;
arch/sh/mm/init.c renamed from arch/sh/mm/init.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +3 -0
@@ -412,6 +412,9 @@ int arch_add_memory(int nid, u64 start,unsigned long nr_pages = size >>PAGE_SHIFT ;int ret; + if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot) +return -EINVAL ; +/* We only have ZONE_NORMAL, so this is easy.. */ ret =__add_pages (nid, start_pfn, nr_pages, params);if (unlikely (ret))
arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +12 -0
@@ -858,6 +858,18 @@ int arch_add_memory(int nid, u64 start, {unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ; +int ret; + +/* +* The page tables were already mapped at boot so if the caller +* requests a different mapping type then we must change all the +* pages with __set_memory_prot(). +*/ +if (params->pgprot.pgprot !=PAGE_KERNEL .pgprot) { + ret =__set_memory_prot (start, nr_pages, params->pgprot); +if (ret) +return ret; + }return __add_pages (nid, start_pfn, nr_pages, params); }
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +1 -1
@@ -868,7 +868,7 @@ int arch_add_memory(int nid, u64 start,unsigned long start_pfn = start >>PAGE_SHIFT ;unsigned long nr_pages = size >>PAGE_SHIFT ; -init_memory_mapping (start, start + size,PAGE_KERNEL ); +init_memory_mapping (start, start + size, params->pgprot);return add_pages (nid, start_pfn, nr_pages, params); }
include/linux/memory_hotplug.h renamed from include/linux/memory_hotplug.h~mm-memory_hotplug-add-pgprot_t-to-mhp_params +3 -0
@@ -56,9 +56,12 @@ enum {/* * Extended parameters for memory hotplug: * altmap: alternative allocator for memmap array (optional) +* pgprot: page protection flags to apply to newly created page tables +* (required) */ struct mhp_params {struct vmem_altmap *altmap; +pgprot_t pgprot; };/*
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +4 -1
@@ -312,6 +312,9 @@ int __ref __add_pages(int nid, unsignedint err;struct vmem_altmap *altmap = params->altmap; +if (WARN_ON_ONCE (!params->pgprot.pgprot)) +return -EINVAL ; + err =check_hotplug_memory_addressable (pfn, nr_pages);if (err)return err;
@@ -1002,7 +1005,7 @@ static int online_memory_block(struct me*/ int __ref add_memory_resource (int nid,struct resource *res) { -struct mhp_params params = {}; +struct mhp_params params = { .pgprot =PAGE_KERNEL };u64 start, size;bool new_node = false;int ret;
mm/memremap.c renamed from mm/memremap.c~mm-memory_hotplug-add-pgprot_t-to-mhp_params +3 -3
@@ -186,8 +186,8 @@ void *memremap_pages(struct dev_pagemap* We do not want any optional features only our own memmap */ .altmap = pgmap_altmap(pgmap), + .pgprot = PAGE_KERNEL, }; -pgprot_t pgprot =PAGE_KERNEL ;int error, is_ram;bool need_devmap_managed = true;
@@ -275,8 +275,8 @@ void *memremap_pages(struct dev_pagemapif (nid <0 ) nid =numa_mem_id (); - error =track_pfn_remap (NULL , &pgprot,PHYS_PFN (res->start),0 , -resource_size (res)); + error =track_pfn_remap (NULL , ¶ms.pgprot,PHYS_PFN (res->start), +0 ,resource_size (res));if (error) goto err_pfn_remap;
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/memremap: set caching mode for PCI P2PDMA memory to WC has been added to the -mm tree. Its filename is mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
The patch titled
Subject: mm/memremap: set caching mode for PCI P2PDMA memory to WC
has been added to the -mm tree. Its filename is
mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Logan Gunthorpe <[email protected]>
Subject: mm/memremap: set caching mode for PCI P2PDMA memory to WC
PCI BAR IO memory should never be mapped as WB, however prior to this the PAT bits were set WB and it was typically overridden by MTRR registers set by the firmware.
Set PCI P2PDMA memory to be UC as this is what it currently, typically, ends up being mapped as on x86 after the MTRR registers override the cache setting.
Future use-cases may need to generalize this by adding flags to select the caching type, as some P2PDMA cases may not want UC. However, those use-cases are not upstream yet and this can be changed when they arrive.
---
mm/memremap.c | 3 +++ 1 file changed, 3 insertions(+)
mm/memremap.c renamed from mm/memremap.c~mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc +3 -0
@@ -210,7 +210,10 @@ void *memremap_pages(struct dev_pagemap }break ;case MEMORY_DEVICE_DEVDAX : + need_devmap_managed = false; +break ;case MEMORY_DEVICE_PCI_P2PDMA : + params.pgprot =pgprot_noncached (params.pgprot); need_devmap_managed = false;break ;default :
_
Patches currently in -mm which might be from [email protected] are
mm-memory_hotplug-drop-the-flags-field-from-struct-mhp_restrictions.patch mm-memory_hotplug-rename-mhp_restrictions-to-mhp_params.patch x86-mm-thread-pgprot_t-through-init_memory_mapping.patch x86-mm-introduce-__set_memory_prot.patch powerpc-mm-thread-pgprot_t-through-create_section_mapping.patch mm-memory_hotplug-add-pgprot_t-to-mhp_params.patch mm-memremap-set-caching-mode-for-pci-p2pdma-memory-to-wc.patch
+ kasan-detect-negative-size-in-memory-operation-function-fix.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kasan/tags: fix -Wdeclaration-after-statement warn has been added to the -mm tree. Its filename is kasan-detect-negative-size-in-memory-operation-function-fix.patch
The patch titled
Subject: kasan/tags: fix -Wdeclaration-after-statement warn
has been added to the -mm tree. Its filename is
kasan-detect-negative-size-in-memory-operation-function-fix.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/kasan-detect-negative-size-in-memory-operation-function-fix.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/kasan-detect-negative-size-in-memory-operation-function-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Qian Cai <[email protected]>
Subject: kasan/tags: fix -Wdeclaration-after-statement warn
The linux-next commit "kasan: detect negative size in memory operation function" introduced a compilation warning,
mm/kasan/tags_report.c:51:27: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
struct kasan_alloc_meta *alloc_meta;
Fix it by moving a code around a bit where there is no strict dependency.
---
mm/kasan/tags_report.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
mm/kasan/tags_report.c renamed from mm/kasan/tags_report.c~kasan-detect-negative-size-in-memory-operation-function-fix +11 -11
@@ -36,17 +36,6 @@const char *get_bug_type (struct kasan_access_info *info) { -/* -* If access_size is a negative number, then it has reason to be -* defined as out-of-bounds bug type. -* -* Casting negative numbers to size_t would indeed turn up as -* a large size_t and its value will be larger than ULONG_MAX/2, -* so that this can qualify as out-of-bounds. -*/ -if (info->access_addr + info->access_size < info->access_addr) -return "out-of-bounds" ; -#ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY struct kasan_alloc_meta *alloc_meta;struct kmem_cache *cache;
@@ -71,6 +60,17 @@ const char *get_bug_type(struct kasan_ac }#endif +/* +* If access_size is a negative number, then it has reason to be +* defined as out-of-bounds bug type. +* +* Casting negative numbers to size_t would indeed turn up as +* a large size_t and its value will be larger than ULONG_MAX/2, +* so that this can qualify as out-of-bounds. +*/ +if (info->access_addr + info->access_size < info->access_addr) +return "out-of-bounds" ; +return "invalid-access" ; }
_
Patches currently in -mm which might be from [email protected] are
mm-disable-kcsan-for-kmemleak.patch mm-swapfile-fix-data-races-in-try_to_unuse.patch kasan-detect-negative-size-in-memory-operation-function-fix.patch mm-vmscan-fix-data-races-at-kswapd_classzone_idx.patch percpu_counter-fix-a-data-race-at-vm_committed_as.patch mm-frontswap-mark-various-intentional-data-races.patch mm-page_io-mark-various-intentional-data-races.patch mm-page_io-mark-various-intentional-data-races-v2.patch mm-swap_state-mark-various-intentional-data-races.patch mm-swapfile-fix-and-annotate-various-data-races.patch mm-swapfile-fix-and-annotate-various-data-races-v2.patch mm-page_counter-fix-various-data-races-at-memsw.patch mm-memcontrol-fix-a-data-race-in-scan-count.patch mm-list_lru-fix-a-data-race-in-list_lru_count_one.patch mm-mempool-fix-a-data-race-in-mempool_free.patch mm-util-annotate-an-data-race-at-vm_committed_as.patch mm-rmap-annotate-a-data-race-at-tlb_flush_batched.patch mm-annotate-a-data-race-in-page_zonenum.patch mm-swap-annotate-data-races-for-lru_rotate_pvecs.patch
+ mm-gup-track-foll_pin-pages-fix-2.patch added to -mm tree
In reply to Andrew MortonThe patch titled
The patch titled
Subject: mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages"
has been added to the -mm tree. Its filename is
mm-gup-track-foll_pin-pages-fix-2.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-track-foll_pin-pages-fix-2.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-track-foll_pin-pages-fix-2.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Claudio Imbrenda <[email protected]>
Subject: mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages"
In case pin fails, we need to unpin, a simple put_page will not be enough
fixup for commit 9947ea2c1e608e32 ("mm/gup: track FOLL_PIN pages")
it can be simply squashed in
---
mm/gup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup.c renamed from mm/gup.c~mm-gup-track-foll_pin-pages-fix-2 +1 -1
@@ -2065,7 +2065,7 @@ static int gup_pte_range(pmd_t pmd, unsi goto pte_unmap;if (unlikely (pte_val (pte) !=pte_val (*ptep))) { -put_page (head); +put_compound_head (head,1 , flags); goto pte_unmap; }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-track-foll_pin-pages-fix-2.patch mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
John Hubbard
reviewerRe: + mm-gup-track-foll_pin-pages-fix-2.patch added to -mm tree
Quoted 6 lines · Andrew Morton
The patch titled
Subject: mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages"has been added to the -mm tree. Its filename is
mm-gup-track-foll_pin-pages-fix-2.patch
This appears to be causing a build failure in mm/gup.c, in mmotm, as of today anyway:
commit 5d9ee416b570 ("pci: test for unexpectedly disabled bridges")
I vaguely recall reviewing an earlier version that moved put_compound_head() up higher in gup.c, in order to avoid this. In any case, that's what this needs in order to build. Sorry for missing it in the review.
Claudio, did you compile-test the patch? I'm not sure how this made it all the way to mmotm without it triggering something, either, but I can't see anything obviously wrong with my tree, which has no local changes applied.
Here's what I'm seeing, and it makes sense because put_compound_head() is actually at line 2323:
mm/gup.c: In function ‘gup_pte_range’:mm/gup.c:2177:4: error: implicit declaration of function ‘put_compound_head’; did you mean ‘set_compound_head’? [-Werror=implicit-function-declaration]
2177 | put_compound_head(head, 1, flags);
| ^~~~~~~~~~~~~~~~~
| set_compound_head
mm/gup.c: At top level:
mm/gup.c:2323:13: warning: conflicting types for ‘put_compound_head’
2323 | static void put_compound_head(struct page *page, int refs, unsigned int flags)
| ^~~~~~~~~~~~~~~~~
mm/gup.c:2323:13: error: static declaration of ‘put_compound_head’ follows non-static declaration
mm/gup.c:2177:4: note: previous implicit declaration of ‘put_compound_head’ was here
2177 | put_compound_head(head, 1, flags);
| ^~~~~~~~~~~~~~~~~And here's a compile-tested (only) proposed fix:
mm/gup.c +22 -22
@@ -2116,6 +2116,28 @@ static inline pte_t gup_get_pte(pte_t *ptep) }#endif /* CONFIG_GUP_GET_PTE_LOW_HIGH */ +static void put_compound_head (struct page *page,int refs,unsigned int flags) +{ +if (flags &FOLL_PIN ) { +mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED , + refs); + +if (hpage_pincount_available (page)) +hpage_pincount_sub (page, refs); +else + refs *=GUP_PIN_COUNTING_BIAS ; + } + +VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); +/* +* Calling put_page() for each ref is unnecessarily slow. Only the last +* ref needs a put_page(). +*/ +if (refs >1 ) +page_ref_sub (page, refs -1 ); +put_page (page); +} +static void __maybe_unused undo_dev_pagemap (int *nr,int nr_start,unsigned int flags,struct page **pages)
@@ -2320,28 +2342,6 @@ static int record_subpages(struct page *page, unsigned long addr,return nr; } -static void put_compound_head (struct page *page,int refs,unsigned int flags) -{ -if (flags &FOLL_PIN ) { -mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED , - refs); - -if (hpage_pincount_available (page)) -hpage_pincount_sub (page, refs); -else - refs *=GUP_PIN_COUNTING_BIAS ; - } - -VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); -/* -* Calling put_page() for each ref is unnecessarily slow. Only the last -* ref needs a put_page(). -*/ -if (refs >1 ) -page_ref_sub (page, refs -1 ); -put_page (page); -} -#ifdef CONFIG_ARCH_HAS_HUGEPD static unsigned long hugepte_addr_end (unsigned long addr,unsigned long end,unsigned long sz)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 53 lines
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-track-foll_pin-pages-fix-2.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-track-foll_pin-pages-fix-2.patchBefore you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's*** Remember to use
Documentation/process/submit-checklist.rstwhen testing your code ***The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Claudio Imbrenda <[email protected]>
Subject: mm/gup: fixup for9947ea2c1e608e32"mm/gup: trackFOLL_PINpages"In case pin fails, we need to unpin, a simple
put_pagewill not be enoughfixup for commit
9947ea2c1e608e32("mm/gup: trackFOLL_PINpages")it can be simply squashed in
Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by John Hubbard <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
mm/gup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/gup.c renamed from mm/gup.c~mm-gup-track-foll_pin-pages-fix-2 +1
-1@@ -2065,7 +2065,7 @@ static int gup_pte_range(pmd_t pmd, unsi goto pte_unmap;if (unlikely (pte_val (pte) !=pte_val (*ptep))) { -put_page (head); +put_compound_head (head,1 , flags); goto pte_unmap; }_
Patches currently in -mm which might be from [email protected] are
mm-gup-track-foll_pin-pages-fix-2.patch mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
Re: + mm-gup-track-foll_pin-pages-fix-2.patch added to -mm tree
Quoted 11 lines · On Tue, 10 Mar 2020 18:46:40 -0700 John Hubbard <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
The patch titled
Subject: mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track
FOLL_PINpages" has been added to the -mm tree. Its filename is
mm-gup-track-foll_pin-pages-fix-2.patchThis appears to be causing a build failure in
mm/gup.c, in mmotm, as of today anyway:
Quoted 6 lines
commit
5d9ee416b570("pci: test for unexpectedly disabled
bridges")I vaguely recall reviewing an earlier version that moved
put_compound_head()up higher ingup.c, in order to avoid this. In
yes, that is what I had sent
Quoted 2 lines
any case, that's what this needs in order to build. Sorry for missing it in the review.
I don't think you missed it, because the patch I sent out to be squashed did move it up
Quoted 1 line
Claudio, did you compile-test the patch? I'm not sure how this made
not only compile tested, I even actually tested-tested it.
Quoted 6 lines
it all the way to mmotm without it triggering something, either, but I can't see anything obviously wrong with my tree, which has no local changes applied.
Here's what I'm seeing, and it makes sense because
put_compound_head()is actually at line 2323:
the patch I had sent out did move put_compound_head to around line 116
Quoted 14 lines
mm/gup.c: In function ‘gup_pte_range’:mm/gup.c:2177:4: error: implicit declaration of function ‘put_compound_head’; did you mean ‘set_compound_head’? [-Werror=implicit-function-declaration] 2177 |put_compound_head(head, 1, flags); | ^~~~~~~~~~~~~~~~~ |set_compound_headmm/gup.c: At top level:mm/gup.c:2323:13: warning: conflicting types for ‘put_compound_head’
2323 | static void put_compound_head(struct page *page, int refs,
unsigned int flags) | ^~~~~~~~~~~~~~~~~mm/gup.c:2323:13: error: static declaration of ‘put_compound_head’ follows non-static declarationmm/gup.c:2177:4: note: previous implicit declaration of ‘put_compound_head’ was here 2177 |put_compound_head(head, 1, flags); | ^~~~~~~~~~~~~~~~~
Quoted 1 line
And here's a compile-tested (only) proposed fix:
I think the most appropriate place would be right after try_grab_compound_head, which is where I had put it.
Quoted 70 lines
mm/gup.c +14
-0@@ -2116,6 +2116,28 @@ static inline pte_t gup_get_pte(pte_t *ptep) }#endif /* CONFIG_GUP_GET_PTE_LOW_HIGH */ +static void put_compound_head (struct page *page,int refs,unsigned int flags) +{ +if (flags &FOLL_PIN ) { +mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED , + refs); + +if (hpage_pincount_available (page)) +hpage_pincount_sub (page, refs); +else + refs *=GUP_PIN_COUNTING_BIAS ; + } + +VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); +/* +* Calling put_page() for each ref is unnecessarily slow. Only the last
mm/gup.c +7
-14+* ref needs a put_page(). +*/ +if (refs >1 ) +page_ref_sub (page, refs -1 ); +put_page (page); +} +static void __maybe_unused undo_dev_pagemap (int *nr,int nr_start,unsigned int flags,struct page **pages)@@ -2320,28 +2342,6 @@ static int record_subpages(struct page *page, unsigned long addr, return nr; } -static void put_compound_head (struct page *page,int refs,unsigned int flags) -{ -if (flags &FOLL_PIN ) { -mod_node_page_state (page_pgdat (page), NR_FOLL_PIN_RELEASED, - refs); - -if (hpage_pincount_available (page)) -hpage_pincount_sub (page, refs); -else - refs *=GUP_PIN_COUNTING_BIAS ; - } - -VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); -/* -* Calling put_page() for each ref is unnecessarily slow. Only the last
mm/gup.c +0
-7-* ref needs a put_page(). -*/ -if (refs >1 ) -page_ref_sub (page, refs -1 ); -put_page (page); -} -#ifdef CONFIG_ARCH_HAS_HUGEPD static unsigned long hugepte_addr_end(unsigned long addr, unsignedlong end, unsigned long sz)
thanks,
John Hubbard
reviewerRe: + mm-gup-track-foll_pin-pages-fix-2.patch added to -mm tree
Quoted 26 lines · Claudio Imbrenda
Quoted 11 lines · On Tue, 10 Mar 2020 18:46:40 -0700 John Hubbard <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
The patch titled
Subject: mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track
FOLL_PINpages" has been added to the -mm tree. Its filename is
mm-gup-track-foll_pin-pages-fix-2.patchThis appears to be causing a build failure in
mm/gup.c, in mmotm, as of today anyway:Quoted 6 lines
commit
5d9ee416b570("pci: test for unexpectedly disabled
bridges")I vaguely recall reviewing an earlier version that moved
put_compound_head()up higher ingup.c, in order to avoid this. Inyes, that is what I had sent
Quoted 2 lines
any case, that's what this needs in order to build. Sorry for missing it in the review.
Quoted 6 lines
I don't think you missed it, because the patch I sent out to be squashed did move it up
Quoted 1 line
Claudio, did you compile-test the patch? I'm not sure how this made
not only compile tested, I even actually tested-tested it.
Andrew, do you want Claudio to resend that patch? It seems like part of it got lost, somehow.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Andrew Morton
maintainerRe: + mm-gup-track-foll_pin-pages-fix-2.patch added to -mm tree
In reply to Claudio ImbrendaQuoted 5 lines · On Wed, 11 Mar 2020 11:13:52 +0100 Claudio Imbrenda <[email protected]>…
Quoted 2 lines
any case, that's what this needs in order to build. Sorry for missing it in the review.
I don't think you missed it, because the patch I sent out to be squashed did move it up
<figures out what happened>
hm, OK,
http://lkml.kernel.org/r/[email protected]
is billed as a fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages" but it actually applies after everything else. I messed up untangling this.
Redone, should be OK now.
+ mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup/writeback: add callbacks for inaccessible pages has been added to the -mm tree. Its filename is mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
The patch titled
Subject: mm/gup/writeback: add callbacks for inaccessible pages
has been added to the -mm tree. Its filename is
mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Claudio Imbrenda <[email protected]>
Subject: mm/gup/writeback: add callbacks for inaccessible pages
With the introduction of protected KVM guests on s390 there is now a concept of inaccessible pages. These pages need to be made accessible before the host can access them.
While cpu accesses will trigger a fault that can be resolved, I/O accesses will just fail. We need to add a callback into architecture code for places that will do I/O, namely when writeback is started or when a page reference is taken.
This is not only to enable paging, file backing etc, it is also necessary to protect the host against a malicious user space. For example a bad QEMU could simply start direct I/O on such protected memory. We do not want userspace to be able to trigger I/O errors and thus the logic is "whenever somebody accesses that page (gup) or does I/O, make sure that this page can be accessed". When the guest tries to access that page we will wait in the page fault handler for writeback to have finished and for the page_ref to be the expected value.
On s390x the function is not supposed to fail, so it is ok to use a WARN_ON on failure. If we ever need some more finegrained handling we can tackle this when we know the details.
---
include/linux/gfp.h | 6 ++++++ mm/gup.c | 30 +++++++++++++++++++++++++++--- mm/page-writeback.c | 9 ++++++++- 3 files changed, 41 insertions(+), 4 deletions(-)
include/linux/gfp.h renamed from include/linux/gfp.h~mm-gup-writeback-add-callbacks-for-inaccessible-pages +6 -0
@@ -485,6 +485,12 @@ static inline void arch_free_page(struct#ifndef HAVE_ARCH_ALLOC_PAGE static inline void arch_alloc_page (struct page *page,int order) { }#endif +#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +static inline int arch_make_page_accessible (struct page *page) +{ +return 0 ; +} +#endif struct page * __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
mm/gup.c renamed from mm/gup.c~mm-gup-writeback-add-callbacks-for-inaccessible-pages +27 -3
@@ -390,6 +390,7 @@ static struct page *follow_page_pte(strustruct page *page;spinlock_t *ptl;pte_t *ptep, pte; +int ret;/* FOLL_GET and FOLL_PIN are mutually exclusive. */ if (WARN_ON_ONCE((flags & (FOLL_PIN | FOLL_GET)) ==
@@ -448,8 +449,6 @@ retry:if (is_zero_pfn (pte_pfn (pte))) { page =pte_page (pte); }else { -int ret; - ret =follow_pfn_pte (vma, address, ptep, flags); page =ERR_PTR (ret); goto out;
@@ -457,7 +456,6 @@ retry: }if (flags &FOLL_SPLIT &&PageTransCompound (page)) { -int ret;get_page (page);pte_unmap_unlock (ptep, ptl);lock_page (page);
@@ -474,6 +472,19 @@ retry: page =ERR_PTR (-ENOMEM ); goto out; } +/* +* We need to make the page accessible if and only if we are going +* to access its content (the FOLL_PIN case). Please see +* Documentation/core-api/pin_user_pages.rst for details. +*/ +if (flags &FOLL_PIN ) { + ret =arch_make_page_accessible (page); +if (ret) { +unpin_user_page (page); + page =ERR_PTR (ret); + goto out; + } + }if (flags &FOLL_TOUCH ) {if ((flags &FOLL_WRITE ) && !pte_dirty (pte) && !PageDirty (page))
@@ -2139,6 +2150,19 @@ static int gup_pte_range(pmd_t pmd, unsiVM_BUG_ON_PAGE (compound_head (page) != head, page); +/* +* We need to make the page accessible if and only if we are +* going to access its content (the FOLL_PIN case). Please +* see Documentation/core-api/pin_user_pages.rst for +* details. +*/ +if (flags &FOLL_PIN ) { + ret =arch_make_page_accessible (page); +if (ret) { +unpin_user_page (page); + goto pte_unmap; + } + }SetPageReferenced (page); pages[*nr] = page; (*nr)++;
mm/page-writeback.c renamed from mm/page-writeback.c~mm-gup-writeback-add-callbacks-for-inaccessible-pages +8 -1
@@ -2764,7 +2764,7 @@ int test_clear_page_writeback(struct pagint __test_set_page_writeback (struct page *page,bool keep_write) {struct address_space *mapping =page_mapping (page); -int ret; +int ret, access_ret;lock_page_memcg (page);if (mapping &&mapping_use_writeback_tags (mapping)) {
@@ -2807,6 +2807,13 @@ int __test_set_page_writeback(struct paginc_zone_page_state (page,NR_ZONE_WRITE_PENDING ); }unlock_page_memcg (page); + access_ret =arch_make_page_accessible (page); +/* +* If writeback has been triggered on a page that cannot be made +* accessible, it is too late to recover here. +*/ +VM_BUG_ON_PAGE (access_ret !=0 , page); +return ret; }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-track-foll_pin-pages-fix-2.patch mm-gup-writeback-add-callbacks-for-inaccessible-pages.patch
+ mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/sparse.c: use macros instead of open-coding has been added to the -mm tree. Its filename is mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch
The patch titled
Subject: mm/sparse.c: use macros instead of open-coding
has been added to the -mm tree. Its filename is
mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: chenqiwu <[email protected]>
Subject: mm/sparse.c: use macros instead of open-coding
Use macros instead of open-coding for better code readability.
---
mm/sparse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/sparse.c renamed from mm/sparse.c~mm-sparsemem-use-wrapped-macros-instead-of-open-coding +3 -3
@@ -385,8 +385,8 @@ static void __init check_usemap_section_ old_pgdat_snr =NR_MEM_SECTIONS ; } - usemap_snr =pfn_to_section_nr (__pa (usage) >>PAGE_SHIFT ); - pgdat_snr =pfn_to_section_nr (__pa (pgdat) >>PAGE_SHIFT ); + usemap_snr =pfn_to_section_nr (virt_to_pfn (usage)); + pgdat_snr =pfn_to_section_nr (virt_to_pfn (pgdat));if (usemap_snr == pgdat_snr)return ;
@@ -677,7 +677,7 @@ struct page * __meminit populate_sectionreturn NULL ; got_map_page: - ret = (struct page *)pfn_to_kaddr (page_to_pfn (page)); + ret = (struct page *)page_to_virt (page); got_map_ptr:return ret;
_
Patches currently in -mm which might be from [email protected] are
mm-slubc-replace-cpu_slab-partial-with-wrapped-apis.patch mm-slubc-replace-kmem_cache-cpu_partial-with-wrapped-apis.patch mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch mm-fix-ambiguous-comments-for-better-code-readability.patch lib-rbtree-fix-coding-style-of-assignments.patch
+ checkpatch-check-proper-licensing-of-devicetree-bindings.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: checkpatch: check proper licensing of Devicetree bindings has been added to the -mm tree. Its filename is checkpatch-check-proper-licensing-of-devicetree-bindings.patch
The patch titled
Subject: checkpatch: check proper licensing of Devicetree bindings
has been added to the -mm tree. Its filename is
checkpatch-check-proper-licensing-of-devicetree-bindings.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/checkpatch-check-proper-licensing-of-devicetree-bindings.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/checkpatch-check-proper-licensing-of-devicetree-bindings.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Lubomir Rintel <[email protected]>
Subject: checkpatch: check proper licensing of Devicetree bindings
According to Devicetree maintainers (see Link: below), the Devicetree binding documents are preferrably licensed (GPL-2.0-only OR BSD-2-Clause).
Let's check that. The actual check is a bit more relaxed, to allow more liberal but compatible licensing (e.g. GPL-2.0-or-later OR BSD-2-Clause).
---
scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-check-proper-licensing-of-devicetree-bindings +11 -0
@@ -3171,6 +3171,17 @@ sub process { WARN("SPDX_LICENSE_TAG", "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr); } + if ($realfile =~ m@^Documentation/devicetree/bindings/@ && + not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) { + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + if (&{$msg_level}("SPDX_LICENSE_TAG", + + "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/; + } + } } } }
_
Patches currently in -mm which might be from [email protected] are
checkpatch-check-spdx-tags-in-yaml-files.patch checkpatch-check-proper-licensing-of-devicetree-bindings.patch
+ kcov-cleanup-debug-messages.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kcov: clean up debug messages has been added to the -mm tree. Its filename is kcov-cleanup-debug-messages.patch
The patch titled
Subject: kcov: clean up debug messages
has been added to the -mm tree. Its filename is
kcov-cleanup-debug-messages.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/kcov-cleanup-debug-messages.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/kcov-cleanup-debug-messages.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrey Konovalov <[email protected]>
Subject: kcov: clean up debug messages
Patch series "kcov: collect coverage from usb soft interrupts", v2.
This patchset extends kcov to allow collecting coverage from soft interrupts and then uses the new functionality to collect coverage from USB code.
This has allowed to find at least one new HID bug [1], which was recently fixed by Alan [2].
[1] https://syzkaller.appspot.com/bug?extid=09ef48aa58261464b621
[2] https://patchwork.kernel.org/patch/11283319/
Any subsystem that uses softirqs (e.g. timers) can make use of this in the future. Looking at the recent syzbot reports, an obvious candidate is the networking subsystem [3, 4, 5 and many more].
[3] https://syzkaller.appspot.com/bug?extid=522ab502c69badc66ab7
[4] https://syzkaller.appspot.com/bug?extid=57f89d05946c53dbbb31
[5] https://syzkaller.appspot.com/bug?extid=df358e65d9c1b9d3f5f4
This patch (of 3):
Previous commit left a lot of excessive debug messages, clean them up.
---
kernel/kcov.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-)
kernel/kcov.c renamed from kernel/kcov.c~kcov-cleanup-debug-messages +2 -20
@@ -98,6 +98,7 @@ static struct kcov_remote *kcov_remote_freturn NULL ; } +/* Must be called with kcov_remote_lock locked. */ static struct kcov_remote *kcov_remote_add (struct kcov *kcov,u64 handle) {struct kcov_remote *remote;
@@ -119,16 +120,13 @@ static struct kcov_remote_area *kcov_remstruct kcov_remote_area *area;struct list_head *pos; -kcov_debug ("size = %u\n" , size);list_for_each (pos, &kcov_remote_areas) { area = list_entry(pos, struct kcov_remote_area, list);if (area->size == size) {list_del (&area->list); -kcov_debug ("rv = %px\n" , area);return area; } } -kcov_debug ("rv = NULL\n" );return NULL ; }
@@ -136,7 +134,6 @@ static struct kcov_remote_area *kcov_remstatic void kcov_remote_area_put (struct kcov_remote_area *area,unsigned int size) { -kcov_debug ("area = %px, size = %u\n" , area, size);INIT_LIST_HEAD (&area->list); area->size = size;list_add (&area->list, &kcov_remote_areas);
@@ -366,7 +363,6 @@ static void kcov_remote_reset(struct kcohash_for_each_safe (kcov_remote_map, bkt, tmp, remote, hnode) {if (remote->kcov != kcov)continue ; -kcov_debug ("removing handle %llx\n" , remote->handle);hash_del (&remote->hnode);kfree (remote); }
@@ -553,7 +549,6 @@ static int kcov_ioctl_locked(struct kcovswitch (cmd) {case KCOV_INIT_TRACE : -kcov_debug ("KCOV_INIT_TRACE\n" );/* * Enable kcov in trace mode and setup buffer size. * Must happen before anything else.
@@ -572,7 +567,6 @@ static int kcov_ioctl_locked(struct kcov kcov->mode =KCOV_MODE_INIT ;return 0 ;case KCOV_ENABLE : -kcov_debug ("KCOV_ENABLE\n" );/* * Enable coverage for the current task. * At this point user must have been enabled trace mode,
@@ -598,7 +592,6 @@ static int kcov_ioctl_locked(struct kcovkcov_get (kcov);return 0 ;case KCOV_DISABLE : -kcov_debug ("KCOV_DISABLE\n" );/* Disable coverage for the current task. */ unused = arg;if (unused !=0 || current->kcov != kcov)
@@ -610,7 +603,6 @@ static int kcov_ioctl_locked(struct kcovkcov_put (kcov);return 0 ;case KCOV_REMOTE_ENABLE : -kcov_debug ("KCOV_REMOTE_ENABLE\n" );if (kcov->mode !=KCOV_MODE_INIT || !kcov->area)return -EINVAL ; t = current;
@@ -629,7 +621,6 @@ static int kcov_ioctl_locked(struct kcov kcov->remote_size = remote_arg->area_size;spin_lock (&kcov_remote_lock);for (i =0 ; i < remote_arg->num_handles; i++) { -kcov_debug ("handle %llx\n" , remote_arg->handles[i]);if (!kcov_check_handle (remote_arg->handles[i], false, true, false)) {spin_unlock (&kcov_remote_lock);
@@ -644,8 +635,6 @@ static int kcov_ioctl_locked(struct kcov } }if (remote_arg->common_handle) { -kcov_debug ("common handle %llx\n" , - remote_arg->common_handle);if (!kcov_check_handle (remote_arg->common_handle, true, false, false)) {spin_unlock (&kcov_remote_lock);
@@ -782,7 +771,6 @@ void kcov_remote_start(u64 handle)spin_lock (&kcov_remote_lock); remote =kcov_remote_find (handle);if (!remote) { -kcov_debug ("no remote found" );spin_unlock (&kcov_remote_lock);return ; }
@@ -810,8 +798,6 @@ void kcov_remote_start(u64 handle)/* Reset coverage size. */ *(u64 *)area =0 ; -kcov_debug ("area = %px, size = %u" , area, size); -kcov_start (t, size, area, mode, sequence); }
@@ -881,10 +867,8 @@ void kcov_remote_stop(void)unsigned int size = t->kcov_size;int sequence = t->kcov_sequence; -if (!kcov) { -kcov_debug ("no kcov found\n" ); +if (!kcov)return ; - }kcov_stop (t); t->kcov =NULL ;
@@ -894,8 +878,6 @@ void kcov_remote_stop(void)* KCOV_DISABLE could have been called between kcov_remote_start() * and kcov_remote_stop(), hence the check. */ -kcov_debug ("move if: %d == %d && %d\n" , - sequence, kcov->sequence, (int )kcov->remote);if (sequence == kcov->sequence && kcov->remote)kcov_move_area (kcov->mode, kcov->area, kcov->size, area);spin_unlock (&kcov->lock);
_
Patches currently in -mm which might be from [email protected] are
kcov-cleanup-debug-messages.patch kcov-collect-coverage-from-interrupts.patch usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
+ kcov-collect-coverage-from-interrupts.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kcov: collect coverage from interrupts has been added to the -mm tree. Its filename is kcov-collect-coverage-from-interrupts.patch
The patch titled
Subject: kcov: collect coverage from interrupts
has been added to the -mm tree. Its filename is
kcov-collect-coverage-from-interrupts.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/kcov-collect-coverage-from-interrupts.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/kcov-collect-coverage-from-interrupts.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrey Konovalov <[email protected]>
Subject: kcov: collect coverage from interrupts
This change extends kcov remote coverage support to allow collecting coverage from soft interrupts in addition to kernel background threads.
To collect coverage from code that is executed in softirq context, a part of that code has to be annotated with kcov_remote_start/stop() in a similar way as how it is done for global kernel background threads. Then the handle used for the annotations has to be passed to the KCOV_REMOTE_ENABLE ioctl.
Internally this patch adjusts the __sanitizer_cov_trace_pc() compiler inserted callback to not bail out when called from softirq context. kcov_remote_start/stop() are updated to save/restore the current per task kcov state in a per-cpu area (in case the softirq came when the kernel was already collecting coverage in task context). Coverage from softirqs is collected into pre-allocated per-cpu areas, whose size is controlled by the new CONFIG_KCOV_IRQ_AREA_SIZE.
---
Documentation/dev-tools/kcov.rst | 17 +- include/linux/sched.h | 3 kernel/kcov.c | 203 ++++++++++++++++++++++------- lib/Kconfig.debug | 9 + 4 files changed, 175 insertions(+), 57 deletions(-)
Documentation/dev-tools/kcov.rst renamed from Documentation/dev-tools/kcov.rst~kcov-collect-coverage-from-interrupts +9 -8
@@ -217,14 +217,15 @@ This allows to collect coverage from two threads: the global ones, that are spawned during kernel boot in a limited number of instances (e.g. one USB hub_event() worker thread is spawned per USB HCD); and the local ones, that are spawned when a user interacts with -some kernel interface (e.g. vhost workers). +some kernel interface (e.g. vhost workers); as well as from soft +interrupts. -To enable collecting coverage from a global background thread, a unique -global handle must be assigned and passed to the corresponding -kcov_remote_start() call. Then a userspace process can pass a list of such -handles to the KCOV_REMOTE_ENABLE ioctl in the handles array field of the -kcov_remote_arg struct. This will attach the used kcov device to the code -sections, that are referenced by those handles. +To enable collecting coverage from a global background thread or from a +softirq, a unique global handle must be assigned and passed to the +corresponding kcov_remote_start() call. Then a userspace process can pass +a list of such handles to the KCOV_REMOTE_ENABLE ioctl in the handles +array field of the kcov_remote_arg struct. This will attach the used kcov +device to the code sections, that are referenced by those handles. Since there might be many local background threads spawned from different userspace processes, we can't use a single global handle per annotation.
@@ -242,7 +243,7 @@ handles as they don't belong to a partic currently reserved and must be zero. In the future the number of bytes used for the subsystem or handle ids might be increased. -When a particular userspace proccess collects coverage by via a common +When a particular userspace proccess collects coverage via a common handle, kcov will collect coverage for each code section that is annotated to use the common handle obtained as kcov_handle from the current task_struct. However non common handles allow to collect coverage
include/linux/sched.h renamed from include/linux/sched.h~kcov-collect-coverage-from-interrupts +3 -0
@@ -1230,6 +1230,9 @@ struct task_struct {/* KCOV sequence number: */ int kcov_sequence; + +/* Collect coverage from softirq context: */ +bool kcov_softirq;#endif #ifdef CONFIG_MEMCG
kernel/kcov.c renamed from kernel/kcov.c~kcov-collect-coverage-from-interrupts +154 -49
434 lines not on this page · raw message
lib/Kconfig.debug renamed from lib/Kconfig.debug~kcov-collect-coverage-from-interrupts +9 -0
@@ -1758,6 +1758,15 @@ config KCOV_INSTRUMENT_ALL filesystem fuzzing with AFL) then you will want to enable coverage for more specific subsets of files, and should say n here. +config KCOV_IRQ_AREA_SIZE + hex "Size of interrupt coverage collection area in words" + depends on KCOV + default 0x40000 + help + KCOV uses preallocated per-cpu areas to collect coverage from + soft interrupts. This specifies the size of those areas in the + number of unsigned long words. + menuconfig RUNTIME_TESTING_MENU bool "Runtime Testing" def_bool y
_
Patches currently in -mm which might be from [email protected] are
kcov-cleanup-debug-messages.patch kcov-collect-coverage-from-interrupts.patch usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
+ usb-core-kcov-collect-coverage-from-usb-complete-callback.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: usb: core: kcov: collect coverage from usb complete callback has been added to the -mm tree. Its filename is usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
The patch titled
Subject: usb: core: kcov: collect coverage from usb complete callback
has been added to the -mm tree. Its filename is
usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrey Konovalov <[email protected]>
Subject: usb: core: kcov: collect coverage from usb complete callback
This patch adds kcov_remote_start/stop() callbacks around the urb complete() callback that is executed in softirq context when dummy_hcd is in use. As the result, kcov can be used to collect coverage from those those callbacks, which is used to facilitate coverage-guided fuzzing with syzkaller.
---
drivers/usb/core/hcd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/hcd.c renamed from drivers/usb/core/hcd.c~usb-core-kcov-collect-coverage-from-usb-complete-callback +3 -0
@@ -31,6 +31,7 @@#include <linux/types.h> #include <linux/genalloc.h> #include <linux/io.h> +#include <linux/kcov.h> #include <linux/phy/phy.h> #include <linux/usb.h>
@@ -1645,7 +1646,9 @@ static void __usb_hcd_giveback_urb(struc/* pass ownership to the completion handler */ urb->status = status; +kcov_remote_start_usb ((u64 )urb->dev->bus->busnum); urb->complete (urb); +kcov_remote_stop ();usb_anchor_resume_wakeups (anchor);atomic_dec (&urb->use_count);
_
Patches currently in -mm which might be from [email protected] are
kcov-cleanup-debug-messages.patch kcov-collect-coverage-from-interrupts.patch usb-core-kcov-collect-coverage-from-usb-complete-callback.patch
+ mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/swap_slots.c: don't reset the cache slot after use has been added to the -mm tree. Its filename is mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch
The patch titled
Subject: mm/swap_slots.c: don't reset the cache slot after use
has been added to the -mm tree. Its filename is
mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Wei Yang <[email protected]>
Subject: mm/swap_slots.c: don't reset the cache slot after use
Currently we clear the cache slot if it is used. While this is not necessary, since this entry would not be used until refilled.
Leave it untouched and assigned the value directly to entry which makes the code little more neat.
Also this patch merges the else and if, since this is the only case we refill and repeat swap cache.
---
mm/swap_slots.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
mm/swap_slots.c renamed from mm/swap_slots.c~mm-swap_slotsc-dont-reset-the-cache-slot-after-use +4 -7
@@ -309,7 +309,7 @@ direct_free:swp_entry_t get_swap_page (struct page *page) { -swp_entry_t entry, *pentry; +swp_entry_t entry;struct swap_slots_cache *cache; entry.val =0 ;
@@ -336,13 +336,10 @@ swp_entry_t get_swap_page(struct page *pif (cache->slots) { repeat:if (cache->nr) { - pentry = &cache->slots[cache->cur++]; - entry = *pentry; - pentry->val =0 ; + entry = cache->slots[cache->cur++]; cache->nr--; - }else { -if (refill_swap_slots_cache (cache)) - goto repeat; + }else if (refill_swap_slots_cache (cache)) { + goto repeat; } }mutex_unlock (&cache->alloc_lock);
_
Patches currently in -mm which might be from [email protected] are
mm-swap_slotsc-dont-reset-the-cache-slot-after-use.patch
+ mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix
has been added to the -mm tree. Its filename is
mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrew Morton <[email protected]>
Subject: mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix
remove unneeded initialization, per David
---
mm/sparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c renamed from mm/sparse.c~mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix +1 -1
@@ -734,7 +734,7 @@ static void section_deactivate(unsignedstruct mem_section *ms =__pfn_to_section (pfn);bool section_is_early =early_section (ms);struct page *memmap =NULL ; -bool empty = false; +bool empty;unsigned long *subsection_map = ms->usage ? &ms->usage->subsection_map[0 ] :NULL ;
_
Patches currently in -mm which might be from [email protected] are
mm-hotplug-fix-hot-remove-failure-in-sparsememvmemmap-case-fix.patch mm.patch memcg-optimize-memorynuma_stat-like-memorystat-fix.patch selftest-add-mremap_dontunmap-selftest-fix.patch selftest-add-mremap_dontunmap-selftest-v7-checkpatch-fixes.patch hugetlb_cgroup-add-reservation-accounting-for-private-mappings-fix.patch hugetlb_cgroup-add-accounting-for-shared-mappings-fix.patch mm-migratec-migrate-pg_readahead-flag-fix.patch proc-faster-open-read-close-with-permanent-files-checkpatch-fixes.patch linux-next-rejects.patch
linux-next-fix.patch
linux-next-git-rejects.patch mm-add-vm_insert_pages-fix.patch net-zerocopy-use-vm_insert_pages-for-tcp-rcv-zerocopy-fix.patch seq_read-info-message-about-buggy-next-functions-fix.patch drivers-tty-serial-sh-scic-suppress-warning.patch kernel-forkc-export-kernel_thread-to-modules.patch
+ linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: linux/bits.h: add compile time sanity check of GENMASK inputs has been added to the -mm tree. Its filename is…
The patch titled
Subject: linux/bits.h: add compile time sanity check of GENMASK inputs
has been added to the -mm tree. Its filename is
linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Rikard Falkeborn <[email protected]>
Subject: linux/bits.h: add compile time sanity check of GENMASK inputs
GENMASK() and GENMASK_ULL() are supposed to be called with the high bit as the first argument and the low bit as the second argument. Mixing them will return a mask with zero bits set.
Recent commits show getting this wrong is not uncommon, see e.g. commit aa4c0c9091b0 ("net: stmmac: Fix misuses of GENMASK macro") and commit 9bdd7bb3a844 ("clocksource/drivers/npcm: Fix misuse of GENMASK macro").
To prevent such mistakes from appearing again, add compile time sanity checking to the arguments of GENMASK() and GENMASK_ULL(). If both arguments are known at compile time, and the low bit is higher than the high bit, break the build to detect the mistake immediately.
Since GENMASK() is used in declarations, BUILD_BUG_ON_ZERO() must be used instead of BUILD_BUG_ON().
__builtin_constant_p does not evaluate is argument, it only checks if it is a constant or not at compile time, and __builtin_choose_expr does not evaluate the expression that is not chosen. Therefore, GENMASK(x++, 0) does only evaluate x++ once.
Commit 95b980d62d52 ("linux/bits.h: make BIT(), GENMASK(), and friends available in assembly") made the macros in linux/bits.h available in assembly. Since BUILD_BUG_OR_ZERO() is not asm compatible, disable the checks if the file is included in an asm file.
Due to bugs in GCC versions before 4.9 [0], disable the check if building with a too old GCC compiler.
[0]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449
---
include/linux/bits.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
include/linux/bits.h renamed from include/linux/bits.h~linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs +20 -2
@@ -18,12 +18,30 @@* position @h. For example * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ -#define GENMASK (h, l) \ +#if !defined(__ASSEMBLY__) && \ + (!defined(CONFIG_CC_IS_GCC ) ||CONFIG_GCC_VERSION >=49000 ) +#include <linux/build_bug.h> +#define GENMASK_INPUT_CHECK (h, l) \ + (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ + __builtin_constant_p((l) > (h)), (l) > (h), 0))) +#else +/* +* BUILD_BUG_ON_ZERO is not available in h files included from asm files, +* disable the input check if that is the case. +*/ +#define GENMASK_INPUT_CHECK (h, l) 0 +#endif + +#define __GENMASK (h, l) \ (((~UL(0)) - (UL(1) << (l)) + 1) & \ (~UL(0) >> (BITS_PER_LONG - 1 - (h)))) +#define GENMASK (h, l) \ + (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) -#define GENMASK_ULL (h, l) \ +#define __GENMASK_ULL (h, l) \ (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) +#define GENMASK_ULL (h, l) \ + (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))#endif /* __LINUX_BITS_H */
_
Patches currently in -mm which might be from [email protected] are
linux-bitsh-add-compile-time-sanity-check-of-genmask-inputs.patch
+ mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/page_alloc.c: use free_area_empty() instead of open-coding has been added to the -mm tree. Its filename is mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch
The patch titled
Subject: mm/page_alloc.c: use free_area_empty() instead of open-coding
has been added to the -mm tree. Its filename is
mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: chenqiwu <[email protected]>
Subject: mm/page_alloc.c: use free_area_empty() instead of open-coding
Use free_area_empty() API to replace list_empty() for better code readability.
---
mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_alloc-use-free_area_empty-instead-of-open-coding +1 -2
@@ -3473,8 +3473,7 @@ bool __zone_watermark_ok(struct zone *z, return true; }#endif -if (alloc_harder && - !list_empty (&area->free_list[MIGRATE_HIGHATOMIC ])) +if (alloc_harder && !free_area_empty (area,MIGRATE_HIGHATOMIC ))return true; }return false;
_
Patches currently in -mm which might be from [email protected] are
mm-slubc-replace-cpu_slab-partial-with-wrapped-apis.patch mm-slubc-replace-kmem_cache-cpu_partial-with-wrapped-apis.patch mm-sparsemem-use-wrapped-macros-instead-of-open-coding.patch mm-page_alloc-use-free_area_empty-instead-of-open-coding.patch mm-fix-ambiguous-comments-for-better-code-readability.patch lib-rbtree-fix-coding-style-of-assignments.patch
+ mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/special: create generic fallbacks for pte_special() and pte_mkspecial() has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm/special: create generic fallbacks for pte_special() and pte_mkspecial()
has been added to the -mm tree. Its filename is
mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Anshuman Khandual <[email protected]>
Subject: mm/special: create generic fallbacks for pte_special() and pte_mkspecial()
Currently there are many platforms that dont enable ARCH_HAS_PTE_SPECIAL but required to define quite similar fallback stubs for special page table entry helpers such as pte_special() and pte_mkspecial(), as they get build in generic MM without a config check. This creates two generic fallback stub definitions for these helpers, eliminating much code duplication.
mips platform has a special case where pte_special() and pte_mkspecial() visibility is wider than what ARCH_HAS_PTE_SPECIAL enablement requires. This restricts those symbol visibility in order to avoid redefinitions which is now exposed through this new generic stubs and subsequent build failure. arm platform set_pte_at() definition needs to be moved into a C file just to prevent a build failure.
---
arch/alpha/include/asm/pgtable.h | 2 arch/arm/include/asm/pgtable-2level.h | 2 arch/arm/include/asm/pgtable.h | 15 ------- arch/arm/mm/mmu.c | 14 ++++++ arch/csky/include/asm/pgtable.h | 3 - arch/hexagon/include/asm/pgtable.h | 2 arch/ia64/include/asm/pgtable.h | 2 arch/m68k/include/asm/mcf_pgtable.h | 10 ---- arch/m68k/include/asm/motorola_pgtable.h | 2 arch/m68k/include/asm/sun3_pgtable.h | 2 arch/microblaze/include/asm/pgtable.h | 4 - arch/mips/include/asm/pgtable.h | 44 ++++++++++++++------- arch/nds32/include/asm/pgtable.h | 9 ---- arch/nios2/include/asm/pgtable.h | 3 - arch/openrisc/include/asm/pgtable.h | 2 arch/parisc/include/asm/pgtable.h | 2 arch/sparc/include/asm/pgtable_32.h | 7 --- arch/um/include/asm/pgtable.h | 10 ---- arch/unicore32/include/asm/pgtable.h | 3 - arch/xtensa/include/asm/pgtable.h | 3 - include/linux/mm.h | 12 +++++ 21 files changed, 58 insertions(+), 95 deletions(-)
arch/alpha/include/asm/pgtable.h renamed from arch/alpha/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -268,7 +268,6 @@ extern inline void pud_clear(pud_t * pudextern inline int pte_write (pte_t pte) {return !(pte_val (pte) & _PAGE_FOW); }extern inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }extern inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } -extern inline int pte_special (pte_t pte) {return 0 ; }extern inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) |= _PAGE_FOW;return pte; }extern inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~(__DIRTY_BITS);return pte; }
@@ -276,7 +275,6 @@ extern inline pte_t pte_mkold(pte_t pte)extern inline pte_t pte_mkwrite (pte_t pte) {pte_val (pte) &= ~_PAGE_FOW;return pte; }extern inline pte_t pte_mkdirty (pte_t pte) {pte_val (pte) |= __DIRTY_BITS;return pte; }extern inline pte_t pte_mkyoung (pte_t pte) {pte_val (pte) |= __ACCESS_BITS;return pte; } -extern inline pte_t pte_mkspecial (pte_t pte) {return pte; }#define PAGE_DIR_OFFSET (tsk,address) pgd_offset((tsk),(address))
arch/arm/include/asm/pgtable-2level.h renamed from arch/arm/include/asm/pgtable-2level.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -211,8 +211,6 @@ static inline pmd_t *pmd_offset(pud_t *p#define pmd_addr_end (addr,end) (end)#define set_pte_ext (ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext) -#define pte_special (pte) (0) -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }/* * We don't have huge page support for short descriptors, for the moment
arch/arm/include/asm/pgtable.h renamed from arch/arm/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +2 -13
@@ -252,19 +252,8 @@ static inline void __sync_icache_dcache(extern void __sync_icache_dcache (pte_t pteval);#endif -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) -{ -unsigned long ext =0 ; - -if (addr <TASK_SIZE &&pte_valid_user (pteval)) { -if (!pte_special (pteval)) -__sync_icache_dcache (pteval); - ext |=PTE_EXT_NG ; - } - -set_pte_ext (ptep, pteval, ext); -} +void set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval);static inline pte_t clear_pte_bit (pte_t pte,pgprot_t prot) {
arch/arm/mm/mmu.c renamed from arch/arm/mm/mmu.c~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +14 -0
@@ -1672,3 +1672,17 @@ void __init early_mm_init(const struct mbuild_mem_type_table ();early_paging_init (mdesc); } + +void set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval) +{ +unsigned long ext =0 ; + +if (addr <TASK_SIZE &&pte_valid_user (pteval)) { +if (!pte_special (pteval)) +__sync_icache_dcache (pteval); + ext |=PTE_EXT_NG ; + } + +set_pte_ext (ptep, pteval, ext); +}
arch/csky/include/asm/pgtable.h renamed from arch/csky/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -3
@@ -110,9 +110,6 @@ extern unsigned long empty_zero_page[PAGextern void load_pgd (unsigned long pg_dir);extern pte_t invalid_pte_table[PTRS_PER_PTE ]; -static inline int pte_special (pte_t pte) {return 0 ; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; } -static inline void set_pte (pte_t *p,pte_t pte) { *p = pte;
arch/hexagon/include/asm/pgtable.h renamed from arch/hexagon/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -158,8 +158,6 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD/* Seems to be zero even in architectures where the zero page is firewalled? */ #define FIRST_USER_ADDRESS 0UL -#define pte_special (pte) 0 -#define pte_mkspecial (pte) (pte)/* HUGETLB not working currently */ #ifdef CONFIG_HUGETLB_PAGE
arch/ia64/include/asm/pgtable.h renamed from arch/ia64/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -298,7 +298,6 @@ extern unsigned long VMALLOC_END;#define pte_exec (pte) ((pte_val(pte) & _PAGE_AR_RX) != 0)#define pte_dirty (pte) ((pte_val(pte) & _PAGE_D) != 0)#define pte_young (pte) ((pte_val(pte) & _PAGE_A) != 0) -#define pte_special (pte) 0/* * Note: we convert AR_RWX to AR_RX and AR_RW to AR_R by clearing the 2nd bit in the
@@ -311,7 +310,6 @@ extern unsigned long VMALLOC_END;#define pte_mkclean (pte) (__pte(pte_val(pte) & ~_PAGE_D))#define pte_mkdirty (pte) (__pte(pte_val(pte) | _PAGE_D))#define pte_mkhuge (pte) (__pte(pte_val(pte))) -#define pte_mkspecial (pte) (pte)/* * Because ia64's Icache and Dcache is not coherent (on a cpu), we need to
arch/m68k/include/asm/mcf_pgtable.h renamed from arch/m68k/include/asm/mcf_pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -10
@@ -235,11 +235,6 @@ static inline int pte_young(pte_t pte)return pte_val (pte) &CF_PAGE_ACCESSED ; } -static inline int pte_special (pte_t pte) -{ -return 0 ; -} -static inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) &= ~CF_PAGE_WRITABLE ;
@@ -312,11 +307,6 @@ static inline pte_t pte_mkcache(pte_t ptreturn pte; } -static inline pte_t pte_mkspecial (pte_t pte) -{ -return pte; -} -#define swapper_pg_dir kernel_pg_dirextern pgd_t kernel_pg_dir[PTRS_PER_PGD ];
arch/m68k/include/asm/motorola_pgtable.h renamed from arch/m68k/include/asm/motorola_pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -174,7 +174,6 @@ static inline void pud_set(pud_t *pudp,static inline int pte_write (pte_t pte) {return !(pte_val (pte) & _PAGE_RONLY); }static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } -static inline int pte_special (pte_t pte) {return 0 ; }static inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) |= _PAGE_RONLY;return pte; }static inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~_PAGE_DIRTY;return pte; }
@@ -192,7 +191,6 @@ static inline pte_t pte_mkcache(pte_t ptpte_val (pte) = (pte_val (pte) & _CACHEMASK040) | m68k_supervisor_cachemode;return pte; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }#define PAGE_DIR_OFFSET (tsk,address) pgd_offset((tsk),(address))
arch/m68k/include/asm/sun3_pgtable.h renamed from arch/m68k/include/asm/sun3_pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -155,7 +155,6 @@ static inline void pmd_clear (pmd_t *pmdstatic inline int pte_write (pte_t pte) {return pte_val (pte) &SUN3_PAGE_WRITEABLE ; }static inline int pte_dirty (pte_t pte) {return pte_val (pte) &SUN3_PAGE_MODIFIED ; }static inline int pte_young (pte_t pte) {return pte_val (pte) &SUN3_PAGE_ACCESSED ; } -static inline int pte_special (pte_t pte) {return 0 ; }static inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) &= ~SUN3_PAGE_WRITEABLE ;return pte; }static inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~SUN3_PAGE_MODIFIED ;return pte; }
@@ -168,7 +167,6 @@ static inline pte_t pte_mknocache(pte_t//static inline pte_t pte_mkcache(pte_t pte) { pte_val(pte) &= SUN3_PAGE_NOCACHE; return pte; } // until then, use: static inline pte_t pte_mkcache (pte_t pte) {return pte; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];extern pgd_t kernel_pg_dir[PTRS_PER_PGD ];
arch/microblaze/include/asm/pgtable.h renamed from arch/microblaze/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -4
@@ -77,10 +77,6 @@ extern pte_t *va_to_pte(unsigned long ad* Undefined behaviour if not.. */ -static inline int pte_special (pte_t pte) {return 0 ; } - -static inline pte_t pte_mkspecial (pte_t pte) {return pte; } -/* Start and end of the vmalloc area. */ /* Make sure to map the vmalloc area above the pinned kernel memory area of 32Mb. */
arch/mips/include/asm/pgtable.h renamed from arch/mips/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +30 -14
72 lines not on this page · raw message
arch/nds32/include/asm/pgtable.h renamed from arch/nds32/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -9
@@ -286,15 +286,6 @@ PTE_BIT_FUNC(mkclean, &=~_PAGE_D); PTE_BIT_FUNC(mkdirty, |=_PAGE_D); PTE_BIT_FUNC(mkold, &=~_PAGE_YOUNG); PTE_BIT_FUNC(mkyoung, |=_PAGE_YOUNG); -static inline int pte_special (pte_t pte) -{ -return 0 ; -} - -static inline pte_t pte_mkspecial (pte_t pte) -{ -return pte; -}/* * Mark the prot value as uncacheable and unbufferable.
arch/nios2/include/asm/pgtable.h renamed from arch/nios2/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -3
@@ -113,7 +113,6 @@ static inline int pte_dirty(pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) \ {return pte_val (pte) & _PAGE_ACCESSED; } -static inline int pte_special (pte_t pte) {return 0 ; }#define pgprot_noncached pgprot_noncached
@@ -168,8 +167,6 @@ static inline pte_t pte_mkdirty(pte_t ptreturn pte; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; } -static inline pte_t pte_mkyoung (pte_t pte) {pte_val (pte) |= _PAGE_ACCESSED;
arch/openrisc/include/asm/pgtable.h renamed from arch/openrisc/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -236,8 +236,6 @@ static inline int pte_write(pte_t pte) {static inline int pte_exec (pte_t pte) {return pte_val (pte) & _PAGE_EXEC; }static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } -static inline int pte_special (pte_t pte) {return 0 ; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }static inline pte_t pte_wrprotect (pte_t pte) {
arch/parisc/include/asm/pgtable.h renamed from arch/parisc/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -2
@@ -377,7 +377,6 @@ static inline void pud_clear(pud_t *pud)static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; }static inline int pte_write (pte_t pte) {return pte_val (pte) & _PAGE_WRITE; } -static inline int pte_special (pte_t pte) {return 0 ; }static inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~_PAGE_DIRTY;return pte; }static inline pte_t pte_mkold (pte_t pte) {pte_val (pte) &= ~_PAGE_ACCESSED;return pte; }
@@ -385,7 +384,6 @@ static inline pte_t pte_wrprotect(pte_tstatic inline pte_t pte_mkdirty (pte_t pte) {pte_val (pte) |= _PAGE_DIRTY;return pte; }static inline pte_t pte_mkyoung (pte_t pte) {pte_val (pte) |= _PAGE_ACCESSED;return pte; }static inline pte_t pte_mkwrite (pte_t pte) {pte_val (pte) |= _PAGE_WRITE;return pte; } -static inline pte_t pte_mkspecial (pte_t pte) {return pte; }/* * Huge pte definitions.
arch/sparc/include/asm/pgtable_32.h renamed from arch/sparc/include/asm/pgtable_32.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -7
@@ -223,11 +223,6 @@ static inline int pte_young(pte_t pte)return pte_val (pte) &SRMMU_REF ; } -static inline int pte_special (pte_t pte) -{ -return 0 ; -} -static inline pte_t pte_wrprotect (pte_t pte) {return __pte (pte_val (pte) & ~SRMMU_WRITE );
@@ -258,8 +253,6 @@ static inline pte_t pte_mkyoung(pte_t ptreturn __pte (pte_val (pte) |SRMMU_REF ); } -#define pte_mkspecial (pte) (pte) -#define pfn_pte (pfn, prot) mk_pte(pfn_to_page(pfn), prot)static inline unsigned long pte_pfn (pte_t pte)
arch/um/include/asm/pgtable.h renamed from arch/um/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -10
@@ -167,11 +167,6 @@ static inline int pte_newprot(pte_t pte)return (pte_present (pte) && (pte_get_bits (pte, _PAGE_NEWPROT))); } -static inline int pte_special (pte_t pte) -{ -return 0 ; -} -/* * ================================= * Flags setting section.
@@ -247,11 +242,6 @@ static inline pte_t pte_mknewpage(pte_treturn (pte); } -static inline pte_t pte_mkspecial (pte_t pte) -{ -return (pte); -} -static inline void set_pte (pte_t *pteptr,pte_t pteval) {pte_copy (*pteptr, pteval);
arch/unicore32/include/asm/pgtable.h renamed from arch/unicore32/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -3
@@ -177,7 +177,6 @@ extern struct page *empty_zero_page;#define pte_dirty (pte) (pte_val(pte) & PTE_DIRTY)#define pte_young (pte) (pte_val(pte) & PTE_YOUNG)#define pte_exec (pte) (pte_val(pte) & PTE_EXEC) -#define pte_special (pte) (0)#define PTE_BIT_FUNC (fn, op) \ static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; }
@@ -189,8 +188,6 @@ PTE_BIT_FUNC(mkdirty, |= PTE_DIRTY); PTE_BIT_FUNC(mkold, &= ~PTE_YOUNG); PTE_BIT_FUNC(mkyoung, |= PTE_YOUNG); -static inline pte_t pte_mkspecial (pte_t pte) {return pte; } -/* * Mark the prot value as uncacheable. */
arch/xtensa/include/asm/pgtable.h renamed from arch/xtensa/include/asm/pgtable.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +0 -3
@@ -266,7 +266,6 @@ static inline void paging_init(void) { }static inline int pte_write (pte_t pte) {return pte_val (pte) & _PAGE_WRITABLE; }static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } -static inline int pte_special (pte_t pte) {return 0 ; }static inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) &= ~(_PAGE_WRITABLE | _PAGE_HW_WRITE);return pte; }
@@ -280,8 +279,6 @@ static inline pte_t pte_mkyoung(pte_t pt {pte_val (pte) |= _PAGE_ACCESSED;return pte; }static inline pte_t pte_mkwrite (pte_t pte) {pte_val (pte) |= _PAGE_WRITABLE;return pte; } -static inline pte_t pte_mkspecial (pte_t pte) - {return pte; }#define pgprot_noncached (prot) (__pgprot(pgprot_val(prot) & ~_PAGE_CA_MASK))
include/linux/mm.h renamed from include/linux/mm.h~mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial +12 -0
@@ -1849,6 +1849,18 @@ static inline void sync_mm_rss(struct mm }#endif +#ifndef CONFIG_ARCH_HAS_PTE_SPECIAL +static inline int pte_special (pte_t pte) +{ +return 0 ; +} + +static inline pte_t pte_mkspecial (pte_t pte) +{ +return pte; +} +#endif +#ifndef CONFIG_ARCH_HAS_PTE_DEVMAP static inline int pte_devmap (pte_t pte) {
_
Patches currently in -mm which might be from [email protected] are
mm-vma-add-missing-vma-flag-readable-name-for-vm_sync.patch mm-vma-make-vma_is_accessible-available-for-general-use.patch mm-vma-replace-all-remaining-open-encodings-with-is_vm_hugetlb_page.patch mm-vma-replace-all-remaining-open-encodings-with-vma_is_anonymous.patch mm-vma-append-unlikely-while-testing-vma-access-permissions.patch mm-vma-move-vm_no_khugepaged-into-generic-header.patch mm-vma-make-vma_is_foreign-available-for-general-use.patch mm-vma-make-is_vma_temporary_stack-available-for-general-use.patch mm-vma-define-a-default-value-for-vm_data_default_flags.patch mm-vma-introduce-vm_access_flags.patch mm-special-create-generic-fallbacks-for-pte_special-and-pte_mkspecial.patch
+ ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: ocfs2: cluster: replace zero-length array with flexible-array member has been added to the -mm tree. Its filename is…
The patch titled
Subject: ocfs2: cluster: replace zero-length array with flexible-array member
has been added to the -mm tree. Its filename is
ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: "Gustavo A. R. Silva" <[email protected]>
Subject: ocfs2: cluster: replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by this change:
"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]
This issue was found with the help of Coccinelle.
[1] https://urldefense.com/v3/__https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html__;!!GqivPVa7Brio!NzMr-YRl2zy-K3lwLVVatz7x0uD2z7-ykQag4GrGigxmfWU8TWzDy6xrkTiW3hYl00czlw$
[2] https://urldefense.com/v3/__https://github.com/KSPP/linux/issues/21__;!!GqivPVa7Brio!NzMr-YRl2zy-K3lwLVVatz7x0uD2z7-ykQag4GrGigxmfWU8TWzDy6xrkTiW3hYHG1nAnw$
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")
---
fs/ocfs2/cluster/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/cluster/tcp.h renamed from fs/ocfs2/cluster/tcp.h~ocfs2-cluster-replace-zero-length-array-with-flexible-array-member +1 -1
@@ -32,7 +32,7 @@ struct o2net_msg__be32 status;__be32 key;__be32 msg_num; -__u8 buf[0 ]; +__u8 buf[]; }; typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data,
_
Patches currently in -mm which might be from [email protected] are
ocfs2-replace-zero-length-array-with-flexible-array-member.patch ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch lib-bch-replace-zero-length-array-with-flexible-array-member.patch lib-ts_bm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_fsm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_kmp-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_4_7-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_3_4-replace-zero-length-array-with-flexible-array-member.patch gcov-fs-replace-zero-length-array-with-flexible-array-member.patch
+ ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: ocfs2: dlm: replace zero-length array with flexible-array member has been added to the -mm tree. Its filename is…
The patch titled
Subject: ocfs2: dlm: replace zero-length array with flexible-array member
has been added to the -mm tree. Its filename is
ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: "Gustavo A. R. Silva" <[email protected]>
Subject: ocfs2: dlm: replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by this change:
"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]
This issue was found with the help of Coccinelle.
[1] https://urldefense.com/v3/__https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html__;!!GqivPVa7Brio!OVOYL_CouISa5L1Lw-20EEFQntw6cKMx-j8UdY4z78uYgzKBUFcfpn50GaurvbV5v7YiUA$
[2] https://urldefense.com/v3/__https://github.com/KSPP/linux/issues/21__;!!GqivPVa7Brio!OVOYL_CouISa5L1Lw-20EEFQntw6cKMx-j8UdY4z78uYgzKBUFcfpn50GaurvbXs8Eh8eg$
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")
---
fs/ocfs2/dlm/dlmcommon.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ocfs2/dlm/dlmcommon.h renamed from fs/ocfs2/dlm/dlmcommon.h~ocfs2-dlm-replace-zero-length-array-with-flexible-array-member +4 -4
@@ -564,7 +564,7 @@ struct dlm_migratable_lockres// 48 bytes u8 lvb[DLM_LVB_LEN ];// 112 bytes -struct dlm_migratable_lock ml[0 ];// 16 bytes each, begins at byte 112 +struct dlm_migratable_lock ml[];// 16 bytes each, begins at byte 112 };#define DLM_MIG_LOCKRES_MAX_LEN \ (sizeof(struct dlm_migratable_lockres) + \
@@ -601,7 +601,7 @@ struct dlm_convert_locku8 name[O2NM_MAX_NAME_LEN ]; -s8 lvb[0 ]; +s8 lvb[]; };#define DLM_CONVERT_LOCK_MAX_LEN (sizeof(struct dlm_convert_lock)+DLM_LVB_LEN)
@@ -616,7 +616,7 @@ struct dlm_unlock_locku8 name[O2NM_MAX_NAME_LEN ]; -s8 lvb[0 ]; +s8 lvb[]; };#define DLM_UNLOCK_LOCK_MAX_LEN (sizeof(struct dlm_unlock_lock)+DLM_LVB_LEN)
@@ -632,7 +632,7 @@ struct dlm_proxy_astu8 name[O2NM_MAX_NAME_LEN ]; -s8 lvb[0 ]; +s8 lvb[]; };#define DLM_PROXY_AST_MAX_LEN (sizeof(struct dlm_proxy_ast)+DLM_LVB_LEN)
_
Patches currently in -mm which might be from [email protected] are
ocfs2-replace-zero-length-array-with-flexible-array-member.patch ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch lib-bch-replace-zero-length-array-with-flexible-array-member.patch lib-ts_bm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_fsm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_kmp-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_4_7-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_3_4-replace-zero-length-array-with-flexible-array-member.patch gcov-fs-replace-zero-length-array-with-flexible-array-member.patch
+ ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: ocfs2: ocfs2_fs.h: replace zero-length array with flexible-array member has been added to the -mm tree. Its filename is…
The patch titled
Subject: ocfs2: ocfs2_fs.h: replace zero-length array with flexible-array member
has been added to the -mm tree. Its filename is
ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: "Gustavo A. R. Silva" <[email protected]>
Subject: ocfs2: ocfs2_fs.h: replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by this change:
"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]
This issue was found with the help of Coccinelle.
[1] https://urldefense.com/v3/__https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html__;!!GqivPVa7Brio!OKPotRhYhHbCG2kibo8Q6_6CuKaa28d_74h1svxyR6rbshrK2L_BdrQpNbvJWBWb40QCkg$
[2] https://urldefense.com/v3/__https://github.com/KSPP/linux/issues/21__;!!GqivPVa7Brio!OKPotRhYhHbCG2kibo8Q6_6CuKaa28d_74h1svxyR6rbshrK2L_BdrQpNbvJWBUhNn9M6g$
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")
---
fs/ocfs2/ocfs2_fs.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
fs/ocfs2/ocfs2_fs.h renamed from fs/ocfs2/ocfs2_fs.h~ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member +9 -9
@@ -470,7 +470,7 @@ struct ocfs2_extent_list {__le16 l_reserved1;__le64 l_reserved2;/* Pad to sizeof(ocfs2_extent_rec) */ -/*10*/ struct ocfs2_extent_rec l_recs[0 ];/* Extent records */ +/*10*/ struct ocfs2_extent_rec l_recs[];/* Extent records */ };/*
@@ -484,7 +484,7 @@ struct ocfs2_chain_list {__le16 cl_count;/* Total chains in this list */ __le16 cl_next_free_rec;/* Next unused chain slot */ __le64 cl_reserved1; -/*10*/ struct ocfs2_chain_rec cl_recs[0 ];/* Chain records */ +/*10*/ struct ocfs2_chain_rec cl_recs[];/* Chain records */ };/*
@@ -496,7 +496,7 @@ struct ocfs2_truncate_log {/*00*/ __le16 tl_count;/* Total records in this log */ __le16 tl_used;/* Number of records in use */ __le32 tl_reserved1; -/*08*/ struct ocfs2_truncate_rec tl_recs[0 ];/* Truncate records */ +/*08*/ struct ocfs2_truncate_rec tl_recs[];/* Truncate records */ };/*
@@ -640,7 +640,7 @@ struct ocfs2_local_alloc__le16 la_size;/* Size of included bitmap, in bytes */ __le16 la_reserved1;__le64 la_reserved2; -/*10*/ __u8 la_bitmap[0 ]; +/*10*/ __u8 la_bitmap[]; };/*
@@ -653,7 +653,7 @@ struct ocfs2_inline_data* for data, starting at id_data */ __le16 id_reserved0;__le32 id_reserved1; -__u8 id_data[0 ];/* Start of user data */ +__u8 id_data[];/* Start of user data */ };/*
@@ -798,7 +798,7 @@ struct ocfs2_dx_entry_list {* possible in de_entries */ __le16 de_num_used;/* Current number of * de_entries entries */ -struct ocfs2_dx_entry de_entries[0 ];/* Indexed dir entries +struct ocfs2_dx_entry de_entries[];/* Indexed dir entries * in a packed array of * length de_num_used */ };
@@ -935,7 +935,7 @@ struct ocfs2_refcount_list {__le16 rl_used;/* Current number of used records */ __le32 rl_reserved2;__le64 rl_reserved1;/* Pad to sizeof(ocfs2_refcount_record) */ -/*10*/ struct ocfs2_refcount_rec rl_recs[0 ];/* Refcount records */ +/*10*/ struct ocfs2_refcount_rec rl_recs[];/* Refcount records */ };
@@ -1021,7 +1021,7 @@ struct ocfs2_xattr_header {buckets. A block uses xb_check and sets this field to zero.) */ -struct ocfs2_xattr_entry xh_entries[0 ];/* xattr entry list. */ +struct ocfs2_xattr_entry xh_entries[];/* xattr entry list. */ };/*
@@ -1207,7 +1207,7 @@ struct ocfs2_local_disk_dqinfo {/* Header of one chunk of a quota file */ struct ocfs2_local_disk_chunk {__le32 dqc_free;/* Number of free entries in the bitmap */ -__u8 dqc_bitmap[0 ];/* Bitmap of entries in the corresponding +__u8 dqc_bitmap[];/* Bitmap of entries in the corresponding * chunk of quota file */ };
_
Patches currently in -mm which might be from [email protected] are
ocfs2-replace-zero-length-array-with-flexible-array-member.patch ocfs2-cluster-replace-zero-length-array-with-flexible-array-member.patch ocfs2-dlm-replace-zero-length-array-with-flexible-array-member.patch ocfs2-ocfs2_fsh-replace-zero-length-array-with-flexible-array-member.patch lib-bch-replace-zero-length-array-with-flexible-array-member.patch lib-ts_bm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_fsm-replace-zero-length-array-with-flexible-array-member.patch lib-ts_kmp-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_4_7-replace-zero-length-array-with-flexible-array-member.patch gcov-gcc_3_4-replace-zero-length-array-with-flexible-array-member.patch gcov-fs-replace-zero-length-array-with-flexible-array-member.patch
+ mm-page_allocc-micro-optimisation-remove-unnecessary-branch.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/page_alloc.c: micro-optimisation Remove unnecessary branch has been added to the -mm tree. Its filename is…
The patch titled
Subject: mm/page_alloc.c: micro-optimisation Remove unnecessary branch
has been added to the -mm tree. Its filename is
mm-page_allocc-micro-optimisation-remove-unnecessary-branch.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-page_allocc-micro-optimisation-remove-unnecessary-branch.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-page_allocc-micro-optimisation-remove-unnecessary-branch.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Mateusz Nosek <[email protected]>
Subject: mm/page_alloc.c: micro-optimisation Remove unnecessary branch
Previously if branch condition was false, the assignment was not executed. The assignment can be safely executed even when the condition is false and it is not incorrect as it assigns the value of 'nodemask' to 'ac.nodemask' which already has the same value.
So as the assignment can be executed unconditionally, the branch can be removed.
---
mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_allocc-micro-optimisation-remove-unnecessary-branch +1 -2
@@ -4764,8 +4764,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u* Restore the original nodemask if it was potentially replaced with * &cpuset_current_mems_allowed to optimize the fast-path attempt. */ -if (unlikely (ac.nodemask != nodemask)) - ac.nodemask = nodemask; + ac.nodemask = nodemask; page =__alloc_pages_slowpath (alloc_mask, order, &ac);
_
Patches currently in -mm which might be from [email protected] are
mm-micro-optimisation-save-two-branches-on-hot-page-allocation-path.patch mm-page_allocc-micro-optimisation-remove-unnecessary-branch.patch mm-vmscanc-clean-code-by-removing-unnecessary-assignment.patch mm-hugetlbc-clean-code-by-removing-unnecessary-initialization.patch mm-shmemc-clean-code-by-removing-unnecessary-assignment.patch mm-mm_initc-clean-code-use-build_bug_on-when-comparing-compile-time-constant.patch
+ mm-gup-rename-nonblocking-to-locked-where-proper.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup: rename "nonblocking" to "locked" where proper has been added to the -mm tree. Its filename is mm-gup-rename-nonblocking-to-locked-where-proper.patch
The patch titled
Subject: mm/gup: rename "nonblocking" to "locked" where proper
has been added to the -mm tree. Its filename is
mm-gup-rename-nonblocking-to-locked-where-proper.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-rename-nonblocking-to-locked-where-proper.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-rename-nonblocking-to-locked-where-proper.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm/gup: rename "nonblocking" to "locked" where proper
Patch series "mm: Page fault enhancements", v6.
This series contains cleanups and enhancements to current page fault logic. The whole idea comes from the discussion between Andrea and Linus on the bug reported by syzbot here:
https://lkml.org/lkml/2017/11/2/833
Basically it does two things:
(a) Allows the page fault logic to be more interactive on not only SIGKILL, but also the rest of userspace signals, and,
(b) Allows the page fault retry (VM_FAULT_RETRY) to happen for more than once.
For (a): with the changes we should be able to react faster when page faults are working in parallel with userspace signals like SIGSTOP and SIGCONT (and more), and with that we can remove the buggy part in userfaultfd and benefit the whole page fault mechanism on faster signal processing to reach the userspace.
For (b), we should be able to allow the page fault handler to loop for even more than twice. Some context: for now since we have FAULT_FLAG_ALLOW_RETRY we can allow to retry the page fault once with the same interrupt context, however never more than twice. This can be not only a potential cleanup to remove this assumption since AFAIU the code itself doesn't really have this twice-only limitation (though that should be a protective approach in the past), at the same time it'll greatly simplify future works like userfaultfd write-protect where it's possible to retry for more than twice (please have a look at [1] below for a possible user that might require the page fault to be handled for a third time; if we can remove the retry limitation we can simply drop that patch and those complexity).
This patch (of 16):
There's plenty of places around __get_user_pages() that has a parameter "nonblocking" which does not really mean that "it won't block" (because it can really block) but instead it shows whether the mmap_sem is released by up_read() during the page fault handling mostly when VM_FAULT_RETRY is returned.
We have the correct naming in e.g. get_user_pages_locked() or get_user_pages_remote() as "locked", however there're still many places that are using the "nonblocking" as name.
Renaming the places to "locked" where proper to better suite the functionality of the variable. While at it, fixing up some of the comments accordingly.
---
mm/gup.c | 44 +++++++++++++++++++++----------------------- mm/hugetlb.c | 8 ++++---- 2 files changed, 25 insertions(+), 27 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-rename-nonblocking-to-locked-where-proper +21 -23
@@ -839,12 +839,12 @@ unmap: }/* -* mmap_sem must be held on entry. If @nonblocking != NULL and -* *@flags does not include FOLL_NOWAIT, the mmap_sem may be released. -* If it is, *@nonblocking will be set to 0 and -EBUSY returned. +* mmap_sem must be held on entry. If @locked != NULL and *@flags +* does not include FOLL_NOWAIT, the mmap_sem may be released. If it +* is, *@locked will be set to 0 and -EBUSY returned. */ static int faultin_page (struct task_struct *tsk,struct vm_area_struct *vma, -unsigned long address,unsigned int *flags,int *nonblocking) +unsigned long address,unsigned int *flags,int *locked) {unsigned int fault_flags =0 ;vm_fault_t ret;
@@ -856,7 +856,7 @@ static int faultin_page(struct task_stru fault_flags |=FAULT_FLAG_WRITE ;if (*flags &FOLL_REMOTE ) fault_flags |=FAULT_FLAG_REMOTE ; -if (nonblocking) +if (locked) fault_flags |=FAULT_FLAG_ALLOW_RETRY ;if (*flags &FOLL_NOWAIT ) fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;
@@ -882,8 +882,8 @@ static int faultin_page(struct task_stru }if (ret &VM_FAULT_RETRY ) { -if (nonblocking && !(fault_flags &FAULT_FLAG_RETRY_NOWAIT )) - *nonblocking =0 ; +if (locked && !(fault_flags &FAULT_FLAG_RETRY_NOWAIT )) + *locked =0 ;return -EBUSY ; }
@@ -960,7 +960,7 @@ static int check_vma_flags(struct vm_are* only intends to ensure the pages are faulted in. * @vmas: array of pointers to vmas corresponding to each page. * Or NULL if the caller does not require them. -* @nonblocking: whether waiting for disk IO or mmap_sem contention +* @locked: whether we're still with the mmap_sem held * * Returns either number of pages pinned (which may be less than the * number requested), or an error. Details about the return value:
@@ -995,13 +995,11 @@ static int check_vma_flags(struct vm_are* appropriate) must be called after the page is finished with, and * before put_page is called. * -* If @nonblocking != NULL, __get_user_pages will not wait for disk IO -* or mmap_sem contention, and if waiting is needed to pin all pages, -* *@nonblocking will be set to 0. Further, if @gup_flags does not -* include FOLL_NOWAIT, the mmap_sem will be released via up_read() in -* this case. +* If @locked != NULL, *@locked will be set to 0 when mmap_sem is +* released by an up_read(). That can happen if @gup_flags does not +* have FOLL_NOWAIT. * -* A caller using such a combination of @nonblocking and @gup_flags +* A caller using such a combination of @locked and @gup_flags * must therefore hold the mmap_sem for reading only, and recognize * when it's been released. Otherwise, it must be held for either * reading or writing and will not be released.
@@ -1013,7 +1011,7 @@ static int check_vma_flags(struct vm_arestatic long __get_user_pages (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,unsigned int gup_flags,struct page **pages, -struct vm_area_struct **vmas,int *nonblocking) +struct vm_area_struct **vmas,int *locked) {long ret =0 , i =0 ;struct vm_area_struct *vma =NULL ;
@@ -1059,7 +1057,7 @@ static long __get_user_pages(struct taskif (is_vm_hugetlb_page (vma)) { i =follow_hugetlb_page (mm, vma, pages, vmas, &start, &nr_pages, i, - gup_flags, nonblocking); + gup_flags, locked);continue ; } }
@@ -1077,7 +1075,7 @@ retry: page =follow_page_mask (vma, start, foll_flags, &ctx);if (!page) { ret =faultin_page (tsk, vma, start, &foll_flags, - nonblocking); + locked);switch (ret) {case 0 : goto retry;
@@ -1338,7 +1336,7 @@ static __always_inline long __get_user_p* @vma: target vma * @start: start address * @end: end address -* @nonblocking: +* @locked: whether the mmap_sem is still held * * This takes care of mlocking the pages too if VM_LOCKED is set. *
@@ -1346,14 +1344,14 @@ static __always_inline long __get_user_p* * vma->vm_mm->mmap_sem must be held. * -* If @nonblocking is NULL, it may be held for read or write and will +* If @locked is NULL, it may be held for read or write and will * be unperturbed. * -* If @nonblocking is non-NULL, it must held for read only and may be -* released. If it's released, *@nonblocking will be set to 0. +* If @locked is non-NULL, it must held for read only and may be +* released. If it's released, *@locked will be set to 0. */ long populate_vma_page_range (struct vm_area_struct *vma, -unsigned long start,unsigned long end,int *nonblocking) +unsigned long start,unsigned long end,int *locked) {struct mm_struct *mm = vma->vm_mm;unsigned long nr_pages = (end - start) /PAGE_SIZE ;
@@ -1388,7 +1386,7 @@ long populate_vma_page_range(struct vm_a* not result in a stack expansion that recurses back here. */ return __get_user_pages (current, mm, start, nr_pages, gup_flags, -NULL ,NULL , nonblocking); +NULL ,NULL , locked); }/*
mm/hugetlb.c renamed from mm/hugetlb.c~mm-gup-rename-nonblocking-to-locked-where-proper +4 -4
@@ -4272,7 +4272,7 @@ out_release_nounlock:long follow_hugetlb_page (struct mm_struct *mm,struct vm_area_struct *vma,struct page **pages,struct vm_area_struct **vmas,unsigned long *position,unsigned long *nr_pages, -long i,unsigned int flags,int *nonblocking) +long i,unsigned int flags,int *locked) {unsigned long pfn_offset;unsigned long vaddr = *position;
@@ -4343,7 +4343,7 @@ long follow_hugetlb_page(struct mm_strucspin_unlock (ptl);if (flags &FOLL_WRITE ) fault_flags |=FAULT_FLAG_WRITE ; -if (nonblocking) +if (locked) fault_flags |=FAULT_FLAG_ALLOW_RETRY ;if (flags &FOLL_NOWAIT ) fault_flags |= FAULT_FLAG_ALLOW_RETRY |
@@ -4360,9 +4360,9 @@ long follow_hugetlb_page(struct mm_strucbreak ; }if (ret &VM_FAULT_RETRY ) { -if (nonblocking && +if (locked && !(fault_flags &FAULT_FLAG_RETRY_NOWAIT )) - *nonblocking =0 ; + *locked =0 ; *nr_pages =0 ;/* * VM_FAULT_RETRY must not return an
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup: fix __get_user_pages() on fault retry of hugetlb has been added to the -mm tree. Its filename is mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch
The patch titled
Subject: mm/gup: fix __get_user_pages() on fault retry of hugetlb
has been added to the -mm tree. Its filename is
mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm/gup: fix __get_user_pages() on fault retry of hugetlb
When follow_hugetlb_page() returns with *locked==0, it means we've got a VM_FAULT_RETRY within the fauling process and we've released the mmap_sem. When that happens, we should stop and bail out.
---
mm/gup.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/gup.c renamed from mm/gup.c~mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb +10 -0
@@ -1058,6 +1058,16 @@ static long __get_user_pages(struct task i =follow_hugetlb_page (mm, vma, pages, vmas, &start, &nr_pages, i, gup_flags, locked); +if (locked && *locked ==0 ) { +/* +* We've got a VM_FAULT_RETRY +* and we've lost mmap_sem. +* We must stop here. +*/ +BUG_ON (gup_flags &FOLL_NOWAIT ); +BUG_ON (ret !=0 ); + goto out; + }continue ; } }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-introduce-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: introduce fault_signal_pending() has been added to the -mm tree. Its filename is mm-introduce-fault_signal_pending.patch
The patch titled
Subject: mm: introduce fault_signal_pending()
has been added to the -mm tree. Its filename is
mm-introduce-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-introduce-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-introduce-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: introduce fault_signal_pending()
For most architectures, we've got a quick path to detect fatal signal after a handle_mm_fault(). Introduce a helper for that quick path.
It cleans the current codes a bit so we don't need to duplicate the same check across archs. More importantly, this will be an unified place that we handle the signal immediately right after an interrupted page fault, so it'll be much easier for us if we want to change the behavior of handling signals later on for all the archs.
Note that currently only part of the archs are using this new helper, because some archs have their own way to handle signals. In the follow up patches, we'll try to apply this helper to all the rest of archs.
Another note is that the "regs" parameter in the new helper is not used yet. It'll be used very soon. Now we kept it in this patch only to avoid touching all the archs again in the follow up patches.
---
arch/alpha/mm/fault.c | 2 +- arch/arm/mm/fault.c | 2 +- arch/hexagon/mm/vm_fault.c | 2 +- arch/ia64/mm/fault.c | 2 +- arch/m68k/mm/fault.c | 2 +- arch/microblaze/mm/fault.c | 2 +- arch/mips/mm/fault.c | 2 +- arch/nds32/mm/fault.c | 2 +- arch/nios2/mm/fault.c | 2 +- arch/openrisc/mm/fault.c | 2 +- arch/parisc/mm/fault.c | 2 +- arch/riscv/mm/fault.c | 2 +- arch/s390/mm/fault.c | 3 +-- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/unicore32/mm/fault.c | 2 +- arch/xtensa/mm/fault.c | 2 +- include/linux/sched/signal.h | 13 +++++++++++++ 18 files changed, 30 insertions(+), 18 deletions(-)
arch/alpha/mm/fault.c renamed from arch/alpha/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -150,7 +150,7 @@ retry:the fault. */ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/arm/mm/fault.c renamed from arch/arm/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -295,7 +295,7 @@ retry:* signal first. We do not need to release the mmap_sem because * it would already be released in __lock_page_or_retry in * mm/filemap.c. */ -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) { +if (fault_signal_pending (fault, regs)) {if (!user_mode (regs)) goto no_context;return 0 ;
arch/hexagon/mm/vm_fault.c renamed from arch/hexagon/mm/vm_fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -91,7 +91,7 @@ good_area: fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;/* The most common case -- we are done. */
arch/ia64/mm/fault.c renamed from arch/ia64/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -141,7 +141,7 @@ retry:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/m68k/mm/fault.c renamed from arch/m68k/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -138,7 +138,7 @@ good_area: fault =handle_mm_fault (vma, address, flags);pr_debug ("handle_mm_fault returns %x\n" , fault); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return 0 ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/microblaze/mm/fault.c renamed from arch/microblaze/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -217,7 +217,7 @@ good_area:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/mips/mm/fault.c renamed from arch/mips/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -154,7 +154,7 @@ good_area:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (regs))return ;perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address);
arch/nds32/mm/fault.c renamed from arch/nds32/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -214,7 +214,7 @@ good_area:* signal first. We do not need to release the mmap_sem because it * would already be released in __lock_page_or_retry in mm/filemap.c. */ -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) { +if (fault_signal_pending (fault, regs)) {if (!user_mode (regs)) goto no_context;return ;
arch/nios2/mm/fault.c renamed from arch/nios2/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -133,7 +133,7 @@ good_area:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/openrisc/mm/fault.c renamed from arch/openrisc/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -161,7 +161,7 @@ good_area: fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/parisc/mm/fault.c renamed from arch/parisc/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -304,7 +304,7 @@ good_area: fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/riscv/mm/fault.c renamed from arch/riscv/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -117,7 +117,7 @@ good_area:* signal first. We do not need to release the mmap_sem because it * would already be released in __lock_page_or_retry in mm/filemap.c. */ -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (tsk)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/s390/mm/fault.c renamed from arch/s390/mm/fault.c~mm-introduce-fault_signal_pending +1 -2
@@ -480,8 +480,7 @@ retry:* the fault. */ fault =handle_mm_fault (vma, address, flags); -/* No reason to continue if interrupted by SIGKILL. */ -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) { +if (fault_signal_pending (fault, regs)) { fault =VM_FAULT_SIGNAL ;if (flags &FAULT_FLAG_RETRY_NOWAIT ) goto out_up;
arch/sparc/mm/fault_32.c renamed from arch/sparc/mm/fault_32.c~mm-introduce-fault_signal_pending +1 -1
@@ -237,7 +237,7 @@ good_area:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/sparc/mm/fault_64.c renamed from arch/sparc/mm/fault_64.c~mm-introduce-fault_signal_pending +1 -1
@@ -425,7 +425,7 @@ good_area: fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs)) goto exit_exception;if (unlikely (fault &VM_FAULT_ERROR )) {
arch/unicore32/mm/fault.c renamed from arch/unicore32/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -250,7 +250,7 @@ retry:* signal first. We do not need to release the mmap_sem because * it would already be released in __lock_page_or_retry in * mm/filemap.c. */ -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return 0 ;if (!(fault &VM_FAULT_ERROR ) && (flags &FAULT_FLAG_ALLOW_RETRY )) {
arch/xtensa/mm/fault.c renamed from arch/xtensa/mm/fault.c~mm-introduce-fault_signal_pending +1 -1
@@ -110,7 +110,7 @@ good_area:*/ fault =handle_mm_fault (vma, address, flags); -if ((fault &VM_FAULT_RETRY ) &&fatal_signal_pending (current)) +if (fault_signal_pending (fault, regs))return ;if (unlikely (fault &VM_FAULT_ERROR )) {
include/linux/sched/signal.h renamed from include/linux/sched/signal.h~mm-introduce-fault_signal_pending +13 -0
@@ -370,6 +370,19 @@ static inline int signal_pending_state(l }/* +* This should only be used in fault handlers to decide whether we +* should stop the current fault routine to handle the signals +* instead, especially with the case where we've got interrupted with +* a VM_FAULT_RETRY. +*/ +static inline bool fault_signal_pending (unsigned int fault_flags, +struct pt_regs *regs) +{ +return unlikely ((fault_flags &VM_FAULT_RETRY ) && +fatal_signal_pending (current)); +} + +/* * Reevaluate whether the task has signals pending delivery. * Wake the task if so. * This is required every time the blocked sigset_t changes.
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ x86-mm-use-helper-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: x86/mm: use helper fault_signal_pending() has been added to the -mm tree. Its filename is x86-mm-use-helper-fault_signal_pending.patch
The patch titled
Subject: x86/mm: use helper fault_signal_pending()
has been added to the -mm tree. Its filename is
x86-mm-use-helper-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/x86-mm-use-helper-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/x86-mm-use-helper-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: x86/mm: use helper fault_signal_pending()
Let's move the fatal signal check even earlier so that we can directly use the new fault_signal_pending() in x86 mm code.
---
arch/x86/mm/fault.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
arch/x86/mm/fault.c renamed from arch/x86/mm/fault.c~x86-mm-use-helper-fault_signal_pending +13 -15
@@ -1464,27 +1464,25 @@ good_area: fault =handle_mm_fault (vma, address, flags); major |= fault &VM_FAULT_MAJOR ; +/* Quick path to respond to signals */ +if (fault_signal_pending (fault, regs)) { +if (!user_mode (regs)) +no_context (regs, hw_error_code, address,SIGBUS , +BUS_ADRERR ); +return ; + } +/* * If we need to retry the mmap_sem has already been released, * and if there is a fatal signal pending there is no guarantee * that we made any progress. Handle this case first. */ -if (unlikely (fault &VM_FAULT_RETRY )) { +if (unlikely ((fault &VM_FAULT_RETRY ) && + (flags &FAULT_FLAG_ALLOW_RETRY ))) {/* Retry at most once */ -if (flags &FAULT_FLAG_ALLOW_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; - flags |=FAULT_FLAG_TRIED ; -if (!fatal_signal_pending (tsk)) - goto retry; - } - -/* User mode? Just return to handle the fatal exception */ -if (flags &FAULT_FLAG_USER ) -return ; - -/* Not returning to user mode? Handle exceptions or die: */ -no_context (regs, hw_error_code, address,SIGBUS ,BUS_ADRERR ); -return ; + flags &= ~FAULT_FLAG_ALLOW_RETRY ; + flags |=FAULT_FLAG_TRIED ; + goto retry; }up_read (&mm->mmap_sem);
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ arc-mm-use-helper-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: arc/mm: use helper fault_signal_pending() has been added to the -mm tree. Its filename is arc-mm-use-helper-fault_signal_pending.patch
The patch titled
Subject: arc/mm: use helper fault_signal_pending()
has been added to the -mm tree. Its filename is
arc-mm-use-helper-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/arc-mm-use-helper-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/arc-mm-use-helper-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: arc/mm: use helper fault_signal_pending()
Let ARC to use the new helper fault_signal_pending() by moving the signal check out of the retry logic as standalone. This should also helps to simplify the code a bit.
---
arch/arc/mm/fault.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
arch/arc/mm/fault.c renamed from arch/arc/mm/fault.c~arc-mm-use-helper-fault_signal_pending +13 -21
@@ -133,29 +133,21 @@ retry: fault =handle_mm_fault (vma, address, flags); +/* Quick path to respond to signals */ +if (fault_signal_pending (fault, regs)) { +if (!user_mode (regs)) + goto no_context; +return ; + } +/* -* Fault retry nuances +* Fault retry nuances, mmap_sem already relinquished by core mm */ -if (unlikely (fault &VM_FAULT_RETRY )) { - -/* -* If fault needs to be retried, handle any pending signals -* first (by returning to user mode). -* mmap_sem already relinquished by core mm for RETRY case -*/ -if (fatal_signal_pending (current)) { -if (!user_mode (regs)) - goto no_context; -return ; - } -/* -* retry state machine -*/ -if (flags &FAULT_FLAG_ALLOW_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; - flags |=FAULT_FLAG_TRIED ; - goto retry; - } +if (unlikely ((fault &VM_FAULT_RETRY ) && + (flags &FAULT_FLAG_ALLOW_RETRY ))) { + flags &= ~FAULT_FLAG_ALLOW_RETRY ; + flags |=FAULT_FLAG_TRIED ; + goto retry; } bad_area:
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ arm64-mm-use-helper-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: arm64/mm: use helper fault_signal_pending() has been added to the -mm tree. Its filename is arm64-mm-use-helper-fault_signal_pending.patch
The patch titled
Subject: arm64/mm: use helper fault_signal_pending()
has been added to the -mm tree. Its filename is
arm64-mm-use-helper-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/arm64-mm-use-helper-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/arm64-mm-use-helper-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: arm64/mm: use helper fault_signal_pending()
Let the arm64 fault handling to use the new fault_signal_pending() helper, by moving the signal handling out of the retry logic.
---
arch/arm64/mm/fault.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
arch/arm64/mm/fault.c renamed from arch/arm64/mm/fault.c~arm64-mm-use-helper-fault_signal_pending +7 -12
@@ -513,19 +513,14 @@ retry: fault =__do_page_fault (mm, addr, mm_flags, vm_flags); major |= fault &VM_FAULT_MAJOR ; -if (fault &VM_FAULT_RETRY ) { -/* -* If we need to retry but a fatal signal is pending, -* handle the signal first. We do not need to release -* the mmap_sem because it would already be released -* in __lock_page_or_retry in mm/filemap.c. -*/ -if (fatal_signal_pending (current)) { -if (!user_mode (regs)) - goto no_context; -return 0 ; - } +/* Quick path to respond to signals */ +if (fault_signal_pending (fault, regs)) { +if (!user_mode (regs)) + goto no_context; +return 0 ; + } +if (fault &VM_FAULT_RETRY ) {/* * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of * starvation.
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ powerpc-mm-use-helper-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: powerpc/mm: use helper fault_signal_pending() has been added to the -mm tree. Its filename is powerpc-mm-use-helper-fault_signal_pending.patch
The patch titled
Subject: powerpc/mm: use helper fault_signal_pending()
has been added to the -mm tree. Its filename is
powerpc-mm-use-helper-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/powerpc-mm-use-helper-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/powerpc-mm-use-helper-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: powerpc/mm: use helper fault_signal_pending()
Let powerpc code to use the new helper, by moving the signal handling earlier before the retry logic.
---
arch/powerpc/mm/fault.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/powerpc/mm/fault.c renamed from arch/powerpc/mm/fault.c~powerpc-mm-use-helper-fault_signal_pending +4 -8
@@ -582,6 +582,9 @@ good_area: major |= fault &VM_FAULT_MAJOR ; +if (fault_signal_pending (fault, regs)) +return user_mode (regs) ?0 :SIGBUS ; +/* * Handle the retry right now, the mmap_sem has been released in that * case.
@@ -595,15 +598,8 @@ good_area:*/ flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; -if (!fatal_signal_pending (current)) - goto retry; + goto retry; } - -/* -* User mode? Just return to handle the fatal exception otherwise -* return to bad_page_fault -*/ -return is_user ?0 :SIGBUS ; }up_read (¤t->mm->mmap_sem);
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ sh-mm-use-helper-fault_signal_pending.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: sh/mm: use helper fault_signal_pending() has been added to the -mm tree. Its filename is sh-mm-use-helper-fault_signal_pending.patch
The patch titled
Subject: sh/mm: use helper fault_signal_pending()
has been added to the -mm tree. Its filename is
sh-mm-use-helper-fault_signal_pending.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/sh-mm-use-helper-fault_signal_pending.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/sh-mm-use-helper-fault_signal_pending.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: sh/mm: use helper fault_signal_pending()
Let SH to use the new fault_signal_pending() helper. Here we'll need to move the up_read() out because that's actually needed as long as !RETRY cases. At the meantime we can drop all the rest of up_read()s now (which seems to be cleaner).
---
arch/sh/mm/fault.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/sh/mm/fault.c renamed from arch/sh/mm/fault.c~sh-mm-use-helper-fault_signal_pending +5 -5
@@ -302,25 +302,25 @@ mm_fault_error(struct pt_regs *regs, uns* Pagefault was interrupted by SIGKILL. We have no reason to * continue pagefault. */ -if (fatal_signal_pending (current)) { -if (!(fault &VM_FAULT_RETRY )) -up_read (¤t->mm->mmap_sem); +if (fault_signal_pending (fault, regs)) {if (!user_mode (regs))no_context (regs, error_code, address);return 1 ; } +/* Release mmap_sem first if necessary */ +if (!(fault &VM_FAULT_RETRY )) +up_read (¤t->mm->mmap_sem); +if (!(fault &VM_FAULT_ERROR ))return 0 ;if (fault &VM_FAULT_OOM ) {/* Kernel mode? Handle exceptions or die: */ if (!user_mode (regs)) { -up_read (¤t->mm->mmap_sem);no_context (regs, error_code, address);return 1 ; } -up_read (¤t->mm->mmap_sem);/* * We ran out of memory, call the OOM killer, and return the
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: return faster for non-fatal signals in user mode faults has been added to the -mm tree. Its filename is mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch
The patch titled
Subject: mm: return faster for non-fatal signals in user mode faults
has been added to the -mm tree. Its filename is
mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: return faster for non-fatal signals in user mode faults
The idea comes from the upstream discussion between Linus and Andrea:
https://lore.kernel.org/lkml/[email protected]/
A summary to the issue: there was a special path in handle_userfault() in the past that we'll return a VM_FAULT_NOPAGE when we detected non-fatal signals when waiting for userfault handling. We did that by reacquiring the mmap_sem before returning. However that brings a risk in that the vmas might have changed when we retake the mmap_sem and even we could be holding an invalid vma structure.
This patch is a preparation of removing that special path by allowing the page fault to return even faster if we were interrupted by a non-fatal signal during a user-mode page fault handling routine.
---
include/linux/sched/signal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/sched/signal.h renamed from include/linux/sched/signal.h~mm-return-faster-for-non-fatal-signals-in-user-mode-faults +2 -1
@@ -379,7 +379,8 @@ static inline bool fault_signal_pending( struct pt_regs *regs) {return unlikely ((fault_flags &VM_FAULT_RETRY ) && -fatal_signal_pending (current)); + (fatal_signal_pending (current) || + (user_mode (regs) &&signal_pending (current)))); }/*
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: don't retake mmap_sem to emulate NOPAGE has been added to the -mm tree. Its filename is userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch
The patch titled
Subject: userfaultfd: don't retake mmap_sem to emulate NOPAGE
has been added to the -mm tree. Its filename is
userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: don't retake mmap_sem to emulate NOPAGE
This patch removes the risk path in handle_userfault() then we will be sure that the callers of handle_mm_fault() will know that the VMAs might have changed. Meanwhile with previous patch we don't lose responsiveness as well since the core mm code now can handle the nonfatal userspace signals even if we return VM_FAULT_RETRY.
---
fs/userfaultfd.c | 24 ------------------------ 1 file changed, 24 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-dont-retake-mmap_sem-to-emulate-nopage +0 -24
@@ -524,30 +524,6 @@ vm_fault_t handle_userfault(struct vm_fa__set_current_state (TASK_RUNNING ); -if (return_to_userland) { -if (signal_pending (current) && - !fatal_signal_pending (current)) { -/* -* If we got a SIGSTOP or SIGCONT and this is -* a normal userland page fault, just let -* userland return so the signal will be -* handled and gdb debugging works. The page -* fault code immediately after we return from -* this function is going to release the -* mmap_sem and it's not depending on it -* (unlike gup would if we were not to return -* VM_FAULT_RETRY). -* -* If a fatal signal is pending we still take -* the streamlined VM_FAULT_RETRY failure path -* and there's no need to retake the mmap_sem -* in such case. -*/ -down_read (&mm->mmap_sem); - ret =VM_FAULT_NOPAGE ; - } - } -/* * Here we race with the list_del; list_add in * userfaultfd_ctx_read(), however because we don't ever run
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-introduce-fault_flag_default.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: introduce FAULT_FLAG_DEFAULT has been added to the -mm tree. Its filename is mm-introduce-fault_flag_default.patch
The patch titled
Subject: mm: introduce FAULT_FLAG_DEFAULT
has been added to the -mm tree. Its filename is
mm-introduce-fault_flag_default.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-introduce-fault_flag_default.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-introduce-fault_flag_default.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: introduce FAULT_FLAG_DEFAULT
Although there're tons of arch-specific page fault handlers, most of them are still sharing the same initial value of the page fault flags. Say, merely all of the page fault handlers would allow the fault to be retried, and they also allow the fault to respond to SIGKILL.
Let's define a default value for the fault flags to replace those initial page fault flags that were copied over. With this, it'll be far easier to introduce new fault flag that can be used by all the architectures instead of touching all the archs.
---
arch/alpha/mm/fault.c | 2 +- arch/arc/mm/fault.c | 2 +- arch/arm/mm/fault.c | 2 +- arch/arm64/mm/fault.c | 2 +- arch/hexagon/mm/vm_fault.c | 2 +- arch/ia64/mm/fault.c | 2 +- arch/m68k/mm/fault.c | 2 +- arch/microblaze/mm/fault.c | 2 +- arch/mips/mm/fault.c | 2 +- arch/nds32/mm/fault.c | 2 +- arch/nios2/mm/fault.c | 2 +- arch/openrisc/mm/fault.c | 2 +- arch/parisc/mm/fault.c | 2 +- arch/powerpc/mm/fault.c | 2 +- arch/riscv/mm/fault.c | 2 +- arch/s390/mm/fault.c | 2 +- arch/sh/mm/fault.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/um/kernel/trap.c | 2 +- arch/unicore32/mm/fault.c | 2 +- arch/x86/mm/fault.c | 2 +- arch/xtensa/mm/fault.c | 2 +- include/linux/mm.h | 7 +++++++ 24 files changed, 30 insertions(+), 23 deletions(-)
arch/alpha/mm/fault.c renamed from arch/alpha/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -89,7 +89,7 @@ do_page_fault(unsigned long address, unsconst struct exception_table_entry *fixup;int si_code =SEGV_MAPERR ;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;/* As of EV6, a load into $31/$f31 is a prefetch, and never faults (or is suppressed by the PALcode). Support that for older CPUs
arch/arc/mm/fault.c renamed from arch/arc/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -100,7 +100,7 @@ void do_page_fault(unsigned long address (regs->ecr_cause == ECR_C_PROTV_INST_FETCH)) exec =1 ; - flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; + flags =FAULT_FLAG_DEFAULT ;if (user_mode (regs)) flags |=FAULT_FLAG_USER ;if (write)
arch/arm64/mm/fault.c renamed from arch/arm64/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -446,7 +446,7 @@ static int __kprobes do_page_fault(unsigstruct mm_struct *mm = current->mm;vm_fault_t fault, major =0 ;unsigned long vm_flags =VM_READ |VM_WRITE |VM_EXEC ; -unsigned int mm_flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int mm_flags =FAULT_FLAG_DEFAULT ;if (kprobe_page_fault (regs, esr))return 0 ;
arch/arm/mm/fault.c renamed from arch/arm/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -241,7 +241,7 @@ do_page_fault(unsigned long addr, unsignstruct mm_struct *mm;int sig, code;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;if (kprobe_page_fault (regs, fsr))return 0 ;
arch/hexagon/mm/vm_fault.c renamed from arch/hexagon/mm/vm_fault.c~mm-introduce-fault_flag_default +1 -1
@@ -41,7 +41,7 @@ void do_page_fault(unsigned long addressint si_code =SEGV_MAPERR ;vm_fault_t fault;const struct exception_table_entry *fixup; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;/* * If we're in an interrupt or have no user context,
arch/ia64/mm/fault.c renamed from arch/ia64/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -65,7 +65,7 @@ ia64_do_page_fault (unsigned long addresstruct mm_struct *mm = current->mm;unsigned long mask;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; mask = ((((isr >>IA64_ISR_X_BIT ) &1UL ) <<VM_EXEC_BIT ) | (((isr >>IA64_ISR_W_BIT ) &1UL ) <<VM_WRITE_BIT ));
arch/m68k/mm/fault.c renamed from arch/m68k/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -71,7 +71,7 @@ int do_page_fault(struct pt_regs *regs,struct mm_struct *mm = current->mm;struct vm_area_struct * vma;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;pr_debug ("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n" , regs->sr, regs->pc, address, error_code, mm ? mm->pgd :NULL );
arch/microblaze/mm/fault.c renamed from arch/microblaze/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -91,7 +91,7 @@ void do_page_fault(struct pt_regs *regs,int code =SEGV_MAPERR ;int is_write = error_code &ESR_S ;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; regs->ear = address; regs->esr = error_code;
arch/mips/mm/fault.c renamed from arch/mips/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -44,7 +44,7 @@ static void __kprobes __do_page_fault(stconst int field =sizeof (unsigned long ) *2 ;int si_code;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);
arch/nds32/mm/fault.c renamed from arch/nds32/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -80,7 +80,7 @@ void do_page_fault(unsigned long entry,int si_code;vm_fault_t fault;unsigned int mask =VM_READ |VM_WRITE |VM_EXEC ; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE); tsk = current;
arch/nios2/mm/fault.c renamed from arch/nios2/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -47,7 +47,7 @@ asmlinkage void do_page_fault(struct pt_struct mm_struct *mm = tsk->mm;int code =SEGV_MAPERR ;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; cause >>=2 ;
arch/openrisc/mm/fault.c renamed from arch/openrisc/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -50,7 +50,7 @@ asmlinkage void do_page_fault(struct pt_struct vm_area_struct *vma;int si_code;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; tsk = current;
arch/parisc/mm/fault.c renamed from arch/parisc/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -274,7 +274,7 @@ void do_page_fault(struct pt_regs *regs,if (!mm) goto no_context; - flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; + flags =FAULT_FLAG_DEFAULT ;if (user_mode (regs)) flags |=FAULT_FLAG_USER ;
arch/powerpc/mm/fault.c renamed from arch/powerpc/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -434,7 +434,7 @@ static int __do_page_fault(struct pt_reg {struct vm_area_struct * vma;struct mm_struct *mm = current->mm; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;int is_exec =TRAP (regs) ==0x400 ;int is_user =user_mode (regs);int is_write =page_fault_is_write (error_code);
arch/riscv/mm/fault.c renamed from arch/riscv/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -30,7 +30,7 @@ asmlinkage void do_page_fault(struct pt_struct vm_area_struct *vma;struct mm_struct *mm;unsigned long addr, cause; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;int code =SEGV_MAPERR ;vm_fault_t fault;
arch/s390/mm/fault.c renamed from arch/s390/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -429,7 +429,7 @@ static inline vm_fault_t do_exception(st address = trans_exc_code & __FAIL_ADDR_MASK;perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address); - flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; + flags =FAULT_FLAG_DEFAULT ;if (user_mode (regs)) flags |=FAULT_FLAG_USER ;if (access ==VM_WRITE || (trans_exc_code & store_indication) ==0x400 )
arch/sh/mm/fault.c renamed from arch/sh/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -380,7 +380,7 @@ asmlinkage void __kprobes do_page_fault(struct mm_struct *mm;struct vm_area_struct * vma;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; tsk = current; mm = tsk->mm;
arch/sparc/mm/fault_32.c renamed from arch/sparc/mm/fault_32.c~mm-introduce-fault_flag_default +1 -1
@@ -168,7 +168,7 @@ asmlinkage void do_sparc_fault(struct ptint from_user = !(regs->psr &PSR_PS );int code;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ;if (text_fault) address = regs->pc;
arch/sparc/mm/fault_64.c renamed from arch/sparc/mm/fault_64.c~mm-introduce-fault_flag_default +1 -1
@@ -271,7 +271,7 @@ asmlinkage void __kprobes do_sparc64_fauint si_code, fault_code;vm_fault_t fault;unsigned long address, mm_rss; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; fault_code =get_thread_fault_code ();
arch/um/kernel/trap.c renamed from arch/um/kernel/trap.c~mm-introduce-fault_flag_default +1 -1
@@ -33,7 +33,7 @@ int handle_page_fault(unsigned long addrpmd_t *pmd;pte_t *pte;int err = -EFAULT ; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; *code_out =SEGV_MAPERR ;
arch/unicore32/mm/fault.c renamed from arch/unicore32/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -202,7 +202,7 @@ static int do_pf(unsigned long addr, unsstruct mm_struct *mm;int sig, code;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; tsk = current; mm = tsk->mm;
arch/x86/mm/fault.c renamed from arch/x86/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -1310,7 +1310,7 @@ void do_user_addr_fault(struct pt_regs *struct task_struct *tsk;struct mm_struct *mm;vm_fault_t fault, major =0 ; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; tsk = current; mm = tsk->mm;
arch/xtensa/mm/fault.c renamed from arch/xtensa/mm/fault.c~mm-introduce-fault_flag_default +1 -1
@@ -43,7 +43,7 @@ void do_page_fault(struct pt_regs *regs)int is_write, is_exec;vm_fault_t fault; -unsigned int flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; +unsigned int flags =FAULT_FLAG_DEFAULT ; code =SEGV_MAPERR ;
include/linux/mm.h renamed from include/linux/mm.h~mm-introduce-fault_flag_default +7 -0
@@ -391,6 +391,13 @@ extern pgprot_t protection_map[16];#define FAULT_FLAG_REMOTE 0x80/* faulting for non current tsk/mm */ #define FAULT_FLAG_INSTRUCTION 0x100/* The fault was during an instruction fetch */ +/* +* The default fault flags that should be used by most of the +* arch-specific page fault handlers. +*/ +#define FAULT_FLAG_DEFAULT (FAULT_FLAG_ALLOW_RETRY | \ + FAULT_FLAG_KILLABLE) +#define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \ { FAULT_FLAG_MKWRITE, "MKWRITE" }, \
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-introduce-fault_flag_interruptible.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: introduce FAULT_FLAG_INTERRUPTIBLE has been added to the -mm tree. Its filename is mm-introduce-fault_flag_interruptible.patch
The patch titled
Subject: mm: introduce FAULT_FLAG_INTERRUPTIBLE
has been added to the -mm tree. Its filename is
mm-introduce-fault_flag_interruptible.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-introduce-fault_flag_interruptible.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-introduce-fault_flag_interruptible.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: introduce FAULT_FLAG_INTERRUPTIBLE
handle_userfaultfd() is currently the only one place in the kernel page fault procedures that can respond to non-fatal userspace signals. It was trying to detect such an allowance by checking against USER & KILLABLE flags, which was "un-official".
In this patch, we introduced a new flag (FAULT_FLAG_INTERRUPTIBLE) to show that the fault handler allows the fault procedure to respond even to non-fatal signals. Meanwhile, add this new flag to the default fault flags so that all the page fault handlers can benefit from the new flag. With that, replacing the userfault check to this one.
Since the line is getting even longer, clean up the fault flags a bit too to ease TTY users.
Although we've got a new flag and applied it, we shouldn't have any functional change with this patch so far.
---
fs/userfaultfd.c | 4 +--- include/linux/mm.h | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~mm-introduce-fault_flag_interruptible +1 -3
@@ -462,9 +462,7 @@ vm_fault_t handle_userfault(struct vm_fa uwq.ctx = ctx; uwq.waken = false; - return_to_userland = - (vmf->flags & (FAULT_FLAG_USER |FAULT_FLAG_KILLABLE )) == - (FAULT_FLAG_USER |FAULT_FLAG_KILLABLE ); + return_to_userland = vmf->flags &FAULT_FLAG_INTERRUPTIBLE ; blocking_state = return_to_userland ?TASK_INTERRUPTIBLE :TASK_KILLABLE ;
include/linux/mm.h renamed from include/linux/mm.h~mm-introduce-fault_flag_interruptible +28 -11
@@ -381,22 +381,38 @@ extern unsigned int kobjsize(const void*/ extern pgprot_t protection_map[16 ]; -#define FAULT_FLAG_WRITE 0x01/* Fault was a write access */ -#define FAULT_FLAG_MKWRITE 0x02/* Fault was mkwrite of existing pte */ -#define FAULT_FLAG_ALLOW_RETRY 0x04/* Retry fault if blocking */ -#define FAULT_FLAG_RETRY_NOWAIT 0x08/* Don't drop mmap_sem and wait when retrying */ -#define FAULT_FLAG_KILLABLE 0x10/* The fault task is in SIGKILL killable region */ -#define FAULT_FLAG_TRIED 0x20/* Second try */ -#define FAULT_FLAG_USER 0x40/* The fault originated in userspace */ -#define FAULT_FLAG_REMOTE 0x80/* faulting for non current tsk/mm */ -#define FAULT_FLAG_INSTRUCTION 0x100/* The fault was during an instruction fetch */ +/** +* Fault flag definitions. +* +* @FAULT_FLAG_WRITE: Fault was a write fault. +* @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE. +* @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked. +* @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_sem and wait when retrying. +* @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region. +* @FAULT_FLAG_TRIED: The fault has been tried once. +* @FAULT_FLAG_USER: The fault originated in userspace. +* @FAULT_FLAG_REMOTE: The fault is not for current task/mm. +* @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. +* @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. +*/ +#define FAULT_FLAG_WRITE 0x01 +#define FAULT_FLAG_MKWRITE 0x02 +#define FAULT_FLAG_ALLOW_RETRY 0x04 +#define FAULT_FLAG_RETRY_NOWAIT 0x08 +#define FAULT_FLAG_KILLABLE 0x10 +#define FAULT_FLAG_TRIED 0x20 +#define FAULT_FLAG_USER 0x40 +#define FAULT_FLAG_REMOTE 0x80 +#define FAULT_FLAG_INSTRUCTION 0x100 +#define FAULT_FLAG_INTERRUPTIBLE 0x200/* * The default fault flags that should be used by most of the * arch-specific page fault handlers. */ #define FAULT_FLAG_DEFAULT (FAULT_FLAG_ALLOW_RETRY | \ - FAULT_FLAG_KILLABLE) + FAULT_FLAG_KILLABLE | \ + FAULT_FLAG_INTERRUPTIBLE)#define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \
@@ -407,7 +423,8 @@ extern pgprot_t protection_map[16]; { FAULT_FLAG_TRIED, "TRIED" }, \ { FAULT_FLAG_USER, "USER" }, \ { FAULT_FLAG_REMOTE, "REMOTE" }, \ - { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" } + { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" }, \ + { FAULT_FLAG_INTERRUPTIBLE, "INTERRUPTIBLE" }/* * vm_fault is filled by the the pagefault handler and passed to the vma's
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-allow-vm_fault_retry-for-multiple-times.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: allow VM_FAULT_RETRY for multiple times has been added to the -mm tree. Its filename is mm-allow-vm_fault_retry-for-multiple-times.patch
The patch titled
Subject: mm: allow VM_FAULT_RETRY for multiple times
has been added to the -mm tree. Its filename is
mm-allow-vm_fault_retry-for-multiple-times.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-allow-vm_fault_retry-for-multiple-times.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-allow-vm_fault_retry-for-multiple-times.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: allow VM_FAULT_RETRY for multiple times
The idea comes from a discussion between Linus and Andrea [1].
Before this patch we only allow a page fault to retry once. We achieved this by clearing the FAULT_FLAG_ALLOW_RETRY flag when doing handle_mm_fault() the second time. This was majorly used to avoid unexpected starvation of the system by looping over forever to handle the page fault on a single page. However that should hardly happen, and after all for each code path to return a VM_FAULT_RETRY we'll first wait for a condition (during which time we should possibly yield the cpu) to happen before VM_FAULT_RETRY is really returned.
This patch removes the restriction by keeping the FAULT_FLAG_ALLOW_RETRY flag when we receive VM_FAULT_RETRY. It means that the page fault handler now can retry the page fault for multiple times if necessary without the need to generate another page fault event. Meanwhile we still keep the FAULT_FLAG_TRIED flag so page fault handler can still identify whether a page fault is the first attempt or not.
Then we'll have these combinations of fault flags (only considering ALLOW_RETRY flag and TRIED flag):
- ALLOW_RETRY and !TRIED: this means the page fault allows to retry, and this is the first try
- ALLOW_RETRY and TRIED: this means the page fault allows to
retry, and this is not the first try
- !ALLOW_RETRY and !TRIED: this means the page fault does not allow to retry at all
- !ALLOW_RETRY and TRIED: this is forbidden and should never be used
In existing code we have multiple places that has taken special care of the first condition above by checking against (fault_flags & FAULT_FLAG_ALLOW_RETRY). This patch introduces a simple helper to detect the first retry of a page fault by checking against both (fault_flags & FAULT_FLAG_ALLOW_RETRY) and !(fault_flag & FAULT_FLAG_TRIED) because now even the 2nd try will have the ALLOW_RETRY set, then use that helper in all existing special paths. One example is in __lock_page_or_retry(), now we'll drop the mmap_sem only in the first attempt of page fault and we'll keep it in follow up retries, so old locking behavior will be retained.
This will be a nice enhancement for current code [2] at the same time a supporting material for the future userfaultfd-writeprotect work, since in that work there will always be an explicit userfault writeprotect retry for protected pages, and if that cannot resolve the page fault (e.g., when userfaultfd-writeprotect is used in conjunction with swapped pages) then we'll possibly need a 3rd retry of the page fault. It might also benefit other potential users who will have similar requirement like userfault write-protection.
GUP code is not touched yet and will be covered in follow up patch.
Please read the thread below for more information.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
---
arch/alpha/mm/fault.c | 2 - arch/arc/mm/fault.c | 1 arch/arm/mm/fault.c | 3 -- arch/arm64/mm/fault.c | 5 ---- arch/hexagon/mm/vm_fault.c | 1 arch/ia64/mm/fault.c | 1 arch/m68k/mm/fault.c | 3 -- arch/microblaze/mm/fault.c | 1 arch/mips/mm/fault.c | 1 arch/nds32/mm/fault.c | 1 arch/nios2/mm/fault.c | 3 -- arch/openrisc/mm/fault.c | 1 arch/parisc/mm/fault.c | 4 --- arch/powerpc/mm/fault.c | 6 ---- arch/riscv/mm/fault.c | 5 ---- arch/s390/mm/fault.c | 5 ---- arch/sh/mm/fault.c | 1 arch/sparc/mm/fault_32.c | 1 arch/sparc/mm/fault_64.c | 1 arch/um/kernel/trap.c | 1 arch/unicore32/mm/fault.c | 4 --- arch/x86/mm/fault.c | 2 - arch/xtensa/mm/fault.c | 1 drivers/gpu/drm/ttm/ttm_bo_vm.c | 12 +++++++-- include/linux/mm.h | 37 ++++++++++++++++++++++++++++++ mm/filemap.c | 2 - mm/internal.h | 6 ++-- 27 files changed, 54 insertions(+), 57 deletions(-)
arch/alpha/mm/fault.c renamed from arch/alpha/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +1 -1
@@ -169,7 +169,7 @@ retry:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; + flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would * have already released it in __lock_page_or_retry
arch/arc/mm/fault.c renamed from arch/arc/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -145,7 +145,6 @@ retry:*/ if (unlikely ((fault &VM_FAULT_RETRY ) && (flags &FAULT_FLAG_ALLOW_RETRY ))) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/arm64/mm/fault.c renamed from arch/arm64/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -5
@@ -521,12 +521,7 @@ retry: }if (fault &VM_FAULT_RETRY ) { -/* -* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of -* starvation. -*/ if (mm_flags &FAULT_FLAG_ALLOW_RETRY ) { - mm_flags &= ~FAULT_FLAG_ALLOW_RETRY ; mm_flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/arm/mm/fault.c renamed from arch/arm/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -3
@@ -319,9 +319,6 @@ retry: regs, addr); }if (fault &VM_FAULT_RETRY ) { -/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. */ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/hexagon/mm/vm_fault.c renamed from arch/hexagon/mm/vm_fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -102,7 +102,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/ia64/mm/fault.c renamed from arch/ia64/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -167,7 +167,6 @@ retry:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
arch/m68k/mm/fault.c renamed from arch/m68k/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -3
@@ -162,9 +162,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { -/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. */ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/*
arch/microblaze/mm/fault.c renamed from arch/microblaze/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -236,7 +236,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/*
arch/mips/mm/fault.c renamed from arch/mips/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -178,7 +178,6 @@ good_area: tsk->min_flt++; }if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/*
arch/nds32/mm/fault.c renamed from arch/nds32/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -246,7 +246,6 @@ good_area: 1, regs, addr); }if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
arch/nios2/mm/fault.c renamed from arch/nios2/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -3
@@ -157,9 +157,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { -/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. */ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/*
arch/openrisc/mm/fault.c renamed from arch/openrisc/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -181,7 +181,6 @@ good_area:else tsk->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
arch/parisc/mm/fault.c renamed from arch/parisc/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +1 -3
@@ -328,14 +328,12 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; -/* * No need to up_read(&mm->mmap_sem) as we would * have already released it in __lock_page_or_retry * in mm/filemap.c. */ - + flags |=FAULT_FLAG_TRIED ; goto retry; } }
arch/powerpc/mm/fault.c renamed from arch/powerpc/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -6
@@ -590,13 +590,7 @@ good_area:* case. */ if (unlikely (fault &VM_FAULT_RETRY )) { -/* We retry only once */ if (flags &FAULT_FLAG_ALLOW_RETRY ) { -/* -* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. -*/ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/riscv/mm/fault.c renamed from arch/riscv/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -5
@@ -144,11 +144,6 @@ good_area: 1, regs, addr); }if (fault &VM_FAULT_RETRY ) { -/* -* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. -*/ - flags &= ~(FAULT_FLAG_ALLOW_RETRY ); flags |=FAULT_FLAG_TRIED ;/*
arch/s390/mm/fault.c renamed from arch/s390/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +1 -4
@@ -513,10 +513,7 @@ retry: fault =VM_FAULT_PFAULT ; goto out_up; } -/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. */ - flags &= ~(FAULT_FLAG_ALLOW_RETRY | -FAULT_FLAG_RETRY_NOWAIT ); + flags &= ~FAULT_FLAG_RETRY_NOWAIT ; flags |=FAULT_FLAG_TRIED ;down_read (&mm->mmap_sem); goto retry;
arch/sh/mm/fault.c renamed from arch/sh/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -481,7 +481,6 @@ good_area: regs, address); }if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/*
arch/sparc/mm/fault_32.c renamed from arch/sparc/mm/fault_32.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -261,7 +261,6 @@ good_area: 1, regs, address); }if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
arch/sparc/mm/fault_64.c renamed from arch/sparc/mm/fault_64.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -449,7 +449,6 @@ good_area: 1, regs, address); }if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
arch/um/kernel/trap.c renamed from arch/um/kernel/trap.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -97,7 +97,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry;
arch/unicore32/mm/fault.c renamed from arch/unicore32/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +1 -3
@@ -259,9 +259,7 @@ retry:else tsk->min_flt++;if (fault &VM_FAULT_RETRY ) { -/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk -* of starvation. */ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; + flags |=FAULT_FLAG_TRIED ; goto retry; } }
arch/x86/mm/fault.c renamed from arch/x86/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -2
@@ -1479,8 +1479,6 @@ good_area:*/ if (unlikely ((fault &VM_FAULT_RETRY ) && (flags &FAULT_FLAG_ALLOW_RETRY ))) { -/* Retry at most once */ - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ; goto retry; }
arch/xtensa/mm/fault.c renamed from arch/xtensa/mm/fault.c~mm-allow-vm_fault_retry-for-multiple-times +0 -1
@@ -128,7 +128,6 @@ good_area:else current->min_flt++;if (fault &VM_FAULT_RETRY ) { - flags &= ~FAULT_FLAG_ALLOW_RETRY ; flags |=FAULT_FLAG_TRIED ;/* No need to up_read(&mm->mmap_sem) as we would
drivers/gpu/drm/ttm/ttm_bo_vm.c renamed from drivers/gpu/drm/ttm/ttm_bo_vm.c~mm-allow-vm_fault_retry-for-multiple-times +9 -3
@@ -59,9 +59,10 @@ static vm_fault_t ttm_bo_vm_fault_idle(s/* * If possible, avoid waiting for GPU with mmap_sem -* held. +* held. We only do this if the fault allows retry and this +* is the first attempt. */ -if (vmf->flags &FAULT_FLAG_ALLOW_RETRY ) { +if (fault_flag_allow_retry_first (vmf->flags)) { ret =VM_FAULT_RETRY ;if (vmf->flags &FAULT_FLAG_RETRY_NOWAIT ) goto out_unlock;
@@ -135,7 +136,12 @@ vm_fault_t ttm_bo_vm_reserve(struct ttm_* for the buffer to become unreserved. */ if (unlikely (!dma_resv_trylock (bo->base.resv))) { -if (vmf->flags &FAULT_FLAG_ALLOW_RETRY ) { +/* +* If the fault allows retry and this is the first +* fault attempt, we try to release the mmap_sem +* before waiting +*/ +if (fault_flag_allow_retry_first (vmf->flags)) {if (!(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) {ttm_bo_get (bo);up_read (&vmf->vma->vm_mm->mmap_sem);
include/linux/mm.h renamed from include/linux/mm.h~mm-allow-vm_fault_retry-for-multiple-times +37 -0
@@ -394,6 +394,25 @@ extern pgprot_t protection_map[16];* @FAULT_FLAG_REMOTE: The fault is not for current task/mm. * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. +* +* About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify +* whether we would allow page faults to retry by specifying these two +* fault flags correctly. Currently there can be three legal combinations: +* +* (a) ALLOW_RETRY and !TRIED: this means the page fault allows retry, and +* this is the first try +* +* (b) ALLOW_RETRY and TRIED: this means the page fault allows retry, and +* we've already tried at least once +* +* (c) !ALLOW_RETRY and !TRIED: this means the page fault does not allow retry +* +* The unlisted combination (!ALLOW_RETRY && TRIED) is illegal and should never +* be used. Note that page faults can be allowed to retry for multiple times, +* in which case we'll have an initial fault with flags (a) then later on +* continuous faults with flags (b). We should always try to detect pending +* signals before a retry to make sure the continuous page faults can still be +* interrupted if necessary. */ #define FAULT_FLAG_WRITE 0x01#define FAULT_FLAG_MKWRITE 0x02
@@ -414,6 +433,24 @@ extern pgprot_t protection_map[16]; FAULT_FLAG_KILLABLE | \ FAULT_FLAG_INTERRUPTIBLE) +/** +* fault_flag_allow_retry_first - check ALLOW_RETRY the first time +* +* This is mostly used for places where we want to try to avoid taking +* the mmap_sem for too long a time when waiting for another condition +* to change, in which case we can try to be polite to release the +* mmap_sem in the first round to avoid potential starvation of other +* processes that would also want the mmap_sem. +* +* Return: true if the page fault allows retry and this is the first +* attempt of the fault handling; false otherwise. +*/ +static inline bool fault_flag_allow_retry_first (unsigned int flags) +{ +return (flags &FAULT_FLAG_ALLOW_RETRY ) && + (!(flags &FAULT_FLAG_TRIED )); +} +#define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \ { FAULT_FLAG_MKWRITE, "MKWRITE" }, \
mm/filemap.c renamed from mm/filemap.c~mm-allow-vm_fault_retry-for-multiple-times +1 -1
@@ -1386,7 +1386,7 @@ EXPORT_SYMBOL_GPL(__lock_page_killable);int __lock_page_or_retry (struct page *page,struct mm_struct *mm,unsigned int flags) { -if (flags &FAULT_FLAG_ALLOW_RETRY ) { +if (fault_flag_allow_retry_first (flags)) {/* * CAUTION! In this case, mmap_sem is not released * even though return 0.
mm/internal.h renamed from mm/internal.h~mm-allow-vm_fault_retry-for-multiple-times +3 -3
@@ -377,10 +377,10 @@ static inline struct file *maybe_unlock_/* * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or * anything, so we only pin the file and drop the mmap_sem if only -* FAULT_FLAG_ALLOW_RETRY is set. +* FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt. */ -if ((flags & (FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT )) == -FAULT_FLAG_ALLOW_RETRY ) { +if (fault_flag_allow_retry_first (flags) && + !(flags &FAULT_FLAG_RETRY_NOWAIT )) { fpin =get_file (vmf->vma->vm_file);up_read (&vmf->vma->vm_mm->mmap_sem); }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-gup-allow-vm_fault_retry-for-multiple-times.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup: allow VM_FAULT_RETRY for multiple times has been added to the -mm tree. Its filename is mm-gup-allow-vm_fault_retry-for-multiple-times.patch
The patch titled
Subject: mm/gup: allow VM_FAULT_RETRY for multiple times
has been added to the -mm tree. Its filename is
mm-gup-allow-vm_fault_retry-for-multiple-times.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-allow-vm_fault_retry-for-multiple-times.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-allow-vm_fault_retry-for-multiple-times.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm/gup: allow VM_FAULT_RETRY for multiple times
This is the gup counterpart of the change that allows the VM_FAULT_RETRY to happen for more than once. One thing to mention is that we must check the fatal signal here before retry because the GUP can be interrupted by that, otherwise we can loop forever.
---
mm/gup.c | 27 +++++++++++++++++++++------ mm/hugetlb.c | 6 ++++-- 2 files changed, 25 insertions(+), 8 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-allow-vm_fault_retry-for-multiple-times +21 -6
@@ -861,7 +861,10 @@ static int faultin_page(struct task_struif (*flags &FOLL_NOWAIT ) fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;if (*flags &FOLL_TRIED ) { -VM_WARN_ON_ONCE (fault_flags &FAULT_FLAG_ALLOW_RETRY ); +/* +* Note: FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_TRIED +* can co-exist +*/ fault_flags |=FAULT_FLAG_TRIED ; }
@@ -1221,7 +1224,6 @@ retry:down_read (&mm->mmap_sem);if (!(fault_flags &FAULT_FLAG_TRIED )) { *unlocked = true; - fault_flags &= ~FAULT_FLAG_ALLOW_RETRY ; fault_flags |=FAULT_FLAG_TRIED ; goto retry; }
@@ -1305,17 +1307,30 @@ static __always_inline long __get_user_pif (likely (pages)) pages += ret; start += ret <<PAGE_SHIFT ; + lock_dropped = true; +retry:/* * Repeat on the address that fired VM_FAULT_RETRY -* without FAULT_FLAG_ALLOW_RETRY but with -* FAULT_FLAG_TRIED. +* with both FAULT_FLAG_ALLOW_RETRY and +* FAULT_FLAG_TRIED. Note that GUP can be interrupted +* by fatal signals, so we need to check it before we +* start trying again otherwise it can loop forever. */ + +if (fatal_signal_pending (current)) +break ; + *locked =1 ; - lock_dropped = true;down_read (&mm->mmap_sem); + ret =__get_user_pages (tsk, mm, start,1 , flags |FOLL_TRIED , - pages,NULL ,NULL ); + pages,NULL , locked); +if (!*locked) { +/* Continue to retry until we succeeded */ +BUG_ON (ret !=0 ); + goto retry; + }if (ret !=1 ) {BUG_ON (ret >1 );if (!pages_done)
mm/hugetlb.c renamed from mm/hugetlb.c~mm-gup-allow-vm_fault_retry-for-multiple-times +4 -2
@@ -4349,8 +4349,10 @@ long follow_hugetlb_page(struct mm_struc fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;if (flags &FOLL_TRIED ) { -VM_WARN_ON_ONCE (fault_flags & -FAULT_FLAG_ALLOW_RETRY ); +/* +* Note: FAULT_FLAG_ALLOW_RETRY and +* FAULT_FLAG_TRIED can co-exist +*/ fault_flags |=FAULT_FLAG_TRIED ; } ret =hugetlb_fault (mm, vma, vaddr, fault_flags);
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-gup-allow-to-react-to-fatal-signals.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/gup: allow to react to fatal signals has been added to the -mm tree. Its filename is mm-gup-allow-to-react-to-fatal-signals.patch
The patch titled
Subject: mm/gup: allow to react to fatal signals
has been added to the -mm tree. Its filename is
mm-gup-allow-to-react-to-fatal-signals.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-gup-allow-to-react-to-fatal-signals.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-gup-allow-to-react-to-fatal-signals.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm/gup: allow to react to fatal signals
The existing gup code does not react to the fatal signals in many code paths. For example, in one retry path of gup we're still using down_read() rather than down_read_killable(). Also, when doing page faults we don't pass in FAULT_FLAG_KILLABLE as well, which means that within the faulting process we'll wait in non-killable way as well. These were spotted by Linus during the code review of some other patches.
Let's allow the gup code to react to fatal signals to improve the responsiveness of threads when during gup and being killed.
---
mm/gup.c | 12 +++++++++--- mm/hugetlb.c | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-allow-to-react-to-fatal-signals +9 -3
@@ -857,7 +857,7 @@ static int faultin_page(struct task_struif (*flags &FOLL_REMOTE ) fault_flags |=FAULT_FLAG_REMOTE ;if (locked) - fault_flags |=FAULT_FLAG_ALLOW_RETRY ; + fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ;if (*flags &FOLL_NOWAIT ) fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;if (*flags &FOLL_TRIED ) {
@@ -1200,7 +1200,7 @@ int fixup_user_fault(struct task_struct address =untagged_addr (address);if (unlocked) - fault_flags |=FAULT_FLAG_ALLOW_RETRY ; + fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ; retry: vma =find_extend_vma (mm, address);
@@ -1322,7 +1322,13 @@ retry:break ; *locked =1 ; -down_read (&mm->mmap_sem); + ret =down_read_killable (&mm->mmap_sem); +if (ret) { +BUG_ON (ret >0 ); +if (!pages_done) + pages_done = ret; +break ; + } ret =__get_user_pages (tsk, mm, start,1 , flags |FOLL_TRIED , pages,NULL , locked);
mm/hugetlb.c renamed from mm/hugetlb.c~mm-gup-allow-to-react-to-fatal-signals +2 -1
@@ -4344,7 +4344,8 @@ long follow_hugetlb_page(struct mm_strucif (flags &FOLL_WRITE ) fault_flags |=FAULT_FLAG_WRITE ;if (locked) - fault_flags |=FAULT_FLAG_ALLOW_RETRY ; + fault_flags |=FAULT_FLAG_ALLOW_RETRY | +FAULT_FLAG_KILLABLE ;if (flags &FOLL_NOWAIT ) fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/userfaultfd: honor FAULT_FLAG_KILLABLE in fault path has been added to the -mm tree. Its filename is mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch
The patch titled
Subject: mm/userfaultfd: honor FAULT_FLAG_KILLABLE in fault path
has been added to the -mm tree. Its filename is
mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm/userfaultfd: honor FAULT_FLAG_KILLABLE in fault path
Userfaultfd fault path was by default killable even if the caller does not have FAULT_FLAG_KILLABLE. That makes sense before in that when with gup we don't have FAULT_FLAG_KILLABLE properly set before. Now after previous patch we've got FAULT_FLAG_KILLABLE applied even for gup code so it should also make sense to let userfaultfd to honor the FAULT_FLAG_KILLABLE.
Because we're unconditionally setting FAULT_FLAG_KILLABLE in gup code right now, this patch should have no functional change. It also cleaned the code a little bit by introducing some helpers.
---
fs/userfaultfd.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~mm-userfaultfd-honor-fault_flag_killable-in-fault-path +28 -8
@@ -334,6 +334,30 @@ out:return ret; } +/* Should pair with userfaultfd_signal_pending() */ +static inline long userfaultfd_get_blocking_state (unsigned int flags) +{ +if (flags &FAULT_FLAG_INTERRUPTIBLE ) +return TASK_INTERRUPTIBLE ; + +if (flags &FAULT_FLAG_KILLABLE ) +return TASK_KILLABLE ; + +return TASK_UNINTERRUPTIBLE ; +} + +/* Should pair with userfaultfd_get_blocking_state() */ +static inline bool userfaultfd_signal_pending (unsigned int flags) +{ +if (flags &FAULT_FLAG_INTERRUPTIBLE ) +return signal_pending (current); + +if (flags &FAULT_FLAG_KILLABLE ) +return fatal_signal_pending (current); + +return false; +} +/* * The locking rules involved in returning VM_FAULT_RETRY depending on * FAULT_FLAG_ALLOW_RETRY, FAULT_FLAG_RETRY_NOWAIT and
@@ -355,7 +379,7 @@ vm_fault_t handle_userfault(struct vm_fastruct userfaultfd_ctx *ctx;struct userfaultfd_wait_queue uwq;vm_fault_t ret =VM_FAULT_SIGBUS ; -bool must_wait, return_to_userland; +bool must_wait;long blocking_state;/*
@@ -462,9 +486,7 @@ vm_fault_t handle_userfault(struct vm_fa uwq.ctx = ctx; uwq.waken = false; - return_to_userland = vmf->flags &FAULT_FLAG_INTERRUPTIBLE ; - blocking_state = return_to_userland ?TASK_INTERRUPTIBLE : -TASK_KILLABLE ; + blocking_state =userfaultfd_get_blocking_state (vmf->flags);spin_lock_irq (&ctx->fault_pending_wqh.lock);/*
@@ -490,8 +512,7 @@ vm_fault_t handle_userfault(struct vm_faup_read (&mm->mmap_sem);if (likely (must_wait && !READ_ONCE (ctx->released) && - (return_to_userland ? !signal_pending (current) : - !fatal_signal_pending (current)))) { + !userfaultfd_signal_pending (vmf->flags))) {wake_up_poll (&ctx->fd_wqh,EPOLLIN );schedule (); ret |=VM_FAULT_MAJOR ;
@@ -513,8 +534,7 @@ vm_fault_t handle_userfault(struct vm_faset_current_state (blocking_state);if (READ_ONCE (uwq.waken) ||READ_ONCE (ctx->released) || - (return_to_userland ?signal_pending (current) : -fatal_signal_pending (current))) +userfaultfd_signal_pending (vmf->flags))break ;schedule (); }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-add-helper-for-writeprotect-check.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: add helper for writeprotect check has been added to the -mm tree. Its filename is userfaultfd-wp-add-helper-for-writeprotect-check.patch
The patch titled
Subject: userfaultfd: wp: add helper for writeprotect check
has been added to the -mm tree. Its filename is
userfaultfd-wp-add-helper-for-writeprotect-check.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-add-helper-for-writeprotect-check.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-add-helper-for-writeprotect-check.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Shaohua Li <[email protected]>
Subject: userfaultfd: wp: add helper for writeprotect check
Patch series "userfaultfd: write protection support", v6.
Overview
========
The uffd-wp work was initialized by Shaohua Li [1], and later continued by Andrea [2]. This series is based upon Andrea's latest userfaultfd tree, and it is a continuous works from both Shaohua and Andrea. Many of the follow up ideas come from Andrea too.
Besides the old MISSING register mode of userfaultfd, the new uffd-wp support provides another alternative register mode called UFFDIO_REGISTER_MODE_WP that can be used to listen to not only missing page faults but also write protection page faults, or even they can be registered together. At the same time, the new feature also provides a new userfaultfd ioctl called UFFDIO_WRITEPROTECT which allows the userspace to write protect a range or memory or fixup write permission of faulted pages.
Please refer to the document patch "userfaultfd: wp:UFFDIO_REGISTER_MODE_WP documentation update" for more information on the new interface and what it can do.
The major workflow of an uffd-wp program should be:
1. Register a memory region with WP mode using UFFDIO_REGISTER_MODE_WP
2. Write protect part of the whole registered region using UFFDIO_WRITEPROTECT, passing in UFFDIO_WRITEPROTECT_MODE_WP to show that we want to write protect the range.
3. Start a working thread that modifies the protected pages, meanwhile listening to UFFD messages.
4. When a write is detected upon the protected range, page fault happens, a UFFD message will be generated and reported to the page fault handling thread
5. The page fault handler thread resolves the page fault using the new UFFDIO_WRITEPROTECT ioctl, but this time passing in !UFFDIO_WRITEPROTECT_MODE_WP instead showing that we want to recover the write permission. Before this operation, the fault handler thread can do anything it wants, e.g., dumps the page to a persistent storage.
6. The worker thread will continue running with the correctly applied write permission from step 5.
Currently there are already two projects that are based on this new userfaultfd feature.
QEMU Live Snapshot: The project provides a way to allow the QEMU
hypervisor to take snapshot of VMs without stopping the VM [3].
LLNL umap library: The project provides a mmap-like interface and
"allow to have an application specific buffer of pages cached from a large file, i.e. out-of-core execution using memory map" [4][5].
Before posting the patchset, this series was smoke tested against QEMU live snapshot and the LLNL umap library (by doing parallel quicksort using 128 sorting threads + 80 uffd servicing threads). My sincere thanks to Marty Mcfadden and Denis Plotnikov for the help along the way.
TODO
====
- hugetlbfs/shmem support
- performance
- more architectures
- cooperate with mprotect()-allowed processes (???)
- ...
References
==========
[1] https://lwn.net/Articles/666187/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/andrea/aa.git/log/?h=userfault
[3] https://github.com/denis-plotnikov/qemu/commits/background-snapshot-kvm
[4] https://github.com/LLNL/umap
[5] https://llnl-umap.readthedocs.io/en/develop/
[6] https://git.kernel.org/pub/scm/linux/kernel/git/andrea/aa.git/commit/?h=userfault&id=b245ecf6cf59156966f3da6e6b674f6695a5ffa5
[7] https://lkml.org/lkml/2018/11/21/370
[8] https://lkml.org/lkml/2018/12/30/64
This patch (of 19):
Add helper for writeprotect check. Will use it later.
---
include/linux/userfaultfd_k.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/userfaultfd_k.h renamed from include/linux/userfaultfd_k.h~userfaultfd-wp-add-helper-for-writeprotect-check +10 -0
@@ -52,6 +52,11 @@ static inline bool userfaultfd_missing(sreturn vma->vm_flags &VM_UFFD_MISSING ; } +static inline bool userfaultfd_wp (struct vm_area_struct *vma) +{ +return vma->vm_flags &VM_UFFD_WP ; +} +static inline bool userfaultfd_armed (struct vm_area_struct *vma) {return vma->vm_flags & (VM_UFFD_MISSING |VM_UFFD_WP );
@@ -95,6 +100,11 @@ static inline bool userfaultfd_missing(s {return false; } + +static inline bool userfaultfd_wp (struct vm_area_struct *vma) +{ +return false; +}static inline bool userfaultfd_armed (struct vm_area_struct *vma) {
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-add-helper-for-writeprotect-check.patch userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
+ userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: hook userfault handler to write protection fault has been added to the -mm tree. Its filename is…
The patch titled
Subject: userfaultfd: wp: hook userfault handler to write protection fault
has been added to the -mm tree. Its filename is
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: wp: hook userfault handler to write protection fault
There are several cases write protection fault happens. It could be a write to zero page, swaped page or userfault write protected page. When the fault happens, there is no way to know if userfault write protect the page before. Here we just blindly issue a userfault notification for vma with VM_UFFD_WP regardless if app write protects it yet. Application should be ready to handle such wp fault.
In the swapin case, always swapin as readonly. This will cause false positive userfaults. We need to decide later if to eliminate them with a flag like soft-dirty in the swap entry (see _PAGE_SWP_SOFT_DIRTY).
hugetlbfs wouldn't need to worry about swapouts but and tmpfs would be handled by a swap entry bit like anonymous memory.
The main problem with no easy solution to eliminate the false positives, will be if/when userfaultfd is extended to real filesystem pagecache. When the pagecache is freed by reclaim we can't leave the radix tree pinned if the inode and in turn the radix tree is reclaimed as well.
The estimation is that full accuracy and lack of false positives could be easily provided only to anonymous memory (as long as there's no fork or as long as MADV_DONTFORK is used on the userfaultfd anonymous range) tmpfs and hugetlbfs, it's most certainly worth to achieve it but in a later incremental patch.
---
mm/memory.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/memory.c renamed from mm/memory.c~userfaultfd-wp-hook-userfault-handler-to-write-protection-fault +9 -1
@@ -2752,6 +2752,11 @@ static vm_fault_t do_wp_page(struct vm_f {struct vm_area_struct *vma = vmf->vma; +if (userfaultfd_wp (vma)) { +pte_unmap_unlock (vmf->pte, vmf->ptl); +return handle_userfault (vmf,VM_UFFD_WP ); + } + vmf->page =vm_normal_page (vma, vmf->address, vmf->orig_pte);if (!vmf->page) {/*
@@ -3949,8 +3954,11 @@ static inline vm_fault_t create_huge_pmd/* `inline' is required to avoid gcc 4.1.2 build error */ static inline vm_fault_t wp_huge_pmd (struct vm_fault *vmf,pmd_t orig_pmd) { -if (vma_is_anonymous (vmf->vma)) +if (vma_is_anonymous (vmf->vma)) { +if (userfaultfd_wp (vmf->vma)) +return handle_userfault (vmf,VM_UFFD_WP );return do_huge_pmd_wp_page (vmf, orig_pmd); + }if (vmf->vma->vm_ops->huge_fault)return vmf->vma->vm_ops->huge_fault (vmf,PE_SIZE_PMD );
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch userfaultfd-wp-add-uffdio_copy_mode_wp.patch userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
+ userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: add WP pagetable tracking to x86 has been added to the -mm tree. Its filename is userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch
The patch titled
Subject: userfaultfd: wp: add WP pagetable tracking to x86
has been added to the -mm tree. Its filename is
userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: wp: add WP pagetable tracking to x86
Accurate userfaultfd WP tracking is possible by tracking exactly which virtual memory ranges were writeprotected by userland. We can't relay only on the RW bit of the mapped pagetable because that information is destroyed by fork() or KSM or swap. If we were to relay on that, we'd need to stay on the safe side and generate false positive wp faults for every swapped out page.
---
arch/x86/Kconfig | 1 arch/x86/include/asm/pgtable.h | 52 +++++++++++++++++++++++++ arch/x86/include/asm/pgtable_64.h | 8 +++ arch/x86/include/asm/pgtable_types.h | 11 ++++- include/asm-generic/pgtable.h | 1 include/asm-generic/pgtable_uffd.h | 51 ++++++++++++++++++++++++ init/Kconfig | 5 ++ 7 files changed, 127 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable_64.h renamed from arch/x86/include/asm/pgtable_64.h~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +7 -1
@@ -189,7 +189,7 @@ extern void sync_global_pgds(unsigned lo* * | ... | 11| 10| 9|8|7|6|5| 4| 3|2| 1|0| <- bit number * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U| W|P| <- bit names -* | TYPE (59-63) | ~OFFSET (9-58) |0|0|X|X| X| X|X|SD|0| <- swp entry +* | TYPE (59-63) | ~OFFSET (9-58) |0|0|X|X| X| X|F|SD|0| <- swp entry * * G (8) is aliased and used as a PROT_NONE indicator for * !present ptes. We need to start storing swap entries above
@@ -197,9 +197,15 @@ extern void sync_global_pgds(unsigned lo* erratum where they can be incorrectly set by hardware on * non-present PTEs. * +* SD Bits 1-4 are not used in non-present format and available for +* special use described below: +* * SD (1) in swp entry is used to store soft dirty bit, which helps us * remember soft dirty over page migration * +* F (2) in swp entry is used to record when a pagetable is +* writeprotected by userfaultfd WP support. +* * Bit 7 in swp entry should be 0 because pmd_present checks not only P, * but also L and G. *
arch/x86/include/asm/pgtable.h renamed from arch/x86/include/asm/pgtable.h~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +52 -0
76 lines not on this page · raw message
arch/x86/include/asm/pgtable_types.h renamed from arch/x86/include/asm/pgtable_types.h~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +10 -1
@@ -32,6 +32,7 @@#define _PAGE_BIT_SPECIAL _PAGE_BIT_SOFTW1#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SOFTW1 +#define _PAGE_BIT_UFFD_WP _PAGE_BIT_SOFTW2/* userfaultfd wrprotected */ #define _PAGE_BIT_SOFT_DIRTY _PAGE_BIT_SOFTW3/* software dirty tracking */ #define _PAGE_BIT_DEVMAP _PAGE_BIT_SOFTW4
@@ -100,6 +101,14 @@#define _PAGE_SWP_SOFT_DIRTY (_AT(pteval_t, 0))#endif +#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP +#define _PAGE_UFFD_WP (_AT(pteval_t, 1) << _PAGE_BIT_UFFD_WP) +#define _PAGE_SWP_UFFD_WP _PAGE_USER +#else +#define _PAGE_UFFD_WP (_AT(pteval_t, 0)) +#define _PAGE_SWP_UFFD_WP (_AT(pteval_t, 0)) +#endif +#if defined(CONFIG_X86_64 ) || defined(CONFIG_X86_PAE )#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)#define _PAGE_DEVMAP (_AT(u64, 1) << _PAGE_BIT_DEVMAP)
@@ -118,7 +127,7 @@*/ #define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP) + _PAGE_SOFT_DIRTY | _PAGE_DEVMAP | _PAGE_UFFD_WP)#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)/*
arch/x86/Kconfig renamed from arch/x86/Kconfig~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +1 -0
@@ -230,6 +230,7 @@ config X86 select VIRT_TO_BUS select X86_FEATURE_NAMES if PROC_FS select PROC_PID_ARCH_STATUS if PROC_FS + select HAVE_ARCH_USERFAULTFD_WP if USERFAULTFD config INSTRUCTION_DECODER def_bool y
include/asm-generic/pgtable.h renamed from include/asm-generic/pgtable.h~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +1 -0
@@ -10,6 +10,7 @@#include <linux/mm_types.h> #include <linux/bug.h> #include <linux/errno.h> +#include <asm-generic/pgtable_uffd.h> #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \ defined(__PAGETABLE_PMD_FOLDED) !=CONFIG_PGTABLE_LEVELS
include/asm-generic/pgtable_uffd.h new file +51 -0
51 lines not on this page · raw message
init/Kconfig renamed from init/Kconfig~userfaultfd-wp-add-wp-pagetable-tracking-to-x86 +5 -0
@@ -1553,6 +1553,11 @@ config ADVISE_SYSCALLS applications use these syscalls, you can disable this option to save space. +config HAVE_ARCH_USERFAULTFD_WP + bool + help + Arch has userfaultfd write protection support + config MEMBARRIER bool "Enable membarrier() system call" if EXPERT default y
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch userfaultfd-wp-add-uffdio_copy_mode_wp.patch userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
+ userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers has been added to the -mm tree. Its filename is userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch
The patch titled
Subject: userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers
has been added to the -mm tree. Its filename is
userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers
Implement helpers methods to invoke userfaultfd wp faults more
selectively: not only when a wp fault triggers on a vma with vma->vm_flags VM_UFFD_WP set, but only if the _PAGE_UFFD_WP bit is set in the pagetable too.
---
include/linux/userfaultfd_k.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
include/linux/userfaultfd_k.h renamed from include/linux/userfaultfd_k.h~userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers +27 -0
@@ -14,6 +14,8 @@#include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */ #include <linux/fcntl.h> +#include <linux/mm.h> +#include <asm-generic/pgtable_uffd.h> /* * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
@@ -57,6 +59,18 @@ static inline bool userfaultfd_wp(structreturn vma->vm_flags &VM_UFFD_WP ; } +static inline bool userfaultfd_pte_wp (struct vm_area_struct *vma, +pte_t pte) +{ +return userfaultfd_wp (vma) &&pte_uffd_wp (pte); +} + +static inline bool userfaultfd_huge_pmd_wp (struct vm_area_struct *vma, +pmd_t pmd) +{ +return userfaultfd_wp (vma) &&pmd_uffd_wp (pmd); +} +static inline bool userfaultfd_armed (struct vm_area_struct *vma) {return vma->vm_flags & (VM_UFFD_MISSING |VM_UFFD_WP );
@@ -106,6 +120,19 @@ static inline bool userfaultfd_wp(structreturn false; } +static inline bool userfaultfd_pte_wp (struct vm_area_struct *vma, +pte_t pte) +{ +return false; +} + +static inline bool userfaultfd_huge_pmd_wp (struct vm_area_struct *vma, +pmd_t pmd) +{ +return false; +} + +static inline bool userfaultfd_armed (struct vm_area_struct *vma) {return false;
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch userfaultfd-wp-add-uffdio_copy_mode_wp.patch userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
+ userfaultfd-wp-add-uffdio_copy_mode_wp.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: add UFFDIO_COPY_MODE_WP has been added to the -mm tree. Its filename is userfaultfd-wp-add-uffdio_copy_mode_wp.patch
The patch titled
Subject: userfaultfd: wp: add UFFDIO_COPY_MODE_WP
has been added to the -mm tree. Its filename is
userfaultfd-wp-add-uffdio_copy_mode_wp.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-add-uffdio_copy_mode_wp.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-add-uffdio_copy_mode_wp.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: wp: add UFFDIO_COPY_MODE_WP
This allows UFFDIO_COPY to map pages write-protected.
[[email protected]: switch to VM_WARN_ON_ONCE in mfill_atomic_pte; add brackets
around "dst_vma->vm_flags & VM_WRITE"; fix wordings in comments and commit messages]
---
fs/userfaultfd.c | 5 ++-- include/linux/userfaultfd_k.h | 2 - include/uapi/linux/userfaultfd.h | 11 ++++---- mm/userfaultfd.c | 36 ++++++++++++++++++++--------- 4 files changed, 35 insertions(+), 19 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-wp-add-uffdio_copy_mode_wp +3 -2
@@ -1724,11 +1724,12 @@ static int userfaultfd_copy(struct userf ret = -EINVAL ;if (uffdio_copy.src + uffdio_copy.len <= uffdio_copy.src) goto out; -if (uffdio_copy.mode & ~UFFDIO_COPY_MODE_DONTWAKE ) +if (uffdio_copy.mode & ~(UFFDIO_COPY_MODE_DONTWAKE |UFFDIO_COPY_MODE_WP )) goto out;if (mmget_not_zero (ctx->mm)) { ret =mcopy_atomic (ctx->mm, uffdio_copy.dst, uffdio_copy.src, - uffdio_copy.len, &ctx->mmap_changing); + uffdio_copy.len, &ctx->mmap_changing, + uffdio_copy.mode);mmput (ctx->mm); }else {return -ESRCH ;
include/linux/userfaultfd_k.h renamed from include/linux/userfaultfd_k.h~userfaultfd-wp-add-uffdio_copy_mode_wp +1 -1
@@ -36,7 +36,7 @@ extern vm_fault_t handle_userfault(strucextern ssize_t mcopy_atomic (struct mm_struct *dst_mm,unsigned long dst_start,unsigned long src_start,unsigned long len, -bool *mmap_changing); +bool *mmap_changing,__u64 mode); extern ssize_t mfill_zeropage(struct mm_struct *dst_mm, unsigned long dst_start, unsigned long len,
include/uapi/linux/userfaultfd.h renamed from include/uapi/linux/userfaultfd.h~userfaultfd-wp-add-uffdio_copy_mode_wp +6 -5
@@ -203,13 +203,14 @@ struct uffdio_copy {__u64 dst;__u64 src;__u64 len; +#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)/* -* There will be a wrprotection flag later that allows to map -* pages wrprotected on the fly. And such a flag will be -* available if the wrprotection ioctl are implemented for the -* range according to the uffdio_register.ioctls. +* UFFDIO_COPY_MODE_WP will map the page write protected on +* the fly. UFFDIO_COPY_MODE_WP is available only if the +* write protected ioctl is implemented for the range +* according to the uffdio_register.ioctls. */ -#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0) +#define UFFDIO_COPY_MODE_WP ((__u64)1<<1)__u64 mode;/*
mm/userfaultfd.c renamed from mm/userfaultfd.c~userfaultfd-wp-add-uffdio_copy_mode_wp +25 -11
@@ -53,7 +53,8 @@ static int mcopy_atomic_pte(struct mm_ststruct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, - struct page **pagep) + struct page **pagep, + bool wp_copy) { struct mem_cgroup *memcg;pte_t _dst_pte, *dst_pte;
@@ -99,9 +100,9 @@ static int mcopy_atomic_pte(struct mm_stif (mem_cgroup_try_charge (page, dst_mm,GFP_KERNEL , &memcg, false)) goto out_release; - _dst_pte =mk_pte (page, dst_vma->vm_page_prot); -if (dst_vma->vm_flags &VM_WRITE ) - _dst_pte =pte_mkwrite (pte_mkdirty (_dst_pte)); + _dst_pte =pte_mkdirty (mk_pte (page, dst_vma->vm_page_prot)); +if ((dst_vma->vm_flags &VM_WRITE ) && !wp_copy) + _dst_pte =pte_mkwrite (_dst_pte); dst_pte =pte_offset_map_lock (dst_mm, dst_pmd, dst_addr, &ptl);if (dst_vma->vm_file) {
@@ -415,7 +416,8 @@ static __always_inline ssize_t mfill_atounsigned long dst_addr, unsigned long src_addr, struct page **page, - bool zeropage) + bool zeropage, + bool wp_copy) { ssize_t err;
@@ -432,11 +434,13 @@ static __always_inline ssize_t mfill_atoif (!(dst_vma->vm_flags &VM_SHARED )) {if (!zeropage) err =mcopy_atomic_pte (dst_mm, dst_pmd, dst_vma, - dst_addr, src_addr, page); + dst_addr, src_addr, page, + wp_copy);else err =mfill_zeropage_pte (dst_mm, dst_pmd, dst_vma, dst_addr); }else { +VM_WARN_ON_ONCE (wp_copy);if (!zeropage) err = shmem_mcopy_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr,
@@ -454,7 +458,8 @@ static __always_inline ssize_t __mcopy_aunsigned long src_start, unsigned long len, bool zeropage, - bool *mmap_changing) + bool *mmap_changing, + __u64 mode) { struct vm_area_struct *dst_vma;ssize_t err;
@@ -462,6 +467,7 @@ static __always_inline ssize_t __mcopy_aunsigned long src_addr, dst_addr;long copied;struct page *page; +bool wp_copy;/* * Sanitize the command parameters:
@@ -508,6 +514,14 @@ retry: goto out_unlock;/* +* validate 'mode' now that we know the dst_vma: don't allow +* a wrprotect copy if the userfaultfd didn't register as WP. +*/ + wp_copy = mode &UFFDIO_COPY_MODE_WP ; +if (wp_copy && !(dst_vma->vm_flags &VM_UFFD_WP )) + goto out_unlock; + +/* * If this is a HUGETLB vma, pass off to appropriate routine */ if (is_vm_hugetlb_page (dst_vma))
@@ -562,7 +576,7 @@ retry:BUG_ON (pmd_trans_huge (*dst_pmd)); err =mfill_atomic_pte (dst_mm, dst_pmd, dst_vma, dst_addr, - src_addr, &page, zeropage); + src_addr, &page, zeropage, wp_copy);cond_resched ();if (unlikely (err == -ENOENT )) {
@@ -609,14 +623,14 @@ out:ssize_t mcopy_atomic (struct mm_struct *dst_mm,unsigned long dst_start,unsigned long src_start,unsigned long len, -bool *mmap_changing) +bool *mmap_changing,__u64 mode) {return __mcopy_atomic (dst_mm, dst_start, src_start, len, false, - mmap_changing); + mmap_changing, mode); }ssize_t mfill_zeropage (struct mm_struct *dst_mm,unsigned long start,unsigned long len,bool *mmap_changing) { -return __mcopy_atomic (dst_mm, start,0 , len, true, mmap_changing); +return __mcopy_atomic (dst_mm, start,0 , len, true, mmap_changing,0 ); }
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch userfaultfd-wp-add-uffdio_copy_mode_wp.patch userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
+ mm-merge-parameters-for-change_protection.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm: merge parameters for change_protection() has been added to the -mm tree. Its filename is mm-merge-parameters-for-change_protection.patch
The patch titled
Subject: mm: merge parameters for change_protection()
has been added to the -mm tree. Its filename is
mm-merge-parameters-for-change_protection.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-merge-parameters-for-change_protection.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-merge-parameters-for-change_protection.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: mm: merge parameters for change_protection()
change_protection() was used by either the NUMA or mprotect() code, there's one parameter for each of the callers (dirty_accountable and prot_numa). Further, these parameters are passed along the calls:
- change_protection_range()
- change_p4d_range()
- change_pud_range()
- change_pmd_range()
- ...
Now we introduce a flag for change_protect() and all these helpers to replace these parameters. Then we can avoid passing multiple parameters multiple times along the way.
More importantly, it'll greatly simplify the work if we want to introduce any new parameters to change_protection(). In the follow up patches, a new parameter for userfaultfd write protection will be introduced.
No functional change at all.
---
include/linux/huge_mm.h | 2 +- include/linux/mm.h | 14 +++++++++++++- mm/huge_memory.c | 3 ++- mm/mempolicy.c | 2 +- mm/mprotect.c | 29 ++++++++++++++++------------- 5 files changed, 33 insertions(+), 17 deletions(-)
include/linux/huge_mm.h renamed from include/linux/huge_mm.h~mm-merge-parameters-for-change_protection +1 -1
@@ -46,7 +46,7 @@ extern bool move_huge_pmd(struct vm_area pmd_t *old_pmd, pmd_t *new_pmd);extern int change_huge_pmd (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,pgprot_t newprot, -int prot_numa); +unsigned long cp_flags);vm_fault_t vmf_insert_pfn_pmd (struct vm_fault *vmf,pfn_t pfn,bool write);vm_fault_t vmf_insert_pfn_pud (struct vm_fault *vmf,pfn_t pfn,bool write);enum transparent_hugepage_flag {
include/linux/mm.h renamed from include/linux/mm.h~mm-merge-parameters-for-change_protection +13 -1
@@ -1770,9 +1770,21 @@ extern unsigned long move_page_tables(st unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len, bool need_rmap_locks); + +/* +* Flags used by change_protection(). For now we make it a bitmap so +* that we can pass in multiple flags just like parameters. However +* for now all the callers are only use one of the flags at the same +* time. +*/ +/* Whether we should allow dirty bit accounting */ +#define MM_CP_DIRTY_ACCT (1UL << 0) +/* Whether this protection change is for NUMA hints */ +#define MM_CP_PROT_NUMA (1UL << 1) +extern unsigned long change_protection (struct vm_area_struct *vma,unsigned long start,unsigned long end,pgprot_t newprot, -int dirty_accountable,int prot_numa); +unsigned long cp_flags);extern int mprotect_fixup (struct vm_area_struct *vma,struct vm_area_struct **pprev,unsigned long start,unsigned long end,unsigned long newflags);
mm/huge_memory.c renamed from mm/huge_memory.c~mm-merge-parameters-for-change_protection +2 -1
@@ -1953,13 +1953,14 @@ bool move_huge_pmd(struct vm_area_struct* - HPAGE_PMD_NR is protections changed and TLB flush necessary */ int change_huge_pmd (struct vm_area_struct *vma,pmd_t *pmd, -unsigned long addr,pgprot_t newprot,int prot_numa) +unsigned long addr,pgprot_t newprot,unsigned long cp_flags) {struct mm_struct *mm = vma->vm_mm;spinlock_t *ptl;pmd_t entry;bool preserve_write;int ret; +bool prot_numa = cp_flags &MM_CP_PROT_NUMA ; ptl =__pmd_trans_huge_lock (pmd, vma);if (!ptl)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-merge-parameters-for-change_protection +1 -1
@@ -627,7 +627,7 @@ unsigned long change_prot_numa(struct vm {int nr_updated; - nr_updated =change_protection (vma, addr, end,PAGE_NONE ,0 ,1 ); + nr_updated =change_protection (vma, addr, end,PAGE_NONE ,MM_CP_PROT_NUMA );if (nr_updated)count_vm_numa_events (NUMA_PTE_UPDATES , nr_updated);
mm/mprotect.c renamed from mm/mprotect.c~mm-merge-parameters-for-change_protection +16 -13
@@ -37,12 +37,14 @@static unsigned long change_pte_range (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t newprot, -int dirty_accountable,int prot_numa) +unsigned long cp_flags) {pte_t *pte, oldpte;spinlock_t *ptl;unsigned long pages =0 ;int target_node =NUMA_NO_NODE ; +bool dirty_accountable = cp_flags &MM_CP_DIRTY_ACCT ; +bool prot_numa = cp_flags &MM_CP_PROT_NUMA ;/* * Can be called with only the mmap_sem for reading by
@@ -188,7 +190,7 @@ static inline int pmd_none_or_clear_bad_static inline unsigned long change_pmd_range (struct vm_area_struct *vma,pud_t *pud,unsigned long addr,unsigned long end, -pgprot_t newprot,int dirty_accountable,int prot_numa) +pgprot_t newprot,unsigned long cp_flags) {pmd_t *pmd;unsigned long next;
@@ -229,7 +231,7 @@ static inline unsigned long change_pmd_r__split_huge_pmd (vma, pmd, addr, false,NULL ); }else {int nr_ptes =change_huge_pmd (vma, pmd, addr, - newprot, prot_numa); + newprot, cp_flags);if (nr_ptes) {if (nr_ptes ==HPAGE_PMD_NR ) {
@@ -244,7 +246,7 @@ static inline unsigned long change_pmd_r/* fall through, the trans huge pmd just split */ } this_pages =change_pte_range (vma, pmd, addr, next, newprot, - dirty_accountable, prot_numa); + cp_flags); pages += this_pages; next:cond_resched ();
@@ -260,7 +262,7 @@ next:static inline unsigned long change_pud_range (struct vm_area_struct *vma,p4d_t *p4d,unsigned long addr,unsigned long end, -pgprot_t newprot,int dirty_accountable,int prot_numa) +pgprot_t newprot,unsigned long cp_flags) {pud_t *pud;unsigned long next;
@@ -272,7 +274,7 @@ static inline unsigned long change_pud_rif (pud_none_or_clear_bad (pud))continue ; pages +=change_pmd_range (vma, pud, addr, next, newprot, - dirty_accountable, prot_numa); + cp_flags); }while (pud++, addr = next, addr != end);return pages;
@@ -280,7 +282,7 @@ static inline unsigned long change_pud_rstatic inline unsigned long change_p4d_range (struct vm_area_struct *vma,pgd_t *pgd,unsigned long addr,unsigned long end, -pgprot_t newprot,int dirty_accountable,int prot_numa) +pgprot_t newprot,unsigned long cp_flags) {p4d_t *p4d;unsigned long next;
@@ -292,7 +294,7 @@ static inline unsigned long change_p4d_rif (p4d_none_or_clear_bad (p4d))continue ; pages +=change_pud_range (vma, p4d, addr, next, newprot, - dirty_accountable, prot_numa); + cp_flags); }while (p4d++, addr = next, addr != end);return pages;
@@ -300,7 +302,7 @@ static inline unsigned long change_p4d_rstatic unsigned long change_protection_range (struct vm_area_struct *vma,unsigned long addr,unsigned long end,pgprot_t newprot, -int dirty_accountable,int prot_numa) +unsigned long cp_flags) {struct mm_struct *mm = vma->vm_mm;pgd_t *pgd;
@@ -317,7 +319,7 @@ static unsigned long change_protection_rif (pgd_none_or_clear_bad (pgd))continue ; pages +=change_p4d_range (vma, pgd, addr, next, newprot, - dirty_accountable, prot_numa); + cp_flags); }while (pgd++, addr = next, addr != end);/* Only flush the TLB if we actually modified any entries: */
@@ -330,14 +332,15 @@ static unsigned long change_protection_runsigned long change_protection (struct vm_area_struct *vma,unsigned long start,unsigned long end,pgprot_t newprot, -int dirty_accountable,int prot_numa) +unsigned long cp_flags) {unsigned long pages;if (is_vm_hugetlb_page (vma)) pages =hugetlb_change_protection (vma, start, end, newprot);else - pages =change_protection_range (vma, start, end, newprot, dirty_accountable, prot_numa); + pages =change_protection_range (vma, start, end, newprot, + cp_flags);return pages; }
@@ -459,7 +462,7 @@ success:vma_set_page_prot (vma);change_protection (vma, start, end, vma->vm_page_prot, - dirty_accountable,0 ); + dirty_accountable ?MM_CP_DIRTY_ACCT :0 );/* * Private VM_LOCKED VMA becoming writable: trigger COW to avoid major
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-apply-_page_uffd_wp-bit.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: apply _PAGE_UFFD_WP bit has been added to the -mm tree. Its filename is userfaultfd-wp-apply-_page_uffd_wp-bit.patch
The patch titled
Subject: userfaultfd: wp: apply _PAGE_UFFD_WP bit
has been added to the -mm tree. Its filename is
userfaultfd-wp-apply-_page_uffd_wp-bit.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-apply-_page_uffd_wp-bit.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-apply-_page_uffd_wp-bit.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: apply _PAGE_UFFD_WP bit
Firstly, introduce two new flags MM_CP_UFFD_WP[_RESOLVE] for change_protection() when used with uffd-wp and make sure the two new flags are exclusively used. Then,
- For MM_CP_UFFD_WP: apply the _PAGE_UFFD_WP bit and remove _PAGE_RW when a range of memory is write protected by uffd
- For MM_CP_UFFD_WP_RESOLVE: remove the _PAGE_UFFD_WP bit and recover _PAGE_RW when write protection is resolved from userspace
And use this new interface in mwriteprotect_range() to replace the old MM_CP_DIRTY_ACCT.
Do this change for both PTEs and huge PMDs. Then we can start to identify which PTE/PMD is write protected by general (e.g., COW or soft dirty tracking), and which is for userfaultfd-wp.
Since we should keep the _PAGE_UFFD_WP when doing pte_modify(), add it into _PAGE_CHG_MASK as well. Meanwhile, since we have this new bit, we can be even more strict when detecting uffd-wp page faults in either do_wp_page() or wp_huge_pmd().
After we're with _PAGE_UFFD_WP, a special case is when a page is both protected by the general COW logic and also userfault-wp. Here the userfault-wp will have higher priority and will be handled first. Only after the uffd-wp bit is cleared on the PTE/PMD will we continue to handle the general COW. These are the steps on what will happen with such a page:
1. CPU accesses write protected shared page (so both protected by general COW and uffd-wp), blocked by uffd-wp first because in do_wp_page we'll handle uffd-wp first, so it has higher priority than general COW.
2. Uffd service thread receives the request, do UFFDIO_WRITEPROTECT to remove the uffd-wp bit upon the PTE/PMD. However here we still keep the write bit cleared. Notify the blocked CPU.
3. The blocked CPU resumes the page fault process with a fault retry, during retry it'll notice it was not with the uffd-wp bit this time but it is still write protected by general COW, then it'll go though the COW path in the fault handler, copy the page, apply write bit where necessary, and retry again.
4. The CPU will be able to access this page with write bit set.
---
include/linux/mm.h | 5 +++++ mm/huge_memory.c | 18 +++++++++++++++++- mm/memory.c | 4 ++-- mm/mprotect.c | 17 +++++++++++++++++ mm/userfaultfd.c | 8 ++++++-- 5 files changed, 47 insertions(+), 5 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~userfaultfd-wp-apply-_page_uffd_wp-bit +5 -0
@@ -1781,6 +1781,11 @@ extern unsigned long move_page_tables(st#define MM_CP_DIRTY_ACCT (1UL << 0)/* Whether this protection change is for NUMA hints */ #define MM_CP_PROT_NUMA (1UL << 1) +/* Whether this change is for write protecting */ +#define MM_CP_UFFD_WP (1UL << 2)/* do wp */ +#define MM_CP_UFFD_WP_RESOLVE (1UL << 3)/* Resolve wp */ +#define MM_CP_UFFD_WP_ALL (MM_CP_UFFD_WP | \ + MM_CP_UFFD_WP_RESOLVE) extern unsigned long change_protection(struct vm_area_struct *vma, unsigned long start, unsigned long end, pgprot_t newprot,
mm/huge_memory.c renamed from mm/huge_memory.c~userfaultfd-wp-apply-_page_uffd_wp-bit +17 -1
@@ -1961,6 +1961,8 @@ int change_huge_pmd(struct vm_area_strucbool preserve_write;int ret;bool prot_numa = cp_flags &MM_CP_PROT_NUMA ; +bool uffd_wp = cp_flags &MM_CP_UFFD_WP ; +bool uffd_wp_resolve = cp_flags &MM_CP_UFFD_WP_RESOLVE ; ptl =__pmd_trans_huge_lock (pmd, vma);if (!ptl)
@@ -2027,6 +2029,17 @@ int change_huge_pmd(struct vm_area_struc entry =pmd_modify (entry, newprot);if (preserve_write) entry =pmd_mk_savedwrite (entry); +if (uffd_wp) { + entry =pmd_wrprotect (entry); + entry =pmd_mkuffd_wp (entry); + }else if (uffd_wp_resolve) { +/* +* Leave the write bit to be handled by PF interrupt +* handler, then things like COW could be properly +* handled. +*/ + entry =pmd_clear_uffd_wp (entry); + } ret =HPAGE_PMD_NR ;set_pmd_at (mm, addr, pmd, entry);BUG_ON (vma_is_anonymous (vma) && !preserve_write &&pmd_write (entry));
@@ -2175,7 +2188,7 @@ static void __split_huge_pmd_locked(strustruct page *page;pgtable_t pgtable;pmd_t old_pmd, _pmd; -bool young, write, soft_dirty, pmd_migration = false; +bool young, write, soft_dirty, pmd_migration = false, uffd_wp = false;unsigned long addr;int i;
@@ -2257,6 +2270,7 @@ static void __split_huge_pmd_locked(stru write =pmd_write (old_pmd); young =pmd_young (old_pmd); soft_dirty =pmd_soft_dirty (old_pmd); + uffd_wp =pmd_uffd_wp (old_pmd); }VM_BUG_ON_PAGE (!page_count (page), page);page_ref_add (page,HPAGE_PMD_NR -1 );
@@ -2290,6 +2304,8 @@ static void __split_huge_pmd_locked(stru entry =pte_mkold (entry);if (soft_dirty) entry =pte_mksoft_dirty (entry); +if (uffd_wp) + entry =pte_mkuffd_wp (entry); } pte =pte_offset_map (&_pmd, addr);BUG_ON (!pte_none (*pte));
mm/memory.c renamed from mm/memory.c~userfaultfd-wp-apply-_page_uffd_wp-bit +2 -2
@@ -2752,7 +2752,7 @@ static vm_fault_t do_wp_page(struct vm_f {struct vm_area_struct *vma = vmf->vma; -if (userfaultfd_wp (vma)) { +if (userfaultfd_pte_wp (vma, *vmf->pte)) {pte_unmap_unlock (vmf->pte, vmf->ptl);return handle_userfault (vmf,VM_UFFD_WP ); }
@@ -3955,7 +3955,7 @@ static inline vm_fault_t create_huge_pmdstatic inline vm_fault_t wp_huge_pmd (struct vm_fault *vmf,pmd_t orig_pmd) {if (vma_is_anonymous (vmf->vma)) { -if (userfaultfd_wp (vmf->vma)) +if (userfaultfd_huge_pmd_wp (vmf->vma, orig_pmd))return handle_userfault (vmf,VM_UFFD_WP );return do_huge_pmd_wp_page (vmf, orig_pmd); }
mm/mprotect.c renamed from mm/mprotect.c~userfaultfd-wp-apply-_page_uffd_wp-bit +17 -0
@@ -45,6 +45,8 @@ static unsigned long change_pte_range(stint target_node =NUMA_NO_NODE ;bool dirty_accountable = cp_flags &MM_CP_DIRTY_ACCT ;bool prot_numa = cp_flags &MM_CP_PROT_NUMA ; +bool uffd_wp = cp_flags &MM_CP_UFFD_WP ; +bool uffd_wp_resolve = cp_flags &MM_CP_UFFD_WP_RESOLVE ;/* * Can be called with only the mmap_sem for reading by
@@ -116,6 +118,19 @@ static unsigned long change_pte_range(stif (preserve_write) ptent =pte_mk_savedwrite (ptent); +if (uffd_wp) { + ptent =pte_wrprotect (ptent); + ptent =pte_mkuffd_wp (ptent); + }else if (uffd_wp_resolve) { +/* +* Leave the write bit to be handled +* by PF interrupt handler, then +* things like COW could be properly +* handled. +*/ + ptent =pte_clear_uffd_wp (ptent); + } +/* Avoid taking write faults for known dirty pages */ if (dirty_accountable && pte_dirty(ptent) && (pte_soft_dirty(ptent) ||
@@ -336,6 +351,8 @@ unsigned long change_protection(struct v {unsigned long pages; +BUG_ON ((cp_flags &MM_CP_UFFD_WP_ALL ) ==MM_CP_UFFD_WP_ALL ); +if (is_vm_hugetlb_page (vma)) pages =hugetlb_change_protection (vma, start, end, newprot);else
mm/userfaultfd.c renamed from mm/userfaultfd.c~userfaultfd-wp-apply-_page_uffd_wp-bit +6 -2
@@ -101,8 +101,12 @@ static int mcopy_atomic_pte(struct mm_st goto out_release; _dst_pte =pte_mkdirty (mk_pte (page, dst_vma->vm_page_prot)); -if ((dst_vma->vm_flags &VM_WRITE ) && !wp_copy) - _dst_pte =pte_mkwrite (_dst_pte); +if (dst_vma->vm_flags &VM_WRITE ) { +if (wp_copy) + _dst_pte =pte_mkuffd_wp (_dst_pte); +else + _dst_pte =pte_mkwrite (_dst_pte); + } dst_pte =pte_offset_map_lock (dst_mm, dst_pmd, dst_addr, &ptl);if (dst_vma->vm_file) {
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork has been added to the -mm tree. Its filename is userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch
The patch titled
Subject: userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork
has been added to the -mm tree. Its filename is
userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork
UFFD_EVENT_FORK support for uffd-wp should be already there, except that we should clean the uffd-wp bit if uffd fork event is not enabled. Detect that to avoid _PAGE_UFFD_WP being set even if the VMA is not being tracked by VM_UFFD_WP. Do this for both small PTEs and huge PMDs.
---
mm/huge_memory.c | 8 ++++++++ mm/memory.c | 8 ++++++++ 2 files changed, 16 insertions(+)
mm/huge_memory.c renamed from mm/huge_memory.c~userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork +8 -0
@@ -1018,6 +1018,14 @@ int copy_huge_pmd(struct mm_struct *dst_ ret = -EAGAIN ; pmd = *src_pmd; +/* +* Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA +* does not have the VM_UFFD_WP, which means that the uffd +* fork event is not enabled. +*/ +if (!(vma->vm_flags &VM_UFFD_WP )) + pmd =pmd_clear_uffd_wp (pmd); +#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION if (unlikely (is_swap_pmd (pmd))) {swp_entry_t entry =pmd_to_swp_entry (pmd);
mm/memory.c renamed from mm/memory.c~userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork +8 -0
@@ -785,6 +785,14 @@ copy_one_pte(struct mm_struct *dst_mm, s pte =pte_mkclean (pte); pte =pte_mkold (pte); +/* +* Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA +* does not have the VM_UFFD_WP, which means that the uffd +* fork event is not enabled. +*/ +if (!(vm_flags &VM_UFFD_WP )) + pte =pte_clear_uffd_wp (pte); + page =vm_normal_page (vma, addr, pte);if (page) {get_page (page);
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: add pmd_swp_*uffd_wp() helpers has been added to the -mm tree. Its filename is userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch
The patch titled
Subject: userfaultfd: wp: add pmd_swp_*uffd_wp() helpers
has been added to the -mm tree. Its filename is
userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: add pmd_swp_*uffd_wp() helpers
Adding these missing helpers for uffd-wp operations with pmd swap/migration entries.
---
arch/x86/include/asm/pgtable.h | 15 +++++++++++++++ include/asm-generic/pgtable_uffd.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+)
arch/x86/include/asm/pgtable.h renamed from arch/x86/include/asm/pgtable.h~userfaultfd-wp-add-pmd_swp_uffd_wp-helpers +15 -0
@@ -1427,6 +1427,21 @@ static inline pte_t pte_swp_clear_uffd_w {return pte_clear_flags (pte, _PAGE_SWP_UFFD_WP); } + +static inline pmd_t pmd_swp_mkuffd_wp (pmd_t pmd) +{ +return pmd_set_flags (pmd, _PAGE_SWP_UFFD_WP); +} + +static inline int pmd_swp_uffd_wp (pmd_t pmd) +{ +return pmd_flags (pmd) & _PAGE_SWP_UFFD_WP; +} + +static inline pmd_t pmd_swp_clear_uffd_wp (pmd_t pmd) +{ +return pmd_clear_flags (pmd, _PAGE_SWP_UFFD_WP); +}#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ #define PKRU_AD_BIT 0x1
include/asm-generic/pgtable_uffd.h renamed from include/asm-generic/pgtable_uffd.h~userfaultfd-wp-add-pmd_swp_uffd_wp-helpers +15 -0
@@ -46,6 +46,21 @@ static __always_inline pte_t pte_swp_cle {return pte; } + +static inline pmd_t pmd_swp_mkuffd_wp (pmd_t pmd) +{ +return pmd; +} + +static inline int pmd_swp_uffd_wp (pmd_t pmd) +{ +return 0 ; +} + +static inline pmd_t pmd_swp_clear_uffd_wp (pmd_t pmd) +{ +return pmd; +}#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ #endif /* _ASM_GENERIC_PGTABLE_UFFD_H */
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-support-swap-and-page-migration.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: support swap and page migration has been added to the -mm tree. Its filename is userfaultfd-wp-support-swap-and-page-migration.patch
The patch titled
Subject: userfaultfd: wp: support swap and page migration
has been added to the -mm tree. Its filename is
userfaultfd-wp-support-swap-and-page-migration.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-support-swap-and-page-migration.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-support-swap-and-page-migration.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: support swap and page migration
For either swap and page migration, we all use the bit 2 of the entry to identify whether this entry is uffd write-protected. It plays a similar role as the existing soft dirty bit in swap entries but only for keeping the uffd-wp tracking for a specific PTE/PMD.
Something special here is that when we want to recover the uffd-wp bit from a swap/migration entry to the PTE bit we'll also need to take care of the _PAGE_RW bit and make sure it's cleared, otherwise even with the _PAGE_UFFD_WP bit we can't trap it at all.
In change_pte_range() we do nothing for uffd if the PTE is a swap entry. That can lead to data mismatch if the page that we are going to write protect is swapped out when sending the UFFDIO_WRITEPROTECT. This patch also applies/removes the uffd-wp bit even for the swap entries.
---
include/linux/swapops.h | 2 ++ mm/huge_memory.c | 3 +++ mm/memory.c | 8 ++++++++ mm/migrate.c | 6 ++++++ mm/mprotect.c | 28 +++++++++++++++++----------- mm/rmap.c | 6 ++++++ 6 files changed, 42 insertions(+), 11 deletions(-)
include/linux/swapops.h renamed from include/linux/swapops.h~userfaultfd-wp-support-swap-and-page-migration +2 -0
@@ -68,6 +68,8 @@ static inline swp_entry_t pte_to_swp_entif (pte_swp_soft_dirty (pte)) pte =pte_swp_clear_soft_dirty (pte); +if (pte_swp_uffd_wp (pte)) + pte =pte_swp_clear_uffd_wp (pte); arch_entry =__pte_to_swp_entry (pte);return swp_entry (__swp_type (arch_entry),__swp_offset (arch_entry)); }
mm/huge_memory.c renamed from mm/huge_memory.c~userfaultfd-wp-support-swap-and-page-migration +3 -0
@@ -2271,6 +2271,7 @@ static void __split_huge_pmd_locked(stru write =is_write_migration_entry (entry); young = false; soft_dirty =pmd_swp_soft_dirty (old_pmd); + uffd_wp =pmd_swp_uffd_wp (old_pmd); }else { page =pmd_page (old_pmd);if (pmd_dirty (old_pmd))
@@ -2303,6 +2304,8 @@ static void __split_huge_pmd_locked(stru entry =swp_entry_to_pte (swp_entry);if (soft_dirty) entry =pte_swp_mksoft_dirty (entry); +if (uffd_wp) + entry =pte_swp_mkuffd_wp (entry); }else { entry =mk_pte (page + i,READ_ONCE (vma->vm_page_prot)); entry =maybe_mkwrite (entry, vma);
mm/memory.c renamed from mm/memory.c~userfaultfd-wp-support-swap-and-page-migration +8 -0
@@ -733,6 +733,8 @@ copy_one_pte(struct mm_struct *dst_mm, s pte =swp_entry_to_pte (entry);if (pte_swp_soft_dirty (*src_pte)) pte =pte_swp_mksoft_dirty (pte); +if (pte_swp_uffd_wp (*src_pte)) + pte =pte_swp_mkuffd_wp (pte);set_pte_at (src_mm, addr, src_pte, pte); } }else if (is_device_private_entry (entry)) {
@@ -762,6 +764,8 @@ copy_one_pte(struct mm_struct *dst_mm, s is_cow_mapping(vm_flags)) {make_device_private_entry_read (&entry); pte =swp_entry_to_pte (entry); +if (pte_swp_uffd_wp (*src_pte)) + pte =pte_swp_mkuffd_wp (pte);set_pte_at (src_mm, addr, src_pte, pte); } }
@@ -3098,6 +3102,10 @@ vm_fault_t do_swap_page(struct vm_faultflush_icache_page (vma, page);if (pte_swp_soft_dirty (vmf->orig_pte)) pte =pte_mksoft_dirty (pte); +if (pte_swp_uffd_wp (vmf->orig_pte)) { + pte =pte_mkuffd_wp (pte); + pte =pte_wrprotect (pte); + }set_pte_at (vma->vm_mm, vmf->address, vmf->pte, pte);arch_do_swap_page (vma->vm_mm, vma, vmf->address, pte, vmf->orig_pte); vmf->orig_pte = pte;
mm/migrate.c renamed from mm/migrate.c~userfaultfd-wp-support-swap-and-page-migration +6 -0
@@ -243,11 +243,15 @@ static bool remove_migration_pte(struct entry =pte_to_swp_entry (*pvmw.pte);if (is_write_migration_entry (entry)) pte =maybe_mkwrite (pte, vma); +else if (pte_swp_uffd_wp (*pvmw.pte)) + pte =pte_mkuffd_wp (pte);if (unlikely (is_zone_device_page (new))) {if (is_device_private_page (new)) { entry =make_device_private_entry (new,pte_write (pte)); pte =swp_entry_to_pte (entry); +if (pte_swp_uffd_wp (*pvmw.pte)) + pte =pte_mkuffd_wp (pte); } }
@@ -2334,6 +2338,8 @@ again: swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pte)) swp_pte =pte_swp_mksoft_dirty (swp_pte); +if (pte_uffd_wp (pte)) + swp_pte =pte_swp_mkuffd_wp (swp_pte);set_pte_at (mm, addr, ptep, swp_pte);/*
mm/mprotect.c renamed from mm/mprotect.c~userfaultfd-wp-support-swap-and-page-migration +17 -11
@@ -139,11 +139,11 @@ static unsigned long change_pte_range(st }ptep_modify_prot_commit (vma, addr, pte, oldpte, ptent); pages++; - }else if (IS_ENABLED (CONFIG_MIGRATION )) { + }else if (is_swap_pte (oldpte)) {swp_entry_t entry =pte_to_swp_entry (oldpte); +pte_t newpte;if (is_write_migration_entry (entry)) { -pte_t newpte;/* * A protection check is difficult so * just be safe and disable write
@@ -152,22 +152,28 @@ static unsigned long change_pte_range(st newpte =swp_entry_to_pte (entry);if (pte_swp_soft_dirty (oldpte)) newpte =pte_swp_mksoft_dirty (newpte); -set_pte_at (vma->vm_mm, addr, pte, newpte); - - pages++; - } - -if (is_write_device_private_entry (entry)) { -pte_t newpte; - +if (pte_swp_uffd_wp (oldpte)) + newpte =pte_swp_mkuffd_wp (newpte); + }else if (is_write_device_private_entry (entry)) {/* * We do not preserve soft-dirtiness. See * copy_one_pte() for explanation. */ make_device_private_entry_read (&entry); newpte =swp_entry_to_pte (entry); -set_pte_at (vma->vm_mm, addr, pte, newpte); +if (pte_swp_uffd_wp (oldpte)) + newpte =pte_swp_mkuffd_wp (newpte); + }else { + newpte = oldpte; + } +if (uffd_wp) + newpte =pte_swp_mkuffd_wp (newpte); +else if (uffd_wp_resolve) + newpte =pte_swp_clear_uffd_wp (newpte); + +if (!pte_same (oldpte, newpte)) { +set_pte_at (vma->vm_mm, addr, pte, newpte); pages++; } }
mm/rmap.c renamed from mm/rmap.c~userfaultfd-wp-support-swap-and-page-migration +6 -0
@@ -1502,6 +1502,8 @@ static bool try_to_unmap_one(struct page swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); +if (pte_uffd_wp (pteval)) + swp_pte =pte_swp_mkuffd_wp (swp_pte);set_pte_at (mm, pvmw.address, pvmw.pte, swp_pte);/* * No need to invalidate here it will synchronize on
@@ -1601,6 +1603,8 @@ static bool try_to_unmap_one(struct page swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); +if (pte_uffd_wp (pteval)) + swp_pte =pte_swp_mkuffd_wp (swp_pte);set_pte_at (mm, address, pvmw.pte, swp_pte);/* * No need to invalidate here it will synchronize on
@@ -1667,6 +1671,8 @@ static bool try_to_unmap_one(struct page swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); +if (pte_uffd_wp (pteval)) + swp_pte =pte_swp_mkuffd_wp (swp_pte);set_pte_at (mm, address, pvmw.pte, swp_pte);/* Invalidate as we cleared the pte */ mmu_notifier_invalidate_range(mm, address,
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ khugepaged-skip-collapse-if-uffd-wp-detected.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: khugepaged: skip collapse if uffd-wp detected has been added to the -mm tree. Its filename is khugepaged-skip-collapse-if-uffd-wp-detected.patch
The patch titled
Subject: khugepaged: skip collapse if uffd-wp detected
has been added to the -mm tree. Its filename is
khugepaged-skip-collapse-if-uffd-wp-detected.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/khugepaged-skip-collapse-if-uffd-wp-detected.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/khugepaged-skip-collapse-if-uffd-wp-detected.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: khugepaged: skip collapse if uffd-wp detected
Don't collapse the huge PMD if there is any userfault write protected small PTEs. The problem is that the write protection is in small page granularity and there's no way to keep all these write protection information if the small pages are going to be merged into a huge PMD.
The same thing needs to be considered for swap entries and migration entries. So do the check as well disregarding khugepaged_max_ptes_swap.
---
include/trace/events/huge_memory.h | 1 + mm/khugepaged.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/trace/events/huge_memory.h renamed from include/trace/events/huge_memory.h~khugepaged-skip-collapse-if-uffd-wp-detected +1 -0
@@ -13,6 +13,7 @@ EM( SCAN_PMD_NULL, "pmd_null") \ EM( SCAN_EXCEED_NONE_PTE, "exceed_none_pte") \ EM( SCAN_PTE_NON_PRESENT, "pte_non_present") \ + EM( SCAN_PTE_UFFD_WP, "pte_uffd_wp") \ EM( SCAN_PAGE_RO, "no_writable_page") \ EM( SCAN_LACK_REFERENCED_PAGE, "lack_referenced_page") \EM (SCAN_PAGE_NULL ,"page_null" ) \
mm/khugepaged.c renamed from mm/khugepaged.c~khugepaged-skip-collapse-if-uffd-wp-detected +23 -0
@@ -29,6 +29,7 @@ enum scan_result {SCAN_PMD_NULL ,SCAN_EXCEED_NONE_PTE ,SCAN_PTE_NON_PRESENT , +SCAN_PTE_UFFD_WP ,SCAN_PAGE_RO ,SCAN_LACK_REFERENCED_PAGE , SCAN_PAGE_NULL,
@@ -1139,6 +1140,15 @@ static int khugepaged_scan_pmd(struct mmpte_t pteval = *_pte;if (is_swap_pte (pteval)) {if (++unmapped <= khugepaged_max_ptes_swap) { +/* +* Always be strict with uffd-wp +* enabled swap entries. Please see +* comment below for pte_uffd_wp(). +*/ +if (pte_swp_uffd_wp (pteval)) { + result =SCAN_PTE_UFFD_WP ; + goto out_unmap; + }continue ; }else { result =SCAN_EXCEED_SWAP_PTE ;
@@ -1158,6 +1168,19 @@ static int khugepaged_scan_pmd(struct mm result =SCAN_PTE_NON_PRESENT ; goto out_unmap; } +if (pte_uffd_wp (pteval)) { +/* +* Don't collapse the page if any of the small +* PTEs are armed with uffd write protection. +* Here we can also mark the new huge pmd as +* write protected if any of the small ones is +* marked but that could bring uknown +* userfault messages that falls outside of +* the registered range. So, just be simple. +*/ + result =SCAN_PTE_UFFD_WP ; + goto out_unmap; + }if (pte_write (pteval)) writable = true;
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: support write protection for userfault vma range has been added to the -mm tree. Its filename is…
The patch titled
Subject: userfaultfd: wp: support write protection for userfault vma range
has been added to the -mm tree. Its filename is
userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Shaohua Li <[email protected]>
Subject: userfaultfd: wp: support write protection for userfault vma range
Add API to enable/disable writeprotect a vma range. Unlike mprotect, this doesn't split/merge vmas.
[[email protected]:
- use the helper to find VMA;
- return -ENOENT if not found to match mcopy case;
- use the new MM_CP_UFFD_WP* flags for change_protection
- check against mmap_changing for failures
- replace find_dst_vma with vma_find_uffd]
---
include/linux/userfaultfd_k.h | 3 + mm/userfaultfd.c | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/linux/userfaultfd_k.h renamed from include/linux/userfaultfd_k.h~userfaultfd-wp-support-write-protection-for-userfault-vma-range +3 -0
@@ -41,6 +41,9 @@ extern ssize_t mfill_zeropage(struct mm_unsigned long dst_start, unsigned long len, bool *mmap_changing); +extern int mwriteprotect_range (struct mm_struct *dst_mm, +unsigned long start,unsigned long len, +bool enable_wp,bool *mmap_changing);/* mm helpers */ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
mm/userfaultfd.c renamed from mm/userfaultfd.c~userfaultfd-wp-support-write-protection-for-userfault-vma-range +54 -0
57 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-add-helper-for-writeprotect-check.patch userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
+ userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: add the writeprotect API to userfaultfd ioctl has been added to the -mm tree. Its filename is…
The patch titled
Subject: userfaultfd: wp: add the writeprotect API to userfaultfd ioctl
has been added to the -mm tree. Its filename is
userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: wp: add the writeprotect API to userfaultfd ioctl
Introduce the new uffd-wp APIs for userspace.
Firstly, we'll allow to do UFFDIO_REGISTER with write protection tracking using the new UFFDIO_REGISTER_MODE_WP flag. Note that this flag can co-exist with the existing UFFDIO_REGISTER_MODE_MISSING, in which case the userspace program can not only resolve missing page faults, and at the same time tracking page data changes along the way.
Secondly, we introduced the new UFFDIO_WRITEPROTECT API to do page level write protection tracking. Note that we will need to register the memory region with UFFDIO_REGISTER_MODE_WP before that.
[[email protected]: write up the commit message] [[email protected]: remove useless block, write commit message, check against
VM_MAYWRITE rather than VM_WRITE when register]
---
fs/userfaultfd.c | 82 +++++++++++++++++++++++------ include/uapi/linux/userfaultfd.h | 23 ++++++++ 2 files changed, 89 insertions(+), 16 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl +66 -16
@@ -314,8 +314,11 @@ static inline bool userfaultfd_must_waitif (!pmd_present (_pmd)) goto out; -if (pmd_trans_huge (_pmd)) +if (pmd_trans_huge (_pmd)) { +if (!pmd_write (_pmd) && (reason &VM_UFFD_WP )) + ret = true; goto out; + }/* * the pmd is stable (as in !pmd_trans_unstable) so we can re-read it
@@ -328,6 +331,8 @@ static inline bool userfaultfd_must_wait*/ if (pte_none (*pte)) ret = true; +if (!pte_write (*pte) && (reason &VM_UFFD_WP )) + ret = true;pte_unmap (pte); out:
@@ -1287,10 +1292,13 @@ static __always_inline int validate_rangreturn 0 ; } -static inline bool vma_can_userfault (struct vm_area_struct *vma) +static inline bool vma_can_userfault (struct vm_area_struct *vma, +unsigned long vm_flags) { -return vma_is_anonymous (vma) ||is_vm_hugetlb_page (vma) || -vma_is_shmem (vma); +/* FIXME: add WP support to hugetlbfs and shmem */ +return vma_is_anonymous (vma) || + ((is_vm_hugetlb_page (vma) ||vma_is_shmem (vma)) && + !(vm_flags &VM_UFFD_WP )); } static int userfaultfd_register(struct userfaultfd_ctx *ctx,
@@ -1322,15 +1330,8 @@ static int userfaultfd_register(struct u vm_flags =0 ;if (uffdio_register.mode &UFFDIO_REGISTER_MODE_MISSING ) vm_flags |=VM_UFFD_MISSING ; -if (uffdio_register.mode &UFFDIO_REGISTER_MODE_WP ) { +if (uffdio_register.mode &UFFDIO_REGISTER_MODE_WP ) vm_flags |=VM_UFFD_WP ; -/* -* FIXME: remove the below error constraint by -* implementing the wprotect tracking mode. -*/ - ret = -EINVAL ; - goto out; - } ret =validate_range (mm, &uffdio_register.range.start, uffdio_register.range.len);
@@ -1380,7 +1381,7 @@ static int userfaultfd_register(struct u/* check not compatible vmas */ ret = -EINVAL ; -if (!vma_can_userfault (cur)) +if (!vma_can_userfault (cur, vm_flags)) goto out_unlock;/*
@@ -1408,6 +1409,8 @@ static int userfaultfd_register(struct uif (end & (vma_hpagesize -1 )) goto out_unlock; } +if ((vm_flags &VM_UFFD_WP ) && !(cur->vm_flags &VM_MAYWRITE )) + goto out_unlock;/* * Check that this vma isn't already owned by a
@@ -1437,7 +1440,7 @@ static int userfaultfd_register(struct u do { cond_resched(); - BUG_ON(!vma_can_userfault(vma)); + BUG_ON(!vma_can_userfault(vma, vm_flags)); BUG_ON(vma->vm_userfaultfd_ctx.ctx && vma->vm_userfaultfd_ctx.ctx != ctx); WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
@@ -1575,7 +1578,7 @@ static int userfaultfd_unregister(struct* provides for more strict behavior to notice * unregistration errors. */ -if (!vma_can_userfault (cur)) +if (!vma_can_userfault (cur, cur->vm_flags)) goto out_unlock; found = true;
@@ -1589,7 +1592,7 @@ static int userfaultfd_unregister(struct do { cond_resched(); - BUG_ON(!vma_can_userfault(vma)); + BUG_ON(!vma_can_userfault(vma, vma->vm_flags)); /* * Nothing to do: this vma is already registered into this
@@ -1802,6 +1805,50 @@ out:return ret; } +static int userfaultfd_writeprotect (struct userfaultfd_ctx *ctx, +unsigned long arg) +{ +int ret; +struct uffdio_writeprotect uffdio_wp; +struct uffdio_writeprotect __user *user_uffdio_wp; +struct userfaultfd_wake_range range; + +if (READ_ONCE (ctx->mmap_changing)) +return -EAGAIN ; + + user_uffdio_wp = (struct uffdio_writeprotect __user *) arg; + +if (copy_from_user (&uffdio_wp, user_uffdio_wp, +sizeof (struct uffdio_writeprotect ))) +return -EFAULT ; + + ret =validate_range (ctx->mm, &uffdio_wp.range.start, + uffdio_wp.range.len); +if (ret) +return ret; + +if (uffdio_wp.mode & ~(UFFDIO_WRITEPROTECT_MODE_DONTWAKE | +UFFDIO_WRITEPROTECT_MODE_WP )) +return -EINVAL ; +if ((uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_WP ) && + (uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_DONTWAKE )) +return -EINVAL ; + + ret =mwriteprotect_range (ctx->mm, uffdio_wp.range.start, + uffdio_wp.range.len, uffdio_wp.mode & +UFFDIO_WRITEPROTECT_MODE_WP , + &ctx->mmap_changing); +if (ret) +return ret; + +if (!(uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_DONTWAKE )) { + range.start = uffdio_wp.range.start; + range.len = uffdio_wp.range.len; +wake_userfault (ctx, &range); + } +return ret; +} +static inline unsigned int uffd_ctx_features (__u64 user_features) {/*
@@ -1883,6 +1930,9 @@ static long userfaultfd_ioctl(struct filcase UFFDIO_ZEROPAGE : ret =userfaultfd_zeropage (ctx, arg);break ; +case UFFDIO_WRITEPROTECT : + ret =userfaultfd_writeprotect (ctx, arg); +break ; }return ret; }
include/uapi/linux/userfaultfd.h renamed from include/uapi/linux/userfaultfd.h~userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl +23 -0
@@ -52,6 +52,7 @@#define _UFFDIO_WAKE (0x02)#define _UFFDIO_COPY (0x03)#define _UFFDIO_ZEROPAGE (0x04) +#define _UFFDIO_WRITEPROTECT (0x06)#define _UFFDIO_API (0x3F)/* userfaultfd ioctl ids */
@@ -68,6 +69,8 @@ struct uffdio_copy)#define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \ struct uffdio_zeropage) +#define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \ + struct uffdio_writeprotect)/* read() structure */ struct uffd_msg {
@@ -232,4 +235,24 @@ struct uffdio_zeropage { __s64 zeropage; }; +struct uffdio_writeprotect { +struct uffdio_range range; +/* +* UFFDIO_WRITEPROTECT_MODE_WP: set the flag to write protect a range, +* unset the flag to undo protection of a range which was previously +* write protected. +* +* UFFDIO_WRITEPROTECT_MODE_DONTWAKE: set the flag to avoid waking up +* any wait thread after the operation succeeds. +* +* NOTE: Write protecting a region (WP=1) is unrelated to page faults, +* therefore DONTWAKE flag is meaningless with WP=1. Removing write +* protection (WP=0) in response to a page fault wakes the faulting +* task unless DONTWAKE is set. +*/ +#define UFFDIO_WRITEPROTECT_MODE_WP ((__u64)1<<0) +#define UFFDIO_WRITEPROTECT_MODE_DONTWAKE ((__u64)1<<1) +__u64 mode; +}; +#endif /* _LINUX_USERFAULTFD_H */
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-hook-userfault-handler-to-write-protection-fault.patch userfaultfd-wp-add-wp-pagetable-tracking-to-x86.patch userfaultfd-wp-userfaultfd_pte-huge_pmd_wp-helpers.patch userfaultfd-wp-add-uffdio_copy_mode_wp.patch userfaultfd-wp-add-the-writeprotect-api-to-userfaultfd-ioctl.patch
+ userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: enabled write protection in userfaultfd API has been added to the -mm tree. Its filename is userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
The patch titled
Subject: userfaultfd: wp: enabled write protection in userfaultfd API
has been added to the -mm tree. Its filename is
userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Shaohua Li <[email protected]>
Subject: userfaultfd: wp: enabled write protection in userfaultfd API
Now it's safe to enable write protection in userfaultfd API
---
include/uapi/linux/userfaultfd.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/uapi/linux/userfaultfd.h renamed from include/uapi/linux/userfaultfd.h~userfaultfd-wp-enabled-write-protection-in-userfaultfd-api +4 -2
@@ -19,7 +19,8 @@* means the userland is reading). */ #define UFFD_API ((__u64)0xAA) -#define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \ +#define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \ + UFFD_FEATURE_EVENT_FORK | \ UFFD_FEATURE_EVENT_REMAP | \ UFFD_FEATURE_EVENT_REMOVE | \ UFFD_FEATURE_EVENT_UNMAP | \
@@ -34,7 +35,8 @@#define UFFD_API_RANGE_IOCTLS \ ((__u64)1 << _UFFDIO_WAKE | \ (__u64)1 << _UFFDIO_COPY | \ - (__u64)1 << _UFFDIO_ZEROPAGE) + (__u64)1 << _UFFDIO_ZEROPAGE | \ + (__u64)1 << _UFFDIO_WRITEPROTECT)#define UFFD_API_RANGE_IOCTLS_BASIC \ ((__u64)1 << _UFFDIO_WAKE | \ (__u64)1 << _UFFDIO_COPY)
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-add-helper-for-writeprotect-check.patch userfaultfd-wp-support-write-protection-for-userfault-vma-range.patch userfaultfd-wp-enabled-write-protection-in-userfaultfd-api.patch
+ userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: don't wake up when doing write protect has been added to the -mm tree. Its filename is userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch
The patch titled
Subject: userfaultfd: wp: don't wake up when doing write protect
has been added to the -mm tree. Its filename is
userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: don't wake up when doing write protect
It does not make sense to try to wake up any waiting thread when we're write-protecting a memory region. Only wake up when resolving a write protected page fault.
---
fs/userfaultfd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-wp-dont-wake-up-when-doing-write-protect +8 -5
@@ -1812,6 +1812,7 @@ static int userfaultfd_writeprotect(strustruct uffdio_writeprotect uffdio_wp;struct uffdio_writeprotect __user *user_uffdio_wp;struct userfaultfd_wake_range range; +bool mode_wp, mode_dontwake;if (READ_ONCE (ctx->mmap_changing))return -EAGAIN ;
@@ -1830,18 +1831,20 @@ static int userfaultfd_writeprotect(struif (uffdio_wp.mode & ~(UFFDIO_WRITEPROTECT_MODE_DONTWAKE |UFFDIO_WRITEPROTECT_MODE_WP ))return -EINVAL ; -if ((uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_WP ) && - (uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_DONTWAKE )) + + mode_wp = uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_WP ; + mode_dontwake = uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_DONTWAKE ; + +if (mode_wp && mode_dontwake)return -EINVAL ; ret =mwriteprotect_range (ctx->mm, uffdio_wp.range.start, - uffdio_wp.range.len, uffdio_wp.mode & -UFFDIO_WRITEPROTECT_MODE_WP , + uffdio_wp.range.len, mode_wp, &ctx->mmap_changing);if (ret)return ret; -if (!(uffdio_wp.mode &UFFDIO_WRITEPROTECT_MODE_DONTWAKE )) { +if (!mode_wp && !mode_dontwake) { range.start = uffdio_wp.range.start; range.len = uffdio_wp.range.len;wake_userfault (ctx, &range);
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-wp-uffdio_register_mode_wp-documentation-update.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update has been added to the -mm tree. Its filename is…
The patch titled
Subject: userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update
has been added to the -mm tree. Its filename is
userfaultfd-wp-uffdio_register_mode_wp-documentation-update.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-uffdio_register_mode_wp-documentation-update.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-uffdio_register_mode_wp-documentation-update.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Martin Cracauer <[email protected]>
Subject: userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update
Add documentation about the write protection support.
---
Documentation/admin-guide/mm/userfaultfd.rst | 51 +++++++++++++++++ 1 file changed, 51 insertions(+)
Documentation/admin-guide/mm/userfaultfd.rst renamed from Documentation/admin-guide/mm/userfaultfd.rst~userfaultfd-wp-uffdio_register_mode_wp-documentation-update +51 -0
@@ -108,6 +108,57 @@ UFFDIO_COPY. They're atomic as in guaran half copied page since it'll keep userfaulting until the copy has finished. +Notes: + +- If you requested UFFDIO_REGISTER_MODE_MISSING when registering then + you must provide some kind of page in your thread after reading from + the uffd. You must provide either UFFDIO_COPY or UFFDIO_ZEROPAGE. + The normal behavior of the OS automatically providing a zero page on + an annonymous mmaping is not in place. + +- None of the page-delivering ioctls default to the range that you + registered with. You must fill in all fields for the appropriate + ioctl struct including the range. + +- You get the address of the access that triggered the missing page + event out of a struct uffd_msg that you read in the thread from the + uffd. You can supply as many pages as you want with UFFDIO_COPY or + UFFDIO_ZEROPAGE. Keep in mind that unless you used DONTWAKE then + the first of any of those IOCTLs wakes up the faulting thread. + +- Be sure to test for all errors including (pollfd[0].revents & + POLLERR). This can happen, e.g. when ranges supplied were + incorrect. + +Write Protect Notifications +--------------------------- + +This is equivalent to (but faster than) using mprotect and a SIGSEGV +signal handler. + +Firstly you need to register a range with UFFDIO_REGISTER_MODE_WP. +Instead of using mprotect(2) you use ioctl(uffd, UFFDIO_WRITEPROTECT, +struct *uffdio_writeprotect) while mode = UFFDIO_WRITEPROTECT_MODE_WP +in the struct passed in. The range does not default to and does not +have to be identical to the range you registered with. You can write +protect as many ranges as you like (inside the registered range). +Then, in the thread reading from uffd the struct will have +msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP set. Now you send +ioctl(uffd, UFFDIO_WRITEPROTECT, struct *uffdio_writeprotect) again +while pagefault.mode does not have UFFDIO_WRITEPROTECT_MODE_WP set. +This wakes up the thread which will continue to run with writes. This +allows you to do the bookkeeping about the write in the uffd reading +thread before the ioctl. + +If you registered with both UFFDIO_REGISTER_MODE_MISSING and +UFFDIO_REGISTER_MODE_WP then you need to think about the sequence in +which you supply a page and undo write protect. Note that there is a +difference between writes into a WP area and into a !WP area. The +former will have UFFD_PAGEFAULT_FLAG_WP set, the latter +UFFD_PAGEFAULT_FLAG_WRITE. The latter did not fail on protection but +you still need to supply a page when UFFDIO_REGISTER_MODE_MISSING was +used. + QEMU/KVM ========
_
Patches currently in -mm which might be from [email protected] are
userfaultfd-wp-uffdio_register_mode_wp-documentation-update.patch
+ userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: wp: declare _UFFDIO_WRITEPROTECT conditionally has been added to the -mm tree. Its filename is userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch
The patch titled
Subject: userfaultfd: wp: declare _UFFDIO_WRITEPROTECT conditionally
has been added to the -mm tree. Its filename is
userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: wp: declare _UFFDIO_WRITEPROTECT conditionally
Only declare _UFFDIO_WRITEPROTECT if the user specified UFFDIO_REGISTER_MODE_WP and if all the checks passed. Then when the user registers regions with shmem/hugetlbfs we won't expose the new ioctl to them. Even with complete anonymous memory range, we'll only expose the new WP ioctl bit if the register mode has MODE_WP.
---
fs/userfaultfd.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-wp-declare-_uffdio_writeprotect-conditionally +13 -3
@@ -1495,14 +1495,24 @@ out_unlock:up_write (&mm->mmap_sem);mmput (mm);if (!ret) { +__u64 ioctls_out; + + ioctls_out = basic_ioctls ?UFFD_API_RANGE_IOCTLS_BASIC : +UFFD_API_RANGE_IOCTLS ; + +/* +* Declare the WP ioctl only if the WP mode is +* specified and all checks passed with the range +*/ +if (!(uffdio_register.mode &UFFDIO_REGISTER_MODE_WP )) + ioctls_out &= ~((__u64 )1 << _UFFDIO_WRITEPROTECT); +/* * Now that we scanned all vmas we can already tell * userland which ioctls methods are guaranteed to * succeed on this range. */ -if (put_user (basic_ioctls ?UFFD_API_RANGE_IOCTLS_BASIC : -UFFD_API_RANGE_IOCTLS , - &user_uffdio_register->ioctls)) +if (put_user (ioctls_out, &user_uffdio_register->ioctls)) ret = -EFAULT ; } out:
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-selftests-refactor-statistics.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: selftests: refactor statistics has been added to the -mm tree. Its filename is userfaultfd-selftests-refactor-statistics.patch
The patch titled
Subject: userfaultfd: selftests: refactor statistics
has been added to the -mm tree. Its filename is
userfaultfd-selftests-refactor-statistics.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-selftests-refactor-statistics.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-selftests-refactor-statistics.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: selftests: refactor statistics
Introduce uffd_stats structure for statistics of the self test, at the same time refactor the code to always pass in the uffd_stats for either read() or poll() typed fault handling threads instead of using two different ways to return the statistic results. No functional change.
With the new structure, it's very easy to introduce new statistics.
---
tools/testing/selftests/vm/userfaultfd.c | 76 +++++++++++++-------- 1 file changed, 49 insertions(+), 27 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-refactor-statistics +49 -27
@@ -86,6 +86,12 @@ static char *area_src, *area_src_alias,static char *zeropage;pthread_attr_t attr; +/* Userfaultfd test statistics */ +struct uffd_stats { +int cpu; +unsigned long missing_faults; +}; +/* pthread_mutex_t starts at page offset 0 */ #define area_mutex (___area, ___nr) \ ((pthread_mutex_t *) ((___area) + (___nr)*page_size))
@@ -125,6 +131,17 @@ static void usage(void)exit (1 ); } +static void uffd_stats_reset (struct uffd_stats *uffd_stats, +unsigned long n_cpus) +{ +int i; + +for (i =0 ; i < n_cpus; i++) { + uffd_stats[i].cpu = i; + uffd_stats[i].missing_faults =0 ; + } +} +static int anon_release_pages (char *rel_area) {int ret =0 ;
@@ -467,8 +484,8 @@ static int uffd_read_msg(int ufd, structreturn 0 ; } -/* Return 1 if page fault handled by us; otherwise 0 */ -static int uffd_handle_page_fault (struct uffd_msg *msg) +static void uffd_handle_page_fault (struct uffd_msg *msg, +struct uffd_stats *stats) {unsigned long offset;
@@ -483,18 +500,19 @@ static int uffd_handle_page_fault(struct offset = (char *)(unsigned long )msg->arg.pagefault.address - area_dst; offset &= ~(page_size-1 ); -return copy_page (uffd, offset); +if (copy_page (uffd, offset)) + stats->missing_faults++; }static void *uffd_poll_thread (void *arg) { -unsigned long cpu = (unsigned long ) arg; +struct uffd_stats *stats = (struct uffd_stats *)arg; +unsigned long cpu = stats->cpu;struct pollfd pollfd[2 ];struct uffd_msg msg;struct uffdio_register uffd_reg;int ret;char tmp_chr; -unsigned long userfaults =0 ; pollfd[0 ].fd = uffd; pollfd[0 ].events =POLLIN ;
@@ -524,7 +542,7 @@ static void *uffd_poll_thread(void *arg) msg.event), exit(1);break ;case UFFD_EVENT_PAGEFAULT : - userfaults +=uffd_handle_page_fault (&msg); +uffd_handle_page_fault (&msg, stats);break ;case UFFD_EVENT_FORK :close (uffd);
@@ -543,28 +561,27 @@ static void *uffd_poll_thread(void *arg)break ; } } -return (void *)userfaults; + +return NULL ; }pthread_mutex_t uffd_read_mutex =PTHREAD_MUTEX_INITIALIZER ;static void *uffd_read_thread (void *arg) { -unsigned long *this_cpu_userfaults; +struct uffd_stats *stats = (struct uffd_stats *)arg;struct uffd_msg msg; - this_cpu_userfaults = (unsigned long *) arg; - *this_cpu_userfaults =0 ; -pthread_mutex_unlock (&uffd_read_mutex);/* from here cancellation is ok */ for (;;) {if (uffd_read_msg (uffd, &msg))continue ; - (*this_cpu_userfaults) +=uffd_handle_page_fault (&msg); +uffd_handle_page_fault (&msg, stats); } -return (void *)NULL ; + +return NULL ; }static void *background_thread (void *arg)
@@ -580,13 +597,12 @@ static void *background_thread(void *argreturn NULL ; } -static int stress (unsigned long *userfaults) +static int stress (struct uffd_stats *uffd_stats) {unsigned long cpu;pthread_t locking_threads[nr_cpus];pthread_t uffd_threads[nr_cpus];pthread_t background_threads[nr_cpus]; -void **_userfaults = (void **) userfaults; finished =0 ;for (cpu =0 ; cpu < nr_cpus; cpu++) {
@@ -595,12 +611,13 @@ static int stress(unsigned long *userfaureturn 1 ;if (bounces &BOUNCE_POLL ) {if (pthread_create (&uffd_threads[cpu], &attr, - uffd_poll_thread, (void *)cpu)) + uffd_poll_thread, + (void *)&uffd_stats[cpu]))return 1 ; }else {if (pthread_create (&uffd_threads[cpu], &attr, uffd_read_thread, - &_userfaults[cpu])) + (void *)&uffd_stats[cpu]))return 1 ;pthread_mutex_lock (&uffd_read_mutex); }
@@ -637,7 +654,8 @@ static int stress(unsigned long *userfaufprintf (stderr,"pipefd write error\n" );return 1 ; } -if (pthread_join (uffd_threads[cpu], &_userfaults[cpu])) +if (pthread_join (uffd_threads[cpu], + (void *)&uffd_stats[cpu]))return 1 ; }else {if (pthread_cancel (uffd_threads[cpu]))
@@ -908,11 +926,11 @@ static int userfaultfd_events_test(void) {struct uffdio_register uffdio_register;unsigned long expected_ioctls; -unsigned long userfaults;pthread_t uffd_mon;int err, features;pid_t pid;char c; +struct uffd_stats stats = {0 };printf ("testing events (fork, remap, remove): " );fflush (stdout);
@@ -939,7 +957,7 @@ static int userfaultfd_events_test(void) "unexpected missing ioctl for anon memory\n"),exit (1 ); -if (pthread_create (&uffd_mon, &attr, uffd_poll_thread,NULL )) +if (pthread_create (&uffd_mon, &attr, uffd_poll_thread, &stats))perror ("uffd_poll_thread create" ),exit (1 ); pid =fork ();
@@ -955,13 +973,13 @@ static int userfaultfd_events_test(void)if (write (pipefd[1 ], &c,sizeof (c)) !=sizeof (c))perror ("pipe write" ),exit (1 ); -if (pthread_join (uffd_mon, (void **)&userfaults)) +if (pthread_join (uffd_mon,NULL ))return 1 ;close (uffd); -printf ("userfaults: %ld\n" , userfaults); +printf ("userfaults: %ld\n" , stats.missing_faults); -return userfaults != nr_pages; +return stats.missing_faults != nr_pages; }static int userfaultfd_sig_test (void )
@@ -973,6 +991,7 @@ static int userfaultfd_sig_test(void)int err, features;pid_t pid;char c; +struct uffd_stats stats = {0 };printf ("testing signal delivery: " );fflush (stdout);
@@ -1004,7 +1023,7 @@ static int userfaultfd_sig_test(void)if (uffd_test_ops->release_pages (area_dst))return 1 ; -if (pthread_create (&uffd_mon, &attr, uffd_poll_thread,NULL )) +if (pthread_create (&uffd_mon, &attr, uffd_poll_thread, &stats))perror ("uffd_poll_thread create" ),exit (1 ); pid =fork ();
@@ -1030,6 +1049,7 @@ static int userfaultfd_sig_test(void)close (uffd);return userfaults !=0 ; } +static int userfaultfd_stress (void ) {void *area;
@@ -1038,7 +1058,7 @@ static int userfaultfd_stress(void)struct uffdio_register uffdio_register;unsigned long cpu;int err; -unsigned long userfaults[nr_cpus]; +struct uffd_stats uffd_stats[nr_cpus]; uffd_test_ops->allocate_area ((void **)&area_src);if (!area_src)
@@ -1167,8 +1187,10 @@ static int userfaultfd_stress(void)if (uffd_test_ops->release_pages (area_dst))return 1 ; +uffd_stats_reset (uffd_stats, nr_cpus); +/* bounce pass */ -if (stress (userfaults)) +if (stress (uffd_stats))return 1 ;/* unregister */
@@ -1211,7 +1233,7 @@ static int userfaultfd_stress(void)printf ("userfaults:" );for (cpu =0 ; cpu < nr_cpus; cpu++) -printf (" %lu" , userfaults[cpu]); +printf (" %lu" , uffd_stats[cpu].missing_faults);printf ("\n" ); }
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ userfaultfd-selftests-add-write-protect-test.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: userfaultfd: selftests: add write-protect test has been added to the -mm tree. Its filename is userfaultfd-selftests-add-write-protect-test.patch
The patch titled
Subject: userfaultfd: selftests: add write-protect test
has been added to the -mm tree. Its filename is
userfaultfd-selftests-add-write-protect-test.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-selftests-add-write-protect-test.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-selftests-add-write-protect-test.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Peter Xu <[email protected]>
Subject: userfaultfd: selftests: add write-protect test
Add uffd tests for write protection.
Instead of introducing new tests for it, let's simply squashing uffd-wp tests into existing uffd-missing test cases. Changes are:
(1) Bouncing tests
We do the write-protection in two ways during the bouncing test:
- By using UFFDIO_COPY_MODE_WP when resolving MISSING pages: then we'll make sure for each bounce process every single page will be at least fault twice: once for MISSING, once for WP.
- By direct call UFFDIO_WRITEPROTECT on existing faulted memories:
To further torture the explicit page protection procedures of uffd-wp, we split each bounce procedure into two halves (in the background thread): the first half will be MISSING+WP for each page as explained above. After the first half, we write protect the faulted region in the background thread to make sure at least half of the pages will be write protected again which is the first half to test the new UFFDIO_WRITEPROTECT call. Then we continue with the 2nd half, which will contain both MISSING and WP faulting tests for the 2nd half and WP-only faults from the 1st half.
(2) Event/Signal test
Mostly previous tests but will do MISSING+WP for each page. For sigbus-mode test we'll need to provide standalone path to handle the write protection faults.
For all tests, do statistics as well for uffd-wp pages.
---
tools/testing/selftests/vm/userfaultfd.c | 157 +++++++++++++++++---- 1 file changed, 133 insertions(+), 24 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-add-write-protect-test +133 -24
@@ -54,6 +54,7 @@#include <linux/userfaultfd.h> #include <setjmp.h> #include <stdbool.h> +#include <assert.h> #include "../kselftest.h"
@@ -76,6 +77,8 @@ static int test_type;#define ALARM_INTERVAL_SECS 10static volatile bool test_uffdio_copy_eexist = true;static volatile bool test_uffdio_zeropage_eexist = true; +/* Whether to test uffd write-protection */ +static bool test_uffdio_wp = false;static bool map_shared;static int huge_fd;
@@ -90,6 +93,7 @@ pthread_attr_t attr;struct uffd_stats {int cpu;unsigned long missing_faults; +unsigned long wp_faults; };/* pthread_mutex_t starts at page offset 0 */
@@ -139,9 +143,29 @@ static void uffd_stats_reset(struct uffdfor (i =0 ; i < n_cpus; i++) { uffd_stats[i].cpu = i; uffd_stats[i].missing_faults =0 ; + uffd_stats[i].wp_faults =0 ; } } +static void uffd_stats_report (struct uffd_stats *stats,int n_cpus) +{ +int i; +unsigned long long miss_total =0 , wp_total =0 ; + +for (i =0 ; i < n_cpus; i++) { + miss_total += stats[i].missing_faults; + wp_total += stats[i].wp_faults; + } + +printf ("userfaults: %llu missing (" , miss_total); +for (i =0 ; i < n_cpus; i++) +printf ("%lu+" , stats[i].missing_faults); +printf ("\b), %llu wp (" , wp_total); +for (i =0 ; i < n_cpus; i++) +printf ("%lu+" , stats[i].wp_faults); +printf ("\b)\n" ); +} +static int anon_release_pages (char *rel_area) {int ret =0 ;
@@ -262,10 +286,15 @@ struct uffd_test_ops {void (*alias_mapping)(__u64 *start,size_t len,unsigned long offset); }; -#define ANON_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ +#define SHMEM_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ (1 << _UFFDIO_COPY) | \ (1 << _UFFDIO_ZEROPAGE)) +#define ANON_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ + (1 << _UFFDIO_COPY) | \ + (1 << _UFFDIO_ZEROPAGE) | \ + (1 << _UFFDIO_WRITEPROTECT)) +static struct uffd_test_ops anon_uffd_test_ops = { .expected_ioctls =ANON_EXPECTED_IOCTLS , .allocate_area = anon_allocate_area,
@@ -274,7 +303,7 @@ static struct uffd_test_ops anon_uffd_te };static struct uffd_test_ops shmem_uffd_test_ops = { - .expected_ioctls =ANON_EXPECTED_IOCTLS , + .expected_ioctls =SHMEM_EXPECTED_IOCTLS , .allocate_area = shmem_allocate_area, .release_pages = shmem_release_pages, .alias_mapping = noop_alias_mapping,
@@ -298,6 +327,21 @@ static int my_bcmp(char *str1, char *strreturn 0 ; } +static void wp_range (int ufd,__u64 start,__u64 len,bool wp) +{ +struct uffdio_writeprotect prms = {0 }; + +/* Write protection page faults */ + prms.range.start = start; + prms.range.len = len; +/* Undo write-protect, do wakeup after that */ + prms.mode = wp ?UFFDIO_WRITEPROTECT_MODE_WP :0 ; + +if (ioctl (ufd,UFFDIO_WRITEPROTECT , &prms)) +fprintf (stderr,"clear WP failed for address 0x%Lx\n" , + start),exit (1 ); +} +static void *locking_thread (void *arg) {unsigned long cpu = (unsigned long ) arg;
@@ -436,7 +480,10 @@ static int __copy_page(int ufd, unsigned uffdio_copy.dst = (unsigned long ) area_dst + offset; uffdio_copy.src = (unsigned long ) area_src + offset; uffdio_copy.len = page_size; - uffdio_copy.mode =0 ; +if (test_uffdio_wp) + uffdio_copy.mode =UFFDIO_COPY_MODE_WP ; +else + uffdio_copy.mode =0 ; uffdio_copy.copy =0 ;if (ioctl (ufd,UFFDIO_COPY , &uffdio_copy)) {/* real retval in ufdio_copy.copy */
@@ -493,15 +540,21 @@ static void uffd_handle_page_fault(strucfprintf (stderr,"unexpected msg event %u\n" , msg->event),exit (1 ); -if (bounces &BOUNCE_VERIFY && - msg->arg.pagefault.flags &UFFD_PAGEFAULT_FLAG_WRITE ) -fprintf (stderr,"unexpected write fault\n" ),exit (1 ); +if (msg->arg.pagefault.flags &UFFD_PAGEFAULT_FLAG_WP ) { +wp_range (uffd, msg->arg.pagefault.address, page_size, false); + stats->wp_faults++; + }else { +/* Missing page faults */ +if (bounces &BOUNCE_VERIFY && + msg->arg.pagefault.flags &UFFD_PAGEFAULT_FLAG_WRITE ) +fprintf (stderr,"unexpected write fault\n" ),exit (1 ); - offset = (char *)(unsigned long )msg->arg.pagefault.address - area_dst; - offset &= ~(page_size-1 ); + offset = (char *)(unsigned long )msg->arg.pagefault.address - area_dst; + offset &= ~(page_size-1 ); -if (copy_page (uffd, offset)) - stats->missing_faults++; +if (copy_page (uffd, offset)) + stats->missing_faults++; + } }static void *uffd_poll_thread (void *arg)
@@ -587,11 +640,30 @@ static void *uffd_read_thread(void *arg)static void *background_thread (void *arg) {unsigned long cpu = (unsigned long ) arg; -unsigned long page_nr; +unsigned long page_nr, start_nr, mid_nr, end_nr; + + start_nr = cpu * nr_pages_per_cpu; + end_nr = (cpu+1 ) * nr_pages_per_cpu; + mid_nr = (start_nr + end_nr) /2 ; -for (page_nr = cpu * nr_pages_per_cpu; - page_nr < (cpu+1 ) * nr_pages_per_cpu; - page_nr++) +/* Copy the first half of the pages */ +for (page_nr = start_nr; page_nr < mid_nr; page_nr++) +copy_page_retry (uffd, page_nr * page_size); + +/* +* If we need to test uffd-wp, set it up now. Then we'll have +* at least the first half of the pages mapped already which +* can be write-protected for testing +*/ +if (test_uffdio_wp) +wp_range (uffd, (unsigned long )area_dst + start_nr * page_size, + nr_pages_per_cpu * page_size, true); + +/* +* Continue the 2nd half of the page copying, handling write +* protection faults if any +*/ +for (page_nr = mid_nr; page_nr < end_nr; page_nr++)copy_page_retry (uffd, page_nr * page_size);return NULL ;
@@ -753,17 +825,31 @@ static int faulting_process(int signal_t }for (nr =0 ; nr < split_nr_pages; nr++) { +int steps =1 ; +unsigned long offset = nr * page_size; +if (signal_test) {if (sigsetjmp (*sigbuf,1 ) !=0 ) { -if (nr == lastnr) { +if (steps ==1 && nr == lastnr) {fprintf (stderr,"Signal repeated\n" );return 1 ; } lastnr = nr;if (signal_test ==1 ) { -if (copy_page (uffd, nr * page_size)) - signalled++; +if (steps ==1 ) { +/* This is a MISSING request */ + steps++; +if (copy_page (uffd, offset)) + signalled++; + }else { +/* This is a WP request */ +assert (steps ==2 ); +wp_range (uffd, + (__u64 )area_dst + + offset, + page_size, false); + } }else { signalled++;continue ;
@@ -776,8 +862,13 @@ static int faulting_process(int signal_tfprintf (stderr,"nr %lu memory corruption %Lu %Lu\n" , nr, count, - count_verify[nr]),exit (1 ); - } + count_verify[nr]); + } +/* +* Trigger write protection if there is by writting +* the same value back. +*/ + *area_count (area_dst, nr) = count; }if (signal_test)
@@ -799,6 +890,11 @@ static int faulting_process(int signal_t nr, count, count_verify[nr]), exit(1); } +/* +* Trigger write protection if there is by writting +* the same value back. +*/ + *area_count (area_dst, nr) = count; }if (uffd_test_ops->release_pages (area_dst))
@@ -902,6 +998,8 @@ static int userfaultfd_zeropage_test(voi uffdio_register.range.start = (unsigned long ) area_dst; uffdio_register.range.len = nr_pages * page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MISSING ; +if (test_uffdio_wp) + uffdio_register.mode |=UFFDIO_REGISTER_MODE_WP ;if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))fprintf (stderr,"register failure\n" ),exit (1 );
@@ -947,6 +1045,8 @@ static int userfaultfd_events_test(void) uffdio_register.range.start = (unsigned long ) area_dst; uffdio_register.range.len = nr_pages * page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MISSING ; +if (test_uffdio_wp) + uffdio_register.mode |=UFFDIO_REGISTER_MODE_WP ;if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))fprintf (stderr,"register failure\n" ),exit (1 );
@@ -977,7 +1077,8 @@ static int userfaultfd_events_test(void)return 1 ;close (uffd); -printf ("userfaults: %ld\n" , stats.missing_faults); + +uffd_stats_report (&stats,1 );return stats.missing_faults != nr_pages; }
@@ -1007,6 +1108,8 @@ static int userfaultfd_sig_test(void) uffdio_register.range.start = (unsigned long ) area_dst; uffdio_register.range.len = nr_pages * page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MISSING ; +if (test_uffdio_wp) + uffdio_register.mode |=UFFDIO_REGISTER_MODE_WP ;if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))fprintf (stderr,"register failure\n" ),exit (1 );
@@ -1139,6 +1242,8 @@ static int userfaultfd_stress(void) uffdio_register.range.start = (unsigned long ) area_dst; uffdio_register.range.len = nr_pages * page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MISSING ; +if (test_uffdio_wp) + uffdio_register.mode |=UFFDIO_REGISTER_MODE_WP ;if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register)) {fprintf (stderr,"register failure\n" );return 1 ;
@@ -1193,6 +1298,11 @@ static int userfaultfd_stress(void)if (stress (uffd_stats))return 1 ; +/* Clear all the write protections if there is any */ +if (test_uffdio_wp) +wp_range (uffd, (unsigned long )area_dst, + nr_pages * page_size, false); +/* unregister */ if (ioctl (uffd,UFFDIO_UNREGISTER , &uffdio_register.range)) {fprintf (stderr,"unregister failure\n" );
@@ -1231,10 +1341,7 @@ static int userfaultfd_stress(void) area_src_alias = area_dst_alias; area_dst_alias = tmp_area; -printf ("userfaults:" ); -for (cpu =0 ; cpu < nr_cpus; cpu++) -printf (" %lu" , uffd_stats[cpu].missing_faults); -printf ("\n" ); +uffd_stats_report (uffd_stats, nr_cpus); }if (err)
@@ -1274,6 +1381,8 @@ static void set_test_type(const char *tyif (!strcmp (type,"anon" )) { test_type =TEST_ANON ; uffd_test_ops = &anon_uffd_test_ops; +/* Only enable write-protect test for anonymous test */ + test_uffdio_wp = true; }else if (!strcmp (type,"hugetlb" )) { test_type =TEST_HUGETLB ; uffd_test_ops = &hugetlb_uffd_test_ops;
_
Patches currently in -mm which might be from [email protected] are
mm-gup-rename-nonblocking-to-locked-where-proper.patch mm-gup-fix-__get_user_pages-on-fault-retry-of-hugetlb.patch mm-introduce-fault_signal_pending.patch x86-mm-use-helper-fault_signal_pending.patch arc-mm-use-helper-fault_signal_pending.patch arm64-mm-use-helper-fault_signal_pending.patch powerpc-mm-use-helper-fault_signal_pending.patch sh-mm-use-helper-fault_signal_pending.patch mm-return-faster-for-non-fatal-signals-in-user-mode-faults.patch userfaultfd-dont-retake-mmap_sem-to-emulate-nopage.patch mm-introduce-fault_flag_default.patch mm-introduce-fault_flag_interruptible.patch mm-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-vm_fault_retry-for-multiple-times.patch mm-gup-allow-to-react-to-fatal-signals.patch mm-userfaultfd-honor-fault_flag_killable-in-fault-path.patch mm-merge-parameters-for-change_protection.patch userfaultfd-wp-apply-_page_uffd_wp-bit.patch userfaultfd-wp-drop-_page_uffd_wp-properly-when-fork.patch userfaultfd-wp-add-pmd_swp_uffd_wp-helpers.patch userfaultfd-wp-support-swap-and-page-migration.patch khugepaged-skip-collapse-if-uffd-wp-detected.patch userfaultfd-wp-dont-wake-up-when-doing-write-protect.patch userfaultfd-wp-declare-_uffdio_writeprotect-conditionally.patch userfaultfd-selftests-refactor-statistics.patch userfaultfd-selftests-add-write-protect-test.patch
+ kmod-make-request_module-return-an-error-when-autoloading-is-disabled.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kmod: make request_module() return an error when autoloading is disabled has been added to the -mm tree. Its filename is…
The patch titled
Subject: kmod: make request_module() return an error when autoloading is disabled
has been added to the -mm tree. Its filename is
kmod-make-request_module-return-an-error-when-autoloading-is-disabled.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/kmod-make-request_module-return-an-error-when-autoloading-is-disabled.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/kmod-make-request_module-return-an-error-when-autoloading-is-disabled.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Eric Biggers <[email protected]>
Subject: kmod: make request_module() return an error when autoloading is disabled
It's long been possible to disable kernel module autoloading completely by setting /proc/sys/kernel/modprobe to the empty string. This can be preferable to setting it to a nonexistent file since it avoids the overhead of an attempted execve(), avoids potential deadlocks, and avoids the call to security_kernel_module_request() and thus on SELinux-based systems eliminates the need to write SELinux rules to dontaudit module_request.
However, when module autoloading is disabled in this way, request_module() returns 0. This is broken because callers expect 0 to mean that the module was successfully loaded.
Apparently this was never noticed because this method of disabling module autoloading isn't used much, and also most callers don't use the return value of request_module() since it's always necessary to check whether the module registered its functionality or not anyway. But improperly returning 0 can indeed confuse a few callers, for example get_fs_type() in fs/filesystems.c where it causes a WARNING to be hit:
if (!fs && (request_module("fs-%.*s", len, name) == 0)) {
fs = __get_fs_type(name, len);
WARN_ONCE(!fs, "request_module fs-%.*s succeeded, but still no fs?
", len, name);
}This is easily reproduced with:
echo > /proc/sys/kernel/modprobe
mount -t NONEXISTENT none /
It causes:
request_module fs-NONEXISTENT succeeded, but still no fs? WARNING: CPU: 1 PID: 1106 at fs/filesystems.c:275 get_fs_type+0xd6/0xf0 [...]
Arguably this warning is broken and should be removed, since the module could have been unloaded already. However, request_module() should also correctly return an error when it fails. So let's make it return -ENOENT, which matches the error when the modprobe binary doesn't exist.
---
kernel/kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kmod.c renamed from kernel/kmod.c~kmod-make-request_module-return-an-error-when-autoloading-is-disabled +2 -2
@@ -120,7 +120,7 @@ out:* invoke it. * * If module auto-loading support is disabled then this function -* becomes a no-operation. +* simply returns -ENOENT. */ int __request_module (bool wait,const char *fmt, ...) {
@@ -137,7 +137,7 @@ int __request_module(bool wait, const chWARN_ON_ONCE (wait &¤t_is_async ());if (!modprobe_path[0 ]) -return 0 ; +return -ENOENT ;va_start (args, fmt); ret =vsnprintf (module_name,MODULE_NAME_LEN , fmt, args);
_
Patches currently in -mm which might be from [email protected] are
kmod-make-request_module-return-an-error-when-autoloading-is-disabled.patch