Skip to content

Commit d68321d

Browse files
committed
Merge tag 'kvm-ppc-fixes-5.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc into kvm-master
PPC KVM fix for 5.5 - Fix a bug where we try to do an ultracall on a system without an ultravisor.
2 parents 19a049f + d89c69f commit d68321d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2712
-696
lines changed

Documentation/virt/kvm/api.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The Definitive KVM (Kernel-based Virtual Machine) API Documentation
55
----------------------
66

77
The kvm API is a set of ioctls that are issued to control various aspects
8-
of a virtual machine. The ioctls belong to three classes:
8+
of a virtual machine. The ioctls belong to the following classes:
99

1010
- System ioctls: These query and set global attributes which affect the
1111
whole kvm subsystem. In addition a system ioctl is used to create
@@ -3002,6 +3002,9 @@ can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
30023002
KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
30033003
indicating the number of supported registers.
30043004

3005+
For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether
3006+
the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported.
3007+
30053008
When debug events exit the main run loop with the reason
30063009
KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
30073010
structure containing architecture specific debug information.
@@ -4146,6 +4149,24 @@ Valid values for 'action':
41464149
#define KVM_PMU_EVENT_ALLOW 0
41474150
#define KVM_PMU_EVENT_DENY 1
41484151

4152+
4.121 KVM_PPC_SVM_OFF
4153+
4154+
Capability: basic
4155+
Architectures: powerpc
4156+
Type: vm ioctl
4157+
Parameters: none
4158+
Returns: 0 on successful completion,
4159+
Errors:
4160+
EINVAL: if ultravisor failed to terminate the secure guest
4161+
ENOMEM: if hypervisor failed to allocate new radix page tables for guest
4162+
4163+
This ioctl is used to turn off the secure mode of the guest or transition
4164+
the guest from secure mode to normal mode. This is invoked when the guest
4165+
is reset. This has no effect if called for a normal guest.
4166+
4167+
This ioctl issues an ultravisor call to terminate the secure guest,
4168+
unpins the VPA pages and releases all the device pages that are used to
4169+
track the secure pages by hypervisor.
41494170

41504171
5. The kvm_run structure
41514172
------------------------

Documentation/virt/kvm/devices/xics.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ XICS interrupt controller
33
Device type supported: KVM_DEV_TYPE_XICS
44

55
Groups:
6-
KVM_DEV_XICS_SOURCES
6+
1. KVM_DEV_XICS_GRP_SOURCES
77
Attributes: One per interrupt source, indexed by the source number.
88

9+
2. KVM_DEV_XICS_GRP_CTRL
10+
Attributes:
11+
2.1 KVM_DEV_XICS_NR_SERVERS (write only)
12+
The kvm_device_attr.addr points to a __u32 value which is the number of
13+
interrupt server numbers (ie, highest possible vcpu id plus one).
14+
Errors:
15+
-EINVAL: Value greater than KVM_MAX_VCPU_ID.
16+
-EFAULT: Invalid user pointer for attr->addr.
17+
-EBUSY: A vcpu is already connected to the device.
18+
919
This device emulates the XICS (eXternal Interrupt Controller
1020
Specification) defined in PAPR. The XICS has a set of interrupt
1121
sources, each identified by a 20-bit source number, and a set of
@@ -38,7 +48,7 @@ least-significant end of the word:
3848

3949
Each source has 64 bits of state that can be read and written using
4050
the KVM_GET_DEVICE_ATTR and KVM_SET_DEVICE_ATTR ioctls, specifying the
41-
KVM_DEV_XICS_SOURCES attribute group, with the attribute number being
51+
KVM_DEV_XICS_GRP_SOURCES attribute group, with the attribute number being
4252
the interrupt source number. The 64 bit state word has the following
4353
bitfields, starting from the least-significant end of the word:
4454

Documentation/virt/kvm/devices/xive.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ the legacy interrupt mode, referred as XICS (POWER7/8).
7878
migrating the VM.
7979
Errors: none
8080

81+
1.3 KVM_DEV_XIVE_NR_SERVERS (write only)
82+
The kvm_device_attr.addr points to a __u32 value which is the number of
83+
interrupt server numbers (ie, highest possible vcpu id plus one).
84+
Errors:
85+
-EINVAL: Value greater than KVM_MAX_VCPU_ID.
86+
-EFAULT: Invalid user pointer for attr->addr.
87+
-EBUSY: A vCPU is already connected to the device.
88+
8189
2. KVM_DEV_XIVE_GRP_SOURCE (write only)
8290
Initializes a new source in the XIVE device and mask it.
8391
Attributes:

