Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3536429pxu; Mon, 19 Oct 2020 14:48:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCqOXg5xiGHvjQW+EMWdkMJE1jUbg4LkngypeL3c262HZ3mIthVksuudVkrU+AkcTJsBmE X-Received: by 2002:a17:906:2e08:: with SMTP id n8mr1916168eji.476.1603144124939; Mon, 19 Oct 2020 14:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603144124; cv=none; d=google.com; s=arc-20160816; b=upeg3/o0Bmu9lg5AVonMEG+RH/PonoOMH5QJTdMwG6eRa/8NOrpw5pHCNOBklzsh7s N7MrCoGHR5RidY8KzmS2wnrfonSRzty9rdIeYgMbex0JWQt3ina/nnmWYsQ2nZQEbPtx wrZldgK5aDFLulb7N4Ha+nJAiHGkNRSIT9kY5XjTMXeHa6mzSaebTY2Dkj4l7Z6BijJo D69eYbGA+jNwOaccGbGPAehCf6ub2FrkrouG20bGlxmYnLwPsgpO5E2LFWkyRTSBztGg DSUQ9gqppxcJnzQdznfB4cJNek2KzTXK8jduDW9m9xEYzHs3Pqm4WcqJODztDAHvmyv4 VOjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aV5CcFNJajE2YwDtwinfiw47UewJC6F9RRToz4kOZHE=; b=prrfHdp339qhPWErPCjj3H+jNbB4nq5mTSk347+zbQYMiVXjIBjQLnR98fH9Q1YZND Su6bEwbV2Qg50BYMhftgAnyMHlqrYHJSZpUtq4Cd4pDBn5Je0n8chXf0mdRGEHbC0bud WuFFQ449ffN/ykRzEph4vG/UQTWpt3HGs4289au6GpT0O39IaZuft5HfaNJHEYT21RYR 0MdzvqAxMWALFtG4tzLSZICQKlrTuNJDUuzUkHn1xdCvfXbQk22Vz6vBp+Mig5x6JCW5 tPp4k3fwIeCSaVWEoFHhT6bSMFi1mvd3CgYoEBrc9iCD8a8GM0EKPkF+RKCSXmrM6Wfr ZfMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hOPSYRIO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o20si895991ejn.279.2020.10.19.14.48.22; Mon, 19 Oct 2020 14:48:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hOPSYRIO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729610AbgJSIxP (ORCPT + 99 others); Mon, 19 Oct 2020 04:53:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:35152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729287AbgJSIxO (ORCPT ); Mon, 19 Oct 2020 04:53:14 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 96A9F20790; Mon, 19 Oct 2020 08:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603097593; bh=1OYAqCqBOwKL+mF0SHedq9tIVQFamriaxmYZcZAS80k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hOPSYRIOpPuOd8ghkXWMl+hUGQuONETBWdG7slsW2Nof/BzKx9dxehJO5TSZttktX ASsuEUhHLaBQ6NxbMQ3DqdLPLsz9fyXSnYsgBDleK8cqYs3DU65utLvYO4RoRxotSY P5qnIyXwpglNVFykG1ku38rKNC/Ruytoil6qlHmY= Date: Mon, 19 Oct 2020 10:53:57 +0200 From: "gregkh@linuxfoundation.org" To: Xu Yilun Cc: "Wu, Hao" , Tom Rix , "mdf@kernel.org" , "linux-fpga@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lgoncalv@redhat.com" Subject: Re: [PATCH 1/2] fpga: dfl: add driver_override support Message-ID: <20201019085357.GA3235300@kroah.com> References: <1602828151-24784-1-git-send-email-yilun.xu@intel.com> <1602828151-24784-2-git-send-email-yilun.xu@intel.com> <63d7730b-d9b8-c75d-16f6-3ebb507aabaa@redhat.com> <20201019040612.GA16172@yilunxu-OptiPlex-7050> <20201019075032.GA28746@yilunxu-OptiPlex-7050> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201019075032.GA28746@yilunxu-OptiPlex-7050> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 19, 2020 at 03:50:32PM +0800, Xu Yilun wrote: > On Mon, Oct 19, 2020 at 03:46:23PM +0800, Wu, Hao wrote: > > > On Fri, Oct 16, 2020 at 09:21:50AM -0700, Tom Rix wrote: > > > > > > > > On 10/15/20 11:02 PM, Xu Yilun wrote: > > > > > Add support for overriding the default matching of a dfl device to a dfl > > > > > driver. It follows the same way that can be used for PCI and platform > > > > > devices. This patch adds the 'driver_override' sysfs file. > > > > > > > > > > Signed-off-by: Xu Yilun > > > > > --- > > > > > Documentation/ABI/testing/sysfs-bus-dfl | 28 ++++++++++++++--- > > > > > drivers/fpga/dfl.c | 54 > > > ++++++++++++++++++++++++++++++++- > > > > > include/linux/dfl.h | 2 ++ > > > > > 3 files changed, 79 insertions(+), 5 deletions(-) > > > > > > > > > > diff --git a/Documentation/ABI/testing/sysfs-bus-dfl > > > b/Documentation/ABI/testing/sysfs-bus-dfl > > > > > index 23543be..db7e8d3 100644 > > > > > --- a/Documentation/ABI/testing/sysfs-bus-dfl > > > > > +++ b/Documentation/ABI/testing/sysfs-bus-dfl > > > > > @@ -1,15 +1,35 @@ > > > > > What:/sys/bus/dfl/devices/dfl_dev.X/type > > > > > -Date:Aug 2020 > > > > > -KernelVersion:5.10 > > > > > +Date:Oct 2020 > > > > > +KernelVersion:5.11 > > > > > Contact:Xu Yilun > > > > > Description:Read-only. It returns type of DFL FIU of the device. > > > Now DFL > > > > > supports 2 FIU types, 0 for FME, 1 for PORT. > > > > > Format: 0x%x > > > > > > > > > > What:/sys/bus/dfl/devices/dfl_dev.X/feature_id > > > > > -Date:Aug 2020 > > > > > -KernelVersion:5.10 > > > > > +Date:Oct 2020 > > > > > +KernelVersion:5.11 > > > > > Contact:Xu Yilun > > > > > Description:Read-only. It returns feature identifier local to its DFL > > > FIU > > > > > type. > > > > > Format: 0x%x > > > > > > > > These updates, do not match the comment. > > > > > > > > Consider splitting this out. > > > > > > I'm sorry it's a typo. The above code should not be changed. > > > > > > > > > > > > + > > > > > +What: /sys/bus/dfl/devices/.../driver_override > > > > > +Date: Oct 2020 > > > > > +KernelVersion: 5.11 > > > > > +Contact: Xu Yilun > > > > I am looking at description and trying to make it consistent with sysfs-bus- > > > pci > > > > > +Description: This file allows the driver for a device to be specified. > > > > > > > > 'to be specified which will override the standard dfl bus feature id to driver > > > mapping.' > > > > > > Yes, it could be improved. > > > > > > Actually now it is the "type" and "feature id" matching, the 2 fields > > > are defined for dfl_driver.id_table. In future for dfl v1, it may be > > > GUID matching, which will be added to id_table. So how about we make it > > > more generic: > > > > > > 'to be specified which will override the standard ID table matching.' > > > > > > > > > > > > > > > > When > > > > > + specified, only a driver with a name matching the value written > > > > > + to driver_override will have an opportunity to bind to the > > > > > + device. The override is specified by writing a string to the > > > > > + driver_override file (echo dfl-uio-pdev > driver_override) and > > > > > + may be cleared with an empty string (echo > driver_override). > > > > > + This returns the device to standard matching rules binding. > > > > > + Writing to driver_override does not automatically unbind the > > > > > + device from its current driver or make any attempt to > > > > > + automatically load the specified driver. If no driver with a > > > > > + matching name is currently loaded in the kernel, the device > > > > > + will not bind to any driver. This also allows devices to > > > > > + opt-out of driver binding using a driver_override name such as > > > > > + "none". Only a single driver may be specified in the override, > > > > > + there is no support for parsing delimiters. > > > > > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c > > > > > index 511b20f..bc35750 100644 > > > > > --- a/drivers/fpga/dfl.c > > > > > +++ b/drivers/fpga/dfl.c > > > > > @@ -262,6 +262,10 @@ static int dfl_bus_match(struct device *dev, > > > struct device_driver *drv) > > > > > struct dfl_driver *ddrv = to_dfl_drv(drv); > > > > > const struct dfl_device_id *id_entry; > > > > > > > > > > +/* When driver_override is set, only bind to the matching driver */ > > > > > +if (ddev->driver_override) > > > > > +return !strcmp(ddev->driver_override, drv->name); > > > > > + > > > > > id_entry = ddrv->id_table; > > > > > if (id_entry) { > > > > > while (id_entry->feature_id) { > > > > > @@ -303,6 +307,53 @@ static int dfl_bus_uevent(struct device *dev, > > > struct kobj_uevent_env *env) > > > > > ddev->type, ddev->feature_id); > > > > > } > > > > > > > > > > > > > I am looking at other implementations of driver_override* and looking for > > > consistency. > > > > > > > > > +static ssize_t driver_override_show(struct device *dev, > > > > > + struct device_attribute *attr, char *buf) > > > > > +{ > > > > > +struct dfl_device *ddev = to_dfl_dev(dev); > > > > > +ssize_t len; > > > > > + > > > > > +device_lock(dev); > > > > > +len = sprintf(buf, "%s\n", ddev->driver_override); > > > > len = snprintf(buf, PAGE_SIZE ... > > > > > > It is good to me. > > > > > > Some bus drivers use snprintf, some use sprintf. > > > > > > I think it is reasonable snprintf is used here, unlike %d, %u ... it is > > > uncertain for the output size of %s. No, no one should care at all about this. If you are caring, then you are using sysfs wrong. Just use sprintf(), you never care about the size of the buffer for a show/store function. Or better yet, use the new sysfs_emit() call, that is what everything will be converted over to anyway. > > you limited the size < a page in store function for driver_override? > > Yes. So normally the sprintf should be OK. But I think it may be safer > if the driver_override pointer is corrupted in some unexpected cases. How can that happen? greg k-h