Skip to content

Commit 2f2e1a5

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Propagate errors from __pkvm_prot_finalize hypercall
If the __pkvm_prot_finalize hypercall returns an error, we WARN but fail to propagate the failure code back to kvm_arch_init(). Pass a pointer to a zero-initialised return variable so that failure to finalise the pKVM protections on a host CPU can be reported back to KVM. Cc: Marc Zyngier <[email protected]> Cc: Quentin Perret <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8579a18 commit 2f2e1a5

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

arch/arm64/kvm/arm.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,9 +1986,25 @@ static int init_hyp_mode(void)
19861986
return err;
19871987
}
19881988

1989-
static void _kvm_host_prot_finalize(void *discard)
1989+
static void _kvm_host_prot_finalize(void *arg)
19901990
{
1991-
WARN_ON(kvm_call_hyp_nvhe(__pkvm_prot_finalize));
1991+
int *err = arg;
1992+
1993+
if (WARN_ON(kvm_call_hyp_nvhe(__pkvm_prot_finalize)))
1994+
WRITE_ONCE(*err, -EINVAL);
1995+
}
1996+
1997+
static int pkvm_drop_host_privileges(void)
1998+
{
1999+
int ret = 0;
2000+
2001+
/*
2002+
* Flip the static key upfront as that may no longer be possible
2003+
* once the host stage 2 is installed.
2004+
*/
2005+
static_branch_enable(&kvm_protected_mode_initialized);
2006+
on_each_cpu(_kvm_host_prot_finalize, &ret, 1);
2007+
return ret;
19922008
}
19932009

19942010
static int finalize_hyp_mode(void)
@@ -2002,15 +2018,7 @@ static int finalize_hyp_mode(void)
20022018
* None of other sections should ever be introspected.
20032019
*/
20042020
kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
2005-
2006-
/*
2007-
* Flip the static key upfront as that may no longer be possible
2008-
* once the host stage 2 is installed.
2009-
*/
2010-
static_branch_enable(&kvm_protected_mode_initialized);
2011-
on_each_cpu(_kvm_host_prot_finalize, NULL, 1);
2012-
2013-
return 0;
2021+
return pkvm_drop_host_privileges();
20142022
}
20152023

20162024
struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)

0 commit comments

Comments
 (0)