arch/powerpc/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,23 @@ config PPC_TRANSACTIONAL_MEM
451451
help
452452
Support user-mode Transactional Memory on POWERPC.
453453

454+
config PPC_UV
455+
bool "Ultravisor support"
456+
depends on KVM_BOOK3S_HV_POSSIBLE
457+
select ZONE_DEVICE
458+
select DEV_PAGEMAP_OPS
459+
select DEVICE_PRIVATE
460+
select MEMORY_HOTPLUG
461+
select MEMORY_HOTREMOVE
462+
default n
463+
help
464+
This option paravirtualizes the kernel to run in POWER platforms that
465+
supports the Protected Execution Facility (PEF). On such platforms,
466+
the ultravisor firmware runs at a privilege level above the
467+
hypervisor.
468+
469+
If unsure, say "N".
470+
454471
config LD_HEAD_STUB_CATCH
455472
bool "Reserve 256 bytes to cope with linker stubs in HEAD text" if EXPERT
456473
depends on PPC64

arch/powerpc/include/asm/hvcall.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@
342342
#define H_TLB_INVALIDATE 0xF808
343343
#define H_COPY_TOFROM_GUEST 0xF80C
344344

345+
/* Flags for H_SVM_PAGE_IN */
346+
#define H_PAGE_IN_SHARED 0x1
347+
348+
/* Platform-specific hcalls used by the Ultravisor */
349+
#define H_SVM_PAGE_IN 0xEF00
350+
#define H_SVM_PAGE_OUT 0xEF04
351+
#define H_SVM_INIT_START 0xEF08
352+
#define H_SVM_INIT_DONE 0xEF0C
353+
345354
/* Values for 2nd argument to H_SET_MODE */
346355
#define H_SET_MODE_RESOURCE_SET_CIABR 1
347356
#define H_SET_MODE_RESOURCE_SET_DAWR 2
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __ASM_KVM_BOOK3S_UVMEM_H__
3+
#define __ASM_KVM_BOOK3S_UVMEM_H__
4+
5+
#ifdef CONFIG_PPC_UV
6+
int kvmppc_uvmem_init(void);
7+
void kvmppc_uvmem_free(void);
8+
int kvmppc_uvmem_slot_init(struct kvm *kvm, const struct kvm_memory_slot *slot);
9+
void kvmppc_uvmem_slot_free(struct kvm *kvm,
10+
const struct kvm_memory_slot *slot);
11+
unsigned long kvmppc_h_svm_page_in(struct kvm *kvm,
12+
unsigned long gra,
13+
unsigned long flags,
14+
unsigned long page_shift);
15+
unsigned long kvmppc_h_svm_page_out(struct kvm *kvm,
16+
unsigned long gra,
17+
unsigned long flags,
18+
unsigned long page_shift);
19+
unsigned long kvmppc_h_svm_init_start(struct kvm *kvm);
20+
unsigned long kvmppc_h_svm_init_done(struct kvm *kvm);
21+
int kvmppc_send_page_to_uv(struct kvm *kvm, unsigned long gfn);
22+
void kvmppc_uvmem_drop_pages(const struct kvm_memory_slot *free,
23+
struct kvm *kvm);
24+
#else
25+
static inline int kvmppc_uvmem_init(void)
26+
{
27+
return 0;
28+
}
29+
30+
static inline void kvmppc_uvmem_free(void) { }
31+
32+
static inline int
33+
kvmppc_uvmem_slot_init(struct kvm *kvm, const struct kvm_memory_slot *slot)
34+
{
35+
return 0;
36+
}
37+
38+
static inline void
39+
kvmppc_uvmem_slot_free(struct kvm *kvm, const struct kvm_memory_slot *slot) { }
40+
41+
static inline unsigned long
42+
kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gra,
43+
unsigned long flags, unsigned long page_shift)
44+
{
45+
return H_UNSUPPORTED;
46+
}
47+
48+
static inline unsigned long
49+
kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra,
50+
unsigned long flags, unsigned long page_shift)
51+
{
52+
return H_UNSUPPORTED;
53+
}
54+
55+
static inline unsigned long kvmppc_h_svm_init_start(struct kvm *kvm)
56+
{
57+
return H_UNSUPPORTED;
58+
}
59+
60+
static inline unsigned long kvmppc_h_svm_init_done(struct kvm *kvm)
61+
{
62+
return H_UNSUPPORTED;
63+
}
64+
65+
static inline int kvmppc_send_page_to_uv(struct kvm *kvm, unsigned long gfn)
66+
{
67+
return -EFAULT;
68+
}
69+
70+
static inline void
71+
kvmppc_uvmem_drop_pages(const struct kvm_memory_slot *free,
72+
struct kvm *kvm) { }
73+
#endif /* CONFIG_PPC_UV */
74+
#endif /* __ASM_KVM_BOOK3S_UVMEM_H__ */

