Patchwork [2/7,v2] KVM regsync: Add register bitmap parameter to kvm_arch_[get|put]_registers

login
register
mail settings
Submitter Jason J. Herne
Date Jan. 10, 2013, 3:28 p.m.
Message ID <1357831723-3884-1-git-send-email-jjherne@us.ibm.com>
Download mbox | patch
Permalink /patch/211069/
State New
Headers show

Comments

Jason J. Herne - Jan. 10, 2013, 3:28 p.m.
From: "Jason J. Herne" <jjherne@us.ibm.com>

Modify kvm_arch_get_registers anf kvm_arch_put_registers interfaces such
that they accept a register bitmap parameter.  Also modify the only caller of
kvm_arch_get_registers such that it passes an appropriate bitmap.  The idea here
is that, for all currently existing calls we want to do nothing different.

Signed-off-by: Jason J. Herne <jjherne@us.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 include/sysemu/kvm.h |   11 ++---------
 kvm-all.c            |    2 +-
 target-i386/cpu.h    |   15 +++++++++++++++
 target-ppc/cpu.h     |   15 +++++++++++++++
 target-s390x/cpu.h   |   15 +++++++++++++++
 target-s390x/kvm.c   |    2 +-
 6 files changed, 49 insertions(+), 11 deletions(-)
Alexander Graf - Jan. 24, 2013, 12:03 p.m.
On 10.01.2013, at 16:28, Jason J. Herne wrote:

> From: "Jason J. Herne" <jjherne@us.ibm.com>
> 
> Modify kvm_arch_get_registers anf kvm_arch_put_registers interfaces such
> that they accept a register bitmap parameter.  Also modify the only caller of
> kvm_arch_get_registers such that it passes an appropriate bitmap.  The idea here
> is that, for all currently existing calls we want to do nothing different.
> 
> Signed-off-by: Jason J. Herne <jjherne@us.ibm.com>
> Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
> include/sysemu/kvm.h |   11 ++---------
> kvm-all.c            |    2 +-
> target-i386/cpu.h    |   15 +++++++++++++++
> target-ppc/cpu.h     |   15 +++++++++++++++
> target-s390x/cpu.h   |   15 +++++++++++++++
> target-s390x/kvm.c   |    2 +-
> 6 files changed, 49 insertions(+), 11 deletions(-)
> 
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 6756e16..e0738ba 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -165,16 +165,9 @@ int kvm_arch_handle_exit(CPUState *cpu, struct kvm_run *run);
> 
> int kvm_arch_process_async_events(CPUState *cpu);
> 
> -int kvm_arch_get_registers(CPUState *cpu);
> +int kvm_arch_get_registers(CPUState *cpu, int regmap);
> 
> -/* state subset only touched by the VCPU itself during runtime */
> -#define KVM_REGSYNC_RUNTIME_STATE   1
> -/* state subset modified during VCPU reset */
> -#define KVM_REGSYNC_RESET_STATE     2
> -/* full state set, modified during initialization or on vmload */
> -#define KVM_REGSYNC_FULL_STATE      3
> -
> -int kvm_arch_put_registers(CPUState *cpu, int level);
> +int kvm_arch_put_registers(CPUState *cpu, int regmap);
> 
> int kvm_arch_init(KVMState *s);
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index aa58b74..1aa61bb 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1494,7 +1494,7 @@ static void do_kvm_cpu_synchronize_state(void *arg)
>     CPUState *cpu = arg;
> 
>     if (!cpu->kvm_vcpu_dirty) {
> -        kvm_arch_get_registers(cpu);
> +        kvm_arch_get_registers(cpu, KVM_REGSYNC_FULL_STATE);
>         cpu->kvm_vcpu_dirty = true;
>     }
> }
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index e56921b..64d9f05 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -1223,4 +1223,19 @@ void enable_kvm_pv_eoi(void);
> /* Return name of 32-bit register, from a R_* constant */
> const char *get_register_name_32(unsigned int reg);
> 
> +/* Architecture specific register synchronization constants */
> +#define KVM_REGSYNC_I386_RUNTIME_REGS 0x01
> +#define KVM_REGSYNC_I386_RESET_REGS 0x02
> +#define KVM_REGSYNC_I386_FULL_REGS 0x04

These should be defined as (1 << x). How about s/REGS/BIT/ here too, to indicate what the defines are really about?

> +
> +/* General register sets made up of architeture specific registers*/
> +/* state subset only touched by the VCPU itself during runtime */
> +#define KVM_REGSYNC_RUNTIME_STATE   KVM_REGSYNC_I386_RUNTIME_REGS
> +/* state subset modified during VCPU reset */
> +#define KVM_REGSYNC_RESET_STATE     (KVM_REGSYNC_RUNTIME_STATE| \
> +                                    KVM_REGSYNC_I386_RESET_REGS)
> +/* full state set, modified during initialization or on vmload */
> +#define KVM_REGSYNC_FULL_STATE      (KVM_REGSYNC_RESET_STATE| \
> +                                    KVM_REGSYNC_I386_FULL_REGS)

Good :)

Since higher state is still a higher number than lower state, all checks in arch-specific code keep working too. Nice :)


Alex

Patch

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 6756e16..e0738ba 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -165,16 +165,9 @@  int kvm_arch_handle_exit(CPUState *cpu, struct kvm_run *run);
 
 int kvm_arch_process_async_events(CPUState *cpu);
 
