All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: Stefan Lengfeld <contact@stefanchrist.eu>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-i2c@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Peter Rosin <peda@axentia.se>,
	linux-omap@vger.kernel.org, linux-tegra@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH 01/12] i2c: remove use of in_atomic()
Date: Tue, 16 Apr 2019 12:48:23 +0200	[thread overview]
Message-ID: <20190416104823.zabxzdxarzfhdw7m@ninjato> (raw)
In-Reply-To: <20190415215546.xr7aftkahcu4ygak@porty>

[-- Attachment #1: Type: text/plain, Size: 2384 bytes --]

Hi Stefan,

> Tested-by: Stefan Lengfeld <contact@stefanchrist.eu>

Thanks for your comments and testing! I will fix the issues you
mentioned and add your tags.

> > +/*
> > + * We only allow atomic transfers for very late communication, e.g. to send
> > + * the powerdown command to a PMIC. Atomic transfers are a corner case and not
> > + * for generic use!
> > + */
> > +static inline bool i2c_in_atomic_xfer_mode(void)
> > +{
> > +	return system_state > SYSTEM_RUNNING && irqs_disabled();
> > +}
> 
> I agree that this code is a lot better than the previous
> 'irqs_disabled() || in_atomic()'. It also makes clear that the atomic
> I2C transfers is only meant for late shutdown I2C communcation.
> 
> 
> After I read the article https://lwn.net/Articles/274695/ again I
> nevertheless cannot really say whether the usage of 'irqs_disabled()' is
> the theoretical correct approach. The article states explicitly that
> only the caller can really decided whether the operation should be
> atomic or not.

During the discussion with Peter, he stated we need irqs_disabled()
because 'system_state > SYSTEM_RUNNING' alone won't do.

> Recap from previous discussions:
> 
> But then you have to patch every call site to use either a new function
> like 'i2c_transfer_atomic()' or the extend I2C message flags. And mostly
> also supported this trough regmap and maybe other translation layers,
> which seems unpractical, may breaking existing usages and maybe not
> worth the hassle.

Yes, I kinda gave up on white-listing late I2C transfers. My hope is
that not too many drivers will have an atomic callback, so the WARN will
trigger often enough to find late transfers which are inappropriate.

Another idea just popping up: Maybe we can improve that even further by
first globally disabling atomic transfers. Drivers knowing they need
this can then call an I2C core helper to enable them (again globally).
Still not perfect as some unwanted late I2C transfers from another
driver could slip through, but this should be rare enough. The pro-side
is we will detect more unwanted late transfers if support for them is
default off. It should be noted that "disabling" means keeping the old
behaviour which is: we try the regular transfer but complain about it.
Only enabling atomic will make the core quiet.

Regards,

   Wolfram


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

WARNING: multiple messages have this Message-ID (diff)
From: Wolfram Sang <wsa@the-dreams.de>
To: Stefan Lengfeld <contact@stefanchrist.eu>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org,
	linux-omap@vger.kernel.org, Peter Rosin <peda@axentia.se>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 01/12] i2c: remove use of in_atomic()
Date: Tue, 16 Apr 2019 12:48:23 +0200	[thread overview]
Message-ID: <20190416104823.zabxzdxarzfhdw7m@ninjato> (raw)
In-Reply-To: <20190415215546.xr7aftkahcu4ygak@porty>


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

Hi Stefan,

> Tested-by: Stefan Lengfeld <contact@stefanchrist.eu>

Thanks for your comments and testing! I will fix the issues you
mentioned and add your tags.

> > +/*
> > + * We only allow atomic transfers for very late communication, e.g. to send
> > + * the powerdown command to a PMIC. Atomic transfers are a corner case and not
> > + * for generic use!
> > + */
> > +static inline bool i2c_in_atomic_xfer_mode(void)
> > +{
> > +	return system_state > SYSTEM_RUNNING && irqs_disabled();
> > +}
> 
> I agree that this code is a lot better than the previous
> 'irqs_disabled() || in_atomic()'. It also makes clear that the atomic
> I2C transfers is only meant for late shutdown I2C communcation.
> 
> 
> After I read the article https://lwn.net/Articles/274695/ again I
> nevertheless cannot really say whether the usage of 'irqs_disabled()' is
> the theoretical correct approach. The article states explicitly that
> only the caller can really decided whether the operation should be
> atomic or not.

During the discussion with Peter, he stated we need irqs_disabled()
because 'system_state > SYSTEM_RUNNING' alone won't do.

> Recap from previous discussions:
> 
> But then you have to patch every call site to use either a new function
> like 'i2c_transfer_atomic()' or the extend I2C message flags. And mostly
> also supported this trough regmap and maybe other translation layers,
> which seems unpractical, may breaking existing usages and maybe not
> worth the hassle.

Yes, I kinda gave up on white-listing late I2C transfers. My hope is
that not too many drivers will have an atomic callback, so the WARN will
trigger often enough to find late transfers which are inappropriate.

