Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 1696fc2

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Consolidate initializing the host data's fpsimd_state/sve in pKVM
Now that we have introduced finalize_init_hyp_mode(), lets consolidate the initializing of the host_data fpsimd_state and sve state. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Fuad Tabba <tabba@google.com> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20240603122852.3923848-8-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent b5b9955 commit 1696fc2

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,14 @@ struct cpu_sve_state {
550550
struct kvm_host_data {
551551
struct kvm_cpu_context host_ctxt;
552552

553-
struct user_fpsimd_state *fpsimd_state; /* hyp VA */
554-
struct cpu_sve_state *sve_state; /* hyp VA */
553+
/*
554+
* All pointers in this union are hyp VA.
555+
* sve_state is only used in pKVM and if system_supports_sve().
556+
*/
557+
union {
558+
struct user_fpsimd_state *fpsimd_state;
559+
struct cpu_sve_state *sve_state;
560+
};
555561

556562
/* Ownership of the FP regs */
557563
enum {

arch/arm64/kvm/arm.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,14 +2444,22 @@ static void finalize_init_hyp_mode(void)
24442444
{
24452445
int cpu;
24462446

2447-
if (!is_protected_kvm_enabled() || !system_supports_sve())
2448-
return;
2447+
if (system_supports_sve() && is_protected_kvm_enabled()) {
2448+
for_each_possible_cpu(cpu) {
2449+
struct cpu_sve_state *sve_state;
24492450

2450-
for_each_possible_cpu(cpu) {
2451-
struct cpu_sve_state *sve_state;
2451+
sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
2452+
per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state =
2453+
kern_hyp_va(sve_state);
2454+
}
2455+
} else {
2456+
for_each_possible_cpu(cpu) {
2457+
struct user_fpsimd_state *fpsimd_state;
24522458

2453-
sve_state = per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state;
2454-
per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->sve_state = kern_hyp_va(sve_state);
2459+
fpsimd_state = &per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->host_ctxt.fp_regs;
2460+
per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)->fpsimd_state =
2461+
kern_hyp_va(fpsimd_state);
2462+
}
24552463
}
24562464
}
24572465

arch/arm64/kvm/hyp/include/nvhe/pkvm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static inline bool pkvm_hyp_vcpu_is_protected(struct pkvm_hyp_vcpu *hyp_vcpu)
5959
}
6060

6161
void pkvm_hyp_vm_table_init(void *tbl);
62-
void pkvm_host_fpsimd_state_init(void);
6362

6463
int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva,
6564
unsigned long pgd_hva);

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,6 @@ void pkvm_hyp_vm_table_init(void *tbl)
249249
vm_table = tbl;
250250
}
251251

252-
void pkvm_host_fpsimd_state_init(void)
253-
{
254-
unsigned long i;
255-
256-
for (i = 0; i < hyp_nr_cpus; i++) {
257-
struct kvm_host_data *host_data = per_cpu_ptr(&kvm_host_data, i);
258-
259-
host_data->fpsimd_state = &host_data->host_ctxt.fp_regs;
260-
}
261-
}
262-
263252
/*
264253
* Return the hyp vm structure corresponding to the handle.
265254
*/

arch/arm64/kvm/hyp/nvhe/setup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void __noreturn __pkvm_init_finalise(void)
324324
goto out;
325325

326326
pkvm_hyp_vm_table_init(vm_table_base);
327-
pkvm_host_fpsimd_state_init();
328327
out:
329328
/*
330329
* We tail-called to here from handle___pkvm_init() and will not return,

0 commit comments

Comments
 (0)