[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210607123210.GD1002214@nvidia.com>
Date: Mon, 7 Jun 2021 09:32:10 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Greg KH <gregkh@...uxfoundation.org>
Cc: Leon Romanovsky <leon@...nel.org>,
Doug Ledford <dledford@...hat.com>,
Kees Cook <keescook@...omium.org>,
Nathan Chancellor <nathan@...nel.org>,
Adit Ranadive <aditr@...are.com>,
Ariel Elior <aelior@...vell.com>,
Christian Benvenuti <benve@...co.com>,
clang-built-linux@...glegroups.com,
Dennis Dalessandro <dennis.dalessandro@...nelisnetworks.com>,
Devesh Sharma <devesh.sharma@...adcom.com>,
Gal Pressman <galpress@...zon.com>,
linux-kernel@...r.kernel.org, linux-rdma@...r.kernel.org,
Michal Kalderon <mkalderon@...vell.com>,
Mike Marciniszyn <mike.marciniszyn@...nelisnetworks.com>,
Mustafa Ismail <mustafa.ismail@...el.com>,
Naresh Kumar PBS <nareshkumar.pbs@...adcom.com>,
Nelson Escobar <neescoba@...co.com>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Potnuri Bharat Teja <bharat@...lsio.com>,
Selvin Xavier <selvin.xavier@...adcom.com>,
Shiraz Saleem <shiraz.saleem@...el.com>,
VMware PV-Drivers <pv-drivers@...are.com>,
Yishai Hadas <yishaih@...dia.com>,
Zhu Yanjun <zyjzyj2000@...il.com>
Subject: Re: [PATCH rdma-next v1 02/15] RDMA/core: Replace the ib_port_data
hw_stats pointers with a ib_port pointer
On Mon, Jun 07, 2021 at 12:23:23PM +0200, Greg KH wrote:
> > static int add_port(struct ib_core_device *coredev, int port_num)
> > {
> > struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
> > @@ -1171,6 +1177,8 @@ static int add_port(struct ib_core_device *coredev, int port_num)
> > setup_hw_stats(device, p, port_num);
> >
> > list_add_tail(&p->kobj.entry, &coredev->port_list);
> > + if (device->port_data && is_full_dev)
> > + device->port_data[port_num].sysfs = p;
>
> You are saving off a pointer to a reference counted structure without
> incrementing the reference count on it?
This storage borrows another reference count, primarily because there
is no locking to read/write .sysfs. It is a fairly common idiom.
You can see it in the free path:
port->ibdev->port_data[port->port_num].sysfs = NULL;
kobject_put(&port->kobj); // port == p above
Due to the lack of locks the whole external thing is arranged so that
the 3 users of .sysfs are sequenced properly around
setup_port()/destroy_port() using other external locks.
Adding more refs without also adding locking is just confusing what
the data protection model is. This is a borrowed ref and access is
only allowed when other locking is properly sequencing it with the ref
owner's manipulation of .sysfs.
Eg I would reject some code sequence like this:
port->ibdev->port_data[port->port_num].sysfs = NULL;
kobject_put(&port->kobj); // one for .sysfs
kobject_put(&port->kobj); // one for our stack
As being pretty bogus.
Jason
Powered by blists - more mailing lists