linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@au1.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@ozlabs.org, Jeremy Kerr <jk@ozlabs.org>
Subject: Re: [RFC PATCH 1/2] powerpc: Add a proper syscall for switching endianness
Date: Tue, 10 Mar 2015 20:34:37 +1100	[thread overview]
Message-ID: <1425980077.4636.265.camel@au1.ibm.com> (raw)
In-Reply-To: <1425973006-22759-1-git-send-email-mpe@ellerman.id.au>

On Tue, 2015-03-10 at 18:36 +1100, Michael Ellerman wrote:
> We currently have a "special" syscall for switching endianness. This is
> syscall number 0x1ebe, which is handled explicitly in the 64-bit syscall
> exception entry.
> 
> That has a few problems, firstly the syscall number is outside of the
> usual range, which confuses various tools. For example strace doesn't
> recognise the syscalls at all.
> 
> Secondly it's handled explicitly as a special case in the syscall
> exception entry, which is complicated enough without it.
> 
> As a first step toward removing the special syscall, we need to add a
> regular syscall that implements the same functionality.
> 
> The logic is simple, it simply toggles the MSR_LE bit in the userspace
> MSR. This is the same as the special syscall, with the caveat that the
> special syscall clobbers fewer registers.

You can set _TIF_RESTOREALL to force a restore of all the registers on
the way back which should do the job.

Cheers,
Ben.

> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  arch/powerpc/include/asm/systbl.h      | 1 +
>  arch/powerpc/include/asm/unistd.h      | 2 +-
>  arch/powerpc/include/uapi/asm/unistd.h | 1 +
>  arch/powerpc/kernel/syscalls.c         | 7 +++++++
>  4 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/include/asm/systbl.h b/arch/powerpc/include/asm/systbl.h
> index 91062eef582f..524bf5dff9f9 100644
> --- a/arch/powerpc/include/asm/systbl.h
> +++ b/arch/powerpc/include/asm/systbl.h
> @@ -367,3 +367,4 @@ SYSCALL_SPU(getrandom)
>  SYSCALL_SPU(memfd_create)
>  SYSCALL_SPU(bpf)
>  COMPAT_SYS(execveat)
> +SYSCALL(switch_endian)
> diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h
> index 36b79c31eedd..f4f8b667d75b 100644
> --- a/arch/powerpc/include/asm/unistd.h
> +++ b/arch/powerpc/include/asm/unistd.h
> @@ -12,7 +12,7 @@
>  #include <uapi/asm/unistd.h>
>  
> 
> -#define __NR_syscalls		363
> +#define __NR_syscalls		364
>  
>  #define __NR__exit __NR_exit
>  #define NR_syscalls	__NR_syscalls
> diff --git a/arch/powerpc/include/uapi/asm/unistd.h b/arch/powerpc/include/uapi/asm/unistd.h
> index ef5b5b1f3123..e4aa173dae62 100644
> --- a/arch/powerpc/include/uapi/asm/unistd.h
> +++ b/arch/powerpc/include/uapi/asm/unistd.h
> @@ -385,5 +385,6 @@
>  #define __NR_memfd_create	360
>  #define __NR_bpf		361
>  #define __NR_execveat		362
> +#define __NR_switch_endian	363
>  
>  #endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */
> diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
> index b2702e87db0d..0ea01957990e 100644
> --- a/arch/powerpc/kernel/syscalls.c
> +++ b/arch/powerpc/kernel/syscalls.c
> @@ -121,3 +121,10 @@ long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
>  	return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
>  			     (u64)len_high << 32 | len_low, advice);
>  }
> +
> +long sys_switch_endian(void)
> +{
> +	current->thread.regs->msr ^= MSR_LE;
> +
> +	return 0;
> +}

  parent reply	other threads:[~2015-03-10  9:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10  7:36 [RFC PATCH 1/2] powerpc: Add a proper syscall for switching endianness Michael Ellerman
2015-03-10  7:36 ` [RFC PATCH 2/2] selftests/powerpc: Add a test of the switch_endian() syscall Michael Ellerman
2015-03-10  9:34 ` Benjamin Herrenschmidt [this message]
2015-03-10 10:55   ` [RFC PATCH 1/2] powerpc: Add a proper syscall for switching endianness Michael Ellerman
2015-03-11  5:38     ` Anshuman Khandual
2015-03-11  5:43       ` Benjamin Herrenschmidt
2015-03-11  6:32         ` Anshuman Khandual

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=1425980077.4636.265.camel@au1.ibm.com \
    --to=benh@au1.ibm.com \
    --cc=jk@ozlabs.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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;
as well as URLs for NNTP newsgroup(s).