irqchip/gic-v3: Lifetime and range fixes in the GICv3 and ITS drivers
cover irqchip/gic-v3: Lifetime and range fixes in the GICv3 and ITS drivers
Hi folks,
Three fixes to the GICv3 and ITS drivers, from reviewing the GIC series floating around and chasing down Sashiko's reports.
The first releases the partition node that gic_irq_get_fwspec_info() takes from of_find_node_by_phandle() and never puts. Sashiko raised it on an of/irq patch of mine, and I said a fix was forthcoming [1].
The second widens the per-device MSI clamp, which truncates to zero when GITS_TYPER.ID_bits is at its maximum and then denies every MSI on that ITS. I couldn't find an implementation that reports that maximum, so this is one value at the edge rather than something anyone is hitting. It carries Cc: stable because the commit it fixes was itself backported, so drop the tag if you'd rather.
The third clears vpt_page once its_vpe_teardown() has freed it, so the NULL guard holds if teardown runs again on the same vPE.
Based on Linux 7.3-rc2 (df2908090cda3).
Cheers,
/fuad
[1] https://lore.kernel.org/all/CA+EHjTx7eP_30vP47=UFk_wMAut-2uf+2DF-MZqn2SLE_k-8qg@mail.gmail.com/
Fuad Tabba (3):
irqchip/gic-v3: Release the partition node in
gic_irq_get_fwspec_info()
irqchip/gic-v3-its: Don't clamp nvecs to zero when id_bits is 32 irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
drivers/irqchip/irq-gic-v3-its.c | 3 ++- drivers/irqchip/irq-gic-v3.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
base-commit: df2908090cda368b01ff43709f51890076c56157
Signature · 1 line
2.39.5
PATCH 1/3 irqchip/gic-v3: Release the partition node in gic_irq_get_fwspec_info()
gic_irq_get_fwspec_info() never puts the node it takes from of_find_node_by_phandle(), so every lookup from a four-cell PPI or EPPI specifier naming a partition leaks one.
The node is only used for the comparison against gic_data.parts[], and the mask returned points into gic_data, so it can go out of scope with the lookup.
--- drivers/irqchip/irq-gic-v3.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/irqchip/irq-gic-v3.c +4 -3
@@ -1728,8 +1728,6 @@ static int gic_irq_get_fwspec_info(struct irq_fwspec *fwspec, struct irq_fwspec_/* If the specifier provides an affinity, use it */ if (fwspec->param_count ==4 && fwspec->param[3 ]) { -struct fwnode_handle *fw; -switch (fwspec->param[0 ]) {case 1 :/* PPI */ case 3 :/* EPPI */
@@ -1738,7 +1736,10 @@ static int gic_irq_get_fwspec_info(struct irq_fwspec *fwspec, struct irq_fwspec_return 0 ; } - fw =of_fwnode_handle (of_find_node_by_phandle (fwspec->param[3 ])); + struct device_node *np __free(device_node) = +of_find_node_by_phandle (fwspec->param[3 ]); +struct fwnode_handle *fw =of_fwnode_handle (np); +if (!fw)return -ENOENT ;
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3: Release the partition node in gic_irq_get_fwspec_info()
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 0773b76611e9c596c825076d422d372697da9940 Gitweb: https://git.kernel.org/tip/0773b76611e9c596c825076d422d372697da9940 Author: Fuad Tabba <[email protected]> AuthorDate: Tue, 08 Sep 2026 15:26:30 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:47 +02:00
irqchip/gic-v3: Release the partition node in gic_irq_get_fwspec_info()
gic_irq_get_fwspec_info() never puts the node it takes from of_find_node_by_phandle(), so every lookup from a four-cell PPI or EPPI specifier naming a partition leaks one.
The node is only used for the comparison against gic_data.parts[], and the mask returned points into gic_data, so it can go out of scope with the lookup.
--- drivers/irqchip/irq-gic-v3.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/irqchip/irq-gic-v3.c +4 -3
@@ -1728,8 +1728,6 @@ static int gic_irq_get_fwspec_info(struct irq_fwspec *fwspec, struct irq_fwspec_/* If the specifier provides an affinity, use it */ if (fwspec->param_count ==4 && fwspec->param[3 ]) { -struct fwnode_handle *fw; -switch (fwspec->param[0 ]) {case 1 :/* PPI */ case 3 :/* EPPI */
@@ -1738,7 +1736,10 @@ static int gic_irq_get_fwspec_info(struct irq_fwspec *fwspec, struct irq_fwspec_return 0 ; } - fw =of_fwnode_handle (of_find_node_by_phandle (fwspec->param[3 ])); + struct device_node *np __free(device_node) = +of_find_node_by_phandle (fwspec->param[3 ]); +struct fwnode_handle *fw =of_fwnode_handle (np); +if (!fw)return -ENOENT ;
PATCH 2/3 irqchip/gic-v3-its: Don't clamp nvecs to zero when id_bits is 32
In reply to Fuad TabbaGITS_TYPER_IDBITS is five bits, so id_bits reaches 32 and min_t(unsigned int, ...) truncates BIT(32) to 0. nvecs becomes 0, its_lpi_alloc() rejects that, and its_msi_prepare() returns -ENOMEM. On 32-bit ARM the shift is undefined instead.
The clamp is correct for every value below the maximum, so only that one value is affected.
--- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -3484,7 +3484,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,* Also honor the ITS's own EID limit. */ id_bits =FIELD_GET (GITS_TYPER_IDBITS , its->typer) +1 ; - nvecs = min_t(unsigned int, nvecs, BIT(id_bits)); + nvecs =min_t (u64, nvecs,BIT_ULL (id_bits)); nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN );
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3-its: Don't clamp nvecs to zero when id_bits is 32
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 5a9d62555e7164ec79a5fe70153d79cf1fdfd614 Gitweb: https://git.kernel.org/tip/5a9d62555e7164ec79a5fe70153d79cf1fdfd614 Author: Fuad Tabba <[email protected]> AuthorDate: Tue, 08 Sep 2026 15:26:31 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:47 +02:00
irqchip/gic-v3-its: Don't clamp nvecs to zero when id_bits is 32
GITS_TYPER_IDBITS is five bits, so id_bits reaches 32 and min_t(unsigned int, ...) truncates BIT(32) to 0. nvecs becomes 0, its_lpi_alloc() rejects that, and its_msi_prepare() returns -ENOMEM. On 32-bit ARM the shift is undefined instead.
The clamp is correct for every value below the maximum, so only that one value is affected.
--- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -3485,7 +3485,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,* Also honor the ITS's own EID limit. */ id_bits =FIELD_GET (GITS_TYPER_IDBITS , its->typer) +1 ; - nvecs = min_t(unsigned int, nvecs, BIT(id_bits)); + nvecs =min_t (u64, nvecs,BIT_ULL (id_bits)); nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN );
PATCH 3/3 irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
In reply to Fuad Tabbaits_vpe_teardown() frees vpt_page without clearing it, so its vpt_page == NULL guard only holds the first time it runs on a vPE. struct its_vpe outlives a failed KVM_DEV_ARM_VGIC_CTRL_INIT, so a retry that fails again frees the pending table and the vPE ID a second time.
--- drivers/irqchip/irq-gic-v3-its.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v3-its.c +1 -0
@@ -4599,6 +4599,7 @@ static void its_vpe_teardown(struct its_vpe *vpe)its_vpe_db_proxy_unmap (vpe);its_vpe_id_free (vpe->vpe_id);its_free_pending_table (vpe->vpt_page); + vpe->vpt_page =NULL ; } static void its_vpe_irq_domain_free(struct irq_domain *domain,
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 0d604b1e4617d18dbb5573290ba447d7369251d1 Gitweb: https://git.kernel.org/tip/0d604b1e4617d18dbb5573290ba447d7369251d1 Author: Fuad Tabba <[email protected]> AuthorDate: Tue, 08 Sep 2026 15:26:32 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:47 +02:00
irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
its_vpe_teardown() frees vpt_page without clearing it, so its vpt_page == NULL guard only holds the first time it runs on a vPE. struct its_vpe outlives a failed KVM_DEV_ARM_VGIC_CTRL_INIT, so a retry that fails again frees the pending table and the vPE ID a second time.
--- drivers/irqchip/irq-gic-v3-its.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v3-its.c +1 -0
@@ -4600,6 +4600,7 @@ static void its_vpe_teardown(struct its_vpe *vpe)its_vpe_db_proxy_unmap (vpe);its_vpe_id_free (vpe->vpe_id);its_free_pending_table (vpe->vpt_page); + vpe->vpt_page =NULL ; } static void its_vpe_irq_domain_free(struct irq_domain *domain,
Quoted 17 lines · Fuad Tabba
Hi folks,
Three fixes to the GICv3 and ITS drivers, from reviewing the GIC series floating around and chasing down Sashiko's reports.
The first releases the partition node that
gic_irq_get_fwspec_info()takes fromof_find_node_by_phandle()and never puts. Sashiko raised it on an of/irq patch of mine, and I said a fix was forthcoming [1].The second widens the per-device MSI clamp, which truncates to zero when GITS_TYPER.ID_bits is at its maximum and then denies every MSI on that ITS. I couldn't find an implementation that reports that maximum, so this is one value at the edge rather than something anyone is hitting. It carries Cc: stable because the commit it fixes was itself backported, so drop the tag if you'd rather.
Quoted 4 lines
The third clears
vpt_pageonceits_vpe_teardown()has freed it, so the NULL guard holds if teardown runs again on the same vPE.Based on Linux 7.3-rc2 (
df2908090cda3).
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 32 lines · Fuad Tabba
Hi folks,
Three fixes to the GICv3 and ITS drivers, from reviewing the GIC series floating around and chasing down Sashiko's reports.
The first releases the partition node that
gic_irq_get_fwspec_info()takes fromof_find_node_by_phandle()and never puts. Sashiko raised it on an of/irq patch of mine, and I said a fix was forthcoming [1].The second widens the per-device MSI clamp, which truncates to zero when GITS_TYPER.ID_bits is at its maximum and then denies every MSI on that ITS. I couldn't find an implementation that reports that maximum, so this is one value at the edge rather than something anyone is hitting. It carries Cc: stable because the commit it fixes was itself backported, so drop the tag if you'd rather.
The third clears
vpt_pageonceits_vpe_teardown()has freed it, so the NULL guard holds if teardown runs again on the same vPE.Based on Linux 7.3-rc2 (
df2908090cda3).Cheers,
/fuad[1] https://lore.kernel.org/all/CA+EHjTx7eP_30vP47=UFk_wMAut-2uf+2DF-MZqn2SLE_k-8qg@mail.gmail.com/
Fuad Tabba (3):
irqchip/gic-v3: Release the partition node ingic_irq_get_fwspec_info()
irqchip/gic-v3-its: Don't clamp nvecs to zero whenid_bitsis 32 irqchip/gic-v3-its: Clearvpt_pageafter freeing the pending table
Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c | 3 ++-
drivers/irqchip/irq-gic-v3.c | 7 ++++---2 files changed, 6 insertions(+), 4 deletions(-)base-commit:
df2908090cda368b01ff43709f51890076c56157
Hi Fuad,
Quoted 32 lines · Fuad Tabba
Hi folks,
Three fixes to the GICv3 and ITS drivers, from reviewing the GIC series floating around and chasing down Sashiko's reports.
The first releases the partition node that
gic_irq_get_fwspec_info()takes fromof_find_node_by_phandle()and never puts. Sashiko raised it on an of/irq patch of mine, and I said a fix was forthcoming [1].The second widens the per-device MSI clamp, which truncates to zero when GITS_TYPER.ID_bits is at its maximum and then denies every MSI on that ITS. I couldn't find an implementation that reports that maximum, so this is one value at the edge rather than something anyone is hitting. It carries Cc: stable because the commit it fixes was itself backported, so drop the tag if you'd rather.
The third clears
vpt_pageonceits_vpe_teardown()has freed it, so the NULL guard holds if teardown runs again on the same vPE.Based on Linux 7.3-rc2 (
df2908090cda3).Cheers,
/fuad[1] https://lore.kernel.org/all/CA+EHjTx7eP_30vP47=UFk_wMAut-2uf+2DF-MZqn2SLE_k-8qg@mail.gmail.com/
Fuad Tabba (3):
irqchip/gic-v3: Release the partition node in
gic_irq_get_fwspec_info()
irqchip/gic-v3-its: Don't clamp nvecs to zero whenid_bitsis 32 irqchip/gic-v3-its: Clearvpt_pageafter freeing the pending table
Quoted 3 lines
drivers/irqchip/irq-gic-v3-its.c | 3 ++- drivers/irqchip/irq-gic-v3.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
All look good to me. Thanks for the fixes!
Zenghui
Hi Thomas,
Quoted 17 lines · Fuad Tabba
Hi folks,
Three fixes to the GICv3 and ITS drivers, from reviewing the GIC series floating around and chasing down Sashiko's reports.
The first releases the partition node that
gic_irq_get_fwspec_info()takes fromof_find_node_by_phandle()and never puts. Sashiko raised it on an of/irq patch of mine, and I said a fix was forthcoming [1].The second widens the per-device MSI clamp, which truncates to zero when GITS_TYPER.ID_bits is at its maximum and then denies every MSI on that ITS. I couldn't find an implementation that reports that maximum, so this is one value at the edge rather than something anyone is hitting. It carries Cc: stable because the commit it fixes was itself backported, so drop the tag if you'd rather.
Quoted 4 lines
The third clears
vpt_pageonceits_vpe_teardown()has freed it, so the NULL guard holds if teardown runs again on the same vPE.Based on Linux 7.3-rc2 (
df2908090cda3).
Gentle ping on this one; it has R-bs from Marc, Radu and Zenghui. Anything else needed for it?
Cheers,
/fuad
Quoted 21 lines
Cheers,
/fuad[1] https://lore.kernel.org/all/CA+EHjTx7eP_30vP47=UFk_wMAut-2uf+2DF-MZqn2SLE_k-8qg@mail.gmail.com/
Fuad Tabba (3):
irqchip/gic-v3: Release the partition node in
gic_irq_get_fwspec_info()
irqchip/gic-v3-its: Don't clamp nvecs to zero whenid_bitsis 32 irqchip/gic-v3-its: Clearvpt_pageafter freeing the pending tabledrivers/irqchip/irq-gic-v3-its.c | 3 ++- drivers/irqchip/irq-gic-v3.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)base-commit:
df2908090cda368b01ff43709f51890076c56157--
2.39.5
yang
Tested-byHi,
Reproduced on /dev/hmv (HarmonyOS KVM). It advertises GITS_TYPER=0x803ff71 (IDBITS=0x1f), which triggers the unsigned-int truncation and causes nvecs to become 0.