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 A0818FCC9DB for ; Tue, 10 Mar 2026 08:56:59 +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=AApFIcDt3UoW+Q5jyAp9cucE1OW55gEJy8RxBqVJkRM=; b=V7vzuSaG3aOI4u+bcpdk9uA0XO gta7X6GWor6u2bm4ym4LmKYm8rIzJpn2zk/WaELRg3MdRNMdNA3MVLgYpyPON/qacAlX8HIGY0TQp z3JtDRuLaQMLqb5SxDF0CSZALfXABWTI/IoIgIjiuCdGRscB0LMbUAbg8ytrDGiSqCuk/H6X0hY1U HD8bwTBrZQCn3d27m8WGVOz7MFPBg7D5Xf4yaNyD3eNWcOsLPr5XGzMTG/vCXX1ZvnTi/Y25zgSvB GqU8lScrIESFq1BVMOkFgKw3OfvdMoFIob4vWqGvePF+1NLZM2eXJ3h5lLmZnFxU5UMo783GTXI3m c0bvwzwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzsta-000000090kz-3dbZ; Tue, 10 Mar 2026 08:56:54 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzstY-000000090ki-3abr for linux-arm-kernel@lists.infradead.org; Tue, 10 Mar 2026 08:56:52 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id E92BB600B0; Tue, 10 Mar 2026 08:56:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 963C4C19423; Tue, 10 Mar 2026 08:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773133011; bh=j4VJOlhEknG6bMkHk1YimyiS2IexRdXTWAVCoIkrRqw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=npF78254cnnPUrOff1mK5nolouVzLkrHEqRX18KjjjopVS38NODo/rLFd9WoQthEc yaVAqwChnF0eM5NjfwFCDmwd6goHzKnfI2Pr7w/oOGqJBejchc2jqOo5C+H8kIsKgk wASeOAWMvtGwPCBwD5/8xvQJaoQLGNMKtF1qBo/do3dYumXQQT7TAgsOxcOo/puX3G IzhPmrfXuscu2tVvCbnZvhEQ1KXjhGQCGd3DgiaqXZSwzCcY9x8Lyb3zu2AuuCjO6m wh4K2kBshnkjOJVIZcgES5LVerURAb+NSuGFCtu6gVfv7KH9z+hTNuysl6wP+DL5QD k/7FL6pxJEBYw== 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 1vzstV-00000000Lru-1h7v; Tue, 10 Mar 2026 08:56:49 +0000 Date: Tue, 10 Mar 2026 08:56:48 +0000 Message-ID: <86ecls6p0v.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: References: <20260309160450.2610295-1-vdonnefort@google.com> <86h5qo7vr9.wl-maz@kernel.org> 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-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 18:07:45 +0000, Vincent Donnefort wrote: > > [...] > > > > 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? > > That works! I can spin a V2 with that if you want. I've sent what I had written yesterday. Tested-by appreciated! Thanks, M. -- Without deviation from the norm, progress is not possible.