[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH 23/34] target-ppc: KVM: Fix some kernel version edge c
From: |
Alexander Graf |
Subject: |
[Qemu-ppc] [PATCH 23/34] target-ppc: KVM: Fix some kernel version edge cases for kvmppc_reset_htab() |
Date: |
Thu, 4 Oct 2012 15:56:45 +0200 |
From: David Gibson <address@hidden>
The kvmppc_reset_htab() function invokes the KVM_PPC_ALLOCATE_HTAB vm ioctl
to request KVM to allocate and reset a hash page table for the guest - it
returns the size of hash table allocated, or 0 to indicate that qemu needs
to allocate the hash table itself. In practice qemu needs to allocate the
htab for full emulation and with Book3sPR KVM, but the kernel has to
allocate it for Book3sHV KVM (the hash table needs to be physically
contiguous in that case).
Unfortunately, the logic in this function is incorrect for some existing
kernels. Specifically:
* at least some PR KVM versions advertise the relevant capability but
don't actually implement the ioctl(), returning ENOTTY.
* For old kernels which don't have the capability, we currently return 0.
This is correct for PV KVM, where we need to allocate the htab, but not for
HV KVM - kernels of this era always allocate a 16MB hash table per guest.
This patch corrects both of these edge cases.
Signed-off-by: David Gibson <address@hidden>
Signed-off-by: Alexander Graf <address@hidden>
---
target-ppc/kvm.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 546c116..1975323 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -1127,18 +1127,38 @@ int kvmppc_reset_htab(int shift_hint)
{
uint32_t shift = shift_hint;
- if (kvm_enabled() &&
- kvm_check_extension(kvm_state, KVM_CAP_PPC_ALLOC_HTAB)) {
+ if (!kvm_enabled()) {
+ /* Full emulation, tell caller to allocate htab itself */
+ return 0;
+ }
+ if (kvm_check_extension(kvm_state, KVM_CAP_PPC_ALLOC_HTAB)) {
int ret;
ret = kvm_vm_ioctl(kvm_state, KVM_PPC_ALLOCATE_HTAB, &shift);
- if (ret < 0) {
+ if (ret == -ENOTTY) {
+ /* At least some versions of PR KVM advertise the
+ * capability, but don't implement the ioctl(). Oops.
+ * Return 0 so that we allocate the htab in qemu, as is
+ * correct for PR. */
+ return 0;
+ } else if (ret < 0) {
return ret;
}
return shift;
}
- /* For now.. */
- return 0;
+ /* We have a kernel that predates the htab reset calls. For PR
+ * KVM, we need to allocate the htab ourselves, for an HV KVM of
+ * this era, it has allocated a 16MB fixed size hash table
+ * already. Kernels of this era have the GET_PVINFO capability
+ * only on PR, so we use this hack to determine the right
+ * answer */
+ if (kvm_check_extension(kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+ /* PR - tell caller to allocate htab */
+ return 0;
+ } else {
+ /* HV - assume 16MB kernel allocated htab */
+ return 24;
+ }
}
static inline uint32_t mfpvr(void)
--
1.6.0.2
- [Qemu-ppc] [PATCH 25/34] pseries: Remove unnecessary locking from PAPR hash table hcalls, (continued)
- [Qemu-ppc] [PATCH 25/34] pseries: Remove unnecessary locking from PAPR hash table hcalls, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 04/34] MAINTAINERS: Document Bamboo machine and ppc4xx devices, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 24/34] ppc405_uc: Fix buffer overflow, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 16/34] pseries: Fix XICS reset, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 11/34] pseries: Fix and cleanup CPU initialization and reset, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 31/34] PPC: e500: increase DTC_LOAD_PAD, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 19/34] pseries: Remove XICS irq type enum type, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 15/34] pseries: Reset emulated PCI TCE tables on system reset, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 09/34] target-ppc: get rid of the HANDLE_NAN{1, 2, 3} macros, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 22/34] pseries: Fix semantics of RTAS int-on, int-off and set-xive functions, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 23/34] target-ppc: KVM: Fix some kernel version edge cases for kvmppc_reset_htab(),
Alexander Graf <=
- [Qemu-ppc] [PATCH 13/34] pseries: Add support for new KVM hash table control call, Alexander Graf, 2012/10/04
- [Qemu-ppc] [PATCH 12/34] pseries: Use new method to correct reset sequence, Alexander Graf, 2012/10/04
- Re: [Qemu-ppc] [Qemu-devel] [PULL 00/34] ppc patch queue 2012-10-04, Aurelien Jarno, 2012/10/06