Skip to content

Commit b05f8b6

Browse files
authored
Merge pull request #790 from nathanchance/update-patches-nov-22-2024
Update patches (November 22, 2024)
2 parents 679bc68 + c13391f commit b05f8b6

6 files changed

+237
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
From afa9b48f327c9ef36bfba4c643a29385a633252b Mon Sep 17 00:00:00 2001
2+
From: Marc Zyngier <maz@kernel.org>
3+
Date: Thu, 10 Oct 2024 16:13:26 +0100
4+
Subject: KVM: arm64: Shave a few bytes from the EL2 idmap code
5+
6+
Our idmap is becoming too big, to the point where it doesn't fit in
7+
a 4kB page anymore.
8+
9+
There are some low-hanging fruits though, such as the el2_init_state
10+
horror that is expanded 3 times in the kernel. Let's at least limit
11+
ourselves to two copies, which makes the kernel link again.
12+
13+
At some point, we'll have to have a better way of doing this.
14+
15+
Reported-by: Nathan Chancellor <nathan@kernel.org>
16+
Signed-off-by: Marc Zyngier <maz@kernel.org>
17+
Link: https://lore.kernel.org/r/20241009204903.GA3353168@thelio-3990X
18+
---
19+
Link: https://git.kernel.org/linus/afa9b48f327c9ef36bfba4c643a29385a633252b
20+
---
21+
arch/arm64/include/asm/kvm_asm.h | 1 +
22+
arch/arm64/kernel/asm-offsets.c | 1 +
23+
arch/arm64/kvm/hyp/nvhe/hyp-init.S | 52 +++++++++++++++++++++-----------------
24+
3 files changed, 31 insertions(+), 23 deletions(-)
25+
26+
diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
27+
index b36a3b6cc01169..67afac659231ed 100644
28+
--- a/arch/arm64/include/asm/kvm_asm.h
29+
+++ b/arch/arm64/include/asm/kvm_asm.h
30+
@@ -178,6 +178,7 @@ struct kvm_nvhe_init_params {
31+
unsigned long hcr_el2;
32+
unsigned long vttbr;
33+
unsigned long vtcr;
34+
+ unsigned long tmp;
35+
};
36+
37+
/*
38+
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
39+
index 27de1dddb0abee..b21dd24b8efc3b 100644
40+
--- a/arch/arm64/kernel/asm-offsets.c
41+
+++ b/arch/arm64/kernel/asm-offsets.c
42+
@@ -146,6 +146,7 @@ int main(void)
43+
DEFINE(NVHE_INIT_HCR_EL2, offsetof(struct kvm_nvhe_init_params, hcr_el2));
44+
DEFINE(NVHE_INIT_VTTBR, offsetof(struct kvm_nvhe_init_params, vttbr));
45+
DEFINE(NVHE_INIT_VTCR, offsetof(struct kvm_nvhe_init_params, vtcr));
46+
+ DEFINE(NVHE_INIT_TMP, offsetof(struct kvm_nvhe_init_params, tmp));
47+
#endif
48+
#ifdef CONFIG_CPU_PM
49+
DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp));
50+
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
51+
index 401af1835be6b7..fc186622606767 100644
52+
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
53+
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
54+
@@ -24,28 +24,25 @@
55+
.align 11
56+
57+
SYM_CODE_START(__kvm_hyp_init)
58+
- ventry __invalid // Synchronous EL2t
59+
- ventry __invalid // IRQ EL2t
60+
- ventry __invalid // FIQ EL2t
61+
- ventry __invalid // Error EL2t
62+
+ ventry . // Synchronous EL2t
63+
+ ventry . // IRQ EL2t
64+
+ ventry . // FIQ EL2t
65+
+ ventry . // Error EL2t
66+
67+
- ventry __invalid // Synchronous EL2h
68+
- ventry __invalid // IRQ EL2h
69+
- ventry __invalid // FIQ EL2h
70+
- ventry __invalid // Error EL2h
71+
+ ventry . // Synchronous EL2h
72+
+ ventry . // IRQ EL2h
73+
+ ventry . // FIQ EL2h
74+
+ ventry . // Error EL2h
75+
76+
ventry __do_hyp_init // Synchronous 64-bit EL1
77+
- ventry __invalid // IRQ 64-bit EL1
78+
- ventry __invalid // FIQ 64-bit EL1
79+
- ventry __invalid // Error 64-bit EL1
80+
+ ventry . // IRQ 64-bit EL1
81+
+ ventry . // FIQ 64-bit EL1
82+
+ ventry . // Error 64-bit EL1
83+
84+
- ventry __invalid // Synchronous 32-bit EL1
85+
- ventry __invalid // IRQ 32-bit EL1
86+
- ventry __invalid // FIQ 32-bit EL1
87+
- ventry __invalid // Error 32-bit EL1
88+
-
89+
-__invalid:
90+
- b .
91+
+ ventry . // Synchronous 32-bit EL1
92+
+ ventry . // IRQ 32-bit EL1
93+
+ ventry . // FIQ 32-bit EL1
94+
+ ventry . // Error 32-bit EL1
95+
96+
/*
97+
* Only uses x0..x3 so as to not clobber callee-saved SMCCC registers.
98+
@@ -76,6 +73,13 @@ __do_hyp_init:
99+
eret
100+
SYM_CODE_END(__kvm_hyp_init)
101+
102+
+SYM_CODE_START_LOCAL(__kvm_init_el2_state)
103+
+ /* Initialize EL2 CPU state to sane values. */
104+
+ init_el2_state // Clobbers x0..x2
105+
+ finalise_el2_state
106+
+ ret
107+
+SYM_CODE_END(__kvm_init_el2_state)
108+
+
109+
/*
110+
* Initialize the hypervisor in EL2.
111+
*
112+
@@ -102,9 +106,12 @@ SYM_CODE_START_LOCAL(___kvm_hyp_init)
113+
// TPIDR_EL2 is used to preserve x0 across the macro maze...
114+
isb
115+
msr tpidr_el2, x0
116+
- init_el2_state
117+
- finalise_el2_state
118+
+ str lr, [x0, #NVHE_INIT_TMP]
119+
+
120+
+ bl __kvm_init_el2_state
121+
+
122+
mrs x0, tpidr_el2
123+
+ ldr lr, [x0, #NVHE_INIT_TMP]
124+
125+
1:
126+
ldr x1, [x0, #NVHE_INIT_TPIDR_EL2]
127+
@@ -199,9 +206,8 @@ SYM_CODE_START_LOCAL(__kvm_hyp_init_cpu)
128+
129+
2: msr SPsel, #1 // We want to use SP_EL{1,2}
130+
131+
- /* Initialize EL2 CPU state to sane values. */
132+
- init_el2_state // Clobbers x0..x2
133+
- finalise_el2_state
134+
+ bl __kvm_init_el2_state
135+
+
136+
__init_el2_nvhe_prepare_eret
137+
138+
/* Enable MMU, set vectors and stack. */
139+
--
140+
cgit 1.2.3-korg
141+

