Skip to content

Commit 117c3b2

Browse files
Marc Zyngieroupton
Marc Zyngier
authored andcommitted
arm64: Rework checks for broken Cavium HW in the PI code
Calling into the MIDR checking framework from the PI code has recently become much harder, due to the new fancy "multi-MIDR" support that relies on tables being populated at boot time, but not that early that they are available to the PI code. There are additional issues with this framework, as the code really isn't position independend *at all*. This leads to some ugly breakages, as reported by Ada. It so appears that the only reason for the PI code to call into the MIDR checking code is to cope with The Most Broken ARM64 System Ever, aka Cavium ThunderX, which cannot deal with nG attributes that result of the combination of KASLR and KPTI as a consequence of Erratum 27456. Duplicate the check for the erratum in the PI code, removing the dependency on the bulk of the MIDR checking framework. This allows dropping that same check from kaslr_requires_kpti(), as the KPTI code already relies on the ARM64_WORKAROUND_CAVIUM_27456 cap. Fixes: c8c2647 ("arm64: Make  _midr_in_range_list() an exported function") Reported-by: Ada Couprie Diaz <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Shameer Kolothum <[email protected]> Cc: Oliver Upton <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent a344e25 commit 117c3b2

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

arch/arm64/include/asm/mmu.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,6 @@ static inline bool kaslr_requires_kpti(void)
9494
return false;
9595
}
9696

97-
/*
98-
* Systems affected by Cavium erratum 24756 are incompatible
99-
* with KPTI.
100-
*/
101-
if (IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456)) {
102-
extern const struct midr_range cavium_erratum_27456_cpus[];
103-
104-
if (is_midr_in_range_list(cavium_erratum_27456_cpus))
105-
return false;
106-
}
107-
10897
return true;
10998
}
11099

arch/arm64/kernel/cpu_errata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static const struct midr_range cavium_erratum_23154_cpus[] = {
335335
#endif
336336

337337
#ifdef CONFIG_CAVIUM_ERRATUM_27456
338-
const struct midr_range cavium_erratum_27456_cpus[] = {
338+
static const struct midr_range cavium_erratum_27456_cpus[] = {
339339
/* Cavium ThunderX, T88 pass 1.x - 2.1 */
340340
MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1),
341341
/* Cavium ThunderX, T81 pass 1.0 */

arch/arm64/kernel/image-vars.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ PROVIDE(__pi_id_aa64smfr0_override = id_aa64smfr0_override);
4747
PROVIDE(__pi_id_aa64zfr0_override = id_aa64zfr0_override);
4848
PROVIDE(__pi_arm64_sw_feature_override = arm64_sw_feature_override);
4949
PROVIDE(__pi_arm64_use_ng_mappings = arm64_use_ng_mappings);
50-
#ifdef CONFIG_CAVIUM_ERRATUM_27456
51-
PROVIDE(__pi_cavium_erratum_27456_cpus = cavium_erratum_27456_cpus);
52-
PROVIDE(__pi_is_midr_in_range_list = is_midr_in_range_list);
53-
#endif
5450
PROVIDE(__pi__ctype = _ctype);
5551
PROVIDE(__pi_memstart_offset_seed = memstart_offset_seed);
5652

arch/arm64/kernel/pi/map_kernel.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ static void __init map_fdt(u64 fdt)
207207
dsb(ishst);
208208
}
209209

210+
/*
211+
* PI version of the Cavium Eratum 27456 detection, which makes it
212+
* impossible to use non-global mappings.
213+
*/
214+
static bool __init ng_mappings_allowed(void)
215+
{
216+
static const struct midr_range cavium_erratum_27456_cpus[] __initconst = {
217+
/* Cavium ThunderX, T88 pass 1.x - 2.1 */
218+
MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1),
219+
/* Cavium ThunderX, T81 pass 1.0 */
220+
MIDR_REV(MIDR_THUNDERX_81XX, 0, 0),
221+
{},
222+
};
223+
224+
for (const struct midr_range *r = cavium_erratum_27456_cpus; r->model; r++) {
225+
if (midr_is_cpu_model_range(read_cpuid_id(), r->model,
226+
r->rv_min, r->rv_max))
227+
return false;
228+
}
229+
230+
return true;
231+
}
232+
210233
asmlinkage void __init early_map_kernel(u64 boot_status, void *fdt)
211234
{
212235
static char const chosen_str[] __initconst = "/chosen";
@@ -246,7 +269,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status, void *fdt)
246269
u64 kaslr_seed = kaslr_early_init(fdt, chosen);
247270

248271
if (kaslr_seed && kaslr_requires_kpti())
249-
arm64_use_ng_mappings = true;
272+
arm64_use_ng_mappings = ng_mappings_allowed();
250273

251274
kaslr_offset |= kaslr_seed & ~(MIN_KIMG_ALIGN - 1);
252275
}

0 commit comments

Comments
 (0)