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=1796391621; b=04HZ/DXwM+ZwFG/AX7PrSrUxtvQfuTF7CcNUi/q7rOgYWBz8AcB/KrIfk9iOtCKSyC/K 39/U8QhF1YYET5dWziQncgLhRx3RJgBGBj0dM6yhePOVoefw4kGCttNdBGdWy2ioj6kHX 5NaZdWzUCEkywDtmadvrF68VkNxWLpC8mBNe1zNftOAp05obG8yvls45FQL+IvnnYQmzO 1umICWf4znrC8qPjpy98lYSI7Diz1etp38TUauzpNERG7VyBm39XS2fcni1hOPJpBhvZv AVri7pQJfEXX5WvidW6oKUGLJf7vzlTZE9ABS2tPcDbgoP8zWWFy6XQKU30DziWPUiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391621; 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=2AmiFLnzfhuySQMt64ZrwysblJeq2X2j1i3P2A15rjE=; b=SCVO0+Q/W1nWN7s5CSObluUg/pJt3F5DPfecLTvOT2KVHvxuvQlsGpRLQ2eweft2W5Ms 8lK4R/PVK0zqB+HCIX+7gNqYQtF2Py7wSbfZqk/7+f47zsIPNcZWjowvhKiEM47Lr5uc0 YZC3hqyzF8M2wl/uFFiOXRCM1OUVeBcKxiFJZwi95qhn/qx9slDanetHJIzR1golyZK6V 0AAaz5a4GvMB4Ju8zkvcdRBdcZVdbvaBlr5QFPU223rYXzfy+IwNevDtvwhuAZMC2/ech 5Fi0derfU3UhxwmeAIdQ0FE+r+5yOUbEkmKtZzK4psS6nv4Cbxhl7RE8/GOvjJKF76A== 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=pdgA+3F9; 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 AEADC606A32D for ; Fri, 4 Dec 2026 13:40:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AEADC606A32D 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=pdgA+3F9 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 E548214BF; Fri, 4 Dec 2026 05:40:16 -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 643CD3F632; Fri, 4 Dec 2026 05:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796391619; bh=7MYI+PbDH5Cg7CAMuQ6SzNyKPe7W8H4bQFzyP/cUKYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pdgA+3F9A1CtLYVzWNKu9LjlYkekhBONLIRw900ufQULZ090q+HscvEC8Gtngi+u9 HCwbiZmWkFulK9zvsY8eEKLZiCwVEDH6I+mXCmhY5+tYzNpuhaQ7cVPaHycOtoqiMK gZBW890POWZGI+MBuiCIVcdleSE1eFKNE3CtYCZo= 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 , Yanan Wang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Usama Arif , stable@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: Unconditionally top up the mmu memcache on user fault Date: Fri, 4 Dec 2026 13:39:59 +0000 Message-ID: X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203-fix-nv-cache-topup-v2-1-afc8fc1f87a2@kernel.org> References: <20261203-fix-nv-cache-topup-v2-1-afc8fc1f87a2@kernel.org> X-Mailing-List: kvmarm@lists.linux.dev 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 Thu, Dec 03, 2026 at 06:45:24PM +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 this is not safe - if the mapping size differs from that at which > the permission fault was taken, we must install a new mapping, which may > require a page table. This can happen when: > > * A guest hypervisor replaces a block in its own S2 with a table without > issuing a TLBI (likely due to a bug) - the shadow S2 mapping size is > clamped to that of the guest's S2, so the shadow block has to be > collapsed. > > * A guest hypervisor does issue the TLBI, but races with another vCPU > which has already taken a permission fault on the shadow block. > > * Nested virtualisation isn't in use at all, but the VMM replaces a THP > with 64K hugetlb pages while a permission fault on it is in flight. > > With the memcache empty, kvm_mmu_memory_cache_alloc() hits its > guest-triggerable WARN_ON(!nobjs) and falls back to a GFP_ATOMIC allocation > under mmu_lock, with a BUG_ON() if that fails. > > Therefore, top up the memcache unconditionally. This is cheap, as the top > up does nothing if the cache already holds enough objects. > > Note that dirty logging had a similar issue, addressed in > commit 56fd1fc526e6 ("KVM: arm64: Top up stage-2 memcache for dirty > logging faults"). > > Local testing with dirty logging disabled indicated no performance > impact. > > kvm_page_table_test was modified to take 65,536 permission faults with > dirty logging disabled, and run on an Apple M2 with the kernel under test > running as an NV guest. The median time across ~70 runs was 1.059s without > this patch and 1.062s with it. Cool! I wonder how that will impact with Usama's patch prepended. Thanks! Leo