Skip to content

Commit 8b5628a

Browse files
committed
Merge tag 'virt' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull ARM virtualization changes: "This contains parts of the ARM KVM support that have dependencies on other patches merged through the arm-soc tree. In combination with patches coming through Russell's tree, this will finally add full support for the kernel based virtual machine on ARM, which has been awaited for some time now. Further, we now have a separate platform for virtual machines and qemu booting that is used by both Xen and KVM, separating these from the Versatile Express reference implementation. Obviously, this new platform is multiplatform capable so it can be combined with existing machines in the same kernel." * tag 'virt' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (38 commits) ARM: arch_timer: include linux/errno.h arm: arch_timer: add missing inline in stub function ARM: KVM: arch_timers: Wire the init code and config option ARM: KVM: arch_timers: Add timer world switch ARM: KVM: arch_timers: Add guest timer core support ARM: KVM: Add VGIC configuration option ARM: KVM: VGIC initialisation code ARM: KVM: VGIC control interface world switch ARM: KVM: VGIC interrupt injection ARM: KVM: vgic: retire queued, disabled interrupts ARM: KVM: VGIC virtual CPU interface management ARM: KVM: VGIC distributor handling ARM: KVM: VGIC accept vcpu and dist base addresses from user space ARM: KVM: Initial VGIC infrastructure code ARM: KVM: Keep track of currently running vcpus KVM: ARM: Introduce KVM_ARM_SET_DEVICE_ADDR ioctl ARM: gic: add __ASSEMBLY__ guard to C definitions ARM: gic: define GICH offsets for VGIC support ARM: gic: add missing distributor defintions ARM: mach-virt: fixup machine descriptor after removal of sys_timer ...
2 parents a8f3740 + fe7dc72 commit 8b5628a

39 files changed

Lines changed: 3466 additions & 878 deletions

File tree

‎Documentation/devicetree/bindings/arm/arch_timer.txt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
* ARM architected timer
22

3-
ARM Cortex-A7 and Cortex-A15 have a per-core architected timer, which
4-
provides per-cpu timers.
3+
ARM cores may have a per-core architected timer, which provides per-cpu timers.
54

65
The timer is attached to a GIC to deliver its per-processor interrupts.
76

87
** Timer node properties:
98

10-
- compatible : Should at least contain "arm,armv7-timer".
9+
- compatible : Should at least contain one of
10+
"arm,armv7-timer"
11+
"arm,armv8-timer"
1112

1213
- interrupts : Interrupt list for secure, non-secure, virtual and
1314
hypervisor timers, in that order.

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,44 @@ This ioctl returns the guest registers that are supported for the
22102210
KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
22112211

22122212

2213+
4.80 KVM_ARM_SET_DEVICE_ADDR
2214+
2215+
Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
2216+
Architectures: arm
2217+
Type: vm ioctl
2218+
Parameters: struct kvm_arm_device_address (in)
2219+
Returns: 0 on success, -1 on error
2220+
Errors:
2221+
ENODEV: The device id is unknown
2222+
ENXIO: Device not supported on current system
2223+
EEXIST: Address already set
2224+
E2BIG: Address outside guest physical address space
2225+
EBUSY: Address overlaps with other device range
2226+
2227+
struct kvm_arm_device_addr {
2228+
__u64 id;
2229+
__u64 addr;
2230+
};
2231+
2232+
Specify a device address in the guest's physical address space where guests
2233+
can access emulated or directly exposed devices, which the host kernel needs
2234+
to know about. The id field is an architecture specific identifier for a
2235+
specific device.
2236+
2237+
ARM divides the id field into two parts, a device id and an address type id
2238+
specific to the individual device.
2239+
2240+
 bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
2241+
field: | 0x00000000 | device id | addr type id |
2242+
2243+
ARM currently only require this when using the in-kernel GIC support for the
2244+
hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2 as the device id. When
2245+
setting the base address for the guest's mapping of the VGIC virtual CPU
2246+
and distributor interface, the ioctl must be called after calling
2247+
KVM_CREATE_IRQCHIP, but before calling KVM_RUN on any of the VCPUs. Calling
2248+
this ioctl twice for any of the base addresses will return -EEXIST.
2249+
2250+
22132251
5. The kvm_run structure
22142252
------------------------
22152253

‎arch/arm/Kconfig‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config ARM
44
select ARCH_BINFMT_ELF_RANDOMIZE_PIE
55
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
66
select ARCH_HAVE_CUSTOM_GPIO_H
7+
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
78
select ARCH_WANT_IPC_PARSE_VERSION
89
select BUILDTIME_EXTABLE_SORT if MMU
910
select CPU_PM if (SUSPEND || CPU_IDLE)
@@ -1112,6 +1113,8 @@ source "arch/arm/mach-versatile/Kconfig"
11121113
source "arch/arm/mach-vexpress/Kconfig"
11131114
source "arch/arm/plat-versatile/Kconfig"
11141115

1116+
source "arch/arm/mach-virt/Kconfig"
1117+
11151118
source "arch/arm/mach-vt8500/Kconfig"
11161119

