Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3086534rwb; Mon, 19 Sep 2022 14:56:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yq1fqc3ZC7UKbQRgNdAyV/xuQFMdAtQ/E7v/wo3sLsLumnkgvjMo2hncWns2IqfHyG/xZ X-Received: by 2002:aa7:df87:0:b0:44e:2851:7e8d with SMTP id b7-20020aa7df87000000b0044e28517e8dmr17589347edy.106.1663624589034; Mon, 19 Sep 2022 14:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663624589; cv=none; d=google.com; s=arc-20160816; b=kSRzxQ8ukWOuvRBojQTaXFk+Q5x2cAPe4J4O9igvOiYnAohcCkAH0FyDcbZfjtK+NO tZt41vhTd1tuN0VolhwUF7Th7kbcnMHWAQ3VSHNOE3MH4cG1vYBXB8oyXeb/h2MD0B7J NGobKzoxZsfkPPsABkcQdJhPrPtfMIJFt1wZuIdlkbKgtn2MKLF1+tepJtvHlQFfXJwU o4X6MLiVi4njjlugjisY3Cgs/jZkVuxai3QXqnsPWREVdSVccRmSOHN0+Oh16E7ZfvOs W8AljJWKOBYF9/v9vFXvyT6NFWfda2NrAwMxX5629+1HWfq2kHQxhAdD+p01Rcj1KlbF Veig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gjTIDoDVidcrSwKtpbC+VVSc/JyHxsNnL7N/PM0OK0M=; b=WF2h2nq0UksWkINzPd8aksYE6yO+fniE8lc5yK+naK7avTLDLTUv/5FyuLLUnnPiti W+xrFwUvyFcD8jZ5kdzBxd16ML7DDfjRLBT+4dynv4O4pP1tZtFTj3W1x1QhNL4s+/DB FhumQ4jEa4r8v8/vaXvgyUPiiV+Puvg7/uL7WsbUXUgB0yRlzyqe7ZXB2qP9/fDKOZz/ mx8eEaJTpIw4KrX9uSoyQRAquAt9qJaOU/b7OolV284CaGy6PaPoEFZOiDeKHNC7jcJp GcNIGVV1AjgBCLwqR5IIJCUOkflR9EcuBb5YA7THojOC/FZnv1jmDBOY5LiDTZWosnqC 6aVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gnu9OWbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa42-20020a1709076d2a00b0077c2e5ea05dsi21799850ejc.267.2022.09.19.14.56.03; Mon, 19 Sep 2022 14:56:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gnu9OWbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229836AbiISVWW (ORCPT + 99 others); Mon, 19 Sep 2022 17:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiISVWV (ORCPT ); Mon, 19 Sep 2022 17:22:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4A7447B95; Mon, 19 Sep 2022 14:22:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5FFFA611DB; Mon, 19 Sep 2022 21:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39CBAC433C1; Mon, 19 Sep 2022 21:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663622539; bh=fbxWbYcpv+Xlpl8GPsmdhWofyWA7VUTSh+HjIQ+CX1c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Gnu9OWbfuDKxIm0HYMi2CpJTSuEA1gnX80dzv6AReiFMamFnchNTCwRHsh62BvkCT MgClcADZHWmggQoTEmKSnZWXtn3bb6St88FtjRHdVlhmwmur9uwylRLLnPuu0C8rb8 ZUlL7MkZdKRVWHiMQZr1piFBIQbAATMwb9VR65QnpoPHGx1AW0VxzP2wXYIIvso+qA 0Vk6kphseY76zKW97nlEjQ9335Fm57LcAeA7PNhSaMJ2GO8TaZpBmU5+CvKs9nK7p3 wbtY3or7u4L5tJzpL7g16psODevZCqdiV09HeuspaVB/+Hg6QEgC+4AHsngBA57qpd Tf0mXxjdgM5eg== Date: Mon, 19 Sep 2022 15:22:16 -0600 From: Keith Busch To: Hugh Dickins Cc: Jens Axboe , Yu Kuai , Jan Kara , Liu Song , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH next] sbitmap: fix lockup while swapping Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 18, 2022 at 02:10:51PM -0700, Hugh Dickins wrote: > I have almost no grasp of all the possible sbitmap races, and their > consequences: but using the same !waitqueue_active() check as used > elsewhere, fixes the lockup and shows no adverse consequence for me. > Fixes: 4acb83417cad ("sbitmap: fix batched wait_cnt accounting") > Signed-off-by: Hugh Dickins > --- > > lib/sbitmap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > --- a/lib/sbitmap.c > +++ b/lib/sbitmap.c > @@ -620,7 +620,7 @@ static bool __sbq_wake_up(struct sbitmap > * function again to wakeup a new batch on a different 'ws'. > */ > if (cur == 0) > - return true; > + return !waitqueue_active(&ws->wait); If it's 0, that is supposed to mean another thread is about to make it not zero as well as increment the wakestate index. That should be happening after patch 48c033314f37 was included, at least. Prior to 4acb83417cad, the code would also return 'true' if the count was already zero, and this batched code wasn't supposed to behave any different in that condition. Anyway, I don't think the waitqueue_active criteria of the current waitstate is correct either. The next waitstate may have waiters too, so we still may need to account for this batch's count in order to wake them.