From: Marc Zyngier <maz@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: "Viresh Kumar" <viresh.kumar@linaro.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: Sat, 31 Jul 2021 10:31:53 +0100 [thread overview]
Message-ID: <87v94q25iu.wl-maz@kernel.org> (raw)
In-Reply-To: <CAK8P3a2pMUpLUFFA62pTcH9LBYfo1g+gYGkqDxmBjUfQA2Uong@mail.gmail.com>
On Fri, 30 Jul 2021 11:05:30 +0100,
Arnd Bergmann <arnd@kernel.org> wrote:
>
> On Fri, Jul 30, 2021 at 10:52 AM Marc Zyngier <maz@kernel.org> wrote:
> > On Fri, 30 Jul 2021 07:45:03 +0100, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > > +
> > > +\item If the GPIO line is configured for level interrupts, the device MUST
> > > + ignore an active interrupt signaled on this GPIO line, until the time the
> > > + buffers are made available again by the driver. Once the buffers are
> > > + available again, and the interrupt on the line is still active, the device
> > > + MUST notify the driver again of an interrupt event.
> >
> > It feels like there is a problem here. A virtio device signals
> > interrupts by using edge triggered signalling. Nothing wrong with
> > that. However, signalling a level over a an edge signalling is much
> > more tricky.
> >
> > For example, let's assume that the irqchip driver handles a level
> > interrupt: it gets the message from the device indicating that a GPIO
> > level interrupt is pending. During the handling, the interrupt is made
> > pending again, without having ever transitioned via an inactive state.
> > If you don't have a mechanism to retrigger the level, you have lost an
> > interrupt.
> >
> > I can't see anything in this document that hints at a way to
> > resample/retrigger a level interrupt, which is what you would normally
> > do on EOI for an interrupt controller that implements level-over-edge
> > signalling.
>
> Thanks a lot for taking a closer look. I still hope this is just a problem
> that needs to be clarified in the description, not something wrong with
> the design, as I don't see the problem yet. As far as I can tell, this is
> different from an edge interrupt, since the eventq communication is
> really a two-way message.
I disagree with this description. The signalling is definitely edge
(it is an event, not a change of state). It actually is a two-way edge
signalling. Nothing wrong with that, but all the pitfalls of the edge
signalling do apply.
>
> The EOI for the level interrupt is the message being enqueued after
> the guest is done processing the interrupt. I can see four ways this
> could go:
>
> 1. If the interrupt has not been made pending again yet, nothing happens
> until it eventually becomes pending again (this is the obvious case)
>
> 2. If it is already pending, chip->irq_eoi() causes the new event descriptor
> to be queued on the eventq, and it signals the host about new buffers
> being available. The /host/ samples the level of the line, notices it is
> pending and puts the resulting buffer back on the 'used' queue even
> before returning from the guest 'notify' function.
> The guest virtio core code keeps processing the 'used' buffers and
> gets back into the interrupt handler.
>
> 3. Same as 2., but the host handles the virtqueue ->notify asynchronously,
> and the guest has already checked the 'used' queue before the host
> adds back the buffer to tell it that the line is still active. Now the guest
> gets notified again after it returns from the virtqueue interrupt, in order
> to process the new 'used' buffer.
>
> 4. The gpio line actually goes into inactive state until after the new event
> is queued in chip->irq_eoi(), but becomes active immediately afterwards.
> Now the host gets interrupted and handles this by queuing the event
> reply but cannot interrupt the guest because it is still processing the
> original virtqueue event. However, since the event is queued, it will be
> processed the same way as 2. or 3. by the virtio core.
>
> Do you see a problem with scenarios 2, 3 or 4, or with another case
> that I may have missed?
Thanks, that's really useful. I don't think you missed much. What the
documentation is missing though is an actual interrupt controller
specification. Although it describes the protocol in great length, at
no point does it explain what the irq_response does in terms of
interrupt life cycle (there is no interrupt life cycle at all). Same
goes for the various states that an interrupt can get. As someone who
spends way too much time reading interrupt controller specs, this is a
first class defect.
Another point I have just realised is that this spec confuses
interrupt mask with interrupt enable. It describes masking interrupts
as an effect of setting the trigger type, but that's completely
unusable. There is a strong expectation from SW that a masked
interrupt doesn't loose signals. If the interrupt is masked by setting
its trigger to NONE, then an edge interrupt coming at this point will
be lost. No cookie for you.
I'm fine with this odd way of *enabling* the interrupt, but masking
cannot lose any signal, ever.
Another unclear aspect is how you switch from one trigger type to
another. Do you have to transition via NONE? I have the strong feeling
that you should if you want to be robust against spurious signals.
> [This all assumes that the host is able to atomically enable
> interrupts and check the current level when processing the new
> buffer. If the host uses the Linux gpiolib ioctl interface, this
> means it has to register for an edge event on the line first, and
> then read the current value before adding the file descriptor to its
> poll table. I feel this is out of the scope of the virtio spec
> though.]
There are certainly a number of implementation difficulties with
this. At this stage, I'm more worried about the guest-visible aspects
so far, but I guess that I should also look at the host side at some
point.
Is there any sample code we could look at, both got guest and host?
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2021-07-31 9:31 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 [this message]
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
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=87v94q25iu.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.