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 A9321CCF9E3 for ; Mon, 10 Nov 2025 11:47:53 +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=FFadn1rzK82qOBkllu8eEKyDMt1yMQyQdxImm7k4Xv0=; b=4XdRNbcabgyVuXrfwMJtse1fuQ 1a/42SG80IjdS/VB9TKE6fKLo/kRIXDHesaBhFPkv2zzny8Hjz/70iADGmoyBF0YYyG4lU+EIfNX1 ZryOU6guQ4vmvLUZkJd4w07Y9LaRXpIqVD4KwxsEEQsqvnYNr2nP64U1ZSswMhLZWcoMJcpAFam+7 l7RN73wcT+p8Q13FL9Oi26qi9xrfAGbnbAct81xh8eDiw8xNcgNoZai9dcT807K9eutQfTcLBoY5V /vYPq1EvgoQYtP0Jt5RaLwSbUo848xSEo2vs6VWmjDeeLdKGcVpUiuQ1GNu5ipks3Su/uZLp+XiMb FdU1iG2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQN8-00000005Lbk-1YkH; Mon, 10 Nov 2025 11:47:46 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQN7-00000005LbY-0N4l for linux-arm-kernel@lists.infradead.org; Mon, 10 Nov 2025 11:47:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 22CB3601A7; Mon, 10 Nov 2025 11:47:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1FEDC19422; Mon, 10 Nov 2025 11:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762775263; bh=99WN30ryzWzH5hzRtlGC+kQjBRsdpDks1HmAmYRDMKA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rcCMBG+VU5HREdfNJgNish0MFJIZMNJB0GFmidQV69QhAQqOZ4lqKFwAPDLb9mAiY Ew6Wn4RUdcGoM6WtLDUdtGNBZVwQJ4fy9PQaj7U3bL6z5JKWqComWBXRmt9533il7O NlfPBLPdzDkucsF6uUXYm50ZpOp80hJdn2Z6RE5CfVob9Ghq5Cb2G6jTDxgI90eV+9 cJdhJa2nmvpOC6BDo1EX75IUo5j+fq1FVuFW71MCaEsNEg508A98DhglHfhOVBq95h sQg5vNRU1fHyAWybkezEUX5uZtVUlYsRjH1m+wrU7eYrk6r4duvg1ZhKvbgERHVzga H4qvzB+ZK9BEw== 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 1vIQN3-00000003qIk-1Cd1; Mon, 10 Nov 2025 11:47:41 +0000 Date: Mon, 10 Nov 2025 11:47:40 +0000 Message-ID: <867bvyun1f.wl-maz@kernel.org> From: Marc Zyngier To: Suzuki K Poulose Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Joey Gouly , Oliver Upton , Zenghui Yu , Christoffer Dall , Volodymyr Babchuk , Yao Yuan Subject: Re: [PATCH v2 04/45] KVM: arm64: Turn vgic-v3 errata traps into a patched-in constant In-Reply-To: References: <20251109171619.1507205-1-maz@kernel.org> <20251109171619.1507205-5-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: suzuki.poulose@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, joey.gouly@arm.com, oupton@kernel.org, yuzenghui@huawei.com, christoffer.dall@arm.com, Volodymyr_Babchuk@epam.com, yaoyuan@linux.alibaba.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, 10 Nov 2025 10:40:21 +0000, Suzuki K Poulose wrote: > > Hi Marc, > > On 09/11/2025 17:15, Marc Zyngier wrote: > > The trap bits are currently only set to manage CPU errata. However, > > we are about to make use of them for purposes beyond beating broken > > CPUs into submission. > > > > For this purpose, turn these errata-driven bits into a patched-in > > constant that is merged with the KVM-driven value at the point of > > programming the ICH_HCR_EL2 register, rather than being directly > > stored with with the shadow value.. > > > > This allows the KVM code to distinguish between a trap being handled > > for the purpose of an erratum workaround, or for KVM's own need. > > > > Signed-off-by: Marc Zyngier > > --- > > ... > > > diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h > > index ac5f9c5d2b980..0ecadfa00397d 100644 > > --- a/arch/arm64/kvm/vgic/vgic.h > > +++ b/arch/arm64/kvm/vgic/vgic.h > > @@ -164,6 +164,22 @@ static inline int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa, > > return ret; > > } > > +void kvm_compute_ich_hcr_trap_bits(struct alt_instr *alt, > > + __le32 *origptr, __le32 *updptr, int nr_inst); > > + > > +static inline u64 vgic_ich_hcr_trap_bits(void) > > +{ > > + u64 hcr; > > minor nit: Do we need a guard to make sure this isn't called before > the capabilities are finalized (given we may use it outside VM > context, e.g. VGIC probe). perhaps : > > WARN_ON(!system_capabilities_finalized()); We already have a BUG_ON() for that at the point of setting up the vectors for pKVM. It wouldn't hurt to move this up as a general check for KVM, but I don't think placing these checks in random leaf functions is very appealing. And if we do, it should be gated to not emit code in the hot path, with something like this (which I find awful): diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h index ec3a61e8e6b30..43f202cb83b48 100644 --- a/arch/arm64/kvm/vgic/vgic.h +++ b/arch/arm64/kvm/vgic/vgic.h @@ -171,6 +171,9 @@ static inline u64 vgic_ich_hcr_trap_bits(void) { u64 hcr; +#if !defined(__KVM_VHE_HYPERVISOR__) && !defined(__KVM_NVHE_HYPERVISOR__) + WARN_ON(!system_capabilities_finalized()); +#endif /* All the traps are in the bottom 16bits */ asm volatile(ALTERNATIVE_CB("movz %0, #0\n", ARM64_ALWAYS_SYSTEM, Thanks, M. -- Without deviation from the norm, progress is not possible.