From: Thomas Gleixner <tglx@linutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] irq/irq_sim: add locking
Date: Fri, 9 Nov 2018 11:19:16 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.1811091108001.1519@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20181108194116.tjkku7hdqf67awuq@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 1494 bytes --]
On Thu, 8 Nov 2018, Uwe Kleine-König wrote:
> On Thu, Nov 08, 2018 at 05:47:48PM +0100, Bartosz Golaszewski wrote:
> > @@ -74,6 +74,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
> > }
> >
> > init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq);
> > + mutex_init(&sim->lock);
> > sim->irq_count = num_irqs;
> >
> > return sim->irq_base;
> > @@ -142,10 +143,14 @@ EXPORT_SYMBOL_GPL(devm_irq_sim_init);
> > */
> > void irq_sim_fire(struct irq_sim *sim, unsigned int offset)
> > {
> > + mutex_lock(&sim->lock);
> > +
> > if (sim->irqs[offset].enabled) {
> > sim->work_ctx.irq = irq_sim_irqnum(sim, offset);
> > irq_work_queue(&sim->work_ctx.work);
> > }
> > +
> > + mutex_unlock(&sim->lock);
>
> This doesn't fix the issue I think. irq_work_queue() only schedules the
> work function. If after irq_sim_fire() returned but before the worker
> runs another irq_sim_fire() is issued the value is still overwritten.
Right. So the obvious solution is to avoid the irq number store and use a
bitfield instead.
struct irq_sim_work_ctx {
...
unsigned long pending;
};
fire(sim, offset)
{
if (!sim->irqs[offset].enabled)
return;
set_bit(offset, &sim->work_ctx.pending);
....
and in the work handler do:
handle(work)
{
struct irq_sim_work_ctx *ctx = container_of(work,....);
while (ctx->pending) {
offs = ffs(ctx->pending);
clr_bit(offs, &ctx->pending);
handle_simple_irq(offs);
}
}
Or something like that.
Thanks,
tglx
next prev parent reply other threads:[~2018-11-09 10:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-08 16:47 [PATCH] irq/irq_sim: add locking Bartosz Golaszewski
2018-11-08 19:41 ` Uwe Kleine-König
2018-11-08 20:55 ` Bartosz Golaszewski
2018-11-08 21:25 ` Uwe Kleine-König
2018-11-09 10:19 ` Thomas Gleixner [this message]
2018-11-09 11:09 ` Bartosz Golaszewski
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=alpine.DEB.2.21.1811091108001.1519@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=brgl@bgdev.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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).