Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp53047ybg; Mon, 8 Jun 2020 16:13:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfVGckteK3HCkNEawZ6gtVyWiz1dszIaiWSOoecT+lqCojS+v45BxiW/cbCLkv4FrhT5Sd X-Received: by 2002:a17:906:b55:: with SMTP id v21mr21649434ejg.298.1591657986130; Mon, 08 Jun 2020 16:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591657986; cv=none; d=google.com; s=arc-20160816; b=t+1neuYMI6jCULg+36R3Cvi38E4eSluYYdJ/zQtNud7hFgMSUGu01MLm0/u9Q4irfg d0XnE/FaBm7vigkQYy6eCdmy4zmqHr/np2e79Insdp6LQFzadsRKhlbTLkazxQ/K2tST ayTiiWoHfKbJvz3J9c7kr0tgtGAewk+UIRyqbVqO2asU4gS46luSZeqQDFmOcDO7QK3f 3nX+wq0Y3EYgfrnShFBznk5cCdKaxuCXIwE1Z1vODgZ5RPiyaafsSljF6RHQxlp7v34M /vUBigPZQPNg0YjmVyZ5QdwCwVj3Emt+ygZkTe/NHbxpx1zsYGOzTa7yZ3PMkrDyZVlJ 3WBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G7kBvqp88zX34VYv2Zr9b7WGrsNxOGLwpOSfYsfDtw0=; b=vayHaBv3inyu2R0WBdHW7pH2zsuTVKvaaiMyL4CK+HI9c4up4CSjk2yUOjfL2vF+Cb u6wDDoDpDiIKNNmbZfDz9Nec92PYbPNDUdwAbO8lBjNueI3O36eg6ZPp/mCF0Z8api9I p7t0J9jmTsHX5xwU6jp/s545F16hkXmxdK6lS0YIKLb8MCxUE+A5/tu97BFzW1wUkFzr hHQ5/hgM8yitBTZmhHZaDImw8s2/NlTO65bTmYVoV598GA4vZLD42XqAPbRnOGtGn4CH jjuXHo5nEldUA9UC9csAh/WfV20G1Wa/SLo35dqhSV0PQnBOLSQvco9KmcUzG0XqY8Ax KWhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X7XKNKCZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si9774618edq.313.2020.06.08.16.12.43; Mon, 08 Jun 2020 16:13:06 -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; dkim=pass header.i=@kernel.org header.s=default header.b=X7XKNKCZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728498AbgFHXJo (ORCPT + 99 others); Mon, 8 Jun 2020 19:09:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:54072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728207AbgFHXIj (ORCPT ); Mon, 8 Jun 2020 19:08:39 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A6A8A2089D; Mon, 8 Jun 2020 23:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657718; bh=0DE62OxpKPeTWcX/ynCTAsqhjaPry1kDxHTLBwogLd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X7XKNKCZ7Oc2FXmlbg1rhnV7Agk45EMGsFGGDJO519jx5eKu/wz0B+LEOFnBo/FxA tMmN23c9NJRnEujLBFuN9ktCWvjCiuqKttj4iVdZi9vjnYY+TMnrBG6qIOTF08n1KV BptiVVBv9DY05RGX6+76ACm032BMb2jP3fI/yUZo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tiezhu Yang , Juxin Gao , Thomas Bogendoerfer , Sasha Levin , linux-mips@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 112/274] MIPS: Make sparse_init() using top-down allocation Date: Mon, 8 Jun 2020 19:03:25 -0400 Message-Id: <20200608230607.3361041-112-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tiezhu Yang [ Upstream commit 269b3a9ac538c4ae87f84be640b9fa89914a2489 ] 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 Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- 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 10bef8f78e7c..573509e0f2d4 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -702,7 +702,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.25.1