linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Quentin Perret <qperret@google.com>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	maz@kernel.org, oliver.upton@linux.dev, james.clark@linaro.org,
	will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com, catalin.marinas@arm.com,
	broonie@kernel.org, kristina.martsenko@arm.com
Subject: Re: [PATCH v4 02/14] KVM: arm64: Group setting traps for protected VMs by control register
Date: Fri, 6 Dec 2024 16:44:19 +0000	[thread overview]
Message-ID: <Z1Mp4zmZRL_8QEmb@google.com> (raw)
In-Reply-To: <20241202154742.3611749-3-tabba@google.com>

On Monday 02 Dec 2024 at 15:47:29 (+0000), Fuad Tabba wrote:
> +static void pvm_init_traps_cptr(struct kvm_vcpu *vcpu)
>  {
> -	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
> -	u64 mdcr_set = 0;
> -	u64 mdcr_clear = 0;
> -	u64 cptr_set = 0;
> +	const u64 id_aa64pfr0 = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR0_EL1);
> +	const u64 id_aa64pfr1 = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR1_EL1);
> +	const u64 id_aa64dfr0 = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
> +	u64 val = vcpu->arch.cptr_el2;
>  
> -	/* Trap/constrain PMU */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), feature_ids)) {
> -		mdcr_set |= MDCR_EL2_TPM | MDCR_EL2_TPMCR;
> -		mdcr_clear |= MDCR_EL2_HPME | MDCR_EL2_MTPME |
> -			      MDCR_EL2_HPMN_MASK;
> +	if (!has_hvhe()) {
> +		val |= CPTR_NVHE_EL2_RES1;
> +		val &= ~(CPTR_NVHE_EL2_RES0);

It's a bit odd to do that at the beginning of the function no? Perhaps
do it last to be sure to overwrite all the changes below?

Also, not sure we need the RES1 part here, kvm_get_reset_cptr_el2()
should have set those for us.

>  	}
>  
> -	/* Trap Debug */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_DebugVer), feature_ids))
> -		mdcr_set |= MDCR_EL2_TDRA | MDCR_EL2_TDA | MDCR_EL2_TDE;
> -
> -	/* Trap OS Double Lock */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_DoubleLock), feature_ids))
> -		mdcr_set |= MDCR_EL2_TDOSA;
> +	/* Trap AMU */
> +	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AMU), id_aa64pfr0))
> +		val |= CPTR_EL2_TAM;
>  
> -	/* Trap SPE */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMSVer), feature_ids)) {
> -		mdcr_set |= MDCR_EL2_TPMS;
> -		mdcr_clear |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT;
> +	/* Trap SVE */
> +	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE), id_aa64pfr0)) {
> +		if (has_hvhe())
> +			val &= ~(CPACR_ELx_ZEN);
> +		else
> +			val |= CPTR_EL2_TZ;
>  	}
>  
> -	/* Trap Trace Filter */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceFilt), feature_ids))
> -		mdcr_set |= MDCR_EL2_TTRF;
> +	/* No SME support in KVM. */
> +	BUG_ON(FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_SME), id_aa64pfr1));
> +	if (has_hvhe())
> +		val &= ~(CPACR_ELx_SMEN);
> +	else
> +		val |= CPTR_EL2_TSM;
>  
>  	/* Trap Trace */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceVer), feature_ids)) {
> +	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceVer), id_aa64dfr0)) {
>  		if (has_hvhe())
> -			cptr_set |= CPACR_EL1_TTA;
> +			val |= CPACR_EL1_TTA;
>  		else
> -			cptr_set |= CPTR_EL2_TTA;
> +			val |= CPTR_EL2_TTA;
>  	}
>  
> -	/* Trap External Trace */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_ExtTrcBuff), feature_ids))
> -		mdcr_clear |= MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT;
> -
> -	vcpu->arch.mdcr_el2 |= mdcr_set;
> -	vcpu->arch.mdcr_el2 &= ~mdcr_clear;
> -	vcpu->arch.cptr_el2 |= cptr_set;
> -}
> -
> -/*
> - * Set trap register values based on features in ID_AA64MMFR0.
> - */
> -static void pvm_init_traps_aa64mmfr0(struct kvm_vcpu *vcpu)
> -{
> -	const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64MMFR0_EL1);
> -	u64 mdcr_set = 0;
> -
> -	/* Trap Debug Communications Channel registers */
> -	if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_FGT), feature_ids))
> -		mdcr_set |= MDCR_EL2_TDCC;
> -
> -	vcpu->arch.mdcr_el2 |= mdcr_set;
> +	vcpu->arch.cptr_el2 = val;
>  }


  reply	other threads:[~2024-12-06 16:46 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 15:47 [PATCH v4 00/14] KVM: arm64: Rework guest VM fixed feature handling and trapping in pKVM Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 01/14] KVM: arm64: Consolidate allowed and restricted VM feature checks Fuad Tabba
2024-12-06 16:12   ` Quentin Perret
2024-12-09  8:03     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 02/14] KVM: arm64: Group setting traps for protected VMs by control register Fuad Tabba
2024-12-06 16:44   ` Quentin Perret [this message]
2024-12-09  8:06     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 03/14] KVM: arm64: Move checking protected vcpu features to a separate function Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 04/14] KVM: arm64: Use KVM extension checks for allowed protected VM capabilities Fuad Tabba
2024-12-06 17:10   ` Quentin Perret
2024-12-09  8:14     ` Fuad Tabba
2024-12-11 13:29       ` Quentin Perret
2024-12-11 13:30         ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 05/14] KVM: arm64: Initialize feature id registers for protected VMs Fuad Tabba
2024-12-06  1:02   ` Oliver Upton
2024-12-06 10:04     ` Fuad Tabba
2024-12-06 17:13   ` Quentin Perret
2024-12-09  8:09     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 06/14] KVM: arm64: Set protected VM traps based on its view of feature registers Fuad Tabba
2024-12-06 17:31   ` Quentin Perret
2024-12-06 17:43     ` Mark Brown
2024-12-06 18:22       ` Marc Zyngier
2024-12-09  8:11         ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 07/14] KVM: arm64: Rework specifying restricted features for protected VMs Fuad Tabba
2024-12-11 12:34   ` Quentin Perret
2024-12-11 13:11     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 08/14] KVM: arm64: Remove fixed_config.h header Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 09/14] KVM: arm64: Remove redundant setting of HCR_EL2 trap bit Fuad Tabba
2024-12-11 12:38   ` Quentin Perret
2024-12-11 12:52     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 10/14] KVM: arm64: Calculate cptr_el2 traps on activating traps Fuad Tabba
2024-12-11 12:46   ` Quentin Perret
2024-12-11 12:55     ` Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 11/14] KVM: arm64: Refactor kvm_reset_cptr_el2() Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 12/14] KVM: arm64: Fix the value of the CPTR_EL2 RES1 bitmask for nVHE Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 13/14] KVM: arm64: Remove PtrAuth guest vcpu flag Fuad Tabba
2024-12-02 15:47 ` [PATCH v4 14/14] KVM: arm64: Convert the SVE guest vcpu flag to a vm flag Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z1Mp4zmZRL_8QEmb@google.com \
    --to=qperret@google.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.clark@linaro.org \
    --cc=joey.gouly@arm.com \
    --cc=kristina.martsenko@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).