All of lore.kernel.org
 help / color / mirror / Atom feed
From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 5/7] ARM: KVM: one_reg coproc set and get BE fixes
Date: Sun, 25 May 2014 21:09:47 +0200	[thread overview]
Message-ID: <20140525190947.GA23583@lvm> (raw)
In-Reply-To: <CAA3XUr0ELPxFsoQ+FyWXkoMEbOi=2VHGyhx_KU0bUz1ukAKx8w@mail.gmail.com>

On Tue, May 13, 2014 at 01:11:34PM -0700, Victor Kamensky wrote:
> Hi Christoffer,
> 

[...]

> >> diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
> >> index 78c0885..64b2b94 100644
> >> --- a/arch/arm/kvm/coproc.c
> >> +++ b/arch/arm/kvm/coproc.c
> >> @@ -634,17 +634,61 @@ static struct coproc_reg invariant_cp15[] = {
> >>       { CRn( 0), CRm( 0), Op1( 1), Op2( 7), is32, NULL, get_AIDR },
> >>  };
> >>
> >> -static int reg_from_user(void *val, const void __user *uaddr, u64 id)
> >> +static int reg_from_user64(u64 *val, const void __user *uaddr, u64 id)
> >> +{
> >> +     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;
> >> +     case 8:
> >> +             *val = tmp.dword;
> >> +             break;
> >> +     }
> >> +     return 0;
> >> +}
> >
> > instead of allowing this 'packing 32 bit values in 64 bit values and
> > packing two 32 bit values in 64 bit values' kernel implementation'y
> > stuff to be passed to these user-space ABI catering function, I really
> > think you want to make reg_from_user64 deal with 64-bit registers, that
> > is, BUG_ON(KVM_REG_SIZE(id) != 8.
> 
> Example of kernel storing value in u64 but register is 32bit is
> set/get_invariant_cp15. Note this function passes struct coproc_reg
> val field address into reg_to_user_xxx function. Since struct coproc_reg
> is generic structure used to describe both 32bit and 64bit coproc registers
> val type cannot be changed to u32. One may try to describe
> val as union of u32 and u64 but I have concern that it would
> create bunch of 'if (KVM_REG_SIZE(id) == 4) { ... } else {  ..}'
> pieces all over the place. I think it is better to have function that
> just can read/write 32bit register from/to u64 value in kernel.

I know what the kernel does internally.  I just think these functions
become conceptually very complicated to cater to one special case.  You
could deal with this in the caller.  Consider get_invariant_cp15:

static int get_invariant_cp15(u64 id, void __user *uaddr)
{
	struct coproc_params params;
	const struct coproc_reg *r;

	if (!index_to_params(id, &params))
		return -ENOENT;

	r = find_reg(&params, invariant_cp15, ARRAY_SIZE(invariant_cp15));
	if (!r)
		return -ENOENT;

	if (KVM_REG_SIZE(id) == 4) {
		u32 val = r->val;
		ret = reg_to_user32(uaddr, &val, id);
	} else if (KVM_REG_SIZE(id) == 8) {
		ret = reg_to_user32(uaddr, &r->val, id);
	}
	return ret;
}

Did you actually try this approach and see how the code looks?

-Christoffer

  reply	other threads:[~2014-05-25 19:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12  5:41 [PATCH v2 0/7] armv7 BE kvm support Victor Kamensky
2014-02-12  5:41 ` [PATCH v2 1/7] ARM: KVM: switch hypervisor into BE mode in case of BE host Victor Kamensky
2014-03-18 22:23   ` Christoffer Dall
2014-03-19  0:52     ` Victor Kamensky
2014-03-19  3:03     ` Christoffer Dall
2014-02-12  5:41 ` [PATCH v2 2/7] ARM: KVM: fix vgic V7 assembler code to work in BE image Victor Kamensky
2014-03-20  1:10   ` Christoffer Dall
2014-02-12  5:41 ` [PATCH v2 3/7] ARM: KVM: handle 64bit values passed to mrcc or from mcrr instructions in BE case Victor Kamensky
2014-03-20  1:11   ` Christoffer Dall
2014-02-12  5:41 ` [PATCH v2 4/7] ARM: KVM: __kvm_vcpu_run function return result fix " Victor Kamensky
2014-03-20  1:11   ` Christoffer Dall
2014-02-12  5:41 ` [PATCH v2 5/7] ARM: KVM: one_reg coproc set and get BE fixes Victor Kamensky
2014-02-12  7:07   ` Alexander Graf
2014-03-20  1:11   ` Christoffer Dall
2014-03-20  1:48     ` Victor Kamensky
2014-03-20  3:01       ` Christoffer Dall
2014-05-13 20:11     ` Victor Kamensky
2014-05-25 19:09       ` Christoffer Dall [this message]
2014-02-12  5:41 ` [PATCH v2 6/7] ARM: KVM: vgic mmio should hold data as LE bytes array in BE case Victor Kamensky
2014-03-20  1:12   ` Christoffer Dall
2014-02-12  5:41 ` [PATCH v2 7/7] ARM: KVM: MMIO support BE host running LE code Victor Kamensky
2014-03-20  1:12   ` 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=20140525190947.GA23583@lvm \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.