mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: YangYang <yang.yang@vivo.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>,
	Omar Sandoval <osandov@fb.com>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH v7] sbitmap: fix io hung due to race on sbitmap_word::cleared
Date: Tue, 16 Jul 2024 11:48:01 +0800	[thread overview]
Message-ID: <37053ba7-68bb-4afc-88cd-8ceac30e2f85@vivo.com> (raw)
In-Reply-To: <263282cd-dadc-43f7-be8f-892248bc3318@acm.org>

On 2024/7/16 1:26, Bart Van Assche wrote:
> On 7/15/24 2:11 AM, Yang Yang wrote:
>> +
>> +    /**
>> +     * @swap_lock: serializes simultaneous updates of ->word and ->cleared
>> +     */
>> +    spinlock_t swap_lock;
>>   } ____cacheline_aligned_in_smp;
> 
> Thank you for having updated this comment.
> 
>> -static inline bool sbitmap_deferred_clear(struct sbitmap_word *map)
>> +static inline bool sbitmap_deferred_clear(struct sbitmap_word *map,
>> +        unsigned int depth, unsigned int alloc_hint, bool wrap)
>>   {
>> -    unsigned long mask;
>> +    unsigned long mask, word_mask;
>> +    bool ret = false;
>> -    if (!READ_ONCE(map->cleared))
>> -        return false;
>> +    guard(spinlock_irqsave)(&map->swap_lock);
>> +
>> +    if (!map->cleared) {
>> +        if (depth > 0) {
>> +            word_mask = (~0UL) >> (BITS_PER_LONG - depth);
>> +            /*
>> +             * The current behavior is to always retry after moving
>> +             * ->cleared to word, and we change it to retry in case
>> +             * of any free bits. To avoid an infinite loop, we need
>> +             * to take wrap & alloc_hint into account, otherwise a
>> +             * soft lockup may occur.
>> +             */
>> +            if (!wrap && alloc_hint)
>> +                word_mask &= ~((1UL << alloc_hint) - 1);
>> +
>> +            if ((READ_ONCE(map->word) & word_mask) == word_mask)
>> +                ret = false;
>> +            else
>> +                ret = true;
>> +        }
>> +
>> +        return ret;
>> +    }
> 
> Now that guard()() is being used, the local variable 'ret' can be eliminated. The if 
> (READ_ONCE() ...) statement can be changed into the
> following: return (READ_ONCE(map->word) & word_mask) != word_mask;
> and "return ret;" can be changed into "return false;". Additionally,
> the indentation depth can be reduced by changing "if (depth > 0) {" ...
> into "if (depth == 0) return false;".

This looks much better, I will make these changes in the next version.

Thanks.

> 
> Otherwise this patch looks good to me.
> 
> Thanks,
> 
> Bart.


      reply	other threads:[~2024-07-16  3:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15  9:11 Yang Yang
2024-07-15 17:26 ` Bart Van Assche
2024-07-16  3:48   ` YangYang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37053ba7-68bb-4afc-88cd-8ceac30e2f85@vivo.com \
    --to=yang.yang@vivo.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=osandov@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®