-int kvm_arch_get_registers(CPUState *cpu);
+int kvm_arch_get_registers(CPUState *cpu, int regmap);
 
-/* state subset only touched by the VCPU itself during runtime */
-#define KVM_REGSYNC_RUNTIME_STATE   1
-/* state subset modified during VCPU reset */
-#define KVM_REGSYNC_RESET_STATE     2
-/* full state set, modified during initialization or on vmload */
-#define KVM_REGSYNC_FULL_STATE      3
-
-int kvm_arch_put_registers(CPUState *cpu, int level);
+int kvm_arch_put_registers(CPUState *cpu, int regmap);
 
 int kvm_arch_init(KVMState *s);
 
diff --git a/kvm-all.c b/kvm-all.c
index aa58b74..1aa61bb 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1494,7 +1494,7 @@  static void do_kvm_cpu_synchronize_state(void *arg)
     CPUState *cpu = arg;
 
     if (!cpu->kvm_vcpu_dirty) {
-        kvm_arch_get_registers(cpu);
+        kvm_arch_get_registers(cpu, KVM_REGSYNC_FULL_STATE);
         cpu->kvm_vcpu_dirty = true;
     }
 }
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e56921b..64d9f05 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1223,4 +1223,19 @@  void enable_kvm_pv_eoi(void);
 /* Return name of 32-bit register, from a R_* constant */
 const char *get_register_name_32(unsigned int reg);
 
+/* Architecture specific register synchronization constants */
+#define KVM_REGSYNC_I386_RUNTIME_REGS 0x01
+#define KVM_REGSYNC_I386_RESET_REGS 0x02
+#define KVM_REGSYNC_I386_FULL_REGS 0x04
+
+/* General register sets made up of architeture specific registers*/
+/* state subset only touched by the VCPU itself during runtime */
+#define KVM_REGSYNC_RUNTIME_STATE   KVM_REGSYNC_I386_RUNTIME_REGS
+/* state subset modified during VCPU reset */
+#define KVM_REGSYNC_RESET_STATE     (KVM_REGSYNC_RUNTIME_STATE| \
+                                    KVM_REGSYNC_I386_RESET_REGS)
+/* full state set, modified during initialization or on vmload */
+#define KVM_REGSYNC_FULL_STATE      (KVM_REGSYNC_RESET_STATE| \
+                                    KVM_REGSYNC_I386_FULL_REGS)
+
 #endif /* CPU_I386_H */
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index e88ebe0..f890ebd 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -2233,4 +2233,19 @@  static inline void cpu_pc_from_tb(CPUPPCState *env, TranslationBlock *tb)
 
 void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env);
 
+/* Architecture specific register synchronization constants */
+#define KVM_REGSYNC_PPC_RUNTIME_REGS 0x01
+#define KVM_REGSYNC_PPC_RESET_REGS 0x02
+#define KVM_REGSYNC_PPC_FULL_REGS 0x04
+
+/* General register sets made up of architeture specific registers*/
+/* state subset only touched by the VCPU itself during runtime */
+#define KVM_REGSYNC_RUNTIME_STATE   KVM_REGSYNC_PPC_RUNTIME_REGS
+/* state subset modified during VCPU reset */
+#define KVM_REGSYNC_RESET_STATE     (KVM_REGSYNC_RUNTIME_STATE| \
+                                    KVM_REGSYNC_PPC_RESET_REGS)
+/* full state set, modified during initialization or on vmload */
+#define KVM_REGSYNC_FULL_STATE      (KVM_REGSYNC_RESET_STATE| \
+                                    KVM_REGSYNC_PPC_FULL_REGS)
+
 #endif /* !defined (__CPU_PPC_H__) */
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index cd565c9..55ea4ee 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -999,4 +999,19 @@  uint32_t set_cc_nz_f64(float64 v);
 /* misc_helper.c */
 void program_interrupt(CPUS390XState *env, uint32_t code, int ilc);
 
+/* Architecture specific register synchronization constants */
+#define KVM_REGSYNC_S390_RUNTIME_REGS 0x01
+#define KVM_REGSYNC_S390_RESET_REGS 0x02
+#define KVM_REGSYNC_S390_FULL_REGS 0x04
+
+/* General register sets made up of architeture specific registers*/
+/* state subset only touched by the VCPU itself during runtime */
+#define KVM_REGSYNC_RUNTIME_STATE   KVM_REGSYNC_S390_RUNTIME_REGS
+/* state subset modified during VCPU reset */
+#define KVM_REGSYNC_RESET_STATE     (KVM_REGSYNC_RUNTIME_STATE| \
+                                    KVM_REGSYNC_S390_RESET_REGS)
+/* full state set, modified during initialization or on vmload */
+#define KVM_REGSYNC_FULL_STATE      (KVM_REGSYNC_RESET_STATE| \
+                                    KVM_REGSYNC_S390_FULL_REGS)
+
 #endif
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index e7b5ad9..4b87f1c 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -151,7 +151,7 @@  int kvm_arch_put_registers(CPUState *cs, int level)
     return 0;
 }
 
-int kvm_arch_get_registers(CPUState *cs)
+int kvm_arch_get_registers(CPUState *cs, int regmap)
 {
     S390CPU *cpu = S390_CPU(cs);
     CPUS390XState *env = &cpu->env;