public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/5] lib: add bitmap_{from,to}_arr64
Date: Mon, 2 May 2022 13:06:56 -0700	[thread overview]
Message-ID: <YnA54HzrdfOr2QYl@yury-laptop> (raw)
In-Reply-To: <YmwIHRhS2f1QTW3b@yury-laptop>

On Fri, Apr 29, 2022 at 08:45:35AM -0700, Yury Norov wrote:
> On Fri, Apr 29, 2022 at 03:59:25PM +0300, Andy Shevchenko wrote:
> > On Thu, Apr 28, 2022 at 01:51:13PM -0700, Yury Norov wrote:
> > > Manipulating 64-bit arrays with bitmap functions is potentially dangerous
> > > because on 32-bit BE machines the order of halfwords doesn't match.
> > > Another issue is that compiler may throw a warning about out-of-boundary
> > > access.
> > > 
> > > This patch adds bitmap_{from,to}_arr64 functions in addition to existing
> > > bitmap_{from,to}_arr32.
> > 
> > ...
> > 
> > > +	bitmap_copy_clear_tail((unsigned long *) (bitmap),	\
> > > +			(const unsigned long *) (buf), (nbits))
> > 
> > Drop spaces after castings. Besides that it might be placed on a single line.
> > 
> > ...
> 
> OK
>  
> > 
> > > +	bitmap_copy_clear_tail((unsigned long *) (buf),		\
> > > +			(const unsigned long *) (bitmap), (nbits))
> > 
> > Ditto.
> > 
> > ...
> > 
> > > +void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits)
> > > +{
> > > +	const unsigned long *end = bitmap + BITS_TO_LONGS(nbits);
> > > +
> > > +	while (bitmap < end) {
> > > +		*buf = *bitmap++;
> > > +		if (bitmap < end)
> > > +			*buf |= (u64)(*bitmap++) << 32;
> > > +		buf++;
> > > +	}
> > >  
> > > +	/* Clear tail bits in last element of array beyond nbits. */
> > > +	if (nbits % 64)
> > > +		buf[-1] &= GENMASK_ULL(nbits, 0);
> > 
> > Hmm... if nbits is > 0 and < 64, wouldn't be this problematic, since
> > end == bitmap? Or did I miss something?
> 
> BITS_TO_LONGS(0) == 0
> BITS_TO_LONGS(1..32) == 1
> BITS_TO_LONGS(33..64) == 2
> 
> The only potential problem with buf[-1] is nbits == 0, but fortunately
> (0 % 64) == 0, and it doesn't happen.
> 
> Thanks,
> Yury

Are there any other concerns? If no, I'll fix formatting and append it to
bitmap-for-next.

Thanks,
Yury

  reply	other threads:[~2022-05-02 20:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 20:51 [PATCH v2 0/5] bitmap: fix conversion from/to fix-sized arrays Yury Norov
2022-04-28 20:51 ` [PATCH 1/5] lib/bitmap: extend comment for bitmap_(from,to)_arr32() Yury Norov
2022-04-28 20:51 ` [PATCH 2/5] lib: add bitmap_{from,to}_arr64 Yury Norov
2022-04-29 12:59   ` Andy Shevchenko
2022-04-29 15:45     ` Yury Norov
2022-05-02 20:06       ` Yury Norov [this message]
2022-05-03  9:56         ` Andy Shevchenko
2022-04-28 20:51 ` [PATCH 3/5] lib/bitmap: add test for bitmap_{from,to}_arr64 Yury Norov
2022-05-19 15:09   ` Guenter Roeck
2022-05-19 16:01     ` Yury Norov
2022-05-19 18:04       ` Guenter Roeck
2022-05-20 16:18         ` Yury Norov
2022-05-21  7:38     ` Yury Norov
2023-02-25 18:47   ` Guenter Roeck
2023-02-26  0:04     ` Yury Norov
2023-02-26  0:06       ` Yury Norov
2023-02-27 14:46         ` Alexander Lobakin
2023-02-27 14:59           ` Guenter Roeck
2023-02-27 19:24             ` Yury Norov
2023-02-27 20:12               ` Guenter Roeck
2023-02-27 20:23                 ` Yury Norov
2023-02-26  0:42       ` Guenter Roeck
2022-04-28 20:51 ` [PATCH 4/5] KVM: s390: replace bitmap_copy with bitmap_{from,to}_arr64 where appropriate Yury Norov
2022-04-28 20:51 ` [PATCH 5/5] drm/amd/pm: use bitmap_{from,to}_arr32 " 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=YnA54HzrdfOr2QYl@yury-laptop \
    --to=yury.norov@gmail.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=svens@linux.ibm.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