[RFC PATCH 0/5] arm/arm64: Making HYP vgic/timer save/restore common

STALE3900d

Revision rfc of 2 in this series.

9 messages, 2 authors, 2016-02-10 · open the first message on its own page

[RFC PATCH 0/5] arm/arm64: Making HYP vgic/timer save/restore common

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:00

With the current state of the C conversion of arm and arm64 world
switches, we are still unable to share some of the most obvious
candidates (GIC and timer save/restore). In order to reduce the bloat,
let's move these files to a common location (virt/kvm/arm/hyp).

The changes are extremely mechanical, with a small hack to deal with
system register names on the 32bit side (I've decided to align on the
64bit names).

I'd like to know what people think of the common location. Does it
makes sense to have a "hyp" subdirectory to indicate that this is not
"normal" kernel code?

These patches are on top of 4.5-rc1, plus the VHE and 32bit WS rewrite
patches, and I've pushed out a branch at

git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/mov-hyp

Marc Zyngier (5):
  arm64: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h
  arm64: KVM: Move vgic-v2 and timer save/restore to virt/kvm/arm/hyp
  ARM: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h
  ARM: KVM: Use common version of vgic-v2-sr.c
  ARM: KVM: Use common version of timer-sr.c

 arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h}  |  9 +++
 arch/arm/kvm/hyp/Makefile                          |  7 +-
 arch/arm/kvm/hyp/banked-sr.c                       |  2 +-
 arch/arm/kvm/hyp/cp15-sr.c                         |  2 +-
 arch/arm/kvm/hyp/switch.c                          |  2 +-
 arch/arm/kvm/hyp/timer-sr.c                        | 71 ------------------
 arch/arm/kvm/hyp/tlb.c                             |  2 +-
 arch/arm/kvm/hyp/vgic-v2-sr.c                      | 84 ----------------------
 .../arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} |  0
 arch/arm64/kvm/hyp/Makefile                        |  7 +-
 arch/arm64/kvm/hyp/debug-sr.c                      |  4 +-
 arch/arm64/kvm/hyp/switch.c                        |  3 +-
 arch/arm64/kvm/hyp/sysreg-sr.c                     |  4 +-
 arch/arm64/kvm/hyp/tlb.c                           |  2 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c                    |  4 +-
 {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c    |  4 +-
 {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c  |  4 +-
 17 files changed, 30 insertions(+), 181 deletions(-)
 rename arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (93%)
 delete mode 100644 arch/arm/kvm/hyp/timer-sr.c
 delete mode 100644 arch/arm/kvm/hyp/vgic-v2-sr.c
 rename arch/arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (100%)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c (97%)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c (98%)

-- 
2.1.4

[RFC PATCH 1/5] arm64: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:01

In order to be able to move code outside of kvm/hyp, we need to make
the global hyp.h file accessible from a standard location.

include/asm/kvm_hyp.h seems good enough.

Signed-off-by: Marc Zyngier <redacted>
---
 arch/arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} | 0
 arch/arm64/kvm/hyp/debug-sr.c                       | 4 +---
 arch/arm64/kvm/hyp/switch.c                         | 3 +--
 arch/arm64/kvm/hyp/sysreg-sr.c                      | 4 +---
 arch/arm64/kvm/hyp/timer-sr.c                       | 4 +---
 arch/arm64/kvm/hyp/tlb.c                            | 2 +-
 arch/arm64/kvm/hyp/vgic-v2-sr.c                     | 4 +---
 arch/arm64/kvm/hyp/vgic-v3-sr.c                     | 4 +---
 8 files changed, 7 insertions(+), 18 deletions(-)
 rename arch/arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (100%)
diff --git a/arch/arm64/kvm/hyp/hyp.h b/arch/arm64/include/asm/kvm_hyp.h
similarity index 100%
rename from arch/arm64/kvm/hyp/hyp.h
rename to arch/arm64/include/asm/kvm_hyp.h
diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c
index c9c1e97..053cf8b 100644
--- a/arch/arm64/kvm/hyp/debug-sr.c
+++ b/arch/arm64/kvm/hyp/debug-sr.c
@@ -19,9 +19,7 @@
 #include <linux/kvm_host.h>
 
 #include <asm/kvm_asm.h>
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 #define read_debug(r,n)		read_sysreg(r##n##_el1)
 #define write_debug(v,r,n)	write_sysreg(v, r##n##_el1)
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index df2cce9..c5222da 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -17,8 +17,7 @@
 
 #include <linux/types.h>
 #include <asm/kvm_asm.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 static bool __hyp_text __fpsimd_enabled_nvhe(void)
 {
diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c
index 36bbdec..8cc3872 100644
--- a/arch/arm64/kvm/hyp/sysreg-sr.c
+++ b/arch/arm64/kvm/hyp/sysreg-sr.c
@@ -19,9 +19,7 @@
 #include <linux/kvm_host.h>
 
 #include <asm/kvm_asm.h>
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /* Yes, this does nothing, on purpose */
 static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { }
diff --git a/arch/arm64/kvm/hyp/timer-sr.c b/arch/arm64/kvm/hyp/timer-sr.c
index f276d9e..ea00d69 100644
--- a/arch/arm64/kvm/hyp/timer-sr.c
+++ b/arch/arm64/kvm/hyp/timer-sr.c
@@ -19,9 +19,7 @@
 #include <linux/compiler.h>
 #include <linux/kvm_host.h>
 
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /* vcpu is already in the HYP VA space */
 void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu)
diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c
index 2a7e0d8..be8177c 100644
--- a/arch/arm64/kvm/hyp/tlb.c
+++ b/arch/arm64/kvm/hyp/tlb.c
@@ -15,7 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
 {
diff --git a/arch/arm64/kvm/hyp/vgic-v2-sr.c b/arch/arm64/kvm/hyp/vgic-v2-sr.c
index e717612..9514a7d 100644
--- a/arch/arm64/kvm/hyp/vgic-v2-sr.c
+++ b/arch/arm64/kvm/hyp/vgic-v2-sr.c
@@ -19,9 +19,7 @@
 #include <linux/irqchip/arm-gic.h>
 #include <linux/kvm_host.h>
 
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /* vcpu is already in the HYP VA space */
 void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu)
diff --git a/arch/arm64/kvm/hyp/vgic-v3-sr.c b/arch/arm64/kvm/hyp/vgic-v3-sr.c
index 9142e082..3a26799 100644
--- a/arch/arm64/kvm/hyp/vgic-v3-sr.c
+++ b/arch/arm64/kvm/hyp/vgic-v3-sr.c
@@ -19,9 +19,7 @@
 #include <linux/irqchip/arm-gic-v3.h>
 #include <linux/kvm_host.h>
 
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 #define vtr_to_max_lr_idx(v)		((v) & 0xf)
 #define vtr_to_nr_pri_bits(v)		(((u32)(v) >> 29) + 1)
-- 
2.1.4

[RFC PATCH 2/5] arm64: KVM: Move vgic-v2 and timer save/restore to virt/kvm/arm/hyp

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:02

We already have virt/kvm/arm/ containing timer and vgic stuff.
Add yet another subdirectory to contain the hyp-specific files
(timer and vgic again).

Signed-off-by: Marc Zyngier <redacted>
---
 arch/arm64/kvm/hyp/Makefile                       | 7 +++++--
 {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c   | 0
 {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c | 0
 3 files changed, 5 insertions(+), 2 deletions(-)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c (100%)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c (100%)
diff --git a/arch/arm64/kvm/hyp/Makefile b/arch/arm64/kvm/hyp/Makefile
index 826032b..5cf4718 100644
--- a/arch/arm64/kvm/hyp/Makefile
+++ b/arch/arm64/kvm/hyp/Makefile
@@ -2,9 +2,12 @@
 # Makefile for Kernel-based Virtual Machine module, HYP part
 #
 
-obj-$(CONFIG_KVM_ARM_HOST) += vgic-v2-sr.o
+KVM=../../../../virt/kvm
+
+obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v2-sr.o
+obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o
+
 obj-$(CONFIG_KVM_ARM_HOST) += vgic-v3-sr.o
-obj-$(CONFIG_KVM_ARM_HOST) += timer-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += sysreg-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += debug-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += entry.o
diff --git a/arch/arm64/kvm/hyp/timer-sr.c b/virt/kvm/arm/hyp/timer-sr.c
similarity index 100%
rename from arch/arm64/kvm/hyp/timer-sr.c
rename to virt/kvm/arm/hyp/timer-sr.c
diff --git a/arch/arm64/kvm/hyp/vgic-v2-sr.c b/virt/kvm/arm/hyp/vgic-v2-sr.c
similarity index 100%
rename from arch/arm64/kvm/hyp/vgic-v2-sr.c
rename to virt/kvm/arm/hyp/vgic-v2-sr.c
-- 
2.1.4

[RFC PATCH 3/5] ARM: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:03

In order to be able to use the code located in virt/kvm/arm/hyp,
we need to make the global hyp.h file accessible from include/asm,
similar to what we did for arm64.

Signed-off-by: Marc Zyngier <redacted>
---
 arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} | 0
 arch/arm/kvm/hyp/banked-sr.c                      | 2 +-
 arch/arm/kvm/hyp/cp15-sr.c                        | 2 +-
 arch/arm/kvm/hyp/switch.c                         | 2 +-
 arch/arm/kvm/hyp/timer-sr.c                       | 4 +---
 arch/arm/kvm/hyp/tlb.c                            | 2 +-
 arch/arm/kvm/hyp/vgic-v2-sr.c                     | 4 +---
 7 files changed, 6 insertions(+), 10 deletions(-)
 rename arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (100%)
diff --git a/arch/arm/kvm/hyp/hyp.h b/arch/arm/include/asm/kvm_hyp.h
similarity index 100%
rename from arch/arm/kvm/hyp/hyp.h
rename to arch/arm/include/asm/kvm_hyp.h
diff --git a/arch/arm/kvm/hyp/banked-sr.c b/arch/arm/kvm/hyp/banked-sr.c
index d02dc80..111bda8 100644
--- a/arch/arm/kvm/hyp/banked-sr.c
+++ b/arch/arm/kvm/hyp/banked-sr.c
@@ -18,7 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 __asm__(".arch_extension     virt");
 
diff --git a/arch/arm/kvm/hyp/cp15-sr.c b/arch/arm/kvm/hyp/cp15-sr.c
index 732abbc..c478281 100644
--- a/arch/arm/kvm/hyp/cp15-sr.c
+++ b/arch/arm/kvm/hyp/cp15-sr.c
@@ -18,7 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx)
 {
diff --git a/arch/arm/kvm/hyp/switch.c b/arch/arm/kvm/hyp/switch.c
index 7325ad3..17c5e57 100644
--- a/arch/arm/kvm/hyp/switch.c
+++ b/arch/arm/kvm/hyp/switch.c
@@ -16,7 +16,7 @@
  */
 
 #include <asm/kvm_asm.h>
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 __asm__(".arch_extension     virt");
 
diff --git a/arch/arm/kvm/hyp/timer-sr.c b/arch/arm/kvm/hyp/timer-sr.c
index d7535fd..2bb0c92 100644
--- a/arch/arm/kvm/hyp/timer-sr.c
+++ b/arch/arm/kvm/hyp/timer-sr.c
@@ -19,9 +19,7 @@
 #include <linux/compiler.h>
 #include <linux/kvm_host.h>
 
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /* vcpu is already in the HYP VA space */
 void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu)
diff --git a/arch/arm/kvm/hyp/tlb.c b/arch/arm/kvm/hyp/tlb.c
index 3854e31..0e46d1b 100644
--- a/arch/arm/kvm/hyp/tlb.c
+++ b/arch/arm/kvm/hyp/tlb.c
@@ -18,7 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /**
  * Flush per-VMID TLBs
diff --git a/arch/arm/kvm/hyp/vgic-v2-sr.c b/arch/arm/kvm/hyp/vgic-v2-sr.c
index e717612..9514a7d 100644
--- a/arch/arm/kvm/hyp/vgic-v2-sr.c
+++ b/arch/arm/kvm/hyp/vgic-v2-sr.c
@@ -19,9 +19,7 @@
 #include <linux/irqchip/arm-gic.h>
 #include <linux/kvm_host.h>
 
-#include <asm/kvm_mmu.h>
-
-#include "hyp.h"
+#include <asm/kvm_hyp.h>
 
 /* vcpu is already in the HYP VA space */
 void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu)
