From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <maz@kernel.org>, <tglx@kernel.org>, <radu@rendec.net>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <zenghui.yu@linux.dev>
Subject: Re: [PATCH v4] irqchip/gic-v3-its: Size the collection table for nr_cpu_ids
Date: Wed, 2 Dec 2026 15:01:08 +0800 [thread overview]
Message-ID: <f8e01142-fd3a-4867-b95d-382b8fa3ba46@huawei.com> (raw)
In-Reply-To: <20261119075405.774417-1-ruanjinjie@huawei.com>
在 2026/11/19 15:54, Jinjie Ruan 写道:
> The collection table is currently sized at a single ITS page size,
> while the driver allocates one collection per CPU indexed by logical
> CPU number. On systems with more CPUs than fit in a single page, no LPI
> can be routed to the excess CPUs and the system grinds to a halt.
>
> Change the allocation policy to size the collection table for nr_cpu_ids
> entries and allow two-level tables, matching the device and VCPU tables.
>
> Because Level-2 tables of an indirect table are normally allocated on
> demand and nothing calls its_alloc_table_entry() for collections,
> populate all Level-2 tables upfront in its_alloc_collections() while
> sleepable allocations are still permitted, and free them in
> its_free_tables().
>
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
> v4:
> - Size the table from nr_cpu_ids, not num_possible_cpus().
> - Populate the Level-2 tables of an indirect collection table, and
> free them alongside the Level-1 one.
> - Link to v3: https://lore.kernel.org/all/20261118025106.623070-1-ruanjinjie@huawei.com/
Hi, Marc,
Any new suggestions or ideas?
Thanks,
Jinjie
> v3:
> - Bail out on a BASER type the architecture does not define.
> - Add Suggested-by.
> - Link to v2: https://lore.kernel.org/all/20261117123116.591621-1-ruanjinjie@huawei.com/
> v2:
> - Cleanup the similar calls of its_parse_indirect_baser() (Marc).
> - Simplfy the commit message (Marc).
> - Drop fix tag and comment (Marc).
> - Link to v1: https://lore.kernel.org/all/20261116022330.273840-1-ruanjinjie@huawei.com/
> ---
> drivers/irqchip/irq-gic-v3-its.c | 74 ++++++++++++++++++++++++------
> include/linux/irqchip/arm-gic-v3.h | 2 +
> 2 files changed, 63 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index c952c069f937..50308af8936f 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -67,6 +67,9 @@ static u32 lpi_id_bits;
>
> static u8 __ro_after_init lpi_prop_prio;
> static struct its_node *find_4_1_its(void);
> +static struct its_baser *its_get_baser(struct its_node *its, u32 type);
> +static bool its_alloc_table_entry(struct its_node *its,
> + struct its_baser *baser, u32 id);
>
> /*
> * Collection structure - just an ID, and a redistributor address to
> @@ -2601,16 +2604,43 @@ static struct its_node *find_sibling_its(struct its_node *cur_its)
> return NULL;
> }
>
> +static void its_free_l1_entries(struct its_baser *baser)
> +{
> + __le64 *table = baser->base;
> + u32 i, nr_entries;
> +
> + if (!(baser->val & GITS_BASER_INDIRECT))
> + return;
> +
> + nr_entries = PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE;
> +
> + for (i = 0; i < nr_entries; i++) {
> + u64 entry = le64_to_cpu(table[i]);
> +
> + if (entry & GITS_LVL1_ENTRY_VALID)
> + its_free_pages(phys_to_virt(entry & GITS_LVL1_ENTRY_ADDR),
> + get_order(baser->psz));
> + table[i] = 0;
> + }
> +}
> +
> static void its_free_tables(struct its_node *its)
> {
> int i;
>
> for (i = 0; i < GITS_BASER_NR_REGS; i++) {
> - if (its->tables[i].base) {
> - if (!its->tables[i].shared)
> - its_free_pages(its->tables[i].base, its->tables[i].order);
> - its->tables[i].base = NULL;
> + struct its_baser *baser = &its->tables[i];
> + u64 type = GITS_BASER_TYPE(baser->val);
> +
> + if (!baser->base)
> + continue;
> +
> + if (!baser->shared) {
> + if (type == GITS_BASER_TYPE_COLLECTION)
> + its_free_l1_entries(baser);
> + its_free_pages(baser->base, baser->order);
> }
> + baser->base = NULL;
> }
> }
>
> @@ -2682,7 +2712,7 @@ static int its_alloc_tables(struct its_node *its)
> u64 val = its_read_baser(its, baser);
> u64 type = GITS_BASER_TYPE(val);
> bool indirect = false;
> - u32 order;
> + u32 order, nr_ids;
>
> if (type == GITS_BASER_TYPE_NONE)
> continue;
> @@ -2696,8 +2726,7 @@ static int its_alloc_tables(struct its_node *its)
>
> switch (type) {
> case GITS_BASER_TYPE_DEVICE:
> - indirect = its_parse_indirect_baser(its, baser, &order,
> - device_ids(its));
> + nr_ids = device_ids(its);
> break;
>
> case GITS_BASER_TYPE_VCPU:
> @@ -2713,11 +2742,21 @@ static int its_alloc_tables(struct its_node *its)
> }
> }
>
> - indirect = its_parse_indirect_baser(its, baser, &order,
> - ITS_MAX_VPEID_BITS);
> + nr_ids = ITS_MAX_VPEID_BITS;
> break;
> +
> + case GITS_BASER_TYPE_COLLECTION:
> + nr_ids = order_base_2(nr_cpu_ids);
> + break;
> +
> + default:
> + pr_err("ITS@%pa: BASER%d has invalid type 0x%llx\n",
> + &its->phys_base, i, type);
> + its_free_tables(its);
> + return -ENXIO;
> }
>
> + indirect = its_parse_indirect_baser(its, baser, &order, nr_ids);
> err = its_setup_baser(its, baser, cache, shr, order, indirect);
> if (err < 0) {
> its_free_tables(its);
> @@ -2885,7 +2924,7 @@ static bool allocate_vpe_l2_table(int cpu, u32 id)
> if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
> gic_flush_dcache_to_poc(page_address(page), psz);
>
> - table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
> + table[idx] = cpu_to_le64(page_to_phys(page) | GITS_LVL1_ENTRY_VALID);
>
> /* Flush Lvl1 entry to PoC if hw doesn't support coherency */
> if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
> @@ -3025,6 +3064,7 @@ static int allocate_vpe_l1_table(void)
>
> static int its_alloc_collections(struct its_node *its)
> {
> + struct its_baser *baser;
> int i;
>
> its->collections = kzalloc_objs(*its->collections, nr_cpu_ids);
> @@ -3034,6 +3074,15 @@ static int its_alloc_collections(struct its_node *its)
> for (i = 0; i < nr_cpu_ids; i++)
> its->collections[i].target_address = ~0ULL;
>
> + baser = its_get_baser(its, GITS_BASER_TYPE_COLLECTION);
> + if (!baser || !(baser->val & GITS_BASER_INDIRECT))
> + return 0;
> +
> + for (i = 0; i < nr_cpu_ids; i++) {
> + if (!its_alloc_table_entry(its, baser, i))
> + return -ENOMEM;
> + }
> +
> return 0;
> }
>
> @@ -3395,7 +3444,7 @@ static bool its_alloc_table_entry(struct its_node *its,
> if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
> gic_flush_dcache_to_poc(page_address(page), baser->psz);
>
> - table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
> + table[idx] = cpu_to_le64(page_to_phys(page) | GITS_LVL1_ENTRY_VALID);
>
> /* Flush Lvl1 entry to PoC if hw doesn't support coherency */
> if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
> @@ -5305,7 +5354,7 @@ static int __init its_probe_one(struct its_node *its)
>
> err = its_alloc_collections(its);
> if (err)
> - goto out_free_tables;
> + goto out_free_collection;
>
> baser = (virt_to_phys(its->cmd_base) |
> GITS_CBASER_RaWaWb |
> @@ -5356,7 +5405,6 @@ static int __init its_probe_one(struct its_node *its)
>
> out_free_collection:
> kfree(its->collections);
> -out_free_tables:
> its_free_tables(its);
> out_free_cmd:
> its_free_pages(its->cmd_base, get_order(ITS_CMD_QUEUE_SZ));
> diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
> index ea5fd2374ebe..9792d2052d6d 100644
> --- a/include/linux/irqchip/arm-gic-v3.h
> +++ b/include/linux/irqchip/arm-gic-v3.h
> @@ -493,6 +493,8 @@
> #define GITS_BASER_TYPE_RESERVED7 7
>
> #define GITS_LVL1_ENTRY_SIZE (8UL)
> +#define GITS_LVL1_ENTRY_VALID (1ULL << 63)
> +#define GITS_LVL1_ENTRY_ADDR GENMASK_ULL(51, 12)
>
> /*
> * ITS commands
prev parent reply other threads:[~2026-12-02 7:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:54 Jinjie Ruan
2026-12-02 7:01 ` Jinjie Ruan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8e01142-fd3a-4867-b95d-382b8fa3ba46@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=radu@rendec.net \
--cc=tglx@kernel.org \
--cc=zenghui.yu@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®