From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60843C33C9E for ; Sat, 11 Jan 2020 10:32:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3574920678 for ; Sat, 11 Jan 2020 10:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738752; bh=jpqiTu4Vr8eMbp5uH9Vomf7i+fxQLjfnRDi+IJs+3zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NwasGDsuEMXKYU0FxLa/BEgTuSP9dx7oTjH8iNwHgvRi/NdPlwL/vwsreuNmwiwHM Jx2xoHHZRafLVsiPorr8Nj+JdO1QmDE/+S5XWIoDNQ8TnCXzoNapR4FhvKouMmmVL5 /5spKtxj1AbDCYg1fc0SJqKAoZ1bQdVeiSlLc7LI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731521AbgAKKcb (ORCPT ); Sat, 11 Jan 2020 05:32:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:45574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731348AbgAKKc2 (ORCPT ); Sat, 11 Jan 2020 05:32:28 -0500 Received: from localhost (unknown [62.119.166.9]) (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 2A4A920880; Sat, 11 Jan 2020 10:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738748; bh=jpqiTu4Vr8eMbp5uH9Vomf7i+fxQLjfnRDi+IJs+3zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i8TYDmvDCeapAIHF3mJp2r8mG+MeBxZ0Za1cZG2qrIcqE4fXEiBQbRzlbKHIfHCit 9SlJUGiIE1si+VdpSdDAzFvp257mCCUvVXP+4LmQ/v5pvOMk4OvuzfiEzZHsUk/JN4 8U749555qqBUKrNBYxsP93CUnJq50DCjTA0DXnTo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omar Sandoval , David Jeffery , John Pittman , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 130/165] sbitmap: only queue kybers wait callback if not already active Date: Sat, 11 Jan 2020 10:50:49 +0100 Message-Id: <20200111094935.853087757@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Jeffery [ Upstream commit df034c93f15ee71df231ff9fe311d27ff08a2a52 ] Under heavy loads where the kyber I/O scheduler hits the token limits for its scheduling domains, kyber can become stuck. When active requests complete, kyber may not be woken up leaving the I/O requests in kyber stuck. This stuck state is due to a race condition with kyber and the sbitmap functions it uses to run a callback when enough requests have completed. The running of a sbt_wait callback can race with the attempt to insert the sbt_wait. Since sbitmap_del_wait_queue removes the sbt_wait from the list first then sets the sbq field to NULL, kyber can see the item as not on a list but the call to sbitmap_add_wait_queue will see sbq as non-NULL. This results in the sbt_wait being inserted onto the wait list but ws_active doesn't get incremented. So the sbitmap queue does not know there is a waiter on a wait list. Since sbitmap doesn't think there is a waiter, kyber may never be informed that there are domain tokens available and the I/O never advances. With the sbt_wait on a wait list, kyber believes it has an active waiter so cannot insert a new waiter when reaching the domain's full state. This race can be fixed by only adding the sbt_wait to the queue if the sbq field is NULL. If sbq is not NULL, there is already an action active which will trigger the re-running of kyber. Let it run and add the sbt_wait to the wait list if still needing to wait. Reviewed-by: Omar Sandoval Signed-off-by: David Jeffery Reported-by: John Pittman Tested-by: John Pittman Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- lib/sbitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 969e5400a615..ee3ce1494568 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -667,8 +667,8 @@ void sbitmap_add_wait_queue(struct sbitmap_queue *sbq, if (!sbq_wait->sbq) { sbq_wait->sbq = sbq; atomic_inc(&sbq->ws_active); + add_wait_queue(&ws->wait, &sbq_wait->wait); } - add_wait_queue(&ws->wait, &sbq_wait->wait); } EXPORT_SYMBOL_GPL(sbitmap_add_wait_queue); -- 2.20.1