diff mbox series

[1/2] target/hppa: Fix proberi instruction emulation for linux-user

Message ID 20220822103131.381075-2-den@openvz.org (mailing list archive)
State New, archived
Headers show
Series block: add missed block_acct_setup with new block device init procedure | expand

Commit Message

Denis V. Lunev Aug. 22, 2022, 10:31 a.m. UTC
From: Helge Deller <deller@gmx.de>

The proberi assembler instruction checks the read/write access rights
for the page of a given address and shall return a value of 1 if the
test succeeds and a value of 0 on failure in the target register.

But when run in linux-user mode, qemu currently simply returns the
return code of page_check_range() which returns 0 on success and -1 on
failure, which is the opposite of what proberi should return.

Fix it by checking the return code of page_check_range() and return the
expected return value.

The easiest way to reproduce the issue is by running
"/lib/ld.so.1 --version" in a chroot which fails without this patch.
At startup of ld.so the __canonicalize_funcptr_for_compare() function is
used to resolve the function address out of a function descriptor, which
fails because proberi (due to the wrong return code) seems to indicate
that the given address isn't accessible.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 target/hppa/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Helge Deller Aug. 22, 2022, 12:38 p.m. UTC | #1
Thank you Denis,

Btw, this patch was already pulled by Richard...

Helge

On 8/22/22 12:31, Denis V. Lunev wrote:
> From: Helge Deller <deller@gmx.de>
>
> The proberi assembler instruction checks the read/write access rights
> for the page of a given address and shall return a value of 1 if the
> test succeeds and a value of 0 on failure in the target register.
>
> But when run in linux-user mode, qemu currently simply returns the
> return code of page_check_range() which returns 0 on success and -1 on
> failure, which is the opposite of what proberi should return.
>
> Fix it by checking the return code of page_check_range() and return the
> expected return value.
>
> The easiest way to reproduce the issue is by running
> "/lib/ld.so.1 --version" in a chroot which fails without this patch.
> At startup of ld.so the __canonicalize_funcptr_for_compare() function is
> used to resolve the function address out of a function descriptor, which
> fails because proberi (due to the wrong return code) seems to indicate
> that the given address isn't accessible.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>  target/hppa/op_helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c
> index cd304f051e..fbd80e4248 100644
> --- a/target/hppa/op_helper.c
> +++ b/target/hppa/op_helper.c
> @@ -170,7 +170,7 @@ target_ureg HELPER(probe)(CPUHPPAState *env, target_ulong addr,
>                            uint32_t level, uint32_t want)
>  {
>  #ifdef CONFIG_USER_ONLY
> -    return page_check_range(addr, 1, want);
> +    return (page_check_range(addr, 1, want) == 0) ? 1 : 0;
>  #else
>      int prot, excp;
>      hwaddr phys;
diff mbox series

Patch

diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c
index cd304f051e..fbd80e4248 100644
--- a/target/hppa/op_helper.c
+++ b/target/hppa/op_helper.c
@@ -170,7 +170,7 @@  target_ureg HELPER(probe)(CPUHPPAState *env, target_ulong addr,
                           uint32_t level, uint32_t want)
 {
 #ifdef CONFIG_USER_ONLY
-    return page_check_range(addr, 1, want);
+    return (page_check_range(addr, 1, want) == 0) ? 1 : 0;
 #else
     int prot, excp;
     hwaddr phys;