Skip to contentSkip to conversation

x86: more flexible alignment handling for xen binary

PATCH Superseded Wei Liu 2 participants 6 messages Mar 18, 2019 – Mar 19, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover x86: more flexible alignment handling for xen binary

Wei Liu (2):
x86: decouple xen alignment setting from EFI/non-EFI build x86/pvshim: use 2M alignment

 xen/arch/x86/Kconfig                  | 26 ++++++++++++++++++++++++++
 xen/arch/x86/configs/pvshim_defconfig |  1 +
 xen/arch/x86/xen.lds.S                | 16 ++++++++++++++--
 3 files changed, 41 insertions(+), 2 deletions(-)
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH 1/2 x86: decouple xen alignment setting from EFI/non-EFI build

Introduce a new Kconfig option to pick the alignment for xen binary. To retain original behaviour, the default pick for EFI build is 2M and non-EFI build 4K.

---
 xen/arch/x86/Kconfig   | 26 ++++++++++++++++++++++++++
 xen/arch/x86/xen.lds.S | 16 ++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)
xen/arch/x86/Kconfig +26 -0
index 5c2d1070b6..b15053cfbe 100644
@@ -138,6 +138,32 @@ config TBOOT
 
 	  If unsure, say Y.
 
+choice
+	prompt "Alignment of Xen binary"
+	depends on X86
+	default XEN_ALIGN_DEFAULT
+	---help---
+	  Specify alignment for Xen binary.
+
+	  If unsure, choose "default".
+
+config XEN_ALIGN_DEFAULT
+	bool "Default alignment"
+	---help---
+	  Pick alignment according to build variants.
+
+	  For EFI build the default alignment is 2M. For non-EFI build
+	  the default alignment is 4K due to syslinux failing to handle
+	  2M alignment.
+
+config XEN_ALIGN_4K
+	bool "4K alignment"
+
+config XEN_ALIGN_2M
+	bool "2M alignment"
+
+endchoice
+
 config XEN_GUEST
 	def_bool n
 	prompt "Xen Guest"
xen/arch/x86/xen.lds.S +14 -2
index 6e9bda5109..163de31574 100644
@@ -12,7 +12,6 @@
 #define FORMAT "pei-x86-64"
 #undef __XEN_VIRT_START
 #define __XEN_VIRT_START __image_base__
-#define SECTION_ALIGN MB(2)
 #define DECL_SECTION(x) x :
 
 ENTRY(efi_start)
@@ -20,13 +19,26 @@ ENTRY(efi_start)
 #else /* !EFI */
 
 #define FORMAT "elf64-x86-64"
-#define SECTION_ALIGN PAGE_SIZE
 #define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START)
 
 ENTRY(start_pa)
 
 #endif /* EFI */
 
+#if defined CONFIG_XEN_ALIGN_2M
+#define SECTION_ALIGN MB(2)
+#elif defined CONFIG_XEN_ALIGN_4K
+#define SECTION_ALIGN PAGE_SIZE
+#elif defined CONFIG_XEN_ALIGN_DEFAULT
+    #ifdef EFI
+        #define SECTION_ALIGN MB(2)
+    #else
+        #define SECTION_ALIGN PAGE_SIZE
+    #endif
+#else
+#error "Section alignment undefined"
+#endif
+
 OUTPUT_FORMAT(FORMAT, FORMAT, FORMAT)
 
 OUTPUT_ARCH(i386:x86-64)
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [PATCH 1/2] x86: decouple xen alignment setting from EFI/non-EFI build

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 15:57, <[email protected]> wrote:

Introduce a new Kconfig option to pick the alignment for xen binary. To retain original behaviour, the default pick for EFI build is 2M and non-EFI build 4K.

Is this a worthwhile step to take, considering that we mean to switch to 2M main section boundaries anyway? I realize it's still not necessarily clear how to get there without re-introducing the boot regression with syslinux that was observed back then, but perhaps time would better be spent there than into introducing configurability? (To be honest I don't recall whether it was determined that there was no way out of this dilemma, but it seems to me there would have been a plan.)

Quoted 13 lines
xen/arch/x86/Kconfig +7 -0
@@ -138,6 +138,32 @@ config TBOOT
 
 	  If unsure, say Y.
 
+choice
+	prompt "Alignment of Xen binary"
+	depends on X86
+	default XEN_ALIGN_DEFAULT
+	---help---
+	  Specify alignment for Xen binary.
+

xen/arch/x86/Kconfig config TBOOT · line 157

