diff options
author | Paul Mackerras <paulus@samba.org> | 2011-06-28 20:25:44 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-07-12 06:16:57 -0400 |
commit | aa04b4cc5be64b4fb9ef4e0fdf2418e2f4737fb2 (patch) | |
tree | 97a3ff14e43424e28a27e0f3be088649818c1b76 /arch/powerpc/include | |
parent | 371fefd6f2dc46668e00871930dde613b88d4bde (diff) |
KVM: PPC: Allocate RMAs (Real Mode Areas) at boot for use by guests
This adds infrastructure which will be needed to allow book3s_hv KVM to
run on older POWER processors, including PPC970, which don't support
the Virtual Real Mode Area (VRMA) facility, but only the Real Mode
Offset (RMO) facility. These processors require a physically
contiguous, aligned area of memory for each guest. When the guest does
an access in real mode (MMU off), the address is compared against a
limit value, and if it is lower, the address is ORed with an offset
value (from the Real Mode Offset Register (RMOR)) and the result becomes
the real address for the access. The size of the RMA has to be one of
a set of supported values, which usually includes 64MB, 128MB, 256MB
and some larger powers of 2.
Since we are unlikely to be able to allocate 64MB or more of physically
contiguous memory after the kernel has been running for a while, we
allocate a pool of RMAs at boot time using the bootmem allocator. The
size and number of the RMAs can be set using the kvm_rma_size=xx and
kvm_rma_count=xx kernel command line options.
KVM exports a new capability, KVM_CAP_PPC_RMA, to signal the availability
of the pool of preallocated RMAs. The capability value is 1 if the
processor can use an RMA but doesn't require one (because it supports
the VRMA facility), or 2 if the processor requires an RMA for each guest.
This adds a new ioctl, KVM_ALLOCATE_RMA, which allocates an RMA from the
pool and returns a file descriptor which can be used to map the RMA. It
also returns the size of the RMA in the argument structure.
Having an RMA means we will get multiple KMV_SET_USER_MEMORY_REGION
ioctl calls from userspace. To cope with this, we now preallocate the
kvm->arch.ram_pginfo array when the VM is created with a size sufficient
for up to 64GB of guest memory. Subsequently we will get rid of this
array and use memory associated with each memslot instead.
This moves most of the code that translates the user addresses into
host pfns (page frame numbers) out of kvmppc_prepare_vrma up one level
to kvmppc_core_prepare_memory_region. Also, instead of having to look
up the VMA for each page in order to check the page size, we now check
that the pages we get are compound pages of 16MB. However, if we are
adding memory that is mapped to an RMA, we don't bother with calling
get_user_pages_fast and instead just offset from the base pfn for the
RMA.
Typically the RMA gets added after vcpus are created, which makes it
inconvenient to have the LPCR (logical partition control register) value
in the vcpu->arch struct, since the LPCR controls whether the processor
uses RMA or VRMA for the guest. This moves the LPCR value into the
kvm->arch struct and arranges for the MER (mediated external request)
bit, which is the only bit that varies between vcpus, to be set in
assembly code when going into the guest if there is a pending external
interrupt request.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'arch/powerpc/include')
-rw-r--r-- | arch/powerpc/include/asm/kvm.h | 5 | ||||
-rw-r--r-- | arch/powerpc/include/asm/kvm_book3s.h | 8 | ||||
-rw-r--r-- | arch/powerpc/include/asm/kvm_host.h | 15 | ||||
-rw-r--r-- | arch/powerpc/include/asm/kvm_ppc.h | 10 | ||||
-rw-r--r-- | arch/powerpc/include/asm/reg.h | 1 |
5 files changed, 30 insertions, 9 deletions
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h index 471bb3d85e0b..a4f6c85431f8 100644 --- a/arch/powerpc/include/asm/kvm.h +++ b/arch/powerpc/include/asm/kvm.h | |||
@@ -282,4 +282,9 @@ struct kvm_create_spapr_tce { | |||
282 | __u32 window_size; | 282 | __u32 window_size; |
283 | }; | 283 | }; |
284 | 284 | ||
285 | /* for KVM_ALLOCATE_RMA */ | ||
286 | struct kvm_allocate_rma { | ||
287 | __u64 rma_size; | ||
288 | }; | ||
289 | |||
285 | #endif /* __LINUX_KVM_POWERPC_H */ | 290 | #endif /* __LINUX_KVM_POWERPC_H */ |
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h index 5537c45d626c..3f91ebd4ae43 100644 --- a/arch/powerpc/include/asm/kvm_book3s.h +++ b/arch/powerpc/include/asm/kvm_book3s.h | |||
@@ -298,14 +298,6 @@ static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu) | |||
298 | static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, | 298 | static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, |
299 | unsigned long pending_now, unsigned long old_pending) | 299 | unsigned long pending_now, unsigned long old_pending) |
300 | { | 300 | { |
301 | /* Recalculate LPCR:MER based on the presence of | ||
302 | * a pending external interrupt | ||
303 | */ | ||
304 | if (test_bit(BOOK3S_IRQPRIO_EXTERNAL, &pending_now) || | ||
305 | test_bit(BOOK3S_IRQPRIO_EXTERNAL_LEVEL, &pending_now)) | ||
306 | vcpu->arch.lpcr |= LPCR_MER; | ||
307 | else | ||
308 | vcpu->arch.lpcr &= ~((u64)LPCR_MER); | ||
309 | } | 301 | } |
310 | 302 | ||
311 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) | 303 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) |
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 0d6d569e19c7..f572d9cc31bd 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h | |||
@@ -28,6 +28,8 @@ | |||
28 | #include <linux/threads.h> | 28 | #include <linux/threads.h> |
29 | #include <linux/spinlock.h> | 29 | #include <linux/spinlock.h> |
30 | #include <linux/kvm_para.h> | 30 | #include <linux/kvm_para.h> |
31 | #include <linux/list.h> | ||
32 | #include <linux/atomic.h> | ||
31 | #include <asm/kvm_asm.h> | 33 | #include <asm/kvm_asm.h> |
32 | #include <asm/processor.h> | 34 | #include <asm/processor.h> |
33 | 35 | ||
@@ -156,6 +158,14 @@ struct kvmppc_spapr_tce_table { | |||
156 | struct page *pages[0]; | 158 | struct page *pages[0]; |
157 | }; | 159 | }; |
158 | 160 | ||
161 | struct kvmppc_rma_info { | ||
162 | void *base_virt; | ||
163 | unsigned long base_pfn; | ||
164 | unsigned long npages; | ||
165 | struct list_head list; | ||
166 | atomic_t use_count; | ||
167 | }; | ||
168 | |||
159 | struct kvm_arch { | 169 | struct kvm_arch { |
160 | #ifdef CONFIG_KVM_BOOK3S_64_HV | 170 | #ifdef CONFIG_KVM_BOOK3S_64_HV |
161 | unsigned long hpt_virt; | 171 | unsigned long hpt_virt; |
@@ -169,6 +179,10 @@ struct kvm_arch { | |||
169 | unsigned long sdr1; | 179 | unsigned long sdr1; |
170 | unsigned long host_sdr1; | 180 | unsigned long host_sdr1; |
171 | int tlbie_lock; | 181 | int tlbie_lock; |
182 | int n_rma_pages; | ||
183 | unsigned long lpcr; | ||
184 | unsigned long rmor; | ||
185 | struct kvmppc_rma_info *rma; | ||
172 | struct list_head spapr_tce_tables; | 186 | struct list_head spapr_tce_tables; |
173 | unsigned short last_vcpu[NR_CPUS]; | 187 | unsigned short last_vcpu[NR_CPUS]; |
174 | struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; | 188 | struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; |
@@ -295,7 +309,6 @@ struct kvm_vcpu_arch { | |||
295 | ulong guest_owned_ext; | 309 | ulong guest_owned_ext; |
296 | ulong purr; | 310 | ulong purr; |
297 | ulong spurr; | 311 | ulong spurr; |
298 | ulong lpcr; | ||
299 | ulong dscr; | 312 | ulong dscr; |
300 | ulong amr; | 313 | ulong amr; |
301 | ulong uamor; | 314 | ulong uamor; |
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 6ef734428634..d121f49d62b8 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h | |||
@@ -124,6 +124,10 @@ extern void kvmppc_map_vrma(struct kvm *kvm, | |||
124 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); | 124 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); |
125 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, | 125 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
126 | struct kvm_create_spapr_tce *args); | 126 | struct kvm_create_spapr_tce *args); |
127 | extern long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, | ||
128 | struct kvm_allocate_rma *rma); | ||
129 | extern struct kvmppc_rma_info *kvm_alloc_rma(void); | ||
130 | extern void kvm_release_rma(struct kvmppc_rma_info *ri); | ||
127 | extern int kvmppc_core_init_vm(struct kvm *kvm); | 131 | extern int kvmppc_core_init_vm(struct kvm *kvm); |
128 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); | 132 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); |
129 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, | 133 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
@@ -177,9 +181,15 @@ static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) | |||
177 | { | 181 | { |
178 | paca[cpu].kvm_hstate.xics_phys = addr; | 182 | paca[cpu].kvm_hstate.xics_phys = addr; |
179 | } | 183 | } |
184 | |||
185 | extern void kvm_rma_init(void); | ||
186 | |||
180 | #else | 187 | #else |
181 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) | 188 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
182 | {} | 189 | {} |
190 | |||
191 | static inline void kvm_rma_init(void) | ||
192 | {} | ||
183 | #endif | 193 | #endif |
184 | 194 | ||
185 | #endif /* __POWERPC_KVM_PPC_H__ */ | 195 | #endif /* __POWERPC_KVM_PPC_H__ */ |
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h index 36a611b398c5..20a053c14270 100644 --- a/arch/powerpc/include/asm/reg.h +++ b/arch/powerpc/include/asm/reg.h | |||
@@ -242,6 +242,7 @@ | |||
242 | #define LPCR_VRMA_LP1 (1ul << (63-16)) | 242 | #define LPCR_VRMA_LP1 (1ul << (63-16)) |
243 | #define LPCR_VRMASD_SH (63-16) | 243 | #define LPCR_VRMASD_SH (63-16) |
244 | #define LPCR_RMLS 0x1C000000 /* impl dependent rmo limit sel */ | 244 | #define LPCR_RMLS 0x1C000000 /* impl dependent rmo limit sel */ |
245 | #define LPCR_RMLS_SH (63-37) | ||
245 | #define LPCR_ILE 0x02000000 /* !HV irqs set MSR:LE */ | 246 | #define LPCR_ILE 0x02000000 /* !HV irqs set MSR:LE */ |
246 | #define LPCR_PECE 0x00007000 /* powersave exit cause enable */ | 247 | #define LPCR_PECE 0x00007000 /* powersave exit cause enable */ |
247 | #define LPCR_PECE0 0x00004000 /* ext. exceptions can cause exit */ | 248 | #define LPCR_PECE0 0x00004000 /* ext. exceptions can cause exit */ |