Skip to contentSkip to conversation

qemu-kvm: Cleanup and switch to upstream - Part III

PATCH Applied Jan Kiszka 5 participants 16 messages May 20, 2011 – May 26, 2011 KVM

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/10 qemu-kvm: Remove obsolete inclusions

In reply to Jan Kiszka

Reduces the diff to upstream.

---
 cpu-exec.c             |    2 --
 exec.c                 |    1 -
 gdbstub.c              |    1 -
 hw/acpi.c              |    3 ---
 hw/ppc440.c            |    1 -
 hw/ppc440_bamboo.c     |    1 -
 hw/ppce500_mpc8544ds.c |    1 -
 hw/virtio-balloon.c    |    1 -
 target-i386/helper.c   |    1 -
 9 files changed, 0 insertions(+), 12 deletions(-)
cpu-exec.c +0 -2
index 583d7d6..6ec519d 100644
@@ -41,8 +41,6 @@
 #endif
 #endif
 
-#include "qemu-kvm.h"
-
 #if defined(__sparc__) && !defined(CONFIG_SOLARIS)
 // Work around ugly bugs in glibc that mangle global register contents
 #undef env
exec.c +0 -1
index 1dc970f..9a493d0 100644
@@ -32,7 +32,6 @@
 #if !defined(TARGET_IA64)
 #include "tcg.h"
 #endif
-#include "qemu-kvm.h"
 
 #include "hw/hw.h"
 #include "hw/qdev.h"
gdbstub.c +0 -1
index df93691..0838948 100644
@@ -34,7 +34,6 @@
 #include "sysemu.h"
 #include "gdbstub.h"
 #endif
-#include "qemu-kvm.h"
 
 #define MAX_PACKET_LENGTH 4096
 
hw/acpi.c +0 -3
index 3d78d5f..ad40fb4 100644
@@ -19,9 +19,6 @@
 #include "hw.h"
 #include "pc.h"
 #include "acpi.h"
