mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: wuchi <wuchi.zero@gmail.com>,
	axboe@kernel.dk, andriy.shevchenko@linux.intel.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch()
Date: Sat, 25 Jun 2022 01:47:24 +0200	[thread overview]
Message-ID: <c2dfae29bb2aa3b6286a3a225a27b116761b9e53.camel@suse.com> (raw)
In-Reply-To: <20220605145835.26916-1-wuchi.zero@gmail.com>

On Sun, 2022-06-05 at 22:58 +0800, wuchi wrote:
> 1. Getting next index before continue branch.
> 2. Checking free bits when setting the target bits. Otherwise,
> it may reuse the busying bits.
> 
> Signed-off-by: wuchi <wuchi.zero@gmail.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

> ---
>  lib/sbitmap.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/sbitmap.c b/lib/sbitmap.c
> index ae4fd4de9ebe..29eb0484215a 100644
> --- a/lib/sbitmap.c
> +++ b/lib/sbitmap.c
> @@ -528,7 +528,7 @@ unsigned long __sbitmap_queue_get_batch(struct
> sbitmap_queue *sbq, int nr_tags,
>  
>                 sbitmap_deferred_clear(map);
>                 if (map->word == (1UL << (map_depth - 1)) - 1)
> -                       continue;
> +                       goto next;
>  
>                 nr = find_first_zero_bit(&map->word, map_depth);
>                 if (nr + nr_tags <= map_depth) {
> @@ -539,6 +539,8 @@ unsigned long __sbitmap_queue_get_batch(struct
> sbitmap_queue *sbq, int nr_tags,
>                         get_mask = ((1UL << map_tags) - 1) << nr;
>                         do {
>                                 val = READ_ONCE(map->word);
> +                               if ((val & ~get_mask) != val)
> +                                       goto next;
>                                 ret = atomic_long_cmpxchg(ptr, val,
> get_mask | val);
>                         } while (ret != val);
>                         get_mask = (get_mask & ~ret) >> nr;
> @@ -549,6 +551,7 @@ unsigned long __sbitmap_queue_get_batch(struct
> sbitmap_queue *sbq, int nr_tags,
>                                 return get_mask;
>                         }
>                 }
> +next:
>                 /* Jump to next index. */
>                 if (++index >= sb->map_nr)
>                         index = 0;


  parent reply	other threads:[~2022-06-24 23:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-05 14:58 wuchi
2022-06-17 10:08 ` chi wu
2022-06-24 23:47 ` Martin Wilck [this message]
2022-06-25 16:59 ` Jens Axboe
2022-06-25 17:02 ` Jens Axboe

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=c2dfae29bb2aa3b6286a3a225a27b116761b9e53.camel@suse.com \
    --to=mwilck@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wuchi.zero@gmail.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®