gpiolib: debugfs: display gpios requested as irq only
diff mbox

Message ID 1431696321-7257-1-git-send-email-grygorii.strashko@linaro.org
State New
Headers show

Commit Message

grygorii.strashko@linaro.org May 15, 2015, 1:25 p.m. UTC
From: Grygorii Strashko <grygorii.strashko@linaro.org>

Now GPIOs, wich are requested as IRQ only, will not be displayed
through GPIO debugfs. For example:
 # cat /proc/interrupts
            CPU0       CPU1
...
209:          0          0  4805d000.gpio  11 Edge      0-0021

 # cat /debug/gpio
...
GPIOs 160-191, platform/4805d000.gpio, gpio:
<--- no info about gpio used as IRQ only here

GPIOs 192-223, platform/48051000.gpio, gpio:
 gpio-203 (vtt_fixed           ) out hi
...

Hence, improve GPIO debugfs code to show such kind of gpio and print
IRQ number also. In addition, add marker "requested" for GPIOs wich
were requested by using gpioX_request().

After this patch sys/kernel/debug/gpio will produce following output:

 # cat /debug/gpio
...
GPIOs 160-191, platform/4805d000.gpio, gpio:
 gpio-171 ((null)              ) in  hi IRQ209

GPIOs 192-223, platform/48051000.gpio, gpio:
 gpio-203 (vtt_fixed           ) out hi requested

Signed-off-by: Grygorii Strashko <grygorii.strashko@linaro.org>
---
 drivers/gpio/gpiolib.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Johan Hovold May 18, 2015, 11:02 a.m. UTC | #1
On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:
> From: Grygorii Strashko <grygorii.strashko@linaro.org>
> 
> Now GPIOs, wich are requested as IRQ only, will not be displayed
> through GPIO debugfs. For example:
>  # cat /proc/interrupts
>             CPU0       CPU1
> ...
> 209:          0          0  4805d000.gpio  11 Edge      0-0021
> 
>  # cat /debug/gpio
> ...
> GPIOs 160-191, platform/4805d000.gpio, gpio:
> <--- no info about gpio used as IRQ only here
> 
> GPIOs 192-223, platform/48051000.gpio, gpio:
>  gpio-203 (vtt_fixed           ) out hi
> ...
> 
> Hence, improve GPIO debugfs code to show such kind of gpio and print
> IRQ number also. In addition, add marker "requested" for GPIOs wich
> were requested by using gpioX_request().
>
> After this patch sys/kernel/debug/gpio will produce following output:
> 
>  # cat /debug/gpio
> ...
> GPIOs 160-191, platform/4805d000.gpio, gpio:
>  gpio-171 ((null)              ) in  hi IRQ209
> 
> GPIOs 192-223, platform/48051000.gpio, gpio:
>  gpio-203 (vtt_fixed           ) out hi requested

This is backwards. All gpios *should* be requested. *If* we are to
include not-requested gpios in the debug output, then it is those pins
that need to be marked as not-requested.

The irq-number mapping could perhaps be useful, but it should go in a
separate patch. I'd suggest adding a '-' before the irq-number (e.g.
"IRQ-209").

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
grygorii.strashko@linaro.org May 18, 2015, 1:06 p.m. UTC | #2
Hi Johan,
On 05/18/2015 02:02 PM, Johan Hovold wrote:
> On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:
>> From: Grygorii Strashko <grygorii.strashko@linaro.org>
>>
>> Now GPIOs, wich are requested as IRQ only, will not be displayed
>> through GPIO debugfs. For example:
>>   # cat /proc/interrupts
>>              CPU0       CPU1
>> ...
>> 209:          0          0  4805d000.gpio  11 Edge      0-0021
>>
>>   # cat /debug/gpio
>> ...
>> GPIOs 160-191, platform/4805d000.gpio, gpio:
>> <--- no info about gpio used as IRQ only here
>>
>> GPIOs 192-223, platform/48051000.gpio, gpio:
>>   gpio-203 (vtt_fixed           ) out hi
>> ...
>>
>> Hence, improve GPIO debugfs code to show such kind of gpio and print
>> IRQ number also. In addition, add marker "requested" for GPIOs wich
>> were requested by using gpioX_request().
>>
>> After this patch sys/kernel/debug/gpio will produce following output:
>>
>>   # cat /debug/gpio
>> ...
>> GPIOs 160-191, platform/4805d000.gpio, gpio:
>>   gpio-171 ((null)              ) in  hi IRQ209
>>
>> GPIOs 192-223, platform/48051000.gpio, gpio:
>>   gpio-203 (vtt_fixed           ) out hi requested
> 
> This is backwards. All gpios *should* be requested. *If* we are to
> include not-requested gpios in the debug output, then it is those pins
> that need to be marked as not-requested.

