From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72C405683 for ; Mon, 3 Apr 2023 13:50:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1147AC433EF; Mon, 3 Apr 2023 13:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680529835; bh=Ht9h3WhbLO9HMrx4DCT09l+wTpGRwuE7tOuuwn07gwQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cW7Z7zmvAx86ZBk0elBEkhQPuQrXbv1FyPvJe013Rx8WE9TL259fJCzxAJMMBCZRK Noch9MwO2uGj7cEPOlPrYqDnMr0VgaQXBdm4as+EQUMShCXNlc+bcGYGx8GxYJmne+ sNq2qN/8rryvuxN0MsJphTc6fSY1T2pkJEltmSan3UoBP7S65IDmetMPvUr/VDhw1m 7XZsFQmpiUHzBzB76v2C31sZXnDSiEJgrJyT5SFy8NhXwuAOBAH0EGl4cfX8ns7GgR IFllXOLSAKxP+tJljVm/2mnbmKH8LsrfydfjglwERNEsYWVQ6usTXgA5fTtHqOBGIX EdA+gLPKj3lPA== 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.95) (envelope-from ) id 1pjKZs-005Jy4-OK; Mon, 03 Apr 2023 14:50:32 +0100 Date: Mon, 03 Apr 2023 14:50:32 +0100 Message-ID: <86wn2tulav.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, oliver.upton@linux.dev, oupton@google.com, will@kernel.org, pbonzini@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, reijiw@google.com, ricarkol@google.com, rananta@google.com, jingzhangos@google.com Subject: Re: [PATCH v4] KVM: arm64: Advertise ID_AA64PFR0_EL1.CSV2/3 to protected VMs In-Reply-To: <20230403132953.2069621-1-tabba@google.com> References: <20230403132953.2069621-1-tabba@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/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: tabba@google.com, kvmarm@lists.linux.dev, oliver.upton@linux.dev, oupton@google.com, will@kernel.org, pbonzini@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, reijiw@google.com, ricarkol@google.com, rananta@google.com, jingzhangos@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 03 Apr 2023 14:29:53 +0100, Fuad Tabba wrote: > > The existing pKVM code attempts to advertise CSV2/3 using values > initialized to 0, but never set. To advertise CSV2/3 to protected > guests, pass the CSV2/3 values to hyp when initializing hyp's > view of guests' ID_AA64PFR0_EL1. > > Similar to non-protected KVM, these are system-wide, rather than > per cpu, for simplicity. > > Fixes: 6c30bfb18d0b ("KVM: arm64: Add handlers for protected VM System Registers") > Signed-off-by: Fuad Tabba > > --- > > Based on: 197b6b60ae7b (6.3-rc4) > Changes from V3: Fix masking to constrain CSV2/3 to 1 (Oliver). > > arch/arm64/kvm/arm.c | 25 ++++++++++++++++++- > .../arm64/kvm/hyp/include/nvhe/fixed_config.h | 5 +++- > arch/arm64/kvm/hyp/nvhe/sys_regs.c | 7 ------ > 3 files changed, 28 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 3bd732eaf087..04401c2851f8 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1889,9 +1889,32 @@ static int __init do_pkvm_init(u32 hyp_va_bits) > return ret; > } > > +static u64 get_hyp_id_aa64pfr0_el1(void) > +{ > + u64 mask = ~(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV2) | > + ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV3)); > + > + /* > + * Track whether the system isn't affected by spectre/meltown in the > + * hypervisor's view of id_aa64pfr0_el1, used for protected VMs. > + * Although this is per-CPU, we make it global for simplicity, e.g., not > + * to have to worry about vcpu migration. > + * > + * Unlike for non-protected VMs, userspace cannot override this for > + * protected VMs. > + */ > + mask |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV2), > + arm64_get_spectre_v2_state() == SPECTRE_UNAFFECTED); > + > + mask |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV3), > + arm64_get_meltdown_state() == SPECTRE_UNAFFECTED); > + > + return read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1) & mask; I'm confused. PFR0.CSV2 is only set if the HW advertises it. But KVM should advertises it to guests if arm64_get_spectre_v2_state() reports "UNAFFECTED". In that later case, "read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1) & mask" will always leave CSV2 to 0. Same thing for CSV3. I'd expect something like: u64 val = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); val &= ~(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV2) | ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV3)); val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV2), arm64_get_spectre_v2_state() == SPECTRE_UNAFFECTED); val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV3), arm64_get_meltdown_state() == SPECTRE_UNAFFECTED); return val; Or did I read that completely wrong? M. -- Without deviation from the norm, progress is not possible.