-#include "kvm.h"
-#include "qemu-kvm.h"
-#include "string.h"
 
 struct acpi_table_header
 {
hw/ppc440.c +0 -1
index 7d651e9..1ed001a 100644
@@ -20,7 +20,6 @@
 #include "ppc405.h"
 #include "sysemu.h"
 #include "kvm.h"
-#include "qemu-kvm.h"
 
 #define PPC440EP_PCI_CONFIG     0xeec00000
 #define PPC440EP_PCI_INTACK     0xeed00000
hw/ppc440_bamboo.c +0 -1
index 6627cd8..20b8629 100644
@@ -23,7 +23,6 @@
 #include "device_tree.h"
 #include "loader.h"
 #include "elf.h"
-#include "qemu-kvm.h"
 
 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
hw/ppce500_mpc8544ds.c +0 -1
index 13153dd..17b0165 100644
@@ -32,7 +32,6 @@
 #include "loader.h"
 #include "elf.h"
 #include "sysbus.h"
-#include "qemu-kvm.h"
 
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
 #define UIMAGE_LOAD_BASE           0
hw/virtio-balloon.c +0 -1
index 447b337..70a8710 100644
@@ -20,7 +20,6 @@
 #include "balloon.h"
 #include "virtio-balloon.h"
 #include "kvm.h"
-#include "qemu-kvm.h"
 #include "qlist.h"
 #include "qint.h"
 #include "qstring.h"
target-i386/helper.c +0 -1
index 4ab5241..2315c84 100644
@@ -32,7 +32,6 @@
 #include "monitor.h"
 #endif
 
-#include "qemu-kvm.h"
 #ifndef OBSOLETE_KVM_IMPL
 #define run_on_cpu on_vcpu
 #endif /* !OBSOLETE_KVM_IMPL */
Signature · 1 line
1.7.1

Jan Kiszka

author
#0 lore raw

cover qemu-kvm: Cleanup and switch to upstream - Part III

This is a rather short round as the next and final one cannot be split up very well.

We start with three code cleanup patches, then work towards using upstream kvm_cpu_exec, and finally rework the core's PIO access management used for device assignment.

Please review/merge.

CC Alexander Graf <[email protected]>

Jan Kiszka (10):
qemu-kvm: Remove obsolete inclusions
qemu-kvm: Remove remaining s390 fragments
qemu-kvm: ppc: Drop diff to upstream
qemu-kvm: Refactor vm exit in kvm_run
qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled
qemu-kvm: Activate iothread version of qemu_cpu_kick_self
qemu-kvm: Refactor exit_request processing in kvm_run
qemu-kvm: Use upstream kvm_arch_process_async_events
qemu-kvm: Use upstream kvm_cpu_exec
qemu-kvm: Rework ioport access management

 cpu-defs.h             |    1 -
 cpu-exec.c             |    2 -
 cpus.c                 |    6 +
 exec.c                 |    1 -
 gdbstub.c              |    1 -
 hw/acpi.c              |    3 -
 hw/device-assignment.c |   20 +--
 hw/ppc440.c            |    1 -
 hw/ppc440_bamboo.c     |    1 -
 hw/ppce500_mpc8544ds.c |    1 -
 hw/virtio-balloon.c    |    1 -
 kvm-all.c              |    3 -
 qemu-kvm-x86.c         |  158 +--------------------
 qemu-kvm.c             |  359 ++++++++++++-----------------------------------
 qemu-kvm.h             |   77 +----------
 target-i386/helper.c   |    1 -
 target-i386/kvm.c      |    4 -
 target-ppc/cpu.h       |   10 +--
 target-ppc/fake-exec.c |  104 --------------
 target-ppc/helper.c    |    1 -
 target-ppc/machine.c   |    1 -
 21 files changed, 121 insertions(+), 635 deletions(-)
 delete mode 100644 target-ppc/fake-exec.c
author
#4 lore raw

PATCH 4/10 qemu-kvm: Refactor vm exit in kvm_run

Use kvm_vcpu_ioctl to simplify the vm exit code a bit. This increases the similarity to upstream.

---
 qemu-kvm.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)
