Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp539498ybt; Fri, 19 Jun 2020 07:47:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGPk7ycAvLN1HGQV5xG2+58A9RUPYm25pwhVwFW+E1DoL8O/+6scnx9AoUyhfEFO3qFPki X-Received: by 2002:a17:906:328d:: with SMTP id 13mr4098248ejw.71.1592578064252; Fri, 19 Jun 2020 07:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592578064; cv=none; d=google.com; s=arc-20160816; b=uRRSZlSbheXnW1mgEPWCF2NT0CPmWiM/TJhkwiH9qUEtmfLCbTgfA+0vF/M3+ewdDC kGNoEK9ZdUAlo5SV/vUL6Da71oHXH/UxuN8BeaWwnIqx5QaKdXALOWlj8GZO+TQ4raa6 k1OgD9PZZbVuJBza8kHVfcJhjZTvA9s2NLSCxHxrwuHh69DpVIdhGgF+1dqlUJdObK5s ROa6Ir1xjXaBGiHJQcnuTeBr0PrL6iSyi4a9Wkrkw7ILksCUcrh4VGs7EnAz0w1r3QeI AuwLNMG6ojSalv85VN2cjvSA1U1cOB2BJxhzbxf+YkYi9KGuBKTxbShlEFsCUKgn3LWR C/Jg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XqAsha7Xr0SwztcCRY8ZYpCEQkjdRt9pNfkmECuRJdc=; b=oI0Kq8+UHNBLtpOaSPCBqALn2K8SOYD8nyQtskUsvBEfAT+eGFPO8hv/XKLpTk/X2q yaY+5aUTl3197eIhjKwxWUF2KGpTmKNsTiZsxOFKOEB6rTXB2PDqTFZjTfmPt9vVvOC1 Ck7oXCSjI4dnWz4DTZyjHLvR2Qa4FruQSohwOQMS8R0YLi+gmF8xOvJ5oWJgAB4+tpUM 6U6Zt65SV7TzOduY4KDOi8PrhCOoXxYgxKnjpHmxs2EygsQMwctyyj9pgd6eAtN/rIit KGUScvqmwTWkbooN1wyAkHhrLesUxN4AxsxrMkL9WsYXdofG55HnSBaQ/CX2KmJrr4Dy Z6Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GOikWrOl; 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 ha3si4034167ejb.563.2020.06.19.07.47.21; Fri, 19 Jun 2020 07:47:44 -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=GOikWrOl; 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 S2388371AbgFSOm3 (ORCPT + 99 others); Fri, 19 Jun 2020 10:42:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:33070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388360AbgFSOmX (ORCPT ); Fri, 19 Jun 2020 10:42:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0725220A8B; Fri, 19 Jun 2020 14:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577743; bh=pxgSyVKkpou3NKy03mk+bnttCALOfZDsUasjBAUo34Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOikWrOlQk65Ef/eju+ucVYeBFgSg0XaoyRbHbhO9w2owNL8L5WYCzOmm/rfa1xyG 6gXR7OzRlzoBpYBPApXRZX1YmFW8J70WaNXAuZKfrdumGNht2CADkHbI8m1Dr/KCgc BsfUJvrfi1ycOv8ZUEzpRbT9jghxbhDDtLTst8ZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juxin Gao , Tiezhu Yang , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 4.9 072/128] MIPS: Make sparse_init() using top-down allocation Date: Fri, 19 Jun 2020 16:32:46 +0200 Message-Id: <20200619141624.000569956@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 7cc1d29334ee..2c3b89a65317 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -847,7 +847,17 @@ static void __init arch_mem_init(char **cmdline_p) BOOTMEM_DEFAULT); #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