From patchwork Fri Jan 28 13:09:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 12728512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7807C433EF for ; Fri, 28 Jan 2022 13:10:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1FC36B0081; Fri, 28 Jan 2022 08:10:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A399B6B008A; Fri, 28 Jan 2022 08:10:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C98A6B0081; Fri, 28 Jan 2022 08:10:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id 23B576B0081 for ; Fri, 28 Jan 2022 08:10:12 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D39AD181AC1E9 for ; Fri, 28 Jan 2022 13:10:11 +0000 (UTC) X-FDA: 79079729022.06.02167B0 Received: from server.lespinasse.org (server.lespinasse.org [63.205.204.226]) by imf21.hostedemail.com (Postfix) with ESMTP id 7515B1C001D for ; Fri, 28 Jan 2022 13:10:10 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-52-ed; t=1643375407; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=IpgfV+Eq7IPQY0KnkKUe0KkKJvFgOUOWn3NBKGqibKI=; b=IctmLJgF3nwhCdB6/nN2BKCbg/+ri5TtsREb7+zxwUF2hZZ/LIaVfPhxghmetQ7a/3M3q Q9VY54et8G/l7GVBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-52-rsa; t=1643375407; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=IpgfV+Eq7IPQY0KnkKUe0KkKJvFgOUOWn3NBKGqibKI=; b=FUNzHOA9sCQEnD5fVX1ed8sbazmtJonEYYM3h4apZTLILl70sj90JbvB3WRW8tXEGINiv IzWe9oPGLIvbeoIBpr9CdyIGkNvw0FYKFNdqK61xuYDoKOkBCEVO0ytOejTTj5Eu2J2FeQV SzNS0w/kdVod39/vbZHvGCL1X6e9d3nbT8J96MVYI96Lr29e+Mg2IDmWtjnSTVWX883uarj n5hllQbi6wTh0FF/uhaA2q+Ct6pIwn/7yizD86pU4Px2VTdvxBK3QaA4JKP5yjI3PylzCqJ gMcCeqKorC8BG/Wp7pQbWsbL/vTP+8SdVKrYWbX00ASCHnKCyqKiI+vLP7XA== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 02248160967; Fri, 28 Jan 2022 05:10:07 -0800 (PST) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id DF25420473; Fri, 28 Jan 2022 05:10:06 -0800 (PST) From: Michel Lespinasse To: Linux-MM , linux-kernel@vger.kernel.org, Andrew Morton Cc: kernel-team@fb.com, Laurent Dufour , Jerome Glisse , Peter Zijlstra , Michal Hocko , Vlastimil Babka , Davidlohr Bueso , Matthew Wilcox , Liam Howlett , Rik van Riel , Paul McKenney , Song Liu , Suren Baghdasaryan , Minchan Kim , Joel Fernandes , David Rientjes , Axel Rasmussen , Andy Lutomirski , Michel Lespinasse Subject: [PATCH v2 11/35] mm: rcu safe vma freeing Date: Fri, 28 Jan 2022 05:09:42 -0800 Message-Id: <20220128131006.67712-12-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220128131006.67712-1-michel@lespinasse.org> References: <20220128131006.67712-1-michel@lespinasse.org> MIME-Version: 1.0 X-Stat-Signature: ij4qudnob56pjykitbrozhuksrnkmitz X-Rspam-User: nil Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=lespinasse.org header.s=srv-52-ed header.b=IctmLJgF; dkim=pass header.d=lespinasse.org header.s=srv-52-rsa header.b=FUNzHOA9; spf=pass (imf21.hostedemail.com: domain of walken@lespinasse.org designates 63.205.204.226 as permitted sender) smtp.mailfrom=walken@lespinasse.org; dmarc=pass (policy=none) header.from=lespinasse.org X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7515B1C001D X-HE-Tag: 1643375410-67093 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 prepares for speculative page faults looking up and copying vmas under protection of an rcu read lock, instead of the usual mmap read lock. Note - it might also be feasible to just use SLAB_TYPESAFE_BY_RCU when creating the vm_area_cachep, but that's probably too subtle to consider here. Signed-off-by: Michel Lespinasse --- include/linux/mm_types.h | 16 +++++++++++----- kernel/fork.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index e4965a6f34f2..b6678578a729 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -374,12 +374,18 @@ struct anon_vma_name { struct vm_area_struct { /* The first cache line has the info for VMA tree walking. */ - unsigned long vm_start; /* Our start address within vm_mm. */ - unsigned long vm_end; /* The first byte after our end address - within vm_mm. */ + union { + struct { + /* VMA covers [vm_start; vm_end) addresses within mm */ + unsigned long vm_start, vm_end; - /* linked list of VM areas per task, sorted by address */ - struct vm_area_struct *vm_next, *vm_prev; + /* linked list of VMAs per task, sorted by address */ + struct vm_area_struct *vm_next, *vm_prev; + }; +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + struct rcu_head vm_rcu; /* Used for deferred freeing. */ +#endif + }; struct rb_node vm_rb; diff --git a/kernel/fork.c b/kernel/fork.c index d75a528f7b21..2e5f2e8de31a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -371,10 +371,23 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) return new; } +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT +static void __vm_area_free(struct rcu_head *head) +{ + struct vm_area_struct *vma = container_of(head, struct vm_area_struct, + vm_rcu); + kmem_cache_free(vm_area_cachep, vma); +} +#endif + void vm_area_free(struct vm_area_struct *vma) { free_vma_anon_name(vma); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + call_rcu(&vma->vm_rcu, __vm_area_free); +#else kmem_cache_free(vm_area_cachep, vma); +#endif } static void account_kernel_stack(struct task_struct *tsk, int account)