From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230794; b=THwL6G0Bde8uM6BAu5Qt95i2PJzGWKOjYX8IZiPIiF7w6BFmBK465hP6PNdEShpaHtBB Zy0E2+SRHi8vZnxVyqARu9Xa2gxQsviOzPSU4KbM9y37pEWZNHcS/Bo+jnJNFk8NR2Cgw vGL7BLeDfKMVlABLQD1uX3TFM0PUkkGhCiMQww7dzUqvooxGRnIfmfoG7zGJ/4QABO4N/ AGdjmasdbJZ4eqvxEGG7CUhzFralzbBU9O6e2BtJ948fb6zPNBWx4yrNreU0+jJ94cfEw hb5imtDc8lnYQurfmY5vb/IhCuZbtJYdbAEid4titmrRhpyNy/sPnU+39QbgHBv7SyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230794; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=5x4aZVzV0cv53rNT+PhT9bIcsAZc3a8JM7aBJuDbLoU=; b=iEz2G5gnua7duGj8MRiIjLhr0YwUT6uSWu9dywg0VtVXaggqTzreCmFxRgLiIUsz6+yj CsDxefXJHrX4K1QMhcbC6Y+SJOksNfhZ3+/ZJe3Vq4yqYZi8eEXz/mAayaH7MTcpoez9B 04PXXudGJQZ94koHyn2mDLgH3YEbrLoxsl8clYYY4srW8jvHdWGctNCqGGj5N5duLk8hD LZN8V/2Gy/0aQCWXGSOE3eI0wdOGvH2B7NSv54IqQ6Ar+/Qt7PutQzjBvgjWCBzXE6XUf Zw8/eUYVH50yN878ThS8nownsAcony7gHimp21/oHaFZMsqxzkBbNYUE47zTHrr3D9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N8LHwSvc; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5DA4606A323 for ; Wed, 2 Dec 2026 16:59:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5DA4606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N8LHwSvc Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb64ef5a14so123132015e9.1 for ; Wed, 02 Dec 2026 08:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796230792; x=1796835592; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=5x4aZVzV0cv53rNT+PhT9bIcsAZc3a8JM7aBJuDbLoU=; b=N8LHwSvcomxZzN7C/aaljIhGZ6sGrKO0XoO0BD3ZRW6i0saykUq5QtWG0jc/eSykjy YWgDKV8NXw47BbPolk0d2062du0bBQ7BGC8gmy+F1Izy5tv56IDbPqIcrf29FSzmS1T/ tEJr2rJX7d3SULVPUC/D6t763yf7IQoY6pfJCEFKvcxtPkBRCi6tv/kS85vb/hUn6g4A aVlGp7GjqCYi18vvnhrxFPTjsjWoNyQ93ehVV+qkOg1rV/IAcYk0TzSRmF1CkLoXzFMf AtHOhqiOgs6CfoOUJu7P6+ZgTE9aeTS/u/gRQi1eXTvZhnvgkDVf7vN7Vj5rMAKChHNw XhqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796230792; x=1796835592; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5x4aZVzV0cv53rNT+PhT9bIcsAZc3a8JM7aBJuDbLoU=; b=PswU7IKaWt3LVl0/E5JEBOeVTpdTuJbrKp9G11gjhsF5IRuOVXRNxyuOtYDTpwfjfh wANK5e0Dm8rhFVG52lzauPdw4AXYIdx8pBDeGjhj2aOG58NbcFkEbdTW4opMDTzULk6T 5E6jf+WhnOGZbZ5iblv/ETFN0i8BjeOnBGUVngBxqV60JHFOwZamauhui55JZwUkNp2d Dz8TzODSEmdDsaj6B74kR9zXHdNTolrQdVnpGKbEQVvRBVH2xGNndzaXzk1fUtk37Jug aDrrF5QV5k1lPSRBPqxAZntVMqrtip4OgfLZUkkrXiSSFzD9h/TPFLtTRtZgjKVBgaih RqRw== X-Forwarded-Encrypted: i=1; AL+hErFlDxKYNWSEpOtZRite8EJiQl7Jza3lIAcF8muVDfOUeEhybZclp7eGQHgRMh8Sst+koOnjBEThHW5SNAE=@vger.kernel.org X-Gm-Message-State: APuU4Z+YCVc7l98mH11hVQFIKGVmue6mFlCx0asZ3Rs7Zj2pXMpsSX8W J/qKObMCj6bbzRfaXu5mogemkQF4znjCXmmFqrv7V+zg6QVCWfOfEcp7hLzVMVCooQ== X-Gm-Gg: AZFdTZcgHPT3tkenMEtYYXh71V1Lf1zqGDT/ESW2yBRdBdcWwwNMhzdRFz5aqwbpzEE DQ9B1tbelcAkW8XOhLWEM0FKtdoBbY9Nq1NOfsUJAqlTVFf63cwUXA6jJzAH7975sHNn/uFYf5Y VbjVflW7ggOclazQtbWv96nb5viG3A5VckWs0UmT/0UNTNACaxTui+eL2Alyfyc2yZRz7kU+uhP 5OrF/t2D4/9jubB0lbbQ6FJ9yl1MGNe69TtvdIQHLx3nPWUMZnHBs18YusOKWeJ3iDYXMV9tasI lJ3Pz71xNOWEE4uVwgMS57Qnu+yTottAyC6YLVep2Ql1rmo/RjghB6+HJfYRc2FOhETRxjkRKRi Mf00Yb7F91AoCh2GCR5nysZvAcE1yKn4bRYzPBWw2aM/DuXSCix+rIYUL6WK4JhzsNuJPeWZbBb 7n57LmPGhiT8+tuEW6rHpnoEu0+BVFwpNF33UPtE4AiXkODjTi9ULqNLl27yS3PYfT9/3cIQ0y1 V3mLTuingqpajaWjMmGuSjetDYavrldh+xpnXF6sQu6SAwZbOLPuh8PZWX2nJSxECr8EYhrs5Mz fKVc8Vh9RNZLn4PHK74EbZHnLZQXzoCLflivFPcp+tqSJPoE5a+yAawtrQGOX/0eb93dKpp4Ec4 FUSqfEr6HFGgN+sPbRwkOJS4boyEFz0nNJmTt9s2rpw== X-Received: by 2002:a05:600c:4e0e:b0:4a1:da58:1ee with SMTP id 5b1f17b1804b1-4bb88938dc9mr852945665e9.31.1796230791606; Wed, 02 Dec 2026 08:59:51 -0800 (PST) Received: from google.com (0.182.34.34.bc.googleusercontent.com. [34.34.182.0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe005f4bdsm385025e9.9.2026.12.02.08.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 08:59:50 -0800 (PST) Date: Wed, 2 Dec 2026 16:59:47 +0000 From: Vincent Donnefort To: Haseeb Ashraf Cc: maz@kernel.org, Oliver Upton , Haseeb Ashraf , Fuad Tabba , Wei-Lin Chang , Joey Gouly , fahad.arslan@siemens.com, Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Quentin Perret , Raghavendra Rao Ananta , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] KVM: arm64: Resume stage-2 range walks where they stopped Message-ID: References: <20261118051648.74580-1-haseebashraf091@gmail.com> <20261118051648.74580-2-haseebashraf091@gmail.com> X-Mailing-List: linux-kernel@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 In-Reply-To: <20261118051648.74580-2-haseebashraf091@gmail.com> On Wed, Nov 18, 2026 at 10:16:48AM +0500, Haseeb Ashraf wrote: > From: Haseeb Ashraf > > stage2_apply_range() walks a range one block-sized chunk at a time. > The walker steps over an invalid entry in one go, but the next walk > starts at the following chunk, so an invalid entry larger than a chunk > is visited once for every chunk it covers. Unmapping the whole IPA > space of a shadow stage-2, as emulating TLBI VMALLS12E1IS and TLBI > ALLE1IS does, takes 2^18 walks with 4K pages and a 48-bit IPA space, > however little it maps. Each walk also ends with a range TLBI when > FEAT_TLBIRANGE and FWB are available. > > On an AmpereOne A192-32X (192 CPUs, Xen on KVM, 4K pages, 48-bit IPA), > a full-range unmap of one shadow stage-2 took 0.84-0.94 s (mean 0.91 s > over 226 unmaps) on 6.18.29. With v3 of this change and the mainline > commits it builds on backported, it took 2.1-45 ms (mean 4.1 ms over 672 > unmaps), with 512 to 1023 walks instead of 262144. The slowest TLBI > VMALLS12E1IS trap took 0.94 s before and 46 ms after. > > Have the walk report the address it reached, and have > stage2_apply_range() resume from there. Unmap, write-protect and flush > all go through it, so all three get this. kvm_pgtable_stage2_unmap(), > kvm_pgtable_stage2_wrprotect() and kvm_pgtable_stage2_flush() now > return the address, or a negative error code, and so do their pKVM > counterparts, which do not walk page tables and return the end of the > range. The other callers, in nested.c and at EL2, only looked for an > error: they now check for a negative value, and those that pass the > result on turn it back into 0. The walk handles every entry it steps > over, including invalid entries that carry state, so nothing has to be > looked up beforehand. > > The unmap of a shadow stage-2 also drops the guest stage-2 records of > the whole span the walk covered: nothing is mapped in the part it > stepped over, so any record there is stale. Each walk that remains > ends with the same deferred TLB invalidation as before. The spans that > were skipped have no valid entry, so there is nothing to invalidate. > > Suggested-by: Oliver Upton > Signed-off-by: Haseeb Ashraf Reviewed-by: Vincent Donnefort > --- > arch/arm64/include/asm/kvm_pgtable.h | 25 ++++++++---- > arch/arm64/include/asm/kvm_pkvm.h | 6 +-- > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 22 +++++++---- > arch/arm64/kvm/hyp/pgtable.c | 55 +++++++++++++++++---------- > arch/arm64/kvm/mmu.c | 32 ++++++++++------ > arch/arm64/kvm/nested.c | 2 +- > arch/arm64/kvm/pkvm.c | 14 +++---- > 7 files changed, 97 insertions(+), 59 deletions(-) > [...]