devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Richard Gong <richard.gong@linux.intel.com>
Cc: Romain Izard <romain.izard.pro@gmail.com>,
	robh+dt@kernel.org, mark.rutland@arm.com, dinguyen@kernel.org,
	atull@kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, sen.li@intel.com,
	Richard Gong <richard.gong@intel.com>
Subject: Re: A potential broken at platform driver?
Date: Tue, 4 Jun 2019 19:03:10 +0200	[thread overview]
Message-ID: <20190604170310.GC14605@kroah.com> (raw)
In-Reply-To: <e3adbd00-e500-70af-1c27-e4c064486561@linux.intel.com>

On Tue, Jun 04, 2019 at 11:13:02AM -0500, Richard Gong wrote:
> 
> Hi Greg,
> 
> On 6/4/19 9:28 AM, Greg KH wrote:
> > On Tue, Jun 04, 2019 at 12:33:03PM +0200, Romain Izard wrote:
> > > On Mon, Jun 03, 2019 at 08:02:55PM +0200, Greg KH wrote:
> > > > > @@ -394,7 +432,7 @@ static struct platform_driver stratix10_rsu_driver = {
> > > > >   	.remove = stratix10_rsu_remove,
> > > > >   	.driver = {
> > > > >   		.name = "stratix10-rsu",
> > > > > -		.groups = rsu_groups,
> > > > > +//		.groups = rsu_groups,
> > > > 
> > > > Are you sure this is the correct pointer?  I think that might be
> > > > pointing to the driver's attributes, not the device's attributes.
> > > > 
> > > > If platform drivers do not have a way to register groups properly, then
> > > > that really needs to be fixed, as trying to register it by yourself as
> > > > you are doing, is ripe for racing with userspace.
> > > This is a very common issue with platform drivers, and it seems to me that
> > > it is not possible to add device attributes when binding a device to a
> > > driver without entering the race condition.
> > > 
> > > My understanding is the following one:
> > > 
> > > The root cause is that the device has already been created and reported
> > > to the userspace with a KOBJ_ADD uevent before the device and the driver
> > > are bound together. On receiving this event, userspace will react, and
> > > it will try to read the device's attributes. In parallel the kernel will
> > > try to find a matching driver. If a driver is found, the kernel will
> > > call the probe function from the driver with the device as a parameter,
> > > and if successful a KOBJ_BIND uevent will be sent to userspace, but this
> > > is a recent addition.
> > > 
> > > Unfortunately, not all created devices will be bound to a driver, and the
> > > existing udev code relies on KOBJ_ADD uevents rather than KOBJ_BIND uevents.
> > > If new per-device attributes have been added to the device during the
> > > binding stage userspace may or may not see them, depending on when userspace
> > > tries to read the device's attributes.
> > > 
> > > I have this possible workaround, but I do not know if it is a good solution:
> > > 
> > > When binding the device and the driver together, create a new device as a
> > > child to the current device, and fill its "groups" member to point to the
> > > per-device attributes' group. As the device will be created with all the
> > > attributes, it will not be affected by the race issues. The functions
> > > handling the attributes will need to be modified to use the parents of their
> > > "device" parameter, instead of the device itself. Additionnaly, the sysfs
> > > location of the attributes will be different, as the child device will show
> > > up in the sysfs path. But for a newly introduced device this will not be
> > > a problem.
> > > 
> > > Is this a good compromise ?
> > 
> > Not really.  You just want the attributes on the platform device itself.
> > 
> > Given the horrible hack that platform devices are today, what's one more
> > hack!
> > 
> > Here's a patch below of what should probably be done here.  Richard, can
> > you change your code to use the new dev_groups pointer in the struct
> > platform_driver and this patch and let me know if that works or not?
> > 
> > Note, I've only compiled this code, not tested it...
> > 
> 
> Your patch works.
> 
> Many thanks for your help!

Nice!

I guess I need to turn it into a real patch now.  Let me do that tonight
and see if I can convert some existing drivers to use it as well...

thanks,

greg k-h

  reply	other threads:[~2019-06-04 17:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 20:20 [PATCHv4 0/4] add Intel Stratix10 remote system update driver richard.gong
2019-05-28 20:20 ` [PATCHv4 1/4] firmware: stratix10-svc: extend svc to support RSU notify and WD features richard.gong
2019-05-28 20:20 ` [PATCHv4 2/4] firmware: add Intel Stratix10 remote system update driver richard.gong
2019-05-28 23:15   ` Greg KH
2019-05-29 14:15     ` Richard Gong
2019-05-28 23:22   ` Greg KH
2019-05-29 14:55     ` Richard Gong
2019-06-03 15:57       ` A potential broken at platform driver? Richard Gong
2019-06-03 18:02         ` Greg KH
2019-06-03 23:08           ` Richard Gong
2019-06-04 14:28             ` Greg KH
2019-06-04 10:33           ` Romain Izard
2019-06-04 14:28             ` Greg KH
2019-06-04 16:13               ` Richard Gong
2019-06-04 17:03                 ` Greg KH [this message]
2019-06-11 14:10                   ` Richard Gong
2019-06-11 15:47                     ` Greg KH
2019-05-28 23:24   ` [PATCHv4 2/4] firmware: add Intel Stratix10 remote system update driver Greg KH
2019-05-29 15:12     ` Richard Gong
2019-05-28 20:20 ` [PATCHv4 3/4] firmware: rsu: document sysfs interface richard.gong
2019-05-28 23:19   ` Greg KH
2019-05-29 15:33     ` Richard Gong
2019-05-28 20:20 ` [PATCHv4 4/4] MAINTAINERS: add maintainer for Intel Stratix10 FW drivers richard.gong

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=20190604170310.GC14605@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=atull@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dinguyen@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=richard.gong@intel.com \
    --cc=richard.gong@linux.intel.com \
    --cc=robh+dt@kernel.org \
    --cc=romain.izard.pro@gmail.com \
    --cc=sen.li@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).