Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1348018lqj; Mon, 3 Jun 2024 20:25:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHauzH5AIa6EW8fp4FYauBXoxFQhyhdbWWA+Jzw8jn3x/pL4X/rqGkjifKhYpeT8spTzuK/W+UsqDthSBXTs558CmRQ2yZRY1yTM+DjA== X-Google-Smtp-Source: AGHT+IE43rqmcZuTjgEmHKE8I56f7qBGwBySCtQ2hmsFqwcxAg9ei0FNlC2HL8aZWyflk3yTgIc+ X-Received: by 2002:a05:6808:4298:b0:3d1:d287:191b with SMTP id 5614622812f47-3d1e34a0603mr10337611b6e.26.1717471555927; Mon, 03 Jun 2024 20:25:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717471555; cv=pass; d=google.com; s=arc-20160816; b=ZDwZpTqXUMd0ZNzyvNGn0652R14HD76kfb3lTSl0LVOueGMHTX0ep3K3NUDuS6DLWQ VhwF9ohijzygJGnazzSzdCvhUmXjMPTExHkDXr0OIGh6QcpknlNplnXSKMLSgf5n+oES roWK7mM4/sE8yo14O30be6/6LOvn2NaGwhy/IaM+Ss6T17qeH0aOahC4ztwgJsx1BkOi U9iAnWgAswiWByTDtrHctXZ9zeDvYk9cg+J25YGVHqfQR1v4/Ey58jJEyhCJTCukbL68 GGDtOYMdT/GGcsno/aLRRk8z32IaqnClfStwLoLVZBU5jgfOFbYfe/1u9oks+HLzw8d6 NTpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=zEUAhiXSNeBDF6NeU6DEm0KF3UmpeqhO8TfskOx9nww=; fh=008kT9pFp9XBdDNZtGi7sdWZgoF0lpVK6tXk08e6k3A=; b=Yw/ybObzY/cVyVCXBrVUuvi02QQbn6zAF/NTx1Tbvqs0Az9TESYpY3pSUgXl66E7eq HK3wWbJsQ5+MibMrBu1KqHNFGCXdxkTAxdzN1rlgSzzpHdcDJ2QZjSx9k+HiUBee0vX9 7Z6S7Geu1WEmyx72S1RPSenfbcXmJFAAit4IMF7JschZy4PkkSReNeZ6h6pvjReO1S3x X5wHsCRZHM1FnjR3g6ZoTBz4MQVrPid13Toxxr7mXuDQi9F2ztDgigbTph2miXD7eeel ops8yjrkRnUepxsjEtZWj1eyBzTrS5/aXoaOonBxoM4rcoPqM36CCvOUHySIrmFflW7M 0tyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HT7Kt77O; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-199982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c705daf069si5911187a12.131.2024.06.03.20.25.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 20:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HT7Kt77O; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-199982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CD5D7B25DA9 for ; Tue, 4 Jun 2024 03:25:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14D4013D609; Tue, 4 Jun 2024 03:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HT7Kt77O" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9588913D2AC for ; Tue, 4 Jun 2024 03:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717471543; cv=none; b=RRR8s17qji7jLO3u+oy+zOttJLLtxVIUaAABz+WJ4Wy04mjT8W/ORTsrBKEZZXVj4rPzpmF2c27t1Te/0Fv5PW+V39S0cMIZ1p8sKUh+32gA/nFY7YyllN6Ad5mPNJE7lb7GCK3v2Kf7g2hSNMsYUusEjmylEkTaHHYdAA3o11E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717471543; c=relaxed/simple; bh=NjrI4lHVFyH79QzE/OE3lhpa4QHszBqtLMquvt/lk1A=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=glYAlGo6ZsxrbnVzTsss1OhRZZy5em3vXMNcIqnKs7EAkNfdGWk3iTxYFlG9GOR4m9398fVPCDZ1so/RhSExTQ2X8XbzZwy70GtSoTVhI1RxuSDrsp9caJKLj5grOpaHMrgBMkc4jlEl0eVOvx9mlFfOAtimCeJ/K/ZIyX2dTsk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HT7Kt77O; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717471540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zEUAhiXSNeBDF6NeU6DEm0KF3UmpeqhO8TfskOx9nww=; b=HT7Kt77Ow/gG5TgOj7p/yQX+HZNoJYUIyAoOADtWU58vPKFB23BHw3Z6nNnEZJcqbjzZPj sY4xB+9wpy59VKM62E734uY2JcbcevhSMgjkYJ6gj3hyGOMlyMb+E/yXL5qZnyzSR14KAJ az1Tnwi3tpaYD0Ngi+bYlLIKbdE9tD4= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-bIukshHwPceXDUwBMxyEtw-1; Mon, 03 Jun 2024 23:25:36 -0400 X-MC-Unique: bIukshHwPceXDUwBMxyEtw-1 Received: by mail-ua1-f69.google.com with SMTP id a1e0cc1a2514c-80ad788d321so120978241.1 for ; Mon, 03 Jun 2024 20:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717471535; x=1718076335; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zEUAhiXSNeBDF6NeU6DEm0KF3UmpeqhO8TfskOx9nww=; b=TRiO2La8KYIJsdJ2JADOwTskhGU5vZJMS06d/N7+auk2vDVDdr3ZXDRZz1r4LKanF4 K1xQpHuyqy+S60yt9JAJijAvzyuv4CfehQdLr4k/9f5oKnmjBT7jGKRKkLO2yv8wuL7y 3Y33zCiVOeJg/qdJqCznNNES+2sD1J1LejWboIRXrpFUsSQYIAPk2ElYvNWU2PNi64UK o5aMYMB8cEY6tcLf7rNZcgWrD2zbs5V9AmcaymV7JN+MjTWNRzPaOOz8XQW4h2hf1Inz ao7zWjoCWQVrKzi0rc1RX+uw0t0sVPbcEOxGTDPnOADp1r3EulTXfvESxzVBLNDmhUdx HRkw== X-Forwarded-Encrypted: i=1; AJvYcCXwhwmenjWmvynAH876Auzq4x07rYQNfLjInLh5o6hoK10Dv09thbMM4vzfPXZPIpQLfrGCnkz4o+QAxRgfXiCujj7nPtQ+hj8XSevy X-Gm-Message-State: AOJu0YxfH8FXHM+/EnuvaOl7Wxfmw8EW1X71Geue+x3Kp+fxT1Lzy3sc Jr5FsdRtHSvusdnEw54xMCoJOrENyEwdFCNQkRjfaBEmANy9UmbfDfxYEi1pCdl5TkU+gTXnvzP R9TASfomUDUC3ZiUKAQ6C+6PXoX7egJK4nORLQzhUMOzNIQN8dF1ZIneXOt0IcRYcZIlYgjp/sm +OedZ/vUObX1Qmoh6OR40hlQi30oHLsfmKrq5f X-Received: by 2002:a05:6102:2413:b0:47e:d83:3baa with SMTP id ada2fe7eead31-48bc20d61c5mr9946003137.1.1717471535495; Mon, 03 Jun 2024 20:25:35 -0700 (PDT) X-Received: by 2002:a05:6102:2413:b0:47e:d83:3baa with SMTP id ada2fe7eead31-48bc20d61c5mr9945993137.1.1717471535155; Mon, 03 Jun 2024 20:25:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240604031124.2261-1-yang.yang@vivo.com> In-Reply-To: <20240604031124.2261-1-yang.yang@vivo.com> From: Ming Lei Date: Tue, 4 Jun 2024 11:25:24 +0800 Message-ID: Subject: Re: [PATCH v2] sbitmap: fix io hung due to race on sbitmap_word::cleared To: Yang Yang Cc: Jens Axboe , Andrew Morton , Pavel Begunkov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Ming Lei Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 4, 2024 at 11:12=E2=80=AFAM Yang Yang wrot= e: > > Configuration for sbq: > depth=3D64, wake_batch=3D6, shift=3D6, map_nr=3D1 > > 1. There are 64 requests in progress: > map->word =3D 0xFFFFFFFFFFFFFFFF > 2. After all the 64 requests complete, and no more requests come: > map->word =3D 0xFFFFFFFFFFFFFFFF, map->cleared =3D 0xFFFFFFFFFFFFFFFF > 3. Now two tasks try to allocate requests: > T1: T2: > __blk_mq_get_tag . > __sbitmap_queue_get . > sbitmap_get . > sbitmap_find_bit . > sbitmap_find_bit_in_word . > __sbitmap_get_word -> nr=3D-1 __blk_mq_get_tag > sbitmap_deferred_clear __sbitmap_queue_get > /* map->cleared=3D0xFFFFFFFFFFFFFFFF */ sbitmap_find_bit > if (!READ_ONCE(map->cleared)) sbitmap_find_bit_in_word > return false; __sbitmap_get_word -> nr=3D-1 > mask =3D xchg(&map->cleared, 0) sbitmap_deferred_clear > atomic_long_andnot() /* map->cleared=3D0 */ > if (!(map->cleared)) > return false; > /* > * map->cleared is cleared by T1 > * T2 fail to acquire the tag > */ > > 4. T2 is the sole tag waiter. When T1 puts the tag, T2 cannot be woken > up due to the wake_batch being set at 6. If no more requests come, T1 > will wait here indefinitely. > > To fix this issue, simply revert commit 661d4f55a794 ("sbitmap: > remove swap_lock"), which causes this issue. I'd suggest to add the following words in commit log: Check on ->cleared and update on both ->cleared and ->word need to be done atomically, and using spinlock could be the simplest solution. Otherwise, the patch looks fine for me. Thanks,