Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4465590ybi; Tue, 11 Jun 2019 07:08:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTkPhHunCvtjp1ubBx5ClU+LpkHJ99eHytTGphCqHxZR5BMq6zFmCrGChta1ZQMccn4qCa X-Received: by 2002:a65:620a:: with SMTP id d10mr20563455pgv.42.1560262088173; Tue, 11 Jun 2019 07:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560262088; cv=none; d=google.com; s=arc-20160816; b=VnCTpSJJMrgiKGTD9zAj9YX8w9YAhMzjpcIR2+o5ZKSxq/KNY/m9fBTRjut0irmFgw 2LdL0DZctoBuCF2XvAe1wL13ljkxmdSQT1RNZEjSFDdxUZIkpkuajmTGLKjbiSh9RyOx 8UXnroBdbqNrby3r6ZwoK5WOQhNbqJACn4u6vmjW1Hkil8iU0gDJibFv8M1WZFfDS3BD 5rLw5DbI6/f30tQnijUQMBL0cgnJy+VuLZNjfoFnNp1PiLTo0FSv1ITeZNo/AWwXNOeN 5Pk3hY2XzjvRkTnWXCJYX7jH9MDxbRy9vo2Q6H7c2s/k3s6h7+jVmahd00tvxNkdZTm4 ahuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=5Fk97I1n+B7xR/v9bp2PXB+irsK+E4RH07UKH1JFbsg=; b=qqIdWv1nQCVPjIFDC+VooFGzUJzQhMfNx/5zs5ThVWDhtMvf3cYq4PKck+KCP3cWOO CYDP9aihtnXJKytXSVtaxrpSz8W7xP5Of7M7rU6Am9lQp9WVzjBX3Ncy8V2WALIOz47i jZcctxtZ8og7TkRHSErzawJ4ZQ6vmdfXIqcr8zyRc4fAAadlpjYeMK7m7antBsof7Eux S33fZ15X8R1yQgxGNb2iJL2uEzw1HUomPCYkno3hGdY2qnXsZQkFxBaPsPnWjNz2ZAnd gKEXHCeoniDLciJNP1Zo/4enp+8+67zIJP4cysfiKHyOjDd3Me6sdndcZypNuU3s1UVu R6qQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si11771855pgq.490.2019.06.11.07.07.51; Tue, 11 Jun 2019 07:08:08 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391551AbfFKN5T (ORCPT + 99 others); Tue, 11 Jun 2019 09:57:19 -0400 Received: from mga14.intel.com ([192.55.52.115]:42646 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387835AbfFKN5S (ORCPT ); Tue, 11 Jun 2019 09:57:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 06:57:18 -0700 X-ExtLoop1: 1 Received: from marshy.an.intel.com (HELO [10.122.105.159]) ([10.122.105.159]) by orsmga003.jf.intel.com with ESMTP; 11 Jun 2019 06:57:16 -0700 Subject: Re: A potential broken at platform driver? To: Greg KH 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 References: <1559074833-1325-1-git-send-email-richard.gong@linux.intel.com> <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> From: Richard Gong Message-ID: Date: Tue, 11 Jun 2019 09:10:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190604170310.GC14605@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Regards, Richard > thanks, > > greg k-h >