Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp92456ybm; Tue, 26 May 2020 11:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTR71i0tsIXML2r8eZZ+rOUqmVsipEQwgrlsH547E6Rqo4U858iGp0aA0BpbN0pV4A+/aD X-Received: by 2002:a17:906:b750:: with SMTP id fx16mr2241999ejb.35.1590518050096; Tue, 26 May 2020 11:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590518050; cv=none; d=google.com; s=arc-20160816; b=ar/LzAdkHOoeW4wqvEfGNbNOYiZtLjQQzCUu3glx94Ygv7A7xK23HWhIww/FzRKnMf jQ+3eSpHwoafwUqEq7aaxC7oU91EBXFNwd5KW5hqDuCOMJBn6JIew0IdSLlX6HEPvkVe MDom2rmncgSo6NVO4Y0RXppA8RAc4Cm0RGRCeZWLHlHTyhRlA27LkLmqIgooTV68gXa9 r/FI2sZmfiy12rB4RZeOFqJrkXifQve2zeOEhpXO9tweMnJlIH4YWNjGD64QPa+Sukyd +lxao1cccURcWeAfNFocMyYu+zrXwhbcHw1v+1MhBl3uJ3yVK1hHbR8RfQjTwk8EQDdq 2TCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=H1fIorXHT7rv+A3gv5QU/+NfwjpkwCbZ0DWUdEpifmU=; b=MNpHbBcJrJOwXTHxcT2PdPUZGt26cksG7UZVFk5VP+3I4U/PnMtyaqYQx14jKT7Wk3 ITp4Gyz4MIsRC7g3vQJL5tlDc8nztA0wUKF/hh+vOiYzoXC7rqFa0pTTYmwiewj2ou93 s1ww2E5SlPl6epiWzP07bUCFsXpV5TC6Zvvb9RZGPm25NySHD8ZyWrMHLRR4rkLVNUFk TV4v0WH/muvmAfZAvs3gMEOwq6FR7i+arvXnPs8NBfwNBEzn+9ErF4j85fU5iTOz5PKz dllvdtDMD23RjDixnTYNtcYANVgCLJwOw9/p86/ZHbnRfYSKPiTr3l+MI9TJfN55j1Jk VLmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i8itfqPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si361172ejf.233.2020.05.26.11.33.46; Tue, 26 May 2020 11:34:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i8itfqPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729302AbgEZSby (ORCPT + 99 others); Tue, 26 May 2020 14:31:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:39354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728067AbgEZSby (ORCPT ); Tue, 26 May 2020 14:31:54 -0400 Received: from pobox.suse.cz (nat1.prg.suse.com [195.250.132.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E298F2068D; Tue, 26 May 2020 18:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590517914; bh=PcBDaM5aceqkX7fvSzO0h7Yd9xAYtumquZkhqZPi6D0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=i8itfqPLREwNNI/VKdXo5BFXbl3rdAnJRvKw1LHH7KVeLqD1OFQc+ClOAiW1zbpvx ktKrib/m79kOTTw5cicXicVLVo6iMlIvOxFx7/mGCYN0UzYADObzCud9OpI7lJej4P cBd+s6nNpXZ0Pr2dmpQhYyn4CkJYrvxOfUk2mmEE= Date: Tue, 26 May 2020 20:31:50 +0200 (CEST) From: Jiri Kosina To: Denis Efremov , Jens Axboe , Omar Sandoval cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Libor Pechacek Subject: Re: [PATCH] block/floppy: fix contended case in floppy_queue_rq() In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ forgot to CC Omar, fixing ] On Tue, 26 May 2020, Jiri Kosina wrote: > From: Jiri Kosina > > Since the switch of floppy driver to blk-mq, the contended (fdc_busy) case > in floppy_queue_rq() is not handled correctly. > > In case we reach floppy_queue_rq() with fdc_busy set (i.e. with the floppy > locked due to another request still being in-flight), we put the request > on the list of requests and return BLK_STS_OK to the block core, without > actually scheduling delayed work / doing further processing of the > request. This means that processing of this request is postponed until > another request comes and passess uncontended. > > Which in some cases might actually never happen and we keep waiting > indefinitely. The simple testcase is > > for i in `seq 1 2000`; do echo -en $i '\r'; blkid --info /dev/fd0 2> /dev/null; done > > run in quemu. That reliably causes blkid eventually indefinitely hanging > in __floppy_read_block_0() waiting for completion, as the BIO callback > never happens, and no further IO is ever submitted on the (non-existent) > floppy device. This was observed reliably on qemu-emulated device. > > Fix that by not queuing the request in the contended case, and return > BLK_STS_RESOURCE instead, so that blk core handles the request > rescheduling and let it pass properly non-contended later. > > Fixes: a9f38e1dec107a ("floppy: convert to blk-mq") > Cc: stable@vger.kernel.org > Tested-by: Libor Pechacek > Signed-off-by: Jiri Kosina > --- > drivers/block/floppy.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index c3daa64cb52c..975cd0a6baa1 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -2938,17 +2938,17 @@ static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx, > (unsigned long long) current_req->cmd_flags)) > return BLK_STS_IOERR; > > - spin_lock_irq(&floppy_lock); > - list_add_tail(&bd->rq->queuelist, &floppy_reqs); > - spin_unlock_irq(&floppy_lock); > - > if (test_and_set_bit(0, &fdc_busy)) { > /* fdc busy, this new request will be treated when the > current one is done */ > is_alive(__func__, "old request running"); > - return BLK_STS_OK; > + return BLK_STS_RESOURCE; > } > > + spin_lock_irq(&floppy_lock); > + list_add_tail(&bd->rq->queuelist, &floppy_reqs); > + spin_unlock_irq(&floppy_lock); > + > command_status = FD_COMMAND_NONE; > __reschedule_timeout(MAXTIMEOUT, "fd_request"); > set_fdc(0); > > -- > Jiri Kosina > SUSE Labs > > -- Jiri Kosina SUSE Labs