Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1307966rwi; Wed, 19 Oct 2022 09:03:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mKq8RMhAxp8awhOUYxHmTFoBc/Rjpb3A7YNPsRf4q/PLa4M80O4ZScoFF0KTWxQVCIc63 X-Received: by 2002:a17:907:3f90:b0:78d:afad:2a78 with SMTP id hr16-20020a1709073f9000b0078dafad2a78mr7541718ejc.68.1666195431894; Wed, 19 Oct 2022 09:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666195431; cv=none; d=google.com; s=arc-20160816; b=HDAQ2Wr6yeAEOwPf3W53O/2KiYNh00+7Kqo+oFzRE7u7gS2qyNptnZfIZ5TReJ3rIq GZeeCHb6ptp9TAchT/x03naCZF5tPUt40954bIYIJWjfveSnfxQAyCTNVmHCv9bo70ba Brzkk/xTVrCMxRlOt/cWyRMvP2k3lB/ayeEuRBmBJ1tzJWk6eI90cuchuMwU1OmsSXRd fBxFg+Im3YMwiP8RWKPSCyHlvT+/lWFo7CkPO09p+jdz5hT3AFRjF9Yrxn6KAXv4/0vA TNS4c4Z0I4XqC5myXBmYez5s3cX2xEz1jkUWUPQeA5my9OF5wq97OF8jV2yFn4eS6t2c xJcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=a50Sl6Y7oXbp/PbRU6wwFOKAQcgLlChD+njiyUUoAVM=; b=U8LcdlaV36ooKHD2ONA1OwkqTefFGgR7yWUMC6EKo7Sx3Xmjw6MQANWUf7S/XdzvOB Z8LrLUXXLxsf7enZt5Rfp27o2KMPQOBBgDgUffiOcI9YGeHprwdjxpxpnOPtU2CiXxP2 DDM5qmpA2VEZT/1GGitbL4HyzQsHizySsa5f6KsbtddwIQf7X6dJiRioXZkQZmya5bGc 0J0REZQjLIa74eLsJE+hNQTGCioJQlfCYeKYPLt60K7SGlD8wgM0NGeGuII+o6Tg3P6k cjfVO9yv240d0KO5WaNZa0Iug4BVCMNCkv4GdlIyyHvuswOeb9kDRJimhr6RtsAR2Eyt 0K6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="h70JsGS/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z102-20020a509e6f000000b0045cd7614e59si14029661ede.451.2022.10.19.09.02.55; Wed, 19 Oct 2022 09:03:51 -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=@google.com header.s=20210112 header.b="h70JsGS/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbiJSPSF (ORCPT + 99 others); Wed, 19 Oct 2022 11:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232255AbiJSPRn (ORCPT ); Wed, 19 Oct 2022 11:17:43 -0400 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F3961D0657 for ; Wed, 19 Oct 2022 08:10:31 -0700 (PDT) Received: by mail-ot1-f53.google.com with SMTP id r13-20020a056830418d00b0065601df69c0so9671189otu.7 for ; Wed, 19 Oct 2022 08:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=a50Sl6Y7oXbp/PbRU6wwFOKAQcgLlChD+njiyUUoAVM=; b=h70JsGS/Zoz8vPmb1ANnoBkMX44g+sxyVOW52S1JD2OZF2n48IxQu5ncLP3M8qRf/h xDBej6UyND7l7rJPQ8i9fjPeQEpcHRKWWQE1+bH9XElFOLZ5VatiL4lNG2FwKSNdP560 UYsXdOZbEIAM94O26kGuqZxoT4hZVPt8WjSVB6BF48sajh5wk3DWAEfEhO1zWv8OgvSG x5K1KidB/krzoG80jSGgoN5JaW9/bc4oE5mUIzLWa+300n71CLDvV3Z0ji7UmGh6gGEQ hRtYYmCzt/S+xdVfTpf5t5lqDUw4nzl8f7GrpR1bpF3IjVcv6ULWT13ehDh+rL+2OLGA IeGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a50Sl6Y7oXbp/PbRU6wwFOKAQcgLlChD+njiyUUoAVM=; b=k6UD1V0zKF8294UaOKI+JbTzN44QWt3IvdzEQKnM1+R5BH6Jot6tyBjnZZ0icb0uy5 MLjemaqXbRZD6Xh5Za21QeQopa8ObNyXNk2h2hqh8XOEeHvLwRA3GbkDYiSyH/yJRRSV aczPwY5vPx3Ymx+5ZX/1w5CBk99QWSIMvnyOTyDFj01v+VkUaNpqrNoqnknqC3rexj/K 02bIVHK6+Xfuwlm7R12FzeNOUGJ41x5fmc3qSIm4xCqClaY68mnbSY6FZVt6nTDUKzWU VryH5jZkO4ODDUrdZYv4s1zcwe0WywxUQaIPucjiAZ8yP6VSC5tC02tJyG1E8A4tLI7N JHOw== X-Gm-Message-State: ACrzQf2rwPZkWrJAYcCGfkUQsyyatkiDyeTwJepMECWyli0pFZn7cypz J4NtTI9U/+/6srgFU1luEw4knw== X-Received: by 2002:a05:6830:3703:b0:65f:c2ff:c526 with SMTP id bl3-20020a056830370300b0065fc2ffc526mr4166999otb.302.1666192109330; Wed, 19 Oct 2022 08:08:29 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w15-20020a9d70cf000000b00661abb66319sm7067181otj.37.2022.10.19.08.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 08:08:29 -0700 (PDT) Date: Wed, 19 Oct 2022 08:08:27 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Greg Kroah-Hartman cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Keith Busch , Jan Kara , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: Re: [PATCH 6.0 517/862] sbitmap: Avoid leaving waitqueue in invalid state in __sbq_wake_up() In-Reply-To: <20221019083312.840347737@linuxfoundation.org> Message-ID: <9edd6656-e1af-e1fa-123a-115c3ba7b1ae@google.com> References: <20221019083249.951566199@linuxfoundation.org> <20221019083312.840347737@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 Wed, 19 Oct 2022, Greg Kroah-Hartman wrote: > From: Jan Kara > > [ Upstream commit 48c033314f372478548203c583529f53080fd078 ] > > When __sbq_wake_up() decrements wait_cnt to 0 but races with someone > else waking the waiter on the waitqueue (so the waitqueue becomes > empty), it exits without reseting wait_cnt to wake_batch number. Once > wait_cnt is 0, nobody will ever reset the wait_cnt or wake the new > waiters resulting in possible deadlocks or busyloops. Fix the problem by > making sure we reset wait_cnt even if we didn't wake up anybody in the > end. > > Fixes: 040b83fcecfb ("sbitmap: fix possible io hung due to lost wakeup") > Reported-by: Keith Busch > Signed-off-by: Jan Kara > Link: https://lore.kernel.org/r/20220908130937.2795-1-jack@suse.cz > Signed-off-by: Jens Axboe > Signed-off-by: Sasha Levin I have no authority on linux-block, but I'll say NAK to this one (and 479/862), and let Jens and Jan overrule me if they disagree. This was another of several 6.1-rc1 commits which had given me lost wakeups never suffered before; was not tagged Cc stable; and (unless I've missed it on lore) never had AUTOSEL posted to linux-block or linux-kernel. Hugh > --- > lib/sbitmap.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) > > diff --git a/lib/sbitmap.c b/lib/sbitmap.c > index 1f31147872e6..bb1970ad4875 100644 > --- a/lib/sbitmap.c > +++ b/lib/sbitmap.c > @@ -605,6 +605,7 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq) > struct sbq_wait_state *ws; > unsigned int wake_batch; > int wait_cnt; > + bool ret; > > ws = sbq_wake_ptr(sbq); > if (!ws) > @@ -615,12 +616,23 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq) > * For concurrent callers of this, callers should call this function > * again to wakeup a new batch on a different 'ws'. > */ > - if (wait_cnt < 0 || !waitqueue_active(&ws->wait)) > + if (wait_cnt < 0) > return true; > > + /* > + * If we decremented queue without waiters, retry to avoid lost > + * wakeups. > + */ > if (wait_cnt > 0) > - return false; > + return !waitqueue_active(&ws->wait); > > + /* > + * When wait_cnt == 0, we have to be particularly careful as we are > + * responsible to reset wait_cnt regardless whether we've actually > + * woken up anybody. But in case we didn't wakeup anybody, we still > + * need to retry. > + */ > + ret = !waitqueue_active(&ws->wait); > wake_batch = READ_ONCE(sbq->wake_batch); > > /* > @@ -649,7 +661,7 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq) > sbq_index_atomic_inc(&sbq->wake_index); > atomic_set(&ws->wait_cnt, wake_batch); > > - return false; > + return ret; > } > > void sbitmap_queue_wake_up(struct sbitmap_queue *sbq) > -- > 2.35.1 > > > >