Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4629493ybi; Tue, 11 Jun 2019 09:42:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSrLWlSJARxQpnx/9BjPRRmDn94fZnhsN8PEvw/0UbYZJtEux+am2/tZpO6MemR7bZdbk4 X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr26482907pjs.101.1560271373221; Tue, 11 Jun 2019 09:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560271373; cv=none; d=google.com; s=arc-20160816; b=ro2Mt5FAKK4GnDzTo2ZEgQBePuK0bLp7wkf+gUwDlO6HVJD16j6f/izWB3RTDEIuls EwGS89dziJ1phRL9lLPjzNKZBf7BAN02m3JDBgjZCJXeGSUHNXnvwsBxkzoubJ1WfrNr 8A1JsRSxipKg/7nlzLlt0WVxJX4moB6liN0mPp+jBzisz4Y/y24TamvXHg/gFlXsMHeb Rna0pNWnUyC0bPJaeoHoY9JMtuOrHden0VSwk60XWl0z6cTGpu90BTHBq1+ENeIBEG6J xNByB4Mo6nDk+fyxAe51bvBVel96lR568XpAJebTGrGJpEsz/310S6plpJbSVfG7Q0ek Afew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qvC9XTJJQ+U9Rc3VJ2l0epzFFM/lxRCDemhU0Jgc3jg=; b=e5/zSR462uyB/QIUpCnqhqaVjxGnq0jj1eVnARToBj2013bHn38Jwh6xJIM/XegJD3 44xtxbFhn3YztQInDDOr87Am/rc9FHQsjlsdRF+qAt32O1xiFXwVx4Yr1WkYu08ThhLK Mk48PRKeaiIKqbrurT5cJFsOVQFW2ndNth0Clk/+WxAkOQpCMCXaTa3BCWfhU9bZ3FiP OE2ZwlRsDzdKWy6uChKxq30HJaknONc6APCCWntzC7cvZ949mX+wPaY35lMXxrGHyMEv w+SYd7MzBJYOERxHVE9tmMdTZeYzo7bPfCfsUVnJfQzp3PL31ePtaBUIjYQzIs12g6On reyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e3yDQiYk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si12398102pgv.105.2019.06.11.09.42.38; Tue, 11 Jun 2019 09:42:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e3yDQiYk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405389AbfFKPrK (ORCPT + 99 others); Tue, 11 Jun 2019 11:47:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:34312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389302AbfFKPrK (ORCPT ); Tue, 11 Jun 2019 11:47:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11BDC2080A; Tue, 11 Jun 2019 15:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560268029; bh=ODzIca1G6HwE9DpSxb7ddhUfILHkfcmRba/4rBqVBxQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=e3yDQiYkifbMrkWt69XVzkQEu4k3E4TzQ+jgCbNCKbq3tFTul7bQtdb/ivvMASCIo D2mWwf5Ja3ceey3cJW0djsE08rHo0qdxViwzpPcbvxzwfEMBWvI9klRn7dfe5Cu8NB PopmPDk+qxIOQXhJWAo78I+DLxkacSjMXgngNke4= Date: Tue, 11 Jun 2019 17:47:06 +0200 From: Greg KH To: Richard Gong Cc: Romain Izard , 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 Subject: Re: A potential broken at platform driver? Message-ID: <20190611154706.GE5706@kroah.com> References: <1559074833-1325-3-git-send-email-richard.gong@linux.intel.com> <20190528232224.GA29225@kroah.com> <1e3b5447-b776-f929-bca6-306f90ac0856@linux.intel.com> <20190603180255.GA18054@kroah.com> <20190604103241.GA4097@5WDYG62> <20190604142803.GA28355@kroah.com> <20190604170310.GC14605@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 11, 2019 at 09:10:05AM -0500, Richard Gong wrote: > > Hi Greg, > > On 6/4/19 12:03 PM, Greg KH wrote: > > 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... > > > > Sorry for asking. > > I haven't seen your patch, did you release that? > I didn't post it yet, sorry. I started on cleaning up the whole kernel tree, to show users of the new groups, and then got side-tracked. The code is in a public branch, I'll clean it up this week and send it off, hopefully I'll have time over the next few days... thanks, greg k-h