Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp29038ybs; Tue, 26 May 2020 02:51:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzblob4POc7Odgn2VN674v9c6vph3NxEJw4gdd5E7vkJq2iB9Uq7mUrEccgPwFQmiF/oG5P X-Received: by 2002:a50:fc06:: with SMTP id i6mr19981903edr.40.1590486704315; Tue, 26 May 2020 02:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590486704; cv=none; d=google.com; s=arc-20160816; b=KkHB8yB3UEbnC41wZhd93EEaxqikoCxXu9dbbdbEeZ5YvGDXP7829216supex70hEN noOICqAbuGcCgW6bQbXdM3afoUzw50bv0YnHKAOQmfdjBS8tFJj5Zs5YASrxCjKzN+tY 9vNVq0KiZHNkUTG4wHzm2NoPU6Jxf7gLhhVQsIH/2JnALfk7jpsWagDDg1Ux3S+WHKFF X8x1RhpaOaWQzL44LUr5EWaAJiFozsRakNKOWgPueOJaNo9ARDACrujSjpSStC6KpKFB 9TcIdkZQ4CP8d0QQfOzY9Y2jP7tI13Mg7fF1nq+cOOzcEonejELGe72Crq5TtPJh4GGi XfXQ== 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:message-id :subject:cc:to:from:date:dkim-signature; bh=EJqVoUsp899yEwTNN+X8jryunLTZV3BOvWvG/sVSG3M=; b=hyF10f2H+pkxkri9X3fPO1loCnUIO4N0hNIUXtlCJc3RtrBeXFnMda+9QWmILmm+At ui1NdCx/4COmolJgi9wrFCpMzOI1alsPju4YM2VHqrmMZNT9JiK6c57qAiFUSmTvXvKn hp7FEmgFe6imZEUkDb94Dok1/ul0lI8+GO2j29u3y4yHWkWGRjXvl5q811qoglker3IV dQLOszNt2Azwhe7c32w7L0nb13YqjEx3dvVrkDHzGzZM4KdisSuMJ0pkZOK+F9r7v16A skQXEHCHrUZt1DMTWgwS+D+XRUh0LFSxpnYcAg/8Ej45jhNeeCOsYQODf8mfrfaLZcvv hUGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MTJWAYIr; 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 q6si11461976edj.601.2020.05.26.02.51.19; Tue, 26 May 2020 02:51:44 -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=MTJWAYIr; 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 S1731746AbgEZJtW (ORCPT + 99 others); Tue, 26 May 2020 05:49:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:40252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728765AbgEZJtV (ORCPT ); Tue, 26 May 2020 05:49:21 -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 11CE02070A; Tue, 26 May 2020 09:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590486561; bh=YbEsQYed/xK56VlugO9eBl8EtQ7JhieFcgQki+VOcDM=; h=Date:From:To:cc:Subject:From; b=MTJWAYIrrw+c/y2vzHTDiVO7J7vRbIlHsZwxg/XHY/CJoktE7bIEk4wwD9qPoS7vw jwsVIBGHnwWJ40YE6rcJ2u/q0QRNSixOikQZJDpVlSmCXaHOgd3UIstrtcQvbyd5NV nFRzSsr1CbqCmnl9fwTBdE03qVFTrbxqS5A6pRGQ= Date: Tue, 26 May 2020 11:49:18 +0200 (CEST) From: Jiri Kosina To: Denis Efremov , Jens Axboe cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Libor Pechacek Subject: [PATCH] block/floppy: fix contended case in floppy_queue_rq() Message-ID: 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 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