Received: by 10.223.176.5 with SMTP id f5csp1987090wra; Sun, 4 Feb 2018 17:30:18 -0800 (PST) X-Google-Smtp-Source: AH8x22619MyVl/wUroFVJJ39YR74UoObtR/AXU1YT8TGb3C5PKp/rrQ4SQtCMA/XghgXefXwNkl1 X-Received: by 10.101.96.47 with SMTP id p15mr369200pgu.390.1517794218716; Sun, 04 Feb 2018 17:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517794218; cv=none; d=google.com; s=arc-20160816; b=IwhdXkQ6KDnfmnwii+nNsmrIqh1rv5avETXu7T7+6ZLHunL6a/k3VzoeyEvE0sTfxJ IZL7pPUggnLDs+tfF1Qlvx3r/7w+fqKDBtH750jQwbtRsEtlBVyjU3CUOaXC6dnmDy7C ZemVrpqjv5fqMZuYRQ8hnSJsRxeNjuYgxfeAB67OigcM2A2GftRLYlNETKtfLBqrwH3u 9gBxuoIduPEcKhPoH1i+UTZVzgBJ1c/j6PV/Ni5UaSiVwv8q4S4T3vALRwJZfkMFjn05 IvkYRZyG9/G6cVTBhIHAAG5DBJOhqCexpWSURBAAVpzduci6Fr6ORrv3eJToEHgGqUYT ba0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QRb5YVURuHpFQYaxuSoVP8NuNXs1UH5YlFgfq+IV8jk=; b=SjO4ikkjVFh9d9n5QmGDFL6d/1usIXXk3C3xKhkEHFHZJzR2FsvEyzNMtiSFaiFfKi GqizgS+EXz7u4RGEVP5ePpbFqD4JVC1fk9YPY6sl5FAJl2qxY59IOaNYCtDPSRK2x7N4 fknzyJieov2n039FYcIXvdTuCzBQT0wgax1ivcOeqrBWlOEsnskKLdEnPid73cQ1mQj0 aNN+WWEmMNKExRPWZ9HoV1+qXlcRHo1B8wwiTs1lhuRPTefo11q8aXkEDEhnoBqcNYvr ZMj5wIGCBm1/c4MerRvqa/z89hdFH9UXgSiT+DRuavm3cfxIcbolEh2lX2oqu4TSxwtc 6hnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f80si46907pfa.111.2018.02.04.17.30.04; Sun, 04 Feb 2018 17:30:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752273AbeBEB3n (ORCPT + 99 others); Sun, 4 Feb 2018 20:29:43 -0500 Received: from mx2.suse.de ([195.135.220.15]:43425 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752310AbeBEB2C (ORCPT ); Sun, 4 Feb 2018 20:28:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AFA41ADCC; Mon, 5 Feb 2018 01:27:59 +0000 (UTC) From: Davidlohr Bueso To: akpm@linux-foundation.org, mingo@kernel.org Cc: peterz@infradead.org, ldufour@linux.vnet.ibm.com, jack@suse.cz, mhocko@kernel.org, kirill.shutemov@linux.intel.com, mawilcox@microsoft.com, mgorman@techsingularity.net, dave@stgolabs.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 03/64] mm: introduce mm locking wrappers Date: Mon, 5 Feb 2018 02:26:53 +0100 Message-Id: <20180205012754.23615-4-dbueso@wotan.suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180205012754.23615-1-dbueso@wotan.suse.de> References: <20180205012754.23615-1-dbueso@wotan.suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davidlohr Bueso This patch adds the necessary wrappers to encapsulate mmap_sem locking and will enable any future changes to be a lot more confined to here. In addition, future users will incrementally be added in the next patches. mm_[read/write]_[un]lock() naming is used. Signed-off-by: Davidlohr Bueso --- include/linux/mm.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 47c06fd20f6a..9d2ed23aa894 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -2675,5 +2676,77 @@ void __init setup_nr_node_ids(void); static inline void setup_nr_node_ids(void) {} #endif +/* + * Address space locking wrappers. + */ +static inline bool mm_is_locked(struct mm_struct *mm, + struct range_lock *range) +{ + return rwsem_is_locked(&mm->mmap_sem); +} + +/* Reader wrappers */ +static inline int mm_read_trylock(struct mm_struct *mm, + struct range_lock *range) +{ + return down_read_trylock(&mm->mmap_sem); +} + +static inline void mm_read_lock(struct mm_struct *mm, struct range_lock *range) +{ + down_read(&mm->mmap_sem); +} + +static inline void mm_read_lock_nested(struct mm_struct *mm, + struct range_lock *range, int subclass) +{ + down_read_nested(&mm->mmap_sem, subclass); +} + +static inline void mm_read_unlock(struct mm_struct *mm, + struct range_lock *range) +{ + up_read(&mm->mmap_sem); +} + +/* Writer wrappers */ +static inline int mm_write_trylock(struct mm_struct *mm, + struct range_lock *range) +{ + return down_write_trylock(&mm->mmap_sem); +} + +static inline void mm_write_lock(struct mm_struct *mm, struct range_lock *range) +{ + down_write(&mm->mmap_sem); +} + +static inline int mm_write_lock_killable(struct mm_struct *mm, + struct range_lock *range) +{ + return down_write_killable(&mm->mmap_sem); +} + +static inline void mm_downgrade_write(struct mm_struct *mm, + struct range_lock *range) +{ + downgrade_write(&mm->mmap_sem); +} + +static inline void mm_write_unlock(struct mm_struct *mm, + struct range_lock *range) +{ + up_write(&mm->mmap_sem); +} + +static inline void mm_write_lock_nested(struct mm_struct *mm, + struct range_lock *range, int subclass) +{ + down_write_nested(&mm->mmap_sem, subclass); +} + +#define mm_write_nest_lock(mm, range, nest_lock) \ + down_write_nest_lock(&(mm)->mmap_sem, nest_lock) + #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */ -- 2.13.6