Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp145329ybz; Tue, 21 Apr 2020 17:17:25 -0700 (PDT) X-Google-Smtp-Source: APiQypLM7dsF1O8oR2jjRtQ2thVDo4/3BFjHqnyM3E1j9dRLTdJAx8P3ffzZKLCnf5Ro0yCFIewr X-Received: by 2002:a05:6402:2203:: with SMTP id cq3mr9259881edb.154.1587514645408; Tue, 21 Apr 2020 17:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587514645; cv=none; d=google.com; s=arc-20160816; b=SD1xUabd5zFBqV6TqpilErMsL7yvQAOTxSACZOyQqX2f8bjnPGvVWyF/3zfhdAbuhe sNHLqaM3HubMa79yZVBSp5XPTxtfUPorEXzD+b7+ik5YrfdLaP6CclLYY3wepygBqjC6 SAbnVBV+SIF26l8rl8mE3b+oss3SSV533UDEkCN4gWu5yNt9WmpWQePSs4ZrT0icWRlV Ii0Tq1iPBPyu+aVy5lW92UQiIuvL2t8EoaSWSJgaPLwmJqWfNVWfMjD1KYaF1y7+fA9z ZUgR5PrpCeesXvXZj+z1qTuMHGy/2WRUeArOkVts2QablbIuIUDqu5BDEO4mmXgbprP3 RxNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=BiEEiVkzSVoyEqKh7AVUXyeKMpCUvM4D35tqNT5BDzI=; b=0BCnLqV3cfEerle0UWzgSppwGViozbqG6jpXO/8aviTpQaaCDUcif+CZ82NKo9Gvae Mh7f7qU2bBHC1udW1bPJeQh7652hDAPV8CgxYxMuBNmd4fseNiVozV9N1LrjBPycH01g 52HokqEaeXR262bOefDRfIE4JYdQo0veuAH7/t877vgjaFXMFJzPDIj8D7O8r5yijoow Vf3qqXtIQ0Z/X0LJC0WpqVXJVVxVBPJF41InYTaYHGuzt32SQOW5CBiOvCc+qXYsyMxP cqOoAJhbwB2UEpmQDAUxgUTa1y/KbPwKIlPq/E28yVkA/+JwmLNsPo/cHtcByIJT7hg9 ht1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZBxfSTH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw10si2512865ejb.369.2020.04.21.17.17.02; Tue, 21 Apr 2020 17:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZBxfSTH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726472AbgDVAO4 (ORCPT + 99 others); Tue, 21 Apr 2020 20:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726409AbgDVAOl (ORCPT ); Tue, 21 Apr 2020 20:14:41 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2E41C0610D5 for ; Tue, 21 Apr 2020 17:14:39 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id y14so199922pgk.18 for ; Tue, 21 Apr 2020 17:14:39 -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=BiEEiVkzSVoyEqKh7AVUXyeKMpCUvM4D35tqNT5BDzI=; b=ZBxfSTH4Jf/kixOoAnairq3UwrJnJI9xCIxf/bGiCkHeAm9ChAhBbaaQdZ/RqNx/6v py3PlzefCpfQkI5EZo2elGDyIMyP4qb0jDB2WzxJt8RrKrqsDDVD290X5CA51GNf3SaY knC0BULD9D+uDIaSdTzAnm5JBMYj+9C77WmxTcRL03wMyePjbrDM/pL9PkSx9dzVzNpv 41MmKfgXzWaJ5JmHaLQ0EJ5q0aPZ1FyLo4tEPxBTVjsjJGxr7du0pbW+Er7qeK+eEump Gs7IoopoPEQxl8aHYPPTNvnRsLS4NuqttG0iX6mbR+ZDTybj23mV+0nNOFT9XqYFjigK 7PrA== 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=BiEEiVkzSVoyEqKh7AVUXyeKMpCUvM4D35tqNT5BDzI=; b=RODRg4LKS3ajdqQXJK0zCGiWQo6HmCBzC/jBzw4SCeSfSp71tNM3MphPQAr6xwMZj9 bX9JLYXQgEBlpBQePl83lzqyhPlGa84rr4EeQfKsvex4aQgeC9LHQ51qrvN7wacuaA6S 9pr02vQ9SNnebHUkNUMAiKvlBpMQ1viz6BSREGOKMIVDCCuDS/v/c+AsLAWlOAgIamhR lVZLnIvBuRLYSsZ6nnFKHApkyVwwXN7r6C5wKhQdk3aGYWh3FwNRKYSIQVzoCPoIexci wQR64NqvQ2RPrTMT6V09QJItq/Ku6d6o1BiOwNRE2gOhOVGOIE6ZXn+4xORGx3hylg9G puDg== X-Gm-Message-State: AGi0PubNsuFDgadc32EmTC2NBJMXHyX073dDFTl7qxAGSYfI9Tl72dBT yX9cJtsTi1kbGTQjku1tyGL3KEQkHUY= X-Received: by 2002:a63:c007:: with SMTP id h7mr23391466pgg.428.1587514479245; Tue, 21 Apr 2020 17:14:39 -0700 (PDT) Date: Tue, 21 Apr 2020 17:14:18 -0700 In-Reply-To: <20200422001422.232330-1-walken@google.com> Message-Id: <20200422001422.232330-7-walken@google.com> Mime-Version: 1.0 References: <20200422001422.232330-1-walken@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v5 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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..17ddd4edf875 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, SINGLE_DEPTH_NESTING); uml_setup_stubs(new); mmap_write_unlock(new); } diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 97ac53b66052..a757cb30ae77 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 41d3f45c058e..a5d1d20ccba7 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)); -- 2.26.1.301.g55bc3eb7cb9-goog