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 28482E77184 for ; Thu, 19 Dec 2024 16:18:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F8DA6B0082; Thu, 19 Dec 2024 11:18:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CF496B008A; Thu, 19 Dec 2024 11:18:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BE016B0096; Thu, 19 Dec 2024 11:18:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 68C5E6B0082 for ; Thu, 19 Dec 2024 11:18:10 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 20FDE81179 for ; Thu, 19 Dec 2024 16:18:10 +0000 (UTC) X-FDA: 82912213986.19.922938B Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf30.hostedemail.com (Postfix) with ESMTP id C55C58000C for ; Thu, 19 Dec 2024 16:17:04 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=p1YX3Wdw; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.160.181 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=1734625073; 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=PSvya3sWJCvbqtoa+A5iuOgdl1JL5ydAuCgtK3OjT54=; b=Y7gNDWnRDHVPUQrWtE5QDBRMif7m8SdMtE6JD1BS7+ukdqYw9Cedt3s/+TEx1njhtAsZKG OWYMr8bOtXlaN84tiab7laUfZ59g0f7xAFdjjU0kKGcj0VRZ3aaTNhGzrY6c1Wx5On0TyA aTWpFv51P61/RQMcR2L6OWtM2k6Idpk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734625073; a=rsa-sha256; cv=none; b=w3EiaEXc3swkqx43bhWiLXifNsmF90+Dm1p6BahyT5HFCwBhpV/YiUiM3WIqCl8Mn4DAyI B4N88bkZt6S+ZNxj/MAOCR6Li41riddIXh50jVG9BsvKlnX6IUstuVpe6iFkDfIDiGChd5 xNylg3+oDpVyPoWj8AUdUQsh/gCOvOs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=p1YX3Wdw; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=surenb@google.com Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4678c9310afso271971cf.1 for ; Thu, 19 Dec 2024 08:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734625087; x=1735229887; 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=PSvya3sWJCvbqtoa+A5iuOgdl1JL5ydAuCgtK3OjT54=; b=p1YX3WdwfZNRP1Spsp4za0nSuqewQx/Oihq6mhvMXybQiYEBAPnBw8T5o3PcEgFaJi dEFEVqodtsNhh29TjOOGF+DAPbEgmNGnfmJvBhB2byekx+Q/4C8ZvDZUC5fOy4dHtXdf 8Ik5YguR+0mK0yaadTJDFbtgs6vkbI2fYuVOy7Nte9by2qu9Dw2dwCmNq/BDHJDyj+UI G5WFRipkamACi1Swz5MLYsaO+qphT79ENro6KguC2S676YmFBfh4kLKcFjF3QV8eu0gT 0eBklsE/EwrvHvytudWyscupdMkQSuwEiKHLkq8wVO86qDoLt6kK/IYB+vlDhzMU9rGp 0jAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734625087; x=1735229887; 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=PSvya3sWJCvbqtoa+A5iuOgdl1JL5ydAuCgtK3OjT54=; b=wNgWmmFNldxQ0NeqVLqqXwfW1Zr8ufmIMJW5yFNMkEtOp6yF+bzODI4FDNN2ebUpem yQhjtnm5rjrSF44lcSZOdRa4KAFI7OfBrvwqLtf8RWg0beyKBxjrSt8gLiAPCA7URf7J MISVfuIYReoh6YYRUgrSdjBl9Se791nVbJF5m3lzPjftZlHod+scLpX5mHD8pczlZepr HjbVAieproHN5z2Mmnx5dbBMBCpXcrHcoQnKON3d1Tn4RAfXlvJSi2SBpJEcm/bzLiN1 Ff2Sdnhv622OTtn8HwbPyLpFdiy6mXTbDTf6jywmfN4Pc7evpTKr9vwRu12x0Sy+sMNE q01g== X-Forwarded-Encrypted: i=1; AJvYcCVNs01+6D6+97zc1Vk5dad0otfR8rRiKwYV/8jV5n+fPO8DtQwdl9Jqu+25rFgrgNFyXzm97nV5eA==@kvack.org X-Gm-Message-State: AOJu0Yw/U6EoSMZyKs6U8yY7hlCmM48YeqZoKoUy3XF+NJri73KUxeVh GtQl0jVT5VlBVDPkh4EMoj+9L5ki9hiNvgTnTUCL/K+wV5y/OodMBOfSbS/nFjLhxEGCMwT0So/ 82sXnayoYA0IqxXHAOGrAED4r3H6lK/srhx03 X-Gm-Gg: ASbGnctkyakw/7uJlbXok4ZE/BVtP08wqf4QZLRjL8EKxq052whn4NgXjLqjwx5KIG5 zBIipNSAx9Ctf52BmkrPs0CKvTOg/FhO3WqS9uA== X-Google-Smtp-Source: AGHT+IEvlItn5zS1FAvY8luxMDMYWlJ4t4FPeuQh450skgtDjOmO17X4KtY0FJE6Do0bmr0IMBnC9QLPXlIgPZSy4hM= X-Received: by 2002:ac8:5d15:0:b0:466:8102:636d with SMTP id d75a77b69052e-46a3d9833demr3274601cf.27.1734625087138; Thu, 19 Dec 2024 08:18:07 -0800 (PST) MIME-Version: 1.0 References: <20241218174428.GQ2354@noisy.programming.kicks-ass.net> <20241219091334.GC26551@noisy.programming.kicks-ass.net> <20241219112011.GA34942@noisy.programming.kicks-ass.net> In-Reply-To: <20241219112011.GA34942@noisy.programming.kicks-ass.net> From: Suren Baghdasaryan Date: Thu, 19 Dec 2024 08:17:55 -0800 Message-ID: Subject: Re: [PATCH v6 10/16] mm: replace vm_lock and detached flag with a reference count To: Peter Zijlstra Cc: "Liam R. Howlett" , akpm@linux-foundation.org, willy@infradead.org, 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: pnpunheybt5b59xoqyxyts9joqr7nisy X-Rspamd-Queue-Id: C55C58000C X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734625024-160878 X-HE-Meta: U2FsdGVkX1/P+WWkvB12A96tDAOf2OAJJbjb3aONVhD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z+8zuHfxrmB6lIA1gNYl39izt2eQ4XpoiBcp2Cs2v0+qppZeZkj5b/9f/OZaeCOMR5cc/FCY5f+Lz+s+1gB/RkCzgAISZ9BRW8rXZuOIM+R6i3SEs/dDr3Jc/p6ML7WDirFPKUB/0ywaYryKFoVJYEmoBqGPjuyKa0qKeFhXXc3E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.042741, 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 Thu, Dec 19, 2024 at 3:20=E2=80=AFAM Peter Zijlstra wrote: > > On Thu, Dec 19, 2024 at 10:13:34AM +0100, Peter Zijlstra wrote: > > On Wed, Dec 18, 2024 at 01:53:17PM -0800, Suren Baghdasaryan wrote: > > > > > Ah, ok I see now. I completely misunderstood what for_each_vma_range(= ) > > > was doing. > > > > > > Then I think vma_start_write() should remain inside > > > vms_gather_munmap_vmas() and all vmas in mas_detach should be > > > > No, it must not. You really are not modifying anything yet (except the > > split, which we've already noted mark write themselves). > > > > > write-locked, even the ones we are not modifying. Otherwise what woul= d > > > prevent the race I mentioned before? > > > > > > __mmap_region > > > __mmap_prepare > > > vms_gather_munmap_vmas // adds vmas to be unmapped into mas_d= etach, > > > // some locked > > > by __split_vma(), some not locked > > > > > > lock_vma_under_rcu() > > > vma =3D mas_walk // finds > > > unlocked vma also in mas_detach > > > vma_start_read(vma) // > > > succeeds since vma is not locked > > > // vma->detached, vm_start, > > > vm_end checks pass > > > // vma is successfully read-lock= ed > > > > > > vms_clean_up_area(mas_detach) > > > vms_clear_ptes > > > // steps on a cleared PTE > > > > So here we have the added complexity that the vma is not unhooked at > > all. Is there anything that would prevent a concurrent gup_fast() from > > doing the same -- touch a cleared PTE? > > > > AFAICT two threads, one doing overlapping mmap() and the other doing > > gup_fast() can result in exactly this scenario. > > > > If we don't care about the GUP case, when I'm thinking we should not > > care about the lockless RCU case either. > > Also, at this point we'll just fail to find a page, and that is nothing > special. The problem with accessing an unmapped VMA is that the > page-table walk will instantiate page-tables. > > Given this is an overlapping mmap -- we're going to need to those > page-tables anyway, so no harm done. > > Only after the VMA is unlinked must we ensure we don't accidentally > re-instantiate page-tables. Got it. I'll need some time to digest all the input but I think I understand more or less the overall direction. Thanks, Peter!