Skip to contentSkip to conversation

x86/jailhouse: fix building without X86_X2APIC

PATCH In review Arnd Bergmann 2 participants 7 messages Jan 15, 2018 – Jan 16, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/jailhouse: fix building without X86_X2APIC

When CONFIG_X86_X2APIC is disabled, jailhouse fails to build:

arch/x86/kernel/jailhouse.c: In function 'jailhouse_get_smp_config':
arch/x86/kernel/jailhouse.c:73:3: error: 'x2apic_phys' undeclared (first use in this function); did you mean 'x2apic_mode'?

The code is protected by an appropriate x2apic_enabled() check that leads to the assignment being optimized out without a link-time reference to x2apic_phys, so we just lack a declaration.

Let's move x2apic_mode and x2apic_phys outside of the #ifdef together, for consistency.

Fixes 11c8dc419bbc ("x86/jailhouse: Enable APIC and SMP support")
---
 arch/x86/include/asm/apic.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/apic.h +2 -2
index 98722773391d..0317d635d9ba 100644
@@ -188,6 +188,8 @@ static inline void lapic_assign_system_vectors(void) { }
 static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { }
 #endif /* !CONFIG_X86_LOCAL_APIC */
 
+extern int x2apic_mode;
+extern int x2apic_phys;
 #ifdef CONFIG_X86_X2APIC
 /*
  * Make previous memory operations globally visible before
@@ -249,8 +251,6 @@ static inline u64 native_x2apic_icr_read(void)
 	return val;
 }
 
-extern int x2apic_mode;
-extern int x2apic_phys;
 extern void __init check_x2apic(void);
 extern void x2apic_setup(void);
 static inline int x2apic_enabled(void)
Signature · 1 line
2.9.0
#1 lore raw

Hi Arnd,

Quoted 23 lines · Arnd Bergmann

When CONFIG_X86_X2APIC is disabled, jailhouse fails to build:

arch/x86/kernel/jailhouse.c: In function 'jailhouse_get_smp_config':
arch/x86/kernel/jailhouse.c:73:3: error: 'x2apic_phys' undeclared (first use in this function); did you mean 'x2apic_mode'?

The code is protected by an appropriate x2apic_enabled() check that leads to the assignment being optimized out without a link-time reference to x2apic_phys, so we just lack a declaration.

Let's move x2apic_mode and x2apic_phys outside of the #ifdef together, for consistency.

Fixes 11c8dc419bbc ("x86/jailhouse: Enable APIC and SMP support")
---
  arch/x86/include/asm/apic.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/apic.h +0 -0
index 98722773391d..0317d635d9ba 100644

arch/x86/include/asm/apic.h static inline void lapic_assign_system_vectors(void) { } · line 192

Quoted 5 lines
arch/x86/include/asm/apic.h +2 -0
@@ -188,6 +188,8 @@ static inline void lapic_assign_system_vectors(void) { }
  static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { }
  #endif /* !CONFIG_X86_LOCAL_APIC */
 
+extern int x2apic_mode;
+extern int x2apic_phys;

We can't do that, adding a macro for the X2APIC=n case is enough

Thanks,
dou

-------------------------8<----------------------

Subject: [PATCH] x86/apic: Add a macro named x2apic_phys for the X2APIC=n case

The x86 system may build failed in the X2APIC=n case, due to the missing of x2apic_phys.

So add a macro named x2apic_phys for the X2APIC=n case.

---
 arch/x86/include/asm/apic.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/apic.h +2 -1
index a9e57f08bfa6..ca5940fb995a 100644
@@ -264,7 +264,8 @@ static inline void x2apic_setup(void) { }
 static inline int x2apic_enabled(void) { return 0; }
 
 #define x2apic_mode		(0)
-#define	x2apic_supported()	(0)
+#define x2apic_phys		(0)
+#define x2apic_supported()	(0)
 #endif /* !CONFIG_X86_X2APIC */
 
 struct irq_data;
#2 lore raw

Hi Arnd,

Quoted 21 lines · Dou Liyang

Hi Arnd,

Quoted 18 lines · Arnd Bergmann

