Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1586129rwb; Fri, 23 Sep 2022 15:16:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4l8ILctmzJ4sC1yze6yk5Kh+LZHiQk1auQDpxU2n9XZx/Zhvtq+nHCTLqaQAQxf9goU5S4 X-Received: by 2002:a63:f050:0:b0:439:db24:8b07 with SMTP id s16-20020a63f050000000b00439db248b07mr9125038pgj.60.1663971401171; Fri, 23 Sep 2022 15:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663971401; cv=none; d=google.com; s=arc-20160816; b=rFDdxuFJASubDZxwL2M7S+9s41DsOfPeoXhbGKHeIGrTi1jVy9TEJYPZ7uecBTQzzf iCOo9hWkb414hxKwBRQMjtE8erddAd3Zzpf8b6UvJ6855l3ECMfPnf6nyo1AovY65je/ viN4plQ5DloCW4JU12iC6DKyJ/wZePSIQcOL2AXRTE6hOtFz0PhvMIbuK5xaOid6LjzI i68QQkQ7CNSbqzAlykkFpBMGZvLWsq93naSjeoMs2SKEfxI+oYogohhz9FoDBkBAq9YX wLjgZoFWC6R7PAOBDlywuwRSty2O0JDySLuy1F4lN10qod6o4Kl9w7bThJOJSXxU2zwo tqOQ== 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=ZGsHfCz0vcFr7tUGQ1YmYn/WTXvbxQ/j0IzGjWxyxBw=; b=grb5x2j0WkEySWdPHGZ1GQgfTdWGVraF3EfmWTdEwAMYD7DFjb8qF21ztX7G/2X8WH Peo6bWsMHYa6UjYr52SGrR5CFStrVy6jEYqDRuxWNtPOzhZSpr4/Lvesmni3vltVlw2i K+0eBhMKVvvEfDCJKJ8/nomHtdwAj5oQwXvfUMlllgIMwQawSU4cVlZC/lDbt75m2yol dqO5Gq1w68ydFnESKoTQ0DkwNmAu8AOUiPfTQhF6NqqzvtZIM+EjsejTABiDhnIeYbRI QJMsMYe4cpueixi5CAMGOXhvadnUEoP70ioo56AJW3uXCabHmK/zgvdpnGid1zXDb5OB k0YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=I0aBEbvg; 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 68-20020a630547000000b0043934d9399fsi10332948pgf.159.2022.09.23.15.16.26; Fri, 23 Sep 2022 15:16:41 -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=I0aBEbvg; 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 S232399AbiIWV35 (ORCPT + 99 others); Fri, 23 Sep 2022 17:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231991AbiIWV3u (ORCPT ); Fri, 23 Sep 2022 17:29:50 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A902ED65 for ; Fri, 23 Sep 2022 14:29:48 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id w39-20020a4a97aa000000b0044dfa1ddc67so244175ooi.6 for ; Fri, 23 Sep 2022 14:29:48 -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; bh=ZGsHfCz0vcFr7tUGQ1YmYn/WTXvbxQ/j0IzGjWxyxBw=; b=I0aBEbvgjLil0ywPPi6Ss08ZtLCUNNMs3cN1rzPH1Z5uZIXD54xYdyBRbtSdAIIQsX vaZouOQ9T1QumiTC3NDHrTvWjJMWeEWpH+OnpplHEVevfIWJdQnjFz6l8RrSgKjgA5mb l0jTr0Vd1DfuBJzhajfHxNR1bKUs6Lq/hXbPH/tHyr5pZ+XiHJPFmB6BKXmd9uAPkSTt VCo/iqiNzCTeNGPd/IQrfCbzegNKym5AqfjjqBUiYKgKnlZ9cgFP2Zn+QP/F7hnQGX1h 38TRWe0xZvw/58iiGuVR+gNj/Pa4pzua3bT0zChkr7ZtNJHk2zlOQz2lZnDEYUnNh0+Z GthQ== 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; bh=ZGsHfCz0vcFr7tUGQ1YmYn/WTXvbxQ/j0IzGjWxyxBw=; b=dv463Iv0qIV4diL9ShuT1O9kScTqrSICGA35DVC15WDfbYNLqP2t/Ah59BK68f3678 qheavEXxWJADNuFtychkJzYVUYwMx6sDle/BnILKXu+tr3aUgjyIqoIkZdJVgEa5ctpg XKGoVhKqvShdeYH3F+nnXlEh1ZxtyQ8uHsweI62b15OEeMrpM4sPwiI3lZf9EePAg7vL B8Zxuu4EnC6FJingkvuUjZCmnPcsAirqeRioCgk+1iZs0nUbtMjf+rRfiySANxOTXAer HABh2Oe/uJseRQ4TY6lUQ1LCQ8w4lhvUi0sLoaXpe9/IqmeGSp93zx23qBIo1XBgrd3H 7dvg== X-Gm-Message-State: ACrzQf09h7sXSkEQ63iBraHfg/fiQAiHo//2mW45n17wmkzG3uK26WM4 MHPxtDzUzu/iDVFbpk1Sez6kdLsL3j7nDA== X-Received: by 2002:a05:6820:1505:b0:476:994:186e with SMTP id ay5-20020a056820150500b004760994186emr4276566oob.28.1663968587374; Fri, 23 Sep 2022 14:29:47 -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 t23-20020a056870609700b0012c21a64a76sm5230776oae.24.2022.09.23.14.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 14:29:46 -0700 (PDT) Date: Fri, 23 Sep 2022 14:29:37 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Keith Busch cc: Hugh Dickins , 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 In-Reply-To: Message-ID: <391b1763-7146-857-e3b6-dc2a8e797162@google.com> References: <20220921164012.s7lvklp2qk6occcg@quack3> <20220923144303.fywkmgnkg6eken4x@quack3> 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,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Fri, 23 Sep 2022, Keith Busch wrote: > 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. It's running fine without lockup so far; but doesn't this change merely narrow the window? If this is interrupted in between atomic_try_cmpxchg() setting wait_cnt to 0 and sbq_index_atomic_inc() advancing wake_index, don't we run the same risk as before, of sbitmap_queue_wake_up() from the interrupt handler getting stuck on that wait_cnt 0? > > --- > 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; > --