11171120
source "arch/arm/mach-w90x900/Kconfig"
@@ -1560,9 +1563,10 @@ config HAVE_ARM_SCU
15601563
help
15611564
This option enables support for the ARM system coherency unit
15621565

1563-
config ARM_ARCH_TIMER
1566+
config HAVE_ARM_ARCH_TIMER
15641567
bool "Architected timer support"
15651568
depends on CPU_V7
1569+
select ARM_ARCH_TIMER
15661570
help
15671571
This option enables support for the ARM architected timer
15681572

‎arch/arm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
194194
machine-$(CONFIG_ARCH_SPEAR13XX) += spear13xx
195195
machine-$(CONFIG_ARCH_SPEAR3XX) += spear3xx
196196
machine-$(CONFIG_MACH_SPEAR600) += spear6xx
197+
machine-$(CONFIG_ARCH_VIRT) += virt
197198
machine-$(CONFIG_ARCH_ZYNQ) += zynq
198199
machine-$(CONFIG_ARCH_SUNXI) += sunxi
199200

‎arch/arm/include/asm/arch_timer.h‎

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,115 @@
11
#ifndef __ASMARM_ARCH_TIMER_H
22
#define __ASMARM_ARCH_TIMER_H
33

4+
#include <asm/barrier.h>
45
#include <asm/errno.h>
56
#include <linux/clocksource.h>
7+
#include <linux/init.h>
8+
#include <linux/types.h>
9+
10+
#include <clocksource/arm_arch_timer.h>
611

712
#ifdef CONFIG_ARM_ARCH_TIMER
813
int arch_timer_of_register(void);
914
int arch_timer_sched_clock_init(void);
10-
struct timecounter *arch_timer_get_timecounter(void);
15+
16+
/*
17+
* These register accessors are marked inline so the compiler can
18+
* nicely work out which register we want, and chuck away the rest of
19+
* the code. At least it does so with a recent GCC (4.6.3).
20+
*/
21+
static inline void arch_timer_reg_write(const int access, const int reg, u32 val)
22+
{
23+
if (access == ARCH_TIMER_PHYS_ACCESS) {
24+
switch (reg) {
25+
case ARCH_TIMER_REG_CTRL:
26+
asm volatile("mcr p15, 0, %0, c14, c2, 1" : : "r" (val));
27+
break;
28+
case ARCH_TIMER_REG_TVAL:
29+
asm volatile("mcr p15, 0, %0, c14, c2, 0" : : "r" (val));
30+
break;
31+
}
32+
}
33+
34+
if (access == ARCH_TIMER_VIRT_ACCESS) {
35+
switch (reg) {
36+
case ARCH_TIMER_REG_CTRL:
37+
asm volatile("mcr p15, 0, %0, c14, c3, 1" : : "r" (val));
38+
break;
39+
case ARCH_TIMER_REG_TVAL:
40+
asm volatile("mcr p15, 0, %0, c14, c3, 0" : : "r" (val));
41+
break;
42+
}
43+
}
44+
45+
isb();
46+
}
47+
48+
static inline u32 arch_timer_reg_read(const int access, const int reg)
49+
{
50+
u32 val = 0;
51+
52+
if (access == ARCH_TIMER_PHYS_ACCESS) {
53+
switch (reg) {
54+
case ARCH_TIMER_REG_CTRL:
55+
asm volatile("mrc p15, 0, %0, c14, c2, 1" : "=r" (val));
56+
break;
57+
case ARCH_TIMER_REG_TVAL:
58+
asm volatile("mrc p15, 0, %0, c14, c2, 0" : "=r" (val));
59+
break;
60+
}
61+
}
62+
63+
if (access == ARCH_TIMER_VIRT_ACCESS) {
64+
switch (reg) {
65+
case ARCH_TIMER_REG_CTRL:
66+
asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r" (val));
67+
break;
68+
case ARCH_TIMER_REG_TVAL:
69+
asm volatile("mrc p15, 0, %0, c14, c3, 0" : "=r" (val));
70+
break;
71+
}
72+
}
73+
74+
return val;
75+
}
76+
77+
static inline u32 arch_timer_get_cntfrq(void)
78+
{
79+
u32 val;
80+
asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (val));
81+
return val;
82+
}
83+
84+
static inline u64 arch_counter_get_cntpct(void)
85+
{
86+
u64 cval;
87+
88+
isb();
89+
asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (cval));
90+
return cval;
91+
}
92+
93+
static inline u64 arch_counter_get_cntvct(void)
94+
{
95+
u64 cval;
96+
97+
isb();
98+
asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (cval));
99+
return cval;
100+
}
101+
102+
static inline void __cpuinit arch_counter_set_user_access(void)
103+
{
104+
u32 cntkctl;
105+
106+
asm volatile("mrc p15, 0, %0, c14, c1, 0" : "=r" (cntkctl));
107+
108+
/* disable user access to everything */
109+
cntkctl &= ~((3 << 8) | (7 << 0));
110+
111+
asm volatile("mcr p15, 0, %0, c14, c1, 0" : : "r" (cntkctl));
112+
}
11113
#else
12114
static inline int arch_timer_of_register(void)
13115
{
@@ -18,11 +120,6 @@ static inline int arch_timer_sched_clock_init(void)
18120
{
19121
return -ENXIO;
20122
}
21-
22-
static inline struct timecounter *arch_timer_get_timecounter(void)
23-
{
24-
return NULL;
25-
}
26123
#endif
27124

28125
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (C) 2012 ARM Ltd.
3+
* Author: Marc Zyngier <marc.zyngier@arm.com>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#ifndef __ASM_ARM_KVM_ARCH_TIMER_H
20+
#define __ASM_ARM_KVM_ARCH_TIMER_H
21+
22+
#include <linux/clocksource.h>
23+
#include <linux/hrtimer.h>
24+
#include <linux/workqueue.h>
25+
26+
struct arch_timer_kvm {
27+
#ifdef CONFIG_KVM_ARM_TIMER
28+
/* Is the timer enabled */
29+
bool enabled;
30+
31+
/* Virtual offset */
32+
cycle_t cntvoff;
33+
#endif
34+
};
35+
36+
struct arch_timer_cpu {
37+
#ifdef CONFIG_KVM_ARM_TIMER
38+
/* Registers: control register, timer value */
39+
u32 cntv_ctl; /* Saved/restored */
40+
cycle_t cntv_cval; /* Saved/restored */
41+
42+
/*
43+
* Anything that is not used directly from assembly code goes
44+
* here.
45+
*/
46+
47+
/* Background timer used when the guest is not running */
48+
struct hrtimer timer;
49+
50+
/* Work queued with the above timer expires */
51+
struct work_struct expired;
52+
53+
/* Background timer active */
54+
bool armed;
55+
56+
/* Timer IRQ */
57+
const struct kvm_irq_level *irq;
58+
#endif
59+
};
60+
61+
#ifdef CONFIG_KVM_ARM_TIMER
62+
int kvm_timer_hyp_init(void);
63+
int kvm_timer_init(struct kvm *kvm);
64+
void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu);
65+
void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu);
66+
void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu);
67+
void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);
68+
#else
69+
static inline int kvm_timer_hyp_init(void)
70+
{
71+
return 0;
72+
};
73+
74+
static inline int kvm_timer_init(struct kvm *kvm)
75+
{
76+
return 0;
77+
}
78+
79+
static inline void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) {}
80+
static inline void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) {}
81+
static inline void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) {}
82+
static inline void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) {}
83+
#endif
84+
85+
#endif

