ANDROID: KVM: arm64: Allow trap handling from pKVM modules
Introduce a new default trap handler for the host that can be set from modules. Bug: 244543039 Bug: 245034629 Change-Id: Iaabfa44f5f2c41af51f36ed4eec8762e7c951c01 Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
@@ -27,6 +27,7 @@ struct pkvm_module_ops {
|
|||||||
int (*register_host_perm_fault_handler)(int (*cb)(struct kvm_cpu_context *ctxt, u64 esr, u64 addr));
|
int (*register_host_perm_fault_handler)(int (*cb)(struct kvm_cpu_context *ctxt, u64 esr, u64 addr));
|
||||||
int (*protect_host_page)(u64 pfn, enum kvm_pgtable_prot prot);
|
int (*protect_host_page)(u64 pfn, enum kvm_pgtable_prot prot);
|
||||||
int (*register_host_smc_handler)(bool (*cb)(struct kvm_cpu_context *));
|
int (*register_host_smc_handler)(bool (*cb)(struct kvm_cpu_context *));
|
||||||
|
int (*register_default_trap_handler)(bool (*cb)(struct kvm_cpu_context *));
|
||||||
int (*register_illegal_abt_notifier)(void (*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_psci_notifier)(void (*cb)(enum pkvm_psci_notification, struct kvm_cpu_context *));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#define HCALL_UNHANDLED -1
|
#define HCALL_UNHANDLED -1
|
||||||
|
|
||||||
int __pkvm_register_host_smc_handler(bool (*cb)(struct kvm_cpu_context *));
|
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_illegal_abt_notifier(void (*cb)(struct kvm_cpu_context *));
|
||||||
|
|
||||||
enum pkvm_psci_notification;
|
enum pkvm_psci_notification;
|
||||||
|
|||||||
@@ -41,12 +41,18 @@ DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
|
|||||||
void __kvm_hyp_host_forward_smc(struct kvm_cpu_context *host_ctxt);
|
void __kvm_hyp_host_forward_smc(struct kvm_cpu_context *host_ctxt);
|
||||||
|
|
||||||
static bool (*default_host_smc_handler)(struct kvm_cpu_context *host_ctxt);
|
static bool (*default_host_smc_handler)(struct kvm_cpu_context *host_ctxt);
|
||||||
|
static bool (*default_trap_handler)(struct kvm_cpu_context *host_ctxt);
|
||||||
|
|
||||||
int __pkvm_register_host_smc_handler(bool (*cb)(struct kvm_cpu_context *))
|
int __pkvm_register_host_smc_handler(bool (*cb)(struct kvm_cpu_context *))
|
||||||
{
|
{
|
||||||
return cmpxchg(&default_host_smc_handler, NULL, cb) ? -EBUSY : 0;
|
return cmpxchg(&default_host_smc_handler, NULL, cb) ? -EBUSY : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int __pkvm_register_default_trap_handler(bool (*cb)(struct kvm_cpu_context *))
|
||||||
|
{
|
||||||
|
return cmpxchg(&default_trap_handler, NULL, cb) ? -EBUSY : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int pkvm_refill_memcache(struct pkvm_hyp_vcpu *hyp_vcpu)
|
static int pkvm_refill_memcache(struct pkvm_hyp_vcpu *hyp_vcpu)
|
||||||
{
|
{
|
||||||
struct pkvm_hyp_vm *hyp_vm = pkvm_hyp_vcpu_to_hyp_vm(hyp_vcpu);
|
struct pkvm_hyp_vm *hyp_vm = pkvm_hyp_vcpu_to_hyp_vm(hyp_vcpu);
|
||||||
@@ -1326,6 +1332,6 @@ void handle_trap(struct kvm_cpu_context *host_ctxt)
|
|||||||
handle_host_mem_abort(host_ctxt);
|
handle_host_mem_abort(host_ctxt);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BUG();
|
BUG_ON(!READ_ONCE(default_trap_handler) || !default_trap_handler(host_ctxt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ const struct pkvm_module_ops module_ops = {
|
|||||||
.register_host_perm_fault_handler = hyp_register_host_perm_fault_handler,
|
.register_host_perm_fault_handler = hyp_register_host_perm_fault_handler,
|
||||||
.protect_host_page = hyp_protect_host_page,
|
.protect_host_page = hyp_protect_host_page,
|
||||||
.register_host_smc_handler = __pkvm_register_host_smc_handler,
|
.register_host_smc_handler = __pkvm_register_host_smc_handler,
|
||||||
|
.register_default_trap_handler = __pkvm_register_default_trap_handler,
|
||||||
.register_illegal_abt_notifier = __pkvm_register_illegal_abt_notifier,
|
.register_illegal_abt_notifier = __pkvm_register_illegal_abt_notifier,
|
||||||
.register_psci_notifier = __pkvm_register_psci_notifier,
|
.register_psci_notifier = __pkvm_register_psci_notifier,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user