Fix building qemu-kvm for non KVM target
cover Fix building qemu-kvm for non KVM target
From: Jes Sorensen <[email protected]>
Hi,
This set of patches fixes building qemu-kvm for non KVM targets, as reported in
http://sourceforge.net/tracker/?func=detail&atid=893831&aid=2984626&group_id=180599
One of the main problem is that we have a tendency to move things from Makefile.objs to Makefile.target in order to be able to use TARGET_I386 etc in hw/*.c files. IMHO we need to start clamping down on this harder and move things into separate files rather than the #ifdef hacks. Hence this patch fixes the short term problem, but there is more work to do for the longer term.
Cheers,
Jes
Jes Sorensen (7):
Only call kvm_set_irqfd() if CONFIG_KVM is defined
No need for kvm_init() stub as already defined in qemu-kvm.h time_drift_fix is x86 only, rather than !ia64
Build certain drivers for MIPS as well.
Only export phys_mem create functions for !CONFIG_USER_ONLY builds Only treat KVM specific cmdline options for KVM enabled builds Only accept -no-hpet for i386 targets
Makefile.target | 2 ++ hw/i8259.c | 2 +- hw/virtio-pci.c | 4 ++++ kvm-stub.c | 5 ----- qemu-kvm.h | 2 ++ vl.c | 4 ++++ 6 files changed, 13 insertions(+), 6 deletions(-)
PATCH 1/7 Only call kvm_set_irqfd() if CONFIG_KVM is defined
From: Jes Sorensen <[email protected]>
Only call kvm_set_irqfd() if CONFIG_KVM is defined to avoid breaking the build for non x86.
--- hw/virtio-pci.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
hw/virtio-pci.c +4 -0
@@ -431,6 +431,7 @@ static void virtio_pci_guest_notifier_read(void *opaque)static int virtio_pci_mask_notifier (PCIDevice *dev,unsigned vector,void *opaque,int masked) { +#ifdef CONFIG_KVM VirtQueue *vq = opaque;EventNotifier *notifier =virtio_queue_get_guest_notifier (vq); int r = kvm_set_irqfd(dev->msix_irq_entries[vector].gsi,
@@ -447,6 +448,9 @@ static int virtio_pci_mask_notifier(PCIDevice *dev, unsigned vector, NULL, NULL, NULL); }return 0 ; +#else +return -ENOSYS ; +#endif }static int virtio_pci_set_guest_notifier (void *opaque,int n,bool assign)
Signature · 1 line
1.6.6.1
[Qemu-devel] Re: [PATCH 1/7] Only call kvm_set_irqfd() if CONFIG_KVM is defined
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only call
kvm_set_irqfd()ifCONFIG_KVMis defined to avoid breaking the build for non x86.
You can just add a stub to kvm-stub.c that returns -ENOSYS.
Paolo
[Qemu-devel] Re: [PATCH 1/7] Only call kvm_set_irqfd() if CONFIG_KVM is defined
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only call
kvm_set_irqfd()ifCONFIG_KVMis defined to avoid breaking the build for non x86.You can just add a stub to
kvm-stub.cthat returns-ENOSYS.Paolo
It's more than that, the code also uses bits in the msix code that isn't globally available.
Cheers,
Jes
[Qemu-devel] Re: [PATCH 1/7] Only call kvm_set_irqfd() if CONFIG_KVM is defined
Quoted 7 lines · Jes Sorensen
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only call
kvm_set_irqfd()ifCONFIG_KVMis defined to avoid breaking the build for non x86.
Quoted 6 lines
Quoted 3 lines
You can just add a stub to
kvm-stub.cthat returns-ENOSYS.Paolo
It's more than that, the code also uses bits in the msix code that isn't globally available.
I see now. BTW, my eventnotifier series conflicts with this part of qemu-kvm, so it's probably better if I work that series out in qemu-kvm first and then upstream. As I would touch this code anyway, I think your patch is fine even if it were be only a stopgap measure.
Maybe the right fix, which I could include in my series, is to change kvm_set_irqfd's calling convention to be like this:
int r = kvm_set_irqfd(&dev->msix_irq_entries[vector],
event_notifier_get_fd(notifier),
!masked);and extract the gsi in the function. Michael, does this make any sense?
Paolo
[Qemu-devel] Re: [PATCH 1/7] Only call kvm_set_irqfd() if CONFIG_KVM is defined
Quoted 23 lines · Paolo Bonzini
Quoted 7 lines · Jes Sorensen
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only call
kvm_set_irqfd()ifCONFIG_KVMis defined to avoid breaking the build for non x86.Quoted 6 lines
Quoted 3 lines
You can just add a stub to
kvm-stub.cthat returns-ENOSYS.Paolo
It's more than that, the code also uses bits in the msix code that isn't globally available.
I see now. BTW, my eventnotifier series conflicts with this part of qemu-kvm, so it's probably better if I work that series out in qemu-kvm first and then upstream. As I would touch this code anyway, I think your patch is fine even if it were be only a stopgap measure.
Maybe the right fix, which I could include in my series, is to change kvm_set_irqfd's calling convention to be like this:
Quoted 7 lines
int r = kvm_set_irqfd(&dev->msix_irq_entries[vector], event_notifier_get_fd(notifier), !masked);and extract the gsi in the function. Michael, does this make any sense?
Paolo
I'm fine with this change.
PATCH 2/7 No need for kvm_init() stub as already defined in qemu-kvm.h
In reply to [email protected]From: Jes Sorensen <[email protected]>
No need for kvm_init() stub in kvm-stub.c as already defined in qemu-kvm.h
--- kvm-stub.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
kvm-stub.c +0 -5
@@ -57,11 +57,6 @@ int kvm_check_extension(KVMState *s, unsigned int extension)return 0 ; } -int kvm_init (int smp_cpus) -{ -return -ENOSYS ; -} -void kvm_flush_coalesced_mmio_buffer (void ) { }
Signature · 1 line
1.6.6.1
[Qemu-devel] Re: [PATCH 2/7] No need for kvm_init() stub as already defined in qemu-kvm.h
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
No need for
kvm_init()stub inkvm-stub.cas already defined inqemu-kvm.h
Why not keep the other one and match upstream? Instead, I'd remove this one and move kvm_inject_x86_mce to kvm-stub.c.
Files that upstream compiles only once will be compiled only without CONFIG_KVM, and will always call the stubs if these are in qemu-kvm.h.
Paolo
[Qemu-devel] Re: [PATCH 2/7] No need for kvm_init() stub as already defined in qemu-kvm.h
Quoted 11 lines · Paolo Bonzini
Quoted 4 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
No need for
kvm_init()stub inkvm-stub.cas already defined inqemu-kvm.hWhy not keep the other one and match upstream? Instead, I'd remove this one and move
kvm_inject_x86_mcetokvm-stub.c.Files that upstream compiles only once will be compiled only without
CONFIG_KVM, and will always call the stubs if these are inqemu-kvm.h.
You're right, time for a v3 of the patch....
Cheers,
Jes
PATCH 3/7 time_drift_fix is x86 only, rather than !ia64
In reply to [email protected]From: Jes Sorensen <[email protected]>
time_drift_fix is x86 only, rather than !ia64, to allow the code to build for other archs, like MIPS.
--- hw/i8259.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/i8259.c +1 -1
@@ -237,7 +237,7 @@ int pic_read_irq(PicState2 *s)if (irq >=0 ) {pic_intack (&s->pics[0 ], irq); -#ifndef TARGET_IA64 +#ifdef TARGET_I386 if (time_drift_fix && irq ==0 ) {extern int64_t timer_acks, timer_ints_to_push; timer_acks++;
Signature · 1 line
1.6.6.1
PATCH 4/7 Build certain drivers for MIPS as well.
In reply to [email protected]From: Jes Sorensen <[email protected]>
pcspk.o i8254.o acpi.o acpi_piix4.o are all required for MIPS as well, add them to Makefile.target accordingly.
--- Makefile.target | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
Makefile.target +2 -0
@@ -245,6 +245,8 @@ obj-ppc-$(CONFIG_KVM) += kvm_ppc.o obj-ppc-$(CONFIG_FDT) += device_tree.o obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o +obj-mips-y += pcspk.o i8254.o +obj-mips-y += acpi.o acpi_piix4.o obj-mips-y += mips_addr.o mips_timer.o mips_int.o obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o
Signature · 1 line
1.6.6.1
PATCH 5/7 Only export phys_mem create functions for !CONFIG_USER_ONLY builds
In reply to [email protected]From: Jes Sorensen <[email protected]>
Only export phys_mem create functions for !CONFIG_USER_ONLY builds
--- qemu-kvm.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
qemu-kvm.h +2 -0
@@ -812,6 +812,7 @@ void qemu_kvm_cpuid_on_env(CPUState *env);void kvm_inject_interrupt (CPUState *env,int mask);void kvm_update_after_sipi (CPUState *env);void kvm_update_interrupt_request (CPUState *env); +#ifndef CONFIG_USER_ONLY void *kvm_cpu_create_phys_mem (target_phys_addr_t start_addr,unsigned long size,int log,int writable);
@@ -819,6 +820,7 @@ void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr, unsigned long size);void kvm_qemu_log_memory (target_phys_addr_t start,target_phys_addr_t size,int log); +#endif int kvm_qemu_create_memory_alias (uint64_t phys_start,uint64_t len,uint64_t target_phys);int kvm_qemu_destroy_memory_alias (uint64_t phys_start);
Signature · 1 line
1.6.6.1
[Qemu-devel] Re: [PATCH 5/7] Only export phys_mem create functions for !CONFIG_USER_ONLY builds
Quoted 22 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only export
phys_memcreate functions for !CONFIG_USER_ONLY buildsSigned-off-by Jes Sorensen<[email protected]>--- qemu-kvm.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)qemu-kvm.h +1
-0@@ -812,6 +812,7 @@ void qemu_kvm_cpuid_on_env(CPUState *env);void kvm_inject_interrupt (CPUState *env,int mask);void kvm_update_after_sipi (CPUState *env);void kvm_update_interrupt_request (CPUState *env); +#ifndef CONFIG_USER_ONLY void *kvm_cpu_create_phys_mem (target_phys_addr_t start_addr,unsigned long size,int log,int writable);
qemu-kvm.h void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr, · line 826
Quoted 7 lines
qemu-kvm.h +1
-0@@ -819,6 +820,7 @@ void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr, unsigned long size);void kvm_qemu_log_memory (target_phys_addr_t start,target_phys_addr_t size,int log); +#endif int kvm_qemu_create_memory_alias (uint64_t phys_start,uint64_t len,uint64_t target_phys);int kvm_qemu_destroy_memory_alias (uint64_t phys_start);
Paolo
PATCH 6/7 Only treat KVM specific cmdline options for KVM enabled builds
In reply to [email protected]From: Jes Sorensen <[email protected]>
Only treat KVM specific cmdline options for KVM enabled builds. This fixes build breakage for target MIPS etc.
--- vl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
vl.c +2 -0
@@ -3264,6 +3264,7 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_kvm: kvm_allowed =0 ;break ; +#ifdef CONFIG_KVM case QEMU_OPTION_no_kvm_irqchip: { kvm_irqchip =0 ; kvm_pit =0 ;
@@ -3281,6 +3282,7 @@ int main(int argc, char **argv, char **envp) kvm_nested =1 ;break ; } +#endif #if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) || defined(TARGET_IA64 ) || defined(__linux__)case QEMU_OPTION_pcidevice:if (assigned_devices_index >=MAX_DEV_ASSIGN_CMDLINE ) {
Signature · 1 line
1.6.6.1
PATCH 7/7 Only accept -no-hpet for i386 targets
In reply to [email protected]From: Jes Sorensen <[email protected]>
Only accept -no-hpet for i386 targets
--- vl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
vl.c +2 -0
@@ -3328,9 +3328,11 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ; +#ifdef TARGET_I386 case QEMU_OPTION_no_hpet: no_hpet =1 ;break ; +#endif case QEMU_OPTION_balloon:if (balloon_parse (optarg) <0 ) {fprintf (stderr,"Unknown -balloon argument %s\n" , optarg);
Signature · 1 line
1.6.6.1
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
Quoted 15 lines · [email protected] wrote:
From: Jes Sorensen <[email protected]>
Only accept -no-hpet for i386 targets
Signed-off-by Jes Sorensen <[email protected]>--- vl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)vl.c +0
-0@@ -3328,9 +3328,11 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_acpi:
vl.c int main(int argc, char **argv, char **envp) · line 3338
Quoted 10 lines
vl.c +2
-0acpi_enabled =0 ;break ; +#ifdef TARGET_I386 case QEMU_OPTION_no_hpet: no_hpet =1 ;break ; +#endif case QEMU_OPTION_balloon:if (balloon_parse (optarg) <0 ) {fprintf (stderr,"Unknown -balloon argument %s\n" , optarg);
Upstream carries no-hpet unconditionally now. I guess you need to clean up a different merge artifact.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
vl.c +1
-0@@ -3328,9 +3328,11 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ; +#ifdef TARGET_I386 case QEMU_OPTION_no_hpet: no_hpet =1 ;
Quoted 8 lines
vl.c int main(int argc, char **argv, char **envp) · line 3338
Quoted 5 lines
vl.c +1
-0break ; +#endif case QEMU_OPTION_balloon:if (balloon_parse (optarg) <0 ) {fprintf (stderr,"Unknown -balloon argument %s\n" , optarg);Upstream carries no-hpet unconditionally now. I guess you need to clean up a different merge artifact.
Upstream seems to have removed the TARGET_I386 around 'int no_hpet = 0;' but to be honest, I think the correct solution is to not expose no_hpet to non x86 targets in upstream.
Cheers,
Jes
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
Quoted 16 lines · Jes Sorensen
Quoted 6 lines · Jan Kiszka
Quoted 6 lines
vl.c +1
-0@@ -3328,9 +3328,11 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ; +#ifdef TARGET_I386 case QEMU_OPTION_no_hpet:Quoted 8 lines
vl.c int main(int argc, char **argv, char **envp) · line 3338
Quoted 6 lines
vl.c +1
-0no_hpet =1 ;break ; +#endif case QEMU_OPTION_balloon:if (balloon_parse (optarg) <0 ) {fprintf (stderr,"Unknown -balloon argument %s\n" , optarg);Upstream carries no-hpet unconditionally now. I guess you need to clean up a different merge artifact.
Quoted 3 lines
Upstream seems to have removed the
TARGET_I386around 'intno_hpet= 0;' but to be honest, I think the correct solution is to not exposeno_hpetto non x86 targets in upstream.
Then I would suggest to address this upstream first. The goal should be to keep the diff low.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
Quoted 6 lines · Jan Kiszka
Quoted 3 lines
Upstream seems to have removed the
TARGET_I386around 'intno_hpet= 0;' but to be honest, I think the correct solution is to not exposeno_hpetto non x86 targets in upstream.Then I would suggest to address this upstream first. The goal should be to keep the diff low.
I agree, I'll send out an updated diff in a minute to make qemu-kvm closer to qemu and then look at option exposure in qemu afterwards.
Cheers,
Jes
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
In reply to [email protected]Quoted 15 lines · On 06/15/2010 01:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Only accept -no-hpet for i386 targets
Signed-off-by Jes Sorensen<[email protected]>--- vl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)vl.c +0
-0@@ -3328,9 +3328,11 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_no_acpi:
vl.c int main(int argc, char **argv, char **envp) · line 3338
Quoted 10 lines
vl.c +2
-0acpi_enabled =0 ;break ; +#ifdef TARGET_I386 case QEMU_OPTION_no_hpet: no_hpet =1 ;break ; +#endif case QEMU_OPTION_balloon:if (balloon_parse (optarg)<0 ) {fprintf (stderr,"Unknown -balloon argument %s\n" , optarg);
This can alternatively be made to match upstream by just removing the #ifdef on no_hpet's declaration.
Not saying that -no-hpet makes any sense on non-i386 targets, mind, but it seems pointless to deviate from upstream.
Paolo
[Qemu-devel] Re: [PATCH 7/7] Only accept -no-hpet for i386 targets
Quoted 7 lines · Paolo Bonzini
This can alternatively be made to match upstream by just removing the #ifdef on no_hpet's declaration.
Not saying that -no-hpet makes any sense on non-i386 targets, mind, but it seems pointless to deviate from upstream.
Paolo
Fixed in v2 of the patchset.
Jes
Quoted 8 lines · On 06/15/2010 02:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Hi,
This set of patches fixes building qemu-kvm for non KVM targets, as reported in
http://sourceforge.net/tracker/?func=detail&atid=893831&aid=2984626&group_id=180599
Quoted 7 lines
One of the main problem is that we have a tendency to move things from Makefile.objs to Makefile.target in order to be able to use
TARGET_I386etc in hw/*.c files. IMHO we need to start clamping down on this harder and move things into separate files rather than the #ifdef hacks. Hence this patch fixes the short term problem, but there is more work to do for the longer term.
It's the other way round. Upstream keeps moving stuff out of Makefile.target, and I move them back during merges, because the only thing I can think of during a merge is "how quickly can I complete this merge".
Thanks for tackling this.
Signature · 1 line
error compiling committee.c: too many arguments to function
Avi Kivity
Reviewed-byQuoted 17 lines · Avi Kivity
Quoted 9 lines · On 06/15/2010 02:04 PM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
Hi,
This set of patches fixes building qemu-kvm for non KVM targets, as reported in
http://sourceforge.net/tracker/?func=detail&atid=893831&aid=2984626&group_id=180599Quoted 6 lines
One of the main problem is that we have a tendency to move things from Makefile.objs to Makefile.target in order to be able to use
TARGET_I386etc in hw/*.c files. IMHO we need to start clamping down on this harder and move things into separate files rather than the #ifdef hacks. Hence this patch fixes the short term problem, but there is more work to do for the longer term.
Quoted 4 lines
It's the other way round. Upstream keeps moving stuff out of Makefile.target, and I move them back during merges, because the only thing I can think of during a merge is "how quickly can I complete this merge".
Thanks for tackling this.
Oh, I though you actually moved things back.
Anyway,
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines · Avi Kivity
It's the other way round. Upstream keeps moving stuff out of Makefile.target, and I move them back during merges, because the only thing I can think of during a merge is "how quickly can I complete this merge".
Thanks for tackling this.
I see. I found at least some of the cases I was tackling was because things had moved from .objs to .target because of the TARGET_I386 checks. Trying to use TARGET_I386 in a file that is listed in Makefile.objs causes nasty warnings.
I would very much like it if we can be more strict not allowing such changes without a very strong reason in the future :)
Part of the problem is of course that there are no easy ways to check for the presence of say HPET since we don't have CONFIG_HPET so TARGET_I386 becomes the easy way :(
Cheers,
Jes
Quoted 13 lines · Jes Sorensen
Quoted 6 lines · Avi Kivity
It's the other way round. Upstream keeps moving stuff out of Makefile.target, and I move them back during merges, because the only thing I can think of during a merge is "how quickly can I complete this merge".
Thanks for tackling this.
I see. I found at least some of the cases I was tackling was because things had moved from .objs to .target because of the
TARGET_I386checks. Trying to useTARGET_I386in a file that is listed in Makefile.objs causes nasty warnings.
Quoted 6 lines
I would very much like it if we can be more strict not allowing such changes without a very strong reason in the future :)
Part of the problem is of course that there are no easy ways to check for the presence of say HPET since we don't have
CONFIG_HPETsoTARGET_I386becomes the easy way :(
On my hpet removal patches, the important bit was that I enabled #define CONFIG_HPET 1
in C land, that makes it easy to do this kind of tests. As it is today, it is very difficult to test for a feature, as we only have TARGET_* defines.
Instead of CONFIG_HPET, we have TARGET_I386.
Later, Juan.
Quoted 8 lines · Juan Quintela
On my hpet removal patches, the important bit was that I enabled #define
CONFIG_HPET1in C land, that makes it easy to do this kind of tests. As it is today, it is very difficult to test for a feature, as we only have TARGET_* defines.
Instead of
CONFIG_HPET, we haveTARGET_I386.
I totally agree, and I'd like to see things like HPET becoming config options. Even for I386 builds, it may not be everybody who wants to build it in.
Cheers,
Jes