summaryrefslogtreecommitdiffstats
path: root/recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch')
-rw-r--r--recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch111
1 files changed, 111 insertions, 0 deletions
diff --git a/recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch b/recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch
new file mode 100644
index 00000000..72592c4b
--- /dev/null
+++ b/recipes-extended/xen/files/0001-x86-make-hypervisor-build-with-gcc11.patch
@@ -0,0 +1,111 @@
1From 722f59d38c710a940ab05e542a83020eb5546dea Mon Sep 17 00:00:00 2001
2From: Jan Beulich <jbeulich@suse.com>
3Date: Thu, 27 May 2021 14:40:29 +0200
4Subject: [PATCH] x86: make hypervisor build with gcc11
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Gcc 11 looks to make incorrect assumptions about valid ranges that
10pointers may be used for addressing when they are derived from e.g. a
11plain constant. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100680.
12
13Utilize RELOC_HIDE() to work around the issue, which for x86 manifests
14in at least
15- mpparse.c:efi_check_config(),
16- tboot.c:tboot_probe(),
17- tboot.c:tboot_gen_frametable_integrity(),
18- x86_emulate.c:x86_emulate() (at -O2 only).
19The last case is particularly odd not just because it only triggers at
20higher optimization levels, but also because it only affects one of at
21least three similar constructs. Various "note" diagnostics claim the
22valid index range to be [0, 2⁶³-1].
23
24Signed-off-by: Jan Beulich <jbeulich@suse.com>
25Tested-by: Jason Andryuk <jandryuk@gmail.com>
26Acked-by: Roger Pau Monné <roger.pau@citrix.com>
27---
28 tools/tests/x86_emulator/x86-emulate.c | 7 +++++++
29 xen/arch/x86/x86_emulate/x86_emulate.c | 2 +-
30 xen/include/asm-x86/fixmap.h | 2 +-
31 xen/include/xen/compiler.h | 6 ++++++
32 xen/include/xen/pdx.h | 2 +-
33 5 files changed, 16 insertions(+), 3 deletions(-)
34
35diff --git a/tools/tests/x86_emulator/x86-emulate.c b/tools/tests/x86_emulator/x86-emulate.c
36index 07f892dbbb..ea286d6ad8 100644
37--- a/tools/tests/x86_emulator/x86-emulate.c
38+++ b/tools/tests/x86_emulator/x86-emulate.c
39@@ -8,6 +8,13 @@
40
41 #define ERR_PTR(val) NULL
42
43+/* See gcc bug 100680, but here don't bother making this version dependent. */
44+#define gcc11_wrap(x) ({ \
45+ unsigned long x_; \
46+ __asm__ ( "" : "=g" (x_) : "0" (x) ); \
47+ (typeof(x))x_; \
48+})
49+
50 #define cpu_has_amd_erratum(nr) 0
51 #define cpu_has_mpx false
52 #define read_bndcfgu() 0
53diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
54index c25d88d0d8..31fdec030c 100644
55--- a/xen/arch/x86/x86_emulate/x86_emulate.c
56+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
57@@ -726,7 +726,7 @@ union vex {
58 #define copy_VEX(ptr, vex) ({ \
59 if ( !mode_64bit() ) \
60 (vex).reg |= 8; \
61- (ptr)[0 - PFX_BYTES] = ext < ext_8f08 ? 0xc4 : 0x8f; \
62+ gcc11_wrap(ptr)[0 - PFX_BYTES] = ext < ext_8f08 ? 0xc4 : 0x8f; \
63 (ptr)[1 - PFX_BYTES] = (vex).raw[0]; \
64 (ptr)[2 - PFX_BYTES] = (vex).raw[1]; \
65 container_of((ptr) + 1 - PFX_BYTES, typeof(vex), raw[0]); \
66diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h
67index 0db314baeb..20746afd0a 100644
68--- a/xen/include/asm-x86/fixmap.h
69+++ b/xen/include/asm-x86/fixmap.h
70@@ -78,7 +78,7 @@ extern void __set_fixmap(
71
72 #define clear_fixmap(idx) __set_fixmap(idx, 0, 0)
73
74-#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
75+#define __fix_to_virt(x) gcc11_wrap(FIXADDR_TOP - ((x) << PAGE_SHIFT))
76 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
77
78 #define fix_to_virt(x) ((void *)__fix_to_virt(x))
79diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
80index 17cf00e1ec..696c7eb89e 100644
81--- a/xen/include/xen/compiler.h
82+++ b/xen/include/xen/compiler.h
83@@ -140,6 +140,12 @@
84 __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
85 (typeof(ptr)) (__ptr + (off)); })
86
87+#if CONFIG_GCC_VERSION >= 110000 /* See gcc bug 100680. */
88+# define gcc11_wrap(x) RELOC_HIDE(x, 0)
89+#else
90+# define gcc11_wrap(x) (x)
91+#endif
92+
93 #ifdef __GCC_ASM_FLAG_OUTPUTS__
94 # define ASM_FLAG_OUT(yes, no) yes
95 #else
96diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h
97index 770fadc06c..9fcfb0ce52 100644
98--- a/xen/include/xen/pdx.h
99+++ b/xen/include/xen/pdx.h
100@@ -19,7 +19,7 @@ extern u64 pdx_region_mask(u64 base, u64 len);
101 extern void set_pdx_range(unsigned long smfn, unsigned long emfn);
102
103 #define page_to_pdx(pg) ((pg) - frame_table)
104-#define pdx_to_page(pdx) (frame_table + (pdx))
105+#define pdx_to_page(pdx) gcc11_wrap(frame_table + (pdx))
106
107 bool __mfn_valid(unsigned long mfn);
108
109--
1102.25.1
111