lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d1661817-1036-420a-9f76-a7124e6550a7@molgen.mpg.de>
Date: Tue, 25 Feb 2025 21:43:47 +0100
From: Paul Menzel <pmenzel@...gen.mpg.de>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
 Linus Walleij <linus.walleij@...aro.org>, linux-gpio@...r.kernel.org,
 LKML <linux-kernel@...r.kernel.org>, linux-pci@...r.kernel.org,
 regressions@...ts.linux.dev
Subject: Re: Linux logs new warning `gpio gpiochip0:
 gpiochip_add_data_with_key: get_direction failed: -22`

Dear Bartosz,


Thank you for your support.

Am 24.02.25 um 09:51 schrieb brgl@...ev.pl:
> On Sun, 23 Feb 2025 23:04:05 +0100, Paul Menzel <pmenzel@...gen.mpg.de> said:

>> Am 23.02.25 um 21:54 schrieb Bartosz Golaszewski:
>>> On Fri, Feb 21, 2025 at 10:02 PM Paul Menzel <pmenzel@...gen.mpg.de> wrote:
>>>>
>>>>> What GPIO driver is it using? It's likely that it's not using the
>>>>> provider API correctly and this change uncovered it, I'd like to take
>>>>> a look at it and fix it.
>>>>
>>>> How do I find out? The commands below do not return anything.
>>>>
>>>>        $ lsmod | grep gpio
>>>>        $ lspci -nn | grep -i gpio
>>>>        $ sudo dmesg | grep gpio
>>>>        [    5.150955] gpio gpiochip0: gpiochip_add_data_with_key: get_direction failed: -22
>>>>        [Just these lines match.]
>>
>>> If you have libgpiod-tools installed, you can post the output of
>>> gpiodetect here.
>>
>>       $ sudo gpiodetect
>>       gpiochip0 [INT344B:00] (152 lines)
> 
> So it's pinctrl-intel, specifically this function in
> drivers/pinctrl/intel/pinctrl-intel.c:
> 
> static int intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
> {
> 	struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
> 	void __iomem *reg;
> 	u32 padcfg0;
> 	int pin;
> 
> 	pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
> 	if (pin < 0)
> 		return -EINVAL;
> 
> 	reg = intel_get_padcfg(pctrl, pin, PADCFG0);
> 	if (!reg)
> 		return -EINVAL;
> 
> 	scoped_guard(raw_spinlock_irqsave, &pctrl->lock)
> 		padcfg0 = readl(reg);
> 
> 	if (padcfg0 & PADCFG0_PMODE_MASK)
> 		return -EINVAL;
> 
> 	if (__intel_gpio_get_direction(padcfg0) & PAD_CONNECT_OUTPUT)
> 		return GPIO_LINE_DIRECTION_OUT;
> 
> 	return GPIO_LINE_DIRECTION_IN;
> }
> 
> Can you add some logs and see which -EINVAL is returned here specifically?

Sure. I used the diff below, and added `dyndbg="file pinctrl-intel.c 
+p"` added to `/boot/grub/grub.cfg`.

```
diff --git a/drivers/pinctrl/intel/pinctrl-intel.c 
b/drivers/pinctrl/intel/pinctrl-intel.c
index 527e4b87ae52..f0922d9e64ee 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1067,18 +1067,24 @@ static int intel_gpio_get_direction(struct 
gpio_chip *chip, unsigned int offset)
         int pin;

         pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
-       if (pin < 0)
+       if (pin < 0) {
+               dev_dbg(pctrl->dev, "pin < 0");
                 return -EINVAL;
+       }

         reg = intel_get_padcfg(pctrl, pin, PADCFG0);
-       if (!reg)
+       if (!reg) {
+               dev_dbg(pctrl->dev, "not reg");
                 return -EINVAL;
+       }

         scoped_guard(raw_spinlock_irqsave, &pctrl->lock)
                 padcfg0 = readl(reg);

-       if (padcfg0 & PADCFG0_PMODE_MASK)
+       if (padcfg0 & PADCFG0_PMODE_MASK) {
+               dev_dbg(pctrl->dev, "padcfg0 = %x", padcfg0);
                 return -EINVAL;
+       }

         if (__intel_gpio_get_direction(padcfg0) & PAD_CONNECT_OUTPUT)
                 return GPIO_LINE_DIRECTION_OUT;
```

These are the logs:

```
[    0.198584] sunrisepoint-pinctrl INT344B:00: Community0 features: 
0x000000
[    0.198613] sunrisepoint-pinctrl INT344B:00: Community1 features: 
0x00000c
[    0.198629] sunrisepoint-pinctrl INT344B:00: Community2 features: 
0x000000
[    0.198687] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198688] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198693] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198694] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198699] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198700] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198704] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198705] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198709] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198710] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198715] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198715] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198720] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198721] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198730] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198731] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198735] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198736] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198741] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198741] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198746] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198747] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198756] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198757] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198766] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198767] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198812] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198812] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198817] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198818] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198822] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198823] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198837] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198838] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198843] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198843] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198848] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198849] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198853] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198854] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198863] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198864] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198874] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.198875] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198879] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198880] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198884] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.198885] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198938] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198939] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198944] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198945] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198950] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198951] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198972] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198973] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198978] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198979] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198989] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198990] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199006] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199007] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199011] sunrisepoint-pinctrl INT344B:00: padcfg0 = 84000700
[    0.199012] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199028] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199029] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199034] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199035] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199040] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199041] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199045] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199046] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199211] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199211] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199217] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199217] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199239] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.199240] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199255] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199256] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199261] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199262] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199267] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199268] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199273] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199274] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199278] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199279] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199284] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199285] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199301] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000502
[    0.199302] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199307] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199308] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199312] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199313] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199318] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199319] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199324] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199325] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199382] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000600
[    0.199383] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199387] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000600
[    0.199388] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
```

With

     #define PADCFG0_PMODE_MASK              GENMASK(13, 10)

indeed one bit is always set in this range.

> In any case: Linus: what should be our policy here? There are some pinctrl
> drivers which return EINVAL if the pin in question is not in GPIO mode. I don't
> think this is an error. Returning errors should be reserved for read failures
> and so on. Are you fine with changing the logic here to explicitly default to
> INPUT as until recently all errors would be interpreted as such anyway?


Kind regards,

Paul

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