Quoted 10 lines
xen/arch/x86/Kconfig +10 -0
+	  If unsure, choose "default".
+
+config XEN_ALIGN_DEFAULT
+	bool "Default alignment"
+	---help---
+	  Pick alignment according to build variants.
+
+	  For EFI build the default alignment is 2M. For non-EFI build
+	  the default alignment is 4K due to syslinux failing to handle
+	  2M alignment.

Wasn't it the resulting image size rather than the alignment itself which did cause the problem? Has the issue been fixed in newer syslinux?

xen/arch/x86/Kconfig config TBOOT · line 163

Quoted 5 lines
xen/arch/x86/Kconfig +5 -0
+config XEN_ALIGN_4K
+	bool "4K alignment"
+
+config XEN_ALIGN_2M
+	bool "2M alignment"

In patch 2 you only need the latter - is there really much value in allowing explicitly requesting 4k?

Quoted 14 lines
xen/arch/x86/Kconfig +3 -1
@@ -20,13 +19,26 @@ ENTRY(efi_start)
 #else /* !EFI */
 
 #define FORMAT "elf64-x86-64"
-#define SECTION_ALIGN PAGE_SIZE
 #define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START)
 
 ENTRY(start_pa)
 
 #endif /* EFI */
 
+#if defined CONFIG_XEN_ALIGN_2M
+#define SECTION_ALIGN MB(2)
+#elif defined CONFIG_XEN_ALIGN_4K

xen/arch/x86/Kconfig ENTRY(efi_start) · line 40

Quoted 10 lines
xen/arch/x86/Kconfig +10 -0
+#define SECTION_ALIGN PAGE_SIZE
+#elif defined CONFIG_XEN_ALIGN_DEFAULT
+    #ifdef EFI
+        #define SECTION_ALIGN MB(2)
+    #else
+        #define SECTION_ALIGN PAGE_SIZE
+    #endif
+#else
+#error "Section alignment undefined"
+#endif

How about converting the last #elif to #else and omitting the #error? Also would you mind using the defined() style (i.e. with parentheses), as we commonly do elsewhere? And please use uniform indentation (or not) of directives. I also find the indentation itself quite unusual - we have almost no examples of it being like this outside of files we've imported from elsewhere. Typically we retain the # in column 1 and indent only the actual directive keyword.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#3 lore raw

Re: [PATCH 1/2] x86: decouple xen alignment setting from EFI/non-EFI build

Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 15:57, <[email protected]> wrote:

Introduce a new Kconfig option to pick the alignment for xen binary. To retain original behaviour, the default pick for EFI build is 2M and non-EFI build 4K.

Quoted 8 lines

Is this a worthwhile step to take, considering that we mean to switch to 2M main section boundaries anyway? I realize it's still not necessarily clear how to get there without re-introducing the boot regression with syslinux that was observed back then, but perhaps time would better be spent there than into introducing configurability? (To be honest I don't recall whether it was determined that there was no way out of this dilemma, but it seems to me there would have been a plan.)

I think it would definitely be sensible to fix it there. But we still have older syslinux to deal with. I don't think they're going away any time soon.

Quoted 20 lines
Quoted 20 lines
xen/arch/x86/Kconfig +13 -0
@@ -138,6 +138,32 @@ config TBOOT
 
 	  If unsure, say Y.
 
+choice
+	prompt "Alignment of Xen binary"
+	depends on X86
+	default XEN_ALIGN_DEFAULT
+	---help---
+	  Specify alignment for Xen binary.
+
+	  If unsure, choose "default".
+
+config XEN_ALIGN_DEFAULT
+	bool "Default alignment"
+	---help---
+	  Pick alignment according to build variants.
Quoted 9 lines

xen/arch/x86/Kconfig config TBOOT · line 157

Quoted 4 lines
xen/arch/x86/Kconfig +4 -0
+
+	  For EFI build the default alignment is 2M. For non-EFI build
+	  the default alignment is 4K due to syslinux failing to handle
+	  2M alignment.

Wasn't it the resulting image size rather than the alignment itself which did cause the problem? Has the issue been fixed in newer syslinux?

Right. I can make this clearer.

"due to syslinux failing to handle the image size increment induced by 2M alignment".

Also, I think s/binary/image/ in the description would be better.

Looking at syslinux.git I don't immediately see patches to fix the issue (if there is such issue in the first place).

Quoted 9 lines

xen/arch/x86/Kconfig config TBOOT · line 163

Quoted 5 lines
xen/arch/x86/Kconfig +5 -0
+config XEN_ALIGN_4K
+	bool "4K alignment"
+
+config XEN_ALIGN_2M
+	bool "2M alignment"

