diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2015-04-07 12:09:20 -0400 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-04-07 12:09:20 -0400 |
| commit | bf0fb67cf957fc8ecfaaa2819b7d6a0f795e2ef2 (patch) | |
| tree | 22697f7deae781dbbacd2e19a5030df2e8551e6a /include/kvm | |
| parent | 8999602d08a804ae9cb271fdd5378f910058112d (diff) | |
| parent | d44758c0dfc5993a4b9952935a7eae4c91ebb6b4 (diff) | |
Merge tag 'kvm-arm-for-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into 'kvm-next'
KVM/ARM changes for v4.1:
- fixes for live migration
- irqfd support
- kvm-io-bus & vgic rework to enable ioeventfd
- page ageing for stage-2 translation
- various cleanups
Diffstat (limited to 'include/kvm')
| -rw-r--r-- | include/kvm/arm_arch_timer.h | 31 | ||||
| -rw-r--r-- | include/kvm/arm_vgic.h | 117 | ||||
| -rw-r--r-- | include/kvm/iodev.h | 76 |
3 files changed, 102 insertions, 122 deletions
diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index b3f45a578344..e5966758c093 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h | |||
| @@ -24,17 +24,14 @@ | |||
| 24 | #include <linux/workqueue.h> | 24 | #include <linux/workqueue.h> |
| 25 | 25 | ||
| 26 | struct arch_timer_kvm { | 26 | struct arch_timer_kvm { |
| 27 | #ifdef CONFIG_KVM_ARM_TIMER | ||
| 28 | /* Is the timer enabled */ | 27 | /* Is the timer enabled */ |
| 29 | bool enabled; | 28 | bool enabled; |
| 30 | 29 | ||
| 31 | /* Virtual offset */ | 30 | /* Virtual offset */ |
| 32 | cycle_t cntvoff; | 31 | cycle_t cntvoff; |
| 33 | #endif | ||
| 34 | }; | 32 | }; |
| 35 | 33 | ||
| 36 | struct arch_timer_cpu { | 34 | struct arch_timer_cpu { |
| 37 | #ifdef CONFIG_KVM_ARM_TIMER | ||
| 38 | /* Registers: control register, timer value */ | 35 | /* Registers: control register, timer value */ |
| 39 | u32 cntv_ctl; /* Saved/restored */ | 36 | u32 cntv_ctl; /* Saved/restored */ |
| 40 | cycle_t cntv_cval; /* Saved/restored */ | 37 | cycle_t cntv_cval; /* Saved/restored */ |
| @@ -55,10 +52,8 @@ struct arch_timer_cpu { | |||
| 55 | 52 | ||
| 56 | /* Timer IRQ */ | 53 | /* Timer IRQ */ |
| 57 | const struct kvm_irq_level *irq; | 54 | const struct kvm_irq_level *irq; |
| 58 | #endif | ||
| 59 | }; | 55 | }; |
| 60 | 56 | ||
| 61 | #ifdef CONFIG_KVM_ARM_TIMER | ||
| 62 | int kvm_timer_hyp_init(void); | 57 | int kvm_timer_hyp_init(void); |
| 63 | void kvm_timer_enable(struct kvm *kvm); | 58 | void kvm_timer_enable(struct kvm *kvm); |
| 64 | void kvm_timer_init(struct kvm *kvm); | 59 | void kvm_timer_init(struct kvm *kvm); |
| @@ -72,30 +67,6 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu); | |||
| 72 | u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); | 67 | u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); |
| 73 | int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); | 68 | int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); |
| 74 | 69 | ||
| 75 | #else | 70 | bool kvm_timer_should_fire(struct kvm_vcpu *vcpu); |
| 76 | static inline int kvm_timer_hyp_init(void) | ||
| 77 | { | ||
| 78 | return 0; | ||
| 79 | }; | ||
| 80 | |||
| 81 | static inline void kvm_timer_enable(struct kvm *kvm) {} | ||
| 82 | static inline void kvm_timer_init(struct kvm *kvm) {} | ||
| 83 | static inline void kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, | ||
| 84 | const struct kvm_irq_level *irq) {} | ||
| 85 | static inline void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) {} | ||
| 86 | static inline void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) {} | ||
| 87 | static inline void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) {} | ||
| 88 | static inline void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) {} | ||
| 89 | |||
| 90 | static inline int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) | ||
| 91 | { | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | static inline u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid) | ||
| 96 | { | ||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | #endif | ||
| 100 | 71 | ||
| 101 | #endif | 72 | #endif |
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 66203b268984..133ea00aa83b 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/irqreturn.h> | 24 | #include <linux/irqreturn.h> |
| 25 | #include <linux/spinlock.h> | 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/types.h> | 26 | #include <linux/types.h> |
| 27 | #include <kvm/iodev.h> | ||
| 27 | 28 | ||
| 28 | #define VGIC_NR_IRQS_LEGACY 256 | 29 | #define VGIC_NR_IRQS_LEGACY 256 |
| 29 | #define VGIC_NR_SGIS 16 | 30 | #define VGIC_NR_SGIS 16 |
| @@ -140,16 +141,21 @@ struct vgic_params { | |||
| 140 | }; | 141 | }; |
| 141 | 142 | ||
| 142 | struct vgic_vm_ops { | 143 | struct vgic_vm_ops { |
| 143 | bool (*handle_mmio)(struct kvm_vcpu *, struct kvm_run *, | ||
| 144 | struct kvm_exit_mmio *); | ||
| 145 | bool (*queue_sgi)(struct kvm_vcpu *, int irq); | 144 | bool (*queue_sgi)(struct kvm_vcpu *, int irq); |
| 146 | void (*add_sgi_source)(struct kvm_vcpu *, int irq, int source); | 145 | void (*add_sgi_source)(struct kvm_vcpu *, int irq, int source); |
| 147 | int (*init_model)(struct kvm *); | 146 | int (*init_model)(struct kvm *); |
| 148 | int (*map_resources)(struct kvm *, const struct vgic_params *); | 147 | int (*map_resources)(struct kvm *, const struct vgic_params *); |
| 149 | }; | 148 | }; |
| 150 | 149 | ||
| 150 | struct vgic_io_device { | ||
| 151 | gpa_t addr; | ||
| 152 | int len; | ||
| 153 | const struct vgic_io_range *reg_ranges; | ||
| 154 | struct kvm_vcpu *redist_vcpu; | ||
| 155 | struct kvm_io_device dev; | ||
| 156 | }; | ||
| 157 | |||
| 151 | struct vgic_dist { | 158 | struct vgic_dist { |
| 152 | #ifdef CONFIG_KVM_ARM_VGIC | ||
| 153 | spinlock_t lock; | 159 | spinlock_t lock; |
| 154 | bool in_kernel; | 160 | bool in_kernel; |
| 155 | bool ready; | 161 | bool ready; |
| @@ -197,6 +203,9 @@ struct vgic_dist { | |||
| 197 | /* Level-triggered interrupt queued on VCPU interface */ | 203 | /* Level-triggered interrupt queued on VCPU interface */ |
| 198 | struct vgic_bitmap irq_queued; | 204 | struct vgic_bitmap irq_queued; |
| 199 | 205 | ||
| 206 | /* Interrupt was active when unqueue from VCPU interface */ | ||
| 207 | struct vgic_bitmap irq_active; | ||
| 208 | |||
| 200 | /* Interrupt priority. Not used yet. */ | 209 | /* Interrupt priority. Not used yet. */ |
| 201 | struct vgic_bytemap irq_priority; | 210 | struct vgic_bytemap irq_priority; |
| 202 | 211 | ||
| @@ -237,8 +246,12 @@ struct vgic_dist { | |||
| 237 | /* Bitmap indicating which CPU has something pending */ | 246 | /* Bitmap indicating which CPU has something pending */ |
| 238 | unsigned long *irq_pending_on_cpu; | 247 | unsigned long *irq_pending_on_cpu; |
| 239 | 248 | ||
| 249 | /* Bitmap indicating which CPU has active IRQs */ | ||
| 250 | unsigned long *irq_active_on_cpu; | ||
| 251 | |||
| 240 | struct vgic_vm_ops vm_ops; | 252 | struct vgic_vm_ops vm_ops; |
| 241 | #endif | 253 | struct vgic_io_device dist_iodev; |
| 254 | struct vgic_io_device *redist_iodevs; | ||
| 242 | }; | 255 | }; |
| 243 | 256 | ||
| 244 | struct vgic_v2_cpu_if { | 257 | struct vgic_v2_cpu_if { |
| @@ -266,13 +279,18 @@ struct vgic_v3_cpu_if { | |||
| 266 | }; | 279 | }; |
| 267 | 280 | ||
| 268 | struct vgic_cpu { | 281 | struct vgic_cpu { |
| 269 | #ifdef CONFIG_KVM_ARM_VGIC | ||
| 270 | /* per IRQ to LR mapping */ | 282 | /* per IRQ to LR mapping */ |
| 271 | u8 *vgic_irq_lr_map; | 283 | u8 *vgic_irq_lr_map; |
| 272 | 284 | ||
| 273 | /* Pending interrupts on this VCPU */ | 285 | /* Pending/active/both interrupts on this VCPU */ |
| 274 | DECLARE_BITMAP( pending_percpu, VGIC_NR_PRIVATE_IRQS); | 286 | DECLARE_BITMAP( pending_percpu, VGIC_NR_PRIVATE_IRQS); |
| 287 | DECLARE_BITMAP( active_percpu, VGIC_NR_PRIVATE_IRQS); | ||
| 288 | DECLARE_BITMAP( pend_act_percpu, VGIC_NR_PRIVATE_IRQS); | ||
| 289 | |||
| 290 | /* Pending/active/both shared interrupts, dynamically sized */ | ||
| 275 | unsigned long *pending_shared; | 291 | unsigned long *pending_shared; |
| 292 | unsigned long *active_shared; | ||
| 293 | unsigned long *pend_act_shared; | ||
| 276 | 294 | ||
| 277 | /* Bitmap of used/free list registers */ | 295 | /* Bitmap of used/free list registers */ |
| 278 | DECLARE_BITMAP( lr_used, VGIC_V2_MAX_LRS); | 296 | DECLARE_BITMAP( lr_used, VGIC_V2_MAX_LRS); |
| @@ -285,7 +303,6 @@ struct vgic_cpu { | |||
| 285 | struct vgic_v2_cpu_if vgic_v2; | 303 | struct vgic_v2_cpu_if vgic_v2; |
| 286 | struct vgic_v3_cpu_if vgic_v3; | 304 | struct vgic_v3_cpu_if vgic_v3; |
| 287 | }; | 305 | }; |
| 288 | #endif | ||
| 289 | }; | 306 | }; |
| 290 | 307 | ||
| 291 | #define LR_EMPTY 0xff | 308 | #define LR_EMPTY 0xff |
| @@ -295,10 +312,7 @@ struct vgic_cpu { | |||
| 295 | 312 | ||
| 296 | struct kvm; | 313 | struct kvm; |
| 297 | struct kvm_vcpu; | 314 | struct kvm_vcpu; |
| 298 | struct kvm_run; | ||
| 299 | struct kvm_exit_mmio; | ||
| 300 | 315 | ||
| 301 | #ifdef CONFIG_KVM_ARM_VGIC | ||
| 302 | int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write); | 316 | int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write); |
| 303 | int kvm_vgic_hyp_init(void); | 317 | int kvm_vgic_hyp_init(void); |
| 304 | int kvm_vgic_map_resources(struct kvm *kvm); | 318 | int kvm_vgic_map_resources(struct kvm *kvm); |
| @@ -312,8 +326,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, | |||
| 312 | bool level); | 326 | bool level); |
| 313 | void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); | 327 | void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); |
| 314 | int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); | 328 | int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); |
| 315 | bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, | 329 | int kvm_vgic_vcpu_active_irq(struct kvm_vcpu *vcpu); |
| 316 | struct kvm_exit_mmio *mmio); | ||
| 317 | 330 | ||
| 318 | #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) | 331 | #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) |
| 319 | #define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus)) | 332 | #define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus)) |
| @@ -335,84 +348,4 @@ static inline int vgic_v3_probe(struct device_node *vgic_node, | |||
| 335 | } | 348 | } |
| 336 | #endif | 349 | #endif |
| 337 | 350 | ||
| 338 | #else | ||
| 339 | static inline int kvm_vgic_hyp_init(void) | ||
| 340 | { | ||
| 341 | return 0; | ||
| 342 | } | ||
| 343 | |||
| 344 | static inline int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr) | ||
| 345 | { | ||
| 346 | return 0; | ||
| 347 | } | ||
| 348 | |||
| 349 | static inline int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) | ||
| 350 | { | ||
| 351 | return -ENXIO; | ||
| 352 | } | ||
| 353 | |||
| 354 | static inline int kvm_vgic_map_resources(struct kvm *kvm) | ||
| 355 | { | ||
| 356 | return 0; | ||
| 357 | } | ||
| 358 | |||
| 359 | static inline int kvm_vgic_create(struct kvm *kvm, u32 type) | ||
| 360 | { | ||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | |||
| 364 | static inline void kvm_vgic_destroy(struct kvm *kvm) | ||
| 365 | { | ||
| 366 | } | ||
| 367 | |||
| 368 | static inline void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu) | ||
| 369 | { | ||
| 370 | } | ||
| 371 | |||
| 372 | static inline int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) | ||
| 373 | { | ||
| 374 | return 0; | ||
| 375 | } | ||
| 376 | |||
| 377 | static inline void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) {} | ||
| 378 | static inline void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) {} | ||
| 379 | |||
| 380 | static inline int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, | ||
| 381 | unsigned int irq_num, bool level) | ||
| 382 | { | ||
| 383 | return 0; | ||
| 384 | } | ||
| 385 | |||
| 386 | static inline int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu) | ||
| 387 | { | ||
| 388 | return 0; | ||
| 389 | } | ||
| 390 | |||
| 391 | static inline bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, | ||
| 392 | struct kvm_exit_mmio *mmio) | ||
| 393 | { | ||
| 394 | return false; | ||
| 395 | } | ||
| 396 | |||
| 397 | static inline int irqchip_in_kernel(struct kvm *kvm) | ||
| 398 | { | ||
| 399 | return 0; | ||
| 400 | } | ||
| 401 | |||
| 402 | static inline bool vgic_initialized(struct kvm *kvm) | ||
| 403 | { | ||
| 404 | return true; | ||
| 405 | } | ||
| 406 | |||
| 407 | static inline bool vgic_ready(struct kvm *kvm) | ||
| 408 | { | ||
| 409 | return true; | ||
| 410 | } | ||
| 411 | |||
| 412 | static inline int kvm_vgic_get_max_vcpus(void) | ||
| 413 | { | ||
| 414 | return KVM_MAX_VCPUS; | ||
| 415 | } | ||
| 416 | #endif | ||
| 417 | |||
| 418 | #endif | 351 | #endif |
diff --git a/include/kvm/iodev.h b/include/kvm/iodev.h new file mode 100644 index 000000000000..a6d208b916f5 --- /dev/null +++ b/include/kvm/iodev.h | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* | ||
| 2 | * This program is free software; you can redistribute it and/or modify | ||
| 3 | * it under the terms of the GNU General Public License as published by | ||
| 4 | * the Free Software Foundation; either version 2 of the License. | ||
| 5 | * | ||
| 6 | * This program is distributed in the hope that it will be useful, | ||
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 9 | * GNU General Public License for more details. | ||
| 10 | * | ||
| 11 | * You should have received a copy of the GNU General Public License | ||
| 12 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __KVM_IODEV_H__ | ||
| 16 | #define __KVM_IODEV_H__ | ||
| 17 | |||
| 18 | #include <linux/kvm_types.h> | ||
| 19 | #include <linux/errno.h> | ||
| 20 | |||
| 21 | struct kvm_io_device; | ||
| 22 | struct kvm_vcpu; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * kvm_io_device_ops are called under kvm slots_lock. | ||
| 26 | * read and write handlers return 0 if the transaction has been handled, | ||
| 27 | * or non-zero to have it passed to the next device. | ||
| 28 | **/ | ||
| 29 | struct kvm_io_device_ops { | ||
| 30 | int (*read)(struct kvm_vcpu *vcpu, | ||
| 31 | struct kvm_io_device *this, | ||
| 32 | gpa_t addr, | ||
| 33 | int len, | ||
| 34 | void *val); | ||
| 35 | int (*write)(struct kvm_vcpu *vcpu, | ||
| 36 | struct kvm_io_device *this, | ||
| 37 | gpa_t addr, | ||
| 38 | int len, | ||
| 39 | const void *val); | ||
| 40 | void (*destructor)(struct kvm_io_device *this); | ||
| 41 | }; | ||
| 42 | |||
| 43 | |||
| 44 | struct kvm_io_device { | ||
| 45 | const struct kvm_io_device_ops *ops; | ||
| 46 | }; | ||
| 47 | |||
| 48 | static inline void kvm_iodevice_init(struct kvm_io_device *dev, | ||
| 49 | const struct kvm_io_device_ops *ops) | ||
| 50 | { | ||
| 51 | dev->ops = ops; | ||
| 52 | } | ||
| 53 | |||
| 54 | static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu, | ||
| 55 | struct kvm_io_device *dev, gpa_t addr, | ||
| 56 | int l, void *v) | ||
| 57 | { | ||
| 58 | return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v) | ||
| 59 | : -EOPNOTSUPP; | ||
| 60 | } | ||
| 61 | |||
| 62 | static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu, | ||
| 63 | struct kvm_io_device *dev, gpa_t addr, | ||
| 64 | int l, const void *v) | ||
| 65 | { | ||
| 66 | return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v) | ||
| 67 | : -EOPNOTSUPP; | ||
| 68 | } | ||
| 69 | |||
| 70 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) | ||
| 71 | { | ||
| 72 | if (dev->ops->destructor) | ||
| 73 | dev->ops->destructor(dev); | ||
| 74 | } | ||
| 75 | |||
| 76 | #endif /* __KVM_IODEV_H__ */ | ||
