From patchwork Mon Feb 24 20:30: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: 11401515 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 576EC14BC for ; Mon, 24 Feb 2020 20:31:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 251E220675 for ; Mon, 24 Feb 2020 20:31:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZmRudue6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 251E220675 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 5E3FD6B009D; Mon, 24 Feb 2020 15:31:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 594766B009F; Mon, 24 Feb 2020 15:31:41 -0500 (EST) 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 45C6F6B00A0; Mon, 24 Feb 2020 15:31:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 2C7F76B009D for ; Mon, 24 Feb 2020 15:31:41 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D8093180AD811 for ; Mon, 24 Feb 2020 20:31:40 +0000 (UTC) X-FDA: 76526166360.22.key43_2bb104bbff709 X-Spam-Summary: 2,0,0,ff71fe54d5303b26,d41d8cd98f00b204,3qzjuxgykcfoo2dc6f8gg8d6.4gedafmp-eecn24c.gj8@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:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2897:3138:3139:3140:3141:3142:3152:3354:3865:3867:3868:3870:3871:3874:4321:4605:5007:6120:6261:6653:7875:7901:9969:10004:10400:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12895:12986:13161:13229:14096:14097:14181:14659:14721:21080:21444:21451:21627:30029:30054:30070,0,RBL:209.85.216.73:@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: key43_2bb104bbff709 X-Filterd-Recvd-Size: 5984 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 20:31:40 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id ds13so414210pjb.6 for ; Mon, 24 Feb 2020 12:31:40 -0800 (PST) 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=4nToiY2tbBhHPVFjSeElw81KToEmHGD/Ax+HeTGm2FY=; b=ZmRudue6xhsLsfjHOrs5OZYXuogq0BvUy+AWUgnWXuy6YaXq5hxFrvntyKyc/+r7Tu wqQ+OHbpUU6qU016Ux5wi0dz6RrBxjHeibzG9XtifnWkPLhQJcvQwcdtmxBSXAaMa9Yg Rbhl9UP5oasFmJIkRD0Bxr9vpLcwzwaz2Qg3dcQXPNzDf4DTUSzOb9DY7/kx1gBnhlIh XOuHoNvmcMNY6YyVz72/0M7RJcIt8g4zyjNVHy44vlW6hhLBNy6RuyAnm1vIDJzgb/k4 BaYfma8TxoHrwt1eCIQjhGRufZWNfSvD/bzOinQHD/dPv6MWZ3N2trZeck9MAXoKYeXd np6g== 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=4nToiY2tbBhHPVFjSeElw81KToEmHGD/Ax+HeTGm2FY=; b=rl4miSP1InHP2HJws4Wlc55WF7gJYFYuXyYccWlTnfzUC/2Y40/T1PxEvqk0okp8Nw 9Pgbk85GIjg7JxDGFBIK+x1sd/FBFiYT+UsYNz9MqpPMxegE/aKwipOrzVBeE/KA22fN Hwxa5RQoqsHVlgvuKYxtAnqFtKRxliXfdxb6nKW1TFtlJ/LjqqNSZKPSvQ0jB0f+H2/C z+Lq+YbFhH9dpRWRqgYSzVvwODD2QGcRbhavMBZ9f/3sgqhxgBRpAAotkfFC8qkIqcUt wWFRtZ+ESQ6NKoWxT8jdwn4OVIh0MrmhQTI52iDPc4zfpbGw0OLqGbQNa58XBAg0gL7O khUQ== X-Gm-Message-State: APjAAAW25hGqeO0s0mX3tDmZFUyeH9MmvEoQZ98QHYT+VaHsHnVn26qI gZSwYyhFl7v36v09iXFjypOsq5P4Hgs= X-Google-Smtp-Source: APXvYqwrigCJMUBjQPXEqSR8Xo2JBAEokqnyrTUE8kveT6DGltATjSRfluXb+VLmxJISQilaiMeAxXMH1Kw= X-Received: by 2002:a63:3383:: with SMTP id z125mr2687769pgz.265.1582576299143; Mon, 24 Feb 2020 12:31:39 -0800 (PST) Date: Mon, 24 Feb 2020 12:30:49 -0800 In-Reply-To: <20200224203057.162467-1-walken@google.com> Message-Id: <20200224203057.162467-17-walken@google.com> Mime-Version: 1.0 References: <20200224203057.162467-1-walken@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [RFC PATCH 16/24] MM locking API: add vma locking API From: Michel Lespinasse To: Peter Zijlstra , Andrew Morton , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , "Liam R . Howlett" , Jerome Glisse , Davidlohr Bueso , David Rientjes Cc: linux-mm , 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: This change adds the mm_vma_lock() and mm_vma_unlock() functions, which are to be used to protect per-mm global structures (such as the vma rbtree) when writers only hold a range lock. The functions are no-ops when CONFIG_MM_LOCK_RANGE is not enabled, as mmap_sem already protects such structures in that case. Signed-off-by: Michel Lespinasse --- include/linux/mm_lock.h | 24 ++++++++++++++++++++---- include/linux/mm_types.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git include/linux/mm_lock.h include/linux/mm_lock.h index a4d60bd56899..ebcc46bba211 100644 --- include/linux/mm_lock.h +++ include/linux/mm_lock.h @@ -14,6 +14,9 @@ static inline void mm_init_lock(struct mm_struct *mm) init_rwsem(&mm->mmap_sem); } +static inline void mm_vma_lock(struct mm_struct *mm) {} +static inline void mm_vma_unlock(struct mm_struct *mm) {} + static inline void mm_init_coarse_lock_range(struct mm_lock_range *range) {} static inline void mm_init_lock_range(struct mm_lock_range *range, unsigned long start, unsigned long end) {} @@ -107,6 +110,9 @@ static inline void mm_init_lock(struct mm_struct *mm) init_rwsem(&mm->mmap_sem); } +static inline void mm_vma_lock(struct mm_struct *mm) {} +static inline void mm_vma_unlock(struct mm_struct *mm) {} + static inline void mm_init_coarse_lock_range(struct mm_lock_range *range) { range->mm = NULL; @@ -131,10 +137,11 @@ static inline bool mm_range_is_coarse(struct mm_lock_range *range) #define __DEP_MAP_MM_LOCK_INITIALIZER(lockname) #endif -#define MM_LOCK_INITIALIZER(name) { \ - .mutex = __MUTEX_INITIALIZER(name.mutex), \ - .rb_root = RB_ROOT, \ - __DEP_MAP_MM_LOCK_INITIALIZER(name) \ +#define MM_LOCK_INITIALIZER(name) { \ + .mutex = __MUTEX_INITIALIZER(name.mutex), \ + .rb_root = RB_ROOT, \ + .vma_mutex = __MUTEX_INITIALIZER(name.vma_mutex), \ + __DEP_MAP_MM_LOCK_INITIALIZER(name) \ } #define MM_COARSE_LOCK_RANGE_INITIALIZER { \ @@ -148,9 +155,18 @@ static inline void mm_init_lock(struct mm_struct *mm) mutex_init(&mm->mmap_sem.mutex); mm->mmap_sem.rb_root = RB_ROOT; + mutex_init(&mm->mmap_sem.vma_mutex); lockdep_init_map(&mm->mmap_sem.dep_map, "&mm->mmap_sem", &__key, 0); } +static inline void mm_vma_lock(struct mm_struct *mm) { + mutex_lock(&mm->mmap_sem.vma_mutex); +} + +static inline void mm_vma_unlock(struct mm_struct *mm) { + mutex_unlock(&mm->mmap_sem.vma_mutex); +} + static inline void mm_init_lock_range(struct mm_lock_range *range, unsigned long start, unsigned long end) { range->start = start; diff --git include/linux/mm_types.h include/linux/mm_types.h index 941610c906b3..c40341d851cb 100644 --- include/linux/mm_types.h +++ include/linux/mm_types.h @@ -292,9 +292,11 @@ struct mm_lock { struct mutex mutex; struct rb_root rb_root; unsigned long seq; + struct mutex vma_mutex; #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif + }; #endif