Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1995958yba; Mon, 15 Apr 2019 02:46:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/2bJ4A0B9YoFc0B1Yk1174bcqZCS0jVhtOnYkFrQ3BOHwPQY4zD5c+NLYw7j0VlYF4ZrL X-Received: by 2002:a17:902:2702:: with SMTP id c2mr55305702plb.37.1555321616817; Mon, 15 Apr 2019 02:46:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555321616; cv=none; d=google.com; s=arc-20160816; b=Fz9ALeOgbeeSyrccc5hggzcNx38IZx630uL/8yYEj9B7ab4jpClH5/KHvXaVeA8qPO DbpjjBqbdZKDPEZTVHPfKy3J8DF4zF0d/d6CnSjliGvOQ6ykWBrT7YQntrIUlz+LsIUn Lndwb0qJxCdHS4XaRYB+FkAFwjiVlILr6pVGUP8xY0nXHSFSDBsPZkgLM8Km2GyJv+tO 9IEqMboTCW3SwhZ3Nlw/K+6HVPjAx3MyklwOGmx2YbWum4ifomUVGr2DihK73Rxmo+Ix R7iBCwLapRmM9dQqvGxzC//fwkCeJ9xbZtKxP7TPeah9clvF01Bn6wDCPa67qF2awXFf LmQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=TvjQTBHZ8eKcjE8JIHf6Aai9PE6GLAnyWXAWihFQLXs=; b=oe3GCNdNSTVjVcjEtKjGGkVEn7iR1v7JNSZvJH+cuF7esHuR3rc8qQ3ldQ0q9ctmI6 dkgPlp9p6xfAhBFzc53mXAvCkOY98ba+J+B1wqwISuQs6fCtZuPupbVW/UlTlKTAeRzr 9VEgGQJqR5wnjWvJyvRJKSKfUuZFsBceqMBP6DLmIUGBhKwr5q2fKQtyApOSvRrW2Pey 0d792/QXywtzaElvReMeUo+3Pd2hJYwaNjgkyy5fig2XC0fejj2d+VKRCO9rbyRED7JT zhcJ/2UKme1Eg3bXWtrkHcc2/wx9sG9A0xePRLpkLAr0bObBBXEZQLYj67rfrNckzKRf 9kGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay8si38816124plb.202.2019.04.15.02.46.40; Mon, 15 Apr 2019 02:46:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbfDOJqG (ORCPT + 99 others); Mon, 15 Apr 2019 05:46:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:56964 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725816AbfDOJqG (ORCPT ); Mon, 15 Apr 2019 05:46:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 981F6B020; Mon, 15 Apr 2019 09:46:04 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 15 Apr 2019 11:46:04 +0200 From: Roman Penyaev To: Bart Van Assche Cc: Bob Liu , linux-block@vger.kernel.org, shirley.ma@oracle.com, martin.petersen@oracle.com, Roman Pen , Akinobu Mita , Tejun Heo , Jens Axboe , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-block-owner@vger.kernel.org Subject: Re: [RESEND PATCH] blk-mq: fix hang caused by freeze/unfreeze sequence In-Reply-To: <0763cb5a-5598-69e3-e5ac-765989aab5b1@acm.org> References: <20190409090828.16282-1-bob.liu@oracle.com> <0763cb5a-5598-69e3-e5ac-765989aab5b1@acm.org> Message-ID: <84cf04edf8f3f3b87b78383a1837aff3@suse.de> X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-04-13 05:42, Bart Van Assche wrote: > On 4/9/19 2:08 AM, Bob Liu wrote: >> void blk_freeze_queue_start(struct request_queue *q) >> { >> - int freeze_depth; >> - >> - freeze_depth = atomic_inc_return(&q->mq_freeze_depth); >> - if (freeze_depth == 1) { >> + mutex_lock(&q->mq_freeze_lock); >> + if (++q->mq_freeze_depth == 1) { >> percpu_ref_kill(&q->q_usage_counter); >> + mutex_unlock(&q->mq_freeze_lock); >> if (queue_is_mq(q)) >> blk_mq_run_hw_queues(q, false); >> + } else { >> + mutex_unlock(&q->mq_freeze_lock); >> } >> } > Have you considered to move the mutex_unlock() call to the end of the > function > such that there is only one mutex_unlock() call instead of two? In case > you > would be worried about holding the mutex around the code that runs the > queue, > how about changing the blk_mq_run_hw_queues() call such that the queues > are > run async? Hi Bart, The only purpose of 'mq_freeze_lock' is to avoid race between mq_freeze_depth variable and the following usage of q_usage_counter percpu ref. I admit that my original comment is quite unclear, but locked section should be as short as possible, so returning to your question: better to have two unlock calls instead of expanding locked critical section. Unfortunately I do not have hardware to play again with the issue, but I see there is a nice candidate for a quick reproduction: null_blk queues with shared tags. Having several queues with shared tags and a script, which powers on/off (I mean 'power' entry of configfs of the null_blk) different null devices from different cpus it is quite possible to trigger the issue. Random short msdelay() in correct places can help to increase probability to hit the issue quite fast. But Bob, what is the backtrace of the issue you hit? What is the device? Conditions to reproduce the issue are quite specific and frankly I did not find any "naked" (without any locks) calls of blk_mq_freeze/unfreeze sequence, the only candidate which I found, seems, null_blk (not 100% sure, but worth to try). -- Roman