From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 11/14] KVM: ARM: Demux CCSIDR in the userspace API
Date: Mon, 19 Nov 2012 15:03:49 +0000 [thread overview]
Message-ID: <20121119150349.GD3205@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <20121110154328.2836.78376.stgit@chazy-air>
On Sat, Nov 10, 2012 at 03:43:28PM +0000, Christoffer Dall wrote:
> The Cache Size Selection Register (CSSELR) selects the current Cache
> Size ID Register (CCSIDR). You write which cache you are interested
> in to CSSELR, and read the information out of CCSIDR.
>
> Which cache numbers are valid is known by reading the Cache Level ID
> Register (CLIDR).
>
> To export this state to userspace, we add a KVM_REG_ARM_DEMUX
> numberspace (17), which uses 8 bits to represent which register is
> being demultiplexed (0 for CCSIDR), and the lower 8 bits to represent
> this demultiplexing (in our case, the CSSELR value, which is 4 bits).
>
> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Rusty Russell <rusty.russell@linaro.org>
[...]
> Documentation/virtual/kvm/api.txt | 2
> arch/arm/include/uapi/asm/kvm.h | 9 ++
> arch/arm/kvm/coproc.c | 163 ++++++++++++++++++++++++++++++++++++-
> 3 files changed, 171 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index 9671cd2..bf8f99c 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -1804,6 +1804,8 @@ ARM 32-bit CP15 registers have the following id bit patterns:
> ARM 64-bit CP15 registers have the following id bit patterns:
> 0x4003 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
>
> +ARM CCSIDR registers are demultiplexed by CSSELR value:
> + 0x4002 0000 0011 00 <csselr:8>
>
> 4.69 KVM_GET_ONE_REG
>
> diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h
> index a807d9a..78a629c 100644
> --- a/arch/arm/include/uapi/asm/kvm.h
> +++ b/arch/arm/include/uapi/asm/kvm.h
> @@ -80,6 +80,15 @@ struct kvm_arch_memory_slot {
> #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT)
> #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / 4)
>
> +/* Some registers need more space to represent values. */
> +#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT)
> +#define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00
> +#define KVM_REG_ARM_DEMUX_ID_SHIFT 8
> +#define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
> +#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF
> +#define KVM_REG_ARM_DEMUX_VAL_SHIFT 0
> +
> +
> /* KVM_IRQ_LINE irq field index values */
> #define KVM_ARM_IRQ_TYPE_SHIFT 24
> #define KVM_ARM_IRQ_TYPE_MASK 0xff
> diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
> index 95a0f5e..9ce5861 100644
> --- a/arch/arm/kvm/coproc.c
> +++ b/arch/arm/kvm/coproc.c
> @@ -35,6 +35,12 @@
> * Co-processor emulation
> *****************************************************************************/
>
> +/* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */
> +static u32 cache_levels;
> +
> +/* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */
> +#define CSSELR_MAX 12
> +
> int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run)
> {
> kvm_inject_undefined(vcpu);
> @@ -548,11 +554,112 @@ static int set_invariant_cp15(u64 id, void __user *uaddr)
> return 0;
> }
>
> +static bool is_valid_cache(u32 val)
> +{
> + u32 level, ctype;
> +
> + if (val >= CSSELR_MAX)
> + return -ENOENT;
> +
> + /* Bottom bit is Instruction or Data bit. Next 3 bits are level. */
> + level = (val >> 1);
> + ctype = (cache_levels >> (level * 3)) & 7;
> +
> + switch (ctype) {
> + case 0: /* No cache */
> + return false;
> + case 1: /* Instruction cache only */
> + return (val & 1);
> + case 2: /* Data cache only */
> + case 4: /* Unified cache */
> + return !(val & 1);
> + case 3: /* Separate instruction and data caches */
> + return true;
> + default: /* Reserved: we can't know instruction or data. */
> + return false;
> + }
> +}
> +
> +/* Which cache CCSIDR represents depends on CSSELR value. */
> +static u32 get_ccsidr(u32 csselr)
> +{
> + u32 ccsidr;
> +
> + /* Make sure noone else changes CSSELR during this! */
> + local_irq_disable();
> + /* Put value into CSSELR */
> + asm volatile("mcr p15, 2, %0, c0, c0, 0" : : "r" (csselr));
You need an isb() here, otherwise you might still address the wrong
cache (the two accesses don't hazard in the CPU).
Will
WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Christoffer Dall <c.dall@virtualopensystems.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
Marcelo Tosatti <mtosatti@redhat.com>,
Rusty Russell <rusty.russell@linaro.org>
Subject: Re: [PATCH v4 11/14] KVM: ARM: Demux CCSIDR in the userspace API
Date: Mon, 19 Nov 2012 15:03:49 +0000 [thread overview]
Message-ID: <20121119150349.GD3205@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <20121110154328.2836.78376.stgit@chazy-air>
On Sat, Nov 10, 2012 at 03:43:28PM +0000, Christoffer Dall wrote:
> The Cache Size Selection Register (CSSELR) selects the current Cache
> Size ID Register (CCSIDR). You write which cache you are interested
> in to CSSELR, and read the information out of CCSIDR.
>
> Which cache numbers are valid is known by reading the Cache Level ID
> Register (CLIDR).
>
> To export this state to userspace, we add a KVM_REG_ARM_DEMUX
> numberspace (17), which uses 8 bits to represent which register is
> being demultiplexed (0 for CCSIDR), and the lower 8 bits to represent
> this demultiplexing (in our case, the CSSELR value, which is 4 bits).
>
> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Rusty Russell <rusty.russell@linaro.org>
[...]
> Documentation/virtual/kvm/api.txt | 2
> arch/arm/include/uapi/asm/kvm.h | 9 ++
> arch/arm/kvm/coproc.c | 163 ++++++++++++++++++++++++++++++++++++-
> 3 files changed, 171 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index 9671cd2..bf8f99c 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -1804,6 +1804,8 @@ ARM 32-bit CP15 registers have the following id bit patterns:
> ARM 64-bit CP15 registers have the following id bit patterns:
> 0x4003 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
>
> +ARM CCSIDR registers are demultiplexed by CSSELR value:
> + 0x4002 0000 0011 00 <csselr:8>
>
> 4.69 KVM_GET_ONE_REG
>
> diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h
> index a807d9a..78a629c 100644
> --- a/arch/arm/include/uapi/asm/kvm.h
> +++ b/arch/arm/include/uapi/asm/kvm.h
> @@ -80,6 +80,15 @@ struct kvm_arch_memory_slot {
> #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT)
> #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / 4)
>
> +/* Some registers need more space to represent values. */
> +#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT)
> +#define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00
> +#define KVM_REG_ARM_DEMUX_ID_SHIFT 8
> +#define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
> +#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF
> +#define KVM_REG_ARM_DEMUX_VAL_SHIFT 0
> +
> +
> /* KVM_IRQ_LINE irq field index values */
> #define KVM_ARM_IRQ_TYPE_SHIFT 24
> #define KVM_ARM_IRQ_TYPE_MASK 0xff
> diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
> index 95a0f5e..9ce5861 100644
> --- a/arch/arm/kvm/coproc.c
> +++ b/arch/arm/kvm/coproc.c
> @@ -35,6 +35,12 @@
> * Co-processor emulation
> *****************************************************************************/
>
> +/* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */
> +static u32 cache_levels;
> +
> +/* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */
> +#define CSSELR_MAX 12
> +
> int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run)
> {
> kvm_inject_undefined(vcpu);
> @@ -548,11 +554,112 @@ static int set_invariant_cp15(u64 id, void __user *uaddr)
> return 0;
> }
>
> +static bool is_valid_cache(u32 val)
> +{
> + u32 level, ctype;
> +
> + if (val >= CSSELR_MAX)
> + return -ENOENT;
> +
> + /* Bottom bit is Instruction or Data bit. Next 3 bits are level. */
> + level = (val >> 1);
> + ctype = (cache_levels >> (level * 3)) & 7;
> +
> + switch (ctype) {
> + case 0: /* No cache */
> + return false;
> + case 1: /* Instruction cache only */
> + return (val & 1);
> + case 2: /* Data cache only */
> + case 4: /* Unified cache */
> + return !(val & 1);
> + case 3: /* Separate instruction and data caches */
> + return true;
> + default: /* Reserved: we can't know instruction or data. */
> + return false;
> + }
> +}
> +
> +/* Which cache CCSIDR represents depends on CSSELR value. */
> +static u32 get_ccsidr(u32 csselr)
> +{
> + u32 ccsidr;
> +
> + /* Make sure noone else changes CSSELR during this! */
> + local_irq_disable();
> + /* Put value into CSSELR */
> + asm volatile("mcr p15, 2, %0, c0, c0, 0" : : "r" (csselr));
You need an isb() here, otherwise you might still address the wrong
cache (the two accesses don't hazard in the CPU).
Will
next prev parent reply other threads:[~2012-11-19 15:03 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-10 15:42 [PATCH v4 00/14] KVM/ARM Implementation Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 01/14] ARM: Add page table and page defines needed by KVM Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:14 ` Will Deacon
2012-11-19 14:14 ` Will Deacon
2012-11-29 15:57 ` Christoffer Dall
2012-11-29 15:57 ` Christoffer Dall
2012-11-30 11:46 ` Will Deacon
2012-11-30 11:46 ` Will Deacon
2012-11-30 15:54 ` Christoffer Dall
2012-11-30 15:54 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 02/14] ARM: Section based HYP idmap Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:16 ` Will Deacon
2012-11-19 14:16 ` Will Deacon
2012-11-29 18:59 ` Christoffer Dall
2012-11-29 18:59 ` Christoffer Dall
2012-11-30 10:58 ` Will Deacon
2012-11-30 10:58 ` Will Deacon
2012-11-30 16:29 ` Christoffer Dall
2012-11-30 16:29 ` Christoffer Dall
2012-11-19 14:25 ` Rob Herring
2012-11-19 14:25 ` Rob Herring
2012-11-10 15:42 ` [PATCH v4 03/14] ARM: Factor out cpuid implementor and part number Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:21 ` Will Deacon
2012-11-19 14:21 ` Will Deacon
2012-11-29 21:38 ` Christoffer Dall
2012-11-29 21:38 ` Christoffer Dall
2012-11-30 10:21 ` Will Deacon
2012-11-30 10:21 ` Will Deacon
2012-11-30 15:42 ` Christoffer Dall
2012-11-30 15:42 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 04/14] KVM: ARM: Initial skeleton to compile KVM support Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:41 ` Will Deacon
2012-11-19 14:41 ` Will Deacon
2012-11-29 22:36 ` Christoffer Dall
2012-11-29 22:36 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 05/14] KVM: ARM: Hypervisor inititalization Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:51 ` Will Deacon
2012-11-19 14:51 ` Will Deacon
2012-11-19 15:27 ` Cyril Chemparathy
2012-11-19 15:27 ` Cyril Chemparathy
2012-11-30 5:41 ` Christoffer Dall
2012-11-30 5:41 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 06/14] KVM: ARM: Memory virtualization setup Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:53 ` Will Deacon
2012-11-19 14:53 ` Will Deacon
2012-11-19 15:05 ` Christoffer Dall
2012-11-19 15:05 ` Christoffer Dall
2012-11-10 15:42 ` [PATCH v4 07/14] KVM: ARM: Inject IRQs and FIQs from userspace Christoffer Dall
2012-11-10 15:42 ` Christoffer Dall
2012-11-19 14:55 ` Will Deacon
2012-11-19 14:55 ` Will Deacon
2012-11-19 15:04 ` Christoffer Dall
2012-11-19 15:04 ` Christoffer Dall
2012-11-19 15:26 ` Will Deacon
2012-11-19 15:26 ` Will Deacon
2012-11-19 16:09 ` Christoffer Dall
2012-11-19 16:09 ` Christoffer Dall
2012-11-19 16:21 ` Will Deacon
2012-11-19 16:21 ` Will Deacon
2012-11-30 6:13 ` Christoffer Dall
2012-11-30 6:13 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 08/14] KVM: ARM: World-switch implementation Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 14:57 ` Will Deacon
2012-11-19 14:57 ` Will Deacon
2012-11-30 6:37 ` Christoffer Dall
2012-11-30 6:37 ` Christoffer Dall
2012-11-30 15:15 ` Will Deacon
2012-11-30 15:15 ` Will Deacon
2012-11-30 16:47 ` Christoffer Dall
2012-11-30 16:47 ` Christoffer Dall
2012-11-30 17:14 ` Will Deacon
2012-11-30 17:14 ` Will Deacon
2012-11-30 18:49 ` Christoffer Dall
2012-11-30 18:49 ` Christoffer Dall
2012-12-03 10:33 ` Marc Zyngier
2012-12-03 10:33 ` Marc Zyngier
2012-12-03 15:05 ` Christoffer Dall
2012-12-03 15:05 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 09/14] KVM: ARM: Emulation framework and CP15 emulation Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 15:01 ` Will Deacon
2012-11-19 15:01 ` Will Deacon
2012-11-19 15:27 ` [kvmarm] " Peter Maydell
2012-11-19 15:27 ` Peter Maydell
2012-11-20 2:18 ` Rusty Russell
2012-11-20 2:18 ` Rusty Russell
2012-11-30 20:22 ` Christoffer Dall
2012-11-30 20:22 ` Christoffer Dall
2012-12-03 11:05 ` Will Deacon
2012-12-03 11:05 ` Will Deacon
2012-12-03 19:09 ` Christoffer Dall
2012-12-03 19:09 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 10/14] KVM: ARM: User space API for getting/setting co-proc registers Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 15:02 ` Will Deacon
2012-11-19 15:02 ` Will Deacon
2012-11-30 6:42 ` Christoffer Dall
2012-11-30 6:42 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 11/14] KVM: ARM: Demux CCSIDR in the userspace API Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 15:03 ` Will Deacon [this message]
2012-11-19 15:03 ` Will Deacon
2012-11-30 6:45 ` Christoffer Dall
2012-11-30 6:45 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 12/14] KVM: ARM: VFP userspace interface Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 13/14] KVM: ARM: Handle guest faults in KVM Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 15:07 ` Will Deacon
2012-11-19 15:07 ` Will Deacon
2012-11-30 21:40 ` Christoffer Dall
2012-11-30 21:40 ` Christoffer Dall
2012-12-03 13:06 ` Will Deacon
2012-12-03 13:06 ` Will Deacon
2012-12-03 15:02 ` Christoffer Dall
2012-12-03 15:02 ` Christoffer Dall
2012-11-10 15:43 ` [PATCH v4 14/14] KVM: ARM: Handle I/O aborts Christoffer Dall
2012-11-10 15:43 ` Christoffer Dall
2012-11-19 15:09 ` Will Deacon
2012-11-19 15:09 ` Will Deacon
2012-11-30 14:46 ` Dave Martin
2012-11-30 14:46 ` Dave Martin
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=20121119150349.GD3205@mudshark.cambridge.arm.com \
--to=will.deacon@arm.com \
--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.