Sry, but I didn't fully understand your point here ( - Why is it backward?
Now GPIO can be requested in three ways:
1) As pure GPIO (gpioX_request())
2) As pure GPIO IRQ, especially in DT boot case. 
  DT:
	interrupt-parent = <&gpio6>;
	interrupts = <11 IRQ_TYPE_EDGE_FALLING>; 
  Code:
	platform_get_irq() or of_irq_get()
        request_irq()
3) combination of (1) and (2) with one restriction
   - GPIO direction should be 'In' and can't be changed.

Personally I'm using this case for debug purposes to do a fast check of GPIO pin state
through GPIO sysfs (GPIO export) when such GPIO is used as GPIO IRQ in some driver
and I don't see that corresponding IRQ is triggered as expected.  

So, this patch just adds missed information in GPIO debugfs for the case (2) in general.

Of course, format of the marker "requested" is discussable. Could be:
- "requested" --> "not-requested"
- "I R" or "I G" where I - IRQ, G - GPIO, R - requested
- etc.

> 
> The irq-number mapping could perhaps be useful, but it should go in a
> separate patch. I'd suggest adding a '-' before the irq-number (e.g.
> "IRQ-209").

I've thought about this, but finally decided not to split it.
Could be done, if you insist )
Johan Hovold May 18, 2015, 3:08 p.m. UTC | #3
On Mon, May 18, 2015 at 04:06:08PM +0300, Grygorii.Strashko@linaro.org wrote:
> Hi Johan,
> On 05/18/2015 02:02 PM, Johan Hovold wrote:
> > On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:
> >> From: Grygorii Strashko <grygorii.strashko@linaro.org>
> >>
> >> Now GPIOs, wich are requested as IRQ only, will not be displayed
> >> through GPIO debugfs. For example:
> >>   # cat /proc/interrupts
> >>              CPU0       CPU1
> >> ...
> >> 209:          0          0  4805d000.gpio  11 Edge      0-0021
> >>
> >>   # cat /debug/gpio
> >> ...
> >> GPIOs 160-191, platform/4805d000.gpio, gpio:
> >> <--- no info about gpio used as IRQ only here
> >>
> >> GPIOs 192-223, platform/48051000.gpio, gpio:
> >>   gpio-203 (vtt_fixed           ) out hi
> >> ...
> >>
> >> Hence, improve GPIO debugfs code to show such kind of gpio and print
> >> IRQ number also. In addition, add marker "requested" for GPIOs wich
> >> were requested by using gpioX_request().
> >>
> >> After this patch sys/kernel/debug/gpio will produce following output:
> >>
> >>   # cat /debug/gpio
> >> ...
> >> GPIOs 160-191, platform/4805d000.gpio, gpio:
> >>   gpio-171 ((null)              ) in  hi IRQ209
> >>
> >> GPIOs 192-223, platform/48051000.gpio, gpio:
> >>   gpio-203 (vtt_fixed           ) out hi requested
> > 
> > This is backwards. All gpios *should* be requested. *If* we are to
> > include not-requested gpios in the debug output, then it is those pins
> > that need to be marked as not-requested.
> 
> Sry, but I didn't fully understand your point here ( - Why is it
> backward?

My main point was that you should mark the pins used for irq only
instead of the other way round.

We should also consider making sure that pins only used for irq are also
requested.

With the current sysfs-interface it is for example to possible to
request the same irq, and when that pin is unexported (or only irq
released) the pin will no longer be marked for irq (just a flag that is
cleared) so that the direction can be changed...

