From patchwork Fri Jan 27 19:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119255 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 32160C54EAA for ; Fri, 27 Jan 2023 19:41:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C77766B008A; Fri, 27 Jan 2023 14:41:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C271A6B008C; Fri, 27 Jan 2023 14:41:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC7D76B0092; Fri, 27 Jan 2023 14:41:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 99D946B008A for ; Fri, 27 Jan 2023 14:41:55 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 70EED16039C for ; Fri, 27 Jan 2023 19:41:55 +0000 (UTC) X-FDA: 80401599390.05.F00E792 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf17.hostedemail.com (Postfix) with ESMTP id BBFAA40021 for ; Fri, 27 Jan 2023 19:41:44 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=oFyOjlhE; spf=pass (imf17.hostedemail.com: domain of 37yjUYwYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37yjUYwYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674848504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Nu9/mdu38G6WtBjXb6Do7xpUyt6CdrDbmAUDhoyp47k=; b=6cVtnSH1CYtPAOqYOhW2Jx9BE3eqWl+9Gn30UfIBeMJmfIdakZGShc09IflDAzzyXe1xXA PxdA1KYnwhEHvDgahHHyN7ZIkUS3KRzYunNTeyik1kOMb6sknYqYp1i9dV1w0ro9WKsjHy fFixl4XxLsKKHuPSDgS3pE1bMHdLj8A= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=oFyOjlhE; spf=pass (imf17.hostedemail.com: domain of 37yjUYwYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37yjUYwYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674848504; a=rsa-sha256; cv=none; b=PRo+1smCHlqdmuCSQcHIe3kx7Dst87zWZDnNJco/6S4aAGooAAQhdatgNRYXJ/5TE4tlXR J0tyMbMToYs2qD6U44T8mxfTPBWlEIQiPrpwn3ZOdHB+dwzKVFRE+LTEe3jvFyHsVvQ5U6 SnCa2uWEo/i5MghUVf989ZF/CGiCFWI= Received: by mail-yb1-f202.google.com with SMTP id t13-20020a056902018d00b0074747131938so6388726ybh.12 for ; Fri, 27 Jan 2023 11:41:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Nu9/mdu38G6WtBjXb6Do7xpUyt6CdrDbmAUDhoyp47k=; b=oFyOjlhEa6jPD1d+pKzu8xqMu9sShcBJM0zkcdXAO9bWZHfs5hDegJ8sEKWFr4AQNl iGPCIH7iC8aR5RiIjRoH9W2KUncZPWl0b5vsJXQEB2UE60mYiP5ldYuNlEW3dM96CgJp +2KdvoCyVN7G6APzAMKWAfXHTUhAA+JaJZhJgfnGwlr68Zr0GLZrYj2YnOQkKo96sWGj Ng0DOWnRANnP+XQns5edhVeWyYl+9EdfDgkHbYKOkVF++Ku/0IaWanDTI7HqCQuL/w5R edw8ZGqmSQJCCmVgs5lV30HhGrOZqx2K3qMJgNbHCqjkT1CdH2dJNnKk0QEKLZZ9jCPS y7/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Nu9/mdu38G6WtBjXb6Do7xpUyt6CdrDbmAUDhoyp47k=; b=POMaYp8TtRMrfQf+Io5hO35N9V1vIlYX0xZBh54kZlCwtzJEAhiTH/0r/5LpiRhUT3 eARGXFKe4eoSt77RxE01vXCoaBUshLGkxu3ev6UBStUMZcoMs7UsWDLvjRcCRyynwJND +PqogY5Iiz5vyIgYSyiiPae0ky8D1EjJce7bWTK65Z3URS1/uC3sQqCGwyrgZmCjEGC6 FIYQGOucH9QauSbvcwJVlRjaqzkT3VCCaEaH76FXJn4YeX1Bi3xxLhytSiiu1EgyC3a8 NHnxlMob5fehAF3GbOqBedogMX+I4BYvWhTdQaX5fWvgrAPJZoWHVpPPG/Rdf4bxtwX3 s+0w== X-Gm-Message-State: AFqh2kpXBXwzeDnvTomSBzieL/jv+ysE77wWfcy0uTL7b/v1vtd+QHlm PyiyD+GyQc6dwJginNITL4JYwT+g1UA= X-Google-Smtp-Source: AMrXdXtMMT5r56SGjlxKGvDbQirEmfUIu1ilIQcv1/3wi/4TSk/ascWeVtYTcuwkoFwuriGWfFUnQoKWHlg= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a0d:cdc7:0:b0:4df:f712:5d57 with SMTP id p190-20020a0dcdc7000000b004dff7125d57mr3818080ywd.303.1674848495850; Fri, 27 Jan 2023 11:41:35 -0800 (PST) Date: Fri, 27 Jan 2023 11:40:46 -0800 In-Reply-To: <20230127194110.533103-1-surenb@google.com> Mime-Version: 1.0 References: <20230127194110.533103-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230127194110.533103-10-surenb@google.com> Subject: [PATCH v2 09/33] mm: rcu safe VMA freeing From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BBFAA40021 X-Stat-Signature: apqwounq4u4dskbpx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EyHGOUtuhVyXdEbLOcvdYdiuD859Vn3+RZC4Yzfr8YPYc5xsoGWQ1R1v54MznE02sEekes5GuVGRIJn8VPXO0Tt5NQw0rm8K6L3EgmL0lGJT/QjhUgbs7VAMLW2Y46I853XD7Oz6WQJJvMz1J4nDULDjJFcR2dnpPIOpVtJ61f2dsoVmekx+9ropvHrXT9fJbutDTO6KN3XITPrrAgo0QwaQ60TxXmnEB4MnrB3QiTwQ5JPNmdAve0IAM/U9pb3ESVhnBZfkxauX2BUFxSU3I/ZGOKUtRJshnR0UWJatihBP/hIqIcl2pUCVjcZBuXGsQfRaenjJF5uunHXd4gG9NszkE3gjKFf5y81FW7DOb3SPS2jWS4FUnmf5twGj7sTwNzpOKx2CTeHSCP//VulGAO1+kpYCfBbaC1jrmSZiV38lw393o18Jek65TL6U+/V4F99L63sBG7ui4JoZnwB0k5xuxL4nxe6uSAmQzdDVJ04TvEvHa1zCGo9X4SPHsJdqXWaI9wfC2CF3h4t0PiJTdyCAN/H8Zv3KlUFC3Wof03u680qnwjlMy4PJ22+Wq5F3z7Pdwse1X1D18/saiXKucHZN8L7nQ2w9xcMv3XDeCVzFTCB8MZwlbN4vlQBSUyClKj2Ua3hPLW58kRNxDpUXRGu19L4dcbK5iFh03OgJLonHFMw4o/SoGC7XTBBsuwwD0/fw2KmzMiDpj0TZM6bHcB2H3fcKEf/JUrxXwAm1LbUC4MxkScHxU8eJ3yKLvZ74OOJ3VFatvA8GZ4sB1vh8SSy5SxTgKVYuvOt3brwNTmg== 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: From: Michel Lespinasse This prepares for page faults handling under VMA lock, looking up VMAs under protection of an rcu read lock, instead of the usual mmap read lock. Signed-off-by: Michel Lespinasse Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 13 ++++++++++--- kernel/fork.c | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8410c3052148..62e413f84011 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -480,9 +480,16 @@ 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; + unsigned long vm_end; + }; +#ifdef CONFIG_PER_VMA_LOCK + struct rcu_head vm_rcu; /* Used for deferred freeing. */ +#endif + }; struct mm_struct *vm_mm; /* The address space we belong to. */ diff --git a/kernel/fork.c b/kernel/fork.c index 5f23d5e03362..314d51eb91da 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -479,12 +479,30 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) return new; } -void vm_area_free(struct vm_area_struct *vma) +static void __vm_area_free(struct vm_area_struct *vma) { free_anon_vma_name(vma); kmem_cache_free(vm_area_cachep, vma); } +#ifdef CONFIG_PER_VMA_LOCK +static void vm_area_free_rcu_cb(struct rcu_head *head) +{ + struct vm_area_struct *vma = container_of(head, struct vm_area_struct, + vm_rcu); + __vm_area_free(vma); +} +#endif + +void vm_area_free(struct vm_area_struct *vma) +{ +#ifdef CONFIG_PER_VMA_LOCK + call_rcu(&vma->vm_rcu, vm_area_free_rcu_cb); +#else + __vm_area_free(vma); +#endif +} + static void account_kernel_stack(struct task_struct *tsk, int account) { if (IS_ENABLED(CONFIG_VMAP_STACK)) {