ANDROID: KVM: arm64: Introduce a hyp panic module notifier

pKVM modules may need to be notified in case of unexpected same-level
EL2 exceptions, which result in a hyp panic. To do so, introduce a new
notifier on the hyp_panic path.

Bug: 244373730
Change-Id: I144609a933d648ddf2aebcd950e64d6035bf8be3
Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
Quentin Perret
2022-12-23 11:13:28 +00:00
parent 07274b5ec4
commit 7d969932ee
4 changed files with 12 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ struct pkvm_module_ops {
int (*register_default_trap_handler)(bool (*cb)(struct kvm_cpu_context *));
int (*register_illegal_abt_notifier)(void (*cb)(struct kvm_cpu_context *));
int (*register_psci_notifier)(void (*cb)(enum pkvm_psci_notification, struct kvm_cpu_context *));
int (*register_hyp_panic_notifier)(void (*cb)(struct kvm_cpu_context *host_ctxt));
};
struct pkvm_module_section {

View File

@@ -6,6 +6,7 @@
int __pkvm_register_host_smc_handler(bool (*cb)(struct kvm_cpu_context *));
int __pkvm_register_default_trap_handler(bool (*cb)(struct kvm_cpu_context *));
int __pkvm_register_illegal_abt_notifier(void (*cb)(struct kvm_cpu_context *));
int __pkvm_register_hyp_panic_notifier(void (*cb)(struct kvm_cpu_context *));
enum pkvm_psci_notification;
int __pkvm_register_psci_notifier(void (*cb)(enum pkvm_psci_notification, struct kvm_cpu_context *));

View File

@@ -109,6 +109,7 @@ const struct pkvm_module_ops module_ops = {
.register_default_trap_handler = __pkvm_register_default_trap_handler,
.register_illegal_abt_notifier = __pkvm_register_illegal_abt_notifier,
.register_psci_notifier = __pkvm_register_psci_notifier,
.register_hyp_panic_notifier = __pkvm_register_hyp_panic_notifier,
};
int __pkvm_init_module(void *module_init)

View File

@@ -333,6 +333,12 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
return exit_code;
}
static void (*hyp_panic_notifier)(struct kvm_cpu_context *host_ctxt);
int __pkvm_register_hyp_panic_notifier(void (*cb)(struct kvm_cpu_context *host_ctxt))
{
return cmpxchg(&hyp_panic_notifier, NULL, cb) ? -EBUSY : 0;
}
asmlinkage void __noreturn hyp_panic(void)
{
u64 spsr = read_sysreg_el2(SYS_SPSR);
@@ -344,6 +350,9 @@ asmlinkage void __noreturn hyp_panic(void)
host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
vcpu = host_ctxt->__hyp_running_vcpu;
if (READ_ONCE(hyp_panic_notifier))
hyp_panic_notifier(host_ctxt);
if (vcpu) {
__timer_disable_traps(vcpu);
__deactivate_traps(vcpu);