When CONFIG_X86_X2APIC is disabled, jailhouse fails to build:

arch/x86/kernel/jailhouse.c: In function 'jailhouse_get_smp_config':
arch/x86/kernel/jailhouse.c:73:3: error: 'x2apic_phys' undeclared (first use in this function); did you mean 'x2apic_mode'?

The code is protected by an appropriate x2apic_enabled() check that leads to the assignment being optimized out without a link-time reference to x2apic_phys, so we just lack a declaration.

Let's move x2apic_mode and x2apic_phys outside of the #ifdef together, for consistency.

Fixes 11c8dc419bbc ("x86/jailhouse: Enable APIC and SMP support")

---
  arch/x86/include/asm/apic.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

arch/x86/include/asm/apic.h static inline void · line 192

Quoted 10 lines
arch/x86/include/asm/apic.h +2 -0
index 98722773391d..0317d635d9ba 100644
@@ -188,6 +188,8 @@ static inline void 
 lapic_assign_system_vectors(void) { }
   static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { }
   #endif /* !CONFIG_X86_LOCAL_APIC */
+extern int x2apic_mode;
+extern int x2apic_phys;

We can't do that, adding a macro for the X2APIC=n case is enough

I am sorry when I looked into your code in tip tree. I found this measure is not true. please try the the following v2 patch.

The reason I don't want to expose the x2apic_mode and x2apic_phys is that they may be misused in X2APIC=n case. So I create an interface to wrap it. do you think so? ;-)

Thanks,
dou.

---
 arch/x86/include/asm/apic.h | 10 +++++++++-
 arch/x86/kernel/apic/apic.c |  2 +-
 arch/x86/kernel/jailhouse.c |  2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)
arch/x86/include/asm/apic.h +9 -1
index 98722773391d..ac25ac2e49af 100644
@@ -251,6 +251,11 @@ static inline u64 native_x2apic_icr_read(void)
 
 extern int x2apic_mode;
 extern int x2apic_phys;
+static inline void apic_set_x2apic_phys(void)
+{
+	x2apic_phys = 1;
+}
+
 extern void __init check_x2apic(void);
 extern void x2apic_setup(void);
 static inline int x2apic_enabled(void)
@@ -265,7 +270,10 @@ static inline void x2apic_setup(void) { }
 static inline int x2apic_enabled(void) { return 0; }
 
 #define x2apic_mode		(0)
-#define	x2apic_supported()	(0)
+#define x2apic_phys		(0)
+#define x2apic_supported()	(0)
+
+static inline void apic_set_x2apic_phys(void){}
 #endif /* !CONFIG_X86_X2APIC */
 
 struct irq_data;
arch/x86/kernel/apic/apic.c +1 -1
index 25ddf02598d2..440ff200104f 100644
@@ -1746,7 +1746,7 @@ static __init void try_to_enable_x2apic(int remap_mode)
 		 * without IR all CPUs can be addressed by IOAPIC/MSI
 		 * only in physical mode
 		 */
-		x2apic_phys = 1;
+		apic_set_x2apic_phys();
 	}
 	x2apic_enable();
 }
arch/x86/kernel/jailhouse.c +1 -1
index d6d5976a9b51..ce62162efcf2 100644
@@ -70,7 +70,7 @@ static void __init jailhouse_get_smp_config(unsigned int early)
 		 * We do not have access to IR inside Jailhouse non-root cells.
 		 * So we have to run in physical mode.
 		 */
-		x2apic_phys = 1;
+		apic_set_x2apic_phys();
 
 		/*
 		 * This will trigger the switch to apic_x2apic_phys.
Quoted 31 lines

Thanks,
    dou

-------------------------8<----------------------

Subject: [PATCH] x86/apic: Add a macro named x2apic_phys for the X2APIC=n case

The x86 system may build failed in the X2APIC=n case, due to the missing of x2apic_phys.

So add a macro named x2apic_phys for the X2APIC=n case.

---
  arch/x86/include/asm/apic.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/apic.h +2 -1
index a9e57f08bfa6..ca5940fb995a 100644
@@ -264,7 +264,8 @@ static inline void x2apic_setup(void) { }
  static inline int x2apic_enabled(void) { return 0; }
 
  #define x2apic_mode        (0)
-#define    x2apic_supported()    (0)
+#define x2apic_phys        (0)
+#define x2apic_supported()    (0)
  #endif /* !CONFIG_X86_X2APIC */
 
  struct irq_data;
