Skip to content

Commit 4cb7779

Browse files
Marc ZyngierKAGA-KOKO
authored andcommitted
irqchip/gic-v3: Fix rk3399 workaround when secure interrupts are enabled
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 <chf.fritz@googlemail.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Christoph Fritz <chf.fritz@googlemail.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20250215185241.3768218-1-maz@kernel.org Closes: https://lore.kernel.org/r/b1266652fb64857246e8babdf268d0df8f0c36d9.camel@googlemail.com
1 parent 0ad2507 commit 4cb7779

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
}
@@ -1922,6 +1931,18 @@ static bool gic_enable_quirk_arm64_2941627(void *data)
19221931
return true;
19231932
}
19241933

1934+
static bool gic_enable_quirk_rk3399(void *data)
1935+
{
1936+
struct gic_chip_data *d = data;
1937+
1938+
if (of_machine_is_compatible("rockchip,rk3399")) {
1939+
d->flags |= FLAGS_WORKAROUND_INSECURE;
1940+
return true;
1941+
}
1942+
1943+
return false;
1944+
}
1945+
19251946
static bool rd_set_non_coherent(void *data)
19261947
{
19271948
struct gic_chip_data *d = data;
@@ -1996,6 +2017,12 @@ static const struct gic_quirk gic_quirks[] = {
19962017
.property = "dma-noncoherent",
19972018
.init = rd_set_non_coherent,
19982019
},
2020+
{
2021+
.desc = "GICv3: Insecure RK3399 integration",
2022+
.iidr = 0x0000043b,
2023+
.mask = 0xff000fff,
2024+
.init = gic_enable_quirk_rk3399,
2025+
},
19992026
{
20002027
}
20012028
};
@@ -2004,7 +2031,7 @@ static void gic_enable_nmi_support(void)
20042031
{
20052032
int i;
20062033

2007-
if (!gic_prio_masking_enabled())
2034+
if (!gic_prio_masking_enabled() || nmi_support_forbidden)
20082035
return;
20092036

20102037
rdist_nmi_refs = kcalloc(gic_data.ppi_nr + SGI_NR,

0 commit comments

Comments
 (0)