linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Xu Yilun <yilun.xu@intel.com>
Cc: Tom Rix <trix@redhat.com>,
	mdf@kernel.org, linux-fpga@vger.kernel.org,
	linux-kernel@vger.kernel.org, lgoncalv@redhat.com,
	hao.wu@intel.com
Subject: Re: [PATCH 1/2] fpga: dfl: add driver_override support
Date: Mon, 19 Oct 2020 11:03:16 +0200	[thread overview]
Message-ID: <20201019090316.GA3237088@kroah.com> (raw)
In-Reply-To: <20201019085233.GB28746@yilunxu-OptiPlex-7050>

On Mon, Oct 19, 2020 at 04:52:33PM +0800, Xu Yilun wrote:
> On Mon, Oct 19, 2020 at 12:06:13PM +0800, Xu Yilun 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 <yilun.xu@intel.com>
> > > > ---
> > > >  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 <yilun.xu@intel.com>
> > > >  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 <yilun.xu@intel.com>
> > > >  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 <yilun.xu@intel.com>
> > > 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.
> 
> Sorry, I checked the Documentation/filesystems/sysfs.rst again and found
> I didn't remember it correctly.
> 
> The snprintf is must not be used, sprintf() or scnprintf() should be
> used. So I prefer sprintf() here, following other implementations.
> 
> sprintf() should be safe here, as we already limited the input of
> driver_override string to less then PAGE_SIZE on store().

As already mentioned, please use sysfs_emit() instead.

thanks,

greg k-h

  reply	other threads:[~2020-10-19  9:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16  6:02 [PATCH 0/2] UIO support for dfl devices Xu Yilun
2020-10-16  6:02 ` [PATCH 1/2] fpga: dfl: add driver_override support Xu Yilun
2020-10-16 16:21   ` Tom Rix
2020-10-19  4:06     ` Xu Yilun
2020-10-19  7:46       ` Wu, Hao
2020-10-19  7:50         ` Xu Yilun
2020-10-19  8:53           ` gregkh
2020-10-19  8:52       ` Xu Yilun
2020-10-19  9:03         ` Greg KH [this message]
2020-10-20  0:42           ` Xu Yilun
2020-10-19 13:55       ` Tom Rix
2020-10-20  7:11         ` Xu Yilun
2020-10-20  7:32           ` Greg KH
2020-10-20  8:57             ` Xu Yilun
2020-10-20  9:21               ` Greg KH
2020-10-21  7:25                 ` Xu Yilun
2020-11-09  2:30                   ` Xu Yilun
2020-10-20 14:13           ` Tom Rix
2020-10-16  6:02 ` [PATCH 2/2] fpga: dfl: add the userspace I/O device support for DFL devices Xu Yilun
2020-10-16 16:36   ` Tom Rix
2020-10-19  4:16     ` Xu Yilun
2020-10-19 14:01       ` Tom Rix
2020-10-16 16:40 ` [PATCH 0/2] UIO support for dfl devices Tom Rix
2020-10-19  4:17   ` Xu Yilun

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=20201019090316.GA3237088@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=hao.wu@intel.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=trix@redhat.com \
    --cc=yilun.xu@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).