From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755250Ab3ADAvP (ORCPT ); Thu, 3 Jan 2013 19:51:15 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:30582 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755144Ab3ADAuw (ORCPT ); Thu, 3 Jan 2013 19:50:52 -0500 From: Yinghai Lu To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: "Eric W. Biederman" , Andrew Morton , Borislav Petkov , Jan Kiszka , Jason Wessel , linux-kernel@vger.kernel.org, Yinghai Lu , Konrad Rzeszutek Wilk , Joerg Roedel Subject: [PATCH v7u1 26/31] x86: Don't enable swiotlb if there is not enough ram for it Date: Thu, 3 Jan 2013 16:48:46 -0800 Message-Id: <1357260531-11115-27-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357260531-11115-1-git-send-email-yinghai@kernel.org> References: <1357260531-11115-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Normal boot path on system with iommu support: swiotlb buffer will be allocated early at first and then try to initialize iommu, if iommu for intel or amd could setup properly, swiotlb buffer will be freed. The early allocating is with bootmem, and get panic when we try to use kdump with buffer above 4G only if swiotlb is enabled. because actually the kernel can go on without swiotlb, and use intel iommu. Try disable swiotlb if there is not enough ram for it. That is for kdump to use kernel above 4G. Suggested-by: Eric W. Biederman Signed-off-by: Yinghai Lu Cc: Konrad Rzeszutek Wilk Cc: Joerg Roedel --- arch/x86/kernel/pci-swiotlb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c index 6c483ba..949ebfe 100644 --- a/arch/x86/kernel/pci-swiotlb.c +++ b/arch/x86/kernel/pci-swiotlb.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,11 @@ static struct dma_map_ops swiotlb_dma_ops = { .dma_supported = NULL, }; +static bool __init enough_mem_for_swiotlb(void) +{ + /* do we have less than 1M RAM under 4G ? */ + return memblock_mem_size(1ULL<<(32-PAGE_SHIFT)) > (1ULL<<20); +} /* * pci_swiotlb_detect_override - set swiotlb to 1 if necessary * @@ -58,12 +64,12 @@ static struct dma_map_ops swiotlb_dma_ops = { */ int __init pci_swiotlb_detect_override(void) { - int use_swiotlb = swiotlb | swiotlb_force; - if (swiotlb_force) swiotlb = 1; + else if (!enough_mem_for_swiotlb()) + swiotlb = 0; - return use_swiotlb; + return swiotlb; } IOMMU_INIT_FINISH(pci_swiotlb_detect_override, pci_xen_swiotlb_detect, @@ -78,7 +84,7 @@ int __init pci_swiotlb_detect_4gb(void) { /* don't initialize swiotlb if iommu=off (no_iommu=1) */ #ifdef CONFIG_X86_64 - if (!no_iommu && max_pfn > MAX_DMA32_PFN) + if (!no_iommu && max_pfn > MAX_DMA32_PFN && enough_mem_for_swiotlb()) swiotlb = 1; #endif return swiotlb; -- 1.7.10.4