From patchwork Mon Feb 24 20:30:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11401485 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 9F9B8924 for ; Mon, 24 Feb 2020 20:31:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63A7F20675 for ; Mon, 24 Feb 2020 20:31:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Kpt+Eby1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63A7F20675 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 B8EAE6B0010; Mon, 24 Feb 2020 15:31:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A765E6B0032; Mon, 24 Feb 2020 15:31:04 -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 98C4B6B0037; Mon, 24 Feb 2020 15:31:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 724A56B0010 for ; Mon, 24 Feb 2020 15:31:04 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 21CCF283A for ; Mon, 24 Feb 2020 20:31:04 +0000 (UTC) X-FDA: 76526164848.16.boys17_26581bb57184e X-Spam-Summary: 2,0,0,63b7a4fd94aedfc0,d41d8cd98f00b204,3hjjuxgykcdunrcbvexffxcv.tfdczelo-ddbmrtb.fix@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:3865:3867:3870:3871:3874:4250:4321:4605:5007:6120:6261:6653:7875:7901:9969:10004:10400:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:14096:14097:14110:14181:14659:14721:21080:21444:21451:21627:21990,0,RBL:209.85.215.202:@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:23,LUA_SUMMARY:none X-HE-Tag: boys17_26581bb57184e X-Filterd-Recvd-Size: 5213 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 20:31:03 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id 22so3420423pgw.17 for ; Mon, 24 Feb 2020 12:31:03 -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=6WvjRiSpown38CK25rwzKHDBkhPoLyfSbpmVDS9ELyM=; b=Kpt+Eby1mRPxXLxVO2mVgj1xfhsuqOtEa80HGpVoYQgDfjpEbCS71R9wuRbdEFXcEN BBB8zz72QzoMiYJW2YD7uh+P5zZBIRG89G8WzweFWmXUElAKP9yHJe4SQsYJ7KdKSrMw t7wCuGQbTbaH1dhrqj7kyZ2TiA8YCi7yrTZlKRoOpX46CcKpLQQ6hNOmyBGUMWcgixZl CMAwgfybLy9/QMRTZUSkt8bQBZMIAIcNnLbpRf7mqxkbSxB1XYFEK6debDW9Gi11hgCj zvBqssNhI/I14YwwRhqvQ1mr4A7nVWV8u+iacLTOXcWQcqVqhexTVguezqOCVRzMvXXa d6NA== 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=6WvjRiSpown38CK25rwzKHDBkhPoLyfSbpmVDS9ELyM=; b=IbKnKJTqrYWkhYHAeKeAn8lr/LCKH1ArNLqYWVZVsLyv7I+FJBjIB/iAcPH41bSe4m MTUZmQCTXjQsh6RC5iYGS7F7OzndoWcJCEOlS2mW+ZexlXFEtZvus4d2CQQ7QBi9C0+7 VdmVqiT6RQ9xmvVWtUaWSgFDGWO/fc9ZGP5yICCRg2IFKIR0Fe5kBkfE8v5MqYYolJwr fln0ntCbM3DGxkqycfTS5ChGKab0V1TO9qOyl6FPx6XtXlZB4JFEivSpAL7FcqB5StRZ AG5dpQwf6OpIrGaoa4VZ4FHi0yiOm3AFdHq+VVJjM8qUd7JaoVlz9KLd2SKmfa3Ygq/5 JPtQ== X-Gm-Message-State: APjAAAVZKL46OGJ/70SWtnqurEOSaEuYg+FSlY4SRtPYASDzbYwl7spz QqCYMKSx8S8slNGZvcALkWQJu3zgXCc= X-Google-Smtp-Source: APXvYqy1kQ/242Ir7ArBeTTk0abFUYNw7P+UA6Wd82K50T52J/W5OyTQYoq/T0PbN3zbDq0gOqHYD947cHY= X-Received: by 2002:a63:4e22:: with SMTP id c34mr18679078pgb.263.1582576262234; Mon, 24 Feb 2020 12:31:02 -0800 (PST) Date: Mon, 24 Feb 2020 12:30:34 -0800 In-Reply-To: <20200224203057.162467-1-walken@google.com> Message-Id: <20200224203057.162467-2-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 01/24] MM locking API: initial implementation as rwsem wrappers 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 wraps the existing mmap_sem related rwsem calls into a new MM locking API. This is in preparation to extending that API to support locking fine grained memory ranges. Signed-off-by: Michel Lespinasse --- include/linux/mm.h | 1 + include/linux/mm_lock.h | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 include/linux/mm_lock.h diff --git include/linux/mm.h include/linux/mm.h index cfaa8feecfe8..052f423d7f67 100644 --- include/linux/mm.h +++ include/linux/mm.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git include/linux/mm_lock.h include/linux/mm_lock.h new file mode 100644 index 000000000000..b5f134285e53 --- /dev/null +++ include/linux/mm_lock.h @@ -0,0 +1,59 @@ +#ifndef _LINUX_MM_LOCK_H +#define _LINUX_MM_LOCK_H + +static inline void mm_init_lock(struct mm_struct *mm) +{ + init_rwsem(&mm->mmap_sem); +} + +static inline void mm_write_lock(struct mm_struct *mm) +{ + down_write(&mm->mmap_sem); +} + +static inline int mm_write_lock_killable(struct mm_struct *mm) +{ + return down_write_killable(&mm->mmap_sem); +} + +static inline bool mm_write_trylock(struct mm_struct *mm) +{ + return down_write_trylock(&mm->mmap_sem) != 0; +} + +static inline void mm_write_unlock(struct mm_struct *mm) +{ + up_write(&mm->mmap_sem); +} + +static inline void mm_downgrade_write_lock(struct mm_struct *mm) +{ + downgrade_write(&mm->mmap_sem); +} + +static inline void mm_read_lock(struct mm_struct *mm) +{ + down_read(&mm->mmap_sem); +} + +static inline int mm_read_lock_killable(struct mm_struct *mm) +{ + return down_read_killable(&mm->mmap_sem); +} + +static inline bool mm_read_trylock(struct mm_struct *mm) +{ + return down_read_trylock(&mm->mmap_sem) != 0; +} + +static inline void mm_read_unlock(struct mm_struct *mm) +{ + up_read(&mm->mmap_sem); +} + +static inline bool mm_is_locked(struct mm_struct *mm) +{ + return rwsem_is_locked(&mm->mmap_sem) != 0; +} + +#endif /* _LINUX_MM_LOCK_H */