mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Lobakin <alobakin@pm.me>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Alexander Lobakin <alobakin@pm.me>,
	Andrew Morton <akpm@linux-foundation.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Jens Axboe <axboe@kernel.dk>, Keith Busch <kbusch@kernel.org>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] asm-generic: fix __get_unaligned_be48() on 32 bit platforms
Date: Mon, 11 Apr 2022 20:00:49 +0000	[thread overview]
Message-ID: <20220411195403.230899-1-alobakin@pm.me> (raw)
In-Reply-To: <20220406233909.529613-1-alobakin@pm.me>

From: Alexander Lobakin <alobakin@pm.me>
Date: Wed, 06 Apr 2022 23:46:04 +0000

> While testing the new macros for working with 48 bit containers,
> I faced a weird problem:
>
> 32 + 16: 0x2ef6e8da 0x79e60000
> 48: 0xffffe8da + 0x79e60000
>
> All the bits starting from the 32nd were getting 1d in 9/10 cases.
> The debug showed:
>
> p[0]: 0x00002e0000000000
> p[1]: 0x00002ef600000000
> p[2]: 0xffffffffe8000000
> p[3]: 0xffffffffe8da0000
> p[4]: 0xffffffffe8da7900
> p[5]: 0xffffffffe8da79e6
>
> that the value becomes a garbage after the third OR, i.e. on
> `p[2] << 24`.
> When the 31st bit is 1 and there's no explicit cast to an unsigned,
> it's being considered as a signed int and getting sign-extended on
> OR, so `e8000000` becomes `ffffffffe8000000` and messes up the
> result.
> Cast the @p[2] to u64 as well to avoid this. Now:
>
> 32 + 16: 0x7ef6a490 0xddc10000
> 48: 0x7ef6a490 + 0xddc10000
>
> p[0]: 0x00007e0000000000
> p[1]: 0x00007ef600000000
> p[2]: 0x00007ef6a4000000
> p[3]: 0x00007ef6a4900000
> p[4]: 0x00007ef6a490dd00
> p[5]: 0x00007ef6a490ddc1
>
> Fixes: c2ea5fcf53d5 ("asm-generic: introduce be48 unaligned accessors")
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>

Uhm, ping?

> ---
>  include/asm-generic/unaligned.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unalign=
> ed.h
> index 8fc637379899..df30f11b4a46 100644
> --- a/include/asm-generic/unaligned.h
> +++ b/include/asm-generic/unaligned.h
> @@ -143,7 +143,7 @@ static inline void put_unaligned_be48(const u64 val, v=
> oid *p)
>
>  static inline u64 __get_unaligned_be48(const u8 *p)
>  {
> -	return (u64)p[0] << 40 | (u64)p[1] << 32 | p[2] << 24 |
> +	return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 |
>  		p[3] << 16 | p[4] << 8 | p[5];
>  }
>
> --
> 2.35.1

Thanks,
Al


  reply	other threads:[~2022-04-11 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06 23:46 Alexander Lobakin
2022-04-11 20:00 ` Alexander Lobakin [this message]
2022-04-11 21:20   ` Bart Van Assche
2022-04-11 23:41     ` Keith Busch

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=20220411195403.230899-1-alobakin@pm.me \
    --to=alobakin@pm.me \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.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®