From: Hannes Reinecke <hare@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>,
Bart Van Assche <bvanassche@acm.org>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Joe Lawrence <jdl1291@gmail.com>
Subject: Re: [PATCH RFC] Remove the cancel_delayed_work() call from scsi_put_command()
Date: Fri, 23 May 2014 13:36:38 +0200 [thread overview]
Message-ID: <537F32C6.1010109@suse.de> (raw)
In-Reply-To: <537F30D6.9060206@redhat.com>
On 05/23/2014 01:28 PM, Paolo Bonzini wrote:
> Il 23/05/2014 12:37, Bart Van Assche ha scritto:
>> On 05/23/14 11:24, Paolo Bonzini wrote:
>>> Il 23/05/2014 08:09, Hannes Reinecke ha scritto:
>>>>
>>>> And when freeing a command we absolutely need to make sure that
>>>> the workqueue is empty.
>>>> So calling cancel_delayed_work() was the obvious thing to do.
>>>
>>> You would need cancel_delayed_work_sync, but if it really
>>> happened that
>>> the work item is running, it would cause a double free.
>>>
>>>> I'd be fine with adding a WARN_ON(!list_empty(&cmd->abort_work))
>>>> here, however. This will clear up the intent of this statement.
>>>
>>> BUG_ON even, since you'd get badness from the double free anyway.
>>
>> Hello Paolo,
>>
>> Are you aware that Linus strongly prefers WARN_ON_ONCE() over
>> BUG_ON() ?
>> See e.g. https://lkml.org/lkml/2012/9/27/461 or
>> https://lkml.org/lkml/2014/4/28/657.
>
> Yes, I am and I even downgraded some KVM BUG_ONs recently.
>
> But in this case I think that memory corruption is going to happen
> anyway unless you consciously leak the Scsi_Cmnd * (because if you
> use WARN_ON, you also need to return early as Linus suggested in the
> second email).
>
> So the WARN_ON/BUG_ON choice here should not just consider what
> makes the problem easier to debug; hanging the machine before
> guaranteed badness seems to me like a good use for BUG_ON.
>
So this should work, right?
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 88d46fe..53b8b94 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -334,7 +334,7 @@ void scsi_put_command(struct scsi_cmnd *cmd)
list_del_init(&cmd->list);
spin_unlock_irqrestore(&cmd->device->list_lock, flags);
- cancel_delayed_work(&cmd->abort_work);
+ BUG_ON(delayed_work_pending(&cmd->abort_work));
__scsi_put_command(cmd->device->host, cmd);
}
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@suse.de +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2014-05-23 11:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 13:30 [PATCH RFC] Remove the cancel_delayed_work() call from scsi_put_command() Bart Van Assche
2014-05-22 16:22 ` Paolo Bonzini
2014-05-22 17:41 ` Bart Van Assche
2014-05-23 6:09 ` Hannes Reinecke
2014-05-23 9:24 ` Paolo Bonzini
2014-05-23 10:37 ` Bart Van Assche
2014-05-23 11:28 ` Paolo Bonzini
2014-05-23 11:36 ` Hannes Reinecke [this message]
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=537F32C6.1010109@suse.de \
--to=hare@suse.de \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=hch@infradead.org \
--cc=jdl1291@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=pbonzini@redhat.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.