patches/arm64-fixes/series

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
506a1ac4c4464a61e4336e135841067dbc040aaa.patch
22
20241018_arnd_media_mediatek_vcodec_mark_vdec_vp9_slice_map_counts_eob_coef_noinline.patch
3+
afa9b48f327c9ef36bfba4c643a29385a633252b.patch

patches/mainline/series

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
20240819_nathan_hexagon_disable_constant_extender_optimization_for_llvm_prior_to_19_1_0.patch
21
20241018_arnd_media_mediatek_vcodec_mark_vdec_vp9_slice_map_counts_eob_coef_noinline.patch
2+
v2_20241121_nathan_hexagon_disable_constant_extender_optimization_for_llvm_prior_to_19_1_0.patch

patches/mainline/20240819_nathan_hexagon_disable_constant_extender_optimization_for_llvm_prior_to_19_1_0.patch patches/mainline/v2_20241121_nathan_hexagon_disable_constant_extender_optimization_for_llvm_prior_to_19_1_0.patch

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
From git@z Thu Jan 1 00:00:00 1970
2-
Subject: [PATCH] hexagon: Disable constant extender optimization for LLVM
3-
prior to 19.1.0
2+
Subject: [PATCH v2] hexagon: Disable constant extender optimization for
3+
LLVM prior to 19.1.0
44
From: Nathan Chancellor <nathan@kernel.org>
5-
Date: Mon, 19 Aug 2024 11:16:10 -0700
6-
Message-Id: <20240819-hexagon-disable-constant-expander-pass-v1-1-36a734e9527d@kernel.org>
5+
Date: Thu, 21 Nov 2024 11:22:18 -0700
6+
Message-Id: <20241121-hexagon-disable-constant-expander-pass-v2-1-1a92e9afb0f4@kernel.org>
77
MIME-Version: 1.0
88
Content-Type: text/plain; charset="utf-8"
99
Content-Transfer-Encoding: 7bit
1010

