From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD2D9F4181C for ; Mon, 9 Mar 2026 17:34:00 +0000 (UTC) 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:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UkVp5p+EyHzYxl20mkArWDCxcrrAf38UPx9PSZxnzWw=; b=Da6prRjgQgaFbLtDjME0ZVxsh8 MIiF/B3gnQtnspaFH/oEdJXhrF54Vr/ByKINOBMuFwyfpiEt6k0ntS83JbJ8WoNd4VOe1sD0EEQ3u BwR/LWrS3+QOsWliCWZwB2dmXlgcPRyaM7ydhoE8pmAa2Zwi+KN5MbuwjLUl9dayjyvYNGB6kEbEu vss+Lv17hnIh+U+4xD+N4mBKx3ypnRMNFNwfjlEVBE7ux55xXVlQu7+tXoi4CpOsjSdgOCPaiBD/a 0icipXrCIJE4Qzl1Lq/MO9v0iuUWuFuBtgXAe5zuxXrmr+jZe27qF+V1vfSoX0ec8A+owY3E3+pXx /4aTiuFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzeUL-00000007pfp-1BJb; Mon, 09 Mar 2026 17:33:53 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzeUJ-00000007pfA-0IfH for linux-arm-kernel@lists.infradead.org; Mon, 09 Mar 2026 17:33:52 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 8AE4240499; Mon, 9 Mar 2026 17:33:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61F1CC2BC9E; Mon, 9 Mar 2026 17:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773077629; bh=hakByczqTTOCC3dDLy2o9AhSeGLwX0Wh5hMgqvcn8Kc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lSSBaehIbE4OA+NhgIwOwlJy/lL4ixwPUnzNU4PgpHC6POnKmru79zVQlwNHhJ5OF inejQPMIRhD4VBnXGjpWkuXpJ3qjWb300yVCsGK6/neZeF33g+vD+YZmvwqMcWUKIM qQxngcww2U41JEhbyCsQ7xR1X1E6wOvMi0aZVEYiJQLKSACe48qy7phV0GQ/GbLpb8 qNMwqj4eBj2UjEAguCiixEuYG1TuVtVLunB7sWWXMNfQSJUBrUphIvq0eAojEzO/h4 DayK1gU5raHChNWFPZWiY9N2nzgmrKeWmnoezPsHmqNOTKRUw9hEnU239EyHj7EpH0 a7AkOCVxdH9UQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vzeUF-0000000088G-0GCq; Mon, 09 Mar 2026 17:33:47 +0000 Date: Mon, 09 Mar 2026 17:33:46 +0000 Message-ID: <86h5qo7vr9.wl-maz@kernel.org> From: Marc Zyngier To: Vincent Donnefort Cc: oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, qperret@google.com, tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-team@android.com Subject: Re: [PATCH] KVM: arm64: Fix ICV_DIR_EL1 trapping detection for pKVM In-Reply-To: <20260309160450.2610295-1-vdonnefort@google.com> References: <20260309160450.2610295-1-vdonnefort@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: vdonnefort@google.com, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, qperret@google.com, tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260309_103351_174236_DC6E854D X-CRM114-Status: GOOD ( 27.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 09 Mar 2026 16:04:50 +0000, Vincent Donnefort wrote: > > For non-VHE KVM, can_trap_icv_dir_el1() relies on a hyp-stub HVC to > read the ICH_VTR_EL2 register. This isn't compatible with pKVM enabled > devices which are failing late calls to verify_local_cpu_caps() when > hotplugging a CPU. > > In verify_local_cpu_caps(), system_has_cap initialised before pKVM kills > the hyp-stub is most likely set, while cpu_has_cap fails to probe the > feature creates a capability conflict and prevents the CPU from going > online. > > Add an HVC to get the ICH_VTR_EL2 register and use it in for ICV_DIR_EL1 > trapping detection. > > Signed-off-by: Vincent Donnefort > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index a1ad12c72ebf..81bac8faec44 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -81,6 +81,7 @@ enum __kvm_host_smccc_func { > __KVM_HOST_SMCCC_FUNC___kvm_timer_set_cntvoff, > __KVM_HOST_SMCCC_FUNC___vgic_v3_save_aprs, > __KVM_HOST_SMCCC_FUNC___vgic_v3_restore_vmcr_aprs, > + __KVM_HOST_SMCCC_FUNC___vgic_v3_get_ich_vtr_el2, > __KVM_HOST_SMCCC_FUNC___pkvm_reserve_vm, > __KVM_HOST_SMCCC_FUNC___pkvm_unreserve_vm, > __KVM_HOST_SMCCC_FUNC___pkvm_init_vm, > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index c31f8e17732a..0bca57c1cbe0 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -2345,13 +2345,17 @@ static bool can_trap_icv_dir_el1(const struct arm64_cpu_capabilities *entry, > !is_midr_in_range_list(has_vgic_v3)) > return false; > > - if (is_kernel_in_hyp_mode()) > + if (is_kernel_in_hyp_mode()) { > res.a1 = read_sysreg_s(SYS_ICH_VTR_EL2); > - else > + } else if (system_capabilities_finalized() && is_protected_kvm_enabled()) { > + arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__vgic_v3_get_ich_vtr_el2), &res); > + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) > + return false; > + } else { > arm_smccc_1_1_hvc(HVC_GET_ICH_VTR_EL2, &res); > - > - if (res.a0 == HVC_STUB_ERR) > - return false; > + if (res.a0 == HVC_STUB_ERR) > + return false; > + } > > return res.a1 & ICH_VTR_EL2_TDS; > } > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > index e7790097db93..0432852228f9 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > @@ -463,6 +463,11 @@ static void handle___vgic_v3_get_gic_config(struct kvm_cpu_context *host_ctxt) > cpu_reg(host_ctxt, 1) = __vgic_v3_get_gic_config(); > } > > +static void handle___vgic_v3_get_ich_vtr_el2(struct kvm_cpu_context *host_ctxt) > +{ > + cpu_reg(host_ctxt, 1) = read_sysreg_s(SYS_ICH_VTR_EL2); > +} > + > static void handle___vgic_v3_init_lrs(struct kvm_cpu_context *host_ctxt) > { > __vgic_v3_init_lrs(); > @@ -622,6 +627,7 @@ static const hcall_t host_hcall[] = { > HANDLE_FUNC(__kvm_timer_set_cntvoff), > HANDLE_FUNC(__vgic_v3_save_aprs), > HANDLE_FUNC(__vgic_v3_restore_vmcr_aprs), > + HANDLE_FUNC(__vgic_v3_get_ich_vtr_el2), > HANDLE_FUNC(__pkvm_reserve_vm), > HANDLE_FUNC(__pkvm_unreserve_vm), > HANDLE_FUNC(__pkvm_init_vm), > This looks incredibly complicated. Since pKVM forbids late onlining of CPUs, you are absolutely sure that you have already seen the CPU being hot-plugged on. So it would make a lot more sense to just return the current value of the property you are trying to re-evaluate: you know for sure it cannot change under your feet. I have quickly tested the following hack: diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index c31f8e17732a3..947ff71b3b66b 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2345,6 +2345,9 @@ static bool can_trap_icv_dir_el1(const struct arm64_cpu_capabilities *entry, !is_midr_in_range_list(has_vgic_v3)) return false; + if (system_capabilities_finalized() && is_protected_kvm_enabled()) + return cpus_have_final_cap(ARM64_HAS_ICH_HCR_EL2_TDIR); + if (is_kernel_in_hyp_mode()) res.a1 = read_sysreg_s(SYS_ICH_VTR_EL2); else which works for me. Could you please give it a go? Thanks, M. -- Without deviation from the norm, progress is not possible.