#3 lore raw
Quoted 16 lines · Dou Liyang
Quoted 5 lines · Dou Liyang
Quoted 5 lines
arch/x86/include/asm/apic.h +0 -0
index 98722773391d..0317d635d9ba 100644
@@ -188,6 +188,8 @@ static inline void lapic_assign_system_vectors(void)
Quoted 9 lines

arch/x86/include/asm/apic.h static inline void lapic_assign_system_vectors(void) · line 193

Quoted 6 lines
arch/x86/include/asm/apic.h +2 -0
 { }
  static inline void lapic_assign_legacy_vector(unsigned int i, bool r) {
 }
  #endif /* !CONFIG_X86_LOCAL_APIC */
+extern int x2apic_mode;
+extern int x2apic_phys;

We can't do that, adding a macro for the X2APIC=n case is enough

Quoted 6 lines

I am sorry when I looked into your code in tip tree. I found this measure is not true. please try the the following v2 patch.

The reason I don't want to expose the x2apic_mode and x2apic_phys is that they may be misused in X2APIC=n case. So I create an interface to wrap it. do you think so? ;-)

I'm not sure I follow what the intention of that is. If you want to hide those two variables, maybe make them 'static' and remove the extern declarations?

Quoted 18 lines
arch/x86/include/asm/apic.h +5 -0
index 98722773391d..ac25ac2e49af 100644
@@ -251,6 +251,11 @@ static inline u64 native_x2apic_icr_read(void)
 
 extern int x2apic_mode;
 extern int x2apic_phys;
+static inline void apic_set_x2apic_phys(void)
+{
+       x2apic_phys = 1;
+}
+
 extern void __init check_x2apic(void);
 extern void x2apic_setup(void);
 static inline int x2apic_enabled(void)
@@ -265,7 +270,10 @@ static inline void x2apic_setup(void) { }
 static inline int x2apic_enabled(void) { return 0; }

arch/x86/include/asm/apic.h static inline void x2apic_setup(void) { } · line 279

Quoted 10 lines
arch/x86/include/asm/apic.h +4 -1
 
 #define x2apic_mode            (0)
-#define        x2apic_supported()      (0)
+#define x2apic_phys            (0)
+#define x2apic_supported()     (0)
+
+static inline void apic_set_x2apic_phys(void){}
 #endif /* !CONFIG_X86_X2APIC */
 
 struct irq_data;

I see nothing wrong it with this, but also don't see anything it does that improves the interface.

Arnd

#4 lore raw

Hi Arnd,

[...]

Quoted 5 lines
Quoted 3 lines

The reason I don't want to expose the x2apic_mode and x2apic_phys is that they may be misused in X2APIC=n case. So I create an interface to wrap it. do you think so? ;-)

I'm not sure I follow what the intention of that is. If you want to hide

My purpose of that is hiding the variables in X2APIC=n case.

Quoted 3 lines

those two variables, maybe make them 'static' and remove the extern declarations?

Yes, that's what I really want, But due to the simple "x2apic_phys= 1" operation, doing that may be too fat, I guess.

Quoted 27 lines
Quoted 27 lines
arch/x86/include/asm/apic.h +9 -1
index 98722773391d..ac25ac2e49af 100644
@@ -251,6 +251,11 @@ static inline u64 native_x2apic_icr_read(void)
 
  extern int x2apic_mode;
  extern int x2apic_phys;
+static inline void apic_set_x2apic_phys(void)
+{
+       x2apic_phys = 1;
+}
+
  extern void __init check_x2apic(void);
  extern void x2apic_setup(void);
  static inline int x2apic_enabled(void)
@@ -265,7 +270,10 @@ static inline void x2apic_setup(void) { }
  static inline int x2apic_enabled(void) { return 0; }
 
  #define x2apic_mode            (0)
