All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	will@kernel.org, qperret@google.com, seanjc@google.com,
	alexandru.elisei@arm.com, catalin.marinas@arm.com,
	philmd@linaro.org, james.morse@arm.com, suzuki.poulose@arm.com,
	oliver.upton@linux.dev, mark.rutland@arm.com, broonie@kernel.org,
	joey.gouly@arm.com, rananta@google.com, yuzenghui@huawei.com
Subject: Re: [PATCH v2 7/7] KVM: arm64: Consolidate initializing the host data's fpsimd_state/sve in pKVM
Date: Tue, 21 May 2024 23:55:55 +0100	[thread overview]
Message-ID: <86msoin5ac.wl-maz@kernel.org> (raw)
In-Reply-To: <20240521163720.3812851-8-tabba@google.com>

On Tue, 21 May 2024 17:37:20 +0100,
Fuad Tabba <tabba@google.com> wrote:
> 
> Now that we have introduced finalize_init_hyp_mode(), lets
> consolidate the initializing of the host_data fpsimd_state and
> sve state.
> 
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
>  arch/arm64/include/asm/kvm_host.h      | 10 ++++++++--
>  arch/arm64/kvm/arm.c                   | 18 ++++++++++++------
>  arch/arm64/kvm/hyp/include/nvhe/pkvm.h |  1 -
>  arch/arm64/kvm/hyp/nvhe/pkvm.c         | 11 -----------
>  arch/arm64/kvm/hyp/nvhe/setup.c        |  1 -
>  5 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index 7b3745ef1d73..8a170f314498 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -536,8 +536,14 @@ struct kvm_cpu_context {
>  struct kvm_host_data {
>  	struct kvm_cpu_context host_ctxt;
>  
> -	struct user_fpsimd_state *fpsimd_state;	/* hyp VA */
> -	struct user_sve_state *sve_state;	/* hyp VA */
> +	/*
> +	 * All pointers in this union are hyp VA.
> +	 * sve_state is only used in pKVM and if system_supports_sve().
> +	 */
> +	union {
> +		struct user_fpsimd_state *fpsimd_state;
> +		struct user_sve_state *sve_state;
> +	};
>  
>  	/* Ownership of the FP regs */
>  	enum {
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index a9b1b0e9c319..a1c7e0ad6951 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -2445,14 +2445,20 @@ static void finalize_init_hyp_mode(void)
>  {
>  	int cpu;
>  
> -	if (!is_protected_kvm_enabled() || !system_supports_sve())
> -		return;
> -
>  	for_each_possible_cpu(cpu) {
> -		struct user_sve_state *sve_state;
> +		if (system_supports_sve() && is_protected_kvm_enabled()) {
> +			struct user_sve_state *sve_state;
>  
> -		sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
> -		per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state = kern_hyp_va(sve_state);
> +			sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
> +			per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state =
> +				kern_hyp_va(sve_state);
> +		} else {
> +			struct user_fpsimd_state *fpsimd_state;
> +
> +			fpsimd_state = &per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->host_ctxt.fp_regs;
> +			per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->fpsimd_state =
> +				kern_hyp_va(fpsimd_state);
> +		}

nit: SVE support and protected state do not change on a per CPU basis,
so checking for these inside the loop is pretty counter intuitive.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	will@kernel.org, qperret@google.com, seanjc@google.com,
	alexandru.elisei@arm.com, catalin.marinas@arm.com,
	philmd@linaro.org, james.morse@arm.com, suzuki.poulose@arm.com,
	oliver.upton@linux.dev, mark.rutland@arm.com, broonie@kernel.org,
	joey.gouly@arm.com, rananta@google.com, yuzenghui@huawei.com
Subject: Re: [PATCH v2 7/7] KVM: arm64: Consolidate initializing the host data's fpsimd_state/sve in pKVM
Date: Tue, 21 May 2024 23:55:55 +0100	[thread overview]
Message-ID: <86msoin5ac.wl-maz@kernel.org> (raw)
In-Reply-To: <20240521163720.3812851-8-tabba@google.com>

On Tue, 21 May 2024 17:37:20 +0100,
Fuad Tabba <tabba@google.com> wrote:
> 
> Now that we have introduced finalize_init_hyp_mode(), lets
> consolidate the initializing of the host_data fpsimd_state and
> sve state.
> 
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
>  arch/arm64/include/asm/kvm_host.h      | 10 ++++++++--
>  arch/arm64/kvm/arm.c                   | 18 ++++++++++++------
>  arch/arm64/kvm/hyp/include/nvhe/pkvm.h |  1 -
>  arch/arm64/kvm/hyp/nvhe/pkvm.c         | 11 -----------
>  arch/arm64/kvm/hyp/nvhe/setup.c        |  1 -
>  5 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index 7b3745ef1d73..8a170f314498 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -536,8 +536,14 @@ struct kvm_cpu_context {
>  struct kvm_host_data {
>  	struct kvm_cpu_context host_ctxt;
>  
> -	struct user_fpsimd_state *fpsimd_state;	/* hyp VA */
> -	struct user_sve_state *sve_state;	/* hyp VA */
> +	/*
> +	 * All pointers in this union are hyp VA.
> +	 * sve_state is only used in pKVM and if system_supports_sve().
> +	 */
> +	union {
> +		struct user_fpsimd_state *fpsimd_state;
> +		struct user_sve_state *sve_state;
> +	};
>  
>  	/* Ownership of the FP regs */
>  	enum {
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index a9b1b0e9c319..a1c7e0ad6951 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -2445,14 +2445,20 @@ static void finalize_init_hyp_mode(void)
>  {
>  	int cpu;
>  
> -	if (!is_protected_kvm_enabled() || !system_supports_sve())
> -		return;
> -
>  	for_each_possible_cpu(cpu) {
> -		struct user_sve_state *sve_state;
> +		if (system_supports_sve() && is_protected_kvm_enabled()) {
> +			struct user_sve_state *sve_state;
>  
> -		sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
> -		per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state = kern_hyp_va(sve_state);
> +			sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
> +			per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state =
> +				kern_hyp_va(sve_state);
> +		} else {
> +			struct user_fpsimd_state *fpsimd_state;
> +
> +			fpsimd_state = &per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->host_ctxt.fp_regs;
> +			per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->fpsimd_state =
> +				kern_hyp_va(fpsimd_state);
> +		}

nit: SVE support and protected state do not change on a per CPU basis,
so checking for these inside the loop is pretty counter intuitive.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-05-21 22:55 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21 16:37 [PATCH v2 0/7] KVM: arm64: Fix handling of host fpsimd/sve state in protected mode Fuad Tabba
2024-05-21 16:37 ` Fuad Tabba
2024-05-21 16:37 ` [PATCH v2 1/7] KVM: arm64: Reintroduce __sve_save_state Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 16:37 ` [PATCH v2 2/7] KVM: arm64: Abstract set/clear of CPTR_EL2 bits behind helper Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 21:08   ` Marc Zyngier
2024-05-21 21:08     ` Marc Zyngier
2024-05-22 13:48     ` Fuad Tabba
2024-05-22 13:48       ` Fuad Tabba
2024-05-28  7:58       ` Marc Zyngier
2024-05-28  7:58         ` Marc Zyngier
2024-05-21 16:37 ` [PATCH v2 3/7] KVM: arm64: Specialize handling of host fpsimd state on trap Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 16:37 ` [PATCH v2 4/7] KVM: arm64: Store the maximum sve vector length at hyp Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 21:21   ` Marc Zyngier
2024-05-21 21:21     ` Marc Zyngier
2024-05-22 14:36     ` Fuad Tabba
2024-05-22 14:36       ` Fuad Tabba
2024-05-21 16:37 ` [PATCH v2 5/7] KVM: arm64: Allocate memory at hyp for host sve state in pKVM Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 21:44   ` Marc Zyngier
2024-05-21 21:44     ` Marc Zyngier
2024-05-22 14:37     ` Fuad Tabba
2024-05-22 14:37       ` Fuad Tabba
2024-05-28  8:16       ` Marc Zyngier
2024-05-28  8:16         ` Marc Zyngier
2024-05-21 16:37 ` [PATCH v2 6/7] KVM: arm64: Eagerly restore host fpsimd/sve " Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 22:52   ` Marc Zyngier
2024-05-21 22:52     ` Marc Zyngier
2024-05-22 14:48     ` Fuad Tabba
2024-05-22 14:48       ` Fuad Tabba
2024-05-28  8:21       ` Marc Zyngier
2024-05-28  8:21         ` Marc Zyngier
2024-05-21 16:37 ` [PATCH v2 7/7] KVM: arm64: Consolidate initializing the host data's fpsimd_state/sve " Fuad Tabba
2024-05-21 16:37   ` Fuad Tabba
2024-05-21 22:55   ` Marc Zyngier [this message]
2024-05-21 22:55     ` Marc Zyngier
2024-05-22 14:49     ` Fuad Tabba
2024-05-22 14:49       ` 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=86msoin5ac.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=alexandru.elisei@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=oliver.upton@linux.dev \
    --cc=philmd@linaro.org \
    --cc=qperret@google.com \
    --cc=rananta@google.com \
    --cc=seanjc@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.