Skip to content

Commit b221498

Browse files
committed
Merge branch 'kvm-arm/timer' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms into next/virt
From Marc Zyngier, this branch enables virtual GIC and timer for KVM/ARM. * 'kvm-arm/timer' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms: 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
2 parents 0582b05 + 967f842 commit b221498

18 files changed

Lines changed: 2581 additions & 14 deletions

File tree

‎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

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)