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 1823AC83F09 for ; Tue, 8 Jul 2025 12:47:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D4676B0313; Tue, 8 Jul 2025 08:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AC5C6B0315; Tue, 8 Jul 2025 08:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79B646B0316; Tue, 8 Jul 2025 08:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 618DF6B0313 for ; Tue, 8 Jul 2025 08:47:54 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D51E359D83 for ; Tue, 8 Jul 2025 12:47:53 +0000 (UTC) X-FDA: 83641074426.19.775B23B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 2555DC0011 for ; Tue, 8 Jul 2025 12:47:51 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IAMlhLI7; spf=pass (imf28.hostedemail.com: domain of will@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751978872; 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=FfZUNqK6AHMDIyBuxYJk20uehJ5G711r6J8Dl14Pilc=; b=0D2WtEjPGTamBjd/zytPfFnOHUoR+wZN7FGapvgU5546saNeoeQRpY6DgBs0l/RVP2lcws jiNDvg9cS91RMnYq/V3K8HoCTyNyLbYDou365zagWxIYN7qvEU5T/ioaiAHWViAD2c7DKu VuJEkbg2SqbmwS6z+1zoJOo9R+oFnWM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IAMlhLI7; spf=pass (imf28.hostedemail.com: domain of will@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751978872; a=rsa-sha256; cv=none; b=3UdmxvMMju9VrYXIh1XuZo1Caz/Wb94wULA+jC7Ij7qXRaq6sZnn0LsRnNOdeaz1/svDW3 shbxv44LFYGz+JVM4LkvXGKm5ucUc6QnmIKnKAvSFroVken76aS7XR8uk0Ev2rpSOCyuuJ hghFHnpE+/xd+cfblCU4oWS2/sNahQ4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E48215C60D3; Tue, 8 Jul 2025 12:47:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEA48C4CEED; Tue, 8 Jul 2025 12:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751978870; bh=osuOgrPS2qSqQveywb0omF1aib+vgM1aAsa1ykg2SH4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IAMlhLI7cory+R2Bv4G4I7BkDERGpi3VYc+VJGMY+ZmNiGrhtDEs5lgtn+8wiu4u6 EZFwzSY16+e5Ji4D7Z6CjUvZ/aXOfk0tPqg+X7zkamPyn+7COaeDs9tzZNxW6e1Bde RDRJRPH4YlXqHDgCmiM5y9tWAtKbqTUdHFW/6cSunfJLTNzYsSBxUUuFjipdJmxqcw K7hhKc+761noYebQwzzUpbXXXpHiwdELTf7fK7AeLVsfnlClHKizMH3s0RzYNTa7lh cOMY4Vu2GYsVOri9ahMntePMKOUl0lTQF5na6epLFdZ7pqzS6A+Z0ZkjhA69R2BzK6 PfXrRaTRRXXBg== Date: Tue, 8 Jul 2025 13:47:38 +0100 From: Will Deacon To: Jason Gunthorpe Cc: David Hildenbrand , Ankit Agrawal , "maz@kernel.org" , "oliver.upton@linux.dev" , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "catalin.marinas@arm.com" , "ryan.roberts@arm.com" , "shahuang@redhat.com" , "lpieralisi@kernel.org" , "ddutile@redhat.com" , "seanjc@google.com" , Aniket Agashe , Neo Jia , Kirti Wankhede , Krishnakant Jaju , "Tarun Gupta (SW-GPU)" , Vikram Sethi , Andy Currid , Alistair Popple , John Hubbard , Dan Williams , Zhi Wang , Matt Ochs , Uday Dhoke , Dheeraj Nigam , "alex.williamson@redhat.com" , "sebastianene@google.com" , "coltonlewis@google.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "ardb@kernel.org" , "akpm@linux-foundation.org" , "gshan@redhat.com" , "linux-mm@kvack.org" , "tabba@google.com" , "qperret@google.com" , "kvmarm@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "maobibo@loongson.cn" , "pbonzini@redhat.com" Subject: Re: [PATCH v9 3/6] KVM: arm64: Block cacheable PFNMAP mapping Message-ID: References: <20250621042111.3992-1-ankita@nvidia.com> <20250621042111.3992-4-ankita@nvidia.com> <20250630122501.GQ167785@nvidia.com> <4b06b163-e1ce-4c20-b878-4593bc86bf53@redhat.com> <20250704164750.GO1410929@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250704164750.GO1410929@nvidia.com> X-Rspam-User: X-Rspamd-Queue-Id: 2555DC0011 X-Rspamd-Server: rspam09 X-Stat-Signature: a9rrxh8tdoyf7nmw14tif98rkhpujjhe X-HE-Tag: 1751978871-314613 X-HE-Meta: U2FsdGVkX1/luv6T671K0tIXLVGUhmYzFoInnfeNXpEIuEVGazKmN1ic97RqpctTj4Be57GxodU+1m/Dc4WbxvDvWWmB8cdpiIiRcOea761/8bJJLEdcrCKb2XiRWbiV3bl8xUCWChYw6E1Yn5GstI1ar5fV3yYiNdGq5bVNUzJb2vfMFBMvYF/G9L75yBWS/lt5nwmSzNmICl+rWIgRlH1ToPCXDFYHMFtSoAZr/6AnrcA8CjsFzfWup7ZuD1vRv1FKWK0I9UV1jB94YR+hUFOJyQ3hssvy0U0tjcfP3h56KHM5RjF/chXFo5lkrGwAaSrPrXUCD2L8ou2Bo7csHupMpwH7iSK52yK4E+F9LUI7DgITK+rQ4lKAoumyZ/THZObTSrk8SchsC8RTzSX5FFdviHlKh41a22z6TCV9J5igoJLR6u0TK2HkXyVwogTkxpKIHEgiFYb1bnfrpRh800danDpqdqg34xFs1089HBIyYIg0it9VQ1JzZFo317Mave1x60kGWyhUrtTRIVsKPop7jwi7uqJsZ3FixQdyyKT/yLm5wZTue2HlSn7hRldwh4oVBTjcZoGiJV0TN/Exny8xwpsfLfsUn8iK2RoIrdIWGn5QR0wrj3/NYjowefXcJqEfTkbXk1bVlQpxXE8wfqFO92VPpUsUGVj2KCYdOXfIsl8BDqJcIIf8bNadS++3bHhZRfT33Ti0Pe3nPrcepFDExrTG6N2zy7JYr2J7VzmbnG55sAwx8ux2BmeyVoUtf39WB010Ryf0ac2mIW3Cr7C2cZO2XFxHR+uqv5vUURXEZN+g3WT5O+P7LuEgiLITFDG0FcljN0XsIln2iWR+Ow/v1VNw7+d9s5PBltBR5S6vVmApznbc3svzSB+y39eg7kkQ2El/Jb8gTzsUsvnTN73qGTk5xUXvP2RYFjk/gui3yUKNwcy4BVtlmvq+YXbONzpoZVwQN/DzPU4Z0aH j3qLWTEW hoAswuvXQv4f+HAva4uQ0Ts9ZS9z0gM9Pj4Ccxf6N2K6ntDQbfIIPlyD9QbowAo3yfwaBaNRDXzuo5XyKw/ulitRDPSg6CUzbCE1g/FDEEZsF+fV/8CpgKqC6jykBfpWxmHaE+lQuaxfD+kvzWv9QzzYCFWDsrQ5eL/y9XeyXcmUPsocataK8HbNctBuKkiGfaJVFpu8kWWLPq8U0tzGdjkNAvtmRPeCcd6nt8R8/7V7iC36Ob66iaDDUOfbk2FFMGWK+tqj7FGmAsL6wzyqqkDOEu4o3jYUunkNwXbic7rw6LdQSVVCKz2dHp3uMMfQDJpvlmVG4J80yD4+T0bnXvOAhdQ== 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, Jul 04, 2025 at 01:47:50PM -0300, Jason Gunthorpe wrote: > On Fri, Jul 04, 2025 at 05:04:17PM +0100, Will Deacon wrote: > > On Fri, Jul 04, 2025 at 02:21:32PM +0200, David Hildenbrand wrote: > > > On 30.06.25 14:25, Jason Gunthorpe wrote: > > > > On Mon, Jun 30, 2025 at 01:56:43AM +0000, Ankit Agrawal wrote: > > > > > > Sorry for the drive-by comment, but I was looking at this old series from > > > > > > Paolo (look at the cover letter and patch 5): > > > > > > > > > > > > https://lore.kernel.org/r/20250109133817.314401-1-pbonzini@redhat.com > > > > > > > > > > > > in which he points out that the arm64 get_vma_page_shift() function > > > > > > incorrectly assumes that a VM_PFNMAP VMA is physically contiguous, which > > > > > > may not be the case if a driver calls remap_pfn_range() to mess around > > > > > > with mappings within the VMA. I think that implies that the optimisation > > > > > > in 2aa53d68cee6 ("KVM: arm64: Try stage2 block mapping for host device > > > > > > MMIO") is unsound. > > > > > > > > > > Hm yeah, that does seem problematic. Perhaps we need a new > > > > > vma flag that could help the driver communicate to the KVM that the > > > > > mapping is contiguous and it can go ahead with the optimization? > > > > > E.g. something similar to VM_ALLOW_ANY_UNCACHED. > > > > > > > > I think Paolo has the right direction - remove any attempts by KVM to > > > > expand contiguity, it should only copy the primary's PTEs and rely on > > > > the primary to discover contiguity. No new flags. > > > > > > 100% > > > > The part I don't understand, however, is that I can't see an MMU notifier > > anywhere on the successful remap_pfn_range() path. So if a driver is > > using that interface to change the mapping properties of a VM_PFNMAP VMA, > > how do we ensure that the guest doesn't use whatever stale mappings it's > > faulted in previously? Did I just miss something? > > Generally mmu notifiers are for invalidation, not used when > establishing new mappings. > > It is not legal to use remap_pfn_range() to replace already mapped > PTEs. It can only be used during a fop mmap callback to establish the > first mapping during VMA creation. Thus there can be no present > mapping cached in a secondary and no need to invalidate. Aha, thanks, I had completely missed that. I thought remap_pfn_range() was quietly unmapping any existing mapping it ran into, but that's not the case at all. Cheers, Will