-- 
2.1.4

[RFC PATCH 4/5] ARM: KVM: Use common version of vgic-v2-sr.c

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:04

No need to keep our own private version, the common one is
strictly identical.

Signed-off-by: Marc Zyngier <redacted>
---
 arch/arm/kvm/hyp/Makefile     |  5 ++-
 arch/arm/kvm/hyp/vgic-v2-sr.c | 82 -------------------------------------------
 2 files changed, 4 insertions(+), 83 deletions(-)
 delete mode 100644 arch/arm/kvm/hyp/vgic-v2-sr.c
diff --git a/arch/arm/kvm/hyp/Makefile b/arch/arm/kvm/hyp/Makefile
index a7d3a7e..34645a4 100644
--- a/arch/arm/kvm/hyp/Makefile
+++ b/arch/arm/kvm/hyp/Makefile
@@ -2,10 +2,13 @@
 # Makefile for Kernel-based Virtual Machine module, HYP part
 #
 
+KVM=../../../../virt/kvm
+
+obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v2-sr.o
+
 obj-$(CONFIG_KVM_ARM_HOST) += tlb.o
 obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += timer-sr.o
-obj-$(CONFIG_KVM_ARM_HOST) += vgic-v2-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += vfp.o
 obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += entry.o