arch/powerpc/include/asm/kvm_host.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ struct kvm_hpt_info {
275275

276276
struct kvm_resize_hpt;
277277

278+
/* Flag values for kvm_arch.secure_guest */
279+
#define KVMPPC_SECURE_INIT_START 0x1 /* H_SVM_INIT_START has been called */
280+
#define KVMPPC_SECURE_INIT_DONE 0x2 /* H_SVM_INIT_DONE completed */
281+
278282
struct kvm_arch {
279283
unsigned int lpid;
280284
unsigned int smt_mode; /* # vcpus per virtual core */
@@ -330,6 +334,8 @@ struct kvm_arch {
330334
#endif
331335
struct kvmppc_ops *kvm_ops;
332336
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
337+
struct mutex uvmem_lock;
338+
struct list_head uvmem_pfns;
333339
struct mutex mmu_setup_lock; /* nests inside vcpu mutexes */
334340
u64 l1_ptcr;
335341
int max_nested_lpid;
@@ -401,7 +407,6 @@ struct kvmppc_mmu {
401407
u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
402408
int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr,
403409
struct kvmppc_pte *pte, bool data, bool iswrite);
404-
void (*reset_msr)(struct kvm_vcpu *vcpu);
405410
void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
406411
int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
407412
u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);

arch/powerpc/include/asm/kvm_ppc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ struct kvmppc_ops {
271271
union kvmppc_one_reg *val);
272272
void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
273273
void (*vcpu_put)(struct kvm_vcpu *vcpu);
274+
void (*inject_interrupt)(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags);
274275
void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
275276
int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
276277
struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id);
@@ -321,6 +322,7 @@ struct kvmppc_ops {
321322
int size);
322323
int (*store_to_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
323324
int size);
325+
int (*svm_off)(struct kvm *kvm);
324326
};
325327

326328
extern struct kvmppc_ops *kvmppc_hv_ops;

arch/powerpc/include/asm/reg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,18 @@
748748
#define SPRN_USPRG7 0x107 /* SPRG7 userspace read */
749749
#define SPRN_SRR0 0x01A /* Save/Restore Register 0 */
750750
#define SPRN_SRR1 0x01B /* Save/Restore Register 1 */
751+
752+
#ifdef CONFIG_PPC_BOOK3S
753+
/*
754+
* Bits loaded from MSR upon interrupt.
755+
* PPC (64-bit) bits 33-36,42-47 are interrupt dependent, the others are
756+
* loaded from MSR. The exception is that SRESET and MCE do not always load
757+
* bit 62 (RI) from MSR. Don't use PPC_BITMASK for this because 32-bit uses
758+
* it.
759+
*/
760+
#define SRR1_MSR_BITS (~0x783f0000UL)
761+
#endif
762+
751763
#define SRR1_ISI_NOPT 0x40000000 /* ISI: Not found in hash */
752764
#define SRR1_ISI_N_OR_G 0x10000000 /* ISI: Access is no-exec or G */
753765
#define SRR1_ISI_PROT 0x08000000 /* ISI: Other protection fault */

arch/powerpc/include/asm/ultravisor-api.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
#define UV_WRITE_PATE 0xF104
2727
#define UV_RETURN 0xF11C
2828
#define UV_ESM 0xF110
29+
#define UV_REGISTER_MEM_SLOT 0xF120
30+
#define UV_UNREGISTER_MEM_SLOT 0xF124
31+
#define UV_PAGE_IN 0xF128
32+
#define UV_PAGE_OUT 0xF12C
2933
#define UV_SHARE_PAGE 0xF130
3034
#define UV_UNSHARE_PAGE 0xF134
3135
#define UV_UNSHARE_ALL_PAGES 0xF140
36+
#define UV_PAGE_INVAL 0xF138
37+
#define UV_SVM_TERMINATE 0xF13C
3238

3339
#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */

0 commit comments

Comments
 (0)