‎arch/arm/include/asm/kvm_asm.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
#define c13_TID_URW 23 /* Thread ID, User R/W */
4646
#define c13_TID_URO 24 /* Thread ID, User R/O */
4747
#define c13_TID_PRIV 25 /* Thread ID, Privileged */
48-
#define NR_CP15_REGS 26 /* Number of regs (incl. invalid) */
48+
#define c14_CNTKCTL 26 /* Timer Control Register (PL1) */
49+
#define NR_CP15_REGS 27 /* Number of regs (incl. invalid) */
4950

5051
#define ARM_EXCEPTION_RESET 0
5152
#define ARM_EXCEPTION_UNDEFINED 1

‎arch/arm/include/asm/kvm_host.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <asm/kvm_asm.h>
2424
#include <asm/kvm_mmio.h>
2525
#include <asm/fpstate.h>
26+
#include <asm/kvm_arch_timer.h>
2627

2728
#define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS
2829
#define KVM_MEMORY_SLOTS 32
@@ -37,6 +38,8 @@
3738
#define KVM_NR_PAGE_SIZES 1
3839
#define KVM_PAGES_PER_HPAGE(x) (1UL<<31)
3940

41+
#include <asm/kvm_vgic.h>
42+
4043
struct kvm_vcpu;
4144
u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
4245
int kvm_target_cpu(void);
@@ -47,6 +50,9 @@ struct kvm_arch {
4750
/* VTTBR value associated with below pgd and vmid */
4851
u64 vttbr;
4952

53+
/* Timer */
54+
struct arch_timer_kvm timer;
55+
5056
/*
5157
* Anything that is not used directly from assembly code goes
5258
* here.
@@ -58,6 +64,9 @@ struct kvm_arch {
5864

5965
/* Stage-2 page table */
6066
pgd_t *pgd;
67+
68+
/* Interrupt controller */
69+
struct vgic_dist vgic;
6170
};
6271

6372
#define KVM_NR_MEM_OBJS 40
@@ -92,6 +101,10 @@ struct kvm_vcpu_arch {
92101
struct vfp_hard_struct vfp_guest;
93102
struct vfp_hard_struct *vfp_host;
94103

104+
/* VGIC state */
105+
struct vgic_cpu vgic_cpu;
106+
struct arch_timer_cpu timer_cpu;
107+
95108
/*
96109
* Anything that is not used directly from assembly code goes
97110
* here.
@@ -158,4 +171,14 @@ static inline int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
158171
{
159172
return 0;
160173
}
174+
175+
struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
176+
struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
177+
178+
int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
179+
unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu);
180+
struct kvm_one_reg;
181+
int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
182+
int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
183+
161184
#endif /* __ARM_KVM_HOST_H__ */

0 commit comments

Comments
 (0)