powerpc/kvm/cma: Fix panic introduces by signed shift operation
Subsystems (3)
PATCH 1/1 powerpc/kvm/cma: Fix panic introduces by signed shift operation
fc95ca7284bc54953165cba76c3228bd2cdb9591 introduces a memset in kvmppc_alloc_hpt since the general CMA doesn't clear the memory it allocates.
However, the size argument passed to memset is computed from a signed value and its signed bit is extended by the cast the compiler is doing. This lead to extremely large size value when dealing with order value >= 31, and almost all the memory following the allocated space is cleaned. As a consequence, the system is panicing and may even fail spawning the kdump kernel.
This fix makes use of an unsigned value for the memset's size argument to avoid sign extension. Among this fix, another shift operation which may lead to signed extended value too is also fixed.
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +2 -2
@@ -62,10 +62,10 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp) } kvm->arch.hpt_cma_alloc =0 ; - page =kvm_alloc_hpt (1 << (order -PAGE_SHIFT )); + page =kvm_alloc_hpt (1ul << (order -PAGE_SHIFT ));if (page) { hpt = (unsigned long )pfn_to_kaddr (page_to_pfn (page)); -memset ((void *)hpt,0 , (1 << order)); +memset ((void *)hpt,0 , (1ul << order)); kvm->arch.hpt_cma_alloc =1 ; }
Signature · 1 line
1.9.1
Il 02/09/2014 18:13, Laurent Dufour ha scritto:
Quoted 34 lines
fc95ca7284bc54953165cba76c3228bd2cdb9591introduces a memset inkvmppc_alloc_hptsince the general CMA doesn't clear the memory it allocates.However, the size argument passed to memset is computed from a signed value and its signed bit is extended by the cast the compiler is doing. This lead to extremely large size value when dealing with order value >= 31, and almost all the memory following the allocated space is cleaned. As a consequence, the system is panicing and may even fail spawning the kdump kernel.
This fix makes use of an unsigned value for the memset's size argument to avoid sign extension. Among this fix, another shift operation which may lead to signed extended value too is also fixed.
Cc Alexey Kardashevskiy <[email protected]>Cc Paul Mackerras <[email protected]>Cc Alexander Graf <[email protected]>Cc Aneesh Kumar K.V <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/powerpc/kvm/book3s_64_mmu_hv.c +0
-0@@ -62,10 +62,10 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp) }
arch/powerpc/kvm/book3s_64_mmu_hv.c long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp) · line 71
Quoted 10 lines
arch/powerpc/kvm/book3s_64_mmu_hv.c +2
-2kvm->arch.hpt_cma_alloc =0 ; - page =kvm_alloc_hpt (1 << (order -PAGE_SHIFT )); + page =kvm_alloc_hpt (1ul << (order -PAGE_SHIFT ));if (page) { hpt = (unsigned long )pfn_to_kaddr (page_to_pfn (page)); -memset ((void *)hpt,0 , (1 << order)); +memset ((void *)hpt,0 , (1ul << order)); kvm->arch.hpt_cma_alloc =1 ; }
Thanks, applied to kvm/master.
Paolo