linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/5] ARM64: KVM: set and get of sys registers in BE case
Date: Wed, 19 Mar 2014 20:41:41 -0700	[thread overview]
Message-ID: <20140320034141.GR1297@cbox> (raw)
In-Reply-To: <1392184643-6108-3-git-send-email-victor.kamensky@linaro.org>

On Tue, Feb 11, 2014 at 09:57:20PM -0800, Victor Kamensky wrote:
> This patch fixes issue of reading and writing V8 sys registers in
> BE case. It is similar to V7 "ARM: kvm one_reg coproc set and get
> BE fixes" patch.
> 
> It changes reg_from_user and reg_to_user functions to have strong
> typed 'u64 *val' argument. And it uses endian angnostic way to
> pick up righ word from '*val' in case when register size is 4 bytes.
> 
> Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
> ---
>  arch/arm64/kvm/sys_regs.c | 39 +++++++++++++++++++++++++++++++++------
>  1 file changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 02e9d09..e7c3e24 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -701,18 +701,45 @@ static struct sys_reg_desc invariant_sys_regs[] = {
>  	  NULL, get_ctr_el0 },
>  };
>  
> -static int reg_from_user(void *val, const void __user *uaddr, u64 id)
> +static int reg_from_user(u64 *val, const void __user *uaddr, u64 id)
>  {
> -	/* This Just Works because we are little endian. */
> -	if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0)
> +	unsigned long regsize = KVM_REG_SIZE(id);
> +	union {
> +		u32	word;
> +		u64	dword;
> +	} tmp = {0};
> +
> +	if (copy_from_user(&tmp, uaddr, regsize) != 0)
>  		return -EFAULT;
> +	switch (regsize) {
> +	case 4:
> +		*val = tmp.word;
> +		break;

This should never happen for arm64, right?  IIRC, we expose all system
registers, even the aarch32 ones, as 64-bit versions with padded zeros,
just like in the ARM ARM...

> +	case 8:
> +		*val = tmp.dword;
> +		break;
> +	}
>  	return 0;
>  }
>  
> -static int reg_to_user(void __user *uaddr, const void *val, u64 id)
> +static int reg_to_user(void __user *uaddr, const u64 *val, u64 id)
>  {
> -	/* This Just Works because we are little endian. */
> -	if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0)
> +	unsigned long regsize = KVM_REG_SIZE(id);
> +	union {
> +		u32	word;
> +		u64	dword;
> +	} tmp;
> +
> +	switch (regsize) {
> +	case 4:
> +		tmp.word = *val;
> +		break;

same

> +	case 8:
> +		tmp.dword = *val;
> +		break;
> +	}
> +
> +	if (copy_to_user(uaddr, &tmp, regsize) != 0)
>  		return -EFAULT;
>  	return 0;
>  }
> -- 
> 1.8.1.4
> 

-- 
Christoffer

  reply	other threads:[~2014-03-20  3:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12  5:57 [PATCH 0/5] aarch64 BE kvm support Victor Kamensky
2014-02-12  5:57 ` [PATCH 1/5] ARM64: KVM: MMIO support BE host running LE code Victor Kamensky
2014-03-20  3:41   ` Christoffer Dall
2014-02-12  5:57 ` [PATCH 2/5] ARM64: KVM: set and get of sys registers in BE case Victor Kamensky
2014-03-20  3:41   ` Christoffer Dall [this message]
2014-02-12  5:57 ` [PATCH 3/5] ARM64: KVM: store kvm_vcpu_fault_info est_el2 as word Victor Kamensky
2014-03-20  3:41   ` Christoffer Dall
2014-02-12  5:57 ` [PATCH 4/5] ARM64: KVM: vgic_elrsr and vgic_eisr need to be byteswapped in BE case Victor Kamensky
2014-02-12  7:15   ` Alexander Graf
2014-03-20  3:42   ` Christoffer Dall
2014-02-12  5:57 ` [PATCH 5/5] ARM64: KVM: fix vgic_bitmap_get_reg function for BE 64bit case Victor Kamensky
2014-03-20  3:43   ` Christoffer Dall

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=20140320034141.GR1297@cbox \
    --to=christoffer.dall@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).