From mboxrd@z Thu Jan 1 00:00:00 1970 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 3F1E8E7717F for ; Mon, 16 Dec 2024 21:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A372C6B00AD; Mon, 16 Dec 2024 16:57:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6C06B00B0; Mon, 16 Dec 2024 16:57:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 887C26B00B4; Mon, 16 Dec 2024 16:57:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 697806B00AD for ; Mon, 16 Dec 2024 16:57:44 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1E8CC1C620D for ; Mon, 16 Dec 2024 21:57:44 +0000 (UTC) X-FDA: 82902183630.27.60859C1 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf03.hostedemail.com (Postfix) with ESMTP id D3DA420008 for ; Mon, 16 Dec 2024 21:57:28 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GL8s5o6l; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of surenb@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734386234; a=rsa-sha256; cv=none; b=1OUdPWa8p9SMTirWhczYVyIlV15Pv0IT3WroqNU44NED6OFfFfBoJ4ropIZRYppf/B4tZA KyTpkGcj/BLQWFe+8Ks1uGPFlIvcRKOrqI8yV9ACLajrJxNBRv2OANU4NuO6T3NHjTRWrY E1qoSjFdTq1+FU7gXUA5479uSdMy3d0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GL8s5o6l; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of surenb@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734386234; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5T5roncOghweZCeQmSlAea4USG1OweAi+z5lLSWaOYw=; b=cGvdofs8IenOfkrR6RX8FVgTG9NFrx0jWLRe8YC5P8WftTWQriWND+lC6Bn1lWyPObNlte es/C2MBjKt3xB4JWEpn3UKBinN1pPYIjtgAMoiwUUiUD8QewYQhCsWOe3IUwlbHcRNxCP/ mFNw3wc1aAtE50z6H4716uA9fJwG9tE= Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-4679b5c66d0so21801cf.1 for ; Mon, 16 Dec 2024 13:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734386261; x=1734991061; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5T5roncOghweZCeQmSlAea4USG1OweAi+z5lLSWaOYw=; b=GL8s5o6lJk7AtxJ6ATA8VZRBYq8fI75rDh0xh/CZ4xLhfJMhRi4MNDOiS1RwFIpCoo jEk9OiD0vtadvg4+8YyW6y9dOSzbkFzLAzYFuON65mqzAP5+hzXrZpNSWURleF/HlCWK mfLQpBa7FDf7M4Lf5r73L1JPPJw9pXpzBtLrJkM2HJ8dSllrArAzEpescdeQOhTqyTfx tv2Hq9qi3e+JLPOv67JbOpaL4vuuab4dkdVpf1GhrM5VzOOKG9ZLJI7Aqs1ZxhICvc+b g+0dwGjPQsUlS7WzSNWpP756j7WLHUTZ35lfQkF5m/zFH0X3o35/OfeIgD4z1tLAp7Hq 1cRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734386261; x=1734991061; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5T5roncOghweZCeQmSlAea4USG1OweAi+z5lLSWaOYw=; b=NahKS4vHKVmG7H3Dz5QclzLoOOkKUyBnL5hwrsp+RkeSxeXVuSCCCMNlFQJMUxkjV9 8Q/+i+WfhXQWBw3H6i5DKW1MfIx80mHDbOPZHjMqIymdbcFMhqMxMAKg+ofPugWbFZ5K sM0qd2EAA3qr6zLukkWzXhXtTyjPjwA/deJqOydI/66gxPvfcJAEV9LDmIPaVhruyXyl rCJRytBOPqFlhlSbv9mS84AZDvJ9Xv2BZRwjeyMHxBDcHl1bgMNb58H82Q1ifiD+nGei xQanC1k+etqKyVkZubuSx8MEnehorWXud1i1zCqZ8994YG6VqfUU8CVVAKQMoeFkU1SR eMUA== X-Forwarded-Encrypted: i=1; AJvYcCWBvcwVE63gFq41LbU8/P67UnLlonA17qJIpMSpJPtYOr2Fzq2UUQJ4zpdn5JTtCK0BAw+VN5ql1g==@kvack.org X-Gm-Message-State: AOJu0YyOBRbnh+lAxWPs3WsaBu9YGImswlxH5glBRLMAPovSp4Cma56f 9cVwKr3b8OBOq3JP2KHrcEP3Y9ozgrWmzEUQL4md6APL3w1MkUug6LudpxnJCVnqrhu+6C7/qSq dPzXMiQ4Vywerrqs4+Hy9oPxzA3yzYCR6f2TN X-Gm-Gg: ASbGncuNbWxuqOA75ylwtLnc+E0AJzUa6yVy+dvLY71uh0fCLdXa9LbkGig01RBXvrT Bv53cIoHlYgCsLBZ2k8KlmLUFO+lbJfWJYUh57Q== X-Google-Smtp-Source: AGHT+IFrMpdfUGm37FvnuIHqb4P8MJaEtKV+fo4HiTzztMreBEY3Uftz39OoGg7QpOm/Z5TrOM4DCy0JCcTHtSqaVjo= X-Received: by 2002:a05:622a:210:b0:467:5fea:d4c4 with SMTP id d75a77b69052e-468fb142301mr79521cf.27.1734386261193; Mon, 16 Dec 2024 13:57:41 -0800 (PST) MIME-Version: 1.0 References: <20241216192419.2970941-1-surenb@google.com> <20241216192419.2970941-12-surenb@google.com> <20241216211635.GC9803@noisy.programming.kicks-ass.net> <20241216211826.GA33253@noisy.programming.kicks-ass.net> In-Reply-To: <20241216211826.GA33253@noisy.programming.kicks-ass.net> From: Suren Baghdasaryan Date: Mon, 16 Dec 2024 13:57:29 -0800 Message-ID: Subject: Re: [PATCH v6 11/16] mm: enforce vma to be in detached state before freeing To: Peter Zijlstra Cc: akpm@linux-foundation.org, willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, lokeshgidra@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, klarasmodin@gmail.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: aiijq6ronyzk5tyjz8ai5x6nyna15rj4 X-Rspam-User: X-Rspamd-Queue-Id: D3DA420008 X-Rspamd-Server: rspam08 X-HE-Tag: 1734386248-28903 X-HE-Meta: U2FsdGVkX1+Fug2frShZNFGy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CoTZr1BycjDUTWBUKgcRcioCu+wzNbrTu75zmw8IqXldV+fJmucOPbkTm/qUsQ505laZPar6ELoitqhpVJDXQfmjbjCxstDxSomySfOCciVqx1HLO2ofd8WrsMXH/qIPwzsVbkUOznjmFhXbNS+EoH/RE8vqv6vbsezkQ6xUucQk9IJ4oGZag== X-Bogosity: Ham, tests=bogofilter, spamicity=0.009136, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Dec 16, 2024 at 1:18=E2=80=AFPM Peter Zijlstra wrote: > > On Mon, Dec 16, 2024 at 10:16:35PM +0100, Peter Zijlstra wrote: > > On Mon, Dec 16, 2024 at 11:24:14AM -0800, Suren Baghdasaryan wrote: > > > exit_mmap() frees vmas without detaching them. This will become a pro= blem > > > when we introduce vma reuse. Ensure that vmas are always detached bef= ore > > > being freed. > > > > > > Signed-off-by: Suren Baghdasaryan > > > --- > > > kernel/fork.c | 4 ++++ > > > mm/vma.c | 10 ++++++++-- > > > 2 files changed, 12 insertions(+), 2 deletions(-) > > > > > > diff --git a/kernel/fork.c b/kernel/fork.c > > > index 283909d082cb..f1ddfc7b3b48 100644 > > > --- a/kernel/fork.c > > > +++ b/kernel/fork.c > > > @@ -473,6 +473,10 @@ struct vm_area_struct *vm_area_dup(struct vm_are= a_struct *orig) > > > > > > void __vm_area_free(struct vm_area_struct *vma) > > > { > > > +#ifdef CONFIG_PER_VMA_LOCK > > > + /* The vma should be detached while being destroyed. */ > > > + VM_BUG_ON_VMA(!is_vma_detached(vma), vma); > > > +#endif > > > vma_numab_state_free(vma); > > > free_anon_vma_name(vma); > > > kmem_cache_free(vm_area_cachep, vma); > > > diff --git a/mm/vma.c b/mm/vma.c > > > index fbd7254517d6..0436a7d21e01 100644 > > > --- a/mm/vma.c > > > +++ b/mm/vma.c > > > @@ -413,9 +413,15 @@ void remove_vma(struct vm_area_struct *vma, bool= unreachable) > > > if (vma->vm_file) > > > fput(vma->vm_file); > > > mpol_put(vma_policy(vma)); > > > - if (unreachable) > > > + if (unreachable) { > > > +#ifdef CONFIG_PER_VMA_LOCK > > > + if (!is_vma_detached(vma)) { > > > + vma_start_write(vma); > > > + vma_mark_detached(vma); > > > + } > > > +#endif > > > __vm_area_free(vma); > > > > Again, can't you race with lockess RCU lookups? > > Ah, no, removing vma requires holding mmap_lock for writing and having > the vma locked, which would ensure preceding RCU readers are complete > (per the LOCK_OFFSET waiter thing) and new RCU readers are rejected for > the vma sequence thing. Correct. Once vma is detached it can't be found by new readers. Possible existing readers are purged later in this patchset by calling vma_ensure_detached() from vm_area_free(). I don't do that in this patch because those existing temporary readers do not pose issues up until we start reusing the vmas.