From: Oliver Upton <oliver.upton@linux.dev>
To: Marc Zyngier <maz@kernel.org>
Cc: kvm@vger.kernel.org, kernel-team@android.com,
Schspa Shi <schspa@gmail.com>,
kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 06/19] KVM: arm64: Get rid of reg_from/to_user()
Date: Fri, 8 Jul 2022 12:35:27 -0700 [thread overview]
Message-ID: <YsiG/ylMObDiDE91@google.com> (raw)
In-Reply-To: <20220706164304.1582687-7-maz@kernel.org>
On Wed, Jul 06, 2022 at 05:42:51PM +0100, Marc Zyngier wrote:
> 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.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> arch/arm64/kvm/sys_regs.c | 33 +++++++++------------------------
> 1 file changed, 9 insertions(+), 24 deletions(-)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 1ce439eed3d8..b66be9df7a02 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -44,8 +44,6 @@
> * 64bit interface.
> */
>
> -static int reg_from_user(u64 *val, const void __user *uaddr, u64 id);
> -static int reg_to_user(void __user *uaddr, const u64 *val, u64 id);
> static u64 sys_reg_to_index(const struct sys_reg_desc *reg);
>
> static bool read_from_write_only(struct kvm_vcpu *vcpu,
> @@ -2661,21 +2659,7 @@ static struct sys_reg_desc invariant_sys_regs[] = {
> { SYS_DESC(SYS_CTR_EL0), NULL, get_ctr_el0 },
> };
>
> -static int reg_from_user(u64 *val, const void __user *uaddr, u64 id)
> -{
> - if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0)
> - return -EFAULT;
> - return 0;
> -}
> -
> -static int reg_to_user(void __user *uaddr, const u64 *val, u64 id)
> -{
> - if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0)
> - return -EFAULT;
> - return 0;
> -}
> -
> -static int get_invariant_sys_reg(u64 id, void __user *uaddr)
> +static int get_invariant_sys_reg(u64 id, u64 __user *uaddr)
> {
> const struct sys_reg_desc *r;
>
> @@ -2684,23 +2668,24 @@ static int get_invariant_sys_reg(u64 id, void __user *uaddr)
> if (!r)
> return -ENOENT;
>
> - return reg_to_user(uaddr, &r->val, id);
> + if (put_user(r->val, uaddr))
> + return -EFAULT;
> +
> + return 0;
> }
>
> -static int set_invariant_sys_reg(u64 id, void __user *uaddr)
> +static int set_invariant_sys_reg(u64 id, u64 __user *uaddr)
> {
> const struct sys_reg_desc *r;
> - int err;
> - u64 val = 0; /* Make sure high bits are 0 for 32-bit regs */
> + u64 val;
>
> r = get_reg_by_id(id, invariant_sys_regs,
> ARRAY_SIZE(invariant_sys_regs));
> if (!r)
> return -ENOENT;
>
> - err = reg_from_user(&val, uaddr, id);
> - if (err)
> - return err;
> + if (get_user(val, uaddr))
> + return -EFAULT;
>
> /* This is what we mean by invariant: you can't change it. */
> if (r->val != val)
> --
> 2.34.1
>
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2022-07-11 9:43 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 16:42 [PATCH 00/19] KVM: arm64: vgic-v3 userspace access consolidation (and other goodies) Marc Zyngier
2022-07-06 16:42 ` [PATCH 01/19] KVM: arm64: Add get_reg_by_id() as a sys_reg_desc retrieving helper Marc Zyngier
2022-07-07 4:05 ` Reiji Watanabe
2022-07-07 5:16 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 02/19] KVM: arm64: Reorder handling of invariant sysregs from userspace Marc Zyngier
2022-07-07 4:24 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 03/19] KVM: arm64: Introduce generic get_user/set_user helpers for system registers Marc Zyngier
2022-07-08 19:20 ` Oliver Upton
2022-07-09 6:59 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 04/19] KVM: arm64: Push checks for 64bit registers into the low-level accessors Marc Zyngier
2022-07-08 6:13 ` Reiji Watanabe
2022-07-08 8:05 ` Marc Zyngier
2022-07-06 16:42 ` [PATCH 05/19] KVM: arm64: Consolidate sysreg userspace accesses Marc Zyngier
2022-07-08 19:33 ` Oliver Upton
2022-07-09 6:55 ` Reiji Watanabe
2022-07-12 7:25 ` Marc Zyngier
2022-07-06 16:42 ` [PATCH 06/19] KVM: arm64: Get rid of reg_from/to_user() Marc Zyngier
2022-07-08 19:35 ` Oliver Upton [this message]
2022-07-12 4:34 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 07/19] KVM: arm64: vgic-v3: Simplify vgic_v3_has_cpu_sysregs_attr() Marc Zyngier
2022-07-08 19:38 ` Oliver Upton
2022-07-12 5:22 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 08/19] KVM: arm64: vgic-v3: Push user access into vgic_v3_cpu_sysregs_uaccess() Marc Zyngier
2022-07-12 6:11 ` Reiji Watanabe
2022-07-12 6:52 ` Marc Zyngier
2022-07-13 3:26 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 09/19] KVM: arm64: vgic-v3: Make the userspace accessors use sysreg API Marc Zyngier
2022-07-13 5:21 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 10/19] KVM: arm64: vgic-v3: Convert userspace accessors over to FIELD_GET/FIELD_PREP Marc Zyngier
2022-07-13 5:51 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 11/19] KVM: arm64: vgic-v3: Use u32 to manage the line level from userspace Marc Zyngier
2022-07-13 6:45 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 12/19] KVM: arm64: vgic-v3: Consolidate userspace access for MMIO registers Marc Zyngier
2022-07-14 4:11 ` Reiji Watanabe
2022-07-06 16:42 ` [PATCH 13/19] KVM: arm64: vgic-v2: " Marc Zyngier
2022-07-14 4:43 ` Reiji Watanabe
2022-07-14 7:09 ` Marc Zyngier
2022-07-06 16:42 ` [PATCH 14/19] KVM: arm64: vgic: Use {get, put}_user() instead of copy_{from.to}_user Marc Zyngier
2022-07-14 5:09 ` Reiji Watanabe
2022-07-06 16:43 ` [PATCH 15/19] KVM: arm64: vgic-v2: Add helper for legacy dist/cpuif base address setting Marc Zyngier
2022-07-14 6:37 ` Reiji Watanabe
2022-07-14 7:01 ` Marc Zyngier
2022-07-15 6:44 ` Reiji Watanabe
2022-07-06 16:43 ` [PATCH 16/19] KVM: arm64: vgic: Consolidate userspace access for " Marc Zyngier
2022-07-06 16:43 ` [PATCH 17/19] KVM: arm64: Get rid of find_reg_by_id() Marc Zyngier
2022-07-06 16:43 ` [PATCH 18/19] KVM: arm64: Descope kvm_arm_sys_reg_{get,set}_reg() Marc Zyngier
2022-07-06 16:43 ` [PATCH 19/19] KVM: arm64: Get rid or outdated comments Marc Zyngier
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=YsiG/ylMObDiDE91@google.com \
--to=oliver.upton@linux.dev \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=schspa@gmail.com \
/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