All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Jassi Brar <jassisinghbrar@gmail.com>
Cc: Devicetree List <devicetree@vger.kernel.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	mliljeberg@nvidia.com, Mikko Perttunen <mperttunen@nvidia.com>,
	talho@nvidia.com, linux-serial@vger.kernel.org, jslaby@suse.com,
	linux-tegra@vger.kernel.org, ppessi@nvidia.com,
	Jon Hunter <jonathanh@nvidia.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 01/10] mailbox: Support blocking transfers in atomic context
Date: Thu, 29 Nov 2018 16:23:12 +0100	[thread overview]
Message-ID: <20181129152312.GB23750@ulmo> (raw)
In-Reply-To: <CABb+yY1u24JYO68f74qSJ1RpqidJ4H7cnP1Sy=RdqcBHru5XQg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 5944 bytes --]

On Wed, Nov 28, 2018 at 11:23:36PM -0600, Jassi Brar wrote:
> On Wed, Nov 28, 2018 at 3:43 AM Jon Hunter <jonathanh@nvidia.com> wrote:
> >
> >
> > On 12/11/2018 15:18, Thierry Reding wrote:
> > > From: Thierry Reding <treding@nvidia.com>
> > >
> > > The mailbox framework supports blocking transfers via completions for
> > > clients that can sleep. In order to support blocking transfers in cases
> > > where the transmission is not permitted to sleep, add a new ->flush()
> > > callback that controller drivers can implement to busy loop until the
> > > transmission has been completed. This will automatically be called when
> > > available and interrupts are disabled for clients that request blocking
> > > transfers.
> > >
> > > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > > ---
> > >  drivers/mailbox/mailbox.c          | 8 ++++++++
> > >  include/linux/mailbox_controller.h | 4 ++++
> > >  2 files changed, 12 insertions(+)
> > >
> > > diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
> > > index 674b35f402f5..0eaf21259874 100644
> > > --- a/drivers/mailbox/mailbox.c
> > > +++ b/drivers/mailbox/mailbox.c
> > > @@ -267,6 +267,14 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
> > >               unsigned long wait;
> > >               int ret;
> > >
> > > +             if (irqs_disabled() && chan->mbox->ops->flush) {
> > > +                     ret = chan->mbox->ops->flush(chan, chan->cl->tx_tout);
> > > +                     if (ret < 0)
> > > +                             tx_tick(chan, ret);
> > > +
> > > +                     return ret;
> > > +             }
> >
> > It seems to me that if mbox_send_message() is called from an atomic
> > context AND tx_block is true, then if 'flush' is not populated this
> > should be an error condition as we do not wish to call
> > wait_for_completion from an atomic context.
> >
> > I understand that there is some debate about adding such flush support,
> > but irrespective of the above change, it seems to me that if the
> > mbox_send_message() can be called from an atomic context (which it
> > appears to), then it should be detecting if someone is trying to do so
> > with 'tx_block' set as this should be an error.
> >
> Layers within kernel space have to trust each other. A badly written
> client can break the consumer in so many ways, we can not catch every
> possibility.
> 
> > Furthermore, if the underlying mailbox driver can support sending a
> > message from an atomic context and busy wait until it is done, surely
> > the mailbox framework should provide a means to support this?
> >
> Being able to put the message on bus in atomic context is a feature -
> which we do support. But busy-waiting in a loop is not a feature, and
> we don't want to encourage that.

I agree that in generally busy-waiting is a bad idea and shouldn't be
encouraged. However, I also think that an exception proves the rule. If
you look at the console drivers in drivers/tty/serial, all of them will
busy loop prior to or after sending a character. This is pretty much
part of the API and as such busy-looping is very much a feature.

The reason why this is done is because on one hand we have an atomic
context and on the other hand we want to make sure that all characters
actually make it to the console when we print them.

As an example how this can break, I've taken your suggestion to
implement a producer/consumer mode in the TCU driver where the console
write function will just stash characters into a circular buffer and a
work queue will then use mbox_send_message() to drain the circular
buffer. While this does work on the surface, I was able to concern both
of the issues that I was concerned about: 1) it is easy to overflow the
circular buffer by just dumping enough data at once to the console and
2) when a crash happens, everything in the kernel stops, including the
consumer workqueue that is supposed to drain the circular buffer and
flush messages to the TCU. The result is that, in my particular case,
the boot log will just stop at a random place in the middle of messages
from much earlier in the boot because the TCU hasn't caught up yet and
there's a lot of characters still in the circular buffer.

Now, 1) can be mitigated by increasing the circular buffer size. A value
that seems to give reliably good results in 2 << CONFIG_LOG_BUF_SHIFT. I
thought that I could also mitigate 2) by busy looping in the TCU driver,
but it turns out that that doesn't work. The reason is that since we are
in atomic context with all interrupts disabled, the mailbox won't ever
consume any new characters, so the read pointer in the circular buffer
won't increment, leaving me with no condition upon which to loop that
would work.

Given that 2) can't be solved makes this implementation of the TCU
completely useless as a console.

All of that said, have you had a chance to look at my other proposed
solution for this? I sent it out yesterday, but you can also find the
series here:

	http://patchwork.ozlabs.org/project/linux-tegra/list/?series=78477

