Skip to contentSkip to conversation

target/riscv: Restrict KVM-specific fields from ArchCPU

PATCH In review Philippe Mathieu-Daudé 3 participants 4 messages Jun 24, 2023 – Jul 3, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: Restrict KVM-specific fields from ArchCPU

These fields shouldn't be accessed when KVM is not available.

Restrict the KVM timer migration state. Rename the KVM timer post_load() handler accordingly, because cpu_post_load() is too generic.

---
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict whole vmstate_kvmtimer (thus drop Daniel's R-b)

---
 target/riscv/cpu.h     | 2 ++
 target/riscv/machine.c | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.h +2 -0
index e3e08d315f..b1b56aa29e 100644
@@ -363,12 +363,14 @@ struct CPUArchState {
     hwaddr kernel_addr;
     hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
     /* kvm timer */
     bool kvm_timer_dirty;
     uint64_t kvm_timer_time;
     uint64_t kvm_timer_compare;
     uint64_t kvm_timer_state;
     uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
 };
 
 /*
target/riscv/machine.c +6 -2
index 3ce2970785..d27f8a2a3a 100644
@@ -199,7 +199,8 @@ static bool kvmtimer_needed(void *opaque)
     return kvm_enabled();
 }
 
-static int cpu_post_load(void *opaque, int version_id)
+#ifdef CONFIG_KVM
+static int cpu_kvmtimer_post_load(void *opaque, int version_id)
 {
     RISCVCPU *cpu = opaque;
     CPURISCVState *env = &cpu->env;
@@ -213,7 +214,7 @@ static const VMStateDescription vmstate_kvmtimer = {
     .version_id = 1,
     .minimum_version_id = 1,
     .needed = kvmtimer_needed,
-    .post_load = cpu_post_load,
+    .post_load = cpu_kvmtimer_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
         VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
@@ -221,6 +222,7 @@ static const VMStateDescription vmstate_kvmtimer = {
         VMSTATE_END_OF_LIST()
     }
 };
+#endif
 
 static bool debug_needed(void *opaque)
 {
@@ -409,7 +411,9 @@ const VMStateDescription vmstate_riscv_cpu = {
         &vmstate_vector,
         &vmstate_pointermasking,
         &vmstate_rv128,
+#ifdef CONFIG_KVM
         &vmstate_kvmtimer,
+#endif
         &vmstate_envcfg,
         &vmstate_debug,
         &vmstate_smstateen,
Signature · 1 line
2.38.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

Restrict the KVM timer migration state. Rename the KVM timer post_load() handler accordingly, because cpu_post_load() is too generic.

---

Quoted 67 lines

Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict whole vmstate_kvmtimer (thus drop Daniel's R-b)

---
  target/riscv/cpu.h     | 2 ++
  target/riscv/machine.c | 8 ++++++--
  2 files changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.h +2 -0
index e3e08d315f..b1b56aa29e 100644
@@ -363,12 +363,14 @@ struct CPUArchState {
      hwaddr kernel_addr;
      hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
      /* kvm timer */
      bool kvm_timer_dirty;
      uint64_t kvm_timer_time;
      uint64_t kvm_timer_compare;
      uint64_t kvm_timer_state;
      uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
  };
 
  /*
target/riscv/machine.c +6 -2
index 3ce2970785..d27f8a2a3a 100644
@@ -199,7 +199,8 @@ static bool kvmtimer_needed(void *opaque)
      return kvm_enabled();
  }
 
-static int cpu_post_load(void *opaque, int version_id)
+#ifdef CONFIG_KVM
+static int cpu_kvmtimer_post_load(void *opaque, int version_id)
  {
      RISCVCPU *cpu = opaque;
      CPURISCVState *env = &cpu->env;
@@ -213,7 +214,7 @@ static const VMStateDescription vmstate_kvmtimer = {
      .version_id = 1,
      .minimum_version_id = 1,
      .needed = kvmtimer_needed,
-    .post_load = cpu_post_load,
+    .post_load = cpu_kvmtimer_post_load,
      .fields = (VMStateField[]) {
          VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
          VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
@@ -221,6 +222,7 @@ static const VMStateDescription vmstate_kvmtimer = {
          VMSTATE_END_OF_LIST()
      }
  };
+#endif
 
  static bool debug_needed(void *opaque)
  {
@@ -409,7 +411,9 @@ const VMStateDescription vmstate_riscv_cpu = {
          &vmstate_vector,
          &vmstate_pointermasking,
          &vmstate_rv128,
+#ifdef CONFIG_KVM
          &vmstate_kvmtimer,
+#endif
          &vmstate_envcfg,
          &vmstate_debug,
          &vmstate_smstateen,
#2 lore raw
In reply to Philippe Mathieu-Daudé

target/riscv/machine.c

Quoted 38 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

Restrict the KVM timer migration state. Rename the KVM timer post_load() handler accordingly, because cpu_post_load() is too generic.

---
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict whole vmstate_kvmtimer (thus drop Daniel's R-b)

---
  target/riscv/cpu.h     | 2 ++
  target/riscv/machine.c | 8 ++++++--
  2 files changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.h +2 -0
index e3e08d315f..b1b56aa29e 100644
@@ -363,12 +363,14 @@ struct CPUArchState {
      hwaddr kernel_addr;
      hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
      /* kvm timer */
      bool kvm_timer_dirty;
      uint64_t kvm_timer_time;
      uint64_t kvm_timer_compare;
      uint64_t kvm_timer_state;
      uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
  };
 
  /*
target/riscv/machine.c +0 -0
index 3ce2970785..d27f8a2a3a 100644

Oops, here goes ...

target/riscv/machine.c static bool kvmtimer_needed(void *opaque) · line 202

Quoted 6 lines
target/riscv/machine.c +1 -1
@@ -199,7 +199,8 @@ static bool kvmtimer_needed(void *opaque)
      return kvm_enabled();
  }
 
-static int cpu_post_load(void *opaque, int version_id)
+#ifdef CONFIG_KVM

... this ^^^ line.

Quoted 31 lines
target/riscv/machine.c +5 -1
+static int cpu_kvmtimer_post_load(void *opaque, int version_id)
  {
      RISCVCPU *cpu = opaque;
      CPURISCVState *env = &cpu->env;
@@ -213,7 +214,7 @@ static const VMStateDescription vmstate_kvmtimer = {
      .version_id = 1,
      .minimum_version_id = 1,
      .needed = kvmtimer_needed,
-    .post_load = cpu_post_load,
+    .post_load = cpu_kvmtimer_post_load,
      .fields = (VMStateField[]) {
          VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
          VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
@@ -221,6 +222,7 @@ static const VMStateDescription vmstate_kvmtimer = {
          VMSTATE_END_OF_LIST()
      }
  };
+#endif
 
  static bool debug_needed(void *opaque)
  {
@@ -409,7 +411,9 @@ const VMStateDescription vmstate_riscv_cpu = {
          &vmstate_vector,
          &vmstate_pointermasking,
          &vmstate_rv128,
+#ifdef CONFIG_KVM
          &vmstate_kvmtimer,
+#endif
          &vmstate_envcfg,
          &vmstate_debug,
          &vmstate_smstateen,
Reviewed-by on v2 1/1
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

Restrict the KVM timer migration state. Rename the KVM timer post_load() handler accordingly, because cpu_post_load() is too generic.

Alistair

Quoted 72 lines

---
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict whole vmstate_kvmtimer (thus drop Daniel's R-b)

---
 target/riscv/cpu.h     | 2 ++
 target/riscv/machine.c | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.h +2 -0
index e3e08d315f..b1b56aa29e 100644
@@ -363,12 +363,14 @@ struct CPUArchState {
     hwaddr kernel_addr;
     hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
     /* kvm timer */
     bool kvm_timer_dirty;
     uint64_t kvm_timer_time;
     uint64_t kvm_timer_compare;
     uint64_t kvm_timer_state;
     uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
 };
 
 /*
target/riscv/machine.c +6 -3
index 3ce2970785..d27f8a2a3a 100644
@@ -199,7 +199,8 @@ static bool kvmtimer_needed(void *opaque)
     return kvm_enabled();
 }
 
-static int cpu_post_load(void *opaque, int version_id)
+#ifdef CONFIG_KVM
+static int cpu_kvmtimer_post_load(void *opaque, int version_id)
 {
     RISCVCPU *cpu = opaque;
     CPURISCVState *env = &cpu->env;
@@ -213,7 +214,7 @@ static const VMStateDescription vmstate_kvmtimer = {
     .version_id = 1,
     .minimum_version_id = 1,
     .needed = kvmtimer_needed,
-    .post_load = cpu_post_load,
+    .post_load = cpu_kvmtimer_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
         VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
@@ -221,6 +222,7 @@ static const VMStateDescription vmstate_kvmtimer = {
         VMSTATE_END_OF_LIST()
     }
 };
+#endif
 
 static bool debug_needed(void *opaque)
 {
@@ -409,7 +411,9 @@ const VMStateDescription vmstate_riscv_cpu = {
         &vmstate_vector,
         &vmstate_pointermasking,
         &vmstate_rv128,
+#ifdef CONFIG_KVM
         &vmstate_kvmtimer,
+#endif
         &vmstate_envcfg,
         &vmstate_debug,
         &vmstate_smstateen,
--

2.38.1