diff --git a/arch/arm/kvm/hyp/vgic-v2-sr.c b/arch/arm/kvm/hyp/vgic-v2-sr.c
deleted file mode 100644
index 9514a7d..0000000
--- a/arch/arm/kvm/hyp/vgic-v2-sr.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2012-2015 - ARM Ltd
- * Author: Marc Zyngier <marc.zyngier@arm.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <linux/compiler.h>
-#include <linux/irqchip/arm-gic.h>
-#include <linux/kvm_host.h>
-
-#include <asm/kvm_hyp.h>
-
-/* vcpu is already in the HYP VA space */
-void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu)
-{
-	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
-	struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
-	struct vgic_dist *vgic = &kvm->arch.vgic;
-	void __iomem *base = kern_hyp_va(vgic->vctrl_base);
-	u32 eisr0, eisr1, elrsr0, elrsr1;
-	int i, nr_lr;
-
-	if (!base)
-		return;
-
-	nr_lr = vcpu->arch.vgic_cpu.nr_lr;
-	cpu_if->vgic_vmcr = readl_relaxed(base + GICH_VMCR);
-	cpu_if->vgic_misr = readl_relaxed(base + GICH_MISR);
-	eisr0  = readl_relaxed(base + GICH_EISR0);
-	elrsr0 = readl_relaxed(base + GICH_ELRSR0);
-	if (unlikely(nr_lr > 32)) {
-		eisr1  = readl_relaxed(base + GICH_EISR1);
-		elrsr1 = readl_relaxed(base + GICH_ELRSR1);
-	} else {
-		eisr1 = elrsr1 = 0;
-	}
-#ifdef CONFIG_CPU_BIG_ENDIAN
-	cpu_if->vgic_eisr  = ((u64)eisr0 << 32) | eisr1;
-	cpu_if->vgic_elrsr = ((u64)elrsr0 << 32) | elrsr1;
-#else
-	cpu_if->vgic_eisr  = ((u64)eisr1 << 32) | eisr0;
-	cpu_if->vgic_elrsr = ((u64)elrsr1 << 32) | elrsr0;
-#endif
-	cpu_if->vgic_apr    = readl_relaxed(base + GICH_APR);
-
-	writel_relaxed(0, base + GICH_HCR);
-
-	for (i = 0; i < nr_lr; i++)
-		cpu_if->vgic_lr[i] = readl_relaxed(base + GICH_LR0 + (i * 4));
-}
-
-/* vcpu is already in the HYP VA space */
-void __hyp_text __vgic_v2_restore_state(struct kvm_vcpu *vcpu)
-{
-	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
-	struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
-	struct vgic_dist *vgic = &kvm->arch.vgic;
-	void __iomem *base = kern_hyp_va(vgic->vctrl_base);
-	int i, nr_lr;
-
-	if (!base)
-		return;
-
-	writel_relaxed(cpu_if->vgic_hcr, base + GICH_HCR);
-	writel_relaxed(cpu_if->vgic_vmcr, base + GICH_VMCR);
-	writel_relaxed(cpu_if->vgic_apr, base + GICH_APR);
-
-	nr_lr = vcpu->arch.vgic_cpu.nr_lr;
-	for (i = 0; i < nr_lr; i++)
-		writel_relaxed(cpu_if->vgic_lr[i], base + GICH_LR0 + (i * 4));
-}
-- 
2.1.4

