Handle KVM_PPC_ALLOCATE_HTAB ioctl failure
cover Handle KVM_PPC_ALLOCATE_HTAB ioctl failure
KVM_PPC_ALLOCATE_HTAB ioctl can now return errors and handle that correctly in QEMU.
Also fix !CONFIG_KVM implementation of kvmppc_reset_htab() to return 0 instead of -1.
Changes in v1
------------
- Add a patch to fix !CONFIG_KVM implementation of kvmppc_reset_htab() so that make check passes for ppc64 target on x86 host.
- Explicitly check for shift < 0 error condition in spapr_alloc/reset_htab.
v0: https://lists.gnu.org/archive/html/qemu-ppc/2015-11/msg00012.html
Bharata B Rao (2):
ppc: Let kvmppc_reset_htab() return 0 for !CONFIG_KVM
spapr: Handle failure of KVM_PPC_ALLOCATE_HTAB ioctl
hw/ppc/spapr.c | 20 ++++++++++++++++---- target-ppc/kvm_ppc.h | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 ppc: Let kvmppc_reset_htab() return 0 for !CONFIG_KVM
The !CONFIG_KVM implementation of kvmppc_reset_htab() returns -1 by default. Change this to return 0 so that we fall back to user space HTAB allocation for emulated guests.
This fixes the make check failures for ppc64 emulated target.
--- target-ppc/kvm_ppc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-ppc/kvm_ppc.h +1 -1
@@ -180,7 +180,7 @@ static inline int kvmppc_remove_spapr_tce(void *table, int pfd,static inline int kvmppc_reset_htab (int shift_hint) { -return -1 ; +return 0 ; } static inline uint64_t kvmppc_rma_size(uint64_t current_size,
Signature · 1 line
2.1.0
PATCH 2/2 spapr: Handle failure of KVM_PPC_ALLOCATE_HTAB ioctl
In reply to Bharata B RaoKVM_PPC_ALLOCATE_HTAB ioctl can return -ENOMEM for KVM guests and QEMU never handled this correctly. But this didn't cause any problems till now as KVM_PPC_ALLOCATE_HTAB ioctl returned with smaller than requested HTAB when enough contiguous memory wasn't available in the host. After the proposed kernel change: https://patchwork.ozlabs.org/patch/530501/,KVM_PPC_ALLOCATE_HTAB ioctl will not fallback to lower sized HTAB allocation and will fail if requested HTAB size can't be met.
Check for such failures in QEMU and abort appropriately. This will prevent guest kernel from hanging/freezing during early boot by doing graceful exit when host is unable to allocate requested HTAB.
--- hw/ppc/spapr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +16 -4
@@ -1021,9 +1021,19 @@ static void spapr_alloc_htab(sPAPRMachineState *spapr)* RAM */ shift =kvmppc_reset_htab (spapr->htab_shift); - -if (shift >0 ) { -/* Kernel handles htab, we don't need to allocate one */ +if (shift <0 ) { +/* +* For HV KVM, host kernel will return -ENOMEM when requested +* HTAB size can't be allocated. +*/ +error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" ); + }else if (shift >0 ) { +/* +* Kernel handles htab, we don't need to allocate one +* +* Older kernels can fall back to lower HTAB shift values, +* but we don't allow booting of such guests. +*/ if (shift != spapr->htab_shift) {error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" ); }
@@ -1055,7 +1065,9 @@ static void spapr_reset_htab(sPAPRMachineState *spapr)int index; shift =kvmppc_reset_htab (spapr->htab_shift); -if (shift >0 ) { +if (shift <0 ) { +error_setg (&error_abort,"Failed to reset HTAB" ); + }else if (shift >0 ) {if (shift != spapr->htab_shift) {error_setg (&error_abort,"Requested HTAB allocation failed during reset" ); }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v1 2/2] spapr: Handle failure of KVM_PPC_ALLOCATE_HTAB ioctl
Quoting Bharata B Rao (2015-11-09 23:24:54)
Quoted 24 lines
KVM_PPC_ALLOCATE_HTABioctl can return-ENOMEMfor KVM guests and QEMU never handled this correctly. But this didn't cause any problems till now asKVM_PPC_ALLOCATE_HTABioctl returned with smaller than requested HTAB when enough contiguous memory wasn't available in the host. After the proposed kernel change: https://patchwork.ozlabs.org/patch/530501/,KVM_PPC_ALLOCATE_HTABioctl will not fallback to lower sized HTAB allocation and will fail if requested HTAB size can't be met.Check for such failures in QEMU and abort appropriately. This will prevent guest kernel from hanging/freezing during early boot by doing graceful exit when host is unable to allocate requested HTAB.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)hw/ppc/spapr.c +0
-0@@ -1021,9 +1021,19 @@ static void spapr_alloc_htab(sPAPRMachineState *spapr)* RAM */
hw/ppc/spapr.c static void spapr_alloc_htab(sPAPRMachineState *spapr) · line 1029
Quoted 10 lines
hw/ppc/spapr.c +6
-3shift =kvmppc_reset_htab (spapr->htab_shift); - -if (shift >0 ) { -/* Kernel handles htab, we don't need to allocate one */ +if (shift <0 ) { +/* +* For HV KVM, host kernel will return -ENOMEM when requested +* HTAB size can't be allocated. +*/ +error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" );
Wording is appropriate, but maybe just "Failed to allocate HTAB, try with smaller maxmem" to distinguish it from the error below where the call succeeds but there's a size mismatch?
Quoted 24 lines
hw/ppc/spapr.c +10
-1+ }else if (shift >0 ) { +/* +* Kernel handles htab, we don't need to allocate one +* +* Older kernels can fall back to lower HTAB shift values, +* but we don't allow booting of such guests. +*/ if (shift != spapr->htab_shift) {error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" ); }@@ -1055,7 +1065,9 @@ static void spapr_reset_htab(sPAPRMachineState *spapr)int index; shift =kvmppc_reset_htab (spapr->htab_shift); -if (shift >0 ) { +if (shift <0 ) { +error_setg (&error_abort,"Failed to reset HTAB" ); + }else if (shift >0 ) {if (shift != spapr->htab_shift) {error_setg (&error_abort,"Requested HTAB allocation failed during reset" ); }Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v1 2/2] spapr: Handle failure of KVM_PPC_ALLOCATE_HTAB ioctl
Quoted 25 lines · Michael Roth
Quoting Bharata B Rao (2015-11-09 23:24:54)
Quoted 24 lines
KVM_PPC_ALLOCATE_HTABioctl can return-ENOMEMfor KVM guests and QEMU never handled this correctly. But this didn't cause any problems till now asKVM_PPC_ALLOCATE_HTABioctl returned with smaller than requested HTAB when enough contiguous memory wasn't available in the host. After the proposed kernel change: https://patchwork.ozlabs.org/patch/530501/,KVM_PPC_ALLOCATE_HTABioctl will not fallback to lower sized HTAB allocation and will fail if requested HTAB size can't be met.Check for such failures in QEMU and abort appropriately. This will prevent guest kernel from hanging/freezing during early boot by doing graceful exit when host is unable to allocate requested HTAB.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)hw/ppc/spapr.c +0
-0@@ -1021,9 +1021,19 @@ static void spapr_alloc_htab(sPAPRMachineState *spapr)* RAM */
Quoted 14 lines
hw/ppc/spapr.c static void spapr_alloc_htab(sPAPRMachineState *spapr) · line 1029
Quoted 10 lines
hw/ppc/spapr.c +6
-3shift =kvmppc_reset_htab (spapr->htab_shift); - -if (shift >0 ) { -/* Kernel handles htab, we don't need to allocate one */ +if (shift <0 ) { +/* +* For HV KVM, host kernel will return -ENOMEM when requested +* HTAB size can't be allocated. +*/ +error_setg (&error_abort,"Failed to allocate HTAB of requested size, try with smaller maxmem" );Wording is appropriate, but maybe just "Failed to allocate HTAB, try with smaller maxmem" to distinguish it from the error below where the call succeeds but there's a size mismatch?
Possibly the message could be a little better, but I'm not going to hold up the patches just for that. I've applied tentatively to spapr-next, and I hope to send a pull req with it soon, assuming it survives my tests.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson