From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, kvm@vger.kernel.org,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"Chinmay Rath" <rathc@linux.ibm.com>,
"Matthew Rosato" <mjrosato@linux.ibm.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
qemu-s390x@nongnu.org, "David Hildenbrand" <david@redhat.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Song Gao" <gaosong@loongson.cn>,
"Weiwei Li" <liwei1518@gmail.com>,
qemu-ppc@nongnu.org, "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Eric Farman" <farman@linux.ibm.com>
Subject: [PATCH v2 3/3] accel/kvm: Factor kvm_cpu_synchronize_put() out
Date: Wed, 8 Oct 2025 06:07:14 +0200 [thread overview]
Message-ID: <20251008040715.81513-4-philmd@linaro.org> (raw)
In-Reply-To: <20251008040715.81513-1-philmd@linaro.org>
The same code is duplicated 3 times: factor a common method.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/kvm/kvm-all.c | 47 ++++++++++++++++++---------------------------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 58802f7c3cc..56031925c4e 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2937,22 +2937,32 @@ void kvm_cpu_synchronize_state(CPUState *cpu)
}
}
-static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
+static bool kvm_cpu_synchronize_put(CPUState *cpu, KvmPutState state,
+ const char *desc)
{
Error *err = NULL;
- int ret = kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE, &err);
+ int ret = kvm_arch_put_registers(cpu, state, &err);
if (ret) {
if (err) {
- error_reportf_err(err, "Restoring resisters after reset: ");
+ error_reportf_err(err, "Restoring resisters %s: ", desc);
} else {
- error_report("Failed to put registers after reset: %s",
+ error_report("Failed to put registers %s: %s", desc,
strerror(-ret));
}
- cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
- vm_stop(RUN_STATE_INTERNAL_ERROR);
+ return false;
}
cpu->vcpu_dirty = false;
+
+ return true;
+}
+
+static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
+{
+ if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_RESET_STATE, "after reset")) {
+ cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
+ vm_stop(RUN_STATE_INTERNAL_ERROR);
+ }
}
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
@@ -2966,19 +2976,9 @@ void kvm_cpu_synchronize_post_reset(CPUState *cpu)
static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
{
- Error *err = NULL;
- int ret = kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE, &err);
- if (ret) {
- if (err) {
- error_reportf_err(err, "Putting registers after init: ");
- } else {
- error_report("Failed to put registers after init: %s",
- strerror(-ret));
- }
+ if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_FULL_STATE, "after init")) {
exit(1);
}
-
- cpu->vcpu_dirty = false;
}
void kvm_cpu_synchronize_post_init(CPUState *cpu)
@@ -3168,20 +3168,11 @@ int kvm_cpu_exec(CPUState *cpu)
MemTxAttrs attrs;
if (cpu->vcpu_dirty) {
- Error *err = NULL;
- ret = kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE, &err);
- if (ret) {
- if (err) {
- error_reportf_err(err, "Putting registers after init: ");
- } else {
- error_report("Failed to put registers after init: %s",
- strerror(-ret));
- }
+ if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_RUNTIME_STATE,
+ "at runtime")) {
ret = -1;
break;
}
-
- cpu->vcpu_dirty = false;
}
kvm_arch_pre_run(cpu, run);
--
2.51.0
next prev parent reply other threads:[~2025-10-08 4:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 4:07 [PATCH v2 0/3] accel/kvm: Cleanups around kvm_arch_put_registers() Philippe Mathieu-Daudé
2025-10-08 4:07 ` [PATCH v2 1/3] accel/kvm: Do not expect more then KVM_PUT_FULL_STATE Philippe Mathieu-Daudé
2025-10-08 4:07 ` [PATCH v2 2/3] accel/kvm: Introduce KvmPutState enum Philippe Mathieu-Daudé
2025-10-08 4:07 ` Philippe Mathieu-Daudé [this message]
2025-10-08 16:29 ` [PATCH v2 0/3] accel/kvm: Cleanups around kvm_arch_put_registers() Andrew Jones
2025-10-11 7:04 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251008040715.81513-4-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=arikalo@gmail.com \
--cc=aurelien@aurel32.net \
--cc=borntraeger@linux.ibm.com \
--cc=chenhuacai@kernel.org \
--cc=david@redhat.com \
--cc=dbarboza@ventanamicro.com \
--cc=farman@linux.ibm.com \
--cc=gaosong@loongson.cn \
--cc=harshpb@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jiaxun.yang@flygoat.com \
--cc=kvm@vger.kernel.org \
--cc=liwei1518@gmail.com \
--cc=mjrosato@linux.ibm.com \
--cc=mtosatti@redhat.com \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rathc@linux.ibm.com \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).