Skip to content

Commit 5a420ed

Browse files
author
Marc Zyngier
committed
KVM: arm64: Get rid of reg_from/to_user()
These helpers are only used by the invariant stuff now, and while they pretend to support non-64bit registers, this only serves as a way to scare the casual reviewer... Replace these helpers with our good friends get/put_user(), and don't look back. Reviewed-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 978ceeb commit 5a420ed

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
* 64bit interface.
4545
*/
4646

47-
static int reg_from_user(u64 *val, const void __user *uaddr, u64 id);
48-
static int reg_to_user(void __user *uaddr, const u64 *val, u64 id);
4947
static u64 sys_reg_to_index(const struct sys_reg_desc *reg);
5048

5149
static bool read_from_write_only(struct kvm_vcpu *vcpu,
@@ -2657,21 +2655,7 @@ static struct sys_reg_desc invariant_sys_regs[] = {
26572655
{ SYS_DESC(SYS_CTR_EL0), NULL, get_ctr_el0 },
26582656
};
26592657

2660-
static int reg_from_user(u64 *val, const void __user *uaddr, u64 id)
2661-
{
2662-
if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0)
2663-
return -EFAULT;
2664-
return 0;
2665-
}
2666-
2667-
static int reg_to_user(void __user *uaddr, const u64 *val, u64 id)
2668-
{
2669-
if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0)
2670-
return -EFAULT;
2671-
return 0;
2672-
}
2673-
2674-
static int get_invariant_sys_reg(u64 id, void __user *uaddr)
2658+
static int get_invariant_sys_reg(u64 id, u64 __user *uaddr)
26752659
{
26762660
const struct sys_reg_desc *r;
26772661

@@ -2680,23 +2664,21 @@ static int get_invariant_sys_reg(u64 id, void __user *uaddr)
26802664
if (!r)
26812665
return -ENOENT;
26822666

2683-
return reg_to_user(uaddr, &r->val, id);
2667+
return put_user(r->val, uaddr);
26842668
}
26852669

2686-
static int set_invariant_sys_reg(u64 id, void __user *uaddr)
2670+
static int set_invariant_sys_reg(u64 id, u64 __user *uaddr)
26872671
{
26882672
const struct sys_reg_desc *r;
2689-
int err;
2690-
u64 val = 0; /* Make sure high bits are 0 for 32-bit regs */
2673+
u64 val;
26912674

26922675
r = get_reg_by_id(id, invariant_sys_regs,
26932676
ARRAY_SIZE(invariant_sys_regs));
26942677
if (!r)
26952678
return -ENOENT;
26962679

2697-
err = reg_from_user(&val, uaddr, id);
2698-
if (err)
2699-
return err;
2680+
if (get_user(val, uaddr))
2681+
return -EFAULT;
27002682

27012683
/* This is what we mean by invariant: you can't change it. */
27022684
if (r->val != val)

0 commit comments

Comments
 (0)