From: Bart Van Assche <Bart.VanAssche@wdc.com>
To: "hch@lst.de" <hch@lst.de>
Cc: "zhaohongjiang@huawei.com" <zhaohongjiang@huawei.com>,
"jthumshirn@suse.de" <jthumshirn@suse.de>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
"hare@suse.de" <hare@suse.de>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"yanaijie@huawei.com" <yanaijie@huawei.com>,
"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>,
"miaoxie@huawei.com" <miaoxie@huawei.com>
Subject: Re: [PATCH] scsi: fix race condition when removing target
Date: Wed, 29 Nov 2017 17:39:07 +0000 [thread overview]
Message-ID: <1511977145.2671.13.camel@wdc.com> (raw)
In-Reply-To: <20171129162050.GA32071@lst.de>
On Wed, 2017-11-29 at 17:20 +0100, hch@lst.de wrote:
> On Wed, Nov 29, 2017 at 04:18:30PM +0000, Bart Van Assche wrote:
> > As the above patch description shows it can happen that the SCSI core calls
> > get_device() after the device reference count has reached zero and before
> > the memory for struct device is freed. Although the above patch looks fine
> > to me, would you consider it acceptable to modify get_device() such that it
> > uses kobject_get_unless_zero() instead of kobject_get()? I'm asking this
> > because that change would help to reduce the complexity of the already too
> > complicated SCSI core.
>
> I don't think we can just modify get_device, but we can add a new
> get_device_unless_zero. In fact I have an open coded variant of that
> in nvme, and was planning to submit one for the current merge window..
Sorry but I don't see why we can't modify get_device()? Can you explain why
you think that something like the patch below is wrong?
Thanks,
Bart.
[PATCH] Make it safe to use get_device() if the reference count is zero
---
drivers/base/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 110230d86527..049a5d9dba8a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1916,7 +1916,7 @@ EXPORT_SYMBOL_GPL(device_register);
*/
struct device *get_device(struct device *dev)
{
- return dev ? kobj_to_dev(kobject_get(&dev->kobj)) : NULL;
+ return dev && kobject_get_unless_zero(&dev->kobj) ? dev : NULL;
}
EXPORT_SYMBOL_GPL(get_device);
next prev parent reply other threads:[~2017-11-29 17:39 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 3:05 [PATCH] scsi: fix race condition when removing target Jason Yan
2017-11-29 7:41 ` Hannes Reinecke
2017-11-29 16:18 ` Bart Van Assche
2017-11-29 16:20 ` hch
2017-11-29 17:39 ` Bart Van Assche [this message]
2017-11-30 1:18 ` Jason Yan
2017-11-30 16:08 ` Bart Van Assche
2017-11-30 16:40 ` gregkh
2017-11-30 23:56 ` James Bottomley
2017-12-01 1:12 ` Finn Thain
2017-12-01 8:40 ` Jason Yan
2017-12-01 14:41 ` Ewan D. Milne
2017-12-01 15:35 ` James Bottomley
2017-12-05 12:37 ` Jason Yan
2017-12-05 15:37 ` James Bottomley
2017-12-06 0:41 ` Jason Yan
2017-12-06 2:07 ` James Bottomley
2017-12-06 2:43 ` Jason Yan
2017-11-29 17:39 ` gregkh
2017-11-29 18:49 ` Ewan D. Milne
2017-11-29 19:11 ` Bart Van Assche
2017-11-29 19:20 ` Ewan D. Milne
2017-11-29 19:50 ` Bart Van Assche
2017-11-29 17:39 ` gregkh
2017-11-29 17:47 ` Bart Van Assche
2017-11-29 16:31 ` James Bottomley
2017-11-29 16:34 ` Christoph Hellwig
2017-11-29 16:47 ` James Bottomley
2017-11-29 19:05 ` Ewan D. Milne
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=1511977145.2671.13.camel@wdc.com \
--to=bart.vanassche@wdc.com \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=jthumshirn@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=miaoxie@huawei.com \
--cc=yanaijie@huawei.com \
--cc=zhaohongjiang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.