* [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use()
@ 2024-07-23 17:24 Peter Maydell
2024-07-23 20:57 ` Philippe Mathieu-Daudé
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Peter Maydell @ 2024-07-23 17:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Yoshinori Sato
In update_itlb_use() the variables or_mask and and_mask are uint8_t,
which means that in expressions like "and_mask << 24" the usual C
arithmetic conversions will result in the shift being done as a
signed int type, and so we will shift into the sign bit. For QEMU
this isn't undefined behaviour because we use -fwrapv; but we can
avoid it anyway by using uint32_t types for or_mask and and_mask.
Resolves: Coverity CID 1547628
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/sh4/helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/sh4/helper.c b/target/sh4/helper.c
index 67029106277..9659c695504 100644
--- a/target/sh4/helper.c
+++ b/target/sh4/helper.c
@@ -187,7 +187,7 @@ void superh_cpu_do_interrupt(CPUState *cs)
static void update_itlb_use(CPUSH4State * env, int itlbnb)
{
- uint8_t or_mask = 0, and_mask = (uint8_t) - 1;
+ uint32_t or_mask = 0, and_mask = 0xff;
switch (itlbnb) {
case 0:
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use()
2024-07-23 17:24 [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Peter Maydell
@ 2024-07-23 20:57 ` Philippe Mathieu-Daudé
2024-07-24 0:23 ` Richard Henderson
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 20:57 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Yoshinori Sato
On 23/7/24 19:24, Peter Maydell wrote:
> In update_itlb_use() the variables or_mask and and_mask are uint8_t,
> which means that in expressions like "and_mask << 24" the usual C
> arithmetic conversions will result in the shift being done as a
> signed int type, and so we will shift into the sign bit. For QEMU
> this isn't undefined behaviour because we use -fwrapv; but we can
> avoid it anyway by using uint32_t types for or_mask and and_mask.
>
> Resolves: Coverity CID 1547628
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target/sh4/helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use()
2024-07-23 17:24 [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Peter Maydell
2024-07-23 20:57 ` Philippe Mathieu-Daudé
@ 2024-07-24 0:23 ` Richard Henderson
2024-07-24 3:00 ` Yoshinori Sato
2024-07-29 16:00 ` Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2024-07-24 0:23 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Yoshinori Sato
On 7/24/24 03:24, Peter Maydell wrote:
> In update_itlb_use() the variables or_mask and and_mask are uint8_t,
> which means that in expressions like "and_mask << 24" the usual C
> arithmetic conversions will result in the shift being done as a
> signed int type, and so we will shift into the sign bit. For QEMU
> this isn't undefined behaviour because we use -fwrapv; but we can
> avoid it anyway by using uint32_t types for or_mask and and_mask.
>
> Resolves: Coverity CID 1547628
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
> target/sh4/helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use()
2024-07-23 17:24 [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Peter Maydell
2024-07-23 20:57 ` Philippe Mathieu-Daudé
2024-07-24 0:23 ` Richard Henderson
@ 2024-07-24 3:00 ` Yoshinori Sato
2024-07-29 16:00 ` Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Yoshinori Sato @ 2024-07-24 3:00 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel
On Wed, 24 Jul 2024 02:24:31 +0900,
Peter Maydell wrote:
>
> In update_itlb_use() the variables or_mask and and_mask are uint8_t,
> which means that in expressions like "and_mask << 24" the usual C
> arithmetic conversions will result in the shift being done as a
> signed int type, and so we will shift into the sign bit. For QEMU
> this isn't undefined behaviour because we use -fwrapv; but we can
> avoid it anyway by using uint32_t types for or_mask and and_mask.
>
> Resolves: Coverity CID 1547628
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target/sh4/helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/sh4/helper.c b/target/sh4/helper.c
> index 67029106277..9659c695504 100644
> --- a/target/sh4/helper.c
> +++ b/target/sh4/helper.c
> @@ -187,7 +187,7 @@ void superh_cpu_do_interrupt(CPUState *cs)
>
> static void update_itlb_use(CPUSH4State * env, int itlbnb)
> {
> - uint8_t or_mask = 0, and_mask = (uint8_t) - 1;
> + uint32_t or_mask = 0, and_mask = 0xff;
>
> switch (itlbnb) {
> case 0:
> --
> 2.34.1
>
Reviewed-by: Yoshinori Sato <ysato@users.sourceforge.jp>
--
Yosinori Sato
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use()
2024-07-23 17:24 [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Peter Maydell
` (2 preceding siblings ...)
2024-07-24 3:00 ` Yoshinori Sato
@ 2024-07-29 16:00 ` Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2024-07-29 16:00 UTC (permalink / raw)
To: qemu-devel; +Cc: Yoshinori Sato
On Tue, 23 Jul 2024 at 18:24, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> In update_itlb_use() the variables or_mask and and_mask are uint8_t,
> which means that in expressions like "and_mask << 24" the usual C
> arithmetic conversions will result in the shift being done as a
> signed int type, and so we will shift into the sign bit. For QEMU
> this isn't undefined behaviour because we use -fwrapv; but we can
> avoid it anyway by using uint32_t types for or_mask and and_mask.
>
> Resolves: Coverity CID 1547628
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
I'll take this via my target-arm queue since I'm doing a
pullreq anyway.
thanks
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-07-29 16:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 17:24 [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Peter Maydell
2024-07-23 20:57 ` Philippe Mathieu-Daudé
2024-07-24 0:23 ` Richard Henderson
2024-07-24 3:00 ` Yoshinori Sato
2024-07-29 16:00 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).