From: Marc Zyngier <maz@kernel.org>
To: Lorenzo Pieralisi <lpieralisi@kernel.org>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Thomas Gleixner <tglx@linutronix.de>,
Sascha Bischoff <sascha.bischoff@arm.com>,
Timothy Hayes <timothy.hayes@arm.com>
Subject: Re: [PATCH 2/4] irqchip/gic-v3-its: Implement .msi_teardown() callback
Date: Mon, 12 May 2025 18:00:33 +0100 [thread overview]
Message-ID: <86r00tg3wu.wl-maz@kernel.org> (raw)
In-Reply-To: <aCIiQmfDUNrOCC2y@lpieralisi>
On Mon, 12 May 2025 17:30:58 +0100,
Lorenzo Pieralisi <lpieralisi@kernel.org> wrote:
>
> On Sun, May 11, 2025 at 05:35:18PM +0100, Marc Zyngier wrote:
> > We currently nuke the structure representing an endpoint device
> > translating via an ITS on freeing the last LPI allocated for it.
> >
> > That's an unfortunate state of affair, as it is pretty common for
> > a driver to allocate a single MSI, do something clever, teardown
> > this MSI, and reallocate a whole bunch of them. The nvme driver
> > does exactly that, amongst others.
> >
> > What happens in that case is that the core code is buggy enough
> > to issue another .msi_prepare() call, even if it shouldn't.
> > This luckily cancels the above behaviour and hides the problem.
> >
> > In order to fix the core code, let's start by implementing the new
> > .msi_teardown() callback. Nothing calls it yet, so a side effect
> > is that the its_dev structure will not be freed and that the DID
> > will stay mapped. Not a big deal, and this will be solved in the
> > following patch.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > drivers/irqchip/irq-gic-v3-its-msi-parent.c | 10 ++++
> > drivers/irqchip/irq-gic-v3-its.c | 56 +++++++++++++--------
> > 2 files changed, 45 insertions(+), 21 deletions(-)
>
> First off, thanks a lot for putting this together, it makes an awful
> lot of sense to me.
>
> > index 0115ad6c82593..3472b97477104 100644
> > --- a/drivers/irqchip/irq-gic-v3-its.c
> > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > @@ -3620,8 +3620,43 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> > return err;
> > }
> >
> > +static void its_msi_teardown(struct irq_domain *domain, msi_alloc_info_t *info)
> > +{
> > + struct msi_domain_info *msi_info;
> > + struct its_device *its_dev;
> > + struct its_node *its;
> > + u32 dev_id;
> > +
> > + dev_id = info->scratchpad[0].ul;
>
> I have just managed to get to a keyboard :), I don't think the dev_id
> makes it to this point, we overwrite it with the its_dev pointer in
> its_msi_prepare() (could use second scratchpad for the pointer maybe ?).
>
> I was bitten by this while removing the old IWB code into the new one
> (unrelated to this code but that's how I noticed scratchpad is a union).
Gah, this is missing the fixup I had on top and that I didn't squash:
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index d8c4d3b8256f3..7e0e7f0160936 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -3622,19 +3622,9 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
static void its_msi_teardown(struct irq_domain *domain, msi_alloc_info_t *info)
{
- struct msi_domain_info *msi_info;
- struct its_device *its_dev;
- struct its_node *its;
- u32 dev_id;
-
- dev_id = info->scratchpad[0].ul;
-
- msi_info = msi_get_domain_info(domain);
- its = msi_info->data;
-
- guard(mutex)(&its->dev_alloc_lock);
+ struct its_device *its_dev = info->scratchpad[0].ptr;
- its_dev = its_find_device(its, dev_id);
+ guard(mutex)(&its_dev->its->dev_alloc_lock);
/* If the device is shared, keep everything around */
if (its_dev->shared)
So no need for another scratchpad entry -- the device structure has
everything we need. I'll repost things with tglx's comments addressed
and this fix correctly squashed in.
Sorry for the noise,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-05-12 17:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 16:35 [PATCH 0/4] genirq/msi: Fix device MSI prepare/alloc sequencing Marc Zyngier
2025-05-11 16:35 ` [PATCH 1/4] genirq/msi: Add .msi_teardown() callback as the reverse of .msi_prepare() Marc Zyngier
2025-05-12 14:29 ` Thomas Gleixner
2025-05-12 15:57 ` Marc Zyngier
2025-05-12 18:46 ` Thomas Gleixner
2025-05-11 16:35 ` [PATCH 2/4] irqchip/gic-v3-its: Implement .msi_teardown() callback Marc Zyngier
2025-05-12 14:34 ` Thomas Gleixner
2025-05-12 16:09 ` Marc Zyngier
2025-05-12 18:47 ` Thomas Gleixner
2025-05-12 16:30 ` Lorenzo Pieralisi
2025-05-12 17:00 ` Marc Zyngier [this message]
2025-05-11 16:35 ` [PATCH 3/4] genirq/msi: Move prepare() call to per-device allocation Marc Zyngier
2025-05-12 14:24 ` Thomas Gleixner
2025-05-12 15:55 ` Marc Zyngier
2025-05-11 16:35 ` [PATCH 4/4] irqchip/gic-v3-its: Use allocation size from the prepare call Marc Zyngier
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=86r00tg3wu.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=sascha.bischoff@arm.com \
--cc=tglx@linutronix.de \
--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;
as well as URLs for NNTP newsgroup(s).