Skip to content

Commit 4e6437f

Browse files
Zenghui YuMarc Zyngier
authored andcommitted
irqchip/gic-v4.1: Ensure L2 vPE table is allocated at RD level
In GICv4, we will ensure that level2 vPE table memory is allocated for the specified vpe_id on all v4 ITS, in its_alloc_vpe_table(). This still works well for the typical GICv4.1 implementation, where the new vPE table is shared between the ITSs and the RDs. To make it explicit, let us introduce allocate_vpe_l2_table() to make sure that the L2 tables are allocated on all v4.1 RDs. We're likely not need to allocate memory in it because the vPE table is shared and (L2 table is) already allocated at ITS level, except for the case where the ITS doesn't share anything (say SVPET == 0, practically unlikely but architecturally allowed). The implementation of allocate_vpe_l2_table() is mostly copied from its_alloc_table_entry(). Signed-off-by: Zenghui Yu <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8b718d4 commit 4e6437f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

drivers/irqchip/irq-gic-v3-its.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,72 @@ static u64 inherit_vpe_l1_table_from_rd(cpumask_t **mask)
24432443
return 0;
24442444
}
24452445

2446+
static bool allocate_vpe_l2_table(int cpu, u32 id)
2447+
{
2448+
void __iomem *base = gic_data_rdist_cpu(cpu)->rd_base;
2449+
u64 val, gpsz, npg;
2450+
unsigned int psz, esz, idx;
2451+
struct page *page;
2452+
__le64 *table;
2453+
2454+
if (!gic_rdists->has_rvpeid)
2455+
return true;
2456+
2457+
val = gits_read_vpropbaser(base + SZ_128K + GICR_VPROPBASER);
2458+
2459+
esz = FIELD_GET(GICR_VPROPBASER_4_1_ENTRY_SIZE, val) + 1;
2460+
gpsz = FIELD_GET(GICR_VPROPBASER_4_1_PAGE_SIZE, val);
2461+
npg = FIELD_GET(GICR_VPROPBASER_4_1_SIZE, val) + 1;
2462+
2463+
switch (gpsz) {
2464+
default:
2465+
WARN_ON(1);
2466+
/* fall through */
2467+
case GIC_PAGE_SIZE_4K:
2468+
psz = SZ_4K;
2469+
break;
2470+
case GIC_PAGE_SIZE_16K:
2471+
psz = SZ_16K;
2472+
break;
2473+
case GIC_PAGE_SIZE_64K:
2474+
psz = SZ_64K;
2475+
break;
2476+
}
2477+
2478+
/* Don't allow vpe_id that exceeds single, flat table limit */
2479+
if (!(val & GICR_VPROPBASER_4_1_INDIRECT))
2480+
return (id < (npg * psz / (esz * SZ_8)));
2481+
2482+
/* Compute 1st level table index & check if that exceeds table limit */
2483+
idx = id >> ilog2(psz / (esz * SZ_8));
2484+
if (idx >= (npg * psz / GITS_LVL1_ENTRY_SIZE))
2485+
return false;
2486+
2487+
table = gic_data_rdist_cpu(cpu)->vpe_l1_base;
2488+
2489+
/* Allocate memory for 2nd level table */
2490+
if (!table[idx]) {
2491+
page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(psz));
2492+
if (!page)
2493+
return false;
2494+
2495+
/* Flush Lvl2 table to PoC if hw doesn't support coherency */
2496+
if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
2497+
gic_flush_dcache_to_poc(page_address(page), psz);
2498+
2499+
table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
2500+
2501+
/* Flush Lvl1 entry to PoC if hw doesn't support coherency */
2502+
if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
2503+
gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE);
2504+
2505+
/* Ensure updated table contents are visible to RD hardware */
2506+
dsb(sy);
2507+
}
2508+
2509+
return true;
2510+
}
2511+
24462512
static int allocate_vpe_l1_table(void)
24472513
{
24482514
void __iomem *vlpi_base = gic_data_rdist_vlpi_base();
@@ -2957,6 +3023,7 @@ static bool its_alloc_device_table(struct its_node *its, u32 dev_id)
29573023
static bool its_alloc_vpe_table(u32 vpe_id)
29583024
{
29593025
struct its_node *its;
3026+
int cpu;
29603027

29613028
/*
29623029
* Make sure the L2 tables are allocated on *all* v4 ITSs. We
@@ -2979,6 +3046,19 @@ static bool its_alloc_vpe_table(u32 vpe_id)
29793046
return false;
29803047
}
29813048

3049+
/* Non v4.1? No need to iterate RDs and go back early. */
3050+
if (!gic_rdists->has_rvpeid)
3051+
return true;
3052+
3053+
/*
3054+
* Make sure the L2 tables are allocated for all copies of
3055+
* the L1 table on *all* v4.1 RDs.
3056+
*/
3057+
for_each_possible_cpu(cpu) {
3058+
if (!allocate_vpe_l2_table(cpu, vpe_id))
3059+
return false;
3060+
}
3061+
29823062
return true;
29833063
}
29843064

0 commit comments

Comments
 (0)