gpiolib also depends on pins to be requested to prevent the
gpio-controller driver from being unloaded while in use.

[...]

> Of course, format of the marker "requested" is discussable. Could be:
> - "requested" --> "not-requested"
> - "I R" or "I G" where I - IRQ, G - GPIO, R - requested
> - etc.

How about instead of

	GPIOs 160-191, platform/4805d000.gpio, gpio:
	gpio-171 ((null)              ) in  hi IRQ209

you do something like:

	GPIOs 160-191, platform/4805d000.gpio, gpio:
	gpio-171 (<irq-only>          ) in  hi IRQ-209

> > The irq-number mapping could perhaps be useful, but it should go in a
> > separate patch. I'd suggest adding a '-' before the irq-number (e.g.
> > "IRQ-209").
> 
> I've thought about this, but finally decided not to split it.
> Could be done, if you insist )

Yes, you should split self-contained, logical changes into separate
patches (so they can be reviewed, applied or rejected separately as
well).

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
grygorii.strashko@linaro.org May 18, 2015, 3:17 p.m. UTC | #4
On 05/18/2015 06:08 PM, Johan Hovold wrote:
> On Mon, May 18, 2015 at 04:06:08PM +0300, Grygorii.Strashko@linaro.org wrote:
>> On 05/18/2015 02:02 PM, Johan Hovold wrote:
>>> On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:
>>>> From: Grygorii Strashko <grygorii.strashko@linaro.org>
>>>>
>>>> Now GPIOs, wich are requested as IRQ only, will not be displayed
>>>> through GPIO debugfs. For example:
>>>>    # cat /proc/interrupts
>>>>               CPU0       CPU1
>>>> ...
>>>> 209:          0          0  4805d000.gpio  11 Edge      0-0021
>>>>
>>>>    # cat /debug/gpio
>>>> ...
>>>> GPIOs 160-191, platform/4805d000.gpio, gpio:
>>>> <--- no info about gpio used as IRQ only here
>>>>
>>>> GPIOs 192-223, platform/48051000.gpio, gpio:
>>>>    gpio-203 (vtt_fixed           ) out hi
>>>> ...
>>>>
>>>> Hence, improve GPIO debugfs code to show such kind of gpio and print
>>>> IRQ number also. In addition, add marker "requested" for GPIOs wich
>>>> were requested by using gpioX_request().
>>>>
>>>> After this patch sys/kernel/debug/gpio will produce following output:
>>>>
>>>>    # cat /debug/gpio
>>>> ...
>>>> GPIOs 160-191, platform/4805d000.gpio, gpio:
>>>>    gpio-171 ((null)              ) in  hi IRQ209
>>>>
>>>> GPIOs 192-223, platform/48051000.gpio, gpio:
>>>>    gpio-203 (vtt_fixed           ) out hi requested
>>>
>>> This is backwards. All gpios *should* be requested. *If* we are to
>>> include not-requested gpios in the debug output, then it is those pins
>>> that need to be marked as not-requested.
>>
>> Sry, but I didn't fully understand your point here ( - Why is it
>> backward?
> 
> My main point was that you should mark the pins used for irq only
> instead of the other way round.
> 
> We should also consider making sure that pins only used for irq are also
> requested.
> 
> With the current sysfs-interface it is for example to possible to
> request the same irq, and when that pin is unexported (or only irq
> released) the pin will no longer be marked for irq (just a flag that is
> cleared) so that the direction can be changed...
> 
> gpiolib also depends on pins to be requested to prevent the
> gpio-controller driver from being unloaded while in use.
> 
> [...]
> 
>> Of course, format of the marker "requested" is discussable. Could be:
>> - "requested" --> "not-requested"
>> - "I R" or "I G" where I - IRQ, G - GPIO, R - requested
>> - etc.
> 
> How about instead of
> 
> 	GPIOs 160-191, platform/4805d000.gpio, gpio:
> 	gpio-171 ((null)              ) in  hi IRQ209
> 
> you do something like:
> 
> 	GPIOs 160-191, platform/4805d000.gpio, gpio:
> 	gpio-171 (<irq-only>          ) in  hi IRQ-209