The difference to the earlier versions is that the flushing is now
explicit. I think this combines the best of both worlds. On one hand it
makes the mechanism completely opt-in, so nothing gets hidden in the
regular functions. On the other hand, it allows clients to make use of
this functionality very explicitly. A client that doesn't call the
mbox_flush() function will just not busy-loop. But clients that need to
make sure messages are flushed in atomic contexts can now do that. Does
that sound like a more acceptable solution to you? We could even go and
add documentation to mbox_flush() that it should only be used under
special circumstances.

If you still think that's a bad idea, do you have any other suggestions
on how to move forward?

Thierry

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2018-11-29 15:23 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12 15:18 [PATCH v2 00/10] serial: Add Tegra Combined UART driver Thierry Reding
2018-11-12 15:18 ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 01/10] mailbox: Support blocking transfers in atomic context Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-17 17:27   ` Jassi Brar
2018-11-17 17:27     ` Jassi Brar
2018-11-20 15:29     ` Thierry Reding
2018-11-20 15:29       ` Thierry Reding
2018-11-21 14:27       ` Thierry Reding
2018-11-21 14:27         ` Thierry Reding
2018-11-22  2:18         ` Jassi Brar
2018-11-22  2:18           ` Jassi Brar
2018-11-22  8:47           ` Thierry Reding
2018-11-22  8:47             ` Thierry Reding
2018-11-22 16:07             ` Jassi Brar
2018-11-22 16:07               ` Jassi Brar
2018-11-22 17:34               ` Thierry Reding
2018-11-22 17:34                 ` Thierry Reding
2018-11-23 11:17             ` Thierry Reding
2018-11-23 11:17               ` Thierry Reding
2018-11-23 11:56               ` Thierry Reding
2018-11-23 11:56                 ` Thierry Reding
2018-11-28  9:43   ` Jon Hunter
2018-11-28  9:43     ` Jon Hunter
2018-11-28 10:08     ` Thierry Reding
2018-11-28 10:08       ` Thierry Reding
2018-11-29  5:23     ` Jassi Brar
2018-11-29  5:23       ` Jassi Brar
2018-11-29 15:23       ` Thierry Reding [this message]
2018-12-07  5:56         ` Jassi Brar
2018-12-07  5:56           ` Jassi Brar
2018-12-07  6:19           ` Mikko Perttunen
2018-12-07  6:19             ` Mikko Perttunen
2018-12-08  5:51             ` Jassi Brar
2018-12-08  5:51               ` Jassi Brar
2018-12-08  8:50               ` Greg KH
2018-12-08  8:50                 ` Greg KH
2018-12-09  1:20                 ` Jassi Brar
2018-12-09  1:20                   ` Jassi Brar
2018-12-07 11:32           ` Thierry Reding
2018-12-07 15:39             ` Greg KH
2018-12-07 15:39               ` Greg KH
2018-12-08  6:09             ` Jassi Brar
2018-12-08  6:09               ` Jassi Brar
2018-12-10  9:52               ` Thierry Reding
2018-12-10 20:30                 ` Jassi Brar
2018-12-10 20:30                   ` Jassi Brar
2018-12-10 20:45                   ` Thierry Reding
2018-12-10 21:32                     ` Jassi Brar
2018-12-10 21:32                       ` Jassi Brar
2018-11-12 15:18 ` [PATCH v2 02/10] mailbox: Allow multiple controllers per device Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 03/10] dt-bindings: tegra186-hsp: Add shared mailboxes Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 04/10] mailbox: tegra-hsp: Add support for " Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-13 11:09   ` Jon Hunter
2018-11-13 11:09     ` Jon Hunter
2018-11-13 13:09     ` Thierry Reding
2018-11-13 13:09       ` Thierry Reding
2018-11-13 19:24       ` Jon Hunter
2018-11-13 19:24         ` Jon Hunter
2018-11-12 15:18 ` [PATCH v2 05/10] mailbox: tegra-hsp: Add suspend/resume support Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-13 11:17   ` Jon Hunter
2018-11-13 11:17     ` Jon Hunter
2018-12-10  9:58     ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 06/10] dt-bindings: serial: Add bindings for nvidia, tegra194-tcu Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-13  9:39   ` [PATCH v2 06/10] dt-bindings: serial: Add bindings for nvidia,tegra194-tcu Jon Hunter
2018-11-13  9:39     ` Jon Hunter
2018-11-13 10:03     ` Thierry Reding
2018-11-13 10:03       ` Thierry Reding
2018-11-13 10:11       ` Jon Hunter
2018-11-13 10:11         ` Jon Hunter
2018-11-12 15:18 ` [PATCH v2 07/10] serial: Add Tegra Combined UART driver Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 08/10] arm64: tegra: Add nodes for TCU on Tegra194 Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 09/10] arm64: tegra: Mark TCU as primary serial port on Tegra194 P2888 Thierry Reding
2018-11-12 15:18   ` Thierry Reding
2018-11-12 15:18 ` [PATCH v2 10/10] arm64: defconfig: Enable Tegra TCU Thierry Reding
2018-11-12 15:18   ` Thierry Reding

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=20181129152312.GB23750@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=jslaby@suse.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mliljeberg@nvidia.com \
    --cc=mperttunen@nvidia.com \
    --cc=ppessi@nvidia.com \
    --cc=talho@nvidia.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 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.