From: Richard Purdie <rpurdie@rpsys.net>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Michael Hanselmann <linux-kernel@hansmi.ch>,
LKML <linux-kernel@vger.kernel.org>,
"Antonino A. Daplas" <adaplas@pol.net>
Subject: Re: [patch 5/6] Convert to use mutexes instead of semaphores
Date: Fri, 11 Aug 2006 17:45:51 +0100 [thread overview]
Message-ID: <1155314751.25767.6.camel@localhost.localdomain> (raw)
In-Reply-To: <d120d5000608110707o2b758739x20033b000449113f@mail.gmail.com>
On Fri, 2006-08-11 at 10:07 -0400, Dmitry Torokhov wrote:
> On 8/11/06, Michael Hanselmann <linux-kernel@hansmi.ch> wrote:
> > On Fri, Aug 11, 2006 at 09:34:44AM -0400, Dmitry Torokhov wrote:
> > > How about we add backlight_set_power(&bd, power) to the backlight core
> > > to take care of proper locking for drivers?
A couple of patches were attempted for this but they didn't solve the
underlying races. The main reason was a lack of understanding of what
the existing backlight lock protects and trying to make it do two thinsg
at once.
> > I've tried to add several functions to the backlight core
> > ({s,g}et_{brightness,power}) and they were rejected. Thus all the
> > locking is spread over the drivers. I agree it's faulty right now.
> > It's still easier to move to backlight core functions than to fix all
> > the drivers.
If we can find a way to safely do the locking in the backlight core I
agree.
> > Because I am responsible/wrote for the broken code, how should I
> > proceed?
First, we need to define the potential problems. Dimitry mentioned: "For
example, it could possibly race with setting power through sysfs
attribute". This is not what the lock in the backlight core is for
though. To quote backlight.h:
/* This protects the 'props' field. If 'props' is NULL, the driver that
registered this device has been unloaded, and if class_get_devdata()
points to something in the body of that driver, it is also invalid.
*/
My previous patches have gone a long way to removing race issues. The
need for the existing lock comes from backlight_device_unregister()
which basically does:
class_device_remove_files()
bd->props->brightness = 0;
bd->props->power = 0;
bd->props->update_status(bd);
bd->props = NULL
fb_unregister_client()
class_device_unregister()
If we could guarantee that after class_device_unregister(), nothing was
still executing any of the show/store methods, we'd be fine (the
fb_notifier is safe). As I understand the class device and sysfs
attributes, we can't guarantee that though. I'd appreciate comments from
the device model people as I could be wrong about this. The owner field
also can't help us.
Dimitry's "Backlight: convert to use default class device attributes"
patch should really mean the class_device_unregister() call is moved to
earlier in the function to try and avoid races from the attributes but
it still doesn't guarantee anything.
If we could somehow sync class_device_unregister(), we could get rid of
that semaphore entirely.
Regardless, if we want to add locking for synchronising the attributes
into the core, we need a different lock. I did think the drivers would
be able to handle this themselves with locking inside update_status if
needed but I can see why certain drivers might not like that.
> Well, I was reading some more of the drivers and I am also not sure if
> such methods are needed in backlight core. Let's take atyfb_base.c -
> it tries to manipulate backlight's power from atyfb_blank. But it is
> normally called from fb_blank() which is then calls
> fb_notifier_call_chain(FB_EVENT_BLANK, &event);
> So on the end backlight device will get that event and will turn off
> power anyway. Now, atyfb_blank is also called suring suspend/resume so
> we probably should just add handling of FB_EVENT_SUSPEND and
> FB_EVENT_RESUME to the backlight core.
>
> Richard?
Think about the case where you have 2 framebuffers. The notification
call was left to pass to the driver as only it can work out which
framebuffer a given backlight is attached to.
Cheers,
Richard
next prev parent reply other threads:[~2006-08-11 16:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-11 5:03 [patch 0/6] Backlight & lcd fixes/cleanups Dmitry Torokhov
2006-08-11 5:03 ` [patch 1/6] Convert to use default class device attributes Dmitry Torokhov
2006-08-11 5:03 ` [patch 2/6] Fix error handling when registering new device Dmitry Torokhov
2006-08-11 5:03 ` [patch 3/6] Get rid of excessive amount of likely()s Dmitry Torokhov
2006-08-11 5:03 ` [patch 4/6] Remove "owner" from backlight_properties structure Dmitry Torokhov
2006-08-11 5:03 ` [patch 5/6] Convert to use mutexes instead of semaphores Dmitry Torokhov
2006-08-11 12:58 ` Dmitry Torokhov
2006-08-11 13:16 ` Richard Purdie
2006-08-11 13:34 ` Dmitry Torokhov
2006-08-11 13:42 ` Michael Hanselmann
2006-08-11 14:07 ` Dmitry Torokhov
2006-08-11 16:45 ` Richard Purdie [this message]
2006-08-11 17:20 ` Dmitry Torokhov
2006-08-29 20:54 ` Michael Hanselmann
2006-08-11 5:03 ` [patch 6/6] Move per-device data out of backlight_properties Dmitry Torokhov
2006-08-11 8:02 ` Richard Purdie
2006-08-11 12:27 ` Dmitry Torokhov
2006-08-11 12:55 ` Richard Purdie
2006-08-11 13:10 ` Dmitry Torokhov
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=1155314751.25767.6.camel@localhost.localdomain \
--to=rpurdie@rpsys.net \
--cc=adaplas@pol.net \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-kernel@hansmi.ch \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®