[RFC PATCH 5/5] ARM: KVM: Use common version of timer-sr.c

From: Marc Zyngier <hidden>
Date: 2016-01-28 15:56:05

Using the common HYP timer code is a bit more tricky, since we
use system register names. Nothing a set of macros cannot
work around...

Signed-off-by: Marc Zyngier <redacted>
---
 arch/arm/include/asm/kvm_hyp.h |  9 ++++++
 arch/arm/kvm/hyp/Makefile      |  2 +-
 arch/arm/kvm/hyp/timer-sr.c    | 69 ------------------------------------------
 3 files changed, 10 insertions(+), 70 deletions(-)
 delete mode 100644 arch/arm/kvm/hyp/timer-sr.c
diff --git a/arch/arm/include/asm/kvm_hyp.h b/arch/arm/include/asm/kvm_hyp.h
index 8bbd2a7..dff2f95 100644
--- a/arch/arm/include/asm/kvm_hyp.h
+++ b/arch/arm/include/asm/kvm_hyp.h
@@ -102,6 +102,15 @@
 
 #define VFP_FPEXC	__ACCESS_VFP(FPEXC)
 
+/* AArch64 compatibility macros, only for the timer so far */
+#define read_sysreg_el0(r)		read_sysreg(r##_el0)
+#define write_sysreg_el0(v, r)		write_sysreg(v, r##_el0)
+
+#define cntv_ctl_el0			CNTV_CTL
+#define cntv_cval_el0			CNTV_CVAL
+#define cntvoff_el2			CNTVOFF
+#define cnthctl_el2			CNTHCTL
+
 void __timer_save_state(struct kvm_vcpu *vcpu);
 void __timer_restore_state(struct kvm_vcpu *vcpu);
 
