The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srini@kernel.org>
To: Andrea Tomassetti <andrea.tomassetti@sipearl.com>,
	Srinivas Kandagatla <srini@kernel.org>,
	"linusw@kernel.org" <linusw@kernel.org>
Cc: "johan+linaro@kernel.org" <johan+linaro@kernel.org>,
	"krzk@kernel.org" <krzk@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"peda@axentia.se" <peda@axentia.se>
Subject: Re: [PATCH v2] mux: gpio-mux: add support for 4:1 2-channels mux
Date: Fri, 3 Jul 2026 09:10:53 +0100	[thread overview]
Message-ID: <b5caa738-0473-4253-ab45-596b97f3efc9@kernel.org> (raw)
In-Reply-To: <57cd1b9d-2ee4-48b7-873a-c8baa162c3ab@sipearl.com>



On 6/30/26 4:08 PM, Andrea Tomassetti wrote:
>>> +
>>> +	mux_chip = devm_mux_chip_alloc(dev, cells + 1, sizeof(*mux_gpio));
>> We are now allocating n mux_controls, however mux_gpio_set is not
>> protected against multiple controllers accessing the same gpio resource.
>>
>>
> This is a great point. I see two different type of "race conditions" here:
>     1. serialize accesses in mux_gpio_set
serializing is not the major issue. The end result is.
>     2. "logical race condition" due to how the upper locking mechanism is
> handled by mux/core.c

> 
> The first issue can be easily solved by adding a mutex inside struct mux_gpio
> and use it to serialize accesses in mux_gpio_set.
> 
> OTOH, the second issue is more nasty and depends on how the upper locking
> mechanism is handled by mux/core.c. Please, correct me if I'm wrong, but to me
> it looks like that the core's locking model assumes each mux_control is an
> independently lockable resource. While this is generally true, it doesn't apply
> in the case when there's only one controller that jointly controls two or more
> gpio-muxes. Like in this case.

Yes, we have locking per mux control for a reason, Mux resources are
protected in that control context to make sure the mux is always held in
requested state.

Now with this patch we are using shared resource for multiple mux, that
means an underlying resource can be updated by another mux control
without of each other knowing about it.

Two questions.
1. Why a single resource is split into different mux controls? (sorry In
case I missed previous discussions)

2. Does the hardware allow you to set two different values for the same
resource, respecting both values at any given time. If its gpio, then am
not sure it does.


--srini


> 
> So, adding a mutex at gpio-mux level would fix the race condition of two
> consumers changing the state at the same time (issue 1). But, to my
> understanding, it won't fix issue 2: mutual exclusion on the write makes each
> write atomic, but consumer A's selection can still be immediately hijacked by
> consumer B's, leaving A believing it is reading what it just set when it's
> actually reading whatever B last selected. This happens because the lock used in
> mux/core.c is allocated _per controller_ and not _per chip_. Do you agree with
> my analysis?
> 
> If you agree, I can fix issue 1 but I'd lean towards treating issue 2 as out of
> scope for this patch. Let me know if you see it differently.
> 
> Br,


  reply	other threads:[~2026-07-03  8:10 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 14:11 [PATCH RESEND] mux: gpio-mux: add support for 4:1 2-channels mux Andrea Tomassetti
2026-05-05  8:23 ` Linus Walleij
2026-05-05 15:20   ` Andrea Tomassetti
2026-05-06  7:58     ` Linus Walleij
2026-05-06 12:33       ` [PATCH v2] " Andrea Tomassetti
2026-06-03 11:43         ` Andrea Tomassetti
2026-06-03 14:00           ` Krzysztof Kozlowski
2026-06-08 22:54           ` Linus Walleij
2026-06-17 13:09             ` Tommaso Merciai
2026-06-18 13:04               ` Linus Walleij
2026-06-18 13:27                 ` Tommaso Merciai
2026-06-19  3:51                   ` Krzysztof Kozlowski
2026-06-23 16:44                     ` Tommaso Merciai
2026-06-24  8:59                       ` Geert Uytterhoeven
2026-06-24  9:59                         ` Krzysztof Kozlowski
2026-06-24  9:55                       ` Krzysztof Kozlowski
2026-06-24 22:03                         ` Linus Walleij
2026-06-24 22:11                           ` Linus Walleij
2026-06-25  9:19                             ` Nuno Sá
2026-06-29 19:27                               ` Linus Walleij
2026-07-03  7:32                                 ` Michael Hennerich
2026-07-03 10:02                                   ` Miclaus, Antoniu
2026-07-03 13:19                                     ` Alvin Šipraga
2026-07-03 13:45                                       ` Lad, Prabhakar
2026-06-19 17:23         ` Srinivas Kandagatla
2026-06-30 15:08           ` Andrea Tomassetti
2026-07-03  8:10             ` Srinivas Kandagatla [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-06-25  9:32 Lad, Prabhakar
2026-06-25  9:43 ` Krzysztof Kozlowski
2026-06-25  9:49   ` Greg Kroah-Hartman
2026-06-25  9:59   ` Lad, Prabhakar
2026-06-29 19:24 ` Linus Walleij

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=b5caa738-0473-4253-ab45-596b97f3efc9@kernel.org \
    --to=srini@kernel.org \
    --cc=andrea.tomassetti@sipearl.com \
    --cc=johan+linaro@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox