aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm/book3s_hv_rmhandlers.S
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2011-06-28 20:25:44 -0400
committerAvi Kivity <avi@redhat.com>2011-07-12 06:16:57 -0400
commitaa04b4cc5be64b4fb9ef4e0fdf2418e2f4737fb2 (patch)
tree97a3ff14e43424e28a27e0f3be088649818c1b76 /arch/powerpc/kvm/book3s_hv_rmhandlers.S
parent371fefd6f2dc46668e00871930dde613b88d4bde (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/kvm/book3s_hv_rmhandlers.S')
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S19
1 files changed, 15 insertions, 4 deletions
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index c9bf177b7cf2..9ee223c35285 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -235,10 +235,10 @@ kvmppc_hv_entry:
235 bne 21b 235 bne 21b
236 236
237 /* Primary thread switches to guest partition. */ 237 /* Primary thread switches to guest partition. */
238 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
238 lwz r6,VCPU_PTID(r4) 239 lwz r6,VCPU_PTID(r4)
239 cmpwi r6,0 240 cmpwi r6,0
240 bne 20f 241 bne 20f
241 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
242 ld r6,KVM_SDR1(r9) 242 ld r6,KVM_SDR1(r9)
243 lwz r7,KVM_LPID(r9) 243 lwz r7,KVM_LPID(r9)
244 li r0,LPID_RSVD /* switch to reserved LPID */ 244 li r0,LPID_RSVD /* switch to reserved LPID */
@@ -255,8 +255,18 @@ kvmppc_hv_entry:
25520: lbz r0,VCORE_IN_GUEST(r5) 25520: lbz r0,VCORE_IN_GUEST(r5)
256 cmpwi r0,0 256 cmpwi r0,0
257 beq 20b 257 beq 20b
25810: ld r8,VCPU_LPCR(r4) 258
259 mtspr SPRN_LPCR,r8 259 /* Set LPCR. Set the MER bit if there is a pending external irq. */
26010: ld r8,KVM_LPCR(r9)
261 ld r0,VCPU_PENDING_EXC(r4)
262 li r7,(1 << BOOK3S_IRQPRIO_EXTERNAL)
263 oris r7,r7,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
264 and. r0,r0,r7
265 beq 11f
266 ori r8,r8,LPCR_MER
26711: mtspr SPRN_LPCR,r8
268 ld r8,KVM_RMOR(r9)
269 mtspr SPRN_RMOR,r8
260 isync 270 isync
261 271
262 /* Check if HDEC expires soon */ 272 /* Check if HDEC expires soon */
@@ -464,7 +474,8 @@ hcall_real_cont:
464 /* Check for mediated interrupts (could be done earlier really ...) */ 474 /* Check for mediated interrupts (could be done earlier really ...) */
465 cmpwi r12,BOOK3S_INTERRUPT_EXTERNAL 475 cmpwi r12,BOOK3S_INTERRUPT_EXTERNAL
466 bne+ 1f 476 bne+ 1f
467 ld r5,VCPU_LPCR(r9) 477 ld r5,VCPU_KVM(r9)
478 ld r5,KVM_LPCR(r5)
468 andi. r0,r11,MSR_EE 479 andi. r0,r11,MSR_EE
469 beq 1f 480 beq 1f
470 andi. r0,r5,LPCR_MER 481 andi. r0,r5,LPCR_MER