[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160412114600.GL18882@ulmo.ba.sec>
Date: Tue, 12 Apr 2016 13:46:00 +0200
From: Thierry Reding <thierry.reding@...il.com>
To: Boris Brezillon <boris.brezillon@...e-electrons.com>
Cc: linux-pwm@...r.kernel.org,
Mike Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...eaurora.org>, linux-clk@...r.kernel.org,
Mark Brown <broonie@...nel.org>,
Liam Girdwood <lgirdwood@...il.com>,
Kamil Debski <k.debski@...sung.com>, lm-sensors@...sensors.org,
Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
linux-input@...r.kernel.org, Bryan Wu <cooloney@...il.com>,
Richard Purdie <rpurdie@...ys.net>,
Jacek Anaszewski <j.anaszewski@...sung.com>,
linux-leds@...r.kernel.org,
Maxime Ripard <maxime.ripard@...e-electrons.com>,
Chen-Yu Tsai <wens@...e.org>, linux-sunxi@...glegroups.com,
Joachim Eastwood <manabian@...il.com>,
Thomas Petazzoni <thomas.petazzoni@...e-electrons.com>,
Heiko Stuebner <heiko@...ech.de>,
linux-rockchip@...ts.infradead.org,
Jingoo Han <jingoohan1@...il.com>,
Lee Jones <lee.jones@...aro.org>, linux-fbdev@...r.kernel.org,
Jean-Christophe Plagniol-Villard <plagnioj@...osoft.com>,
Tomi Valkeinen <tomi.valkeinen@...com>,
Robert Jarzmik <robert.jarzmik@...e.fr>,
Alexandre Belloni <alexandre.belloni@...e-electrons.com>,
Kukjin Kim <kgene@...nel.org>,
Krzysztof Kozlowski <k.kozlowski@...sung.com>,
linux-samsung-soc@...r.kernel.org, intel-gfx@...ts.freedesktop.org,
Daniel Vetter <daniel.vetter@...el.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel@...ll.ch>,
dri-devel@...ts.freedesktop.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
Hartley Sweeten <hsweeten@...ionengravers.com>,
Ryan Mallon <rmallon@...il.com>,
Alexander Shiyan <shc_work@...l.ru>, Milo Kim <milo.kim@...com>
Subject: Re: [PATCH v5 04/46] pwm: get rid of pwm->lock
On Tue, Apr 12, 2016 at 01:32:55PM +0200, Boris Brezillon wrote:
> Hi Thierry,
>
> On Tue, 12 Apr 2016 13:22:46 +0200
> Thierry Reding <thierry.reding@...il.com> wrote:
>
> > On Wed, Mar 30, 2016 at 10:03:27PM +0200, Boris Brezillon wrote:
> > > PWM devices are not protected against concurrent accesses. The lock in
> > > pwm_device might let PWM users think it is, but it's actually only
> > > protecting the enabled state.
> > >
> > > Removing this lock should be fine as long as all PWM users are aware that
> > > accesses to the PWM device have to be serialized, which seems to be the
> > > case for all of them except the sysfs interface.
> > > Patch the sysfs code by adding a lock to the pwm_export struct and making
> > > sure it's taken for all accesses to the exported PWM device.
> > >
> > > Signed-off-by: Boris Brezillon <boris.brezillon@...e-electrons.com>
> > > ---
> > > drivers/pwm/core.c | 19 ++++--------------
> > > drivers/pwm/sysfs.c | 57 ++++++++++++++++++++++++++++++++++++++++++-----------
> > > include/linux/pwm.h | 2 --
> > > 3 files changed, 50 insertions(+), 28 deletions(-)
> >
> > This is a little overzealous. Only accesses that can cause races need to
> > be protected by the lock. All of the *_show() callbacks don't modify the
> > PWM device in any way, so there is no need to protect them against
> > concurrent accesses.
>
> This is probably true for this set of changes, but what will happen
> when we'll switch to the atomic API? There's no guarantee that
> pwm->state = *newstate is done atomically, and you may see a partially
> updated state when calling pwm_get_state() while another thread is
> calling pwm_apply_state().
I'd argue that for sysfs it doesn't matter since the userspace API is
non-atomic anyway. As such it doesn't really matter which part of the
state you're getting because only one field from the query is exposed
to userspace, hence the coherence of the state is irrelevant.
All other users should be taking care of the serialization themselves
already.
Thierry
Download attachment "signature.asc" of type "application/pgp-signature" (820 bytes)
Powered by blists - more mailing lists