1111
The Hexagon-specific constant extender optimization in LLVM may crash on
12-
Linux kernel code [1] (such as with a bcachefs change in -next):
12+
Linux kernel code [1], such as fs/bcache/btree_io.c after
13+
commit 32ed4a620c54 ("bcachefs: Btree path tracepoints") in 6.12:
1314

1415
clang: llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp:745: bool (anonymous namespace)::HexagonConstExtenders::ExtRoot::operator<(const HCE::ExtRoot &) const: Assertion `ThisB->getParent() == OtherB->getParent()' failed.
1516
Stack dump:
@@ -26,18 +27,29 @@ This has been resolved in LLVM main (20.0.0) [2] and backported to LLVM
2627
constant expander optimization using the '-mllvm' option when using a
2728
toolchain that is not fixed.
2829

30+
Cc: stable@vger.kernel.org
2931
Link: https://github.com/llvm/llvm-project/issues/99714 [1]
3032
Link: https://github.com/llvm/llvm-project/commit/68df06a0b2998765cb0a41353fcf0919bbf57ddb [2]
3133
Link: https://github.com/llvm/llvm-project/commit/2ab8d93061581edad3501561722ebd5632d73892 [3]
3234
Reviewed-by: Brian Cain <bcain@quicinc.com>
33-
Link: https://lore.kernel.org/r/20240819-hexagon-disable-constant-expander-pass-v1-1-36a734e9527d@kernel.org
35+
Link: https://lore.kernel.org/r/20241121-hexagon-disable-constant-expander-pass-v2-1-1a92e9afb0f4@kernel.org
3436
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
37+
---
38+
Andrew, can you please take this for 6.13? Our CI continues to hit this.
39+
40+
Changes in v2:
41+
- Rebase on 6.12 to make sure it is still applicable
42+
- Name exact bcachefs commit that introduces crash now that it is
43+
merged
44+
- Add 'Cc: stable' as this is now visible in a stable release
45+
- Carry forward Brian's reviewed-by
46+
- Link to v1: https://lore.kernel.org/r/20240819-hexagon-disable-constant-expander-pass-v1-1-36a734e9527d@kernel.org
3547
---
3648
arch/hexagon/Makefile | 6 ++++++
3749
1 file changed, 6 insertions(+)
3850

3951
diff --git a/arch/hexagon/Makefile b/arch/hexagon/Makefile
40-
index 92d005958dfb..ff172cbe5881 100644
52+
index 92d005958dfb232d48a4ca843b46262a84a08eb4..ff172cbe5881a074f9d9430c37071992a4c8beac 100644
4153
--- a/arch/hexagon/Makefile
4254
+++ b/arch/hexagon/Makefile
4355
@@ -32,3 +32,9 @@ KBUILD_LDFLAGS += $(ldflags-y)
@@ -52,7 +64,7 @@ index 92d005958dfb..ff172cbe5881 100644
5264
+endif
5365

5466
---
55-
base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
67+
base-commit: adc218676eef25575469234709c2d87185ca223a
5668
change-id: 20240802-hexagon-disable-constant-expander-pass-8b6b61db6afc
5769

5870
Best regards,

patches/stable/series

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
20241018_arnd_media_mediatek_vcodec_mark_vdec_vp9_slice_map_counts_eob_coef_noinline.patch
2+
v2_20241121_nathan_hexagon_disable_constant_extender_optimization_for_llvm_prior_to_19_1_0.patch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
From git@z Thu Jan 1 00:00:00 1970
2+
Subject: [PATCH v2] hexagon: Disable constant extender optimization for
3+
LLVM prior to 19.1.0
4+
From: Nathan Chancellor <nathan@kernel.org>
5+
Date: Thu, 21 Nov 2024 11:22:18 -0700
6+
Message-Id: <20241121-hexagon-disable-constant-expander-pass-v2-1-1a92e9afb0f4@kernel.org>
7+
MIME-Version: 1.0
8+
Content-Type: text/plain; charset="utf-8"
9+
Content-Transfer-Encoding: 7bit
10+
11+
The Hexagon-specific constant extender optimization in LLVM may crash on
12+
Linux kernel code [1], such as fs/bcache/btree_io.c after
13+
commit 32ed4a620c54 ("bcachefs: Btree path tracepoints") in 6.12:
14+
15+
clang: llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp:745: bool (anonymous namespace)::HexagonConstExtenders::ExtRoot::operator<(const HCE::ExtRoot &) const: Assertion `ThisB->getParent() == OtherB->getParent()' failed.
16+
Stack dump:
17+
0. Program arguments: clang --target=hexagon-linux-musl ... fs/bcachefs/btree_io.c
18+
1. <eof> parser at end of file
19+
2. Code generation
20+
3. Running pass 'Function Pass Manager' on module 'fs/bcachefs/btree_io.c'.
21+
4. Running pass 'Hexagon constant-extender optimization' on function '@__btree_node_lock_nopath'
22+
23+
Without assertions enabled, there is just a hang during compilation.
24+
25+
This has been resolved in LLVM main (20.0.0) [2] and backported to LLVM
26+
19.1.0 but the kernel supports LLVM 13.0.1 and newer, so disable the
27+
constant expander optimization using the '-mllvm' option when using a
28+
toolchain that is not fixed.
29+
30+
Cc: stable@vger.kernel.org
31+
Link: https://github.com/llvm/llvm-project/issues/99714 [1]
32+
Link: https://github.com/llvm/llvm-project/commit/68df06a0b2998765cb0a41353fcf0919bbf57ddb [2]
33+
Link: https://github.com/llvm/llvm-project/commit/2ab8d93061581edad3501561722ebd5632d73892 [3]
34+
Reviewed-by: Brian Cain <bcain@quicinc.com>
35+
Link: https://lore.kernel.org/r/20241121-hexagon-disable-constant-expander-pass-v2-1-1a92e9afb0f4@kernel.org
36+
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
37+
---
38+
Andrew, can you please take this for 6.13? Our CI continues to hit this.
39+
40+
Changes in v2:
41+
- Rebase on 6.12 to make sure it is still applicable
42+
- Name exact bcachefs commit that introduces crash now that it is
43+
merged
44+
- Add 'Cc: stable' as this is now visible in a stable release
45+
- Carry forward Brian's reviewed-by
46+
- Link to v1: https://lore.kernel.org/r/20240819-hexagon-disable-constant-expander-pass-v1-1-36a734e9527d@kernel.org
47+
---
48+
arch/hexagon/Makefile | 6 ++++++
49+
1 file changed, 6 insertions(+)
50+
51+
diff --git a/arch/hexagon/Makefile b/arch/hexagon/Makefile
52+
index 92d005958dfb232d48a4ca843b46262a84a08eb4..ff172cbe5881a074f9d9430c37071992a4c8beac 100644
53+
--- a/arch/hexagon/Makefile
54+
+++ b/arch/hexagon/Makefile
55+
@@ -32,3 +32,9 @@ KBUILD_LDFLAGS += $(ldflags-y)
56+
TIR_NAME := r19
57+
KBUILD_CFLAGS += -ffixed-$(TIR_NAME) -DTHREADINFO_REG=$(TIR_NAME) -D__linux__
58+
KBUILD_AFLAGS += -DTHREADINFO_REG=$(TIR_NAME)
59+
+
60+
+# Disable HexagonConstExtenders pass for LLVM versions prior to 19.1.0
61+
+# https://github.com/llvm/llvm-project/issues/99714
62+
+ifneq ($(call clang-min-version, 190100),y)
63+
+KBUILD_CFLAGS += -mllvm -hexagon-cext=false
64+
+endif
65+
66+
---
67+
base-commit: adc218676eef25575469234709c2d87185ca223a
68+
change-id: 20240802-hexagon-disable-constant-expander-pass-8b6b61db6afc
69+
70+
Best regards,
71+
--
72+
Nathan Chancellor <nathan@kernel.org>
73+

0 commit comments

Comments
 (0)