* [PATCH RESEND] asm-generic: fix __get_unaligned_be48() on 32 bit platforms
@ 2022-04-12 21:59 Alexander Lobakin
2022-04-12 22:31 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Lobakin @ 2022-04-12 21:59 UTC (permalink / raw)
To: linux-nvme, linux-block, linux-crypto
Cc: Arnd Bergmann, Bart Van Assche, Jens Axboe, Keith Busch,
Chaitanya Kulkarni, Martin K. Petersen, Christoph Hellwig,
Andrew Morton, linux-arch, linux-kernel, Alexander Lobakin
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>
---
Resend: target linux-block, expand Ccs a bit
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/unaligned.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, void *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.2
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH RESEND] asm-generic: fix __get_unaligned_be48() on 32 bit platforms
2022-04-12 21:59 [PATCH RESEND] asm-generic: fix __get_unaligned_be48() on 32 bit platforms Alexander Lobakin
@ 2022-04-12 22:31 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-04-12 22:31 UTC (permalink / raw)
To: alobakin, linux-crypto, linux-nvme, linux-block
Cc: bvanassche, linux-kernel, kch, kbusch, Christoph Hellwig,
Andrew Morton, linux-arch, martin.petersen, Arnd Bergmann
On Tue, 12 Apr 2022 21:59:16 +0000, Alexander Lobakin wrote:
> 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:
>
> [...]
Applied, thanks!
[1/1] asm-generic: fix __get_unaligned_be48() on 32 bit platforms
commit: b97687527be85a55e12804c98745c5619eadcc32
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-12 23:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 21:59 [PATCH RESEND] asm-generic: fix __get_unaligned_be48() on 32 bit platforms Alexander Lobakin
2022-04-12 22:31 ` Jens Axboe
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®