From patchwork Fri Apr 24 01:39:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11506933 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28D8C92A for ; Fri, 24 Apr 2020 01:40:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE24120736 for ; Fri, 24 Apr 2020 01:40:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OpXzBSsx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE24120736 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F04B48E0006; Thu, 23 Apr 2020 21:40:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EB4C18E0003; Thu, 23 Apr 2020 21:40:03 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA4058E0006; Thu, 23 Apr 2020 21:40:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id C11188E0003 for ; Thu, 23 Apr 2020 21:40:03 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 73A626122 for ; Fri, 24 Apr 2020 01:40:03 +0000 (UTC) X-FDA: 76741042686.21.maid76_3aa8cb9f38c28 X-Spam-Summary: 2,0,0,d45e0c7ae5b171eb,d41d8cd98f00b204,walken@google.com,,RULES_HIT:1:2:41:69:355:379:800:960:973:982:988:989:1260:1277:1312:1313:1314:1345:1359:1437:1516:1518:1519:1593:1594:1595:1596:1605:1730:1747:1777:1792:1801:2194:2199:2393:2559:2562:2904:3138:3139:3140:3141:3142:3152:3165:3865:3866:3867:3868:3870:3871:4051:4250:4321:4605:5007:6119:6261:6653:6742:7903:8603:9010:9036:9969:10004:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13138:13149:13230:13231:13439:13895:14096:14097:14394:21080:21222:21433:21444:21451:21627:21795:21987:21990:30003:30029:30051:30054:30070,0,RBL:209.85.216.68:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:34,LUA_SUMMARY:none X-HE-Tag: maid76_3aa8cb9f38c28 X-Filterd-Recvd-Size: 11639 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 01:40:02 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id a7so3326822pju.2 for ; Thu, 23 Apr 2020 18:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=68Nx2V8aZ/ShCL5lhF0+fP6Gwyx0200ThlJtcELp36E=; b=OpXzBSsxwfLCg1Fm8bhwdgNV04pYonI9vicEN6e72BxIcNWF4ejewW74Sf3Sw02xuf hZliOvZsG4rH77xHjyQUKE0EBincQr7n/Ueenctw47W0AU6h1wPPskfo+9q3ayovHMY6 +zweC/tU+jmEH6gAayNafg+ZHz/lYQGEkeZt/e/GBg87h5Cw/q4xpIHuTOe5Gg8UU964 0tWXsxA40wiK/PQfuZ7Sn/lp+6s6ACm4r5ooCtBvfDwNiTnV21LM3XyuXs+Ywt54u1MT ZpY8v5iqOpWTN2FLbbQsM/M4GxM8pAvuwKMRcOITc7sCPwN7xC1SQJDFO/aiXoJFwZ1N dq3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=68Nx2V8aZ/ShCL5lhF0+fP6Gwyx0200ThlJtcELp36E=; b=T44QDgUbWtrVVssZLedibw+NsFi1aUOxpcq5jYNNY3qfqrEUrJ3Pw+A/2Mz9oXDS3y 2OK0dUK8U08s3br39sNAkNY47jWh5PXFDe8ppLXPtHgcu32ZYFT8S6j6SvRbXAxD3+A2 4JiAoGgqJToOx7iNgM7IHHXCGExQaDEjXsZ2iS+9yf1+vhjUmUY80SMUmO/0jcOLOONb i24vzwZ+13gkznqbrF04nzy/e1KCwS1KobDezJwUSyLQz42iIvbCkNFzkxeMsWSRaQWw zusYdIVXw9T0DiU0UhqKSw5wBkTCpx0RUnS2iXELsPkDk27zOdaD+u8Xe9GuwUc5fQsk 5SpA== X-Gm-Message-State: AGi0PuaKk4nEJKPGtR1iWZlxUcmBtq0y6R/c/93+OYnylXR+sfC0UqOZ HmgagmINvgSMm3WV9UN13yTgsw== X-Google-Smtp-Source: APiQypKQqJaem5xVn+CH3gnRms1htPRwe3w5eIVaLVtSZBJGLpN4BihhHy6fH/KuhwX7AlL01LCacg== X-Received: by 2002:a17:90a:4e81:: with SMTP id o1mr3601742pjh.161.1587692401505; Thu, 23 Apr 2020 18:40:01 -0700 (PDT) Received: from google.com ([2620:15c:2cd:202:2523:d194:de3b:636f]) by smtp.gmail.com with ESMTPSA id x10sm3219587pgq.79.2020.04.23.18.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 18:40:00 -0700 (PDT) Date: Thu, 23 Apr 2020 18:39:58 -0700 From: Michel Lespinasse To: Matthew Wilcox Cc: Andrew Morton , linux-mm , LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Daniel Jordan Subject: [PATCH v5.5 10/10] mmap locking API: rename mmap_sem to mmap_lock Message-ID: <20200424013958.GC158937@google.com> References: <20200422001422.232330-1-walken@google.com> <20200422001422.232330-11-walken@google.com> <20200422015829.GR5820@bombadil.infradead.org> <20200423015917.GA13910@bombadil.infradead.org> <20200424012612.GA158937@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200424012612.GA158937@google.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rename the mmap_sem field to mmap_lock. Any new uses of this lock should now go through the new mmap locking api. The mmap_lock is still implemented as a rwsem, though this could change in the future. Signed-off-by: Michel Lespinasse Reviewed-by: Vlastimil Babka --- arch/ia64/mm/fault.c | 4 +-- arch/x86/mm/fault.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- include/linux/mm_types.h | 2 +- include/linux/mmap_lock.h | 38 +++++++++++++-------------- mm/memory.c | 2 +- mm/mmap.c | 4 +-- mm/mmu_notifier.c | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c index 693f00b117e1..9b95050c2048 100644 --- a/arch/ia64/mm/fault.c +++ b/arch/ia64/mm/fault.c @@ -70,8 +70,8 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re mask = ((((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT) | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT)); - /* mmap_sem is performance critical.... */ - prefetchw(&mm->mmap_sem); + /* mmap_lock is performance critical.... */ + prefetchw(&mm->mmap_lock); /* * If we're in an interrupt or have no user context, we must not take the fault.. diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 181f66b9049f..35f530f9dfc0 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1522,7 +1522,7 @@ dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long hw_error_code, unsigned long address) { - prefetchw(¤t->mm->mmap_sem); + prefetchw(¤t->mm->mmap_lock); trace_page_fault_entries(regs, hw_error_code, address); if (unlikely(kmmio_fault(regs, address))) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index dc9ef302f517..701f3995f621 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -661,7 +661,7 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj) struct etnaviv_gem_userptr *userptr = &etnaviv_obj->userptr; int ret, pinned = 0, npages = etnaviv_obj->base.size >> PAGE_SHIFT; - might_lock_read(¤t->mm->mmap_sem); + might_lock_read(¤t->mm->mmap_lock); if (userptr->mm != current->mm) return -EPERM; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4aba6c0c2ba8..d13b90399c16 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -436,7 +436,7 @@ struct mm_struct { spinlock_t page_table_lock; /* Protects page tables and some * counters */ - struct rw_semaphore mmap_sem; + struct rw_semaphore mmap_lock; struct list_head mmlist; /* List of maybe swapped mm's. These * are globally strung together off diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 5bf7cee5d93b..9dc632add390 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -4,67 +4,67 @@ #include #define MMAP_LOCK_INITIALIZER(name) \ - .mmap_sem = __RWSEM_INITIALIZER(name.mmap_sem), + .mmap_lock = __RWSEM_INITIALIZER(name.mmap_lock), static inline void mmap_init_lock(struct mm_struct *mm) { - init_rwsem(&mm->mmap_sem); + init_rwsem(&mm->mmap_lock); } static inline void mmap_write_lock(struct mm_struct *mm) { - down_write(&mm->mmap_sem); + down_write(&mm->mmap_lock); } static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass) { - down_write_nested(&mm->mmap_sem, subclass); + down_write_nested(&mm->mmap_lock, subclass); } static inline int mmap_write_lock_killable(struct mm_struct *mm) { - return down_write_killable(&mm->mmap_sem); + return down_write_killable(&mm->mmap_lock); } static inline bool mmap_write_trylock(struct mm_struct *mm) { - return down_write_trylock(&mm->mmap_sem) != 0; + return down_write_trylock(&mm->mmap_lock) != 0; } static inline void mmap_write_unlock(struct mm_struct *mm) { - up_write(&mm->mmap_sem); + up_write(&mm->mmap_lock); } static inline void mmap_write_downgrade(struct mm_struct *mm) { - downgrade_write(&mm->mmap_sem); + downgrade_write(&mm->mmap_lock); } static inline void mmap_read_lock(struct mm_struct *mm) { - down_read(&mm->mmap_sem); + down_read(&mm->mmap_lock); } static inline int mmap_read_lock_killable(struct mm_struct *mm) { - return down_read_killable(&mm->mmap_sem); + return down_read_killable(&mm->mmap_lock); } static inline bool mmap_read_trylock(struct mm_struct *mm) { - return down_read_trylock(&mm->mmap_sem) != 0; + return down_read_trylock(&mm->mmap_lock) != 0; } static inline void mmap_read_unlock(struct mm_struct *mm) { - up_read(&mm->mmap_sem); + up_read(&mm->mmap_lock); } static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm) { - if (down_read_trylock(&mm->mmap_sem)) { - rwsem_release(&mm->mmap_sem.dep_map, _RET_IP_); + if (down_read_trylock(&mm->mmap_lock)) { + rwsem_release(&mm->mmap_lock.dep_map, _RET_IP_); return true; } return false; @@ -72,19 +72,19 @@ static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm) static inline void mmap_read_unlock_non_owner(struct mm_struct *mm) { - up_read_non_owner(&mm->mmap_sem); + up_read_non_owner(&mm->mmap_lock); } static inline void mmap_assert_locked(struct mm_struct *mm) { - VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_sem, -1), mm); - VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm); + VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_lock, -1), mm); + VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm); } static inline void mmap_assert_write_locked(struct mm_struct *mm) { - VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_sem, 0), mm); - VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm); + VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_lock, 0), mm); + VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm); } #endif /* _LINUX_MMAP_LOCK_H */ diff --git a/mm/memory.c b/mm/memory.c index 20f98ea8968e..c2963e7affa9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4811,7 +4811,7 @@ void __might_fault(const char *file, int line) __might_sleep(file, line, 0); #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) if (current->mm) - might_lock_read(¤t->mm->mmap_sem); + might_lock_read(¤t->mm->mmap_lock); #endif } EXPORT_SYMBOL(__might_fault); diff --git a/mm/mmap.c b/mm/mmap.c index 2f4ffccc5972..80a47031d5db 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3474,7 +3474,7 @@ static void vm_lock_anon_vma(struct mm_struct *mm, struct anon_vma *anon_vma) * The LSB of head.next can't change from under us * because we hold the mm_all_locks_mutex. */ - down_write_nest_lock(&anon_vma->root->rwsem, &mm->mmap_sem); + down_write_nest_lock(&anon_vma->root->rwsem, &mm->mmap_lock); /* * We can safely modify head.next after taking the * anon_vma->root->rwsem. If some other vma in this mm shares @@ -3504,7 +3504,7 @@ static void vm_lock_mapping(struct mm_struct *mm, struct address_space *mapping) */ if (test_and_set_bit(AS_MM_ALL_LOCKS, &mapping->flags)) BUG(); - down_write_nest_lock(&mapping->i_mmap_rwsem, &mm->mmap_sem); + down_write_nest_lock(&mapping->i_mmap_rwsem, &mm->mmap_lock); } } diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 24eb9d1ed0a7..2f348b6c9c9a 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -983,7 +983,7 @@ int mmu_interval_notifier_insert(struct mmu_interval_notifier *interval_sub, struct mmu_notifier_subscriptions *subscriptions; int ret; - might_lock(&mm->mmap_sem); + might_lock(&mm->mmap_lock); subscriptions = smp_load_acquire(&mm->notifier_subscriptions); if (!subscriptions || !subscriptions->has_itree) {