qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] i386/kvm: Fix kvm_enable_x2apic link error in non-KVM builds


From: Phil Dennis-Jordan
Subject: Re: [PATCH] i386/kvm: Fix kvm_enable_x2apic link error in non-KVM builds
Date: Wed, 13 Nov 2024 19:14:51 +0100



On Wed 13. Nov 2024 at 19:06, Paolo Bonzini <pbonzini@redhat.com> wrote:
On 11/13/24 15:49, Phil Dennis-Jordan wrote:
> It appears that existing call sites for the kvm_enable_x2apic()
> function rely on the compiler eliding the calls during optimisation
> when building with KVM disabled, or on platforms other than Linux,
> where that function is declared but not defined.
>
> This fragile reliance recently broke down when commit b12cb38 added
> a new call site which apparently failed to be optimised away when
> building QEMU on macOS with clang, resulting in a link error.

That's weird, can you check the preprocessor output?  The definition
of kvm_irqchip_in_kernel() should be just "false" on macOS, in fact
even the area you're changing should be simplified like

Yeah, to be honest this header file seems a bit of a mess. It’s being #included by a bunch of .c files in hw/ despite being located in target/ not include/ which suggests to me that some of the declarations ought to be moved.

As I’m not really familiar with any of the KVM code base I would not normally be attempting to clean this up but the staging & master branches currently don’t build on macOS, so I was aiming for the simplest fix possible for the immediate problem.

(I will test your patch shortly however.)


diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h
index 9de9c0d3038..7edb154a16e 100644
--- a/target/i386/kvm/kvm_i386.h
+++ b/target/i386/kvm/kvm_i386.h
@@ -13,8 +13,7 @@

  #include "sysemu/kvm.h"

-#ifdef CONFIG_KVM
-
+/* always false if !CONFIG_KVM */
  #define kvm_pit_in_kernel() \
      (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
  #define kvm_pic_in_kernel()  \
@@ -22,14 +21,6 @@
  #define kvm_ioapic_in_kernel() \
      (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())

-#else
-
-#define kvm_pit_in_kernel()      0
-#define kvm_pic_in_kernel()      0
-#define kvm_ioapic_in_kernel()   0
-
-#endif  /* CONFIG_KVM */
-
  bool kvm_has_smm(void);
  bool kvm_enable_x2apic(void);

Paolo

>
> Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
> ---
>   target/i386/kvm/kvm_i386.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h
> index 9de9c0d3038..7ce47388d90 100644
> --- a/target/i386/kvm/kvm_i386.h
> +++ b/target/i386/kvm/kvm_i386.h
> @@ -21,17 +21,18 @@
>       (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
>   #define kvm_ioapic_in_kernel() \
>       (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
> +bool kvm_enable_x2apic(void);
>   
>   #else
>   
>   #define kvm_pit_in_kernel()      0
>   #define kvm_pic_in_kernel()      0
>   #define kvm_ioapic_in_kernel()   0
> +#define kvm_enable_x2apic()      0
>   
>   #endif  /* CONFIG_KVM */
>   
>   bool kvm_has_smm(void);
> -bool kvm_enable_x2apic(void);
>   bool kvm_hv_vpindex_settable(void);
>   bool kvm_enable_hypercall(uint64_t enable_mask);
>   


reply via email to

[Prev in Thread] Current Thread [Next in Thread]