Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054249; b=gtXN+cmn8FqQDb3ta6wqzBeksQn0KQNMmiorccl27p/PvoKLtZbndwa4SAMsIMNlwUwD SJNBtsqpe82SBcwAqwyKqGtmH3mIIB3prGgcEoYZqWzkqvKoFzeFakJFLNEGE960JuEBu SCM6IDVU1ur2UJcCiIB1xA7AkZtD+uHRT/raGODdF//T2fLV+sOTe7QYBJvmxCU1xIfg3 8OCW1ZlAVx7Cph0WnA89bHeJerByalSLltggWzB6/ut8lAMT2ZXuc5xEydY2qGvTnk3uv P6rQtLTcxa5B6afzu9I+lBNDFCaE4yfZzD3ccFtiMnCtTIzLyyxedP1JpMj2mI4X4gw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054249; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=qoG2Snfm1gEyO58DOXiS/E3XhSedg2F4SykGb1Kp+A4=; b=rodyocNO54OW9xmxjPnrd2mlOJavnAB8bez1KBTwtz5htmiItfcfoyv1RGRhqLxzXKuo 6dl4q3kR9agLFVV1ZFLQUO7qKc+1/2ak3LuqnoSPjA56jVKyS8/MnJ7bn/5k+zysvsocT Ik9/OdpTPfth4UYy5yCrC2pcKn6rdWOM0zGh5YpSb1wVq+4mdpVhIUHKZh4aiv2way6vf vs8Xb3sGN4XzSSw07U/e+MEojZIenP1y1qHxk2hhTWXF7ISo6LcY4gYJ4jiJpGghb4P3e 8QT4NeEoLp1i5P2S/mQIhpnX7FwaofxkhZxAAniVszcxFvqvLYNW577zfQ8o/0H35Tw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VZD3ePae; arc=none smtp.remote-ip=209.85.128.71 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 76635606A31C for ; Mon, 30 Nov 2026 15:57:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 76635606A31C 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=flex--vdonnefort.bounces.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=VZD3ePae Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4bbb2a62535so22046665e9.2 for ; Mon, 30 Nov 2026 07:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054248; x=1796659048; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qoG2Snfm1gEyO58DOXiS/E3XhSedg2F4SykGb1Kp+A4=; b=VZD3ePaewQE4ho9UHDd5Q+EveYxw2UcrU83cYhSFo+LKZrs1bgp6KoIRMAyWZghOeb vr6VktShktVNLFCpGBGYnPlOcr9feqqVnDG73aPVllSulpC0QYNbzMIAvJMk5HmEFGWM BsGI4BVY6zH4tCy7LWvoFMQITkUsEmsSaEjCcI69pKlMOgwmlCwAmsTSzSTNaur9Dc6Z 9xjlrZENBfHmov9YRkdwsj5czwL3y+yIopWrSdYars8L3vc/x7g94hb3gi1A3sErNSI3 O3rVJIOhCxORebC8yjMnoCc/fDa/II2RzTeKBtzJ+EiS2sNutWHpsjsB7R+ZHHZFxNsn a5yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054248; x=1796659048; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qoG2Snfm1gEyO58DOXiS/E3XhSedg2F4SykGb1Kp+A4=; b=iQGxrA4rTwSzJrFeTwSglrsY5Q6ONWGOr9AepJGe4/R+8RzCaTdin5H1nZADRm1Spk S0WLlrAX+KtVWtuTUM29QbP/qmwX2BaLVfy3sZc62IkVbU+EZzuQE8pzF6+0o08GC0Kn DQC9mSutZYG6R9QLBYtgrwQAIEAGcMaEQmVFKkiSdM5++4W37K1/lOGm7e0WzHS25VxW ZK3spbpKas5y0I3/O0/FcpGJ5p6ZeKqfsK9jXwEB6jsVc7vlgpUbl8JIXcOv10oFrsGV OGBKyzComD0q9jzATLFUB1zBrPpcq92VWDgqX6HYNfqrEQ4viEgX1UkOH85lSLt4NHLx NVBA== X-Forwarded-Encrypted: i=1; AL+hErEvcj/aMxrDIIEd8VOgNh6T7cDCis1KjPFhKzfSaa5IJA7TF6THu6KwogD/CW7aAwyctVvQLqE=@lists.linux.dev X-Gm-Message-State: APuU4Z8q4rQzyKVw5ayiKfXYzvfDLVzHyIBkZWW/4wlRYXhRCGU1S61I oYOIyuy8bX6bAFIQ3l2q3jZLoeYs0+H/urhjfH+1jkvDxQ2Z/YfVdIJN59lGisF8X+UIZODoSof oPy74hPCU0fe9hSs7OBd2Ww== X-Received: from wmg12.prod.google.com ([2002:a05:600c:22cc:b0:4a1:8e4a:36d3]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f0d:b0:4bb:5c97:f4b1 with SMTP id 5b1f17b1804b1-4bb8881941bmr735582605e9.24.1796054247506; Mon, 30 Nov 2026 07:57:27 -0800 (PST) Date: Mon, 30 Nov 2026 15:56:45 +0000 In-Reply-To: <20261130155710.2371874-1-vdonnefort@google.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 References: <20261130155710.2371874-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155710.2371874-2-vdonnefort@google.com> Subject: [PATCH v5 01/25] KVM: arm64: Prefault host stage-2 entries on block split From: Vincent Donnefort To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, kernel-team@android.com, fuad.tabba@linux.dev, qperret@google.com, weilin.chang@arm.com, Keir Fraser , Vincent Donnefort Content-Type: text/plain; charset="UTF-8" From: Keir Fraser For the host stage-2 that is idmap, we can avoid lazy-mapping on block splitting by propagating existing valid mappings to neighbouring entries of the new table. With stage2_map_prefault_idmap(), kvm_pgtable_stage2_annotate() installs valid leaf entries when splitting a host stage-2 block. Issue a trailing dsb(ishst) so the new table is visible to the hardware walker, matching kvm_pgtable_stage2_map(). Signed-off-by: Keir Fraser Co-developed-by: Quentin Perret Signed-off-by: Quentin Perret Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/pgtable.c | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 9c83837b184d..8fbcc5df9b63 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1032,10 +1032,52 @@ static int stage2_map_walk_table_pre(const struct kvm_pgtable_visit_ctx *ctx, return 0; } +static void stage2_map_prefault_idmap(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t *ptep) +{ + kvm_pte_t block_pte = ctx->old; + bool counted; + u64 pa; + int i; + + if (!kvm_pte_valid(block_pte)) + return; + + counted = stage2_pte_is_counted(block_pte); + + /* + * Shared walks not supported: cannot rollback refcounts on break + * failure. + */ + if (counted && WARN_ON_ONCE(kvm_pgtable_walk_shared(ctx))) + return; + + pa = ALIGN_DOWN(ctx->addr, kvm_granule_size(ctx->level)); + for (i = 0; i < PTRS_PER_PTE; ++i, ++ptep, pa += kvm_granule_size(ctx->level + 1)) { + kvm_pte_t pte = kvm_init_valid_leaf_pte(pa, block_pte, ctx->level + 1); + + /* + * Skip ptes in the range being modified by the caller if we're + * installing last level entries. Otherwise, we need to + * temporarily put in a valid mapping to make sure the + * prefaulting logic is triggered on the next + * stage2_map_walk_leaf(). This adds an unnecessary TLBI as + * we'll presumably re-break the freshly installed block, but + * that should happen very infrequently. + */ + if ((ctx->level < (KVM_PGTABLE_LAST_LEVEL - 1)) || + (pa < ctx->addr) || (pa >= ctx->end)) { + *ptep = pte; + if (counted) + ctx->mm_ops->get_page(ptep); + } + } +} + static int stage2_map_walk_leaf(const struct kvm_pgtable_visit_ctx *ctx, struct stage2_map_data *data) { struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; + struct kvm_pgtable *pgt = data->mmu->pgt; kvm_pte_t *childp, new; int ret; @@ -1053,6 +1095,9 @@ static int stage2_map_walk_leaf(const struct kvm_pgtable_visit_ctx *ctx, if (!childp) return -ENOMEM; + if (pgt->flags & KVM_PGTABLE_S2_IDMAP) + stage2_map_prefault_idmap(ctx, childp); + if (!stage2_try_break_pte(ctx, data->mmu)) { mm_ops->put_page(childp); return -EAGAIN; @@ -1151,6 +1196,7 @@ int kvm_pgtable_stage2_annotate(struct kvm_pgtable *pgt, u64 addr, u64 size, return -EINVAL; ret = kvm_pgtable_walk(pgt, addr, size, &walker); + dsb(ishst); return ret; } -- 2.56.1.839.g22a8290db9-goog