From patchwork Wed Apr 15 00:43:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11489453 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 84E921392 for ; Wed, 15 Apr 2020 00:44:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51B482064A for ; Wed, 15 Apr 2020 00:44:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="v3U3zcnH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51B482064A 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 05C208E000F; Tue, 14 Apr 2020 20:44:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 00D7F8E000B; Tue, 14 Apr 2020 20:44:19 -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 DC92C8E000F; Tue, 14 Apr 2020 20:44:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id C15FD8E000B for ; Tue, 14 Apr 2020 20:44:19 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 931585DD5 for ; Wed, 15 Apr 2020 00:44:19 +0000 (UTC) X-FDA: 76708243038.05.burn35_42d59f94b0022 X-Spam-Summary: 2,0,0,885b637e626bdfb5,d41d8cd98f00b204,34liwxgykcocfjutnwpxxpun.lxvurwdg-vvtejlt.xap@flex--walken.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3369:3865:3866:3867:3871:3874:4321:4605:5007:6119:6261:6653:6742:7875:9969:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12555:12895:13149:13230:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:30003:30054:30070,0,RBL:209.85.210.202:@flex--walken.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.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:24,LUA_SUMMARY:none X-HE-Tag: burn35_42d59f94b0022 X-Filterd-Recvd-Size: 5629 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Apr 2020 00:44:19 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id w14so1437941pfq.3 for ; Tue, 14 Apr 2020 17:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ggOUzmI+Bo7l84q6+4eSP8RoHAFlUo3STFyyVvEfbuY=; b=v3U3zcnHadO8cIVqK7qs+yu9BjT5Cu1yAHrgYE84xqRz3dmpsNBbK1nkzqhxkzu76r Ru0/6QNuYt+D1VgkJZRfOvPwdG04Th2lgPYfFMUyA6NNnrhEnzYzWqOUgvstcD1y3zaG wu23Wkj4xhbxMmuuc+xK0vNGWDDc2Ai/L7BvERBgMf8gaJtdQTpU/jFQKJSKRMmNUcZl xI9r/noAK5QO/zR3AKqv503yzone0RbaRApvB3/Ns3XttF80P2z4DOEjIh9ATw+sqyqi YFk1WiX+kSu54pgBnYh06eEiG/sgDLROhy5OWH8NS3B1wH0Gt/Mc6Z+1jpW91zzIwGKU +gmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ggOUzmI+Bo7l84q6+4eSP8RoHAFlUo3STFyyVvEfbuY=; b=a94EVyMkL0Q+taSwfmdFNWowfNIlb+lVu5qSUsXTeMHOqcpJaYR7utHjH2xwnbYeMB oUPXkkVfG6jWB440AoH1YFnEx7uzEb/oRQWHL46722tzFB3iRN+Fbu3WEf0KO8Uk8FpH txsUGPslqDkQEly8Eo55bMZtQvYcvsSesnGPTeqGpaDx/+zJeBxlppGVQ06zURuhthGw CjXM5V8o1GFyi/FWOKehE4odfKCQUtkPMOTKn5KTI9I6cu99j1YrrZH+6QILUoofYtyp TyUhB/Fs3r7S7X+MOFuGWRykxO2G8LNl91FmHq7W8/3o+PqIi5Kk74xPfFqyArUw3AiU gxYw== X-Gm-Message-State: AGi0PuYuchmGXLHhiKjyVXK0xYzR7/DdhZV2eUt3SExoVhsIA8q2ku0i Kp6qyCPWOpH2IEOfK0xEqgkHJBVFZYM= X-Google-Smtp-Source: APiQypKSHiRQIgo5oWUk5CjgE3NHcJLyFdkH8jRqO+eAwck4UEAr8xG7J11X7lWnOWO5y3p9NfdQWkaGVrg= X-Received: by 2002:a17:90a:3287:: with SMTP id l7mr3119309pjb.126.1586911458346; Tue, 14 Apr 2020 17:44:18 -0700 (PDT) Date: Tue, 14 Apr 2020 17:43:52 -0700 In-Reply-To: <20200415004353.130248-1-walken@google.com> Message-Id: <20200415004353.130248-10-walken@google.com> Mime-Version: 1.0 References: <20200415004353.130248-1-walken@google.com> X-Mailer: git-send-email 2.26.0.110.g2183baf09c-goog Subject: [PATCH v4 09/10] mmap locking API: use lockdep_assert_held From: Michel Lespinasse To: Andrew Morton , linux-mm Cc: LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Daniel Jordan , Michel Lespinasse 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: Use lockdep_assert_held when asserting that mmap_sem is held. Using this instead of rwsem_is_locked makes the assertions more tolerant of future changes to the lock type. Signed-off-by: Michel Lespinasse --- fs/userfaultfd.c | 6 +++--- mm/gup.c | 2 +- mm/memory.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 9c645eee1a59..81ae8315f1e6 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -234,7 +234,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, pte_t *ptep, pte; bool ret = true; - VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); + lockdep_assert_held(&mm->mmap_sem); ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); @@ -286,7 +286,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, pte_t *pte; bool ret = true; - VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); + lockdep_assert_held(&mm->mmap_sem); pgd = pgd_offset(mm, address); if (!pgd_present(*pgd)) @@ -405,7 +405,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) * 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)); + lockdep_assert_held(&mm->mmap_sem); ctx = vmf->vma->vm_userfaultfd_ctx.ctx; if (!ctx) diff --git a/mm/gup.c b/mm/gup.c index 0404e52513b2..dd8f045b047b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1403,7 +1403,7 @@ long populate_vma_page_range(struct vm_area_struct *vma, 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); + lockdep_assert_held(&mm->mmap_sem); gup_flags = FOLL_TOUCH | FOLL_POPULATE | FOLL_MLOCK; if (vma->vm_flags & VM_LOCKONFAULT) diff --git a/mm/memory.c b/mm/memory.c index e6dd3309c5a3..66baf5142e6b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1214,7 +1214,7 @@ static inline unsigned long zap_pud_range(struct mmu_gather *tlb, 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); + lockdep_assert_held(&tlb->mm->mmap_sem); split_huge_pud(vma, pud, addr); } else if (zap_huge_pud(tlb, vma, pud, addr)) goto next;