target/riscv: Restrict KVM-specific fields from ArchCPU
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
@@ -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
@@ -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
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, becausecpu_post_load()is too generic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 67 lines
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict wholevmstate_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@@ -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@@ -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,
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, becausecpu_post_load()is too generic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict wholevmstate_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@@ -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
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,
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, becausecpu_post_load()is too generic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 72 lines
---
Since v1 https://lore.kernel.org/qemu-devel/[email protected]/:
- Restrict wholevmstate_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@@ -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@@ -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