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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FCC4C3DA4A for ; Fri, 16 Aug 2024 14:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DuswRPhqxZF2X8qLOLYIapi1ZWMauW2dTfqaGd5YdE0=; b=tPdqbGQ6JU0sJ5qgeo+LfCQRoW 0MvZ6qPhIdAUT0JhgIowdKglEHhFEW+hHy3YAa8wgsV6VNoJ1JnOCjhaj0R2E4EeITDgZ3EC3o27w r97SzghkjbLqrHxcZdikDlZgkDFdk0WAgYzrIvuwiihN6959W5+NNJePAuRgTjVqVaIWL35m13VcX 0CpcLv94qXLRKGMDah/SWoOqIsEByg/V1WyybMjaPANHZ1VOzMjG/nUubdNoT/asqaBfWTAh1CTMg 0Ld+uPB56HGn3gGSh0zwWrYiUS4iIADPpcR9YEvmeI15Kn1cJA1ddcww+yJYtvYKrH1yHb/QnoqSV /tNvWqxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sexqB-0000000DCHY-1SfO; Fri, 16 Aug 2024 14:22:07 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sexpW-0000000DC9w-18kL for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 14:21:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723818084; 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=DuswRPhqxZF2X8qLOLYIapi1ZWMauW2dTfqaGd5YdE0=; b=W7/4anR299478RtcyBIyFJD4iszdiFozlFMk6u4cPSByzg+qaJaVwnVq5vOb4J924W3g5O EKUxTGTN+IphCKhNBREaMV4w5JDaBU75TR9w1RAfMxCjc15skdAYnkebzq0XvN7/7L2JFV 2ObVFglWlz7K8KS2mpB1GTSeYuJfLHo= 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-456-nxcdzX5hNy-JEUfyI7Tsrg-1; Fri, 16 Aug 2024 10:21:22 -0400 X-MC-Unique: nxcdzX5hNy-JEUfyI7Tsrg-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3daf1458b58so304426b6e.0 for ; Fri, 16 Aug 2024 07:21:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723818082; x=1724422882; 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=DuswRPhqxZF2X8qLOLYIapi1ZWMauW2dTfqaGd5YdE0=; b=u8WBh50At5nbiWPlfJuqLx0T0e09RQeIqjIsEhmR3oPAWG5X1B6sO0XLBJrh6eaYWU NuHMvX+Rmb//55CW0GTPp2W2W37oKN9vUhDjxZPdL7QmJxLe+e8YrfMSDoLn4wr2NUkt ccZ2e8fo2vQ6l7wh8h83cM91lEXd02qjOraAGOfsNkVzacrkrg6k1TS5GIVo/Rx97eaQ r0RXdsdEePTiVB1NBzLEuMUwM5mDKf4TQWiVgIwoJ7+tF4uN4lGj0KhEwqgTXghZFSBU +i9IluVPw++92Ig748DPwrolbvtoUQeRqgkMBM4CUBDB2a3WBXPg3CDbYzQovpyUS2Ho EA7Q== X-Forwarded-Encrypted: i=1; AJvYcCUTC9gcwaOfRcLW/U7hcZGiVCmHJqnHaLAN7ZhNPJ2/Ra4eFCjUH+yVXQH3zN1cS0MyYoBXt5bKX6ofxTK1CL/sYT1doEOg5jQAssvnH/tiolJOFUY= X-Gm-Message-State: AOJu0YzOZrOMb68cJjXUofL8PtrhvO80afZVVDFHHwu0JSl+fo7y4WlC cDEPdFwIAZ+/TEMcgq7It040S2keIT9fx/Lpdaxmjt97MuVEbhcfbDwxXl0BIdXMamFt/hhvuVH 1YuztzMy++qEfcjSAY122ALUOf+kIk7W4DOprCdjOA+hpVSujCReoFYW0v8jnh2CsjBJ43Me2 X-Received: by 2002:a05:6808:148a:b0:3d9:402e:4d17 with SMTP id 5614622812f47-3dd3acb5e6dmr1979644b6e.2.1723818081691; Fri, 16 Aug 2024 07:21:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDqekk9YZ0zc1gPPIevbw82K49KS4P67EowjlW1kTTHelWBjTXZ7lPyZqRU/oSZDp42I5DQA== X-Received: by 2002:a05:6808:148a:b0:3d9:402e:4d17 with SMTP id 5614622812f47-3dd3acb5e6dmr1979620b6e.2.1723818081238; Fri, 16 Aug 2024 07:21:21 -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 af79cd13be357-7a4ff1073b4sm176155085a.104.2024.08.16.07.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 07:21:20 -0700 (PDT) Date: Fri, 16 Aug 2024 10:21:17 -0400 From: Peter Xu To: David Hildenbrand Cc: Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sean Christopherson , Oscar Salvador , 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> <20240814130525.GH2032816@nvidia.com> <81080764-7c94-463f-80d3-e3b2968ddf5f@redhat.com> MIME-Version: 1.0 In-Reply-To: <81080764-7c94-463f-80d3-e3b2968ddf5f@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_072126_462705_721C4F5B X-CRM114-Status: GOOD ( 41.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 16, 2024 at 11:30:31AM +0200, David Hildenbrand wrote: > On 14.08.24 15:05, Jason Gunthorpe wrote: > > On Fri, Aug 09, 2024 at 07:25:36PM +0200, David Hildenbrand wrote: > > > > > > > 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. > > > > It is more than just relying on the special bit.. > > > > VM_PFNMAP/VM_MIXEDMAP should really only be used inside > > vm_normal_page() because thay are, effectively, support for a limited > > emulation of the special bit on arches that don't have them. There are > > a bunch of weird rules that are used to try and make that work > > properly that have to be followed. > > > > On arches with the sepcial bit they should possibly never be checked > > since the special bit does everything you need. > > > > Arguably any place reading those flags out side of vm_normal_page/etc > > is suspect. > > IIUC, your opinion matches mine: VM_PFNMAP/VM_MIXEDMAP and pte_special()/... > usage should be limited to vm_normal_page/vm_normal_page_pmd/ ... of course, > GUP-fast is special (one of the reason for "pte_special()" and friends after > all). The issue is at least GUP currently doesn't work with pfnmaps, while there're potentially users who wants to be able to work on both page + !page use cases. Besides access_process_vm(), KVM also uses similar thing, and maybe more; these all seem to be valid use case of reference the vma flags for PFNMAP and such, so they can identify "it's pfnmap" or more generic issues like "permission check error on pgtable". The whole private mapping thing definitely made it complicated. > > > > > > > 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 :) ). > > > > Like here.. > > > > > > 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). > > > > I've squashed many bugs where kernel drivers don't demand userspace > > use MAP_SHARED when asking for a PFNMAP, and of course userspace has > > gained the wrong flags too. I don't know if anyone needs this, but it > > has crept wrongly into the API. > > > > Maybe an interesting place to start is a warning printk about using an > > obsolete feature and see where things go from there?? > > Maybe we should start with some way to pr_warn_ONCE() whenever we get a > COW/unshare-fault in such a MAP_PRIVATE mapping, and essentially populate > the fresh anon folio. > > Then we don't only know who mmaps() something like that, but who actually > relies on getting anon folios in there. Sounds useful to me, if nobody yet has solid understanding of those private mappings while we'd want to collect some info. My gut feeling is we'll see some valid use of them, but I hope I'm wrong.. I hope we can still leave that as a separate thing so we focus on large mappings in this series. And yes, I'll stick with special bits here to not add one more flag reference. Thanks, -- Peter Xu