diff --git a/arch/arm/kvm/hyp/Makefile b/arch/arm/kvm/hyp/Makefile
index 34645a4..2d6c33e 100644
--- a/arch/arm/kvm/hyp/Makefile
+++ b/arch/arm/kvm/hyp/Makefile
@@ -5,10 +5,10 @@
 KVM=../../../../virt/kvm
 
 obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v2-sr.o
+obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o
 
 obj-$(CONFIG_KVM_ARM_HOST) += tlb.o
 obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o
-obj-$(CONFIG_KVM_ARM_HOST) += timer-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += vfp.o
 obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o
 obj-$(CONFIG_KVM_ARM_HOST) += entry.o
diff --git a/arch/arm/kvm/hyp/timer-sr.c b/arch/arm/kvm/hyp/timer-sr.c
deleted file mode 100644
index 2bb0c92..0000000
--- a/arch/arm/kvm/hyp/timer-sr.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2012-2015 - ARM Ltd
- * Author: Marc Zyngier <marc.zyngier@arm.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <clocksource/arm_arch_timer.h>
-#include <linux/compiler.h>
-#include <linux/kvm_host.h>
-
-#include <asm/kvm_hyp.h>
-
-/* vcpu is already in the HYP VA space */
-void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu)
-{
-	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
-	struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
-	u64 val;
-
-	if (kvm->arch.timer.enabled) {
-		timer->cntv_ctl = read_sysreg(CNTV_CTL);
-		timer->cntv_cval = read_sysreg(CNTV_CVAL);
-	}
-
-	/* Disable the virtual timer */
-	write_sysreg(0, CNTV_CTL);
-
-	/* Allow physical timer/counter access for the host */
-	val = read_sysreg(CNTHCTL);
-	val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
-	write_sysreg(val, CNTHCTL);
-
-	/* Clear cntvoff for the host */
-	write_sysreg(0, CNTVOFF);
-}
-
-void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu)
-{
-	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
-	struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
-	u64 val;
-
-	/*
-	 * Disallow physical timer access for the guest
-	 * Physical counter access is allowed
-	 */
-	val = read_sysreg(CNTHCTL);
-	val &= ~CNTHCTL_EL1PCEN;
-	val |= CNTHCTL_EL1PCTEN;
-	write_sysreg(val, CNTHCTL);
-
-	if (kvm->arch.timer.enabled) {
-		write_sysreg(kvm->arch.timer.cntvoff, CNTVOFF);
-		write_sysreg(timer->cntv_cval, CNTV_CVAL);
-		isb();
-		write_sysreg(timer->cntv_ctl, CNTV_CTL);
-	}
-}
-- 
2.1.4

[RFC PATCH 0/5] arm/arm64: Making HYP vgic/timer save/restore common

From: Christoffer Dall <hidden>
Date: 2016-02-09 19:06:16

On Thu, Jan 28, 2016 at 03:56:00PM +0000, Marc Zyngier wrote:
With the current state of the C conversion of arm and arm64 world
switches, we are still unable to share some of the most obvious
candidates (GIC and timer save/restore). In order to reduce the bloat,
let's move these files to a common location (virt/kvm/arm/hyp).

The changes are extremely mechanical, with a small hack to deal with
system register names on the 32bit side (I've decided to align on the
64bit names).

