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 4/6] arm64/kvm: use {read,write}_sysreg()
Date: Thu, 8 Sep 2016 15:34:46 +0200	[thread overview]
Message-ID: <20160908133446.GA9940@cbox> (raw)
In-Reply-To: <1473339339-32334-5-git-send-email-mark.rutland@arm.com>

On Thu, Sep 08, 2016 at 01:55:37PM +0100, Mark Rutland wrote:
> A while back we added {read,write}_sysreg accessors to handle accesses
> to system registers, without the usual boilerplate asm volatile,
> temporary variable, etc.
> 
> This patch makes use of these in the arm64 KVM code to make the code
> shorter and clearer.
> 
> At the same time, a comment style violation next to a system register
> access is fixed up in reset_pmcr, and comments describing whether
> operations are reads or writes are removed as this is now painfully
> obvious.

Acked-by: Christoffer Dall <christoffer.dall@linaro.org>

> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Christoffer Dall <christoffer.dall@linaro.org>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> ---
>  arch/arm64/include/asm/virt.h        |  6 ++----
>  arch/arm64/kvm/sys_regs.c            | 31 +++++++++++--------------------
>  arch/arm64/kvm/sys_regs_generic_v8.c |  6 ++----
>  3 files changed, 15 insertions(+), 28 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
> index 1788545..c5cc940 100644
> --- a/arch/arm64/include/asm/virt.h
> +++ b/arch/arm64/include/asm/virt.h
> @@ -45,6 +45,7 @@
>  #ifndef __ASSEMBLY__
>  
>  #include <asm/ptrace.h>
> +#include <asm/sysreg.h>
>  
>  /*
>   * __boot_cpu_mode records what mode CPUs were booted in.
> @@ -75,10 +76,7 @@ static inline bool is_hyp_mode_mismatched(void)
>  
>  static inline bool is_kernel_in_hyp_mode(void)
>  {
> -	u64 el;
> -
> -	asm("mrs %0, CurrentEL" : "=r" (el));
> -	return el == CurrentEL_EL2;
> +	return read_sysreg(CurrentEL) == CurrentEL_EL2;
>  }
>  
>  #ifdef CONFIG_ARM64_VHE
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index e51367d..f302fdb 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -36,6 +36,7 @@
>  #include <asm/kvm_host.h>
>  #include <asm/kvm_mmu.h>
>  #include <asm/perf_event.h>
> +#include <asm/sysreg.h>
>  
>  #include <trace/events/kvm.h>
>  
> @@ -67,11 +68,9 @@ static u32 get_ccsidr(u32 csselr)
>  
>  	/* Make sure noone else changes CSSELR during this! */
>  	local_irq_disable();
> -	/* Put value into CSSELR */
> -	asm volatile("msr csselr_el1, %x0" : : "r" (csselr));
> +	write_sysreg(csselr, csselr_el1);
>  	isb();
> -	/* Read result out of CCSIDR */
> -	asm volatile("mrs %0, ccsidr_el1" : "=r" (ccsidr));
> +	ccsidr = read_sysreg(ccsidr_el1);
>  	local_irq_enable();
>  
>  	return ccsidr;
> @@ -174,9 +173,7 @@ static bool trap_dbgauthstatus_el1(struct kvm_vcpu *vcpu,
>  	if (p->is_write) {
>  		return ignore_write(vcpu, p);
>  	} else {
> -		u32 val;
> -		asm volatile("mrs %0, dbgauthstatus_el1" : "=r" (val));
> -		p->regval = val;
> +		p->regval = read_sysreg(dbgauthstatus_el1);
>  		return true;
>  	}
>  }
> @@ -429,10 +426,7 @@ static void reset_wcr(struct kvm_vcpu *vcpu,
>  
>  static void reset_amair_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
>  {
> -	u64 amair;
> -
> -	asm volatile("mrs %0, amair_el1\n" : "=r" (amair));
> -	vcpu_sys_reg(vcpu, AMAIR_EL1) = amair;
> +	vcpu_sys_reg(vcpu, AMAIR_EL1) = read_sysreg(amair_el1);
>  }
>  
>  static void reset_mpidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
> @@ -456,8 +450,9 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
>  {
>  	u64 pmcr, val;
>  
> -	asm volatile("mrs %0, pmcr_el0\n" : "=r" (pmcr));
> -	/* Writable bits of PMCR_EL0 (ARMV8_PMU_PMCR_MASK) is reset to UNKNOWN
> +	pmcr = read_sysreg(pmcr_el0);
> +	/*
> +	 * Writable bits of PMCR_EL0 (ARMV8_PMU_PMCR_MASK) are reset to UNKNOWN
>  	 * except PMCR.E resetting to zero.
>  	 */
>  	val = ((pmcr & ~ARMV8_PMU_PMCR_MASK)
> @@ -557,9 +552,9 @@ static bool access_pmceid(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
>  		return false;
>  
>  	if (!(p->Op2 & 1))
> -		asm volatile("mrs %0, pmceid0_el0\n" : "=r" (pmceid));
> +		pmceid = read_sysreg(pmceid0_el0);
>  	else
> -		asm volatile("mrs %0, pmceid1_el0\n" : "=r" (pmceid));
> +		pmceid = read_sysreg(pmceid1_el0);
>  
>  	p->regval = pmceid;
>  
> @@ -1833,11 +1828,7 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
>  	static void get_##reg(struct kvm_vcpu *v,			\
>  			      const struct sys_reg_desc *r)		\
>  	{								\
> -		u64 val;						\
> -									\
> -		asm volatile("mrs %0, " __stringify(reg) "\n"		\
> -			     : "=r" (val));				\
> -		((struct sys_reg_desc *)r)->val = val;			\
> +		((struct sys_reg_desc *)r)->val = read_sysreg(reg);	\
>  	}
>  
>  FUNCTION_INVARIANT(midr_el1)
> diff --git a/arch/arm64/kvm/sys_regs_generic_v8.c b/arch/arm64/kvm/sys_regs_generic_v8.c
> index ed90578..46af718 100644
> --- a/arch/arm64/kvm/sys_regs_generic_v8.c
> +++ b/arch/arm64/kvm/sys_regs_generic_v8.c
> @@ -26,6 +26,7 @@
>  #include <asm/kvm_host.h>
>  #include <asm/kvm_emulate.h>
>  #include <asm/kvm_coproc.h>
> +#include <asm/sysreg.h>
>  #include <linux/init.h>
>  
>  #include "sys_regs.h"
> @@ -43,10 +44,7 @@ static bool access_actlr(struct kvm_vcpu *vcpu,
>  
>  static void reset_actlr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
>  {
> -	u64 actlr;
> -
> -	asm volatile("mrs %0, actlr_el1\n" : "=r" (actlr));
> -	vcpu_sys_reg(vcpu, ACTLR_EL1) = actlr;
> +	vcpu_sys_reg(vcpu, ACTLR_EL1) = read_sysreg(actlr_el1);
>  }
>  
>  /*
> -- 
> 1.9.1
> 

  reply	other threads:[~2016-09-08 13:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 12:55 [PATCH 0/6] arm64: replace open-coded {msr, mrs} with {read, write}_sysreg() Mark Rutland
2016-09-08 12:55 ` [PATCH 1/6] arm64: sysreg: allow write_sysreg to use XZR Mark Rutland
2016-09-08 14:12   ` Robin Murphy
2016-09-08 12:55 ` [PATCH 2/6] arm64: arch_timer: simplify accessors Mark Rutland
2016-09-08 12:55 ` [PATCH 3/6] arm64: dcc: " Mark Rutland
2016-09-08 12:55 ` [PATCH 4/6] arm64/kvm: use {read,write}_sysreg() Mark Rutland
2016-09-08 13:34   ` Christoffer Dall [this message]
2016-09-08 12:55 ` [PATCH 5/6] arm64: simplify sysreg manipulation Mark Rutland
2016-09-08 12:55 ` [PATCH 6/6] arm64: simplify contextidr_thread_switch Mark Rutland

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=20160908133446.GA9940@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).