Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1717609rwd; Thu, 1 Jun 2023 21:54:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VBQW23/KhHvGl95NWyvAATE+NmwXvpcUaiAPmLibak+AXcSUxVaNUSNna5z613124S+og X-Received: by 2002:ac8:5f48:0:b0:3f3:9489:1c33 with SMTP id y8-20020ac85f48000000b003f394891c33mr13896217qta.36.1685681652507; Thu, 01 Jun 2023 21:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685681652; cv=none; d=google.com; s=arc-20160816; b=u4LMfnI/4llmGOOaQNWFX6zUvXBKedpGAnyoRbOUCsu1ezQOfE2uv2QWAR8t2vZaje FPgxsPyHoAceiSHhvB18opaVdKRmNBLcwUMiSm1mkUQ3M439lWn90F0xMLbTINpxuF26 vgIJr43O1jHYRYrzgylPfH3l/HAGxeAIrrZ+sBmUHPAmqUbrobq2jBqRy/trr2K7k7Wu Hj/GvGCs0Uv45avk6dVuG2Hmwd6OiaSQDIVze75kwFDvUSRnao8vIyM9pp2Gns4YtO6I f7pjj+gG7HU8XwTcjHEq8pZBCkHBFHyUrCaqbZ9LyyZqkwshv8fKqkcRA+ag2OP7i89f IFbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=jJxGCGn41BvabvDFNoHM5AnkkTjflqlE1qMNlE8NrT0=; b=l0WXS/zYhmGfPSgNPMa05z2hkadvAKW0J845zelunuu7b13otziB5qKgGTLfipJ0iQ h0Deg5s+cuHWiCZgBCAhOw21mBdAFEVbMlcA4UqMzBAYVE2rZ6wTnQqeGglOje0YLAl5 LLiq0P5ovmucznYApfpyh7vf6/xNQyeD2387wLrdKmQ+dQxFMQMfz4I48zms3ljkE1+S jny7XAuXjwLSD7bKez19Pq1xD4nZWLhsLW6xZQTL6F3L/rDf/vGlOMyvGyid1AsXVZHb jFO0fH5OHlwfYVc8+GANLsv2RfnOPjBFTi5WenPS93m5N36xecIQZjtMFtnfdl5gY+FX sNrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hLiVWg2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m26-20020a638c1a000000b005347d133470si391035pgd.385.2023.06.01.21.53.59; Thu, 01 Jun 2023 21:54:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hLiVWg2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233597AbjFBEh7 (ORCPT + 99 others); Fri, 2 Jun 2023 00:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjFBEh5 (ORCPT ); Fri, 2 Jun 2023 00:37:57 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C793F2 for ; Thu, 1 Jun 2023 21:37:54 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-bad1ae90c2eso1731081276.2 for ; Thu, 01 Jun 2023 21:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685680673; x=1688272673; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=jJxGCGn41BvabvDFNoHM5AnkkTjflqlE1qMNlE8NrT0=; b=hLiVWg2vLRCGga9dPaoBmb31J4RQXoKrnLyjofX4nrluqzG+krMZEBkG963VV3+V4S s+8cFe/GC9jT+mttHRcUgLqdAWaNK+4XJfOsKmkfRyxraldoFeK3u0aDrpHHDFy8+geA I+BVR4akDprVaJTfkU3zr7Uc//8VHDpcHsKp892pLRDmIDEe7dHVOra7Xn0lK7TCCWon b3GYtV2/SVVlBXw+4utgS9GHQrb+vEIMWNAyb6VxBnHIWrXHPzYDBTAmo8nwbHBXjTfw wghXDbSao4T2gtOYNqjy91CEhqjmEc3+JG5hRAUqAvMS4wRt8RVjEj6zljJFtyHOjo50 ZEfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685680673; x=1688272673; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jJxGCGn41BvabvDFNoHM5AnkkTjflqlE1qMNlE8NrT0=; b=bWgSLRuollopjZ+dAm6hEJmcuSqi/YDB0O40/XU1iRZVjqcGPVXur4x8mn6UYmlLUL I8rFcKno1Ei6jM4F7mffSIAfA7TzDYRkTLdsMiLa73vimkMPrN6xlJ6yCDuREjVlRN3i 57IQrPNLstoWaXKrQvzORNYKf6LRQVJ9fzG9sGHGCfDDgho40lCltIUXOb/YYiJBK7DV AZWpytBVg+pkG/tkp+vUH42zJi7RMU/jXq8+RozByCd40nCxFAYfIv+qnHKRWZxq4+sH MSoddYQu/hrTKSXodWM3BerkZxiKyr5ni1cWtrqA0E4ji8aT/LB/mAau8NjYN+5fo1BQ MIGA== X-Gm-Message-State: AC+VfDxMZ5fSEBSA5PLJHBDKGSJj39B4Bj5YL3jHmLCL7G3NBe1oegoJ HPheq4WUdzw9Hw1ENOlNHE6xFA== X-Received: by 2002:a25:2b09:0:b0:b69:8770:9d95 with SMTP id r9-20020a252b09000000b00b6987709d95mr2183916ybr.17.1685680672998; Thu, 01 Jun 2023 21:37:52 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 194-20020a2503cb000000b00ba8c2f3e1a4sm64190ybd.56.2023.06.01.21.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 21:37:52 -0700 (PDT) Date: Thu, 1 Jun 2023 21:37:38 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Jann Horn cc: Hugh Dickins , Andrew Morton , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Russell King , "David S. Miller" , Michael Ellerman , "Aneesh Kumar K.V" , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , Alexander Gordeev , linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 00/12] mm: free retracted page table by RCU In-Reply-To: Message-ID: <3a33b59f-47c1-9dea-209a-9f77eec3cb1@google.com> References: <35e983f5-7ed3-b310-d949-9ae8b130cdab@google.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1463760895-147145368-1685680672=:27841" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463760895-147145368-1685680672=:27841 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 31 May 2023, Jann Horn wrote: > On Mon, May 29, 2023 at 8:11=E2=80=AFAM Hugh Dickins w= rote: > > Here is the third series of patches to mm (and a few architectures), ba= sed > > on v6.4-rc3 with the preceding two series applied: in which khugepaged > > takes advantage of pte_offset_map[_lock]() allowing for pmd transitions= =2E >=20 > To clarify: Part of the design here is that when you look up a user > page table with pte_offset_map_nolock() or pte_offset_map() without > holding mmap_lock in write mode, and you later lock the page table > yourself, you don't know whether you actually have the real page table > or a detached table that is currently in its RCU grace period, right? Right. (And I'd rather not assume anything of mmap_lock, but there are one or two or three places that may still do so.) > And detached tables are supposed to consist of only zeroed entries, > and we assume that no relevant codepath will do anything bad if one of > these functions spuriously returns a pointer to a page table full of > zeroed entries? (Nit that I expect you're well aware of: IIRC "zeroed" isn't 0 on s390.) If someone is using pte_offset_map() without lock, they must be prepared to accept page-table-like changes. The limits of pte_offset_map_nolock() with later spin_lock(ptl): I'm still exploring: there's certainly an argument that one ought to do a pmd_same() check before proceeding, but I don't think anywhere needs that at present. Whether the page table has to be full of zeroed entries when detached: I believe it is always like that at present (by the end of the series, when the collapse_pte_offset_map() oddity is fixed), but whether it needs to be so I'm not sure. Quite likely it will need to be; but I'm open to the possibility that all it needs is to be still a page table, with perhaps new entries from a new usage in it. The most obvious vital thing (in the split ptlock case) is that it remains a struct page with a usable ptl spinlock embedded in it. The question becomes more urgent when/if extending to replacing the pagetable pmd by huge pmd in one go, without any mmap_lock: powerpc wants to deposit the page table for later use even in the shmem/file case (and all arches in the anon case): I did work out the details once before, but I'm not sure whether I would still agree with myself; and was glad to leave replacement out of this series, to revisit some time later. >=20 > So in particular, in handle_pte_fault() we can reach the "if > (unlikely(!pte_same(*vmf->pte, entry)))" with vmf->pte pointing to a > detached zeroed page table, but we're okay with that because in that > case we know that !pte_none(vmf->orig_pte)&&pte_none(*vmf->pte) , > which implies !pte_same(*vmf->pte, entry) , which means we'll bail > out? There is no current (even at end of series) circumstance in which we could be pointing to a detached page table there; but yes, I want to allow for that, and yes I agree with your analysis. But with the interesting unanswered question for the future, of what if the same value could be found there: would that imply it's safe to proceed, or would some further prevention be needed? >=20 > If that's the intent, it might be good to add some comments, because > at least to me that's not very obvious. That's a very fair request; but I shall have difficulty deciding where to place such comments. I shall have to try, then you redirect me. And I think we approach this in opposite ways: my nature is to put some infrastructure in place, and then look at it to see what we can get away with; whereas your nature is to define upfront what the possibilities are. We can expect some tussles! Thanks, Hugh ---1463760895-147145368-1685680672=:27841--