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 981E7ECAAA1 for ; Fri, 9 Sep 2022 16:19:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D1F68D0002; Fri, 9 Sep 2022 12:19:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 181616B0072; Fri, 9 Sep 2022 12:19:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04A518D0002; Fri, 9 Sep 2022 12:19:24 -0400 (EDT) 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 EAF766B0071 for ; Fri, 9 Sep 2022 12:19:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8C9F581008 for ; Fri, 9 Sep 2022 16:19:23 +0000 (UTC) X-FDA: 79893057006.10.A1EF529 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf04.hostedemail.com (Postfix) with ESMTP id 36C4940080 for ; Fri, 9 Sep 2022 16:19:23 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id 202so3371095ybe.13 for ; Fri, 09 Sep 2022 09:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=2KJtyG0OrgeeUZ3tbEzNZEApZJ2MVSJ3tdGvELtllWA=; b=Vtzxz/3WnYzehsvxEe5bYGVLVOYdFWrSTvZz1vALAWuaevC3U5WtB+f78lFCZF324w FiscSmbXyU+XOB2/F7lOYLYlIX8OuFWYPchdz5uYxmpm9O//MmQsACLWQpqvEvhHp78u Fqcicq6ClSVver2X4O9EIw1QxejGbytPeJEB/dU6IAFURZmla+3iGvObrXUwU6kzrvty vvKRbbaLhKfEVSQiX5d/rnqzs2MN5BTC2/L2bdEQkmQOw6LxzvEJ4w2N+ZccRlBLFUqE QBiGhcqj/PQWmuf5DYdZqpxP0dQ13hOo5+doY9eqgJ0sxS0rfuqgmlMiu7e7iSGtWTIp SMdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=2KJtyG0OrgeeUZ3tbEzNZEApZJ2MVSJ3tdGvELtllWA=; b=1imPi9xOzamEWgtq7YTFuNuEWDEU0MTeeMh3RZf2d1SbKey/0GTxOLQvAuedxT9U73 GxToGI6gcD2OROTnUa87Lf508qkXhAllg3sKTt3S82QlfiJlCrH+beB5Rbg2+1jrDIEf /3ekoY+3B+cWoCv5iMD88VyUtO2RMiMOtXX1bG26tvTDSnSaG6m1oyYcoPF0+bhBqlK8 F0gXXqOt7spf/OSErxg8XNkrOY2Wf6ek/Dot1hvq1eD5SGcBVJAocwKTO6P4ysLdXj/2 jUo6NArKu6HpLUiFkckdEWqmoiPe2DnHJwr/omY2X8KZ0SaHrGttSXaGwXnrjrcvG30c 0nDg== X-Gm-Message-State: ACgBeo2k/NIOsRwD7FhAdi8almR+22JydSfIKVa88acUp9YD65uBO6Eq mCHHMuRmkA76y/Vv1mfzEImP+7TzC3ti8eKve/+aXg== X-Google-Smtp-Source: AA6agR5nRzGlVojCwvyK5XF84Xj8sLR9CtuVgi9z+gwaNZrGge2Gh6ZuqKhqShhWXfC987DrYFOeiSZ3ndHTh5gSVbA= X-Received: by 2002:a05:6902:2d0:b0:694:d257:4c4b with SMTP id w16-20020a05690202d000b00694d2574c4bmr12464223ybh.316.1662740362348; Fri, 09 Sep 2022 09:19:22 -0700 (PDT) MIME-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> <20220901173516.702122-17-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 9 Sep 2022 09:19:11 -0700 Message-ID: Subject: Re: [RFC PATCH RESEND 16/28] kernel/fork: assert no VMA readers during its destruction To: Laurent Dufour Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, 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, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662740363; a=rsa-sha256; cv=none; b=jf9RJrBD+jqLWcsoTa1zu3mNq5wS+S3xgyEd60MDZSsZVmUfEjRBg9sSXDi5c9XE/fXO4Z phMCskDnCFtWKhOZxjCuBZAJR1Qz4Zb/8a5pl/jKpY/bjLBzWTT7rpNDwGqiUoOpJY0A7z SlV/DKUAp4TZqu4Jy1oHm5+Oa+W5h20= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Vtzxz/3W"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 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=1662740363; 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=2KJtyG0OrgeeUZ3tbEzNZEApZJ2MVSJ3tdGvELtllWA=; b=OEw1RQNpiTkPcDibtgZV6/+FKYIphTH/m7w9Qxg8ElX3pJoN565VLNSnLpReOAr3tLV/VO ZeVrVo9t3tXm4N8LXl6s36gKUsE77WyoA2fpFXIiYi3LzZOO2t4S9uU5EbpdkY8LdritaP Iu3nmDkW3Njicpl8b7jpfANu0c949q4= X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Vtzxz/3W"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=surenb@google.com X-Stat-Signature: 3fooowg5ofrrqzj719fpc6xr3bhdm6wh X-Rspamd-Queue-Id: 36C4940080 X-HE-Tag: 1662740363-691661 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: On Fri, Sep 9, 2022 at 6:56 AM Laurent Dufour wrote= : > > Le 01/09/2022 =C3=A0 19:35, Suren Baghdasaryan a =C3=A9crit : > > Assert there are no holders of VMA lock for reading when it is about to= be > > destroyed. > > > > Signed-off-by: Suren Baghdasaryan > > --- > > include/linux/mm.h | 8 ++++++++ > > kernel/fork.c | 2 ++ > > 2 files changed, 10 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index dc72be923e5b..0d9c1563c354 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -676,6 +676,13 @@ static inline void vma_assert_write_locked(struct = vm_area_struct *vma, int pos) > > VM_BUG_ON_VMA(vma->vm_lock_seq !=3D READ_ONCE(vma->vm_mm->mm_lock= _seq), vma); > > } > > > > +static inline void vma_assert_no_reader(struct vm_area_struct *vma) > > +{ > > + VM_BUG_ON_VMA(rwsem_is_locked(&vma->lock) && > > + vma->vm_lock_seq !=3D READ_ONCE(vma->vm_mm->mm_lock= _seq), > > + vma); > > +} > > + > > #else /* CONFIG_PER_VMA_LOCK */ > > > > static inline void vma_init_lock(struct vm_area_struct *vma) {} > > @@ -685,6 +692,7 @@ static inline bool vma_read_trylock(struct vm_area_= struct *vma) > > static inline void vma_read_unlock(struct vm_area_struct *vma) {} > > static inline void vma_assert_locked(struct vm_area_struct *vma) {} > > static inline void vma_assert_write_locked(struct vm_area_struct *vma,= int pos) {} > > +static inline void vma_assert_no_reader(struct vm_area_struct *vma) {} > > > > #endif /* CONFIG_PER_VMA_LOCK */ > > > > diff --git a/kernel/fork.c b/kernel/fork.c > > index 1872ad549fed..b443ba3a247a 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -487,6 +487,8 @@ static void __vm_area_free(struct rcu_head *head) > > { > > struct vm_area_struct *vma =3D container_of(head, struct vm_area_= struct, > > vm_rcu); > > + /* The vma should either have no lock holders or be write-locked.= */ > > + vma_assert_no_reader(vma); > > I'm wondering if this can be hit in the case the thread freeing a VMA is > preempted before incrementing the mm ref count, like this: > > VMA is about to be freed > write lock VMA > free vma -> call_rcu > .. > <--- thread preempted > rcu handler runs > rcu calls __vm_area_free() <<<<<< At this point the VMA is still write-locked (mm seq count hasn't been incremented yet), correct? If so then vma_assert_no_reader() will not assert because the second condition of VMA being write-locked is satisfied. Did I miss anything? > unlock mmap_lock and increase the mm seq count > > > > kmem_cache_free(vm_area_cachep, vma); > > } > > #endif >