lkml.org 
[lkml]   [2012]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v6 23/27] x86: Don't panic if can not alloc buffer for swiotlb
Date
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 could panic when we try to use
kdump with buffer above 4G only.

Replace the panic with WARN, and the kernel can go on without swiotlb,
and could iommu later.

Signed-off-by: Yinghai Lu <yinghai@kerne.org>
---
arch/x86/kernel/pci-swiotlb.c | 5 ++++-
include/linux/swiotlb.h | 2 +-
lib/swiotlb.c | 17 +++++++++++------
3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 6c483ba..6f93eb7 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -91,7 +91,10 @@ IOMMU_INIT(pci_swiotlb_detect_4gb,
void __init pci_swiotlb_init(void)
{
if (swiotlb) {
- swiotlb_init(0);
+ if (swiotlb_init(0)) {
+ swiotlb = 0;
+ return;
+ }
dma_ops = &swiotlb_dma_ops;
}
}
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 8d08b3e..f7535d1 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -22,7 +22,7 @@ extern int swiotlb_force;
*/
#define IO_TLB_SHIFT 11

-extern void swiotlb_init(int verbose);
+int swiotlb_init(int verbose);
extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
extern unsigned long swiotlb_nr_tbl(void);
extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index f114bf6..6b99ea7 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -170,7 +170,7 @@ void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
* Statically reserve bounce buffer space and initialize bounce buffer data
* structures for the software IO TLB used to implement the DMA API.
*/
-static void __init
+static int __init
swiotlb_init_with_default_size(size_t default_size, int verbose)
{
unsigned long bytes;
@@ -185,17 +185,22 @@ swiotlb_init_with_default_size(size_t default_size, int verbose)
/*
* Get IO TLB memory from the low pages
*/
- io_tlb_start = alloc_bootmem_low_pages(PAGE_ALIGN(bytes));
- if (!io_tlb_start)
- panic("Cannot allocate SWIOTLB buffer");
+ io_tlb_start = alloc_bootmem_low_pages_nopanic(PAGE_ALIGN(bytes));
+ if (!io_tlb_start) {
+ WARN(1, "Cannot allocate SWIOTLB buffer");
+ return -1;
+ }

swiotlb_init_with_tbl(io_tlb_start, io_tlb_nslabs, verbose);
+
+ return 0;
}

-void __init
+int __init
swiotlb_init(int verbose)
{
- swiotlb_init_with_default_size(64 * (1<<20), verbose); /* default to 64MB */
+ /* default to 64MB */
+ return swiotlb_init_with_default_size(64 * (1<<20), verbose);
}

/*
--
1.7.10.4


\
 
 \ /
  Last update: 2012-12-13 23:41    [W:0.301 / U:0.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site