KVM: arm/arm64: Allow user injection of external data aborts
In some scenarios, such as buggy guest or incorrect configuration of the VMM and firmware description data, userspace will detect a memory access to a portion of the IPA, which is not mapped to any MMIO region. For this purpose, the appropriate action is to inject an external abort to the guest. The kernel already has functionality to inject an external abort, but we need to wire up a signal from user space that lets user space tell the kernel to do this. It turns out, we already have the set event functionality which we can perfectly reuse for this. Signed-off-by: Christoffer Dall <christoffer.dall@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org>
This commit is contained in:
Родитель
c726200dd1
Коммит
da345174ce
|
@ -1002,12 +1002,18 @@ Specifying exception.has_esr on a system that does not support it will return
|
||||||
-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
|
-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
|
||||||
will return -EINVAL.
|
will return -EINVAL.
|
||||||
|
|
||||||
|
It is not possible to read back a pending external abort (injected via
|
||||||
|
KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered
|
||||||
|
directly to the virtual CPU).
|
||||||
|
|
||||||
|
|
||||||
struct kvm_vcpu_events {
|
struct kvm_vcpu_events {
|
||||||
struct {
|
struct {
|
||||||
__u8 serror_pending;
|
__u8 serror_pending;
|
||||||
__u8 serror_has_esr;
|
__u8 serror_has_esr;
|
||||||
|
__u8 ext_dabt_pending;
|
||||||
/* Align it to 8 bytes */
|
/* Align it to 8 bytes */
|
||||||
__u8 pad[6];
|
__u8 pad[5];
|
||||||
__u64 serror_esr;
|
__u64 serror_esr;
|
||||||
} exception;
|
} exception;
|
||||||
__u32 reserved[12];
|
__u32 reserved[12];
|
||||||
|
@ -1051,9 +1057,23 @@ contain a valid state and shall be written into the VCPU.
|
||||||
|
|
||||||
ARM/ARM64:
|
ARM/ARM64:
|
||||||
|
|
||||||
|
User space may need to inject several types of events to the guest.
|
||||||
|
|
||||||
Set the pending SError exception state for this VCPU. It is not possible to
|
Set the pending SError exception state for this VCPU. It is not possible to
|
||||||
'cancel' an Serror that has been made pending.
|
'cancel' an Serror that has been made pending.
|
||||||
|
|
||||||
|
If the guest performed an access to I/O memory which could not be handled by
|
||||||
|
userspace, for example because of missing instruction syndrome decode
|
||||||
|
information or because there is no device mapped at the accessed IPA, then
|
||||||
|
userspace can ask the kernel to inject an external abort using the address
|
||||||
|
from the exiting fault on the VCPU. It is a programming error to set
|
||||||
|
ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or
|
||||||
|
KVM_EXIT_ARM_NISV. This feature is only available if the system supports
|
||||||
|
KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in
|
||||||
|
how userspace reports accesses for the above cases to guests, across different
|
||||||
|
userspace implementations. Nevertheless, userspace can still emulate all Arm
|
||||||
|
exceptions by manipulating individual registers using the KVM_SET_ONE_REG API.
|
||||||
|
|
||||||
See KVM_GET_VCPU_EVENTS for the data structure.
|
See KVM_GET_VCPU_EVENTS for the data structure.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,8 +131,9 @@ struct kvm_vcpu_events {
|
||||||
struct {
|
struct {
|
||||||
__u8 serror_pending;
|
__u8 serror_pending;
|
||||||
__u8 serror_has_esr;
|
__u8 serror_has_esr;
|
||||||
|
__u8 ext_dabt_pending;
|
||||||
/* Align it to 8 bytes */
|
/* Align it to 8 bytes */
|
||||||
__u8 pad[6];
|
__u8 pad[5];
|
||||||
__u64 serror_esr;
|
__u64 serror_esr;
|
||||||
} exception;
|
} exception;
|
||||||
__u32 reserved[12];
|
__u32 reserved[12];
|
||||||
|
|
|
@ -255,6 +255,12 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
|
||||||
{
|
{
|
||||||
events->exception.serror_pending = !!(*vcpu_hcr(vcpu) & HCR_VA);
|
events->exception.serror_pending = !!(*vcpu_hcr(vcpu) & HCR_VA);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We never return a pending ext_dabt here because we deliver it to
|
||||||
|
* the virtual CPU directly when setting the event and it's no longer
|
||||||
|
* 'pending' at this point.
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,12 +269,16 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
|
||||||
{
|
{
|
||||||
bool serror_pending = events->exception.serror_pending;
|
bool serror_pending = events->exception.serror_pending;
|
||||||
bool has_esr = events->exception.serror_has_esr;
|
bool has_esr = events->exception.serror_has_esr;
|
||||||
|
bool ext_dabt_pending = events->exception.ext_dabt_pending;
|
||||||
|
|
||||||
if (serror_pending && has_esr)
|
if (serror_pending && has_esr)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
else if (serror_pending)
|
else if (serror_pending)
|
||||||
kvm_inject_vabt(vcpu);
|
kvm_inject_vabt(vcpu);
|
||||||
|
|
||||||
|
if (ext_dabt_pending)
|
||||||
|
kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,9 @@ struct kvm_vcpu_events {
|
||||||
struct {
|
struct {
|
||||||
__u8 serror_pending;
|
__u8 serror_pending;
|
||||||
__u8 serror_has_esr;
|
__u8 serror_has_esr;
|
||||||
|
__u8 ext_dabt_pending;
|
||||||
/* Align it to 8 bytes */
|
/* Align it to 8 bytes */
|
||||||
__u8 pad[6];
|
__u8 pad[5];
|
||||||
__u64 serror_esr;
|
__u64 serror_esr;
|
||||||
} exception;
|
} exception;
|
||||||
__u32 reserved[12];
|
__u32 reserved[12];
|
||||||
|
|
|
@ -712,6 +712,12 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
|
||||||
if (events->exception.serror_pending && events->exception.serror_has_esr)
|
if (events->exception.serror_pending && events->exception.serror_has_esr)
|
||||||
events->exception.serror_esr = vcpu_get_vsesr(vcpu);
|
events->exception.serror_esr = vcpu_get_vsesr(vcpu);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We never return a pending ext_dabt here because we deliver it to
|
||||||
|
* the virtual CPU directly when setting the event and it's no longer
|
||||||
|
* 'pending' at this point.
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -720,6 +726,7 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
|
||||||
{
|
{
|
||||||
bool serror_pending = events->exception.serror_pending;
|
bool serror_pending = events->exception.serror_pending;
|
||||||
bool has_esr = events->exception.serror_has_esr;
|
bool has_esr = events->exception.serror_has_esr;
|
||||||
|
bool ext_dabt_pending = events->exception.ext_dabt_pending;
|
||||||
|
|
||||||
if (serror_pending && has_esr) {
|
if (serror_pending && has_esr) {
|
||||||
if (!cpus_have_const_cap(ARM64_HAS_RAS_EXTN))
|
if (!cpus_have_const_cap(ARM64_HAS_RAS_EXTN))
|
||||||
|
@ -733,6 +740,9 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
|
||||||
kvm_inject_vabt(vcpu);
|
kvm_inject_vabt(vcpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ext_dabt_pending)
|
||||||
|
kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvm_inject_dabt - inject a data abort into the guest
|
* kvm_inject_dabt - inject a data abort into the guest
|
||||||
* @vcpu: The VCPU to receive the undefined exception
|
* @vcpu: The VCPU to receive the data abort
|
||||||
* @addr: The address to report in the DFAR
|
* @addr: The address to report in the DFAR
|
||||||
*
|
*
|
||||||
* It is assumed that this code is called from the VCPU thread and that the
|
* It is assumed that this code is called from the VCPU thread and that the
|
||||||
|
@ -125,7 +125,7 @@ void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvm_inject_pabt - inject a prefetch abort into the guest
|
* kvm_inject_pabt - inject a prefetch abort into the guest
|
||||||
* @vcpu: The VCPU to receive the undefined exception
|
* @vcpu: The VCPU to receive the prefetch abort
|
||||||
* @addr: The address to report in the DFAR
|
* @addr: The address to report in the DFAR
|
||||||
*
|
*
|
||||||
* It is assumed that this code is called from the VCPU thread and that the
|
* It is assumed that this code is called from the VCPU thread and that the
|
||||||
|
|
|
@ -1007,6 +1007,7 @@ struct kvm_ppc_resize_hpt {
|
||||||
#define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
|
#define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
|
||||||
#define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
|
#define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
|
||||||
#define KVM_CAP_ARM_NISV_TO_USER 176
|
#define KVM_CAP_ARM_NISV_TO_USER 176
|
||||||
|
#define KVM_CAP_ARM_INJECT_EXT_DABT 177
|
||||||
|
|
||||||
#ifdef KVM_CAP_IRQ_ROUTING
|
#ifdef KVM_CAP_IRQ_ROUTING
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
||||||
case KVM_CAP_VCPU_EVENTS:
|
case KVM_CAP_VCPU_EVENTS:
|
||||||
case KVM_CAP_ARM_IRQ_LINE_LAYOUT_2:
|
case KVM_CAP_ARM_IRQ_LINE_LAYOUT_2:
|
||||||
case KVM_CAP_ARM_NISV_TO_USER:
|
case KVM_CAP_ARM_NISV_TO_USER:
|
||||||
|
case KVM_CAP_ARM_INJECT_EXT_DABT:
|
||||||
r = 1;
|
r = 1;
|
||||||
break;
|
break;
|
||||||
case KVM_CAP_ARM_SET_DEVICE_ADDR:
|
case KVM_CAP_ARM_SET_DEVICE_ADDR:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче