Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1019014lqt; Fri, 7 Jun 2024 06:03:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuEddsol3yxggMbdGRGyfTfdn2r3N7s7O3Gc+F9gas4qQyI13KGBkCo9Z7VXzGLrGHFiPrh4TRxdnz5gI1DQ9L1NP43M4LENB5wg9JNQ== X-Google-Smtp-Source: AGHT+IHa4gr42+ALnKweeD10BzOuCZxORAMYHPd8JtgnBvZrY1cmGCoAlPDNDbVikNoSoumiJNUy X-Received: by 2002:a05:6358:6f9c:b0:19f:19dd:901d with SMTP id e5c5f4694b2df-19f1ff8f480mr298015455d.26.1717765393867; Fri, 07 Jun 2024 06:03:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717765393; cv=pass; d=google.com; s=arc-20160816; b=ExO0rhZJDN8oGC425F1Jcxtm/ceDfD/6kgIoZsfLRTdv4qEDXo3xkzKIBRS6rI6l+Z fzq1zwLddAorgLMInlvW8kq18/4OE9EVF2BfT4dX7vnNIeBkftaZUJ2mtt1g5pU1Z8RD 9FVs2pW6cW6Ii6EL+Ifrj7zLRtepQ590kEP6QcIGQEpiFWboCUyTggUteYrb77b9x9l2 /HpXNPyNwmoqwFAjT+cNpx2vebyf9k3I4PHj3yKxQpEGgRzFuJUDEkCUH3EyjGs8xjB+ Gsfv67rxItyA8FQthJp9mlPWMNN42eBdxcRE25B14OKyFV0EZv2iMhi8OqtWEIMJLHI0 y14Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=fwNu32j4Qgs9o4RZx2A4i2wz9FLKQtp05joxe1btFUA=; fh=mf2M44I3UuFGn0ESayGkcUt1gsLtgJE0TFD+bBFUtYg=; b=pzVOoFsiCPjMGV0p2VgiQgv348wNj0QRyoTF0biOYV9vfTkOmQQ+YyBNay4xG04/lj 4QaFaVugSAt2VpeYLpou+0ECMW3HU6e5j2PwHLjRhBYuvkr/r4i1+S+3l85RH1m8RrVQ yWb1UhNkl/b77Ao+xAmYK2RPsBK6rE5G/1e/1Ki+e/KEJ66IlZBShCHYjQWVLbn9JtL0 lEaPKht+gUY0SQQrrleEepMHSdNF34aEi88RJV0A44TBiCnquuKC0jt91Nug2bh1x6Kd 8ApXCGs9tOt7pJuox2RwOlenjO62QpkvlCsTPjk42b0G5p1Jehc3lddKE3JNlbUHvcEr B9ZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Co5j6d96; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-206105-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206105-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de208317f0si3107419a12.175.2024.06.07.06.03.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 06:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206105-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Co5j6d96; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-206105-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206105-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 214DD28758A for ; Fri, 7 Jun 2024 12:59:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3907C19408D; Fri, 7 Jun 2024 12:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Co5j6d96" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9ED8C18C330; Fri, 7 Jun 2024 12:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717765148; cv=none; b=qgrpI8Cjli93yjxf7pSj3OpXqchTPALH1EvqH0GLlDBNPyZz0e2IAxb9X+rasnBdlHXBvHV1R3djOSqYJtSLzhR9vFXMnL7zhlKHKiUC7Iij2XZxUWcK0uHazRgB6J1yfIx53vAxlUt8YZFww4WFDpDbooOF1Gtov/WKNkq7Pbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717765148; c=relaxed/simple; bh=vjt1+QeSp5Sb/mevIOfvfW6Aev/mE5JAlBBwzVe8frA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=h4Ea+kqRqIu4oep/KvsBXfyxNZ+pwrWeyYG2Cpultwt0VHJYzYLyVm84pJXQQeB2tbfAUzRIQv49yoCzgbKkDw23KE9VUMhceaDk2cMtkuetGUI+nJLldQqzQuzbOSVr8MMYsmxC008eySqUmZf18OxD19olFPiCdOrqhmAcKJc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Co5j6d96; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-57864327f6eso2460604a12.1; Fri, 07 Jun 2024 05:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717765145; x=1718369945; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fwNu32j4Qgs9o4RZx2A4i2wz9FLKQtp05joxe1btFUA=; b=Co5j6d96t47/fcPM5PsIf0vPJelgRLIcDkgwGgqW+tE0M8C0OcR1sM7phA7QSbXPa+ PuhSgwQZKTcnMWEHesMso8IElm+D1nTuwHvsj8vgaAqmZ9/cNpSLwR35avqqT4aOCJrR ZfbT4cBfEd1rw1cH/qyK2ZHfSjZMygTJn2OIK5OK7pSTX9gXGSbjxsaEGiYbiP0D+nJL G662WKWILaPYQQTSqkIVQftYSvVFPiGPFuPFllEihQedSc1aXdH4U5dV/4DyM7K7fjUa 0RdKkRhoP+8QCjn9PSROBWboKwXcNKQSAowhGCxL5FDWDHesj6R1LsNuWpje22hkW1tG 0z0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717765145; x=1718369945; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fwNu32j4Qgs9o4RZx2A4i2wz9FLKQtp05joxe1btFUA=; b=WfmHUb6hNIczdB2arpSpMMV6JvQYMMGgtxv/0FBfjRSiQ88rrv9mS9F9ZqwuL7lONF uJYf4ntiJSB9fv6kCmPu6Mo+H0MRIqAeWXNEm7is3d0RP73rqRnwD7FcwpNihrlqZfCx c11ltShrX5wCy7vwfOKe12H9RuJ4tVTTJcmmbcXp875qje3unMZp4mlE9XpS4RS/ozz+ UsoJNafDn1kNWH+7YA8Od3OC78AeVAkDt2MyGlZ2arw2zSpbEpDV34dHoOyj2yC8WSDy QVBhN4nZMfuMgBialARyX9YKp4DIa6y/96TIvBW6V2vImzyeg3z1KMI8Azex/UdnxQCO jMQw== X-Forwarded-Encrypted: i=1; AJvYcCWYuZRdM2lyuwmqke4dPlBeMrIfHceAX5ZlZJn0ql9GRqnmGzqF4KeqPmQyhgjmAIcgcSUaWdRtS+DjEUPdF5Zz5DfGlya+16jt27xWxIEgFvHkDktXkVx/rULi3//viBqgHNYo6vsyo/s= X-Gm-Message-State: AOJu0YzNutazsNI2ucExzTeXzbbU+3fWUpEz04sD+vtD3cgRtLbL8cLu 8aHnay1/EWMGB111DkAY7FpV45L0iVzUEZdYpdJUauqsp5oAFKJQ X-Received: by 2002:a50:cdc2:0:b0:574:ebf4:f786 with SMTP id 4fb4d7f45d1cf-57c4e3f5be7mr2219873a12.16.1717765144630; Fri, 07 Jun 2024 05:59:04 -0700 (PDT) Received: from [192.168.42.79] ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57aae229712sm2726504a12.81.2024.06.07.05.59.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jun 2024 05:59:04 -0700 (PDT) Message-ID: Date: Fri, 7 Jun 2024 13:59:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] sbitmap: fix io hung due to race on sbitmap_word::cleared To: YangYang , Yu Kuai , Ming Lei Cc: Jens Axboe , Andrew Morton , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, "yukuai (C)" References: <20240604031124.2261-1-yang.yang@vivo.com> Content-Language: en-US From: Pavel Begunkov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 6/4/24 08:03, YangYang wrote: > On 2024/6/4 14:12, Yu Kuai wrote: >> Hi, >> >> 在 2024/06/04 11:25, Ming Lei 写道: >>> On Tue, Jun 4, 2024 at 11:12 AM Yang Yang wrote: >>>> >>>> Configuration for sbq: >>>>    depth=64, wake_batch=6, shift=6, map_nr=1 >>>> >>>> 1. There are 64 requests in progress: >>>>    map->word = 0xFFFFFFFFFFFFFFFF >>>> 2. After all the 64 requests complete, and no more requests come: >>>>    map->word = 0xFFFFFFFFFFFFFFFF, map->cleared = 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=-1              __blk_mq_get_tag >>>>    sbitmap_deferred_clear                    __sbitmap_queue_get >>>>    /* map->cleared=0xFFFFFFFFFFFFFFFF */     sbitmap_find_bit >>>>      if (!READ_ONCE(map->cleared))           sbitmap_find_bit_in_word >>>>        return false;                         __sbitmap_get_word -> nr=-1 >>>>      mask = xchg(&map->cleared, 0)           sbitmap_deferred_clear >>>>      atomic_long_andnot()                    /* map->cleared=0 */ >>>>                                                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. >> >> Maybe I'm noob, but I'm confused how can this fix the problem, looks >> like the race condition doesn't change. >> >> In sbitmap_find_bit_in_word: >> >> 1) __sbitmap_get_word read word; >> 2) sbitmap_deferred_clear clear cleared; >> 3) sbitmap_deferred_clear update word; >> >> 2) and 3) are done atomically while 1) can still concurrent with 3): >> >> t1: >> sbitmap_find_bit_in_word >>   __sbitmap_get_word >>   -> read old word, return -1 >          t2: >>          sbitmap_find_bit_in_word >>           __sbitmap_get_word >>           -> read old word, return -1 >>   sbitmap_deferred_clear >>   -> clear cleared and update word >>          sbitmap_deferred_clear >>          -> cleared is cleared, fail > > Yes, you are right, this patch cannot fix this issue. One other alternative is to kill ->cleared. It's not immediately clear how important it is. Do we have any numbers? >> BYW, I still think it's fine to fix this problem by trying the >> __sbitmap_get_word() at least one more time if __sbitmap_get_word() >> failed. > > Err, after trying one more time __sbitmap_get_word() may still fail. -- Pavel Begunkov