-#define        x2apic_supported()      (0)
+#define x2apic_phys            (0)
+#define x2apic_supported()     (0)
+
+static inline void apic_set_x2apic_phys(void){}
  #endif /* !CONFIG_X86_X2APIC */
 
Quoted 5 lines

arch/x86/include/asm/apic.h static inline void x2apic_setup(void) { } · line 279

Quoted 1 line
arch/x86/include/asm/apic.h +0 -0
  struct irq_data;

I see nothing wrong it with this, but also don't see anything it does that improves the interface.

Another way we can choice is wrap the code with "CONFIG_X86_X2APIC".

Thanks,
dou
--------------------------------8<------------------------------------

arch/x86/kernel/jailhouse.c +1 -0
index d6d5976a9b51..d4aee43c8912 100644
@@ -65,6 +65,7 @@ static void __init jailhouse_get_smp_config(unsigned int early)
        };
        unsigned int cpu;
 
+#ifdef CONFIG_X86_X2APIC
        if (x2apic_enabled()) {
                /*
                 * We do not have access to IR inside Jailhouse 

non-root cells.
@@ -79,6 +80,7 @@ static void __init jailhouse_get_smp_config(unsigned int early)

                 */
                default_acpi_madt_oem_check("", "");
        }

+#endif

        register_lapic_address(0xfee00000);
Quoted 4 lines

Arnd

#5 lore raw
Quoted 9 lines · Dou Liyang

Hi Arnd,

[...]

Quoted 6 lines
Quoted 4 lines

The reason I don't want to expose the x2apic_mode and x2apic_phys is that they may be misused in X2APIC=n case. So I create an interface to wrap it. do you think so? ;-)

Quoted 4 lines
Quoted 1 line

I'm not sure I follow what the intention of that is. If you want to hide

My purpose of that is hiding the variables in X2APIC=n case.

But why? I'd say either hide them all the time, or don't hide them at all.

Quoted 6 lines
Quoted 3 lines

I see nothing wrong it with this, but also don't see anything it does that improves the interface.

Another way we can choice is wrap the code with "CONFIG_X86_X2APIC".

But why? That just makes perfectly reasonably code uglier. Generally speaking, compiler conditionals are better than preprocessor conditionals for this, as they are easier to read and provide better compile-time coverage when things go wrong, such as the missing declaration.

Arnd

Quoted 21 lines

--------------------------------8<------------------------------------

arch/x86/kernel/jailhouse.c +1 -0
index d6d5976a9b51..d4aee43c8912 100644
@@ -65,6 +65,7 @@ static void __init jailhouse_get_smp_config(unsigned int
 early)
        };
        unsigned int cpu;
 
+#ifdef CONFIG_X86_X2APIC
        if (x2apic_enabled()) {
                /*

* We do not have access to IR inside Jailhouse non-root
cells.

arch/x86/kernel/jailhouse.c +1 -0
@@ -79,6 +80,7 @@ static void __init jailhouse_get_smp_config(unsigned int
 early)
                 */
                default_acpi_madt_oem_check("", "");
        }
+#endif
#6 lore raw

Hi Arnd,

Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Dou Liyang

Hi Arnd,

[...]

Quoted 6 lines
Quoted 4 lines

The reason I don't want to expose the x2apic_mode and x2apic_phys is that they may be misused in X2APIC=n case. So I create an interface to wrap it. do you think so? ;-)

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I'm not sure I follow what the intention of that is. If you want to hide

My purpose of that is hiding the variables in X2APIC=n case.

But why? I'd say either hide them all the time, or don't hide them at all.

In this case, I prefer to hide them all the time.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I see nothing wrong it with this, but also don't see anything it does that improves the interface.

Quoted 8 lines
Quoted 2 lines

Another way we can choice is wrap the code with "CONFIG_X86_X2APIC".

But why? That just makes perfectly reasonably code uglier. Generally speaking, compiler conditionals are better than preprocessor conditionals for this, as they are easier to read and provide better compile-time coverage when things go wrong, such as the missing declaration.

Yes, Indeed. Thank you for telling me that.

Thanks,
dou.