qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Marcelo Tosatti" <mtosatti@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Xiaoyao Li" <xiaoyao.li@intel.com>,
	"Chenyi Qiang" <chenyi.qiang@intel.com>,
	qemu-devel@nongnu.org
Subject: [PATCH 1/2] i386/kvm: Get X86MachineState in kvm_arch_init() without the cast check
Date: Tue, 29 Jul 2025 14:20:13 +0800	[thread overview]
Message-ID: <20250729062014.1669578-2-xiaoyao.li@intel.com> (raw)
In-Reply-To: <20250729062014.1669578-1-xiaoyao.li@intel.com>

Commit 8f54bbd0b4d9 ("x86: Check for machine state object class before
typecasting it") added back the object_dynamic_cast() check before
casting MachineState to X86MachineState. And commit 035d1ef26565 ("i386:
Add ratelimit for bus locks acquired in guest") followed it.

The reason to check object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE)
before commit 8f54bbd0b4d9 was that smm was not supported for microvm
machine at that time. But after commit 8f54bbd0b4d9, smm is supported
for all x86 machines (both pc and microvm). And since it's the
target-specifc implementation of kvm_arch_init() in target/i386/kvm/kvm.c,
I don't see how it would be called for other machines than x86machine,
and why the check of object_dynamic_cast() is needed.

Drop the object_dynamic_cast() check and simplify the code.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 target/i386/kvm/kvm.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 369626f8c8d7..d145ad49e4e5 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -3230,6 +3230,7 @@ static int kvm_vm_enable_energy_msrs(KVMState *s)
 
 int kvm_arch_init(MachineState *ms, KVMState *s)
 {
+    X86MachineState *x86ms = X86_MACHINE(ms);
     int ret;
     struct utsname utsname;
     Error *local_err = NULL;
@@ -3311,8 +3312,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
     }
 
     if (kvm_check_extension(s, KVM_CAP_X86_SMM) &&
-        object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE) &&
-        x86_machine_is_smm_enabled(X86_MACHINE(ms))) {
+        x86_machine_is_smm_enabled(x86ms)) {
         smram_machine_done.notify = register_smram_listener;
         qemu_add_machine_init_done_notifier(&smram_machine_done);
     }
@@ -3326,18 +3326,14 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
         }
     }
 
-    if (object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE)) {
-        X86MachineState *x86ms = X86_MACHINE(ms);
-
-        if (x86ms->bus_lock_ratelimit > 0) {
-            ret = kvm_vm_enable_bus_lock_exit(s);
-            if (ret < 0) {
-                return ret;
-            }
-            ratelimit_init(&bus_lock_ratelimit_ctrl);
-            ratelimit_set_speed(&bus_lock_ratelimit_ctrl,
-                                x86ms->bus_lock_ratelimit, BUS_LOCK_SLICE_TIME);
+    if (x86ms->bus_lock_ratelimit > 0) {
+        ret = kvm_vm_enable_bus_lock_exit(s);
+        if (ret < 0) {
+            return ret;
         }
+        ratelimit_init(&bus_lock_ratelimit_ctrl);
+        ratelimit_set_speed(&bus_lock_ratelimit_ctrl,
+                            x86ms->bus_lock_ratelimit, BUS_LOCK_SLICE_TIME);
     }
 
     if (kvm_check_extension(s, KVM_CAP_X86_NOTIFY_VMEXIT)) {
-- 
2.43.0



  reply	other threads:[~2025-07-29  6:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-29  6:20 [PATCH 0/2] i386/kvm: Cleanups in kvm_arch_init() Xiaoyao Li
2025-07-29  6:20 ` Xiaoyao Li [this message]
2025-07-29  7:12   ` [PATCH 1/2] i386/kvm: Get X86MachineState in kvm_arch_init() without the cast check Philippe Mathieu-Daudé
2025-07-29  7:51   ` Chenyi Qiang
2025-07-29  6:20 ` [PATCH 2/2] i386/kvm: Drop KVM_CAP_X86_SMM check in kvm_arch_init() Xiaoyao Li
2025-09-12  5:48 ` [PATCH 0/2] i386/kvm: Cleanups " Xiaoyao Li

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=20250729062014.1669578-2-xiaoyao.li@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=chenyi.qiang@intel.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).