From patchwork Fri Mar 27 22:50: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: 11463255 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 95C3114B4 for ; Fri, 27 Mar 2020 22:51:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62BCD2071B for ; Fri, 27 Mar 2020 22:51:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mOxcA4kt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62BCD2071B 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 A681C6B0070; Fri, 27 Mar 2020 18:51:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A17986B0071; Fri, 27 Mar 2020 18:51:21 -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 8B78F6B0072; Fri, 27 Mar 2020 18:51:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 680E36B0070 for ; Fri, 27 Mar 2020 18:51:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2E5918248068 for ; Fri, 27 Mar 2020 22:51:21 +0000 (UTC) X-FDA: 76642639962.09.cars13_45f49950be163 X-Spam-Summary: 2,0,0,6013770ab067986e,d41d8cd98f00b204,3z4n-xgykcgiwalkengoogle.comlinux-mmkvack.org@flex--walken.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1801:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3868:3870:3871:3874:4250:4321:4605:5007:6261:6653:6742:7903:8660:9969:10004:10400:11026:11473:11657:11658:11914:12043:12296:12297:12438:12555:12895:12986:13141:13148:13153:13228:13230:14096:14097:14181:14394:14659:14721:21080:21220:21433:21444:21451:21627:21990:30054,0,RBL:209.85.210.201:@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:25,LUA_SUMMARY:none X-HE-Tag: cars13_45f49950be163 X-Filterd-Recvd-Size: 5972 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 22:51:20 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id s8so9563067pfd.23 for ; Fri, 27 Mar 2020 15:51:20 -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=9JjmHpcSetUzd2DQK65fziZHzZsJKOqreOscrjvhn1w=; b=mOxcA4ktC5UqT4y7L4l/BUK52XTyHPa9goELov+T+H7q5BNgQv4ayBvYB3qZIq9JD5 BkrHzzRy/mikJbiyQehvSUDR14j4lc/SbRKPhL9SAWz1X46altDUabXYu7JBewzLNhH7 pS9hADkzlEnvPIHN/WaCGYkx5egXD8vAVXJLDFGHDZwQO3mW7QarQNLDLYr/HPIplrzN AqeNYlxnIIHjDB0mfNordUwzkzCuYd8y9bB4YaOqpj/GGG625fPja9UFrVPih7fWRV6n fVQD0AsnlmIaD6dXFcUaWdvhs9nnb6+egsYg2TytI/wJXBHhtU03HIm7koHhFeJsmG42 552w== 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=9JjmHpcSetUzd2DQK65fziZHzZsJKOqreOscrjvhn1w=; b=jg4HzMtRUHPEwx6CtqxJNYlMS21r5KeCShcBdotDd/Xc3a7uLG6jgO5apR+kCK8sBq Pb4GjQAazGA091oBVuiD9kJIZazr0fv8fRf8pQCxSb2v61JgLjeG0Dk1gzSNvwq+cFN+ tPk1r2qagyDUKnVGdq4HFzNgTsrwDKQGntvIcMTxzL0oML/rjTpAP7eQy/JdEKnQr34f fBgsBR3HsSJk9Rjn5/OesyRbQjDit7tNL8HiIt66wsPRUQB9S27RzaGwpcMjQYAqWQmU n2Z8oIFGc9oXxvPHmThSLN//uPylQfMz9G+EioVK+BoiWW/zyGul6SlhSOIaaeuc7zPm K+fA== X-Gm-Message-State: ANhLgQ3elCC79JDSQTkYSU8UM1szKG1CKy5E/N+8MZe6pqbrq04u6vWE a97Bjc4rOdpjGlCBhsxI9fr3cWJPmyQ= X-Google-Smtp-Source: ADFU+vuSsgM/jrzZ4eZBp7cSHVGsQXOE2CSs9MIM1i2Xg2Z0bI/jIRcAISkde1W+6I9nqAHgiJTRgVoY8Lk= X-Received: by 2002:a63:f243:: with SMTP id d3mr1605790pgk.254.1585349479677; Fri, 27 Mar 2020 15:51:19 -0700 (PDT) Date: Fri, 27 Mar 2020 15:50:58 -0700 In-Reply-To: <20200327225102.25061-1-walken@google.com> Message-Id: <20200327225102.25061-7-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 06/10] mmap locking API: convert nested write lock sites 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: Add API for nested write locks and convert the few call sites doing that. Signed-off-by: Michel Lespinasse --- arch/um/include/asm/mmu_context.h | 5 +++-- include/linux/mmap_lock.h | 11 +++++++++++ kernel/fork.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h index 62262c5c7785..cc15173f7518 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -8,6 +8,7 @@ #include #include +#include #include @@ -47,9 +48,9 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new) * when the new ->mm is used for the first time. */ __switch_mm(&new->context.id); - down_write_nested(&new->mmap_sem, 1); + mmap_write_lock_nested(new, 1); uml_setup_stubs(new); - mmap_write_unlock(new); + mmap_write_unlock_nested(new); } static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 8b5a3cd56118..36fb758401d6 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -11,6 +11,11 @@ static inline void mmap_write_lock(struct mm_struct *mm) down_write(&mm->mmap_sem); } +static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass) +{ + down_write_nested(&mm->mmap_sem, subclass); +} + static inline int mmap_write_lock_killable(struct mm_struct *mm) { return down_write_killable(&mm->mmap_sem); @@ -26,6 +31,12 @@ static inline void mmap_write_unlock(struct mm_struct *mm) up_write(&mm->mmap_sem); } +/* Pairs with mmap_write_lock_nested() */ +static inline void mmap_write_unlock_nested(struct mm_struct *mm) +{ + up_write(&mm->mmap_sem); +} + static inline void mmap_downgrade_write_lock(struct mm_struct *mm) { downgrade_write(&mm->mmap_sem); diff --git a/kernel/fork.c b/kernel/fork.c index c321910d46e8..3460308b2213 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -497,7 +497,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, /* * Not linked in yet - no deadlock potential: */ - down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING); + mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING); /* No ordering required: file already has been exposed. */ RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm)); @@ -612,7 +612,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, /* a new mm has just been created */ retval = arch_dup_mmap(oldmm, mm); out: - mmap_write_unlock(mm); + mmap_write_unlock_nested(mm); flush_tlb_mm(oldmm); mmap_write_unlock(oldmm); dup_userfaultfd_complete(&uf);