From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, daniel.m.jordan@oracle.com,
dbueso@suse.de, hughd@google.com, jgg@ziepe.ca,
jglisse@redhat.com, jhubbard@nvidia.com, ldufour@linux.ibm.com,
Liam.Howlett@oracle.com, linux-mm@kvack.org,
mm-commits@vger.kernel.org, peterz@infradead.org,
rientjes@google.com, torvalds@linux-foundation.org,
vbabka@suse.cz, walken@google.com, willy@infradead.org,
yinghan@google.com
Subject: [patch 68/93] mmap locking API: add mmap_assert_locked() and mmap_assert_write_locked()
Date: Mon, 08 Jun 2020 21:33:44 -0700 [thread overview]
Message-ID: <20200609043344.m3SxCY1jL%akpm@linux-foundation.org> (raw)
In-Reply-To: <20200608212922.5b7fa74ca3f4e2444441b7f9@linux-foundation.org>
From: Michel Lespinasse <walken@google.com>
Subject: mmap locking API: add mmap_assert_locked() and mmap_assert_write_locked()
Add new APIs to assert that mmap_sem is held.
Using this instead of rwsem_is_locked and lockdep_assert_held[_write]
makes the assertions more tolerant of future changes to the lock type.
Link: http://lkml.kernel.org/r/20200520052908.204642-10-walken@google.com
Signed-off-by: Michel Lespinasse <walken@google.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Laurent Dufour <ldufour@linux.ibm.com>
Cc: Liam Howlett <Liam.Howlett@oracle.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ying Han <yinghan@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
arch/x86/events/core.c | 2 +-
fs/userfaultfd.c | 6 +++---
include/linux/mmap_lock.h | 14 ++++++++++++++
mm/gup.c | 2 +-
mm/hmm.c | 2 +-
mm/memory.c | 2 +-
mm/mmu_notifier.c | 6 +++---
mm/pagewalk.c | 6 +++---
mm/util.c | 2 +-
9 files changed, 28 insertions(+), 14 deletions(-)
--- a/arch/x86/events/core.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/arch/x86/events/core.c
@@ -2181,7 +2181,7 @@ static void x86_pmu_event_mapped(struct
* For now, this can't happen because all callers hold mmap_sem
* for write. If this changes, we'll need a different solution.
*/
- lockdep_assert_held_write(&mm->mmap_sem);
+ mmap_assert_write_locked(mm);
if (atomic_inc_return(&mm->context.perf_rdpmc_allowed) == 1)
on_each_cpu_mask(mm_cpumask(mm), cr4_update_pce, NULL, 1);
--- a/fs/userfaultfd.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/fs/userfaultfd.c
@@ -234,7 +234,7 @@ static inline bool userfaultfd_huge_must
pte_t *ptep, pte;
bool ret = true;
- VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
+ mmap_assert_locked(mm);
ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
@@ -286,7 +286,7 @@ static inline bool userfaultfd_must_wait
pte_t *pte;
bool ret = true;
- VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
+ mmap_assert_locked(mm);
pgd = pgd_offset(mm, address);
if (!pgd_present(*pgd))
@@ -405,7 +405,7 @@ vm_fault_t handle_userfault(struct vm_fa
* Coredumping runs without mmap_sem so we can only check that
* the mmap_sem is held, if PF_DUMPCORE was not set.
*/
- WARN_ON_ONCE(!rwsem_is_locked(&mm->mmap_sem));
+ mmap_assert_locked(mm);
ctx = vmf->vma->vm_userfaultfd_ctx.ctx;
if (!ctx)
--- a/include/linux/mmap_lock.h~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/include/linux/mmap_lock.h
@@ -1,6 +1,8 @@
#ifndef _LINUX_MMAP_LOCK_H
#define _LINUX_MMAP_LOCK_H
+#include <linux/mmdebug.h>
+
#define MMAP_LOCK_INITIALIZER(name) \
.mmap_sem = __RWSEM_INITIALIZER((name).mmap_sem),
@@ -73,4 +75,16 @@ static inline void mmap_read_unlock_non_
up_read_non_owner(&mm->mmap_sem);
}
+static inline void mmap_assert_locked(struct mm_struct *mm)
+{
+ lockdep_assert_held(&mm->mmap_sem);
+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
+}
+
+static inline void mmap_assert_write_locked(struct mm_struct *mm)
+{
+ lockdep_assert_held_write(&mm->mmap_sem);
+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
+}
+
#endif /* _LINUX_MMAP_LOCK_H */
--- a/mm/gup.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/gup.c
@@ -1425,7 +1425,7 @@ long populate_vma_page_range(struct vm_a
VM_BUG_ON(end & ~PAGE_MASK);
VM_BUG_ON_VMA(start < vma->vm_start, vma);
VM_BUG_ON_VMA(end > vma->vm_end, vma);
- VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
+ mmap_assert_locked(mm);
gup_flags = FOLL_TOUCH | FOLL_POPULATE | FOLL_MLOCK;
if (vma->vm_flags & VM_LOCKONFAULT)
--- a/mm/hmm.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/hmm.c
@@ -563,7 +563,7 @@ int hmm_range_fault(struct hmm_range *ra
struct mm_struct *mm = range->notifier->mm;
int ret;
- lockdep_assert_held(&mm->mmap_sem);
+ mmap_assert_locked(mm);
do {
/* If range is no longer valid force retry. */
--- a/mm/memory.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/memory.c
@@ -1211,7 +1211,7 @@ static inline unsigned long zap_pud_rang
next = pud_addr_end(addr, end);
if (pud_trans_huge(*pud) || pud_devmap(*pud)) {
if (next - addr != HPAGE_PUD_SIZE) {
- VM_BUG_ON_VMA(!rwsem_is_locked(&tlb->mm->mmap_sem), vma);
+ mmap_assert_locked(tlb->mm);
split_huge_pud(vma, pud, addr);
} else if (zap_huge_pud(tlb, vma, pud, addr))
goto next;
--- a/mm/mmu_notifier.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/mmu_notifier.c
@@ -609,7 +609,7 @@ int __mmu_notifier_register(struct mmu_n
struct mmu_notifier_subscriptions *subscriptions = NULL;
int ret;
- lockdep_assert_held_write(&mm->mmap_sem);
+ mmap_assert_write_locked(mm);
BUG_ON(atomic_read(&mm->mm_users) <= 0);
if (IS_ENABLED(CONFIG_LOCKDEP)) {
@@ -761,7 +761,7 @@ struct mmu_notifier *mmu_notifier_get_lo
struct mmu_notifier *subscription;
int ret;
- lockdep_assert_held_write(&mm->mmap_sem);
+ mmap_assert_write_locked(mm);
if (mm->notifier_subscriptions) {
subscription = find_get_mmu_notifier(mm, ops);
@@ -1006,7 +1006,7 @@ int mmu_interval_notifier_insert_locked(
mm->notifier_subscriptions;
int ret;
- lockdep_assert_held_write(&mm->mmap_sem);
+ mmap_assert_write_locked(mm);
if (!subscriptions || !subscriptions->has_itree) {
ret = __mmu_notifier_register(NULL, mm);
--- a/mm/pagewalk.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/pagewalk.c
@@ -395,7 +395,7 @@ int walk_page_range(struct mm_struct *mm
if (!walk.mm)
return -EINVAL;
- lockdep_assert_held(&walk.mm->mmap_sem);
+ mmap_assert_locked(walk.mm);
vma = find_vma(walk.mm, start);
do {
@@ -453,7 +453,7 @@ int walk_page_range_novma(struct mm_stru
if (start >= end || !walk.mm)
return -EINVAL;
- lockdep_assert_held(&walk.mm->mmap_sem);
+ mmap_assert_locked(walk.mm);
return __walk_page_range(start, end, &walk);
}
@@ -472,7 +472,7 @@ int walk_page_vma(struct vm_area_struct
if (!walk.mm)
return -EINVAL;
- lockdep_assert_held(&walk.mm->mmap_sem);
+ mmap_assert_locked(walk.mm);
err = walk_page_test(vma->vm_start, vma->vm_end, &walk);
if (err > 0)
--- a/mm/util.c~mmap-locking-api-add-mmap_assert_locked-and-mmap_assert_write_locked
+++ a/mm/util.c
@@ -437,7 +437,7 @@ int __account_locked_vm(struct mm_struct
unsigned long locked_vm, limit;
int ret = 0;
- lockdep_assert_held_write(&mm->mmap_sem);
+ mmap_assert_write_locked(mm);
locked_vm = mm->locked_vm;
if (inc) {
_
next prev parent reply other threads:[~2020-06-09 4:33 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-09 4:29 incoming Andrew Morton
2020-06-09 4:29 ` [patch 01/93] kallsyms/printk: add loglvl to print_ip_sym() Andrew Morton
2020-06-09 4:30 ` [patch 02/93] alpha: add show_stack_loglvl() Andrew Morton
2020-06-09 4:30 ` [patch 03/93] arc: " Andrew Morton
2020-06-09 4:30 ` [patch 04/93] arm/asm: add loglvl to c_backtrace() Andrew Morton
2020-06-09 4:30 ` [patch 05/93] arm: add loglvl to unwind_backtrace() Andrew Morton
2020-06-09 4:30 ` [patch 06/93] arm: add loglvl to dump_backtrace() Andrew Morton
2020-06-09 4:30 ` [patch 07/93] arm: wire up dump_backtrace_{entry,stm} Andrew Morton
2020-06-09 4:30 ` [patch 08/93] arm: add show_stack_loglvl() Andrew Morton
2020-06-09 4:30 ` [patch 09/93] arm64: add loglvl to dump_backtrace() Andrew Morton
2020-06-09 4:30 ` [patch 10/93] arm64: add show_stack_loglvl() Andrew Morton
2020-06-09 4:30 ` [patch 11/93] c6x: " Andrew Morton
2020-06-09 4:30 ` [patch 12/93] csky: " Andrew Morton
2020-06-09 4:30 ` [patch 13/93] h8300: " Andrew Morton
2020-06-09 4:30 ` [patch 14/93] hexagon: " Andrew Morton
2020-06-09 4:30 ` [patch 15/93] ia64: pass log level as arg into ia64_do_show_stack() Andrew Morton
2020-06-09 4:30 ` [patch 16/93] ia64: add show_stack_loglvl() Andrew Morton
2020-06-09 4:30 ` [patch 17/93] m68k: " Andrew Morton
2020-06-09 4:30 ` [patch 18/93] microblaze: add loglvl to microblaze_unwind_inner() Andrew Morton
2020-06-09 4:30 ` [patch 19/93] microblaze: add loglvl to microblaze_unwind() Andrew Morton
2020-06-09 4:30 ` [patch 20/93] microblaze: add show_stack_loglvl() Andrew Morton
2020-06-09 4:30 ` [patch 21/93] mips: " Andrew Morton
2020-06-09 4:31 ` [patch 22/93] nds32: " Andrew Morton
2020-06-09 4:31 ` [patch 23/93] nios2: " Andrew Morton
2020-06-09 4:31 ` [patch 24/93] openrisc: " Andrew Morton
2020-06-09 4:31 ` [patch 25/93] parisc: " Andrew Morton
2020-06-09 4:31 ` [patch 26/93] powerpc: " Andrew Morton
2020-06-09 4:31 ` [patch 27/93] riscv: " Andrew Morton
2020-06-09 4:31 ` [patch 28/93] s390: " Andrew Morton
2020-06-09 4:31 ` [patch 29/93] sh: add loglvl to dump_mem() Andrew Morton
2020-06-09 4:31 ` [patch 30/93] sh: remove needless printk() Andrew Morton
2020-06-09 4:31 ` [patch 31/93] sh: add loglvl to printk_address() Andrew Morton
2020-06-09 4:31 ` [patch 32/93] sh: add loglvl to show_trace() Andrew Morton
2020-06-09 4:31 ` [patch 33/93] sh: add show_stack_loglvl() Andrew Morton
2020-06-09 4:31 ` [patch 34/93] sparc: " Andrew Morton
2020-06-09 4:31 ` [patch 35/93] um/sysrq: remove needless variable sp Andrew Morton
2020-06-09 4:31 ` [patch 36/93] um: add show_stack_loglvl() Andrew Morton
2020-06-09 4:31 ` [patch 37/93] unicore32: remove unused pmode argument in c_backtrace() Andrew Morton
2020-06-09 4:31 ` [patch 38/93] unicore32: add loglvl to c_backtrace() Andrew Morton
2020-06-09 4:31 ` [patch 39/93] unicore32: add show_stack_loglvl() Andrew Morton
2020-06-09 4:31 ` [patch 40/93] x86: add missing const qualifiers for log_lvl Andrew Morton
2020-06-09 4:32 ` [patch 41/93] x86: add show_stack_loglvl() Andrew Morton
2020-06-09 4:32 ` [patch 42/93] xtensa: add loglvl to show_trace() Andrew Morton
2020-06-09 4:32 ` [patch 43/93] xtensa: add show_stack_loglvl() Andrew Morton
2020-06-09 4:32 ` [patch 44/93] sysrq: use show_stack_loglvl() Andrew Morton
2020-06-09 4:32 ` [patch 45/93] x86/amd_gart: print stacktrace for a leak with KERN_ERR Andrew Morton
2020-06-09 4:32 ` [patch 46/93] power: use show_stack_loglvl() Andrew Morton
2020-06-09 4:32 ` [patch 47/93] kdb: don't play with console_loglevel Andrew Morton
2020-06-09 4:32 ` [patch 48/93] sched: print stack trace with KERN_INFO Andrew Morton
2020-06-09 4:32 ` [patch 49/93] kernel: use show_stack_loglvl() Andrew Morton
2020-06-09 4:32 ` [patch 50/93] kernel: rename show_stack_loglvl() => show_stack() Andrew Morton
2020-06-09 4:32 ` [patch 51/93] mm: don't include asm/pgtable.h if linux/mm.h is already included Andrew Morton
2020-06-09 4:32 ` [patch 52/93] mm: introduce include/linux/pgtable.h Andrew Morton
2020-06-09 4:32 ` [patch 53/93] mm: reorder includes after introduction of linux/pgtable.h Andrew Morton
2020-06-09 4:32 ` [patch 54/93] csky: replace definitions of __pXd_offset() with pXd_index() Andrew Morton
2020-06-09 4:32 ` [patch 55/93] m68k/mm/motorola: move comment about page table allocation funcitons Andrew Morton
2020-06-09 4:32 ` [patch 56/93] m68k/mm: move {cache,nocahe}_page() definitions close to their user Andrew Morton
2020-06-09 4:33 ` [patch 57/93] x86/mm: simplify init_trampoline() and surrounding logic Andrew Morton
2020-06-09 4:33 ` [patch 58/93] mm: pgtable: add shortcuts for accessing kernel PMD and PTE Andrew Morton
2020-06-09 4:33 ` [patch 59/93] mm: consolidate pte_index() and pte_offset_*() definitions Andrew Morton
2020-06-09 4:33 ` [patch 60/93] mmap locking API: initial implementation as rwsem wrappers Andrew Morton
2020-06-09 4:33 ` [patch 61/93] MMU notifier: use the new mmap locking API Andrew Morton
2020-06-09 4:33 ` [patch 62/93] DMA reservations: " Andrew Morton
2020-06-09 4:33 ` [patch 63/93] mmap locking API: use coccinelle to convert mmap_sem rwsem call sites Andrew Morton
2020-06-09 4:33 ` [patch 64/93] mmap locking API: convert mmap_sem call sites missed by coccinelle Andrew Morton
2020-06-09 4:33 ` [patch 65/93] mmap locking API: convert nested write lock sites Andrew Morton
2020-06-09 4:33 ` [patch 66/93] mmap locking API: add mmap_read_trylock_non_owner() Andrew Morton
2020-06-09 4:33 ` [patch 67/93] mmap locking API: add MMAP_LOCK_INITIALIZER Andrew Morton
2020-06-09 4:33 ` Andrew Morton [this message]
2020-06-09 4:33 ` [patch 69/93] mmap locking API: rename mmap_sem to mmap_lock Andrew Morton
2020-06-09 4:33 ` [patch 70/93] mmap locking API: convert mmap_sem API comments Andrew Morton
2020-06-09 4:33 ` [patch 71/93] mmap locking API: convert mmap_sem comments Andrew Morton
2020-06-09 4:33 ` [patch 72/93] maccess: unexport probe_kernel_write() Andrew Morton
2020-06-09 4:34 ` [patch 73/93] maccess: remove various unused weak aliases Andrew Morton
2020-06-09 4:34 ` [patch 74/93] maccess: remove duplicate kerneldoc comments Andrew Morton
2020-06-09 4:34 ` [patch 75/93] maccess: clarify " Andrew Morton
2020-06-09 4:34 ` [patch 76/93] maccess: update the top of file comment Andrew Morton
2020-06-09 4:34 ` [patch 77/93] maccess: rename strncpy_from_unsafe_user to strncpy_from_user_nofault Andrew Morton
2020-06-09 4:34 ` [patch 78/93] maccess: rename strncpy_from_unsafe_strict to strncpy_from_kernel_nofault Andrew Morton
2020-06-09 4:34 ` [patch 79/93] maccess: rename strnlen_unsafe_user to strnlen_user_nofault Andrew Morton
2020-06-09 4:34 ` [patch 80/93] maccess: remove probe_read_common and probe_write_common Andrew Morton
2020-06-09 4:34 ` [patch 81/93] maccess: unify the probe kernel arch hooks Andrew Morton
2020-06-09 4:34 ` [patch 82/93] bpf: factor out a bpf_trace_copy_string helper Andrew Morton
2020-06-09 4:34 ` [patch 83/93] bpf: handle the compat string in bpf_trace_copy_string better Andrew Morton
2020-06-09 4:34 ` [patch 84/93] bpf:bpf_seq_printf(): handle potentially unsafe format string better Andrew Morton
2020-06-09 4:34 ` [patch 85/93] bpf: rework the compat kernel probe handling Andrew Morton
2020-06-09 4:34 ` [patch 86/93] tracing/kprobes: handle mixed kernel/userspace probes better Andrew Morton
2020-06-09 4:34 ` [patch 87/93] maccess: remove strncpy_from_unsafe Andrew Morton
2020-06-09 4:34 ` [patch 88/93] maccess: always use strict semantics for probe_kernel_read Andrew Morton
2020-06-09 4:34 ` [patch 89/93] maccess: move user access routines together Andrew Morton
2020-06-09 4:34 ` [patch 90/93] maccess: allow architectures to provide kernel probing directly Andrew Morton
2020-06-09 4:35 ` [patch 91/93] x86: use non-set_fs based maccess routines Andrew Morton
2020-06-09 18:01 ` Linus Torvalds
2020-06-09 18:06 ` Linus Torvalds
2020-06-10 6:57 ` Christoph Hellwig
2020-06-09 4:35 ` [patch 92/93] maccess: return -ERANGE when probe_kernel_read() fails Andrew Morton
2020-06-09 4:35 ` [patch 93/93] include/linux/cache.h: expand documentation over __read_mostly Andrew Morton
2020-06-17 15:51 ` Christopher Lameter
2020-06-09 5:34 ` mmotm 2020-06-08-22-33 uploaded Andrew Morton
2020-06-09 5:36 ` mmotm 2020-06-08-22-35 uploaded Andrew Morton
2020-06-09 16:58 ` incoming Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200609043344.m3SxCY1jL%akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Liam.Howlett@oracle.com \
--cc=daniel.m.jordan@oracle.com \
--cc=dbueso@suse.de \
--cc=hughd@google.com \
--cc=jgg@ziepe.ca \
--cc=jglisse@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-mm@kvack.org \
--cc=mm-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--cc=walken@google.com \
--cc=willy@infradead.org \
--cc=yinghan@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).