In general agree, but i propose to do it as 
	GPIOs 160-191, platform/4805d000.gpio, gpio:
 	gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>

My intention is - this interface could be considered as more or less stable, so
it is better to add additional information at the end of each line to avoid
potential breakage of User space SW (test/debug scripts).

if you agree I'll update and re-send.
 
>>> The irq-number mapping could perhaps be useful, but it should go in a
>>> separate patch. I'd suggest adding a '-' before the irq-number (e.g.
>>> "IRQ-209").
>>
>> I've thought about this, but finally decided not to split it.
>> Could be done, if you insist )
> 
> Yes, you should split self-contained, logical changes into separate
> patches (so they can be reviewed, applied or rejected separately as
> well).

np. There will be two patches
- one to display "irq-only" gpios
- second to add IRQ number

Thanks.
Johan Hovold May 18, 2015, 3:58 p.m. UTC | #5
On Mon, May 18, 2015 at 06:17:45PM +0300, Grygorii.Strashko@linaro.org wrote:
> On 05/18/2015 06:08 PM, Johan Hovold wrote:

> > How about instead of
> > 
> > 	GPIOs 160-191, platform/4805d000.gpio, gpio:
> > 	gpio-171 ((null)              ) in  hi IRQ209
> > 
> > you do something like:
> > 
> > 	GPIOs 160-191, platform/4805d000.gpio, gpio:
> > 	gpio-171 (<irq-only>          ) in  hi IRQ-209
> 
> In general agree, but i propose to do it as 
> 	GPIOs 160-191, platform/4805d000.gpio, gpio:
>  	gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>

I have no strong opinion on whether to use the name-field here or not.

Using the name-field rather than adding a new one could perhaps be
less confusing to current parsers.

> My intention is - this interface could be considered as more or less
> stable, so it is better to add additional information at the end of
> each line to avoid potential breakage of User space SW (test/debug
> scripts).

But if the interface is considered stable (and some people do) you would
not be able to add anything here. This *is* a real issue, but I'll defer
this one to Linus and Alexandre.

Perhaps we should just leave things as they are.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij May 19, 2015, 2:12 p.m. UTC | #6
On Mon, May 18, 2015 at 5:17 PM, Grygorii.Strashko@linaro.org
<grygorii.strashko@linaro.org> wrote:
> On 05/18/2015 06:08 PM, Johan Hovold wrote:

>>       GPIOs 160-191, platform/4805d000.gpio, gpio:
>>       gpio-171 (<irq-only>          ) in  hi IRQ-209
>
> In general agree, but i propose to do it as
>         GPIOs 160-191, platform/4805d000.gpio, gpio:
>         gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>
>
> My intention is - this interface could be considered as more or less stable, so
> it is better to add additional information at the end of each line to avoid
> potential breakage of User space SW (test/debug scripts).

