From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AEBD606A331 for ; Wed, 2 Dec 2026 17:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=OnF9tXoL; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IIeUD08j 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:In-Reply-To:Content-Type: 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-Unsubscribe-Post:List-Owner; bh=5x4aZVzV0cv53rNT+PhT9bIcsAZc3a8JM7aBJuDbLoU=; b=OnF9tXoL1aoOZKW3vKvGWdyJH/ t8SON1p+cKNlBcoB/YxMWQmoQaqy06rgIXKTXJxZ254O5OQn2Tzko/8BLVXfF0j0Io9EFnwTjbkdA L2qs82gJdcyI/Q21EidRcvCL4kB0fANvjQTvrXUjd4QstT3KjFKLV+pJ8tPzkuvI4QL8h52xYpjhX OGRB8ARUDmOjF2J2Vt+3RMF0cRWOv+DjP9IkP5wIYcjz6RmeF+BLd0aYJ9iAkwcLVoQixVy5zXWk9 QXJQYfr67tt/RKP+DMOFQvyDr3ZRMGNx0/kTSCmXXxMZ4EFZiToU/+66etqHG6lxWhiICCmxlt5D6 ciFvm8qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYngT-0000000CIjg-1DLQ; Wed, 02 Dec 2026 16:59:57 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYngQ-0000000CIiR-0FzW for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 16:59:55 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4a214c5c4c0so126794335e9.3 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=lists.infradead.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=IIeUD08jQkC77LHkYBGlnGaSKpg7aVEFGTaaO3q6VIQjRL3GLy9HhUqwRzD0/GniOr NHeMtsfqL+eRmKt8MND0wq9RZbbd+2gWG3osOr6BDRSGuguidrTGp06wLf/unKRI95d2 lCgI68F1g4iAnqyinz1ZEUD7OD8NDPw8y7GJW4z8MFEEaf/i1Tuicy4ZLZ9/6ZLEcTdz 2CBoox3iFW57XUr46lgrI0oAgTRqnuoF4x258cX4L7J//XTxQ/X6Usopn62C+1iMDzzh bfgip01j9ZzWWgcRW9SGPDTyoGulwVWD65L6v+ZG0qH5T8foFTYq7QwZn+8Z6HLPD1Lc VxUw== 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+PhT9bIcsAZc3a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5j r2qXi0m25ySU4EQMfHb9bC4Aj58T48ZTmR6z1MO6mXp6++7sX2f5/ZqY6fS/JG9M432RD9OFyic QacyQ0qETuTP1Qb9IEdTq0tFNOdi9ULgt0Qxxm+SEOqog9b6G9zoy0tnKBWESqHUenWTfBiXABM 1sin4D2Pfx0H5WlKDcAgHmaJfn809ckeUDHsWnvdQquFdNqlLLS0LQasqLer1jgWSWwGre73c/i Ncidr9De/RNbfviCz+UjZC0ZQfWWC/vf3I76ZigdGZw== 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261118051648.74580-2-haseebashraf091@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_085954_138978_BF7E16F9 X-CRM114-Status: GOOD ( 23.90 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-23.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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(-) > [...]