qemu-kvm.c +7 -10
index 19ede6e..e5b8e42 100644
@@ -299,7 +299,6 @@ static int kvm_run(CPUState *env)
 {
     int r;
     struct kvm_run *run = env->kvm_run;
-    int fd = env->kvm_fd;
 
   again:
     if (env->kvm_vcpu_dirty) {
@@ -319,22 +318,20 @@ static int kvm_run(CPUState *env)
         env->exit_request = 0;
         pthread_kill(env->thread->thread, SIG_IPI);
     }
-    r = ioctl(fd, KVM_RUN, 0);
-
-    if (r == -1 && errno != EINTR && errno != EAGAIN) {
-        r = -errno;
-        post_kvm_run(env);
-        fprintf(stderr, "kvm_run: %s\n", strerror(-r));
-        return r;
-    }
+    r = kvm_vcpu_ioctl(env, KVM_RUN, 0);
 
     post_kvm_run(env);
 
     kvm_flush_coalesced_mmio_buffer();
 
-    if (r == -1) {
+    if (r == -EINTR || r == -EAGAIN) {
         return 1;
     }
+    if (r < 0) {
+        fprintf(stderr, "kvm_run: %s\n", strerror(-r));
+        return r;
+    }
+
     if (1) {
         switch (run->exit_reason) {
         case KVM_EXIT_UNKNOWN:
Signature · 1 line
1.7.1
author
#6 lore raw

PATCH 6/10 qemu-kvm: Activate iothread version of qemu_cpu_kick_self

In reply to Jan Kiszka

This is a temporary hack: We will soon use this service for kvm which is running in iothread mode - but with CONFIG_IOTHREAD disabled.

---
 cpus.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
cpus.c +6 -0
index 5d1c396..b64c29f 100644
@@ -590,6 +590,7 @@ void qemu_cpu_kick(void *env)
 {
 }
 
+#ifdef UNUSED_IMPL
 void qemu_cpu_kick_self(void)
 {
 #ifndef _WIN32
@@ -600,6 +601,7 @@ void qemu_cpu_kick_self(void)
     abort();
 #endif
 }
+#endif
 
 void qemu_notify_event(void)
 {
@@ -848,6 +850,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
     return NULL;
 }
 
+#endif
 static void qemu_cpu_kick_thread(CPUState *env)
 {
 #ifndef _WIN32
@@ -866,6 +869,7 @@ static void qemu_cpu_kick_thread(CPUState *env)
     }
 #endif
 }
+#ifdef CONFIG_IOTHREAD
 
 void qemu_cpu_kick(void *_env)
 {
@@ -878,6 +882,7 @@ void qemu_cpu_kick(void *_env)
     }
 }
 
+#endif
 void qemu_cpu_kick_self(void)
 {
 #ifndef _WIN32
@@ -891,6 +896,7 @@ void qemu_cpu_kick_self(void)
     abort();
 #endif
 }
+#ifdef CONFIG_IOTHREAD
 
 int qemu_cpu_is_self(void *_env)
 {
Signature · 1 line
1.7.1
author
#7 lore raw

PATCH 7/10 qemu-kvm: Refactor exit_request processing in kvm_run

In reply to Jan Kiszka

Move closer to upstream by reusing its self-signaling service in kvm_run, maintain cpu_single_env the same way, push this under qemu_mutex, and clear exit_request unconditionally when leaving kvm_run.

---
 qemu-kvm.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
qemu-kvm.c +14 -11
index 843c973..24c667c 100644
@@ -278,16 +278,21 @@ static inline void push_nmi(void)
 static void post_kvm_run(CPUState *env)
 {
     pthread_mutex_lock(&qemu_mutex);
-    kvm_arch_post_run(env, env->kvm_run);
     cpu_single_env = env;
+
+    kvm_arch_post_run(env, env->kvm_run);
 }
 
-static int pre_kvm_run(CPUState *env)
+static void pre_kvm_run(CPUState *env)
 {
     kvm_arch_pre_run(env, env->kvm_run);
 
+    if (env->exit_request) {
+        qemu_cpu_kick_self();
+    }
+
+    cpu_single_env = NULL;
     pthread_mutex_unlock(&qemu_mutex);
-    return 0;
 }
 
 int kvm_is_ready_for_interrupt_injection(CPUState *env)
@@ -300,6 +305,8 @@ static int kvm_run(CPUState *env)
     int r;
     struct kvm_run *run = env->kvm_run;
 
+    cpu_single_env = env;
+
   again:
     if (env->kvm_vcpu_dirty) {
         kvm_arch_put_registers(env, KVM_PUT_RUNTIME_STATE);
@@ -310,14 +317,8 @@ static int kvm_run(CPUState *env)
         run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
     }
 
-    r = pre_kvm_run(env);
-    if (r) {
-        return r;
-    }
-    if (env->exit_request) {
-        env->exit_request = 0;
-        pthread_kill(env->thread->thread, SIG_IPI);
-    }
+    pre_kvm_run(env);
+
     r = kvm_vcpu_ioctl(env, KVM_RUN, 0);
 
     post_kvm_run(env);
@@ -325,6 +326,7 @@ static int kvm_run(CPUState *env)
     kvm_flush_coalesced_mmio_buffer();
 
     if (r == -EINTR || r == -EAGAIN) {
+        env->exit_request = 0;
         return 1;
     }
     if (r < 0) {
@@ -384,6 +386,7 @@ static int kvm_run(CPUState *env)
     if (!r) {
         goto again;
     }
+    env->exit_request = 0;
     return r;
 }
 
Signature · 1 line
1.7.1
author
#8 lore raw

PATCH 8/10 qemu-kvm: Use upstream kvm_arch_process_async_events

In reply to Jan Kiszka

Upstream's kvm_arch_process_async_events is now identical to qemu-kvm's combination of kvm_arch_process_async_events and process_irqchip_events.

---
 qemu-kvm-x86.c    |   49 -------------------------------------------------
 qemu-kvm.c        |   13 +------------
 qemu-kvm.h        |    2 --
 target-i386/kvm.c |    2 --
 4 files changed, 1 insertions(+), 65 deletions(-)
qemu-kvm-x86.c +0 -49
index b009251..18f7c3a 100644
@@ -225,16 +225,6 @@ void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
     }
 }
 
-int kvm_arch_has_work(CPUState *env)
-{
-    if (((env->interrupt_request & CPU_INTERRUPT_HARD) &&
-         (env->eflags & IF_MASK)) ||
-        (env->interrupt_request & CPU_INTERRUPT_NMI)) {
-        return 1;
-    }
-    return 0;
-}
-
 int kvm_arch_try_push_interrupts(void *opaque)
 {
     CPUState *env = cpu_single_env;
@@ -331,42 +321,3 @@ int kvm_arch_init_irq_routing(void)
 
     return 0;
 }
-
-void kvm_arch_process_irqchip_events(CPUState *env)
-{
-    if (env->interrupt_request & CPU_INTERRUPT_INIT) {
-        kvm_cpu_synchronize_state(env);
-        do_cpu_init(env);
-    }
-    if (env->interrupt_request & CPU_INTERRUPT_SIPI) {
-        kvm_cpu_synchronize_state(env);
-        do_cpu_sipi(env);
-    }
-}
-
-int kvm_arch_process_async_events(CPUState *env)
-{
-    if (env->interrupt_request & CPU_INTERRUPT_MCE) {
-        /* We must not raise CPU_INTERRUPT_MCE if it's not supported. */
-        assert(env->mcg_cap);
-
-        env->interrupt_request &= ~CPU_INTERRUPT_MCE;
-
-        kvm_cpu_synchronize_state(env);
-
-        if (env->exception_injected == EXCP08_DBLE) {
-            /* this means triple fault */
-            qemu_system_reset_request();
-            env->exit_request = 1;
-            return 0;
-        }
-        env->exception_injected = EXCP12_MCHK;
-        env->has_error_code = 0;
-
-        env->halted = 0;
-        if (kvm_irqchip_in_kernel() && env->mp_state == KVM_MP_STATE_HALTED) {
-            env->mp_state = KVM_MP_STATE_RUNNABLE;
-        }
-    }
-    return 0;
-}
qemu-kvm.c +1 -12
index 24c667c..41c4219 100644
@@ -1032,23 +1032,12 @@ static void qemu_kvm_system_reset(void)
     resume_all_threads();
 }
 
