From patchwork Wed Apr 15 00:43:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11489447 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 B2F741392 for ; Wed, 15 Apr 2020 00:44:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F73520737 for ; Wed, 15 Apr 2020 00:44:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i1bpkIty" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F73520737 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 899428E000C; Tue, 14 Apr 2020 20:44:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 823698E000B; Tue, 14 Apr 2020 20:44:12 -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 738A38E000C; Tue, 14 Apr 2020 20:44:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 58F008E000B for ; Tue, 14 Apr 2020 20:44:12 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 20545181AEF1E for ; Wed, 15 Apr 2020 00:44:12 +0000 (UTC) X-FDA: 76708242744.20.eyes87_41be4388b6b5a X-Spam-Summary: 2,0,0,508f04feea1eb5ba,d41d8cd98f00b204,32liwxgykcn8xbmlfohpphmf.dpnmjovy-nnlwbdl.psh@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:3352:3865:3868:3870:3871:3874:4250:4321:4605:5007:6261:6653:6742: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.215.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: eyes87_41be4388b6b5a X-Filterd-Recvd-Size: 5158 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Apr 2020 00:44:11 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id u15so1334017pgg.14 for ; Tue, 14 Apr 2020 17:44:11 -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=UjNERNq8Aq8bZu5IIILXtpvcau9meFsW7FMuBohne+g=; b=i1bpkItyD1E346kP/89xta90B+TuHGZiUbt/x3MIvq+bvW15lb05O4/lQkdPiJ9NGQ 93sLq3bZ0gCmmBs2NzvanaM5+i/dlvyVeSpkp5CAVl26E/vZDbirlDxpFHnFoGt0asff De+h6ZaWm9zwZliT9jPHTLXv7N8vr/JVd3LV7PLjsPYaE5eCL7pyvWG7c/boM6S6SiQ8 DL83Mwca9qPVHPySOD3QPy0y9xpjNuXuzHvASgjvTwBAnYeenWMlqJp7UjOd4mpJU6bD EkyJRDjvpgKhXJbcQIC6wQknfksS4JPa7DaDbZInnGYHQ5aD/8fgByYqhQqtygZa3D/6 Fi5g== 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=UjNERNq8Aq8bZu5IIILXtpvcau9meFsW7FMuBohne+g=; b=rUIdpC3gMxcSYkaHkyh0jbow1LJ9yTGN8a6sxJI3zo0dn8cji0DsLwOi05ow86tRv2 bOcsio0rr6V3j5/MniogtsdnIeeKMv3xUaEwS1SBuVqcM7GJSnWp1GnRhw1JqgDPgtHO v7RkJhARYsZEaT/htna0BbbVIaLJDnGJB0X+hg0K/y5TMUFr+EQZ4jPzsj0atg/lgTx/ x7RP5AeV8d5K184M1Yb+hsGoxiMReWlWxisVjYkaSu40IvK8Tp/TZIMmcGBhQL39kilg VgI5KxUipvXyuPNp/vz1fGEkIjFdJABlul1560oVPL+4YOWKOAUn4EtwfIuSFpallJyF Um8w== X-Gm-Message-State: AGi0PuYMrDucGqgGC5S0yUCWnN38HfaNVcBk6ajQJcEKiadL6SGacxjA UnjoV8DZiyvK1JUsMzmNmxFzOfHwurU= X-Google-Smtp-Source: APiQypJbfrDGo32N0kQWg0rjiAGglPFM6uGFD1dgxEVO66T2nAcht+qTohafqDdYOoPPr9VCwJjI0Buz46A= X-Received: by 2002:a63:4625:: with SMTP id t37mr23188575pga.83.1586911450839; Tue, 14 Apr 2020 17:44:10 -0700 (PDT) Date: Tue, 14 Apr 2020 17:43:49 -0700 In-Reply-To: <20200415004353.130248-1-walken@google.com> Message-Id: <20200415004353.130248-7-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 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 , 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: Add API for nested write locks and convert the few call sites doing that. Signed-off-by: Michel Lespinasse Reviewed-by: Daniel Jordan --- arch/um/include/asm/mmu_context.h | 3 ++- include/linux/mmap_lock.h | 5 +++++ kernel/fork.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h index 62262c5c7785..07e1cb53a89f 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,7 +48,7 @@ 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); } diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 8b5a3cd56118..9d34b0690403 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); diff --git a/kernel/fork.c b/kernel/fork.c index 9a2511a6714f..bdb5ec3574eb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -499,7 +499,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));