All the mail mirrored from 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, 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, smostafa@google.com
Subject: Re: [PATCH v2 01/47] KVM: arm64: Allocate per-cpu memory for the host fpsimd state in pKVM
Date: Tue, 16 Apr 2024 13:54:48 +0100	[thread overview]
Message-ID: <861q75sc13.wl-maz@kernel.org> (raw)
In-Reply-To: <20240416095638.3620345-2-tabba@google.com>

On Tue, 16 Apr 2024 10:55:52 +0100,
Fuad Tabba <tabba@google.com> wrote:
> 
> Allocate a per-cpu fpsimd_state to store the host's state when in
> protected mode. Since the host_fpsimd_state pointer has been
> excluded from kvm_vcpu_arch, no memory has been allocated to
> store it in protected mode, and its value hasn't been set.

Why do we need this? The EL2 already has its own private host state,
which has a full FP state already.

On non-pKVM, we save the host's view directly into the process
state. Obviously, we can't do that with pKVM. But we can absolutely
use the host context for that, and we shouldn't need any extra
allocation.

> Fixes: 51e09b5572d6 ("KVM: arm64: Exclude host_fpsimd_state pointer from kvm_vcpu_arch")
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
>  arch/arm64/kvm/hyp/include/nvhe/pkvm.h |  1 +
>  arch/arm64/kvm/hyp/nvhe/pkvm.c         | 18 ++++++++++++++++++
>  arch/arm64/kvm/hyp/nvhe/setup.c        |  1 +
>  3 files changed, 20 insertions(+)
> 
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
> index 82b3d62538a6..20c3f6e13b99 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
> @@ -54,6 +54,7 @@ pkvm_hyp_vcpu_to_hyp_vm(struct pkvm_hyp_vcpu *hyp_vcpu)
>  }
>  
>  void pkvm_hyp_vm_table_init(void *tbl);
> +void pkvm_host_fpsimd_state_init(void);
>  
>  int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva,
>  		   unsigned long pgd_hva);
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 26dd9a20ad6e..16ccb69e6479 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -18,6 +18,14 @@ unsigned long __icache_flags;
>  /* Used by kvm_get_vttbr(). */
>  unsigned int kvm_arm_vmid_bits;
>  
> +/*
> + * Host FPSIMD state. Written to when the guest accesses its own FPSIMD state,
> + * and read when the guest state is live and we need to switch back to the host.
> + *
> + * Only valid when guest_owns_fp_regs() is true.
> + */
> +DEFINE_PER_CPU(struct user_fpsimd_state, host_fpsimd_state);
> +
>  /*
>   * Set trap register values based on features in ID_AA64PFR0.
>   */
> @@ -247,6 +255,16 @@ void pkvm_hyp_vm_table_init(void *tbl)
>  	vm_table = tbl;
>  }
>  
> +void pkvm_host_fpsimd_state_init(void)
> +{
> +	unsigned long i;
> +
> +	for (i = 0; i < hyp_nr_cpus; i++) {
> +		per_cpu_ptr(&kvm_host_data, i)->fpsimd_state =
> +			per_cpu_ptr(&host_fpsimd_state, i);
> +	}

I'd expect this to be instead:

	for (i = 0; i < hyp_nr_cpus; i++)
		per_cpu_ptr(&kvm_host_data, i)->fpsimd_state = &(per_cpu_ptr(&host_host_data, i)->fp_regs);

and the static allocation to go away.

Thanks,

	M.

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

  parent reply	other threads:[~2024-04-16 12:54 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  9:55 [PATCH v2 00/47] KVM: arm64: Preamble for pKVM Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 01/47] KVM: arm64: Allocate per-cpu memory for the host fpsimd state in pKVM Fuad Tabba
2024-04-16 10:57   ` Mark Brown
2024-04-16 12:54   ` Marc Zyngier [this message]
2024-04-16 13:08     ` Marc Zyngier
2024-04-16 13:10       ` Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 02/47] KVM: arm64: Do not re-initialize the KVM lock Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 03/47] KVM: arm64: Issue CMOs when tearing down guest s2 pages Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 04/47] KVM: arm64: Avoid BUG-ing from the host abort path Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 05/47] KVM: arm64: Fix comment for __pkvm_vcpu_init_traps() Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 06/47] KVM: arm64: Change kvm_handle_mmio_return() return polarity Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 07/47] KVM: arm64: Move setting the page as dirty out of the critical section Fuad Tabba
2024-04-16  9:55 ` [PATCH v2 08/47] KVM: arm64: Check for PTE validity when checking for executable/cacheable Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 09/47] KVM: arm64: Avoid BBM when changing only s/w bits in Stage-2 PTE Fuad Tabba
2024-04-16 16:59   ` Oliver Upton
2024-04-16 18:06     ` Fuad Tabba
2024-04-16 18:19       ` Oliver Upton
2024-04-16  9:56 ` [PATCH v2 10/47] KVM: arm64: Support TLB invalidation in guest context Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 11/47] KVM: arm64: Simplify vgic-v3 hypercalls Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 12/47] KVM: arm64: Add is_pkvm_initialized() helper Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 13/47] KVM: arm64: Introduce predicates to check for protected state Fuad Tabba
2024-04-16 17:18   ` Oliver Upton
2024-04-16 18:07     ` Fuad Tabba
2024-04-16 18:10       ` Oliver Upton
2024-04-16 18:12         ` Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 14/47] KVM: arm64: Split up nvhe/fixed_config.h Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 15/47] KVM: arm64: Move pstate reset value definitions to kvm_arm.h Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 16/47] KVM: arm64: Clarify rationale for ZCR_EL1 value restored on guest exit Fuad Tabba
2024-04-16 10:47   ` Mark Brown
2024-04-16 13:38     ` Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 17/47] KVM: arm64: Refactor calculating SVE state size to use helpers Fuad Tabba
2024-04-16 10:48   ` Mark Brown
2024-04-16  9:56 ` [PATCH v2 18/47] KVM: arm64: Do not map the host fpsimd state to hyp in pKVM Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 19/47] KVM: arm64: Move some kvm_psci functions to a shared header Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 20/47] KVM: arm64: Refactor reset_mpidr() to extract its computation Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 21/47] KVM: arm64: Refactor kvm_vcpu_enable_ptrauth() for hyp use Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 22/47] KVM: arm64: Refactor enter_exception64() Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 23/47] KVM: arm64: Add PC_UPDATE_REQ flags covering all PC updates Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 24/47] KVM: arm64: Add vcpu flag copy primitive Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 25/47] KVM: arm64: Introduce gfn_to_memslot_prot() Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 26/47] KVM: arm64: Do not use the hva in kvm_handle_guest_abort() Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 27/47] KVM: arm64: Introduce hyp_rwlock_t Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 28/47] KVM: arm64: Add atomics-based checking refcount implementation at EL2 Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 29/47] KVM: arm64: Use atomic refcount helpers for 'struct hyp_page::refcount' Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 30/47] KVM: arm64: Remove locking from EL2 allocation fast-paths Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 31/47] KVM: arm64: Reformat/beautify PTP hypercall documentation Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 32/47] KVM: arm64: Rename firmware pseudo-register documentation file Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 33/47] KVM: arm64: Document the KVM/arm64-specific calls in hypercalls.rst Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 34/47] KVM: arm64: Prevent kmemleak from accessing .hyp.data Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 35/47] KVM: arm64: Do not set the virtual timer offset for protected vCPUs Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 36/47] KVM: arm64: Check directly whether a vcpu is protected Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 37/47] KVM: arm64: Trap debug break and watch from guest Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 38/47] KVM: arm64: Restrict protected VM capabilities Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 39/47] KVM: arm64: Do not support MTE for protected VMs Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 40/47] KVM: arm64: Move pkvm_vcpu_init_traps() to hyp vcpu init Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 41/47] KVM: arm64: Fix initializing traps in protected mode Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 42/47] KVM: arm64: Advertise GICv3 sysreg interface to protected guests Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 43/47] KVM: arm64: Force injection of a data abort on NISV MMIO exit Fuad Tabba
2024-04-16  9:56 ` [PATCH v2 44/47] KVM: arm64: Remove unused vcpu parameter from guest_owns_fp_regs() Fuad Tabba
2024-04-16 10:49   ` Mark Brown
2024-04-16  9:56 ` [PATCH v2 45/47] KVM: arm64: Move guest_owns_fp_regs() to enable use in KVM code Fuad Tabba
2024-04-16 10:50   ` Mark Brown
2024-04-16  9:56 ` [PATCH v2 46/47] KVM: arm64: Add host_owns_fp_regs() Fuad Tabba
2024-04-16 10:51   ` Mark Brown
2024-04-16  9:56 ` [PATCH v2 47/47] KVM: arm64: Refactor checks for FP state ownership Fuad Tabba
2024-04-16 10:55   ` Mark Brown
2024-04-16 13:33     ` Marc Zyngier

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=861q75sc13.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=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=smostafa@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    /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.