What? If I wanted a stable interface I would use sysfs and document
the ABI in Documentation/ABI/*.

debugfs is not ABI.

Debugfs is instable by definition, it is not for production. If tests depend on
it they need to be ready to break and be updated, and in such case
it is a very very good idea to put any such tests in tools/* in the
kernel itself, as does trace-cmd and friends so you can patch the
tests at the same time you patch the code.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij May 19, 2015, 2:28 p.m. UTC | #7
On Mon, May 18, 2015 at 1:02 PM, Johan Hovold <johan@kernel.org> wrote:
> On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:

>> GPIOs 192-223, platform/48051000.gpio, gpio:
>>  gpio-203 (vtt_fixed           ) out hi requested
>
> This is backwards. All gpios *should* be requested. *If* we are to
> include not-requested gpios in the debug output, then it is those pins
> that need to be marked as not-requested.

It depends, really. As concluded in earlier discussions when we
introduced gpiochip_[un]lock_as_irq() the gpiolib and irqchip APIs
are essentially orthogonal.

At one point I was suggesting that any driver using a GPIO for
IRQ should first request the gpio line with gpiod_get() and then
use gpio_to_irq() on the descriptor. Always.

However as it turns out (and after being hammered down by
the DT and ACPI people for this stance) I changed opinion,
because even if that stringence would be nice, it doesn't
abstract the hardware well enough for drivers that "just need
an IRQ". These don't care of whether a line to the primary
IRQ controller or a dedicated external IRQ pin or some
cascaded GPIO chip is providing the IRQ, they just want
their IRQ resource.

If I would persist in my stance that the API must be used like
so it would have implications on how HW descriptions such
as DT or ACPI describe their resources and essentially put
requirements out to other operating systems than Linux using
DT or ACPI to do it the same way for this reason. That would
be unreasonable.

So it was deemed these resource APIs need to be orthogonal.

The same would apply to any other resource that is similar to a
GPIO and an IRQ line, don't know what a good example would be.

So to atleast try to safeguard from a scenario such as

- Client A requests IRQ from the irqchip side of the API
  and sets up a level active-low IRQ on it

- Client B request the same line as GPIO

- Client B sets it to output and drivers it low.

- Client A crashes in an infinite IRQ loop as that line
  is not hammered low and will generate IRQs until
  the end of time.

I introduced the gpiochip_[un]lock_as_irq() calls so we
could safeguard against this. Notably that blocks client A
from setting the line as output. I hope.

I thought this would mean the line would only be used as IRQ
in this case, so I could block any gpiod_get() calls to that
line but *of course* some driver is using the IRQ and snooping
into the GPIO value at the same time. So can't simplify things
like so either.

Maybe I'm smashing open doors here...

Anyway to get back to the original statement:

> This is backwards. All gpios *should* be requested. *If* we are to
> include not-requested gpios in the debug output, then it is those pins
> that need to be marked as not-requested.

This is correct, all GPIOs accessed *as gpios* should be
requested, no matter if they are then cast to IRQs by gpiod_to_irq
or not. However if the same hardware is used as only "some IRQ"
through it's irqchip interface, it needs not be requested, but
that is by definition not a GPIO, it is an IRQ.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
grygorii.strashko@linaro.org May 19, 2015, 2:37 p.m. UTC | #8
Hi Linus,

On 05/19/2015 05:12 PM, Linus Walleij wrote:
> On Mon, May 18, 2015 at 5:17 PM, Grygorii.Strashko@linaro.org
> <grygorii.strashko@linaro.org> wrote:
>> On 05/18/2015 06:08 PM, Johan Hovold wrote:
> 
>>>        GPIOs 160-191, platform/4805d000.gpio, gpio:
>>>        gpio-171 (<irq-only>          ) in  hi IRQ-209
>>
>> In general agree, but i propose to do it as
>>          GPIOs 160-191, platform/4805d000.gpio, gpio:
>>          gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>
>>
>> My intention is - this interface could be considered as more or less stable, so
>> it is better to add additional information at the end of each line to avoid
>> potential breakage of User space SW (test/debug scripts).
> 
> What? If I wanted a stable interface I would use sysfs and document
> the ABI in Documentation/ABI/*.
> 
> debugfs is not ABI.
> 
> Debugfs is instable by definition, it is not for production. If tests depend on
> it they need to be ready to break and be updated, and in such case
> it is a very very good idea to put any such tests in tools/* in the
> kernel itself, as does trace-cmd and friends so you can patch the
> tests at the same time you patch the code.

Okay. Sorry, My comment was not fully correct - keyword was "more or less stable"
and of course it is not ABI.

Any way, the question is till here - How would it better to do?
  gpio-171 (<irq-only>          ) in  hi IRQ-209
-- or --
  gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>

Thanks a lot for your comments.
Linus Walleij May 19, 2015, 2:50 p.m. UTC | #9
On Tue, May 19, 2015 at 4:37 PM, Grygorii.Strashko@linaro.org
<grygorii.strashko@linaro.org> wrote:

> Any way, the question is till here - How would it better to do?
>   gpio-171 (<irq-only>          ) in  hi IRQ-209
> -- or --
>   gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>

The latter I think. No strong opinion really.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johan Hovold May 19, 2015, 3:39 p.m. UTC | #10
On Tue, May 19, 2015 at 04:12:35PM +0200, Linus Walleij wrote:
> On Mon, May 18, 2015 at 5:17 PM, Grygorii.Strashko@linaro.org
> <grygorii.strashko@linaro.org> wrote:
> > On 05/18/2015 06:08 PM, Johan Hovold wrote:
> 
> >>       GPIOs 160-191, platform/4805d000.gpio, gpio:
> >>       gpio-171 (<irq-only>          ) in  hi IRQ-209
> >
> > In general agree, but i propose to do it as
> >         GPIOs 160-191, platform/4805d000.gpio, gpio:
> >         gpio-171 ((null)          ) in  hi IRQ-209 <irq-only>
> >
> > My intention is - this interface could be considered as more or less stable, so
> > it is better to add additional information at the end of each line to avoid
> > potential breakage of User space SW (test/debug scripts).
> 
> What? If I wanted a stable interface I would use sysfs and document
> the ABI in Documentation/ABI/*.
> 
> debugfs is not ABI.

As I mentioned in my response to Grygorii, not everyone -- and most
notably apparently not even Linus Torvalds -- agrees on this:

	"The fact that something is documented (whether correctly or
	not) has absolutely _zero_ impact on anything at all. What makes
	something an ABI is that it's useful and available. The only way
	something isn't an ABI is by _explicitly_ making sure that it's
	not available even by mistake in a stable form for binary use.

	Example: kernel internal data structures and function calls. We
	make sure that you simply _cannot_ make a binary that works
	across kernel versions. That is the only way for an ABI to not
	form."

	https://lwn.net/Articles/309298/

In this case, it could be worked around by providing another debugfs
file with gpios used as IRQs, I guess.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij May 20, 2015, 7:21 a.m. UTC | #11
On Tue, May 19, 2015 at 5:39 PM, Johan Hovold <johan@kernel.org> wrote:
> On Tue, May 19, 2015 at 04:12:35PM +0200, Linus Walleij wrote:

>> What? If I wanted a stable interface I would use sysfs and document
>> the ABI in Documentation/ABI/*.
>>
>> debugfs is not ABI.
>
> As I mentioned in my response to Grygorii, not everyone -- and most
> notably apparently not even Linus Torvalds -- agrees on this:

Yeah I was sloppy I guess.

What I mean, precisely is that sysfs is ABI, whether documented or
not.

Even debugfs is actually blurry, as per
Documentation/filesystems/debugfs.txt:

"The debugfs filesystem is also intended to not serve as a stable
ABI to user space; in theory, there are no stability constraints placed on
files exported there.  The real world is not always so simple, though [1];
even debugfs interfaces are best designed with the idea that they will need
to be maintained forever."

But I haven't been bitten by it yet so that's why I allow some poetic
license.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johan Hovold May 21, 2015, 2:25 p.m. UTC | #12
On Tue, May 19, 2015 at 04:28:55PM +0200, Linus Walleij wrote:
> On Mon, May 18, 2015 at 1:02 PM, Johan Hovold <johan@kernel.org> wrote:
> > On Fri, May 15, 2015 at 04:25:21PM +0300, grygorii.strashko@linaro.org wrote:
> 
> >> GPIOs 192-223, platform/48051000.gpio, gpio:
> >>  gpio-203 (vtt_fixed           ) out hi requested
> >
> > This is backwards. All gpios *should* be requested. *If* we are to
> > include not-requested gpios in the debug output, then it is those pins
> > that need to be marked as not-requested.
> 
> It depends, really. As concluded in earlier discussions when we
> introduced gpiochip_[un]lock_as_irq() the gpiolib and irqchip APIs
> are essentially orthogonal.

[...]

> So to atleast try to safeguard from a scenario such as
> 
> - Client A requests IRQ from the irqchip side of the API
>   and sets up a level active-low IRQ on it
> 
> - Client B request the same line as GPIO
> 
> - Client B sets it to output and drivers it low.
> 
> - Client A crashes in an infinite IRQ loop as that line
>   is not hammered low and will generate IRQs until
>   the end of time.
> 
> I introduced the gpiochip_[un]lock_as_irq() calls so we
> could safeguard against this. Notably that blocks client A
> from setting the line as output. I hope.

A problem with the current implementation is that it uses as a flag
rather than a refcount. As I pointed out elsewhere in this thread, it is
possible to request a shared IRQ (e.g. via the sysfs interface) and
release it, thereby making it possible to change the direction of the
pin while still in use for irq.

> I thought this would mean the line would only be used as IRQ
> in this case, so I could block any gpiod_get() calls to that
> line but *of course* some driver is using the IRQ and snooping
> into the GPIO value at the same time. So can't simplify things
> like so either.
> 
> Maybe I'm smashing open doors here...

No, I understand that use case. But there are some issues with how it's
currently implemented. Besides the example above, nothing pins a gpio
chip driver in memory unless it has requested gpios, specifically,
requesting a pin for irq use is not enough.

> Anyway to get back to the original statement:
> 
> > This is backwards. All gpios *should* be requested. *If* we are to
> > include not-requested gpios in the debug output, then it is those pins
> > that need to be marked as not-requested.
> 
> This is correct, all GPIOs accessed *as gpios* should be
> requested, no matter if they are then cast to IRQs by gpiod_to_irq
> or not. However if the same hardware is used as only "some IRQ"
> through it's irqchip interface, it needs not be requested, but
> that is by definition not a GPIO, it is an IRQ.

True. And since it is not a GPIO, should it show up in
/sys/kernel/debug/gpio? ;)

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johan Hovold May 21, 2015, 2:34 p.m. UTC | #13
On Wed, May 20, 2015 at 09:21:16AM +0200, Linus Walleij wrote:
> On Tue, May 19, 2015 at 5:39 PM, Johan Hovold <johan@kernel.org> wrote:
> > On Tue, May 19, 2015 at 04:12:35PM +0200, Linus Walleij wrote:
> 
> >> What? If I wanted a stable interface I would use sysfs and document
> >> the ABI in Documentation/ABI/*.
> >>
> >> debugfs is not ABI.
> >
> > As I mentioned in my response to Grygorii, not everyone -- and most
> > notably apparently not even Linus Torvalds -- agrees on this:
> 
> Yeah I was sloppy I guess.
> 
> What I mean, precisely is that sysfs is ABI, whether documented or
> not.
> 
> Even debugfs is actually blurry, as per
> Documentation/filesystems/debugfs.txt:
> 
> "The debugfs filesystem is also intended to not serve as a stable
> ABI to user space; in theory, there are no stability constraints placed on
> files exported there.  The real world is not always so simple, though [1];
> even debugfs interfaces are best designed with the idea that they will need
> to be maintained forever."
> 
> But I haven't been bitten by it yet so that's why I allow some poetic
> license.

Yes, and the [1] reference in that quote is the LWN article I referred
to.

I also see you already "broke" that ABI in a similar way in 2013 with
d468bf9ecaab ("gpio: add API to be strict about GPIO IRQ usage") by
adding the IRQ field.

Your call. :)

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 59eaa23..ea11706 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2259,19 +2259,23 @@  static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	int			is_irq;
 
 	for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) {
-		if (!test_bit(FLAG_REQUESTED, &gdesc->flags))
+		if (!test_bit(FLAG_REQUESTED, &gdesc->flags) &&
+		    !test_bit(FLAG_USED_AS_IRQ, &gdesc->flags))
 			continue;
 
 		gpiod_get_direction(gdesc);
 		is_out = test_bit(FLAG_IS_OUT, &gdesc->flags);
 		is_irq = test_bit(FLAG_USED_AS_IRQ, &gdesc->flags);
-		seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s",
+		seq_printf(s, " gpio-%-3d (%-20.20s) %s %s",
 			gpio, gdesc->label,
 			is_out ? "out" : "in ",
 			chip->get
 				? (chip->get(chip, i) ? "hi" : "lo")
-				: "?  ",
-			is_irq ? "IRQ" : "   ");
+				: "?  ");
+		if (is_irq)
+			seq_printf(s, " IRQ%d", gpiod_to_irq(gdesc));
+		if (test_bit(FLAG_REQUESTED, &gdesc->flags))
+			seq_puts(s, " requested");
 		seq_printf(s, "\n");
 	}
 }