In patch 2 you only need the latter - is there really much value in allowing explicitly requesting 4k?

I thought there would be a case in which users want 4K explicitly? I'm certainly fine with dropping the 4K alignment option.

Quoted 25 lines
Quoted 14 lines
xen/arch/x86/Kconfig +3 -1
@@ -20,13 +19,26 @@ ENTRY(efi_start)
 #else /* !EFI */
 
 #define FORMAT "elf64-x86-64"
-#define SECTION_ALIGN PAGE_SIZE
 #define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START)
 
 ENTRY(start_pa)
 
 #endif /* EFI */
 
+#if defined CONFIG_XEN_ALIGN_2M
+#define SECTION_ALIGN MB(2)
+#elif defined CONFIG_XEN_ALIGN_4K

xen/arch/x86/Kconfig ENTRY(efi_start) · line 40

Quoted 10 lines
xen/arch/x86/Kconfig +10 -0
+#define SECTION_ALIGN PAGE_SIZE
+#elif defined CONFIG_XEN_ALIGN_DEFAULT
+    #ifdef EFI
+        #define SECTION_ALIGN MB(2)
+    #else
+        #define SECTION_ALIGN PAGE_SIZE
+    #endif
+#else
+#error "Section alignment undefined"
+#endif
Quoted 8 lines

How about converting the last #elif to #else and omitting the #error? Also would you mind using the defined() style (i.e. with parentheses), as we commonly do elsewhere? And please use uniform indentation (or not) of directives. I also find the indentation itself quite unusual - we have almost no examples of it being like this outside of files we've imported from elsewhere. Typically we retain the # in column 1 and indent only the actual directive keyword.

Will fix (after we determine what to do with 4K option).

Wei.

Quoted 4 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [PATCH 1/2] x86: decouple xen alignment setting from EFI/non-EFI build

Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 19.03.19 at 12:24, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 15:57, <[email protected]> wrote:
xen/arch/x86/Kconfig +13 -0
@@ -138,6 +138,32 @@ config TBOOT
 
 	  If unsure, say Y.
 
+choice
+	prompt "Alignment of Xen binary"
+	depends on X86
+	default XEN_ALIGN_DEFAULT
+	---help---
+	  Specify alignment for Xen binary.
+
+	  If unsure, choose "default".
+
+config XEN_ALIGN_DEFAULT
+	bool "Default alignment"
+	---help---
+	  Pick alignment according to build variants.
Quoted 9 lines

xen/arch/x86/Kconfig config TBOOT · line 157

Quoted 4 lines
xen/arch/x86/Kconfig +4 -0
+
+	  For EFI build the default alignment is 2M. For non-EFI build
+	  the default alignment is 4K due to syslinux failing to handle
+	  2M alignment.

Wasn't it the resulting image size rather than the alignment itself which did cause the problem? Has the issue been fixed in newer syslinux?

Quoted 6 lines

Right. I can make this clearer.

"due to syslinux failing to handle the image size increment induced by 2M alignment".

Also, I think s/binary/image/ in the description would be better.

Agreed.

Quoted 11 lines
Quoted 8 lines

xen/arch/x86/Kconfig config TBOOT · line 163

Quoted 5 lines
xen/arch/x86/Kconfig +5 -0
+config XEN_ALIGN_4K
+	bool "4K alignment"
+
+config XEN_ALIGN_2M
+	bool "2M alignment"

In patch 2 you only need the latter - is there really much value in allowing explicitly requesting 4k?

I thought there would be a case in which users want 4K explicitly? I'm certainly fine with dropping the 4K alignment option.

Well, without a specific need or request I'd prefer not to see extra options introduced.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#5 lore raw

PATCH 2/2 x86/pvshim: use 2M alignment

In reply to Wei Liu

The pvshim is loaded directly by toolstack. Use 2M alignment for potential better performance.

---
 xen/arch/x86/configs/pvshim_defconfig | 1 +
 1 file changed, 1 insertion(+)
xen/arch/x86/configs/pvshim_defconfig +1 -0
index a12e3d0465..8e50b60cda 100644
@@ -5,6 +5,7 @@ CONFIG_PVH_GUEST=y
 CONFIG_PV_SHIM=y
 CONFIG_PV_SHIM_EXCLUSIVE=y
 CONFIG_NR_CPUS=32
+CONFIG_XEN_ALIGN_2M=y
 # Disable features not used by the PV shim
 # CONFIG_SHADOW_PAGING is not set
 # CONFIG_BIGMEM is not set
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel