From patchwork Fri Mar 27 22:51:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11463261 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 96ED414B4 for ; Fri, 27 Mar 2020 22:51:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63A2E2076B for ; Fri, 27 Mar 2020 22:51:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oy+pJbNf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63A2E2076B 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 F1B106B0073; Fri, 27 Mar 2020 18:51:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E85F06B0074; Fri, 27 Mar 2020 18:51:28 -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 D4C206B0075; Fri, 27 Mar 2020 18:51:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id B49A16B0073 for ; Fri, 27 Mar 2020 18:51:28 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 75DC1181AD0A5 for ; Fri, 27 Mar 2020 22:51:28 +0000 (UTC) X-FDA: 76642640256.03.tub16_470cb3d25d116 X-Spam-Summary: 2,0,0,69d83cc4804385f0,d41d8cd98f00b204,3b4n-xgykcgoeitsmvowwotm.kwutqvcf-uusdiks.wzo@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:25,LUA_SUMMARY:none X-HE-Tag: tub16_470cb3d25d116 X-Filterd-Recvd-Size: 5630 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 22:51:28 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id r16so8154452pls.5 for ; Fri, 27 Mar 2020 15:51:27 -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=oy+pJbNfN27cWWr81XSBaziJYK6CASpEPROsDy+RxWz/gsUiIHaho5ILpjN+1rWoFe RZhgrmyC1NEzv4mWNRVD6rMrblcdvgRDl9vwC/Hpb5tWi9WpeMARBdyviuOShwXU+eIj 0wKuYmua2wLVH4PldXOQn01xAJfMu+UgEsxgbSzE3zHtEhUTZbpR8NMkdjhHIETiRSvy ejXTRfhBCmaEMEOYUQSpakroSZaqXVgU3VIGeY3DYOs6WCXz/XscvuhN2I2VXBbMvwb4 Xlddmz8hpGwBRuywv2TIOtvKKl0P4zPYZ1oj/HFJKvmdX1OXKTqs6LYjMPwYUkM5VRj1 WZbQ== 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=tKXOG9goG5j5IChVvXG1v8HfmKAHaim0CDiJo6AZhyMNNWe7xhmGorHLGIJasidEiN OKSjNTvenUfCYxIPNCqvOqdUVqBuNuB2E1nnsr/UeG5x2P69AzFFSbFkVrw00ltXlTg+ OxTOH0bejeez7tvJlSOYhqHe9cu4rHkHgzk9gJfNSk/7z7nqkeS7kfEBU7jy23coKIcs q6+xiW/uArysL41RN/Cg1kYO1vJ3llujs7g7lg37N+aX9To49yyS94K1QyzFRMAnc5xg O8RUPEIvxJnBZCiv1d2mH3J8NKeCehAhOmilF3nLOKZrqeCPojaZ2LYvof+Xj0nfF105 ae9Q== X-Gm-Message-State: ANhLgQ3FPnWY9nO9u5XlQ+H6c+H4KCjIuiy0day2j87QGQZHOiX4ogkZ XQz+AwqV0G5LZhgn/zcCXxMzzTjbej0= X-Google-Smtp-Source: ADFU+vvWd0IqiXiflyLpZ9mh9GOnzskLcl81XiO1ntJlLp1NZ1mpzt1ePzWvfoNKv3KayCXYoxGRvL7WJ5Y= X-Received: by 2002:a17:90a:222d:: with SMTP id c42mr1811170pje.16.1585349487110; Fri, 27 Mar 2020 15:51:27 -0700 (PDT) Date: Fri, 27 Mar 2020 15:51:01 -0700 In-Reply-To: <20200327225102.25061-1-walken@google.com> Message-Id: <20200327225102.25061-10-walken@google.com> Mime-Version: 1.0 References: <20200327225102.25061-1-walken@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v3 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;