From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230794; b=2uAkKTo0d3Sd9+EOHLbXsVNhrHtlA3bUZalfEoZWdT6ymSeuuU0q3H8VKbBjqWAvFSc4 H5ZV7OTK0J1GQ2cRGc10UYTV7TZVcEKpj3mzoxedhIm2Hz9U80yX2XFi4YoSZvs2B8gvd UoC/YBr2TItS1pLk4xypgrEpjeqpkypKt+kjYnTs0m8+GVLNtsrGFTta4Jp1iIuptRO5L Cq+QuH09Wb19bvbGmikOY92iNuP10PHftEPl0z86w7QQ7ivqBc1UivpAZ66mF0gLNsj4e fC4h6tPnBCwqLsT1fzSZy65/gFF2FB8m/eEh9MmdhPfdR9oVoTpWxdXRw8CcP8s2ZCA== 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=QfQ4P6DERMxmj6iEnYxCGQSBZTAsiVSZ6CZI7p6pq/Jfz39sSAW7oxN6INgIfoMr9G5t pJ1Yop5sUlnz8YHd3UgyNziE8DH4Bze7QcO7ivwhKtJTIR2+iceY3FVW3Aoy1a/tDt1Am wTc5A+n2INsl7UZ2ChV46RY1Wip96Qfg8QRUgcYL+TDkTPybuOiL+NkVwIf7UNKA1i/Mt Kf9IP+fJx1cIZjNT8j51LhNcPMmnKPHvwFtuGzGhOmQKZm1ljkmb/nRTlqn6iAiKeDsdG qufc00c3dTWpBT53m6LnEVDn08oZxjTeik2/ET8/cd+TQXeM0QUEbXGRD9vqHmrFdAg== 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=buX4txii; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 C5CBE606A322 for ; Wed, 2 Dec 2026 16:59:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5CBE606A322 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=buX4txii Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a214c5c4c0so126794365e9.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.linux.dev; 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=buX4txiiuQV1fEgRqDKEsh7HoQcSkDyXW2nG7E6512crSipE8yjCNsAw3GDcwUHV+v egZuzhtqdSnyMQZwn8xSQOthOd1PA1xnu5Ws4pAEYECNwD5KsiYPI65JeXUmwrHGCA6m B/FgUZ3x0b5KiX5RXiFTYl8PbWPW53NxNeryLUGpAuKJ9GoUS5Zl0aHfvtCl3KZVsQT/ jfNXG0AKxipUfvz6Ns3xNGvyMOfoAtblh1U1OS9nLxpKH9vzD6eoD7Pqp4cWUReLhRRN LDlWibXhdqM32adknO1/pxNvFi+OPFnN6Zrql+49MqrAA8gi5R1mrfn9mEI7sTfH6myu 9Uug== 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=DtjhGds6adQQ6V3yh1zTeuiXDXjv5dls4mlAvhcIVELx/q+F9VWawM4CbvBYB5GKVf jL+e4WeJ96Vlor4ldDt9EAM/iYSiYqQg6YSYhu1ud3mzGx1sN48L2ebwaYs8uNtecW2I 22JH+jYfkyMjBrtgwx9/C2BkNpQp1Ibm+L1NFAWZMDHrhEWdGWByM7A6aszc8vh2za9f yfKpIZJpmNASgzHUnC8Dy1cZUKJrLVu73dVjpmkWpb0HHe59VileuNFTFpZRU7E074BJ B0PkPd+by0msqxk5opKU4MPx0d5WWVFoNc5siXhOyWejB/U01WH3QOIN274YycbrWlRp a2gA== X-Forwarded-Encrypted: i=1; AL+hErHMZ56+xdAu30W8rJiybGrjQtQXZMjBxTAJwThTWAytirdECeCGcW1bcS0eT7wgwdEoJ3DAxWM=@lists.linux.dev X-Gm-Message-State: APuU4Z+XbYhzVCxB/YafiU9rzh1ararIgT11HhCJTPDjyzm4Zi3aS5oP 7bI+wbIczyy1aeM2oggpnb56mvQXo2elRyaDyQPlPPBRcgehukogiIbfp010gHSg7Q== X-Gm-Gg: AZFdTZc/GMp8FWehBfgVCuVhE9OJ3vG65pN3NSqD20FcQ8gpvR6+rD3YMeerFepcOOd phSL3MyBes5jzrs9BOwEUHUvsNVO8NsixeYxD5pWzY12d/9UQc2oYYNU9mj1krAfcotilplEYVX jxMB3JffdEkfD/rri0FMzlJVUC6Gq79S56mxlIXeJkdk8h8xCnF+qV80sp415FQaidrkCvFDtzw c0lDeRJKCZ3+iC3QRDgj4qedMJTdYWIMdCZ2hWAa1cWytOHVTTmqJ2r7y9fNpPi4XFjRu32zJgb 4sEqz/Xb7dFrYNMdyEZYWaAmaEdVyhUt/izxGIKthKpgVJxklqUh2JneNvH9atjA/uvU22kR7sG GAcxgjFLhX13U3apFflD8pXxQqVEhXGmQQ+BIUaMvX7K4jI8UqDEwZO/pOTS+Q1zd+WrtJILgqJ dyN2CcR45Z/B0OoG7YTXCG3/+AhTnmgM5p1VG/AkWsHovZa5kkzYsZxCFjvYOyYy4tHm26o1768 gWBECHGCmR7uXg6EMoY3pPTBi3N1EK7HKD1fFZwmpp3sVh7+gJFQ+ACoghhbifSoYhAE9r4O5C2 AyrsdIKu1Vs4ktpL3buWs/Ralqzhr/wenHfB/pEod8HKSPmwQMgZQyxp71dTHDtk+DrTNFK6oT9 +sse38m107gRn/m2Cax7IfEJUbFRTp4k2X8Pd3XWB2Q== 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: 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 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(-) > [...]