KVM: PPC: Book3S: Don't crash if irqfd used with no in-kernel XICS emulation
Subsystems (3)
PATCH 1/2 KVM: PPC: Book3S: Don't crash if irqfd used with no in-kernel XICS emulation
It turns out that if userspace creates a pseries-type VM without in-kernel XICS (interrupt controller) emulation, and then connects an eventfd to the VM as an irqfd, and the eventfd gets signalled, that the code will try to deliver an interrupt via the non-existent XICS object and crash the host kernel with a NULL pointer dereference.
To fix this, we check for the presence of the XICS object before trying to deliver the interrupt, and return with an error if not.
--- arch/powerpc/kvm/book3s_xics.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kvm/book3s_xics.c +2 -0
@@ -1252,6 +1252,8 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, {struct kvmppc_xics *xics = kvm->arch.xics; +if (!xics) +return -ENODEV ;return ics_deliver_irq (xics, irq, level); }
Signature · 1 line
2.8.1
PATCH 2/2 KVM: PPC: Implement kvm_arch_intc_initialized() for PPC
It doesn't make sense to create irqfds for a VM that doesn't have in-kernel interrupt controller emulation. There is an existing interface for architecture code to tell the irqfd code whether or not any interrupt controller has been initialized, called kvm_arch_intc_initialized(), so let's implement that for powerpc.
--- arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/kvm/powerpc.c | 13 +++++++++++++ 2 files changed, 15 insertions(+)
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -43,6 +43,8 @@#include <asm/cputhreads.h> #define KVM_MAX_VCPU_ID (threads_per_subcore * KVM_MAX_VCORES) +#define __KVM_HAVE_ARCH_INTC_INITIALIZED +#ifdef CONFIG_KVM_MMIO #define KVM_COALESCED_MMIO_PAGE_OFFSET 1#endif
arch/powerpc/kvm/powerpc.c +13 -0
@@ -1167,6 +1167,19 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,return r; } +bool kvm_arch_intc_initialized (struct kvm *kvm) +{ +#ifdef CONFIG_KVM_MPIC +if (kvm->arch.mpic) +return true; +#endif +#ifdef CONFIG_KVM_XICS +if (kvm->arch.xics) +return true; +#endif +return false; +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
Signature · 1 line
2.8.1