From patchwork Tue Oct 20 13:36:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 54950 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9KDb34T016616 for ; Tue, 20 Oct 2009 13:37:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752058AbZJTNg5 (ORCPT ); Tue, 20 Oct 2009 09:36:57 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752021AbZJTNg5 (ORCPT ); Tue, 20 Oct 2009 09:36:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41830 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889AbZJTNg4 (ORCPT ); Tue, 20 Oct 2009 09:36:56 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9KDb1J5032358 for ; Tue, 20 Oct 2009 09:37:01 -0400 Received: from localhost.localdomain (vpn-12-215.rdu.redhat.com [10.11.12.215]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9KDaxIw032546; Tue, 20 Oct 2009 09:37:00 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH] v3: use upstream kvm_vcpu_ioctl Date: Tue, 20 Oct 2009 11:36:58 -0200 Message-Id: <1256045818-7115-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/kvm-all.c b/kvm-all.c index 0a8aa4c..50cd1fb 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -863,7 +863,6 @@ int kvm_vm_ioctl(KVMState *s, int type, ...) return ret; } -#ifdef KVM_UPSTREAM int kvm_vcpu_ioctl(CPUState *env, int type, ...) { int ret; @@ -881,8 +880,6 @@ int kvm_vcpu_ioctl(CPUState *env, int type, ...) return ret; } -#endif - int kvm_has_sync_mmu(void) { #ifdef KVM_CAP_SYNC_MMU diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index fb70ede..09e4f8c 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -174,18 +174,11 @@ static int kvm_handle_tpr_access(CPUState *env) int kvm_enable_vapic(CPUState *env, uint64_t vapic) { - int r; struct kvm_vapic_addr va = { .vapic_addr = vapic, }; - r = ioctl(env->kvm_fd, KVM_SET_VAPIC_ADDR, &va); - if (r == -1) { - r = -errno; - perror("kvm_enable_vapic"); - return r; - } - return 0; + return kvm_vcpu_ioctl(env, KVM_SET_VAPIC_ADDR, &va); } #endif @@ -283,28 +276,29 @@ int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_start) int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s) { - int r; + int r = 0; + if (!kvm_irqchip_in_kernel()) - return 0; - r = ioctl(env->kvm_fd, KVM_GET_LAPIC, s); - if (r == -1) { - r = -errno; - perror("kvm_get_lapic"); - } - return r; + return r; + + r = kvm_vcpu_ioctl(env, KVM_GET_LAPIC, s); + if (r < 0) + fprintf(stderr, "KVM_GET_LAPIC failed\n") + return r; } int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s) { - int r; + int r = 0; + if (!kvm_irqchip_in_kernel()) return 0; - r = ioctl(env->kvm_fd, KVM_SET_LAPIC, s); - if (r == -1) { - r = -errno; - perror("kvm_set_lapic"); - } - return r; + + r = kvm_vcpu_ioctl(env, KVM_SET_LAPIC, s); + + if (r < 0) + fprintf(stderr, "KVM_SET_LAPIC failed\n") + return r; } #endif @@ -356,7 +350,6 @@ int kvm_has_pit_state2(kvm_context_t kvm) void kvm_show_code(CPUState *env) { #define SHOW_CODE_LEN 50 - int fd = env->kvm_fd; struct kvm_regs regs; struct kvm_sregs sregs; int r, n; @@ -365,13 +358,13 @@ void kvm_show_code(CPUState *env) char code_str[SHOW_CODE_LEN * 3 + 1]; unsigned long rip; - r = ioctl(fd, KVM_GET_SREGS, &sregs); - if (r == -1) { + r = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); + if (r < 0 ) { perror("KVM_GET_SREGS"); return; } - r = ioctl(fd, KVM_GET_REGS, ®s); - if (r == -1) { + r = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); + if (r < 0) { perror("KVM_GET_REGS"); return; } @@ -420,29 +413,25 @@ struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm) int kvm_get_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n) { struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs); - int r, e; + int r; kmsrs->nmsrs = n; memcpy(kmsrs->entries, msrs, n * sizeof *msrs); - r = ioctl(env->kvm_fd, KVM_GET_MSRS, kmsrs); - e = errno; + r = kvm_vcpu_ioctl(env, KVM_GET_MSRS, kmsrs); memcpy(msrs, kmsrs->entries, n * sizeof *msrs); free(kmsrs); - errno = e; return r; } int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n) { struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs); - int r, e; + int r; kmsrs->nmsrs = n; memcpy(kmsrs->entries, msrs, n * sizeof *msrs); - r = ioctl(env->kvm_fd, KVM_SET_MSRS, kmsrs); - e = errno; + r = kvm_vcpu_ioctl(env, KVM_SET_MSRS, kmsrs); free(kmsrs); - errno = e; return r; } @@ -464,7 +453,7 @@ int kvm_get_mce_cap_supported(kvm_context_t kvm, uint64_t *mce_cap, int kvm_setup_mce(CPUState *env, uint64_t *mcg_cap) { #ifdef KVM_CAP_MCE - return ioctl(env->kvm_fd, KVM_X86_SETUP_MCE, mcg_cap); + return kvm_vcpu_ioctl(env, KVM_X86_SETUP_MCE, mcg_cap); #else return -ENOSYS; #endif @@ -473,7 +462,7 @@ int kvm_setup_mce(CPUState *env, uint64_t *mcg_cap) int kvm_set_mce(CPUState *env, struct kvm_x86_mce *m) { #ifdef KVM_CAP_MCE - return ioctl(env->kvm_fd, KVM_X86_SET_MCE, m); + return kvm_vcpu_ioctl(env, KVM_X86_SET_MCE, m); #else return -ENOSYS; #endif @@ -496,13 +485,12 @@ static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) void kvm_show_regs(CPUState *env) { - int fd = env->kvm_fd; struct kvm_regs regs; struct kvm_sregs sregs; int r; - r = ioctl(fd, KVM_GET_REGS, ®s); - if (r == -1) { + r = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); + if (r < 0) { perror("KVM_GET_REGS"); return; } @@ -517,8 +505,8 @@ void kvm_show_regs(CPUState *env) regs.r8, regs.r9, regs.r10, regs.r11, regs.r12, regs.r13, regs.r14, regs.r15, regs.rip, regs.rflags); - r = ioctl(fd, KVM_GET_SREGS, &sregs); - if (r == -1) { + r = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); + if (r < 0) { perror("KVM_GET_SREGS"); return; } @@ -563,7 +551,7 @@ int kvm_setup_cpuid(CPUState *env, int nent, cpuid->nent = nent; memcpy(cpuid->entries, entries, nent * sizeof(*entries)); - r = ioctl(env->kvm_fd, KVM_SET_CPUID, cpuid); + r = kvm_vcpu_ioctl(env, KVM_SET_CPUID, cpuid); free(cpuid); return r; @@ -579,11 +567,7 @@ int kvm_setup_cpuid2(CPUState *env, int nent, cpuid->nent = nent; memcpy(cpuid->entries, entries, nent * sizeof(*entries)); - r = ioctl(env->kvm_fd, KVM_SET_CPUID2, cpuid); - if (r == -1) { - fprintf(stderr, "kvm_setup_cpuid2: %m\n"); - r = -errno; - } + r = kvm_vcpu_ioctl(env, KVM_SET_CPUID2, cpuid); free(cpuid); return r; } @@ -634,13 +618,7 @@ static int tpr_access_reporting(CPUState *env, int enabled) r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_VAPIC); if (r <= 0) return -ENOSYS; - r = ioctl(env->kvm_fd, KVM_TPR_ACCESS_REPORTING, &tac); - if (r == -1) { - r = -errno; - perror("KVM_TPR_ACCESS_REPORTING"); - return r; - } - return 0; + return kvm_vcpu_ioctl(env, KVM_TPR_ACCESS_REPORTING, &tac); } int kvm_enable_tpr_access_reporting(CPUState *env) diff --git a/qemu-kvm.c b/qemu-kvm.c index b58a457..b8ae4d8 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -816,32 +816,32 @@ static int handle_debug(CPUState *env) int kvm_get_regs(CPUState *env, struct kvm_regs *regs) { - return ioctl(env->kvm_fd, KVM_GET_REGS, regs); + return kvm_vcpu_ioctl(env, KVM_GET_REGS, regs); } int kvm_set_regs(CPUState *env, struct kvm_regs *regs) { - return ioctl(env->kvm_fd, KVM_SET_REGS, regs); + return kvm_vcpu_ioctl(env, KVM_SET_REGS, regs); } int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu) { - return ioctl(env->kvm_fd, KVM_GET_FPU, fpu); + return kvm_vcpu_ioctl(env, KVM_GET_FPU, fpu); } int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu) { - return ioctl(env->kvm_fd, KVM_SET_FPU, fpu); + return kvm_vcpu_ioctl(env, KVM_SET_FPU, fpu); } int kvm_get_sregs(CPUState *env, struct kvm_sregs *sregs) { - return ioctl(env->kvm_fd, KVM_GET_SREGS, sregs); + return kvm_vcpu_ioctl(env, KVM_GET_SREGS, sregs); } int kvm_set_sregs(CPUState *env, struct kvm_sregs *sregs) { - return ioctl(env->kvm_fd, KVM_SET_SREGS, sregs); + return kvm_vcpu_ioctl(env, KVM_SET_SREGS, sregs); } #ifdef KVM_CAP_MP_STATE @@ -851,7 +851,7 @@ int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state) r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_MP_STATE); if (r > 0) - return ioctl(env->kvm_fd, KVM_GET_MP_STATE, mp_state); + return kvm_vcpu_ioctl(env, KVM_GET_MP_STATE, mp_state); return -ENOSYS; } @@ -861,7 +861,7 @@ int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state) r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_MP_STATE); if (r > 0) - return ioctl(env->kvm_fd, KVM_SET_MP_STATE, mp_state); + return kvm_vcpu_ioctl(env, KVM_SET_MP_STATE, mp_state); return -ENOSYS; } #endif @@ -1046,13 +1046,13 @@ int kvm_inject_irq(CPUState *env, unsigned irq) struct kvm_interrupt intr; intr.irq = irq; - return ioctl(env->kvm_fd, KVM_INTERRUPT, &intr); + return kvm_vcpu_ioctl(env, KVM_INTERRUPT, &intr); } #ifdef KVM_CAP_SET_GUEST_DEBUG int kvm_set_guest_debug(CPUState *env, struct kvm_guest_debug *dbg) { - return ioctl(env->kvm_fd, KVM_SET_GUEST_DEBUG, dbg); + return kvm_vcpu_ioctl(env, KVM_SET_GUEST_DEBUG, dbg); } #endif @@ -1062,18 +1062,13 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset) int r; if (!sigset) { - r = ioctl(env->kvm_fd, KVM_SET_SIGNAL_MASK, NULL); - if (r == -1) - r = -errno; - return r; + return kvm_vcpu_ioctl(env, KVM_SET_SIGNAL_MASK, NULL); } sigmask = qemu_malloc(sizeof(*sigmask) + sizeof(*sigset)); sigmask->len = 8; memcpy(sigmask->sigset, sigset, sizeof(*sigset)); - r = ioctl(env->kvm_fd, KVM_SET_SIGNAL_MASK, sigmask); - if (r == -1) - r = -errno; + r = kvm_vcpu_ioctl(env, KVM_SET_SIGNAL_MASK, sigmask); free(sigmask); return r; } @@ -1086,7 +1081,7 @@ int kvm_pit_in_kernel(kvm_context_t kvm) int kvm_inject_nmi(CPUState *env) { #ifdef KVM_CAP_USER_NMI - return ioctl(env->kvm_fd, KVM_NMI); + return kvm_vcpu_ioctl(env, KVM_NMI); #else return -ENOSYS; #endif diff --git a/qemu-kvm.h b/qemu-kvm.h index 525d78d..480129b 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -1168,6 +1168,7 @@ extern KVMState *kvm_state; int kvm_ioctl(KVMState *s, int type, ...); int kvm_vm_ioctl(KVMState *s, int type, ...); +int kvm_vcpu_ioctl(CPUState *env, int type, ...); int kvm_check_extension(KVMState *s, unsigned int ext); #endif