netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arseny Maslennikov <ar@cs.msu.ru>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-rdma@vger.kernel.org, Doug Ledford <dledford@redhat.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH v4 3/3] IB/ipoib: Log sysfs 'dev_id' accesses from userspace
Date: Sun, 9 Sep 2018 21:11:46 +0300	[thread overview]
Message-ID: <20180909181146.GA29632@cello.Dlink> (raw)
In-Reply-To: <20180907154359.GA14627@ziepe.ca>

[-- Attachment #1: Type: text/plain, Size: 3223 bytes --]

On Fri, Sep 07, 2018 at 09:43:59AM -0600, Jason Gunthorpe wrote:
> On Thu, Sep 06, 2018 at 05:51:12PM +0300, Arseny Maslennikov wrote:
> > Some tools may currently be using only the deprecated attribute;
> > let's print an elaborate and clear deprecation notice to kmsg.
> > 
> > To do that, we have to replace the whole sysfs file, since we inherit
> > the original one from netdev.
> > 
> > Signed-off-by: Arseny Maslennikov <ar@cs.msu.ru>
> >  drivers/infiniband/ulp/ipoib/ipoib_main.c | 31 +++++++++++++++++++++++
> >  1 file changed, 31 insertions(+)
> > 
> > diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
> > index 30f840f874b3..74732726ec6f 100644
> > +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
> > @@ -2386,6 +2386,35 @@ int ipoib_add_pkey_attr(struct net_device *dev)
> >  	return device_create_file(&dev->dev, &dev_attr_pkey);
> >  }
> >  
> > +/*
> > + * We erroneously exposed the iface's port number in the dev_id
> > + * sysfs field long after dev_port was introduced for that purpose[1],
> > + * and we need to stop everyone from relying on that.
> > + * Let's overload the shower routine for the dev_id file here
> > + * to gently bring the issue up.
> > + *
> > + * [1] https://www.spinics.net/lists/netdev/msg272123.html
> > + */
> > +static ssize_t dev_id_show(struct device *dev,
> > +			   struct device_attribute *attr, char *buf)
> > +{
> > +	struct net_device *ndev = to_net_dev(dev);
> > +
> > +	if (ndev->dev_id == ndev->dev_port)
> > +		netdev_info_once(ndev,
> > +			"\"%s\" wants to know my dev_id. Should it look at dev_port instead? See Documentation/ABI/testing/sysfs-class-net for more info.\n",
> > +			current->comm);
> > +
> > +	return sprintf(buf, "%#x\n", ndev->dev_id);
> > +}
> > +static DEVICE_ATTR_RO(dev_id);
> > +
> > +int ipoib_intercept_dev_id_attr(struct net_device *dev)
> > +{
> > +	device_remove_file(&dev->dev, &dev_attr_dev_id);
> > +	return device_create_file(&dev->dev, &dev_attr_dev_id);
> > +}
> 
> Isn't this racey with userspace? Ie what happens if udev is querying
> the dev_id right here?

udev in particular does not use dev_id at all since 2014, because "why
would we keep using dev_id if it is not the right thing to use?".

> 
> Do we know there is no userspace doing this?
> 

Not for sure.

If we move all the sysfs handling stuff we introduce in _add_port():
 - pkey
 - umcast
 - {create,delete}_child
 - connected/datagram mode
to _ndo_init(), which is called by register_netdev before it sends
the netlink message, would that suffice to eliminate the race?
(Sysfs files for {create,delete}_child go to _parent_init() then).

> >  static struct net_device *ipoib_add_port(const char *format,
> >  					 struct ib_device *hca, u8 port)
> >  {
> > @@ -2427,6 +2456,8 @@ static struct net_device *ipoib_add_port(const char *format,
> >  	 */
> >  	ndev->priv_destructor = ipoib_intf_free;
> >  
> > +	if (ipoib_intercept_dev_id_attr(ndev))
> > +		goto sysfs_failed;
> 
> No device_remove_file needed?
> 

As far as I understand, unregister_netdevice takes care of it
while destroying the related kobject.

> Jason

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2018-09-09 23:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06 14:51 [PATCH v4 0/3] IB/ipoib: Use dev_port to disambiguate port numbers Arseny Maslennikov
2018-09-06 14:51 ` [PATCH v4 1/3] Documentation/ABI: document /sys/class/net/*/dev_port Arseny Maslennikov
2018-09-06 14:51 ` [PATCH v4 2/3] IB/ipoib: Use dev_port to expose network interface port numbers Arseny Maslennikov
2018-09-06 14:51 ` [PATCH v4 3/3] IB/ipoib: Log sysfs 'dev_id' accesses from userspace Arseny Maslennikov
2018-09-07 15:43   ` Jason Gunthorpe
2018-09-07 17:14     ` Doug Ledford
2018-09-07 17:24       ` Jason Gunthorpe
2018-09-09 18:11     ` Arseny Maslennikov [this message]
2018-09-09 20:55       ` Arseny Maslennikov
2018-09-13 15:45         ` Doug Ledford
2018-09-13 16:50 ` [PATCH v4 0/3] IB/ipoib: Use dev_port to disambiguate port numbers Doug Ledford

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=20180909181146.GA29632@cello.Dlink \
    --to=ar@cs.msu.ru \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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).