From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: [PATCH] kvm-userspace: Switch to KVM_CAP_USER_NMI Date: Thu, 11 Dec 2008 16:54:57 +0100 Message-ID: <494137D1.30105@siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: Avi Kivity , Hollis Blanchard , "Zhang, Xiantao" To: kvm-devel Return-path: Received: from gecko.sbs.de ([194.138.37.40]:16571 "EHLO gecko.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756151AbYLKP4K (ORCPT ); Thu, 11 Dec 2008 10:56:10 -0500 Sender: kvm-owner@vger.kernel.org List-ID: [Hope I will not cause troubles to other archs this time.] Adopt to new KVM_CAP_USER_NMI interface for injecting NMIs from qemu user space. As this capability is only provided on archs actually requiring it, we can also drop a lot of empty arch stubs. Signed-off-by: Jan Kiszka --- libkvm/libkvm.c | 8 ++++---- libkvm/libkvm.h | 2 ++ qemu/qemu-kvm-ia64.c | 4 ---- qemu/qemu-kvm-powerpc.c | 7 ------- qemu/qemu-kvm-x86.c | 2 ++ qemu/qemu-kvm.c | 9 +++------ user/main-ppc.c | 5 ----- user/main.c | 4 ++++ 8 files changed, 15 insertions(+), 26 deletions(-) diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c index f6ddfde..d4b1a73 100644 --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -832,9 +832,11 @@ int try_push_interrupts(kvm_context_t kvm) return kvm->callbacks->try_push_interrupts(kvm->opaque); } -void push_nmi(kvm_context_t kvm) +static inline void push_nmi(kvm_context_t kvm) { +#ifdef KVM_CAP_USER_NMI kvm->callbacks->push_nmi(kvm->opaque); +#endif /* KVM_CAP_USER_NMI */ } void post_kvm_run(kvm_context_t kvm, void *env) @@ -868,9 +870,7 @@ int kvm_run(kvm_context_t kvm, int vcpu, void *env) struct kvm_run *run = kvm->run[vcpu]; again: -#ifdef KVM_CAP_NMI push_nmi(kvm); -#endif #if !defined(__s390__) if (!kvm->irqchip_in_kernel) run->request_interrupt_window = try_push_interrupts(kvm); @@ -1032,7 +1032,7 @@ int kvm_has_sync_mmu(kvm_context_t kvm) int kvm_inject_nmi(kvm_context_t kvm, int vcpu) { -#ifdef KVM_CAP_NMI +#ifdef KVM_CAP_USER_NMI return ioctl(kvm->vcpu_fd[vcpu], KVM_NMI); #else return -ENOSYS; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h index 963b184..392065b 100644 --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -66,7 +66,9 @@ struct kvm_callbacks { int (*shutdown)(void *opaque, void *env); int (*io_window)(void *opaque); int (*try_push_interrupts)(void *opaque); +#ifdef KVM_CAP_USER_NMI void (*push_nmi)(void *opaque); +#endif void (*post_kvm_run)(void *opaque, void *env); int (*pre_kvm_run)(void *opaque, void *env); int (*tpr_access)(void *opaque, int vcpu, uint64_t rip, int is_write); diff --git a/qemu/qemu-kvm-ia64.c b/qemu/qemu-kvm-ia64.c index a6b17af..8cd3cff 100644 --- a/qemu/qemu-kvm-ia64.c +++ b/qemu/qemu-kvm-ia64.c @@ -57,10 +57,6 @@ int kvm_arch_try_push_interrupts(void *opaque) return 1; } -void kvm_arch_push_nmi(void *opaque) -{ -} - void kvm_arch_update_regs_for_sipi(CPUState *env) { } diff --git a/qemu/qemu-kvm-powerpc.c b/qemu/qemu-kvm-powerpc.c index fa534ed..bded6cb 100644 --- a/qemu/qemu-kvm-powerpc.c +++ b/qemu/qemu-kvm-powerpc.c @@ -188,13 +188,6 @@ int kvm_arch_try_push_interrupts(void *opaque) return 0; } -void kvm_arch_push_nmi(void *opaque) -{ - /* no nmi irq, so discard that call for now and return success. - * This might later get mapped to something on powerpc too if we want - * to support the nmi monitor command somwhow */ -} - void kvm_arch_update_regs_for_sipi(CPUState *env) { printf("%s: no kvm-powerpc multi processor support yet!\n", __func__); diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c index 2e68ace..616c7c6 100644 --- a/qemu/qemu-kvm-x86.c +++ b/qemu/qemu-kvm-x86.c @@ -667,6 +667,7 @@ int kvm_arch_try_push_interrupts(void *opaque) return (env->interrupt_request & CPU_INTERRUPT_HARD) != 0; } +#ifdef KVM_CAP_USER_NMI void kvm_arch_push_nmi(void *opaque) { CPUState *env = cpu_single_env; @@ -680,6 +681,7 @@ void kvm_arch_push_nmi(void *opaque) if (r < 0) printf("cpu %d fail inject NMI\n", env->cpu_index); } +#endif /* KVM_CAP_USER_NMI */ void kvm_arch_update_regs_for_sipi(CPUState *env) { diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c index 067cf03..e95f656 100644 --- a/qemu/qemu-kvm.c +++ b/qemu/qemu-kvm.c @@ -154,11 +154,6 @@ static int try_push_interrupts(void *opaque) return kvm_arch_try_push_interrupts(opaque); } -static void push_nmi(void *opaque) -{ - kvm_arch_push_nmi(opaque); -} - static void post_kvm_run(void *opaque, void *data) { CPUState *env = (CPUState *)data; @@ -742,7 +737,9 @@ static struct kvm_callbacks qemu_kvm_ops = { .shutdown = kvm_shutdown, .io_window = kvm_io_window, .try_push_interrupts = try_push_interrupts, - .push_nmi = push_nmi, +#ifdef KVM_CAP_USER_NMI + .push_nmi = kvm_arch_push_nmi, +#endif .post_kvm_run = post_kvm_run, .pre_kvm_run = pre_kvm_run, #ifdef TARGET_I386 diff --git a/user/main-ppc.c b/user/main-ppc.c index 71afc9e..fed87ed 100644 --- a/user/main-ppc.c +++ b/user/main-ppc.c @@ -90,10 +90,6 @@ static int test_try_push_interrupts(void *opaque) return 0; } -static void test_push_nmi(void *opaque) -{ -} - static void test_post_kvm_run(void *opaque, void *vcpu) { } @@ -182,7 +178,6 @@ static struct kvm_callbacks test_callbacks = { .halt = test_halt, .io_window = test_io_window, .try_push_interrupts = test_try_push_interrupts, - .push_nmi = test_push_nmi, .post_kvm_run = test_post_kvm_run, .pre_kvm_run = test_pre_kvm_run, .powerpc_dcr_read = test_dcr_read, diff --git a/user/main.c b/user/main.c index 55639b5..9ba5b5e 100644 --- a/user/main.c +++ b/user/main.c @@ -323,9 +323,11 @@ static int test_try_push_interrupts(void *opaque) return 0; } +#ifdef KVM_CAP_USER_NMI static void test_push_nmi(void *opaque) { } +#endif static void test_post_kvm_run(void *opaque, void *vcpu) { @@ -373,7 +375,9 @@ static struct kvm_callbacks test_callbacks = { .halt = test_halt, .io_window = test_io_window, .try_push_interrupts = test_try_push_interrupts, +#ifdef KVM_CAP_USER_NMI .push_nmi = test_push_nmi, +#endif .post_kvm_run = test_post_kvm_run, .pre_kvm_run = test_pre_kvm_run, .shutdown = test_shutdown,