-static void process_irqchip_events(CPUState *env)
-{
-    kvm_arch_process_irqchip_events(env);
-    if (kvm_arch_has_work(env))
-        env->halted = 0;
-}
-
 static int kvm_main_loop_cpu(CPUState *env)
 {
     while (1) {
         int run_cpu = !kvm_cpu_is_stopped(env);
         if (run_cpu) {
-            kvm_arch_process_async_events(env);
-            if (!kvm_irqchip_in_kernel()) {
-                process_irqchip_events(env);
-                run_cpu = !env->halted;
-            }
+            run_cpu = !kvm_arch_process_async_events(env);
         }
         if (run_cpu) {
             kvm_cpu_exec(env);
qemu-kvm.h +0 -2
index 8ff773a..5621cfa 100644
@@ -314,8 +314,6 @@ void kvm_hpet_disable_kpit(void);
 void on_vcpu(CPUState *env, void (*func)(void *data), void *data);
 void kvm_update_interrupt_request(CPUState *env);
 
-int kvm_arch_has_work(CPUState *env);
-void kvm_arch_process_irqchip_events(CPUState *env);
 int kvm_arch_try_push_interrupts(void *opaque);
 void kvm_arch_push_nmi(void);
 int kvm_set_boot_cpu_id(KVMState *s, uint32_t id);
target-i386/kvm.c +0 -2
index a4365bf..e98eccf 100644
@@ -1636,7 +1636,6 @@ void kvm_arch_post_run(CPUState *env, struct kvm_run *run)
     cpu_set_apic_base(env->apic_state, run->apic_base);
 }
 
-#ifdef OBSOLETE_KVM_IMPL
 int kvm_arch_process_async_events(CPUState *env)
 {
     if (env->interrupt_request & CPU_INTERRUPT_MCE) {
@@ -1682,7 +1681,6 @@ int kvm_arch_process_async_events(CPUState *env)
 
     return env->halted;
 }
-#endif
 
 static int kvm_handle_halt(CPUState *env)
 {
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH 2/10 qemu-kvm: Remove remaining s390 fragments

In reply to Jan Kiszka

qemu-kvm is not used with s390, only upstream works theses days. So remove any conditionals related to this arch.

---
 qemu-kvm.c |   12 ------------
 qemu-kvm.h |   10 +---------
 2 files changed, 1 insertions(+), 21 deletions(-)
qemu-kvm.c +0 -12
index c9ff5fe..19ede6e 100644
@@ -307,11 +307,9 @@ static int kvm_run(CPUState *env)
         env->kvm_vcpu_dirty = 0;
     }
     push_nmi();
-#if !defined(__s390__)
     if (!kvm_state->irqchip_in_kernel) {
         run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
     }
-#endif
 
     r = pre_kvm_run(env);
     if (r) {
@@ -334,11 +332,9 @@ static int kvm_run(CPUState *env)
 
     kvm_flush_coalesced_mmio_buffer();
 
-#if !defined(__s390__)
     if (r == -1) {
         return 1;
     }
-#endif
     if (1) {
         switch (run->exit_reason) {
         case KVM_EXIT_UNKNOWN:
@@ -372,14 +368,6 @@ static int kvm_run(CPUState *env)
         case KVM_EXIT_SHUTDOWN:
             r = handle_shutdown(env);
             break;
-#if defined(__s390__)
-        case KVM_EXIT_S390_SIEIC:
-            r = kvm_s390_handle_intercept(kvm, env, run);
-            break;
-        case KVM_EXIT_S390_RESET:
-            r = kvm_s390_handle_reset(kvm, env, run);
-            break;
-#endif
 	case KVM_EXIT_INTERNAL_ERROR:
             r = kvm_handle_internal_error(env, run);
 	    break;
qemu-kvm.h +1 -9
index b552e1e..8ff773a 100644
@@ -15,10 +15,6 @@
 
 #ifdef CONFIG_KVM
 
-#if defined(__s390__)
-#include <asm/ptrace.h>
-#endif
-
 #include <stdint.h>
 
 #ifndef __user
@@ -31,11 +27,7 @@
 
 /* FIXME: share this number with kvm */
 /* FIXME: or dynamically alloc/realloc regions */
-#ifdef __s390__
-#define KVM_MAX_NUM_MEM_REGIONS 1u
-#define MAX_VCPUS 64
-#define LIBKVM_S390_ORIGIN (0UL)
-#elif defined(__ia64__)
+#if defined(__ia64__)
 #define KVM_MAX_NUM_MEM_REGIONS 32u
 #define MAX_VCPUS 256
 #else
Signature · 1 line
1.7.1
author
#5 lore raw

PATCH 5/10 qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled

In reply to Jan Kiszka

Another step forward to use signaling services from cpus.c.

---
 cpu-defs.h |    1 -
 qemu-kvm.c |    6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)
cpu-defs.h +0 -1
index 624fd1a..5a0f11d 100644
@@ -158,7 +158,6 @@ typedef struct CPUWatchpoint {
 struct qemu_work_item;
 
 struct KVMCPUState {
-    int signalled;
     struct qemu_work_item *queued_work_first, *queued_work_last;
 };
 
qemu-kvm.c +3 -3
index e5b8e42..843c973 100644
@@ -840,12 +840,12 @@ void kvm_update_interrupt_request(CPUState *env)
          * Testing for created here is really redundant
          */
         if (current_env && current_env->created &&
-            env != current_env && !env->kvm_cpu_state.signalled) {
+            env != current_env && !env->thread_kicked) {
             signal = 1;
         }
 
         if (signal) {
-            env->kvm_cpu_state.signalled = 1;
+            env->thread_kicked = true;
             if (env->thread) {
                 pthread_kill(env->thread->thread, SIG_IPI);
             }
@@ -941,7 +941,7 @@ static void kvm_main_loop_wait(CPUState *env, int timeout)
         pthread_cond_signal(&qemu_pause_cond);
     }
 
-    env->kvm_cpu_state.signalled = 0;
+    env->thread_kicked = false;
 }
 
 static int all_threads_paused(void)
Signature · 1 line
1.7.1
author
#12 lore raw

PATCH 10/10 qemu-kvm: Rework ioport access management

In reply to Jan Kiszka

Clean up the interface for enabling/disabling direct ioport access for assigned devices. There is now only a register and a deregister service. Both are automatically updating the access on all vcpus. Besides that, there is an update service for newly created VCPUs that applies all currently registered regions.

---
 hw/device-assignment.c |   20 +++------
 qemu-kvm-x86.c         |   12 ++++--
 qemu-kvm.c             |  107 ++++++++++++++++++++++++++++++++++--------------
 qemu-kvm.h             |   21 ++-------
 4 files changed, 96 insertions(+), 64 deletions(-)
hw/device-assignment.c +7 -13
index abc38f8..57d8dc0 100644
@@ -298,7 +298,7 @@ static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num,
     AssignedDevice *r_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
     AssignedDevRegion *region = &r_dev->v_addrs[region_num];
     int first_map = (region->e_size == 0);
-    CPUState *env;
+    int r;
 
     region->e_physbase = addr;
     region->e_size = size;
@@ -307,17 +307,11 @@ static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num,
           addr, region->u.r_baseport, type, size, region_num);
 
     if (first_map && region->region->resource_fd < 0) {
-	struct ioperm_data *data;
-
-	data = qemu_mallocz(sizeof(struct ioperm_data));
-	data->start_port = region->u.r_baseport;
-	data->num = region->r_size;
-	data->turn_on = 1;
-
-	kvm_add_ioperm_data(data);
-
-	for (env = first_cpu; env; env = env->next_cpu)
-	    kvm_ioperm(env, data);
+        r = kvm_add_ioport_region(region->u.r_baseport, region->r_size);
+        if (r < 0) {
+            fprintf(stderr, "%s: failed to enable ioport access (%m)\n",
+                    __func__);
+        }
     }
 
     register_ioport_read(addr, size, 1, assigned_dev_ioport_readb,
@@ -832,7 +826,7 @@ static void free_assigned_device(AssignedDevice *dev)
         }
         if (pci_region->type & IORESOURCE_IO) {
             if (pci_region->resource_fd < 0) {
-                kvm_remove_ioperm_data(region->u.r_baseport, region->r_size);
+                kvm_remove_ioport_region(region->u.r_baseport, region->r_size);
             }
         } else if (pci_region->type & IORESOURCE_MEM) {
             if (region->u.r_virtbase) {
qemu-kvm-x86.c +8 -4
index 89bb692..2a01ccc 100644
@@ -164,14 +164,18 @@ static int _kvm_arch_init_vcpu(CPUState *env)
 #ifdef KVM_EXIT_TPR_ACCESS
     kvm_enable_tpr_access_reporting(env);
 #endif
-    return 0;
+
+    return kvm_update_ioport_access(env);
 }
 
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-void kvm_arch_do_ioperm(void *_data)
+int kvm_arch_set_ioport_access(unsigned long start, unsigned long size,
+                               bool enable)
 {
-    struct ioperm_data *data = _data;
-    ioperm(data->start_port, data->num, data->turn_on);
+    if (ioperm(start, size, enable) < 0) {
+        return -errno;
+    }
+    return 0;
 }
 #endif
 
qemu-kvm.c +76 -31

142 lines not on this page · raw message

qemu-kvm.h +5 -16
index 57dc6aa..094aef2 100644
@@ -282,31 +282,20 @@ void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
 
 int kvm_arch_init_irq_routing(void);
 
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-struct ioperm_data;
+int kvm_add_ioport_region(unsigned long start, unsigned long size);
+int kvm_remove_ioport_region(unsigned long start, unsigned long size);
 
-void kvm_ioperm(CPUState *env, void *data);
-void kvm_add_ioperm_data(struct ioperm_data *data);
-void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
-void kvm_arch_do_ioperm(void *_data);
-#endif
+int kvm_update_ioport_access(CPUState *env);
+int kvm_arch_set_ioport_access(unsigned long start, unsigned long size,
+                               bool enable);
 
 #ifdef CONFIG_KVM
-#include "qemu-queue.h"
-
 extern int kvm_irqchip;
 extern int kvm_pit;
 extern int kvm_pit_reinject;
 extern int kvm_nested;
 extern unsigned int kvm_shadow_memory;
 
-struct ioperm_data {
-    unsigned long start_port;
-    unsigned long num;
-    int turn_on;
-    QLIST_ENTRY(ioperm_data) entries;
-};
-
 int kvm_handle_tpr_access(CPUState *env);
 
 #else
Signature · 1 line
1.7.1
author
#3 lore raw

PATCH 3/10 qemu-kvm: ppc: Drop diff to upstream

In reply to Jan Kiszka

qemu-kvm is x86-only today. Remove the remaining delta of the former ppc support to avoid needless conflicts when sync'ing with upstream.

CC Alexander Graf <[email protected]>
---
 target-ppc/cpu.h       |   10 +----
 target-ppc/fake-exec.c |  104 ------------------------------------------------
 target-ppc/helper.c    |    1 -
 target-ppc/machine.c   |    1 -
 4 files changed, 1 insertions(+), 115 deletions(-)
 delete mode 100644 target-ppc/fake-exec.c
target-ppc/cpu.h +1 -9
index 133df95..7a6a7df 100644
@@ -52,10 +52,9 @@
 #if defined(TARGET_PPCEMB)
 /* Specific definitions for PowerPC embedded */
 /* BookE have 36 bits physical address space */
-#if defined(CONFIG_USER_ONLY) || defined(USE_KVM)
+#if defined(CONFIG_USER_ONLY)
 /* It looks like a lot of Linux programs assume page size
  * is 4kB long. This is evil, but we have to deal with it...
- * Also kvm for embedded powerpc needs (atm) 4kB aligned pages
  */
 #define TARGET_PAGE_BITS 12
 #else /* defined(CONFIG_USER_ONLY) */
@@ -1927,13 +1926,6 @@ static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
 #endif
 }
 
-/* hidden flags (hflags) - used internally by qemu to represent additional
- * cpu states.
- */
-#define HF_HALTED_SHIFT 1
-
-#define HF_HALTED_MASK 1<<HF_HALTED_SHIFT
-
 #if !defined(CONFIG_USER_ONLY)
 static inline int booke206_tlbe_id(CPUState *env, ppcemb_tlb_t *tlbe)
 {
target-ppc/fake-exec.c deleted +0 -104

104 lines not on this page · raw message

target-ppc/helper.c +0 -1
index 95f81ec..4238be6 100644
@@ -28,7 +28,6 @@
 #include "helper_regs.h"
 #include "qemu-common.h"
 #include "kvm.h"
-#include "qemu-kvm.h"
 
 //#define DEBUG_MMU
 //#define DEBUG_BATS
target-ppc/machine.c +0 -1
index 4b98113..0c1986e 100644
@@ -1,7 +1,6 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "kvm.h"
-#include "qemu-kvm.h"
 
 void cpu_save(QEMUFile *f, void *opaque)
 {
Signature · 1 line
1.7.1
author
#9 lore raw

PATCH 9/10 qemu-kvm: Use upstream kvm_cpu_exec

In reply to Jan Kiszka

Upstream's and qemu-kvm's kvm_cpu_exec are not logically equivalent so that we can safely switch the implementations.

A bit refactoring of kvm_main_loop_cpu is required as upstream's cpu loop already contains the asynchronous event processing which ran outside so far.

---
 kvm-all.c         |    3 -
 qemu-kvm-x86.c    |  101 +-----------------------
 qemu-kvm.c        |  225 ++++-------------------------------------------------
 qemu-kvm.h        |   44 +----------
 target-i386/kvm.c |    2 -
 5 files changed, 17 insertions(+), 358 deletions(-)
kvm-all.c +0 -3
index 5ac177f..88d0785 100644
@@ -958,8 +958,6 @@ void kvm_cpu_synchronize_post_init(CPUState *env)
     env->kvm_vcpu_dirty = 0;
 }
 
-#ifdef OBSOLETE_KVM_IMPL
-
 int kvm_cpu_exec(CPUState *env)
 {
     struct kvm_run *run = env->kvm_run;
@@ -1065,7 +1063,6 @@ int kvm_cpu_exec(CPUState *env)
     return ret;
 }
 
-#endif
 int kvm_ioctl(KVMState *s, int type, ...)
 {
     int ret;
qemu-kvm-x86.c +2 -99

130 lines not on this page · raw message

qemu-kvm.c +14 -211

250 lines not on this page · raw message

qemu-kvm.h +1 -43

70 lines not on this page · raw message

target-i386/kvm.c +0 -2
index e98eccf..bccd87c 100644
@@ -1565,7 +1565,6 @@ int kvm_arch_get_registers(CPUState *env)
     return 0;
 }
 
-#ifdef OBSOLETE_KVM_IMPL
 void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {
     int ret;
@@ -1623,7 +1622,6 @@ void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
         run->cr8 = cpu_get_apic_tpr(env->apic_state);
     }
 }
-#endif
 
 void kvm_arch_post_run(CPUState *env, struct kvm_run *run)
 {
Signature · 1 line
1.7.1
#13 lore raw
In reply to Jan Kiszka
Quoted 8 lines · Jan Kiszka

This is a rather short round as the next and final one cannot be split up very well.

We start with three code cleanup patches, then work towards using upstream kvm_cpu_exec, and finally rework the core's PIO access management used for device assignment.

Please review/merge.

So with this set applied, s390 and ppc targets should work in qemu-kvm.git?

Alex

author
#14 lore raw
Quoted 6 lines · Alexander Graf
Quoted 3 lines · Jan Kiszka

This is a rather short round as the next and final one cannot be split up very well.

Quoted 7 lines
Quoted 5 lines

We start with three code cleanup patches, then work towards using upstream kvm_cpu_exec, and finally rework the core's PIO access management used for device assignment.

Please review/merge.

So with this set applied, s390 and ppc targets should work in qemu-kvm.git?

I bet not yet. Part IV will finally switch over to upstream vcpu loop, and that should make them work.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#11 lore raw

Re: [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec

Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Jan Kiszka

Upstream's and qemu-kvm's kvm_cpu_exec are not logically equivalent so

s/not/now/?

Oops, of course.

If there is no other need to repost, this should be fixed on merge.

Thanks,
Jan

Applied
#15 lore raw
In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka

This is a rather short round as the next and final one cannot be split up very well.

We start with three code cleanup patches, then work towards using upstream kvm_cpu_exec, and finally rework the core's PIO access management used for device assignment.

Please review/merge.

Thanks, applied.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.