All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <bgolaszewski@baylibre.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Jean-Philippe Brucker" <jean-philippe@linaro.org>,
	"Bill Mills" <bill.mills@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Enrico Weigelt, metux IT consult" <info@metux.net>,
	virtio-dev@lists.oasis-open.org,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Stratos Mailing List" <stratos-dev@op-lists.linaro.org>,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [PATCH V8 2/2] virtio-gpio: Add support for interrupts
Date: Mon, 02 Aug 2021 12:09:15 +0100	[thread overview]
Message-ID: <87pmuw14tg.wl-maz@kernel.org> (raw)
In-Reply-To: <20210802104942.ovjnouzourvb7vdd@vireshk-i7>

On Mon, 02 Aug 2021 11:49:42 +0100,
Viresh Kumar <viresh.kumar@linaro.org> wrote:
> 
> Hi Marc,
> 
> On 02-08-21, 10:45, Marc Zyngier wrote:
> > On Sun, 01 Aug 2021 14:43:37 +0100,
> > Arnd Bergmann <arnd@kernel.org> wrote:
> > > What are the requirements for a ->irq_mask() operation? Can this
> > > be called in atomic context? If it can, is it allowed to be posted
> > > (e.g. by queuing a new command without waiting for the reply)?
> > 
> > irq_mask() can definitely be called in atomic context. But in this
> > case the driver must implement the bus_lock madness and commit changes
> > to the backend on unlock. See how most of the I2C GPIO implementations
> > work.
> 
> Right, I already have that in place but I have a few doubts on that.
> 
> I can see irq_bus_lock/unlock() getting called around
> irq_mask/unmask/set_type() during request_irq(), and so I can issue
> all the virtio calls from irq_bus_unlock() there.
> 
> But I don't see the same sequence being followed by the irq core
> when an interrupt actually happens, i.e. when I call
> generic_handle_irq() from virtqueue callback for eventq vq. In this
> case, the irq core can directly call mask/unmask() around irq_eoi(),
> without calling the irq_bus_lock/unlock() guards.

You can't take that lock from the core irq code, for obvious reasons:
you're in IRQ context, and you cannot sleep. You definitely need to
use threaded interrupts for this.

> 
> How should the driver take care of these mask/unmask calls, or should it take
> care of it at all, as they should negate each other eventually ?
> 
> > Obviously, this has an effect on performance and complexity. It would
> > be a lot better if there was a way to perform the mask/unmask
> > operations synchronously, without the need of a buffer. For example,
> > virtio-console has the so called 'emergency write' feature, which
> > allows for write operations without any buffer.
> 
> We discussed this sometime back over IRC, and Jean Philippe said this in context
> of virtio-iommu:
> 
>  "From some profiling the overhead of context switching is much greater than
>  that of adding buffers, so adding a new virtio interface to bypass the
>  virtqueue might not show any improvement."
>

If you need something to be synchronous, there is not exactly a
choice. Masking an interrupt is something that is much better as a
synchronous interface, because it leads to tons of further
simplifications. And in my book, simplicity is a much easier path to
correctness.

> We were looking to explore the config space for normal GPIO
> operations as well then.
> 
> The host would be required to perform some action here on a config update and
> the guest would be waiting over an atomic operation for it to complete. So
> eventually it should also be slow.
> 
> > The later would allow the implementation of a "fire and forget"
> > mask/unmask that would still be synchronous.
> 
> > > Alternatively, would it be possible to simply emulate the 'irq_mask()'
> > > operation in software, by not delivering the next interrupt to the
> > > handler until the driver calls irq_unmask()? Once it's been delivered,
> > > it would just not get requeued in this case.
> > 
> > That'd be a poor-man's solution, as you would still get host
> > notifications, which could have an impact in the case of a screaming
> > interrupt.
> 
> Right, irq_bus_unlock() works fine for this though.

To some extent (insert a comment about thrust and flying pigs here).
It imposes a lot of restrictions, adds latency, and makes it harder to
reason about when what happens when. It also means that you are
probably designing for Linux instead of building something more
generic.

Having contributed to a PV interrupt architecture in the recent past,
I quickly realised that keeping things as simple as possible was a
good way to avoid baked-in assumptions. Yes, a synchronous interface
results in a few extra traps. But you can also now reason about it and
*prove* things. YMMV.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.


  reply	other threads:[~2021-08-02 11:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  6:45 [PATCH V8 0/2] virtio: Add specification for virtio-gpio Viresh Kumar
2021-07-30  6:45 ` [PATCH V8 1/2] virtio-gpio: Add the device specification Viresh Kumar
2021-08-06 16:02   ` [virtio-dev] " Cornelia Huck
2021-08-09  4:15     ` Viresh Kumar
2021-08-09  5:50       ` [virtio-dev] " Cornelia Huck
2021-07-30  6:45 ` [PATCH V8 2/2] virtio-gpio: Add support for interrupts Viresh Kumar
2021-07-30  8:08   ` Arnd Bergmann
2021-08-02  5:12     ` Viresh Kumar
2021-07-30  8:52   ` Marc Zyngier
2021-07-30 10:05     ` Arnd Bergmann
2021-07-31  9:31       ` Marc Zyngier
2021-08-01 13:43         ` Arnd Bergmann
2021-08-02  5:54           ` Viresh Kumar
2021-08-02  9:45           ` Marc Zyngier
2021-08-02 10:49             ` Viresh Kumar
2021-08-02 11:09               ` Marc Zyngier [this message]
2021-08-02 11:25             ` Arnd Bergmann

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=87pmuw14tg.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=alex.bennee@linaro.org \
    --cc=arnd@kernel.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=bill.mills@linaro.org \
    --cc=cohuck@redhat.com \
    --cc=geert@linux-m68k.org \
    --cc=info@metux.net \
    --cc=jasowang@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=mst@redhat.com \
    --cc=stratos-dev@op-lists.linaro.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=virtio-dev@lists.oasis-open.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.