Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4522560ybz; Tue, 21 Apr 2020 02:06:13 -0700 (PDT) X-Google-Smtp-Source: APiQypJXSUHdNZSGoLvyc/6TrC50Ssyy7n7D9Jqb+ItNqiXP00N2GIIaXyEBxiSjKgwUsLlrOdib X-Received: by 2002:aa7:d60a:: with SMTP id c10mr18332190edr.66.1587459973193; Tue, 21 Apr 2020 02:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587459973; cv=none; d=google.com; s=arc-20160816; b=v/5LpFETH3IL2p3IcX7UgsmTVWr1Nezla1KQ1Q0aq91HAI2a/b8NB0Fv/mDN1nr97b 8yxELSW+iepVvD+uhUSlhezqLkbMFR9AHGFDGQp0wltLKpg5j/8zJLWAKaBPKwvin1dX x7a2gbFPcSfR3gqi8jh7jUKUi+M1E/MGVFP1auik+I5S4+6Akfby1RrBdV7ZJLF1Mgej 2Jr6GVwjCEhBPvNULC+po2mJtnySmLeZ2jZKgJPdeu37nR1NPwtx/ZHLWRBxxfmHasME piE54MpMaspydRHzjkRvw+BK4svUG/M5NEhPiqNyMP6ueEynp5xhwKEzr/yghMQsoGqt UmGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=cDDct0m+oX+A6J2WWmno4Tc37uHy0u7wJlDpnMybLIo=; b=rAvSI8MeL65ylCdqpw7HYki/a6hxy7+Gy9oxUWjidg0HN/RHOBN10Og44TebKNZmPA z0A62gpwyC34h9M5DFyborYvKhIGXZxWiGamlbudAKG1ATlgpYUOdXSGgDRFPJmrnR5G Ekg6Vbkk9OSjecruz7Wc/2UyNPKaaT3b10BIKqAFgV1rk5kFSuaqjdnj5g1q7W+X0r43 mrnFfJku8hqSIDmu+YwRUdNCVDA2IoKmZ9K94nfvc7dfJP486javRQCceVzNJR1hrDyk Zd7OsskUTVdvYIrijtBGusm5Syxu+rz/YiES4KjWq4ECwKW84AH8XfQ83qaN6YpNEpW3 cnMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si1141429ejr.484.2020.04.21.02.05.50; Tue, 21 Apr 2020 02:06:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728306AbgDUJEv (ORCPT + 99 others); Tue, 21 Apr 2020 05:04:51 -0400 Received: from mail.loongson.cn ([114.242.206.163]:34794 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726052AbgDUJEv (ORCPT ); Tue, 21 Apr 2020 05:04:51 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxT2knt55emXsqAA--.36S5; Tue, 21 Apr 2020 17:04:44 +0800 (CST) From: Tiezhu Yang To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Juxin Gao Subject: [PATCH 3/3] MIPS: Reduce possibility of kernel panic under CONFIG_SWIOTLB Date: Tue, 21 Apr 2020 17:04:29 +0800 Message-Id: <1587459869-12183-4-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1587459869-12183-1-git-send-email-yangtiezhu@loongson.cn> References: <1587459869-12183-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9DxT2knt55emXsqAA--.36S5 X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YCTnIWIevJa73UjIFyTuYvjfUUHq2DUUUU X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the current code, if CONFIG_SWIOTLB is set, when failed to get IO TLB memory from the low pages by plat_swiotlb_setup(), it may lead to the boot process failed with kernel panic. (1) On the Loongson and SiByte platform arch/mips/loongson64/dma.c arch/mips/sibyte/common/dma.c void __init plat_swiotlb_setup(void) { swiotlb_init(1); } kernel/dma/swiotlb.c void __init swiotlb_init(int verbose) { ... vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose)) return; ... pr_warn("Cannot allocate buffer"); no_iotlb_memory = true; } phys_addr_t swiotlb_tbl_map_single() { ... if (no_iotlb_memory) panic("Can not allocate SWIOTLB buffer earlier ..."); ... } (2) On the Cavium OCTEON platform arch/mips/cavium-octeon/dma-octeon.c void __init plat_swiotlb_setup(void) { ... octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE); if (!octeon_swiotlb) panic("%s: Failed to allocate %zu bytes align=%lx\n", __func__, swiotlbsize, PAGE_SIZE); ... } Because IO_TLB_DEFAULT_SIZE is 64M, if the rest size of low memory is less than 64M when call plat_swiotlb_setup(), we can easily reproduce the panic case. In order to reduce the possibility of kernel panic when failed to get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate low memory as small as possible before plat_swiotlb_setup(), so make sparse_init() using top-down allocation. Reported-by: Juxin Gao Co-developed-by: Juxin Gao Signed-off-by: Juxin Gao Signed-off-by: Tiezhu Yang --- arch/mips/kernel/setup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 5481a0c..8db533c 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -700,7 +700,17 @@ static void __init arch_mem_init(char **cmdline_p) memblock_reserve(crashk_res.start, resource_size(&crashk_res)); #endif device_tree_init(); + + /* + * In order to reduce the possibility of kernel panic when failed to + * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate + * low memory as small as possible before plat_swiotlb_setup(), so + * make sparse_init() using top-down allocation. + */ + memblock_set_bottom_up(false); sparse_init(); + memblock_set_bottom_up(true); + plat_swiotlb_setup(); dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); -- 2.1.0