From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796040216; b=RZcuhnAPReflKzwEc51NtN/UKHTvhVI7AVcQVLYaz9HRH+2N2nHe87o+ps6Ku1pY4F0g PEZBCGML6jRbiK//ACbi2LGb8u5sNwYvv/Ih0BaC3EAAzPqfpuVtcPzYs5k48Yct2Z67C PtTiDWkkyud5wDX0o0Uim9xgxEWQcicEGHRtVcqQBLULenXfsgOUavgdy2jlQZU86Yilq 55cH/BRgba1rCT2LoBiF1G5Op827dIX05OdM2if4yBIo1rNjPPb0MFmVzXyu7nUe8nYkh thwWJy0s30obJu0dxGV7354xdMqBk7vQE02QSrem9bsuSIOu5LZ1ePFStNnkrhnQItA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796040216; h=DMARC-Filter:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding; bh=kpLJIfTlpz4wBxLCaRDy0nbTDCDBKZxN7TI1WZryTeo=; b=GN/MD/reRV9TmHaApf0QZ5Eb/ZYaaq3Pm9FWInhZ56r/97SSCAZYojGZdYmURNJXXgnA tA32yEIjeqZ+4jtKz0Rjyo2Qck/NoP6/YJIJc3iPzuqkiVsgibx4UJbdQFZapkql5taqu cxhr7BvlehkqnLbvL9FLE6bC/qJXlorJChh/gwLeBEsAN753vwiOmRbQK1R1gNA58NRKS 76Y0l83L0eGBpDzxCRagFPJ4g+AnOzJkDeS+U+hW94SAbQ7LZEjZltYN8O0kyG5/IXrws AfxJAW9aOSd1KBYGSKByGuTFu9k373ehfgG0ikci/QK2ATYZ36TYBcaQE28uIDyb1zw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Mhjih6Sl; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5CEE606A320; Mon, 30 Nov 2026 12:03:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5CEE606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Mhjih6Sl Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9FE9D1650; Mon, 30 Nov 2026 04:03:31 -0800 (PST) Received: from LeoBrasDK.cambridge.arm.com (LeoBrasDK.cambridge.arm.com [10.2.212.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 68AB13F7D8; Mon, 30 Nov 2026 04:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796040214; bh=lbsanBmOFMTCV/luC08vrWE8KIhLhLmRM26Bo/lX9BQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mhjih6SlRrOUipgy24rCZV2UFvGcfsob9Opls0ILm9yiMlDI3so8k5SAo+WXKgQ82 TezWTxA+BxrBMOYDss5SPfdvHquhEMU5VQRN0/YYsPfbpPhkshBmgEqEOPzwORvQoB WCTTKjKkuVlbCFzaW2CHHYZtT+1L/FvEFyMZh4Bw= From: Leonardo Bras To: "Lorenzo Stoakes (ARM)" Cc: Leonardo Bras , Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Christoffer Dall , Jintack Lim , Wei-Lin Chang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Usama Arif , stable@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV Date: Mon, 30 Nov 2026 12:03:25 +0000 Message-ID: X-Mailer: git-send-email 2.56.1 In-Reply-To: References: <20261126-fix-nv-cache-topup-v1-1-a22c936872fe@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, Nov 27, 2026 at 01:09:11PM +0000, Lorenzo Stoakes (ARM) wrote: > On Fri, Nov 27, 2026 at 11:58:04AM +0000, Leonardo Bras wrote: > > On Thu, Nov 26, 2026 at 05:28:29PM +0000, Lorenzo Stoakes (ARM) wrote: > > > The S2 user fault path tops up the MMU memcache (used for page table > > > pre-allocation as the point at which page tables are installed may not > > > allocate) except when: > > > > > > * It's a permission fault AND > > > * dirty page logging is disabled AND > > > * pKVM is disabled > > > > > > At which point it is assumed no page table will be allocated. > > > > > > However nested virtualisation adds another edge case - the mapping size of > > > a shadow S2 is clamped to that of the guest's own S2. If the guest > > > hypervisor replaces a block mapping with a table, a permission fault on the > > > shadow block has to be mapped at PAGE_SIZE, which requires a page table to > > > collapse the block into. > > > > Can you please expand on how would that happen? > > > > IIUC when a guest hypervisor replaces a block mapping with a table, it > > calls a tlbi in the range, and L0 will trap and remove the Shadow S2 entry, > > then next access shouldn't be a permission but a translation fault. > > > > What am I missing? > > That's a great point, actually :) > > But nothing really enforces that L1 does that for sure, even a bug could produce > that, and you really want to avoid the host getting in bother in that case. > > (The host kernel has to behave properly no matter what guests do). Oh right, there can be malfunctioning guests :) > > I was able to (get claude to) repro this easily. > > But actually I think there's another case too, even assuming everything's > well-behaved: > > * vCPU B: Writes to a read-only shadow block -> permission fault, exits > to the host. > > * vCPU A: Concurrently does its break/TLBI/make on the L1 S2, replacing > the block with writable pages. The TLBI clears the shadow block. > > * vCPU B: Now handles the fault. It's still a permission fault as far as > the ESR is concerned so we skip the top-up, but the L1 S2 now says > page rather than block, so we go to map a page and have to allocate > page table(s) for it. > > This needs the mapping size to have changed (otherwise we just try to relax > permissions, which doesn't allocate) which can happen when splitting, > replacing pages with a THP page, etc. > > In general I think just topping up regardless is the better route, but for > a backport this is the least big change to fix this. > Ok, fair enough. FWIW: Reviewed-by: Leonardo Bras Thanks! Leo