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 771F0C83F03 for ; Wed, 9 Jul 2025 15:06:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 128286B00C6; Wed, 9 Jul 2025 11:06:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1DB6B00C7; Wed, 9 Jul 2025 11:06:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE28D6B00C9; Wed, 9 Jul 2025 11:06:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D8D936B00C6 for ; Wed, 9 Jul 2025 11:06:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 527EA128FE2 for ; Wed, 9 Jul 2025 15:06:41 +0000 (UTC) X-FDA: 83645053002.02.EA7FF30 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf11.hostedemail.com (Postfix) with ESMTP id 5EB1E40011 for ; Wed, 9 Jul 2025 15:06:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=c6N0r3OQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of surenb@google.com designates 209.85.160.174 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=1752073599; 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=fd2LSjDPzvM9cn+8iN5hrypSfDyrgOivdhgeXar2Dyk=; b=lWpjU2cyS0Yem/DZQFdCx9t5OczPLvVPU7Zn0UTnEDpGaKhh4RAjISG5VoYcyjWOANuVM+ qHz1vvOhAcQQRLuDW44PocMFBJQqW8y3sszbpGAPthBEBFFqD4pWpHZ2nGBwuR2gAAgw5D sQco6w8OSYWbLDCxwnfczATyKBEVg0E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752073599; a=rsa-sha256; cv=none; b=qvjcNeTUrIez/l8xbDLwy/RSigqDKD0O6J+c3XRUGDpctwUofJp8arL42RmHh2g1VGagDT Vw5CjzwblsnTbpkwBPlRQ9eJt+Aab9lj7EAxMTKK8aoreDDAYUR3aUxHlsqt+JW17GRRJC OA14duvK2FMSNJWLrSSZpLJytJFT3Lo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=c6N0r3OQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of surenb@google.com designates 209.85.160.174 as permitted sender) smtp.mailfrom=surenb@google.com Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-4a9e8459f28so53931cf.0 for ; Wed, 09 Jul 2025 08:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752073598; x=1752678398; 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=fd2LSjDPzvM9cn+8iN5hrypSfDyrgOivdhgeXar2Dyk=; b=c6N0r3OQzfXFmsPAjaN9BP5JQYqBkGSGjIBAqbSlD7k33RZFdRGum1hIJnF1D8vj3s GkNRYbVa8A7TQRqsYxw15kGGZHYo8HMLyHmooOOPYOd1HQlzDOmGLZx8jrCyzrDN/iSc rnGDp/sEVsLNgGxDNfhJY5nqDXrNtctRP10obS7uQNGuyOBayZqIQremI//xvcxAcnP5 keuQzi+awLH3YTki3N77Jr/JIsMivFHJ5QTz5xlvSsWmnKLgfNf2kRTfVDsLZklGWBhx wCBRVS7uOpB+BeJAYhrh4AnWGK1s/ZaJm7zEXO+sXu/qtmaTLUU9vFAmGjtrrzcH1QAW hxPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752073598; x=1752678398; 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=fd2LSjDPzvM9cn+8iN5hrypSfDyrgOivdhgeXar2Dyk=; b=io9MYi6o9CNUIlRY2M+JDRKOwi2pZet/53ikBvUf+8KTjDXqzDAfU8szhRf2Se4be8 4E9IUKgJN9UUMczqT+xn4My3eDrSV3rms74Nn6HTVqfPYIDy4poZ1+F5SmgU/v7dmj+R dXOv5i6csVfGCyxFUra8YqcsH3EsFqCajNQDkY6q4oS3W8BeiNaJAhgbXiHBCxFAAuHd mdXxQOXSVKBgnTbcxOmck/+iy3CaksQs8pXUY0AOIXGDJhfqV/5S4YPAC6kvy+hdI9gy 0xZhta9cSifisIy6ndDD5eGfDLgvnU7v41iOGGBO6X1S45eoCiFlKwwtO8lWe7lCI6bS 1PxQ== X-Forwarded-Encrypted: i=1; AJvYcCVeOlmbXmZTONmjZ5K9w9zWK9YxaVhof5JVVJCSP94KojVX0wRCyQGVbcFEhGl/dPt0S7wMgIOwQQ==@kvack.org X-Gm-Message-State: AOJu0YzzMrX83RUmHuRHNUt7zxJmeqFcPlZwRTv81m9kNTw9HNwlMbHN 2wUa6MR+QpBiySHH/xKRRI+bulcp06M0Af9NmhPh1ec7sgMZ+6zxtJqfd0xPxPowzze6ODfuM5L q9xOxtCFq3rPyr3Y1hrfafeXN3LdVgp7+FFWe9ZNU X-Gm-Gg: ASbGnctl34wrtD77TkN5Vl1VyGVyl4tYOm4hku5edPn3llcLyh34oGvyZaINiWpdHsa LDqCYZyeaSK9KAbgwrHMNTUoCxcYt91/VbfwTwd4KFkPhoXh/HFVtX7s5tkjxw63gPcVndaLAQy NBwS7CR2UU98E5kUefjDNMrWK7gJxozM5xiWglmqNvORK7p3Jyp2FRvM9uw8VHooPcD85RO1ct4 ggeu1lJaQ== X-Google-Smtp-Source: AGHT+IFObe64g8yHGu0QvxHsq+CwSkBURq49auTx3IFoft8wHRZU0csu9NWkwFe0ATMRPTvxjGwBT7kJkbtOJQwk4cM= X-Received: by 2002:ac8:5f0f:0:b0:4a4:d827:7f93 with SMTP id d75a77b69052e-4a9dca9ca39mr4738371cf.0.1752073597764; Wed, 09 Jul 2025 08:06:37 -0700 (PDT) MIME-Version: 1.0 References: <20250704060727.724817-1-surenb@google.com> <20250704060727.724817-8-surenb@google.com> <3b3521f6-30c8-419e-9615-9228f539251e@suse.cz> In-Reply-To: <3b3521f6-30c8-419e-9615-9228f539251e@suse.cz> From: Suren Baghdasaryan Date: Wed, 9 Jul 2025 15:06:26 +0000 X-Gm-Features: Ac12FXztVJ5s9fCB7K-LjcBbs5GAqT1LZ8_q7BFwH_XHKRDYfr41flVEbIRKQLo Message-ID: Subject: Re: [PATCH v6 7/8] fs/proc/task_mmu: read proc/pid/maps under per-vma lock To: Vlastimil Babka Cc: Lorenzo Stoakes , akpm@linux-foundation.org, Liam.Howlett@oracle.com, david@redhat.com, peterx@redhat.com, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, paulmck@kernel.org, shuah@kernel.org, adobriyan@gmail.com, brauner@kernel.org, josef@toxicpanda.com, yebin10@huawei.com, linux@weissschuh.net, willy@infradead.org, osalvador@suse.de, andrii@kernel.org, ryan.roberts@arm.com, christophe.leroy@csgroup.eu, tjmercier@google.com, kaleshsingh@google.com, aha310510@gmail.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 5EB1E40011 X-Rspamd-Server: rspam03 X-Stat-Signature: q4xyyq1hb7r3ppemkjh5qgrqqry6kqnc X-HE-Tag: 1752073599-994937 X-HE-Meta: U2FsdGVkX1+ktprJXTl6IJwzQLubCZR3P11RDpksceYO7gYaiVZgRz+DBCLN50m1OLf1IU+aQ2ETZPjQsZXsj2Vt8M49A4sXR/zdztSeCP+bZwClb04IUQ4erI1ErJZhv37Nphg8Klt/y+RTSGCqzQPTbrBqbGM4DbSCGkBsHOKFbyZGgdYksAqm59QOLr9+kmkEbN3u5+aTHRpfNR9e5W7iWpDfUl8CKmbp3lqB9pXFMVw7JG8BbmJpkCFtqh7GeuLw+rfmD2TXo7hA4E6evS5D7pHfW0fnIwsmPQUfGpwcr1Etvi+6VSWL7iL1lmZRxJW8YAUrjm+gh4xCu6rtOeIvnDSpnFxwd0UdAQdbH9hg+eHkfDo8XYjpwu27yZY6k815y5oI8dBXngdQwQPPaY4XXqmm3+k0HnyBrURfD2CQ0CpyLbp4I0Ywk1ok2UmuDJAGNsCb3Drmhd8XZayWT7HjbMR3W722EUutA14LW37QIvIA/S/mRYFksWxCcQ/nTZtLNmuxpWXaJIklg/arI8rSaEA1DgZJbQMKvGLQjJevjXtgPn3tVWlCagxp1nxi1xZnPhnaCb2vtVeK1i8aNGCiTLIVoJEaBHTdbS/YhKmSGcKq3A4//kIUYnSvqpLUsb3T+YQlQST+MOE1HFpvTBg8tQF5UVjVHaqR5bWDO3okLvxlled5DjmhZWd1JkpajITjb+p6tTmB7g6Z6kHvZXlYvv2E3m5vl7mszDba6ZQ4RHTwaB8Rq9tvZkfKa9aTCJISDSR9l8L/4gARrJ58S7xAJAaLdPzEItw9Yh5N9T3xXaqAZRPDTew3wp8DKFwUbc0kepiF+Jz23/7fqUkaEtMFqFf6eiM/Q+n1TpJyyURA+fB4m97AS7lXtSQO4zDhSvSkrx1OdkLxPbzopbarAZ57/xbJdOsBg9pRGooxGRSlisP7/LwDQhifU0FDWO4S0dfrWBzTyWbE+a6/gFw cUjp339J lLCHlH5fN8o08+WcSgWgTWao+0vqoeQFr/m/dj3IGbocaz/0Kro0fgVTvLTyfiQ+BA9vJiD4OmlC5SidXXlftXR7H2plnlqD27ff6lcP2DQg47BJi5pjrfHSQKz3TibekldVxYHhl6Xw38HPh48QhLMnaje9B3m4S6KI4aha9vDitHccM66mfzvmTdjn9Xbsb7DV7cl0jlfdMregna23qZuJkN0q1c2H61joxOKzFQcqBjhjjtXdTH5ZeAA== 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: List-Subscribe: List-Unsubscribe: On Wed, Jul 9, 2025 at 3:03=E2=80=AFPM Vlastimil Babka wro= te: > > On 7/9/25 16:43, Suren Baghdasaryan wrote: > > On Wed, Jul 9, 2025 at 1:57=E2=80=AFAM Vlastimil Babka = wrote: > >> > >> On 7/8/25 01:10, Suren Baghdasaryan wrote: > >> >>> + rcu_read_unlock(); > >> >>> + vma =3D lock_vma_under_mmap_lock(mm, iter, address); > >> >>> + rcu_read_lock(); > >> >> OK I guess we hold the RCU lock the whole time as we traverse excep= t when > >> >> we lock under mmap lock. > >> > Correct. > >> > >> I wonder if it's really necessary? Can't it be done just inside > >> lock_next_vma()? It would also avoid the unlock/lock dance quoted abov= e. > >> > >> Even if we later manage to extend this approach to smaps and employ rc= u > >> locking to traverse the page tables, I'd think it's best to separate a= nd > >> fine-grain the rcu lock usage for vma iterator and page tables, if onl= y to > >> avoid too long time under the lock. > > > > I thought we would need to be in the same rcu read section while > > traversing the maple tree using vma_next() but now looking at it, > > maybe we can indeed enter only while finding and locking the next > > vma... > > Liam, would that work? I see struct ma_state containing a node field. > > Can it be freed from under us if we find a vma, exit rcu read section > > then re-enter rcu and use the same iterator to find the next vma? > > If the rcu protection needs to be contigous, and patch 8 avoids the issue= by > always doing vma_iter_init() after rcu_read_lock() (but does it really av= oid > the issue or is it why we see the syzbot reports?) then I guess in the co= de > quoted above we also need a vma_iter_init() after the rcu_read_lock(), > because although the iterator was used briefly under mmap_lock protection= , > that was then unlocked and there can be a race before the rcu_read_lock()= . Quite true. So, let's wait for Liam's confirmation and based on his answer I'll change the patch by either reducing the rcu read section or adding the missing vma_iter_init() after we switch to mmap_lock.