* [PATCH] target: hppa: Fix unaligned double word accesses for hppa64
@ 2024-02-16 5:34 Guenter Roeck
2024-02-16 5:58 ` Charlie Jenkins
2024-02-16 6:16 ` Richard Henderson
0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-02-16 5:34 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-devel, Guenter Roeck, Charlie Jenkins, Helge Deller
Unaligned 64-bit accesses were found in Linux to clobber carry bits,
resulting in bad results if an arithmetic operation involving a
carry bit was executed after an unaligned 64-bit operation.
hppa 2.0 defines additional carry bits in PSW register bits 32..39.
When restoring PSW after executing an unaligned instruction trap,
those bits were not cleared and ended up to be active all the time.
Clearing bit 32..39 in psw prior to restoring it solves the problem.
Fixes: 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Charlie Jenkins <charlie@rivosinc.com>
Cc: Helge Deller <deller@gmx.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
target/hppa/helper.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/target/hppa/helper.c b/target/hppa/helper.c
index 859644c47a..7b798d1227 100644
--- a/target/hppa/helper.c
+++ b/target/hppa/helper.c
@@ -76,7 +76,12 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ulong psw)
}
psw &= ~reserved;
- env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
+ if (hppa_is_pa20(env)) {
+ env->psw = psw & ~(PSW_N | PSW_V | PSW_CB | 0xff00000000ull);
+ } else {
+ env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
+ }
+
env->psw_n = (psw / PSW_N) & 1;
env->psw_v = -((psw / PSW_V) & 1);
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] target: hppa: Fix unaligned double word accesses for hppa64
2024-02-16 5:34 [PATCH] target: hppa: Fix unaligned double word accesses for hppa64 Guenter Roeck
@ 2024-02-16 5:58 ` Charlie Jenkins
2024-02-16 6:54 ` Helge Deller
2024-02-16 6:16 ` Richard Henderson
1 sibling, 1 reply; 5+ messages in thread
From: Charlie Jenkins @ 2024-02-16 5:58 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Richard Henderson, qemu-devel, Helge Deller
On Thu, Feb 15, 2024 at 09:34:15PM -0800, Guenter Roeck wrote:
> Unaligned 64-bit accesses were found in Linux to clobber carry bits,
> resulting in bad results if an arithmetic operation involving a
> carry bit was executed after an unaligned 64-bit operation.
>
> hppa 2.0 defines additional carry bits in PSW register bits 32..39.
> When restoring PSW after executing an unaligned instruction trap,
> those bits were not cleared and ended up to be active all the time.
> Clearing bit 32..39 in psw prior to restoring it solves the problem.
>
> Fixes: 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Charlie Jenkins <charlie@rivosinc.com>
> Cc: Helge Deller <deller@gmx.de>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> target/hppa/helper.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/target/hppa/helper.c b/target/hppa/helper.c
> index 859644c47a..7b798d1227 100644
> --- a/target/hppa/helper.c
> +++ b/target/hppa/helper.c
> @@ -76,7 +76,12 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ulong psw)
> }
> psw &= ~reserved;
>
> - env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
> + if (hppa_is_pa20(env)) {
> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB | 0xff00000000ull);
I thought there was something fishy in this function but was slow on the
uptake...
How about defining a new macro (PSW_CB_HIGH) to hold this value?
- Charlie
> + } else {
> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
> + }
> +
> env->psw_n = (psw / PSW_N) & 1;
> env->psw_v = -((psw / PSW_V) & 1);
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target: hppa: Fix unaligned double word accesses for hppa64
2024-02-16 5:34 [PATCH] target: hppa: Fix unaligned double word accesses for hppa64 Guenter Roeck
2024-02-16 5:58 ` Charlie Jenkins
@ 2024-02-16 6:16 ` Richard Henderson
2024-02-16 6:21 ` Guenter Roeck
1 sibling, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2024-02-16 6:16 UTC (permalink / raw)
To: Guenter Roeck; +Cc: qemu-devel, Charlie Jenkins, Helge Deller
On 2/15/24 19:34, Guenter Roeck wrote:
> - env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
> + if (hppa_is_pa20(env)) {
> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB | 0xff00000000ull);
> + } else {
> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
> + }
There are never any bits above 31 set in env->psw, because all of the CB bits are supposed
to be stored in env->psw_cb. Thus
env->psw = psw & (uint32_t)~(...)
with no need for the pa20 check.
With that,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target: hppa: Fix unaligned double word accesses for hppa64
2024-02-16 6:16 ` Richard Henderson
@ 2024-02-16 6:21 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-02-16 6:21 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel, Charlie Jenkins, Helge Deller
On 2/15/24 22:16, Richard Henderson wrote:
> On 2/15/24 19:34, Guenter Roeck wrote:
>> - env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
>> + if (hppa_is_pa20(env)) {
>> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB | 0xff00000000ull);
>> + } else {
>> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
>> + }
>
> There are never any bits above 31 set in env->psw, because all of the CB bits are supposed to be stored in env->psw_cb. Thus
>
> env->psw = psw & (uint32_t)~(...)
>
> with no need for the pa20 check.
>
> With that,
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
sgtm. I'll test that and send v2 tomorrow (it is getting late).
Thanks,
Guenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] target: hppa: Fix unaligned double word accesses for hppa64
2024-02-16 5:58 ` Charlie Jenkins
@ 2024-02-16 6:54 ` Helge Deller
0 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2024-02-16 6:54 UTC (permalink / raw)
To: Charlie Jenkins, Guenter Roeck; +Cc: Richard Henderson, qemu-devel
On 2/16/24 06:58, Charlie Jenkins wrote:
> On Thu, Feb 15, 2024 at 09:34:15PM -0800, Guenter Roeck wrote:
>> Unaligned 64-bit accesses were found in Linux to clobber carry bits,
>> resulting in bad results if an arithmetic operation involving a
>> carry bit was executed after an unaligned 64-bit operation.
>>
>> hppa 2.0 defines additional carry bits in PSW register bits 32..39.
>> When restoring PSW after executing an unaligned instruction trap,
>> those bits were not cleared and ended up to be active all the time.
>> Clearing bit 32..39 in psw prior to restoring it solves the problem.
>>
>> Fixes: 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")
>> Cc: Richard Henderson <richard.henderson@linaro.org>
>> Cc: Charlie Jenkins <charlie@rivosinc.com>
>> Cc: Helge Deller <deller@gmx.de>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> target/hppa/helper.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/target/hppa/helper.c b/target/hppa/helper.c
>> index 859644c47a..7b798d1227 100644
>> --- a/target/hppa/helper.c
>> +++ b/target/hppa/helper.c
>> @@ -76,7 +76,12 @@ void cpu_hppa_put_psw(CPUHPPAState *env, target_ulong psw)
>> }
>> psw &= ~reserved;
>>
>> - env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
>> + if (hppa_is_pa20(env)) {
>> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB | 0xff00000000ull);
>
> I thought there was something fishy in this function but was slow on the
> uptake...
>
> How about defining a new macro (PSW_CB_HIGH) to hold this value?
...and avoid the hppa_is_pa20() by using PSW_CB_HIGH unconditionally
on 32-bit too (which then gets optimized-out by the compiler).
Nice catch btw!
I wonder if this finally fixes 64-bit Linux kernels on qemu-hppa20....?
Helge
> - Charlie
>
>> + } else {
>> + env->psw = psw & ~(PSW_N | PSW_V | PSW_CB);
>> + }
>> +
>> env->psw_n = (psw / PSW_N) & 1;
>> env->psw_v = -((psw / PSW_V) & 1);
>>
>> --
>> 2.39.2
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-16 13:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16 5:34 [PATCH] target: hppa: Fix unaligned double word accesses for hppa64 Guenter Roeck
2024-02-16 5:58 ` Charlie Jenkins
2024-02-16 6:54 ` Helge Deller
2024-02-16 6:16 ` Richard Henderson
2024-02-16 6:21 ` Guenter Roeck
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).