mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sascha Bischoff <sascha.bischoff@arm.com>
To: Marc Zyngier <maz@kernel.org>,
	 Lorenzo Pieralisi <lpieralisi@kernel.org>,
	 Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>,
	 Timothy Hayes <timothy.hayes@arm.com>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	 Jonathan Cameron <jic23@kernel.org>,
	 "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  Fuad Tabba <fuad.tabba@linux.dev>,
	 Sascha Bischoff <sascha.bischoff@arm.com>
Subject: [PATCH v4 11/13] irqchip/gic-v5: Retain the ITT when device invalidation times out
Date: Wed, 25 Nov 2026 14:40:33 +0000	[thread overview]
Message-ID: <20261125-host_gicv5_fixes-v4-11-0469743c47d8@arm.com> (raw)
In-Reply-To: <20261125-host_gicv5_fixes-v4-0-0469743c47d8@arm.com>

Device registration publishes a DTE pointing to the new ITT before
invalidating the ITS device cache. If invalidation times out, clearing
the DTE in memory does not guarantee that the ITS has discarded a
cached reference to the ITT, and hence the hardware could still try
and access the memory. Freeing the ITT on that path can therefore
leave the ITS accessing memory that has been reallocated.

Device teardown has the same problem: it frees the ITT even when the
invalidation issued after clearing the DTE fails to complete in the
specified timeout.

Retain the ITT on either failure path. Continue returning the
invalidation error, and free the ITT during teardown only after
successful completion. This deliberately retains memory on hardware
failure because a timeout does not cancel the operation or establish
that cached references are gone.

Fixes: 57d72196dfc85 ("irqchip/gic-v5: Add GICv5 ITS support")
Reported-by: Fuad Tabba <fuad.tabba@linux.dev>
Signed-off-by: Sascha Bischoff <sascha.bischoff@arm.com>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Acked-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Link: https://lore.kernel.org/r/20261112145814.853424-1-fuad.tabba@linux.dev
---
 drivers/irqchip/irq-gic-v5-its.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v5-its.c b/drivers/irqchip/irq-gic-v5-its.c
index db13011ef6d9..37835d1600fb 100644
--- a/drivers/irqchip/irq-gic-v5-its.c
+++ b/drivers/irqchip/irq-gic-v5-its.c
@@ -11,6 +11,7 @@
 #include <linux/iommu.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/kmemleak.h>
 #include <linux/msi.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
@@ -165,6 +166,23 @@ static void gicv5_its_free_itt(struct gicv5_its_dev *its_dev)
 		gicv5_its_free_itt_two_level(its_dev);
 }
 
+/* The ITS may still reference these allocations after its_dev is freed. */
+static void gicv5_its_itt_not_leak(struct gicv5_its_dev *its_dev)
+{
+	unsigned int i;
+
+	if (!its_dev->itt_cfg.l2itt) {
+		kmemleak_not_leak(its_dev->itt_cfg.linear.itt);
+		return;
+	}
+
+	for (i = 0; i < its_dev->itt_cfg.l2.num_l1_ents; i++)
+		kmemleak_not_leak(its_dev->itt_cfg.l2.l2ptrs[i]);
+
+	kmemleak_not_leak(its_dev->itt_cfg.l2.l2ptrs);
+	kmemleak_not_leak(its_dev->itt_cfg.l2.l1itt);
+}
+
 static int gicv5_its_create_itt_linear(struct gicv5_its_chip_data *its,
 				       struct gicv5_its_dev *its_dev,
 				       unsigned int event_id_bits)
@@ -540,8 +558,9 @@ static int gicv5_its_device_register(struct gicv5_its_chip_data *its,
 
 	ret = gicv5_its_device_cache_inv(its, its_dev);
 	if (ret) {
+		/* The ITS may still have a cached reference to the ITT. */
 		its_write_table_entry(its, dte, 0);
-		gicv5_its_free_itt(its_dev);
+		gicv5_its_itt_not_leak(its_dev);
 		return ret;
 	}
 
@@ -570,9 +589,15 @@ static int gicv5_its_device_unregister(struct gicv5_its_chip_data *its,
 	its_write_table_entry(its, dte, 0);
 
 	ret = gicv5_its_device_cache_inv(its, its_dev);
+	if (ret) {
+		gicv5_its_itt_not_leak(its_dev);
+		return ret;
+	}
+
+	/* Only release the ITT once the ITS has discarded its references. */
 	gicv5_its_free_itt(its_dev);
 
-	return ret;
+	return 0;
 }
 
 /*

-- 
2.34.1


  parent reply	other threads:[~2026-11-25 14:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 14:40 [PATCH v4 00/13] irqchip/gic-v5: Fix misc IRS and ITS host driver issues Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 01/13] irqchip/gic-v5: Reject SPIs not backed by an IRS Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 02/13] irqchip/gic-v5: Only set IRS DPS when 1ofN routing is supported Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 03/13] irqchip/gic-v5: Serialise IRS synchronisation requests Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 04/13] irqchip/gic-v5: Serialise ITS invalidation commands Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 05/13] irqchip/gic-v5: Use linear DT and ITT when L2 covers all IDs Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 06/13] irqchip/gic-v5: Honour ACPI ITS noncoherent flag Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 07/13] irqchip/gic-v5: Use firmware node name in ITS warning Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 08/13] irqchip/gic-v5: Invalidate ITS device cache before freeing ITT Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 09/13] irqchip/gic-v5: Clean the allocated linear device table size Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 10/13] irqchip/gic-v5: Release ITS MMIO region on DT probe failure Sascha Bischoff
2026-11-25 14:40 ` Sascha Bischoff [this message]
2026-11-25 14:40 ` [PATCH v4 12/13] irqchip/gic-v5: Clean a level 2 device table before making it valid Sascha Bischoff
2026-11-25 14:40 ` [PATCH v4 13/13] irqchip/gic-v5: Invalidate the L1 DTE when allocating an L2 device table Sascha Bischoff

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=20261125-host_gicv5_fixes-v4-11-0469743c47d8@arm.com \
    --to=sascha.bischoff@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=maz@kernel.org \
    --cc=radu@rendec.net \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@kernel.org \
    --cc=timothy.hayes@arm.com \
    /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®