Skip to content

Commit 0129dfe

Browse files
author
Charles Mirabile
committed
irqchip/gic-v3: Fix rk3399 workaround when secure interrupts are enabled
JIRA: https://issues.redhat.com/browse/RHEL-62922 commit 4cb7779 Author: Marc Zyngier <[email protected]> Date: Sat, 15 Feb 2025 18:52:41 +0000 Christoph reports that their rk3399 system dies since commit 773c05f ("irqchip/gic-v3: Work around insecure GIC integrations"). It appears that some rk3399 have secure payloads, and that the firmware sets SCR_EL3.FIQ==1. Obivously, disabling security in that configuration leads to even more problems. Revisit the workaround by: - making it rk3399 specific - checking whether Group-0 is available, which is a good proxy for SCR_EL3.FIQ being 0 - either apply the workaround if Group-0 is available, or disable pseudo-NMIs if not Note that this doesn't mean that the secure side is able to receive interrupts, as all interrupts are made non-secure anyway. Clearly, nobody ever tested secure interrupts on this platform. Fixes: 773c05f ("irqchip/gic-v3: Work around insecure GIC integrations") Reported-by: Christoph Fritz <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Christoph Fritz <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/all/[email protected] Closes: https://lore.kernel.org/r/[email protected] Signed-off-by: Charles Mirabile <[email protected]>
1 parent 99d0eb3 commit 0129dfe

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

drivers/irqchip/irq-gic-v3.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static u8 dist_prio_nmi __ro_after_init = GICV3_PRIO_NMI;
4444
#define FLAGS_WORKAROUND_GICR_WAKER_MSM8996 (1ULL << 0)
4545
#define FLAGS_WORKAROUND_CAVIUM_ERRATUM_38539 (1ULL << 1)
4646
#define FLAGS_WORKAROUND_ASR_ERRATUM_8601001 (1ULL << 2)
47+
#define FLAGS_WORKAROUND_INSECURE (1ULL << 3)
4748

4849
#define GIC_IRQ_TYPE_PARTITION (GIC_IRQ_TYPE_LPI + 1)
4950

@@ -83,6 +84,8 @@ static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key);
8384
#define GIC_LINE_NR min(GICD_TYPER_SPIS(gic_data.rdists.gicd_typer), 1020U)
8485
#define GIC_ESPI_NR GICD_TYPER_ESPIS(gic_data.rdists.gicd_typer)
8586

87+
static bool nmi_support_forbidden;
88+
8689
/*
8790
* There are 16 SGIs, though we only actually use 8 in Linux. The other 8 SGIs
8891
* are potentially stolen by the secure side. Some code, especially code dealing
@@ -163,21 +166,27 @@ static void __init gic_prio_init(void)
163166
{
164167
bool ds;
165168

166-
ds = gic_dist_security_disabled();
167-
if (!ds) {
168-
u32 val;
169-
170-
val = readl_relaxed(gic_data.dist_base + GICD_CTLR);
171-
val |= GICD_CTLR_DS;
172-
writel_relaxed(val, gic_data.dist_base + GICD_CTLR);
169+
cpus_have_group0 = gic_has_group0();
173170

174-
ds = gic_dist_security_disabled();
175-
if (ds)
176-
pr_warn("Broken GIC integration, security disabled");
171+
ds = gic_dist_security_disabled();
172+
if ((gic_data.flags & FLAGS_WORKAROUND_INSECURE) && !ds) {
173+
if (cpus_have_group0) {
174+
u32 val;
175+
176+
val = readl_relaxed(gic_data.dist_base + GICD_CTLR);
177+
val |= GICD_CTLR_DS;
178+
writel_relaxed(val, gic_data.dist_base + GICD_CTLR);
179+
180+
ds = gic_dist_security_disabled();
181+
if (ds)
182+
pr_warn("Broken GIC integration, security disabled\n");
183+
} else {
184+
pr_warn("Broken GIC integration, pNMI forbidden\n");
185+
nmi_support_forbidden = true;
186+
}
177187
}
178188

179189
cpus_have_security_disabled = ds;
180-
cpus_have_group0 = gic_has_group0();
181190

182191
/*
183192
* How priority values are used by the GIC depends on two things:
@@ -209,7 +218,7 @@ static void __init gic_prio_init(void)
209218
* be in the non-secure range, we program the non-secure values into
210219
* the distributor to match the PMR values we want.
211220
*/
212-
if (cpus_have_group0 & !cpus_have_security_disabled) {
221+
if (cpus_have_group0 && !cpus_have_security_disabled) {
213222
dist_prio_irq = __gicv3_prio_to_ns(dist_prio_irq);
214223
dist_prio_nmi = __gicv3_prio_to_ns(dist_prio_nmi);
215224
}
@@ -1924,6 +1933,18 @@ static bool gic_enable_quirk_arm64_2941627(void *data)
19241933
return true;
19251934
}
19261935

1936+
static bool gic_enable_quirk_rk3399(void *data)
1937+
{
1938+
struct gic_chip_data *d = data;
1939+
1940+
if (of_machine_is_compatible("rockchip,rk3399")) {
1941+
d->flags |= FLAGS_WORKAROUND_INSECURE;
1942+
return true;
1943+
}
1944+
1945+
return false;
1946+
}
1947+
19271948
static bool rd_set_non_coherent(void *data)
19281949
{
19291950
struct gic_chip_data *d = data;
@@ -1998,6 +2019,12 @@ static const struct gic_quirk gic_quirks[] = {
19982019
.property = "dma-noncoherent",
19992020
.init = rd_set_non_coherent,
20002021
},
2022+
{
2023+
.desc = "GICv3: Insecure RK3399 integration",
2024+
.iidr = 0x0000043b,
2025+
.mask = 0xff000fff,
2026+
.init = gic_enable_quirk_rk3399,
2027+
},
20012028
{
20022029
}
20032030
};
@@ -2006,7 +2033,7 @@ static void gic_enable_nmi_support(void)
20062033
{
20072034
int i;
20082035

2009-
if (!gic_prio_masking_enabled())
2036+
if (!gic_prio_masking_enabled() || nmi_support_forbidden)
20102037
return;
20112038

20122039
rdist_nmi_refs = kcalloc(gic_data.ppi_nr + SGI_NR,

0 commit comments

Comments
 (0)