From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752581AbbJFSuT (ORCPT ); Tue, 6 Oct 2015 14:50:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36438 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752058AbbJFSuR (ORCPT ); Tue, 6 Oct 2015 14:50:17 -0400 Date: Tue, 6 Oct 2015 14:50:16 -0400 From: Mike Snitzer To: Mikulas Patocka Cc: Jens Axboe , Kent Overstreet , dm-devel@redhat.com, linux-kernel@vger.kernel.org, "Alasdair G. Kergon" Subject: Re: block: flush queued bios when the process blocks Message-ID: <20151006185016.GA31955@redhat.com> References: <5384AA79.4010206@kernel.dk> <5384B26D.1000703@kernel.dk> <5384CE82.90601@kernel.dk> <20151005205943.GB25762@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 06 2015 at 2:17pm -0400, Mikulas Patocka wrote: > > > On Mon, 5 Oct 2015, Mike Snitzer wrote: > > > FYI, I've put rebased versions of your 2 patches in my wip branch, see: > > http://git.kernel.org/cgit/linux/kernel/git/snitzer/linux.git/log/?h=wip > > I found a bug in the first patch > (http://git.kernel.org/cgit/linux/kernel/git/snitzer/linux.git/commit/?h=wip&id=2e90df2e9cf482f45be4230152535fdab525fbd8) > > There is this piece of code: > > spin_lock(&bs->rescue_lock); > bio_list_add(&bs->rescue_list, bio); > spin_unlock(&bs->rescue_lock); > queue_work(bs->rescue_workqueue, &bs->rescue_work); > > It is possible that after spin_unlock and before queue_work the bio is > finished by previous workqueue invocation. When the bio is finished, it is > possible that the block device is unloaded and queue_work accesses freed > memory. > > Change the code so that queue_work is executed inside the spinlock: > spin_lock(&bs->rescue_lock); > bio_list_add(&bs->rescue_list, bio); > queue_work(bs->rescue_workqueue, &bs->rescue_work); > spin_unlock(&bs->rescue_lock); OK, but that should get pulled out to a separate stable@ fix that patch you reference builds on. I've adjusted my 'wip' branch accordingly (with placeholder commit that needs revised header, etc).