I'd like to know what people think of the common location. Does it
makes sense to have a "hyp" subdirectory to indicate that this is not
"normal" kernel code?
I think so, it means to me typically executing in "hyp/el2" or just
low-level hypervisor logic, in the case of VHE.

These patches are on top of 4.5-rc1, plus the VHE and 32bit WS rewrite
patches, and I've pushed out a branch at

git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/mov-hyp

Marc Zyngier (5):
  arm64: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h
  arm64: KVM: Move vgic-v2 and timer save/restore to virt/kvm/arm/hyp
  ARM: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h
  ARM: KVM: Use common version of vgic-v2-sr.c
  ARM: KVM: Use common version of timer-sr.c

 arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h}  |  9 +++
 arch/arm/kvm/hyp/Makefile                          |  7 +-
 arch/arm/kvm/hyp/banked-sr.c                       |  2 +-
 arch/arm/kvm/hyp/cp15-sr.c                         |  2 +-
 arch/arm/kvm/hyp/switch.c                          |  2 +-
 arch/arm/kvm/hyp/timer-sr.c                        | 71 ------------------
 arch/arm/kvm/hyp/tlb.c                             |  2 +-
 arch/arm/kvm/hyp/vgic-v2-sr.c                      | 84 ----------------------
 .../arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} |  0
 arch/arm64/kvm/hyp/Makefile                        |  7 +-
 arch/arm64/kvm/hyp/debug-sr.c                      |  4 +-
 arch/arm64/kvm/hyp/switch.c                        |  3 +-
 arch/arm64/kvm/hyp/sysreg-sr.c                     |  4 +-
 arch/arm64/kvm/hyp/tlb.c                           |  2 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c                    |  4 +-
 {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c    |  4 +-
 {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c  |  4 +-
 17 files changed, 30 insertions(+), 181 deletions(-)
 rename arch/arm/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (93%)
 delete mode 100644 arch/arm/kvm/hyp/timer-sr.c
 delete mode 100644 arch/arm/kvm/hyp/vgic-v2-sr.c
 rename arch/arm64/{kvm/hyp/hyp.h => include/asm/kvm_hyp.h} (100%)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/timer-sr.c (97%)
 rename {arch/arm64/kvm => virt/kvm/arm}/hyp/vgic-v2-sr.c (98%)

-- 
2.1.4

[RFC PATCH 0/5] arm/arm64: Making HYP vgic/timer save/restore common

From: Christoffer Dall <hidden>
Date: 2016-02-09 20:38:03

On Thu, Jan 28, 2016 at 03:56:00PM +0000, Marc Zyngier wrote:
With the current state of the C conversion of arm and arm64 world
switches, we are still unable to share some of the most obvious
candidates (GIC and timer save/restore). In order to reduce the bloat,
let's move these files to a common location (virt/kvm/arm/hyp).

The changes are extremely mechanical, with a small hack to deal with
system register names on the 32bit side (I've decided to align on the
64bit names).

I'd like to know what people think of the common location. Does it
makes sense to have a "hyp" subdirectory to indicate that this is not
"normal" kernel code?

These patches are on top of 4.5-rc1, plus the VHE and 32bit WS rewrite
patches, and I've pushed out a branch at

git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/mov-hyp
ack on this series, tested on TC2 and Mustang as well.

-Christoffer

[RFC PATCH 0/5] arm/arm64: Making HYP vgic/timer save/restore common

From: Marc Zyngier <hidden>
Date: 2016-02-10 16:59:54

On 09/02/16 20:38, Christoffer Dall wrote:
On Thu, Jan 28, 2016 at 03:56:00PM +0000, Marc Zyngier wrote:
quoted
With the current state of the C conversion of arm and arm64 world
switches, we are still unable to share some of the most obvious
candidates (GIC and timer save/restore). In order to reduce the bloat,
let's move these files to a common location (virt/kvm/arm/hyp).

The changes are extremely mechanical, with a small hack to deal with
system register names on the 32bit side (I've decided to align on the
64bit names).

I'd like to know what people think of the common location. Does it
makes sense to have a "hyp" subdirectory to indicate that this is not
"normal" kernel code?

These patches are on top of 4.5-rc1, plus the VHE and 32bit WS rewrite
patches, and I've pushed out a branch at

git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/mov-hyp
ack on this series, tested on TC2 and Mustang as well.
Thanks for all the reviewing!

I'll rebase it once the dust settles on VHE and WSINC, and that will
form one bloody long series...

	M.
-- 
Jazz is not dead. It just smells funny...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help