The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Valentin Schneider <vschneid@redhat.com>
To: Yury Norov <yury.norov@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>,
	Alexey Klimov <klimov.linux@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Andy Whitcroft <apw@canonical.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Dennis Zhou <dennis@kernel.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Kees Cook <keescook@chromium.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Russell King <linux@armlinux.org.uk>
Subject: Re: [PATCH v3 3/4] lib/find_bit: optimize find_next_bit() functions
Date: Wed, 07 Sep 2022 17:27:08 +0100	[thread overview]
Message-ID: <xhsmhfsh3b15v.mognet@vschneid.remote.csb> (raw)
In-Reply-To: <20220827175807.4017673-4-yury.norov@gmail.com>

On 27/08/22 10:58, Yury Norov wrote:
> +#define FIND_NEXT_BIT(FETCH, MUNGE, size, start)				\
> +({										\
> +	unsigned long mask, idx, tmp, sz = (size), __start = (start);		\
> +										\
> +	if (unlikely(__start >= sz))						\
> +		goto out;							\
> +										\
> +	mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start));				\
> +	idx = __start / BITS_PER_LONG;						\
> +										\
> +	for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) {			\
> +		if (idx > sz / BITS_PER_LONG)					\

Does that want to be

                if (idx + 1 >= sz / BITS_PER_LONG)

?

Consider this as used in _find_next_bit() for an all-zero 128-bit wide
bitmap (two ULL's), providing the memory contiguous to the bitmap is also
zero then this will only stop at idx=3, so that's fetching two ULLs too
far.

> +			goto out;						\
> +		idx++;								\
> +	}									\
> +										\
> +	sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz);			\
> +out:										\
> +	sz;									\
> +})


  reply	other threads:[~2022-09-07 16:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-27 17:58 [PATCH v3 0/4] lib: optimize find_bit() functions Yury Norov
2022-08-27 17:58 ` [PATCH v3 1/4] lib/find_bit: introduce FIND_FIRST_BIT() macro Yury Norov
2022-09-07 16:27   ` Valentin Schneider
2022-08-27 17:58 ` [PATCH v3 2/4] lib/find_bit: create find_first_zero_bit_le() Yury Norov
2022-09-07 16:27   ` Valentin Schneider
2022-08-27 17:58 ` [PATCH v3 3/4] lib/find_bit: optimize find_next_bit() functions Yury Norov
2022-09-07 16:27   ` Valentin Schneider [this message]
2022-09-07 16:57     ` Yury Norov
2022-09-09 12:24       ` Sven Schnelle
2022-09-09 14:47         ` Yury Norov
2022-09-09 17:03           ` Andy Shevchenko
2022-08-27 17:58 ` [PATCH v3 4/4] tools: sync find_bit() implementation Yury Norov

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=xhsmhfsh3b15v.mognet@vschneid.remote.csb \
    --to=vschneid@redhat.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=apw@canonical.com \
    --cc=catalin.marinas@arm.com \
    --cc=dennis@kernel.org \
    --cc=keescook@chromium.org \
    --cc=klimov.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linux@roeck-us.net \
    --cc=torvalds@linux-foundation.org \
    --cc=yury.norov@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