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 A9674C52D7C for ; Fri, 9 Aug 2024 21:37:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EF696B0089; Fri, 9 Aug 2024 17:37:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39EEC6B0095; Fri, 9 Aug 2024 17:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23FD76B0098; Fri, 9 Aug 2024 17:37:24 -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 059326B0089 for ; Fri, 9 Aug 2024 17:37:23 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 93D811615EC for ; Fri, 9 Aug 2024 21:37:23 +0000 (UTC) X-FDA: 82434018366.07.793A7DF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 8533D40028 for ; Fri, 9 Aug 2024 21:37:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CPg/K0zn"; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723239408; a=rsa-sha256; cv=none; b=rMJhRTw1RGy604mIVxc7IshmUyZPIFH0AQTCaDmP690dqGKmCq1AnyBDSmfU57XGNDU/o8 Ej06fXmpiSLlGqNXSn2Im6EOF1uzDNL2czVr2uOEE17iQjoeZ+upETgO3f6NYjkSjIFcOI pDCXck2VxTcOyuYk67pRZatlGvLgLwc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CPg/K0zn"; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723239408; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vLaN61XvMItpso5ET5hnaX5H7GrLf1LjcFKL/77gKXA=; b=FliDYMzUMy+Das4nlfIpRAXXrKeFqmVJSCXGSYHiNrUT0JZHu4JMNsrGTRSBAP2g0DPCGh E0k8ZbW3jtw3sCmAu3f32yjRL8YjO6epn8HAbFCdMKHnWBOhBWhiuLRnq8Ozv9+7sDseVv HdnJY4wsxrEMjAh7kMHKtS/EtbUTPgY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723239440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vLaN61XvMItpso5ET5hnaX5H7GrLf1LjcFKL/77gKXA=; b=CPg/K0znk6DAvrHN2whtQWLX06BN2svLNKvNsn+W1fm0OiEmd6nqcBhvzeTugPIeSw8/hh 07Qmb/dG48LZexnABbBe57etR+i+r5f729cJ/91Mt+6blYUsCQUNKDAVjEJ6zXQfm0m9xj N03Sx36KKZXtv2bS2kiaPjxxx65Cffs= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-Pf5K4ETxNK24YJ78Sq_09g-1; Fri, 09 Aug 2024 17:37:19 -0400 X-MC-Unique: Pf5K4ETxNK24YJ78Sq_09g-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3db16c5eabeso642290b6e.1 for ; Fri, 09 Aug 2024 14:37:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723239439; x=1723844239; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vLaN61XvMItpso5ET5hnaX5H7GrLf1LjcFKL/77gKXA=; b=bj8UCqi2mGePy30n35P3q9NZ7KLslZs18k8DNs5bzuR2MzNi7PUuFouHu5kMdJgX+/ Jg8EaWQKE1F2+CtGkNKZQV5yAL91pTcX+XUz2QK8kh/yD+hcNmM8qxScV/Icib9VA8Gm HnnVRnVIzgrbEQJuYvbBrblqnq38t0X+X2mvDprhyyjvvYO/n4eX7WXFh9HNjliglpWt JuxLrivImlq+zFknwFib9hJQpgXBqQV95yxWseYlgtE3P7rK/YCGc0sngFP/M3qjtRbc LjKsaW7j1BidM+jt1L1686D4EuKSQ3L8Rrsc2a4O/3CXVf/O5nbpCMhYNPHoP6HjsrMW rTYQ== X-Gm-Message-State: AOJu0YzJYEu5etjGf3QTp6EGRKmy3U7Bexqa6Blee6Wm7ieWFC53EtnG cJ2BmS9lKN84i04Y7aEeUciKr9Id2gadYhKZj1sufDNk/OL13IpJRi/Vy2rY80CbXlAOexvuG/w BW+mk+hv6jx90neaDJ/3KITD9ilvjexhR0IF/Ig5/C8WL1RCB X-Received: by 2002:a05:6808:2113:b0:3d5:6338:49de with SMTP id 5614622812f47-3dc416e1f18mr1830098b6e.5.1723239438874; Fri, 09 Aug 2024 14:37:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwM82YW2GARYPlTotghl2UYBNZ3FORuZWjx1vF1xR71aVPbyjVU6f+5Zh59bD0enYavl9npw== X-Received: by 2002:a05:6808:2113:b0:3d5:6338:49de with SMTP id 5614622812f47-3dc416e1f18mr1830084b6e.5.1723239438516; Fri, 09 Aug 2024 14:37:18 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4531c1c30b7sm1479831cf.22.2024.08.09.14.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 14:37:17 -0700 (PDT) Date: Fri, 9 Aug 2024 17:37:14 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: Re: [PATCH 06/19] mm/pagewalk: Check pfnmap early for folio_walk_start() Message-ID: References: <20240809160909.1023470-1-peterx@redhat.com> <20240809160909.1023470-7-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: 9ww6bzaub9zqoiwa6hn9t5rb4smnn9bs X-Rspamd-Queue-Id: 8533D40028 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723239441-281888 X-HE-Meta: U2FsdGVkX19KwG7g81XNqWj5k/Y6GgCOPy9p3dEkmcZw6MupQcg/aTEB1oXKXWuH2vWLo4BCD42EOeCOoCm4xmxHcgtA6E+gpXhi8VuEW0eDO3JQs2xvE9Gtr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al8i+NMzP6nW+qmJGVQNyXhHo5UKlUwIvofKOZW0hfgn7QuMgsFuHyAHYyz4Hayf0Wa8e6u+4+JpnrRRrP31KW4PUnJQqS8D8xF5kqU9qcvP1Moc9tFK0YP8NTaVAqK5wsJGY0bDiRNjAIjsGqJfO7ZOZ93Yz5tx5e5COm230/L2qzUUEAuU+aIQSLrH5Qoxn4q+JNFwSPC/q4SiqH7C9uSzpfHI28+jMjrkIk6phx7VIPRDPT+DHDbSp73HvXPEAyYHDYEyk0ugo7bBgLD3rERaQOUsXpKVJfcki9IIev79a/AB+14nRTgbSt9Axb3+zf1QA2neqERU/mOh5dRN3uAkwyCe8qOvJ23B45p3qs4Gh0= 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 Fri, Aug 09, 2024 at 07:25:36PM +0200, David Hildenbrand wrote: > On 09.08.24 18:54, Peter Xu wrote: > > On Fri, Aug 09, 2024 at 06:20:06PM +0200, David Hildenbrand wrote: > > > On 09.08.24 18:08, Peter Xu wrote: > > > > Pfnmaps can always be identified with special bits in the ptes/pmds/puds. > > > > However that's unnecessary if the vma is stable, and when it's mapped under > > > > VM_PFNMAP | VM_IO. > > > > > > > > Instead of adding similar checks in all the levels for huge pfnmaps, let > > > > folio_walk_start() fail even earlier for these mappings. It's also > > > > something gup-slow already does, so make them match. > > > > > > > > Cc: David Hildenbrand > > > > Signed-off-by: Peter Xu > > > > --- > > > > mm/pagewalk.c | 5 +++++ > > > > 1 file changed, 5 insertions(+) > > > > > > > > diff --git a/mm/pagewalk.c b/mm/pagewalk.c > > > > index cd79fb3b89e5..fd3965efe773 100644 > > > > --- a/mm/pagewalk.c > > > > +++ b/mm/pagewalk.c > > > > @@ -727,6 +727,11 @@ struct folio *folio_walk_start(struct folio_walk *fw, > > > > p4d_t *p4dp; > > > > mmap_assert_locked(vma->vm_mm); > > > > + > > > > + /* It has no folio backing the mappings at all.. */ > > > > + if (vma->vm_flags & (VM_IO | VM_PFNMAP)) > > > > + return NULL; > > > > + > > > > > > That is in general not what we want, and we still have some places that > > > wrongly hard-code that behavior. > > > > > > In a MAP_PRIVATE mapping you might have anon pages that we can happily walk. > > > > > > vm_normal_page() / vm_normal_page_pmd() [and as commented as a TODO, > > > vm_normal_page_pud()] should be able to identify PFN maps and reject them, > > > no? > > > > Yep, I think we can also rely on special bit. > > > > When I was working on this whole series I must confess I am already > > confused on the real users of MAP_PRIVATE pfnmaps. E.g. we probably don't > > need either PFNMAP for either mprotect/fork/... at least for our use case, > > then VM_PRIVATE is even one step further. > > Yes, it's rather a corner case indeed. > > > > Here I chose to follow gup-slow, and I suppose you meant that's also wrong? > > I assume just nobody really noticed, just like nobody noticed that > walk_page_test() skips VM_PFNMAP (but not VM_IO :) ). I noticed it, and that's one of the reasons why this series can be small, as walk page callers are intact. > > Your process memory stats will likely miss anon folios on COW PFNMAP > mappings ... in the rare cases where they exist (e.g., mmap() of /dev/mem). Do you mean /proc/$PID/status? I thought that (aka, mm counters) should be fine with anon pages CoWed on top of private pfnmaps, but possibly I misunderstood what you meant. > > > If so, would it make sense we keep them aligned as of now, and change them > > altogether? Or do you think we should just rely on the special bits? > > GUP already refuses to work on a lot of other stuff, so likely not a good > use of time unless somebody complains. > > But yes, long-term we should make all code either respect that it could > happen (and bury less awkward checks in page table walkers) or rip support > for MAP_PRIVATE PFNMAP out completely. > > > > > And, just curious: is there any use case you're aware of that can benefit > > from caring PRIVATE pfnmaps yet so far, especially in this path? > > In general MAP_PRIVATE pfnmaps is not really useful on things like MMIO. > > There was a discussion (in VM_PAT) some time ago whether we could remove > MAP_PRIVATE PFNMAPs completely [1]. At least some users still use COW > mappings on /dev/mem, although not many (and they might not actually write > to these areas). Ah, looks like the private map on /dev/mem is the only thing we know. > > I'm happy if someone wants to try ripping that out, I'm not brave enough :) > > [1] > https://lkml.kernel.org/r/1f2a8ed4-aaff-4be7-b3b6-63d2841a2908@redhat.com > > > > > As far as I read, none of folio_walk_start() users so far should even > > stumble on top of a pfnmap, share or private. But that's a fairly quick > > glimps only. > > do_pages_stat()->do_pages_stat_array() should be able to trigger it, if you > pass "nodes=NULL" to move_pages(). .. so assume this is also about private mapping over /dev/mem, then: someone tries to write some pages there to some MMIO regions, then tries to use move_pages() to fetch which node those pages locate? Hmm.. OK :) > > Maybe s390x could be tricked into it, but likely as you say, most code > shouldn't trigger it. The function itself should be handling it correctly as > of today, though. So indeed I cannot justify it won't be used, and it's not a huge deal indeed if we stick with special bits. Let me go with that in the next version for folio_walk_start(). Thanks, -- Peter Xu