* [PATCH 0/2] hw/i386: Cleanups around kvmclock_create()
@ 2023-06-20 8:32 Philippe Mathieu-Daudé
2023-06-20 8:32 ` [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub Philippe Mathieu-Daudé
2023-06-20 8:32 ` [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h' Philippe Mathieu-Daudé
0 siblings, 2 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-06-20 8:32 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Michael S. Tsirkin, Sergio Lopez,
Eduardo Habkost, Paolo Bonzini, kvm, Marcel Apfelbaum,
Philippe Mathieu-Daudé
After removing the kvmclock_create() stub we restrict
"hw/kvm/clock.h" to x86, the single arch implementing /
using this.
Philippe Mathieu-Daudé (2):
hw/i386: Remove unuseful kvmclock_create() stub
hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h'
{include/hw => hw/i386}/kvm/clock.h | 14 ++------------
hw/i386/kvm/clock.c | 6 ++++--
hw/i386/microvm.c | 6 ++++--
hw/i386/pc_piix.c | 4 ++--
hw/i386/pc_q35.c | 6 ++++--
5 files changed, 16 insertions(+), 20 deletions(-)
rename {include/hw => hw/i386}/kvm/clock.h (65%)
--
2.38.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub
2023-06-20 8:32 [PATCH 0/2] hw/i386: Cleanups around kvmclock_create() Philippe Mathieu-Daudé
@ 2023-06-20 8:32 ` Philippe Mathieu-Daudé
2023-06-20 12:32 ` Alex Bennée
2023-06-20 8:32 ` [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h' Philippe Mathieu-Daudé
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-06-20 8:32 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Michael S. Tsirkin, Sergio Lopez,
Eduardo Habkost, Paolo Bonzini, kvm, Marcel Apfelbaum,
Philippe Mathieu-Daudé
We shouldn't call kvmclock_create() when KVM is not available
or disabled:
- check for kvm_enabled() before calling it
- assert KVM is enabled once called
Since the call is elided when KVM is not available, we can
remove the stub (it is never compiled).
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/kvm/clock.h | 10 ----------
hw/i386/kvm/clock.c | 4 +++-
hw/i386/microvm.c | 4 +++-
hw/i386/pc_piix.c | 2 +-
hw/i386/pc_q35.c | 4 +++-
5 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/include/hw/kvm/clock.h b/include/hw/kvm/clock.h
index 7994071c4f..3efe0a871c 100644
--- a/include/hw/kvm/clock.h
+++ b/include/hw/kvm/clock.h
@@ -13,16 +13,6 @@
#ifndef HW_KVM_CLOCK_H
#define HW_KVM_CLOCK_H
-#ifdef CONFIG_KVM
-
void kvmclock_create(bool create_always);
-#else /* CONFIG_KVM */
-
-static inline void kvmclock_create(bool create_always)
-{
-}
-
-#endif /* !CONFIG_KVM */
-
#endif
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index df70b4a033..0824c6d313 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -332,8 +332,10 @@ void kvmclock_create(bool create_always)
{
X86CPU *cpu = X86_CPU(first_cpu);
- if (!kvm_enabled() || !kvm_has_adjust_clock())
+ assert(kvm_enabled());
+ if (!kvm_has_adjust_clock()) {
return;
+ }
if (create_always ||
cpu->env.features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 7227a2156c..6b762bc18e 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -180,7 +180,9 @@ static void microvm_devices_init(MicrovmMachineState *mms)
x86ms->ioapic2 = ioapic_init_secondary(gsi_state);
}
- kvmclock_create(true);
+ if (kvm_enabled()) {
+ kvmclock_create(true);
+ }
mms->virtio_irq_base = 5;
mms->virtio_num_transports = 8;
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 44146e6ff5..715c063eec 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -193,7 +193,7 @@ static void pc_init1(MachineState *machine,
pc_machine_init_sgx_epc(pcms);
x86_cpus_init(x86ms, pcmc->default_cpu_version);
- if (pcmc->kvmclock_enabled) {
+ if (kvm_enabled() && pcmc->kvmclock_enabled) {
kvmclock_create(pcmc->kvmclock_create_always);
}
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a9a59ed42b..a0553f70f7 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -184,7 +184,9 @@ static void pc_q35_init(MachineState *machine)
pc_machine_init_sgx_epc(pcms);
x86_cpus_init(x86ms, pcmc->default_cpu_version);
- kvmclock_create(pcmc->kvmclock_create_always);
+ if (kvm_enabled()) {
+ kvmclock_create(pcmc->kvmclock_create_always);
+ }
/* pci enabled */
if (pcmc->pci_enabled) {
--
2.38.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub
2023-06-20 8:32 ` [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub Philippe Mathieu-Daudé
@ 2023-06-20 12:32 ` Alex Bennée
0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2023-06-20 12:32 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Richard Henderson, Michael S. Tsirkin, Sergio Lopez,
Eduardo Habkost, Paolo Bonzini, kvm, Marcel Apfelbaum
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> We shouldn't call kvmclock_create() when KVM is not available
> or disabled:
> - check for kvm_enabled() before calling it
> - assert KVM is enabled once called
> Since the call is elided when KVM is not available, we can
> remove the stub (it is never compiled).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h'
2023-06-20 8:32 [PATCH 0/2] hw/i386: Cleanups around kvmclock_create() Philippe Mathieu-Daudé
2023-06-20 8:32 ` [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub Philippe Mathieu-Daudé
@ 2023-06-20 8:32 ` Philippe Mathieu-Daudé
2023-06-20 12:32 ` Alex Bennée
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-06-20 8:32 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Michael S. Tsirkin, Sergio Lopez,
Eduardo Habkost, Paolo Bonzini, kvm, Marcel Apfelbaum,
Philippe Mathieu-Daudé
kvmclock_create() is only implemented in hw/i386/kvm/clock.h.
Restrict the "hw/kvm/clock.h" header to i386 by moving it to
hw/i386/.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
RFC: No other arch had to implement this for 12 years,
safe enough to restrict to x86?
---
{include/hw => hw/i386}/kvm/clock.h | 4 ++--
hw/i386/kvm/clock.c | 2 +-
hw/i386/microvm.c | 2 +-
hw/i386/pc_piix.c | 2 +-
hw/i386/pc_q35.c | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
rename {include/hw => hw/i386}/kvm/clock.h (85%)
diff --git a/include/hw/kvm/clock.h b/hw/i386/kvm/clock.h
similarity index 85%
rename from include/hw/kvm/clock.h
rename to hw/i386/kvm/clock.h
index 3efe0a871c..401c7e445b 100644
--- a/include/hw/kvm/clock.h
+++ b/hw/i386/kvm/clock.h
@@ -10,8 +10,8 @@
* See the COPYING file in the top-level directory.
*/
-#ifndef HW_KVM_CLOCK_H
-#define HW_KVM_CLOCK_H
+#ifndef HW_I386_KVM_CLOCK_H
+#define HW_I386_KVM_CLOCK_H
void kvmclock_create(bool create_always);
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index 0824c6d313..34348a3324 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -22,7 +22,7 @@
#include "kvm/kvm_i386.h"
#include "migration/vmstate.h"
#include "hw/sysbus.h"
-#include "hw/kvm/clock.h"
+#include "hw/i386/kvm/clock.h"
#include "hw/qdev-properties.h"
#include "qapi/error.h"
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 6b762bc18e..8deeb62774 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -32,7 +32,7 @@
#include "hw/loader.h"
#include "hw/irq.h"
-#include "hw/kvm/clock.h"
+#include "hw/i386/kvm/clock.h"
#include "hw/i386/microvm.h"
#include "hw/i386/x86.h"
#include "target/i386/cpu.h"
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 715c063eec..85fe41327c 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -46,7 +46,7 @@
#include "hw/ide/piix.h"
#include "hw/irq.h"
#include "sysemu/kvm.h"
-#include "hw/kvm/clock.h"
+#include "hw/i386/kvm/clock.h"
#include "hw/sysbus.h"
#include "hw/i2c/smbus_eeprom.h"
#include "exec/memory.h"
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a0553f70f7..9e6602dfde 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -35,7 +35,7 @@
#include "hw/i2c/smbus_eeprom.h"
#include "hw/rtc/mc146818rtc.h"
#include "sysemu/kvm.h"
-#include "hw/kvm/clock.h"
+#include "hw/i386/kvm/clock.h"
#include "hw/pci-host/q35.h"
#include "hw/pci/pcie_port.h"
#include "hw/qdev-properties.h"
--
2.38.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h'
2023-06-20 8:32 ` [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h' Philippe Mathieu-Daudé
@ 2023-06-20 12:32 ` Alex Bennée
0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2023-06-20 12:32 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Richard Henderson, Michael S. Tsirkin, Sergio Lopez,
Eduardo Habkost, Paolo Bonzini, kvm, Marcel Apfelbaum
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> kvmclock_create() is only implemented in hw/i386/kvm/clock.h.
> Restrict the "hw/kvm/clock.h" header to i386 by moving it to
> hw/i386/.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> RFC: No other arch had to implement this for 12 years,
> safe enough to restrict to x86?
Importantly the implementation is certainly in i386 only:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-20 12:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-20 8:32 [PATCH 0/2] hw/i386: Cleanups around kvmclock_create() Philippe Mathieu-Daudé
2023-06-20 8:32 ` [PATCH 1/2] hw/i386: Remove unuseful kvmclock_create() stub Philippe Mathieu-Daudé
2023-06-20 12:32 ` Alex Bennée
2023-06-20 8:32 ` [RFC PATCH 2/2] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h' Philippe Mathieu-Daudé
2023-06-20 12:32 ` Alex Bennée
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).