From patchwork Mon Jan 9 20:53:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13094273 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 EC237C61DB3 for ; Mon, 9 Jan 2023 20:54:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 469508E000B; Mon, 9 Jan 2023 15:54:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F0FF8E0001; Mon, 9 Jan 2023 15:54:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26B528E000B; Mon, 9 Jan 2023 15:54:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 184298E0001 for ; Mon, 9 Jan 2023 15:54:01 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E6720120BDE for ; Mon, 9 Jan 2023 20:54:00 +0000 (UTC) X-FDA: 80336462640.30.72274ED Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 54B9340013 for ; Mon, 9 Jan 2023 20:53:59 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Czdnd0b+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 35n68YwYKCPktvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35n68YwYKCPktvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673297639; 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=TT+2XsH00KwTX585kTrU5AriHJozMAXcs0iFxeAd0aM=; b=swpmpASH/gc/nBQLez9nwJWs26WLngF44GMYGevL6Iohbk6BPxh1G/mS4Iz4p3drBPIKiL Q2TP0JAwZe36rmDV+GjFjDiW9FXAbg8gQKGQb64RSZKfCVIRdsuK1t5Wzk2sdwlpgUgP8T Vdb7wA+BEV6Bu2wmWPmAiRHOch8icM0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Czdnd0b+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 35n68YwYKCPktvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35n68YwYKCPktvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673297639; a=rsa-sha256; cv=none; b=lALwaEc4ejDx/NbFT/ZYVnhNldU70bra0SZ4zlEWhFGsi+vW129BbnzWtLa15HBqrT0h50 msj0YtZNfTD9XNvzDNBV7xH0cOMLXpFAE7nrP9JEGNzMZABKpwSmIrEIA2xOMT/HyXYKo/ SEgvAOYdF+0/TGzNKbBvghtZQ1hMdFo= Received: by mail-yb1-f201.google.com with SMTP id h66-20020a252145000000b0071a7340eea9so10190379ybh.6 for ; Mon, 09 Jan 2023 12:53:59 -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=TT+2XsH00KwTX585kTrU5AriHJozMAXcs0iFxeAd0aM=; b=Czdnd0b+5bkyGxVk+9aViJOW1TJ5m6k5XpyXdj4R+Q3dGGEBK2eP5deQvySgSh0iz/ GZ1iYooFrZ5CipGLrqMEQsrY/Zn4kUyQA8m4xIFN7mfEerPKCDkU1AubZLdIfDfth4hu d8dG+6QDcTUs7A9Y052NxeL9TA5a3QdfxlEt4CBoSlbUsLAUBEORkFyS1sdo7qsKHieD EXHjCZRBRMhYEWoMQiXcySJyrWxVf33iALFZt6xsCbFcNo15dZaOnJt+J48Z17ETAj7O 45DKwd6DY6kCK0yPohqOb3E3TN0P5VYKNR4qSRkuKInUqGltfhkGbi1MmOGm2N8pUB+H +TEQ== 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=TT+2XsH00KwTX585kTrU5AriHJozMAXcs0iFxeAd0aM=; b=tYQBLzigA3kp2lx9oqCo8dgtFFgoxM2IYgs28z7F4zypaoYnWxPGaYYtBdhTdawhYM Sie19nsQJf9BfgMaZlE3YUvo1HsX18aZcCIQTxKAGvrDcxhKXDutFzPBYhQIrTMU+dZl 6uH8ZxU6rxtCaW/mi1IJiVmpUonqM4QlW4PDqfCGUCL0UbhZUmp3T16yt0oOMjdUizQd Y15iMrP/nO0bAQwthQuxlBV3sCwIIGhoFtDnxEvy+7KQeGksUyWN1Dtm3p0GAIVp4xsw Wxp/NqamQJiiZDB+fRRGNC8rbX7nNIYI9mivWl8zbuTtm2F3rN5A1Q4NBDcWTTmyD425 4MEw== X-Gm-Message-State: AFqh2kpNpdqe8GXfVvB8haoiaTaXwGTteJ5yzGvoxwV4L3tcUQV8TUSy RNyjgvesX4O7ltr4pIWpAiOCk6qns8k= X-Google-Smtp-Source: AMrXdXtUN3SiDpbjRFPvhoNJBXB5uM1KkpI6Zcz0Naqt9m0yZDl1B9u4vz5wIeviZulbrZU/bcJYjep5MGE= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:9393:6f7a:d410:55ca]) (user=surenb job=sendgmr) by 2002:a25:abea:0:b0:762:b86:e82e with SMTP id v97-20020a25abea000000b007620b86e82emr7288109ybi.407.1673297638462; Mon, 09 Jan 2023 12:53:58 -0800 (PST) Date: Mon, 9 Jan 2023 12:53:02 -0800 In-Reply-To: <20230109205336.3665937-1-surenb@google.com> Mime-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109205336.3665937-8-surenb@google.com> Subject: [PATCH 07/41] mm: Enable maple tree RCU mode by default. 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, laurent.dufour@fr.ibm.com, paulmck@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, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@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, "Liam R. Howlett" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 54B9340013 X-Stat-Signature: efdcxmqiyt7huu5zps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B+uJCwCHGtR2agRXn6/F3DACQMnN5O/Dvx707KRPZRyrSNYYYk1gpjep4q5Bl4MaS8J8U0WV3VYIHyt3GgNsllyPN0uUtOoirAVeDL5lJncOYkvS+Hi7isBDjxur3Kx5gWYTEqWhNP6ugB2y2pmMr1eRAQXDMUIY8mIKe8eLht9INZxMGyKMRMg9mmOFhs2zbg1XzPvVLP3FzZMyViPIxpPq6ub9+CsgA00mKa7oQic+XwTv10A6Po86x22nh1vhX5e/kEb1cyJuTYG9HFnlzjDfJqmYMfKhMVERypT7w5NjHIGZANw00/I= 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: "Liam R. Howlett" Use the maple tree in RCU mode for VMA tracking. This is necessary for the use of per-VMA locking. RCU mode is enabled by default but disabled when exiting an mm and for the new tree during a fork. Also enable RCU for the tree used in munmap operations to ensure the nodes remain valid for readers. Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 3 ++- kernel/fork.c | 3 +++ mm/mmap.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3b8475007734..4b6bce73fbb4 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -810,7 +810,8 @@ struct mm_struct { unsigned long cpu_bitmap[]; }; -#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN) +#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \ + MT_FLAGS_USE_RCU) extern struct mm_struct init_mm; /* Pointer magic because the dynamic array size confuses some compilers. */ diff --git a/kernel/fork.c b/kernel/fork.c index 9f7fe3541897..58aab6c889a4 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -617,6 +617,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto out; + mt_clear_in_rcu(mas.tree); mas_for_each(&old_mas, mpnt, ULONG_MAX) { struct file *file; @@ -703,6 +704,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, retval = arch_dup_mmap(oldmm, mm); loop_out: mas_destroy(&mas); + if (!retval) + mt_set_in_rcu(mas.tree); out: mmap_write_unlock(mm); flush_tlb_mm(oldmm); diff --git a/mm/mmap.c b/mm/mmap.c index 87d929316d57..9db37adfc00a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2304,7 +2304,8 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma, int count = 0; int error = -ENOMEM; MA_STATE(mas_detach, &mt_detach, 0, 0); - mt_init_flags(&mt_detach, MT_FLAGS_LOCK_EXTERN); + mt_init_flags(&mt_detach, mas->tree->ma_flags & + (MT_FLAGS_LOCK_MASK | MT_FLAGS_USE_RCU)); mt_set_external_lock(&mt_detach, &mm->mmap_lock); if (mas_preallocate(mas, vma, GFP_KERNEL)) @@ -3091,6 +3092,7 @@ void exit_mmap(struct mm_struct *mm) */ set_bit(MMF_OOM_SKIP, &mm->flags); mmap_write_lock(mm); + mt_clear_in_rcu(&mm->mm_mt); free_pgtables(&tlb, &mm->mm_mt, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); tlb_finish_mmu(&tlb);