Skip to content

Commit d48965b

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Do not map the host fpsimd state to hyp in pKVM
pKVM maintains its own state at EL2 for tracking the host fpsimd state. Therefore, no need to map and share the host's view with it. Signed-off-by: Fuad Tabba <tabba@google.com> Reviewed-by: Mark Brown <broonie@kernel.org> Acked-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20240423150538.2103045-12-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent cfbdc54 commit d48965b

3 files changed

Lines changed: 4 additions & 31 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,6 @@ struct kvm_vcpu_arch {
663663
struct kvm_guest_debug_arch vcpu_debug_state;
664664
struct kvm_guest_debug_arch external_debug_state;
665665

666-
struct task_struct *parent_task;
667-
668666
/* VGIC state */
669667
struct vgic_cpu vgic_cpu;
670668
struct arch_timer_cpu timer_cpu;
@@ -1262,7 +1260,6 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu);
12621260
void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu);
12631261
void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu);
12641262
void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu);
1265-
void kvm_vcpu_unshare_task_fp(struct kvm_vcpu *vcpu);
12661263

12671264
static inline bool kvm_pmu_counter_deferred(struct perf_event_attr *attr)
12681265
{

arch/arm64/kvm/fpsimd.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
#include <asm/kvm_mmu.h>
1515
#include <asm/sysreg.h>
1616

17-
void kvm_vcpu_unshare_task_fp(struct kvm_vcpu *vcpu)
18-
{
19-
struct task_struct *p = vcpu->arch.parent_task;
20-
struct user_fpsimd_state *fpsimd;
21-
22-
if (!is_protected_kvm_enabled() || !p)
23-
return;
24-
25-
fpsimd = &p->thread.uw.fpsimd_state;
26-
kvm_unshare_hyp(fpsimd, fpsimd + 1);
27-
put_task_struct(p);
28-
}
29-
3017
/*
3118
* Called on entry to KVM_RUN unless this vcpu previously ran at least
3219
* once and the most recent prior KVM_RUN for this vcpu was called from
@@ -38,28 +25,18 @@ void kvm_vcpu_unshare_task_fp(struct kvm_vcpu *vcpu)
3825
*/
3926
int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu)
4027
{
41-
int ret;
42-
4328
struct user_fpsimd_state *fpsimd = &current->thread.uw.fpsimd_state;
29+
int ret;
4430

45-
kvm_vcpu_unshare_task_fp(vcpu);
31+
/* pKVM has its own tracking of the host fpsimd state. */
32+
if (is_protected_kvm_enabled())
33+
return 0;
4634

4735
/* Make sure the host task fpsimd state is visible to hyp: */
4836
ret = kvm_share_hyp(fpsimd, fpsimd + 1);
4937
if (ret)
5038
return ret;
5139

52-
/*
53-
* We need to keep current's task_struct pinned until its data has been
54-
* unshared with the hypervisor to make sure it is not re-used by the
55-
* kernel and donated to someone else while already shared -- see
56-
* kvm_vcpu_unshare_task_fp() for the matching put_task_struct().
57-
*/
58-
if (is_protected_kvm_enabled()) {
59-
get_task_struct(current);
60-
vcpu->arch.parent_task = current;
61-
}
62-
6340
return 0;
6441
}
6542

arch/arm64/kvm/reset.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu)
151151
{
152152
void *sve_state = vcpu->arch.sve_state;
153153

154-
kvm_vcpu_unshare_task_fp(vcpu);
155154
kvm_unshare_hyp(vcpu, vcpu + 1);
156155
if (sve_state)
157156
kvm_unshare_hyp(sve_state, sve_state + vcpu_sve_state_size(vcpu));

0 commit comments

Comments
 (0)