From patchwork Fri Mar 27 02:10:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11461563 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 55DD11668 for ; Fri, 27 Mar 2020 02:11:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1949120787 for ; Fri, 27 Mar 2020 02:11:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CKxR3ona" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1949120787 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 220E36B0073; Thu, 26 Mar 2020 22:11:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1820E6B0074; Thu, 26 Mar 2020 22:11:25 -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 0707B6B0075; Thu, 26 Mar 2020 22:11:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id DFEDD6B0073 for ; Thu, 26 Mar 2020 22:11:24 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BE7BC4DA9 for ; Fri, 27 Mar 2020 02:11:24 +0000 (UTC) X-FDA: 76639515288.24.angle39_c4cff5510859 X-Spam-Summary: 2,0,0,69d83cc4804385f0,d41d8cd98f00b204,3y2b9xgykchw1fqpjslttlqj.htrqnsz2-rrp0fhp.twl@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:12986:13149:13230:14096:14097:14181:14394:14659:14721:21080:21444:21451:21611:21627:30003:30054:30070,0,RBL:209.85.214.201:@flex--walken.bounces.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:23,LUA_SUMMARY:none X-HE-Tag: angle39_c4cff5510859 X-Filterd-Recvd-Size: 5634 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 02:11:24 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id d11so5918375pll.6 for ; Thu, 26 Mar 2020 19:11:24 -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=xbfzfU9BuZhYVtZI+f7wZqdjFxjb/Cu4ZDBLeXOeWh4=; b=CKxR3ona0u2RmWR/xBiXd/BIIQOhDb5ow2tHB7KtIuqP+ipu+a9Y4l2DI7zNDKmFOl cKDWOas4/Ha6AVoNYg0QqMRXa1eBWkoAgP0aMwXZNyjP7xzj2ovpO+xZ9AgSnKaDt/jS lxJsqSxQcg8zr76VzevUeD4QSX7Sohhw1x34d1QvDYqLijCdWbl1fzWEpm76Qt5Ri1CU kn2ZPltn+MjMzxshnsHMQI6QAIZfSJaY0+YT8C9Oez5uvbfqQO5IvQcGrwUDqxpoF8cx dYFKGuGbBrm+eWaouSjJwq8ygg/dx9LHQSwyy3yuBXie4bKHK914vPwitmbybQAtW93j YHPA== 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=xbfzfU9BuZhYVtZI+f7wZqdjFxjb/Cu4ZDBLeXOeWh4=; b=SkkQQ6en/fNJk4g8fPoe4IgbWsS9HaxgcktGLtGJOW6kKGkR8a7XiEQLmOJF66GCCa 11yM43dNdK0H9m7wnzAC2eycdNuQzFKrN8tIQEUlggn76lnXm3Lb7mayOQk6Sjt/nIRE 8UVP7laWpERLgdKo9YKA4zzBfKnLb7TSG8lJp5lJ1nu+ImL7HdPGYLjXn3qGwRwngRBn s+c2Mm7SkVGboAVnpwasHT4ehmIfeRzd0trllgTp3SPFvGlZFF9fjn50VEsSrneRjx3R cUTiwrFOUsiyy8gOi+7autBFFnsxv1BFbZ0dmYLBQV9D+PLvNDWJ8vHcrWmctx4oyljw zV+A== X-Gm-Message-State: ANhLgQ1TgMY3N2Mu4tcK7y1aBQtJKR96SPjSvQGXSNqnjsb9drNqlFp/ 0aAqrLiQ8lqIgLx6a1F5d2CIbYm21fs= X-Google-Smtp-Source: ADFU+vtVAlUiFBKMsrFe3fbDpb5LQUuV30ffPeopL8PT/CYp/gJkXzxDRmTbcl6CF6Uc/4pStbEr2LuEO0U= X-Received: by 2002:a17:90a:bf18:: with SMTP id c24mr3196953pjs.125.1585275083331; Thu, 26 Mar 2020 19:11:23 -0700 (PDT) Date: Thu, 26 Mar 2020 19:10:57 -0700 In-Reply-To: <20200327021058.221911-1-walken@google.com> Message-Id: <20200327021058.221911-10-walken@google.com> Mime-Version: 1.0 References: <20200327021058.221911-1-walken@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v2 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 , Markus Elfring , 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 5914eabd8185..ad1ce223ee6a 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)) @@ -376,7 +376,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 d78965738e7e..1e225eba4787 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1154,7 +1154,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 03fce44eee16..4c125f0a1df9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1202,7 +1202,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;