Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1446559rwb; Fri, 23 Sep 2022 12:48:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7WblSZsiPljS+1xu8CJmy01qIUP7r9CCEf0Ohf3sN9IFa+Cr8i0NYU9SZ05YYaQ3fHXKML X-Received: by 2002:a17:906:9b86:b0:73d:72cf:72af with SMTP id dd6-20020a1709069b8600b0073d72cf72afmr8349437ejc.440.1663962507997; Fri, 23 Sep 2022 12:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663962507; cv=none; d=google.com; s=arc-20160816; b=UkyzYkZ8NRkMnQfmZ08Y7+tZmVC4ysXvmr+Qt78FYcV1qS+GAyJpkSrAfzNwbg02qY ARy66akTOS56Kfkv3J3UNuZHmP1IUP9PV+3UKXEfblQYrqNhq1nSloKGzuYst6uFW5Ti AtiPprscfD8VsYf99IpmePzbHeHeDfM+9J3h1dkNaZxDxLF4MjZECpUNjbgXwIoMBmXo vhIw/pFxFk7AcABabsH9OYgLco+MfoqnsMgMpvGrFG3WVLK9AdOstN1clTM9CT+AxIIz heumX+hrUmB2yBlbILiUnnxb3tlhgG1kTUdgqAZhZMI/4kpg0zyEVjeSsmuL2XLCYm0H m/kA== 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=mQok+YSAvTdmEH+vQqcxRt54JoVLs0wtk+Pw0bYS/Bw=; b=Wh1W0jN3thOLZwi29QxCf+/oKwdLrj5LUGWbEtj06iAPoWa1SvrCYfs4Vu7s7Bohyo r6qTMtZG7PwXi6OhhQPdWPFk9uYHcjvO/bPByAWSQVV1Ad5gGacgWa8FnQTRw1qKBPX7 WvKcsVmgJKr9SEhEurkqDvCJaB8fKS1pBT7aw1DVq4zy/6PFw83qSQJZnKnhMYaqpItm XGP9IZJXAGjoDUSQCJXwRMEfwn/ndZS8+W+prKRj+9EfVYT0XnzICI3YZa73EMoPt6g/ ZpFFgDsNhLswzKNnFES7kwYImGcaFQiyRtNOKfaKQCFKHSUsiz5FJOkhpgSxHEEJWjNv XYvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mLJi8NGQ; 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 y17-20020a056402271100b0044e80aabceasi10034771edd.372.2022.09.23.12.48.02; Fri, 23 Sep 2022 12:48:27 -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=mLJi8NGQ; 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 S232228AbiIWTH1 (ORCPT + 99 others); Fri, 23 Sep 2022 15:07:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiIWTHY (ORCPT ); Fri, 23 Sep 2022 15:07:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94E23124C1C; Fri, 23 Sep 2022 12:07:23 -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 19DE86114C; Fri, 23 Sep 2022 19:07:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0662C433D6; Fri, 23 Sep 2022 19:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663960042; bh=7H8VpOjF/PEX4j/BXyfxiFyc4XiKNHwJzvMMej31jZo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mLJi8NGQanMCvftUQWlJfbezIx1RXhCBo4SDMmstuxEfaSe0WcUnZswts/34rZjDe zmtTVPtr8/uhzhqfBvwxuc2uvLI0E/FWfJRWuLcnggK1in+YUM/CPEUAkQV0nb2lph K31FuPDzG98rboZ6Gndt1Dxr/sGNupEZInWBn7H0NjtmiPk3F04VhEnJpI6XXwR9mz W+fJPFgmPVfOuPVHtUKjqLVA2xlcI7U/fl4gosyfHhrmPX7Q/N9EBKXqlDYgF8mfKn PvfbPtjj28UPPOs+OKdiw9gKa8TrxhS4ctxKuxLJbjFH1iwUTuJZzU2qaDrF4AaEug mi2s552EfTMbA== Date: Fri, 23 Sep 2022 13:07:19 -0600 From: Keith Busch To: Hugh Dickins Cc: Jan Kara , Jens Axboe , Yu Kuai , Liu Song , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH next] sbitmap: fix lockup while swapping Message-ID: References: <20220921164012.s7lvklp2qk6occcg@quack3> <20220923144303.fywkmgnkg6eken4x@quack3> 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 Does the following fix the observation? Rational being that there's no reason to spin on the current wait state that is already under handling; let subsequent clearings proceed to the next inevitable wait state immediately. --- diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 624fa7f118d1..47bf7882210b 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -634,6 +634,13 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr) *nr -= sub; + /* + * Increase wake_index before updating wait_cnt, otherwise concurrent + * callers can see valid wait_cnt in old waitqueue, which can cause + * invalid wakeup on the old waitqueue. + */ + sbq_index_atomic_inc(&sbq->wake_index); + /* * When wait_cnt == 0, we have to be particularly careful as we are * responsible to reset wait_cnt regardless whether we've actually @@ -660,13 +667,6 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr) * of atomic_set(). */ smp_mb__before_atomic(); - - /* - * Increase wake_index before updating wait_cnt, otherwise concurrent - * callers can see valid wait_cnt in old waitqueue, which can cause - * invalid wakeup on the old waitqueue. - */ - sbq_index_atomic_inc(&sbq->wake_index); atomic_set(&ws->wait_cnt, wake_batch); return ret || *nr; --