* [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
@ 2010-04-01 20:07 Blue Swirl
2010-04-01 20:15 ` Anthony Liguori
2010-04-01 20:23 ` Paolo Bonzini
0 siblings, 2 replies; 12+ messages in thread
From: Blue Swirl @ 2010-04-01 20:07 UTC (permalink / raw)
To: qemu-devel
Remove dependency of vl.c to KVM, then we can partially revert
b33612d03540fda7fa67485f1c20395beb7a2bf0.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
Makefile.objs | 2 +-
Makefile.target | 2 +-
arch_init.c | 20 ++++++++++++++++++++
arch_init.h | 2 ++
vl.c | 14 ++------------
5 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/Makefile.objs b/Makefile.objs
index 74d7a3d..4cc8ea6 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -128,7 +128,7 @@ user-obj-y += cutils.o cache-utils.o
# libhw
hw-obj-y =
-hw-obj-y += loader.o
+hw-obj-y += vl.o loader.o
hw-obj-y += virtio.o virtio-console.o
hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
hw-obj-y += watchdog.o
diff --git a/Makefile.target b/Makefile.target
index 167fc8d..2aa02f5 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
# System emulator target
ifdef CONFIG_SOFTMMU
-obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o vl.o
+obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o
# virtio has to be here due to weird dependency between PCI and virtio-net.
# need to fix this properly
obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o
virtio-serial-bus.o
diff --git a/arch_init.c b/arch_init.c
index cfc03ea..001c560 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -41,6 +41,8 @@
#include "gdbstub.h"
#include "hw/smbios.h"
+int kvm_allowed = 0;
+
#ifdef TARGET_SPARC
int graphic_width = 1024;
int graphic_height = 768;
@@ -508,3 +510,21 @@ int xen_available(void)
return 0;
#endif
}
+
+void enable_kvm(void)
+{
+ kvm_allowed = 1;
+}
+
+void kvm_maybe_init(int smp_cpus)
+{
+ if (kvm_enabled()) {
+ int ret;
+
+ ret = kvm_init(smp_cpus);
+ if (ret < 0) {
+ fprintf(stderr, "failed to initialize KVM\n");
+ exit(1);
+ }
+ }
+}
diff --git a/arch_init.h b/arch_init.h
index 682890c..dde4309 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -29,5 +29,7 @@ void cpudef_init(void);
int audio_available(void);
int kvm_available(void);
int xen_available(void);
+void enable_kvm(void);
+void kvm_maybe_init(int smp_cpus);
#endif
diff --git a/vl.c b/vl.c
index 03fccbf..cc214dd 100644
--- a/vl.c
+++ b/vl.c
@@ -145,7 +145,6 @@ int main(int argc, char **argv)
#include "dma.h"
#include "audio/audio.h"
#include "migration.h"
-#include "kvm.h"
#include "balloon.h"
#include "qemu-option.h"
#include "qemu-config.h"
@@ -241,7 +240,6 @@ uint8_t qemu_uuid[16];
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
-int kvm_allowed = 0;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_EMULATE;
@@ -3228,7 +3226,7 @@ int main(int argc, char **argv, char **envp)
printf("Option %s not supported for this
target\n", popt->name);
exit(1);
}
- kvm_allowed = 1;
+ enable_kvm();
break;
case QEMU_OPTION_usb:
usb_enabled = 1;
@@ -3574,15 +3572,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- if (kvm_enabled()) {
- int ret;
-
- ret = kvm_init(smp_cpus);
- if (ret < 0) {
- fprintf(stderr, "failed to initialize KVM\n");
- exit(1);
- }
- }
+ kvm_maybe_init(smp_cpus);
if (qemu_init_main_loop()) {
fprintf(stderr, "qemu_init_main_loop failed\n");
--
1.6.2.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-01 20:07 [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once Blue Swirl
@ 2010-04-01 20:15 ` Anthony Liguori
2010-04-01 20:27 ` Blue Swirl
2010-04-01 20:23 ` Paolo Bonzini
1 sibling, 1 reply; 12+ messages in thread
From: Anthony Liguori @ 2010-04-01 20:15 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
On 04/01/2010 03:07 PM, Blue Swirl wrote:
> Remove dependency of vl.c to KVM, then we can partially revert
> b33612d03540fda7fa67485f1c20395beb7a2bf0.
>
> Signed-off-by: Blue Swirl<blauwirbel@gmail.com>
> ---
> Makefile.objs | 2 +-
> Makefile.target | 2 +-
> arch_init.c | 20 ++++++++++++++++++++
> arch_init.h | 2 ++
> vl.c | 14 ++------------
> 5 files changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/Makefile.objs b/Makefile.objs
> index 74d7a3d..4cc8ea6 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -128,7 +128,7 @@ user-obj-y += cutils.o cache-utils.o
> # libhw
>
> hw-obj-y =
> -hw-obj-y += loader.o
> +hw-obj-y += vl.o loader.o
> hw-obj-y += virtio.o virtio-console.o
> hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
> hw-obj-y += watchdog.o
> diff --git a/Makefile.target b/Makefile.target
> index 167fc8d..2aa02f5 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
> # System emulator target
> ifdef CONFIG_SOFTMMU
>
> -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o vl.o
> +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o
> # virtio has to be here due to weird dependency between PCI and virtio-net.
> # need to fix this properly
> obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o
> virtio-serial-bus.o
> diff --git a/arch_init.c b/arch_init.c
> index cfc03ea..001c560 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -41,6 +41,8 @@
> #include "gdbstub.h"
> #include "hw/smbios.h"
>
> +int kvm_allowed = 0;
> +
> #ifdef TARGET_SPARC
> int graphic_width = 1024;
> int graphic_height = 768;
> @@ -508,3 +510,21 @@ int xen_available(void)
> return 0;
> #endif
> }
> +
> +void enable_kvm(void)
> +{
> + kvm_allowed = 1;
> +}
>
Can we get away with keeping a local to vl.c use_kvm flag and then call
kvm_init() if use_kvm in vl.c?
We can stick a stub kvm_init() in arch_init.c if !CONFIG_KVM.
Regards,
Anthony LIguori
> +void kvm_maybe_init(int smp_cpus)
> +{
> + if (kvm_enabled()) {
> + int ret;
> +
> + ret = kvm_init(smp_cpus);
> + if (ret< 0) {
> + fprintf(stderr, "failed to initialize KVM\n");
> + exit(1);
> + }
> + }
> +}
> diff --git a/arch_init.h b/arch_init.h
> index 682890c..dde4309 100644
> --- a/arch_init.h
> +++ b/arch_init.h
> @@ -29,5 +29,7 @@ void cpudef_init(void);
> int audio_available(void);
> int kvm_available(void);
> int xen_available(void);
> +void enable_kvm(void);
> +void kvm_maybe_init(int smp_cpus);
>
> #endif
> diff --git a/vl.c b/vl.c
> index 03fccbf..cc214dd 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -145,7 +145,6 @@ int main(int argc, char **argv)
> #include "dma.h"
> #include "audio/audio.h"
> #include "migration.h"
> -#include "kvm.h"
> #include "balloon.h"
> #include "qemu-option.h"
> #include "qemu-config.h"
> @@ -241,7 +240,6 @@ uint8_t qemu_uuid[16];
> static QEMUBootSetHandler *boot_set_handler;
> static void *boot_set_opaque;
>
> -int kvm_allowed = 0;
> uint32_t xen_domid;
> enum xen_mode xen_mode = XEN_EMULATE;
>
> @@ -3228,7 +3226,7 @@ int main(int argc, char **argv, char **envp)
> printf("Option %s not supported for this
> target\n", popt->name);
> exit(1);
> }
> - kvm_allowed = 1;
> + enable_kvm();
> break;
> case QEMU_OPTION_usb:
> usb_enabled = 1;
> @@ -3574,15 +3572,7 @@ int main(int argc, char **argv, char **envp)
> exit(1);
> }
>
> - if (kvm_enabled()) {
> - int ret;
> -
> - ret = kvm_init(smp_cpus);
> - if (ret< 0) {
> - fprintf(stderr, "failed to initialize KVM\n");
> - exit(1);
> - }
> - }
> + kvm_maybe_init(smp_cpus);
>
> if (qemu_init_main_loop()) {
> fprintf(stderr, "qemu_init_main_loop failed\n");
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-01 20:07 [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once Blue Swirl
2010-04-01 20:15 ` Anthony Liguori
@ 2010-04-01 20:23 ` Paolo Bonzini
2010-04-02 14:20 ` Blue Swirl
1 sibling, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2010-04-01 20:23 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
On 04/01/2010 10:07 PM, Blue Swirl wrote:
> Remove dependency of vl.c to KVM, then we can partially revert
> b33612d03540fda7fa67485f1c20395beb7a2bf0.
This is ugly...
Michael Tsirkin said in commit ca821806:
Comment on kvm usage: rather than require users to do if(kvm_enabled())
and/or ifdefs, this patch adds an API that, internally, is defined to
stub function on non-kvm build, and checks kvm_enabled for non-kvm
run.
While rest of qemu code still uses if (kvm_enabled()), I think this
approach is cleaner, and we should convert rest of code to it
long term.
Maybe we can start doing this for kvm_init?
> +void enable_kvm(void)
> +{
> + kvm_allowed = 1;
> +}
If you're adding this, this conditional from vl.c
if (!(kvm_available())) {
printf("Option %s not supported for this target\n", popt->name);
exit(1);
}
belongs in arch_init.c too, like in do_smbios_option and
do_acpitable_option.
Alternatively, with the approach I gave above, you can test in
kvm_maybe_init if kvm_init returns -ENOSYS, and print the error above
instead of "failed to initialize KVM".
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-01 20:15 ` Anthony Liguori
@ 2010-04-01 20:27 ` Blue Swirl
2010-04-02 15:01 ` [Qemu-devel] " Paolo Bonzini
0 siblings, 1 reply; 12+ messages in thread
From: Blue Swirl @ 2010-04-01 20:27 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
On 4/1/10, Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 04/01/2010 03:07 PM, Blue Swirl wrote:
>
> > Remove dependency of vl.c to KVM, then we can partially revert
> > b33612d03540fda7fa67485f1c20395beb7a2bf0.
> >
> > Signed-off-by: Blue Swirl<blauwirbel@gmail.com>
> > ---
> > Makefile.objs | 2 +-
> > Makefile.target | 2 +-
> > arch_init.c | 20 ++++++++++++++++++++
> > arch_init.h | 2 ++
> > vl.c | 14 ++------------
> > 5 files changed, 26 insertions(+), 14 deletions(-)
> >
> > diff --git a/Makefile.objs b/Makefile.objs
> > index 74d7a3d..4cc8ea6 100644
> > --- a/Makefile.objs
> > +++ b/Makefile.objs
> > @@ -128,7 +128,7 @@ user-obj-y += cutils.o cache-utils.o
> > # libhw
> >
> > hw-obj-y =
> > -hw-obj-y += loader.o
> > +hw-obj-y += vl.o loader.o
> > hw-obj-y += virtio.o virtio-console.o
> > hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
> > hw-obj-y += watchdog.o
> > diff --git a/Makefile.target b/Makefile.target
> > index 167fc8d..2aa02f5 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
> > # System emulator target
> > ifdef CONFIG_SOFTMMU
> >
> > -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o vl.o
> > +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o
> > # virtio has to be here due to weird dependency between PCI and
> virtio-net.
> > # need to fix this properly
> > obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o
> > virtio-serial-bus.o
> > diff --git a/arch_init.c b/arch_init.c
> > index cfc03ea..001c560 100644
> > --- a/arch_init.c
> > +++ b/arch_init.c
> > @@ -41,6 +41,8 @@
> > #include "gdbstub.h"
> > #include "hw/smbios.h"
> >
> > +int kvm_allowed = 0;
> > +
> > #ifdef TARGET_SPARC
> > int graphic_width = 1024;
> > int graphic_height = 768;
> > @@ -508,3 +510,21 @@ int xen_available(void)
> > return 0;
> > #endif
> > }
> > +
> > +void enable_kvm(void)
> > +{
> > + kvm_allowed = 1;
> > +}
> >
> >
>
> Can we get away with keeping a local to vl.c use_kvm flag and then call
> kvm_init() if use_kvm in vl.c?
It will not be safe to use kvm_enabled() in vl.c, so there needs to be
a target dependent helper. The call to kvm_init could remain in vl.c,
likewise it's not strictly needed to move kvm_allowed to arch_init.c.
They just caused problems with the poisoning check in patch 2/2. But
with this approach, because kvm.h is no longer included, there will
not be any problems.
>
> We can stick a stub kvm_init() in arch_init.c if !CONFIG_KVM.
>
> Regards,
>
> Anthony LIguori
>
>
>
> > +void kvm_maybe_init(int smp_cpus)
> > +{
> > + if (kvm_enabled()) {
> > + int ret;
> > +
> > + ret = kvm_init(smp_cpus);
> > + if (ret< 0) {
> > + fprintf(stderr, "failed to initialize KVM\n");
> > + exit(1);
> > + }
> > + }
> > +}
> > diff --git a/arch_init.h b/arch_init.h
> > index 682890c..dde4309 100644
> > --- a/arch_init.h
> > +++ b/arch_init.h
> > @@ -29,5 +29,7 @@ void cpudef_init(void);
> > int audio_available(void);
> > int kvm_available(void);
> > int xen_available(void);
> > +void enable_kvm(void);
> > +void kvm_maybe_init(int smp_cpus);
> >
> > #endif
> > diff --git a/vl.c b/vl.c
> > index 03fccbf..cc214dd 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -145,7 +145,6 @@ int main(int argc, char **argv)
> > #include "dma.h"
> > #include "audio/audio.h"
> > #include "migration.h"
> > -#include "kvm.h"
> > #include "balloon.h"
> > #include "qemu-option.h"
> > #include "qemu-config.h"
> > @@ -241,7 +240,6 @@ uint8_t qemu_uuid[16];
> > static QEMUBootSetHandler *boot_set_handler;
> > static void *boot_set_opaque;
> >
> > -int kvm_allowed = 0;
> > uint32_t xen_domid;
> > enum xen_mode xen_mode = XEN_EMULATE;
> >
> > @@ -3228,7 +3226,7 @@ int main(int argc, char **argv, char **envp)
> > printf("Option %s not supported for this
> > target\n", popt->name);
> > exit(1);
> > }
> > - kvm_allowed = 1;
> > + enable_kvm();
> > break;
> > case QEMU_OPTION_usb:
> > usb_enabled = 1;
> > @@ -3574,15 +3572,7 @@ int main(int argc, char **argv, char **envp)
> > exit(1);
> > }
> >
> > - if (kvm_enabled()) {
> > - int ret;
> > -
> > - ret = kvm_init(smp_cpus);
> > - if (ret< 0) {
> > - fprintf(stderr, "failed to initialize KVM\n");
> > - exit(1);
> > - }
> > - }
> > + kvm_maybe_init(smp_cpus);
> >
> > if (qemu_init_main_loop()) {
> > fprintf(stderr, "qemu_init_main_loop failed\n");
> >
> >
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-01 20:23 ` Paolo Bonzini
@ 2010-04-02 14:20 ` Blue Swirl
0 siblings, 0 replies; 12+ messages in thread
From: Blue Swirl @ 2010-04-02 14:20 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On 4/1/10, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 04/01/2010 10:07 PM, Blue Swirl wrote:
>
> > Remove dependency of vl.c to KVM, then we can partially revert
> > b33612d03540fda7fa67485f1c20395beb7a2bf0.
> >
>
> This is ugly...
>
> Michael Tsirkin said in commit ca821806:
>
> Comment on kvm usage: rather than require users to do if(kvm_enabled())
> and/or ifdefs, this patch adds an API that, internally, is defined to
> stub function on non-kvm build, and checks kvm_enabled for non-kvm
> run.
>
> While rest of qemu code still uses if (kvm_enabled()), I think this
> approach is cleaner, and we should convert rest of code to it
> long term.
>
> Maybe we can start doing this for kvm_init?
I see now. Yes, this would be better approach, I think this is also
what Anthony proposed.
> > +void enable_kvm(void)
> > +{
> > + kvm_allowed = 1;
> > +}
> >
>
> If you're adding this, this conditional from vl.c
>
> if (!(kvm_available())) {
> printf("Option %s not supported for this target\n", popt->name);
> exit(1);
> }
>
> belongs in arch_init.c too, like in do_smbios_option and
> do_acpitable_option.
>
> Alternatively, with the approach I gave above, you can test in
> kvm_maybe_init if kvm_init returns -ENOSYS, and print the error above
> instead of "failed to initialize KVM".
Also kvm_allowed could be set in kvm-all.c.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-01 20:27 ` Blue Swirl
@ 2010-04-02 15:01 ` Paolo Bonzini
2010-04-02 15:08 ` Anthony Liguori
0 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2010-04-02 15:01 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]
On 04/01/2010 10:27 PM, Blue Swirl wrote:
> It will not be safe to use kvm_enabled() in vl.c, so there needs to be
> a target dependent helper. The call to kvm_init could remain in vl.c,
> likewise it's not strictly needed to move kvm_allowed to arch_init.c.
Not really, because kvm_allowed _can_ be used from once-compiled files.
The attached patch makes kvm-all.c be compiled always, even if
!CONFIG_KVM; functions that require kvm are almost always omitted for
now (so checking kvm_enabled() is required to call them). However,
kvm_init is stubbed so that vl.c can call it.
In the future we could add more stubbing and ultimately do this
unconditionally:
#define kvm_enabled() kvm_allowed
With this patch vl.c can already be compiled once, but I did not include
it because it would conflict with my balloon.c series; I'm doing enough
rebasing these days. Also, qemu-kvm is a bit behind qemu and all these
patches are nightmares for the merges, so it's better IMO if things are
left to calm down a bit.
> They just caused problems with the poisoning check in patch 2/2.
Poisoning kvm_enabled is right, but poisoning kvm_allowed is overkill.
Paolo
[-- Attachment #2: 0001-provide-a-stub-version-of-kvm-all.c-if-CONFIG_KVM.patch --]
[-- Type: text/plain, Size: 4689 bytes --]
From e9bd21893633365567b7c0d468a9971ab02e46f0 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Fri, 2 Apr 2010 09:29:54 +0200
Subject: [PATCH] provide a stub version of kvm-all.c if !CONFIG_KVM
This allows limited use of kvm functions (which will return ENOSYS)
even in once-compiled modules. The patch also improves a bit the error
messages for KVM initialization.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Makefile.target | 4 ++--
kvm-all.c | 16 ++++++++++++++--
kvm.h | 4 +++-
vl.c | 16 +++++++---------
4 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/Makefile.target b/Makefile.target
index 167fc8d..3943de1 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -168,8 +168,8 @@ obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-b
obj-y += event_notifier.o
obj-y += vhost_net.o
obj-$(CONFIG_VHOST_NET) += vhost.o
-obj-y += rwhandler.o
-obj-$(CONFIG_KVM) += kvm.o kvm-all.o
+obj-y += rwhandler.o kvm-all.o
+obj-$(CONFIG_KVM) += kvm.o
LIBS+=-lz
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
diff --git a/kvm-all.c b/kvm-all.c
index 7aa5e57..53f58a6 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -13,14 +13,16 @@
*
*/
+#include "qemu-common.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdarg.h>
+#ifdef CONFIG_KVM
#include <linux/kvm.h>
+#endif
-#include "qemu-common.h"
#include "qemu-barrier.h"
#include "sysemu.h"
#include "hw/hw.h"
@@ -73,6 +75,7 @@ struct KVMState
static KVMState *kvm_state;
+#ifdef CONFIG_KVM
static KVMSlot *kvm_alloc_slot(KVMState *s)
{
int i;
@@ -282,7 +285,7 @@ static int kvm_set_migration_log(int enable)
return 0;
}
-static int test_le_bit(unsigned long nr, unsigned char *addr)
+static inline int test_le_bit(unsigned long nr, unsigned char *addr)
{
return (addr[nr >> 3] >> (nr & 7)) & 1;
}
@@ -561,9 +564,11 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client = {
.sync_dirty_bitmap = kvm_client_sync_dirty_bitmap,
.migration_log = kvm_client_migration_log,
};
+#endif
int kvm_init(int smp_cpus)
{
+#ifdef CONFIG_KVM
static const char upgrade_note[] =
"Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
"(see http://sourceforge.net/projects/kvm).\n";
@@ -683,8 +688,12 @@ err:
qemu_free(s);
return ret;
+#else
+ return -ENOSYS;
+#endif
}
+#ifdef CONFIG_KVM
static int kvm_handle_io(uint16_t port, void *data, int direction, int size,
uint32_t count)
{
@@ -866,6 +875,7 @@ int kvm_cpu_exec(CPUState *env)
return ret;
}
+#endif
int kvm_ioctl(KVMState *s, int type, ...)
{
@@ -1139,6 +1149,7 @@ void kvm_remove_all_breakpoints(CPUState *current_env)
}
#endif /* !KVM_CAP_SET_GUEST_DEBUG */
+#ifdef CONFIG_KVM
int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset)
{
struct kvm_signal_mask *sigmask;
@@ -1156,6 +1167,7 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset)
return r;
}
+#endif
#ifdef KVM_IOEVENTFD
int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
diff --git a/kvm.h b/kvm.h
index 1e5be27..2477cfd 100644
--- a/kvm.h
+++ b/kvm.h
@@ -18,13 +18,15 @@
#include <errno.h>
#include "config-host.h"
#include "qemu-queue.h"
+#include "cpu-common.h"
#ifdef CONFIG_KVM
#include <linux/kvm.h>
#endif
-#ifdef CONFIG_KVM
extern int kvm_allowed;
+
+#ifdef CONFIG_KVM
#define kvm_enabled() (kvm_allowed)
#else
#define kvm_enabled() (0)
diff --git a/vl.c b/vl.c
index 6768cf1..9fe4682 100644
--- a/vl.c
+++ b/vl.c
@@ -3235,10 +3235,6 @@ int main(int argc, char **argv, char **envp)
do_smbios_option(optarg);
break;
case QEMU_OPTION_enable_kvm:
- if (!(kvm_available())) {
- printf("Option %s not supported for this target\n", popt->name);
- exit(1);
- }
kvm_allowed = 1;
break;
case QEMU_OPTION_usb:
@@ -3585,12 +3581,14 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- if (kvm_enabled()) {
- int ret;
-
- ret = kvm_init(smp_cpus);
+ if (kvm_allowed) {
+ int ret = kvm_init(smp_cpus);
if (ret < 0) {
- fprintf(stderr, "failed to initialize KVM\n");
+ if (!kvm_available()) {
+ printf("KVM not supported for this target\n");
+ } else {
+ fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
+ }
exit(1);
}
}
--
1.6.6.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-02 15:01 ` [Qemu-devel] " Paolo Bonzini
@ 2010-04-02 15:08 ` Anthony Liguori
2010-04-02 15:11 ` Paolo Bonzini
2010-04-02 15:43 ` Blue Swirl
0 siblings, 2 replies; 12+ messages in thread
From: Anthony Liguori @ 2010-04-02 15:08 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Blue Swirl, qemu-devel
On 04/02/2010 10:01 AM, Paolo Bonzini wrote:
> On 04/01/2010 10:27 PM, Blue Swirl wrote:
>> It will not be safe to use kvm_enabled() in vl.c, so there needs to be
>> a target dependent helper. The call to kvm_init could remain in vl.c,
>> likewise it's not strictly needed to move kvm_allowed to arch_init.c.
>
> Not really, because kvm_allowed _can_ be used from once-compiled
> files. The attached patch makes kvm-all.c be compiled always, even if
> !CONFIG_KVM; functions that require kvm are almost always omitted for
> now (so checking kvm_enabled() is required to call them). However,
> kvm_init is stubbed so that vl.c can call it.
>
> In the future we could add more stubbing and ultimately do this
> unconditionally:
>
> #define kvm_enabled() kvm_allowed
>
> With this patch vl.c can already be compiled once, but I did not
> include it because it would conflict with my balloon.c series; I'm
> doing enough rebasing these days. Also, qemu-kvm is a bit behind qemu
> and all these patches are nightmares for the merges, so it's better
> IMO if things are left to calm down a bit.
Having kvm-all.c compile with and without CONFIG_KVM is pretty ugly IMHO.
Is compiling vl.c once really that important of a goal? Wouldn't it be
better to split bits out of vl.c and have those compile once? Ideally,
vl.c should be so small that compiling per-target shouldn't matter.
Regards,
Anthony Liguori
>> They just caused problems with the poisoning check in patch 2/2.
>
> Poisoning kvm_enabled is right, but poisoning kvm_allowed is overkill.
>
> Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-02 15:08 ` Anthony Liguori
@ 2010-04-02 15:11 ` Paolo Bonzini
2010-04-02 15:20 ` Anthony Liguori
2010-04-02 15:43 ` Blue Swirl
1 sibling, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2010-04-02 15:11 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Blue Swirl, qemu-devel
On 04/02/2010 05:08 PM, Anthony Liguori wrote:
> Having kvm-all.c compile with and without CONFIG_KVM is pretty ugly IMHO.
>
> Is compiling vl.c once really that important of a goal?
I didn't do this to compile vl.c once. I don't care about that.
I did this as an initial step towards having kvm functions stubbed out
for !CONFIG_KVM, instead of relying on GCC performing
dead-code-elimination on kvm_enabled().
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-02 15:11 ` Paolo Bonzini
@ 2010-04-02 15:20 ` Anthony Liguori
2010-04-02 16:01 ` Paolo Bonzini
0 siblings, 1 reply; 12+ messages in thread
From: Anthony Liguori @ 2010-04-02 15:20 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Blue Swirl, qemu-devel
On 04/02/2010 10:11 AM, Paolo Bonzini wrote:
> On 04/02/2010 05:08 PM, Anthony Liguori wrote:
>> Having kvm-all.c compile with and without CONFIG_KVM is pretty ugly
>> IMHO.
>>
>> Is compiling vl.c once really that important of a goal?
>
> I didn't do this to compile vl.c once. I don't care about that.
>
> I did this as an initial step towards having kvm functions stubbed out
> for !CONFIG_KVM, instead of relying on GCC performing
> dead-code-elimination on kvm_enabled().
I'd prefer a kvm-stub.c implementation as opposed to mixing in
CONFIG_KVM in kvm-all.c
Regards,
Anthony Liguori
> Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-02 15:08 ` Anthony Liguori
2010-04-02 15:11 ` Paolo Bonzini
@ 2010-04-02 15:43 ` Blue Swirl
1 sibling, 0 replies; 12+ messages in thread
From: Blue Swirl @ 2010-04-02 15:43 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Paolo Bonzini, qemu-devel
On 4/2/10, Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 04/02/2010 10:01 AM, Paolo Bonzini wrote:
>
> > On 04/01/2010 10:27 PM, Blue Swirl wrote:
> >
> > > It will not be safe to use kvm_enabled() in vl.c, so there needs to be
> > > a target dependent helper. The call to kvm_init could remain in vl.c,
> > > likewise it's not strictly needed to move kvm_allowed to arch_init.c.
> > >
> >
> > Not really, because kvm_allowed _can_ be used from once-compiled files.
> The attached patch makes kvm-all.c be compiled always, even if !CONFIG_KVM;
> functions that require kvm are almost always omitted for now (so checking
> kvm_enabled() is required to call them). However, kvm_init is stubbed so
> that vl.c can call it.
> >
> > In the future we could add more stubbing and ultimately do this
> unconditionally:
> >
> > #define kvm_enabled() kvm_allowed
> >
> > With this patch vl.c can already be compiled once, but I did not include
> it because it would conflict with my balloon.c series; I'm doing enough
> rebasing these days. Also, qemu-kvm is a bit behind qemu and all these
> patches are nightmares for the merges, so it's better IMO if things are left
> to calm down a bit.
> >
>
> Having kvm-all.c compile with and without CONFIG_KVM is pretty ugly IMHO.
>
> Is compiling vl.c once really that important of a goal? Wouldn't it be
> better to split bits out of vl.c and have those compile once? Ideally, vl.c
> should be so small that compiling per-target shouldn't matter.
But the only thing preventing compiling whole vl.c once is just KVM
init. I'll send a new patch, hopefully it's better.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
@ 2010-04-02 15:46 Blue Swirl
0 siblings, 0 replies; 12+ messages in thread
From: Blue Swirl @ 2010-04-02 15:46 UTC (permalink / raw)
To: qemu-devel
Remove dependency of vl.c to KVM, then we can partially revert
b33612d03540fda7fa67485f1c20395beb7a2bf0.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
Makefile.objs | 2 +-
Makefile.target | 2 +-
arch_init.c | 5 +++++
arch_init.h | 1 +
kvm-all.c | 3 +++
kvm.h | 8 ++++++++
vl.c | 16 +++++-----------
7 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/Makefile.objs b/Makefile.objs
index 11e44a0..cb2ec2c 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -128,7 +128,7 @@ user-obj-y += cutils.o cache-utils.o
# libhw
hw-obj-y =
-hw-obj-y += loader.o
+hw-obj-y += vl.o loader.o
hw-obj-y += virtio.o virtio-console.o
hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
hw-obj-y += watchdog.o
diff --git a/Makefile.target b/Makefile.target
index 167fc8d..2aa02f5 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
# System emulator target
ifdef CONFIG_SOFTMMU
-obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o vl.o
+obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o
# virtio has to be here due to weird dependency between PCI and virtio-net.
# need to fix this properly
obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o
virtio-serial-bus.o
diff --git a/arch_init.c b/arch_init.c
index cfc03ea..055e65d 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -508,3 +508,8 @@ int xen_available(void)
return 0;
#endif
}
+
+int kvm_maybe_init(int smp_cpus)
+{
+ return kvm_init(smp_cpus);
+}
diff --git a/arch_init.h b/arch_init.h
index 682890c..52dd327 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -29,5 +29,6 @@ void cpudef_init(void);
int audio_available(void);
int kvm_available(void);
int xen_available(void);
+int kvm_maybe_init(int smp_cpus);
#endif
diff --git a/kvm-all.c b/kvm-all.c
index 7aa5e57..dc99aae 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -51,6 +51,8 @@ typedef struct KVMSlot
typedef struct kvm_dirty_log KVMDirtyLog;
+int kvm_allowed = 0;
+
struct KVMState
{
KVMSlot slots[32];
@@ -670,6 +672,7 @@ int kvm_init(int smp_cpus)
kvm_state = s;
cpu_register_phys_memory_client(&kvm_cpu_phys_memory_client);
+ kvm_allowed = 1;
return 0;
diff --git a/kvm.h b/kvm.h
index 1e5be27..979f640 100644
--- a/kvm.h
+++ b/kvm.h
@@ -34,7 +34,15 @@ struct kvm_run;
/* external API */
+#ifdef CONFIG_KVM
int kvm_init(int smp_cpus);
+#else
+static inline
+int kvm_init(int smp_cpus)
+{
+ return -ENOSYS;
+}
+#endif
#ifdef NEED_CPU_H
int kvm_init_vcpu(CPUState *env);
diff --git a/vl.c b/vl.c
index 6768cf1..6958b2c 100644
--- a/vl.c
+++ b/vl.c
@@ -145,7 +145,6 @@ int main(int argc, char **argv)
#include "dma.h"
#include "audio/audio.h"
#include "migration.h"
-#include "kvm.h"
#include "balloon.h"
#include "qemu-option.h"
#include "qemu-config.h"
@@ -241,7 +240,6 @@ uint8_t qemu_uuid[16];
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
-int kvm_allowed = 0;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_EMULATE;
@@ -2649,6 +2647,7 @@ int main(int argc, char **argv, char **envp)
#endif
int show_vnc_port = 0;
int defconfig = 1;
+ int enable_kvm = 0;
error_set_progname(argv[0]);
@@ -3239,7 +3238,7 @@ int main(int argc, char **argv, char **envp)
printf("Option %s not supported for this
target\n", popt->name);
exit(1);
}
- kvm_allowed = 1;
+ enable_kvm = 1;
break;
case QEMU_OPTION_usb:
usb_enabled = 1;
@@ -3585,14 +3584,9 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- if (kvm_enabled()) {
- int ret;
-
- ret = kvm_init(smp_cpus);
- if (ret < 0) {
- fprintf(stderr, "failed to initialize KVM\n");
- exit(1);
- }
+ if (enable_kvm && kvm_maybe_init(smp_cpus) < 0) {
+ fprintf(stderr, "failed to initialize KVM\n");
+ exit(1);
}
if (qemu_init_main_loop()) {
--
1.6.2.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once
2010-04-02 15:20 ` Anthony Liguori
@ 2010-04-02 16:01 ` Paolo Bonzini
0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2010-04-02 16:01 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Blue Swirl, qemu-devel
On 04/02/2010 05:20 PM, Anthony Liguori wrote:
>>
>> I didn't do this to compile vl.c once. I don't care about that.
>>
>> I did this as an initial step towards having kvm functions stubbed out
>> for !CONFIG_KVM, instead of relying on GCC performing
>> dead-code-elimination on kvm_enabled().
>
> I'd prefer a kvm-stub.c implementation as opposed to mixing in
> CONFIG_KVM in kvm-all.c
I tried it, but our build system makes it a mess because
compile-once-only can only be done using what once were static
libraries. All files from there are added blindly:
obj-y += $(addprefix ../, $(common-obj-y))
obj-y += $(addprefix ../libdis/, $(libdis-y))
obj-y += $(libobj-y)
obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y))
I'll try something.
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-04-02 16:01 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-01 20:07 [Qemu-devel] [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once Blue Swirl
2010-04-01 20:15 ` Anthony Liguori
2010-04-01 20:27 ` Blue Swirl
2010-04-02 15:01 ` [Qemu-devel] " Paolo Bonzini
2010-04-02 15:08 ` Anthony Liguori
2010-04-02 15:11 ` Paolo Bonzini
2010-04-02 15:20 ` Anthony Liguori
2010-04-02 16:01 ` Paolo Bonzini
2010-04-02 15:43 ` Blue Swirl
2010-04-01 20:23 ` Paolo Bonzini
2010-04-02 14:20 ` Blue Swirl
-- strict thread matches above, loose matches on Subject: below --
2010-04-02 15:46 [Qemu-devel] " Blue Swirl
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).