Another idea just popping up: Maybe we can improve that even further by
first globally disabling atomic transfers. Drivers knowing they need
this can then call an I2C core helper to enable them (again globally).
Still not perfect as some unwanted late I2C transfers from another
driver could slip through, but this should be rare enough. The pro-side
is we will detect more unwanted late transfers if support for them is
default off. It should be noted that "disabling" means keeping the old
behaviour which is: we try the regular transfer but complain about it.
Only enabling atomic will make the core quiet.

Regards,

   Wolfram


[-- 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:[~2019-04-16 10:48 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 12:40 [PATCH 00/12] i2c: core: introduce atomic transfers Wolfram Sang
2019-04-03 12:40 ` Wolfram Sang
2019-04-03 12:40 ` [PATCH 01/12] i2c: remove use of in_atomic() Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-15 12:40   ` Andy Shevchenko
2019-04-15 12:40     ` Andy Shevchenko
2019-04-15 21:55   ` Stefan Lengfeld
2019-04-15 21:55     ` Stefan Lengfeld
2019-04-15 21:55     ` Stefan Lengfeld
2019-04-16 10:48     ` Wolfram Sang [this message]
2019-04-16 10:48       ` Wolfram Sang
2019-04-03 12:40 ` [PATCH 02/12] i2c: core: use I2C locking behaviour also for SMBUS Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-15 12:39   ` Andy Shevchenko
2019-04-15 12:39     ` Andy Shevchenko
2019-04-15 12:39     ` Andy Shevchenko
2019-04-03 12:40 ` [PATCH 03/12] i2c: core: introduce callbacks for atomic transfers Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-15 12:39   ` Andy Shevchenko
2019-04-15 12:39     ` Andy Shevchenko
2019-04-15 21:57   ` Stefan Lengfeld
2019-04-15 21:57     ` Stefan Lengfeld
2019-04-03 12:40 ` [PATCH 04/12] i2c: mux: populate the new *_atomic callbacks Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 15:17   ` Peter Rosin
2019-04-03 15:17     ` Peter Rosin
2019-04-03 15:17     ` Peter Rosin
2019-04-15 12:04     ` Wolfram Sang
2019-04-15 12:04       ` Wolfram Sang
2019-04-15 12:04       ` Wolfram Sang
2019-04-15 12:44   ` Andy Shevchenko
2019-04-15 12:44     ` Andy Shevchenko
2019-04-03 12:40 ` [PATCH 05/12] i2c: demux: handle the new atomic callbacks Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-15 12:37   ` Andy Shevchenko
2019-04-15 12:37     ` Andy Shevchenko
2019-04-03 12:40 ` [PATCH 06/12] i2c: omap: Add the master_xfer_irqless hook Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-15 22:05   ` Stefan Lengfeld
2019-04-15 22:05     ` Stefan Lengfeld
2019-04-16 10:52     ` Wolfram Sang
2019-04-16 10:52       ` Wolfram Sang
2019-04-03 12:40 ` [PATCH 07/12] i2c: tegra-bpmp: convert to use new atomic callbacks Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 12:40 ` [PATCH 08/12] i2c: ocores: refactor setup for polling Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-05 15:09   ` Peter Korsgaard
2019-04-05 15:09     ` Peter Korsgaard
2019-04-05 19:00   ` Andrew Lunn
2019-04-05 19:00     ` Andrew Lunn
2019-04-03 12:40 ` [PATCH 09/12] i2c: ocores: enable atomic xfers Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-05 19:20   ` Andrew Lunn
2019-04-05 19:20     ` Andrew Lunn
2019-04-03 12:40 ` [PATCH 10/12] i2c: stu300: use xfer_atomic callback to bail out early Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-04 15:38   ` Linus Walleij
2019-04-04 15:38     ` Linus Walleij
2019-04-03 12:40 ` [PATCH 11/12] i2c: algo: bit: add flag to whitelist atomic transfers Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-03 12:40 ` [PATCH 12/12] i2c: gpio: flag atomic capability if possible Wolfram Sang
2019-04-03 12:40   ` Wolfram Sang
2019-04-04 15:40   ` Linus Walleij
2019-04-04 15:40     ` Linus Walleij
2019-04-15 12:38   ` Andy Shevchenko
2019-04-15 12:38     ` Andy Shevchenko
2019-04-03 13:15 ` [PATCH 00/12] i2c: core: introduce atomic transfers Andy Shevchenko
2019-04-03 13:15   ` Andy Shevchenko
2019-04-15 12:06   ` Wolfram Sang
2019-04-15 12:06     ` Wolfram Sang
2019-04-15 12:35     ` Andy Shevchenko
2019-04-15 12:35       ` Andy Shevchenko
2019-04-15 12:48       ` Andy Shevchenko
2019-04-15 12:48         ` Andy Shevchenko
2019-04-15 12:50         ` Wolfram Sang
2019-04-15 12:50           ` Wolfram Sang
2019-04-15 12:10 ` Wolfram Sang
2019-04-15 12:10   ` Wolfram Sang

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=20190416104823.zabxzdxarzfhdw7m@ninjato \
    --to=wsa@the-dreams.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=contact@stefanchrist.eu \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=wsa+renesas@sang-engineering.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.