Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp836670yba; Fri, 3 May 2019 11:15:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1GyvXaaBfUV0+m/x7303NmEewnXrBjy77ITp/VvkSa5YpabqYZYUR5ukYyaSep3ifEX/R X-Received: by 2002:a17:902:3064:: with SMTP id u91mr12490377plb.181.1556907301061; Fri, 03 May 2019 11:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556907301; cv=none; d=google.com; s=arc-20160816; b=Szu4QedJZIu5j+S+ORwAjxKjGF4g0eQF09LOhFkmsw5ANGJ5NdT25UZ/n6X0xMLz4w ixyG01Fqm/iNmUi2Bor84UIt9AOJA3dPvvdVa6KmNmBPE8Mamj0+eY+PBgt/PYPkm9w2 Odcn9yHo9BKW+we33xRr/rGh5p13kAF4sAjQjkYpZ+HT41ylTgcqqEL3N+d3CT9cJ7YU F2toCTUX2uXM7odvX0kFFNKkgp1c3LsRT+oFG55tCiejzZzAix+mvt75iH6wegR2dcPI EiglK455kHE9hOo9gNKwdJbW9c9Swx8n0vQhwvf5EmIttu9cQL11y3AYM0zPaED3jWZO dOpQ== 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=v/LR8SgjCFeSasZGBO3FAtfYGfrjDhMD48wHn2t6CEQ=; b=tBK7PaVNqP9Y98aK4DMrzozypQgWJ4PHcV1/o03ysUF30AnQbZzuPov5VmWusrqgeP pwZ3HIComAs52Pnl1wLb2rDPfpHORYyzgdviXmg2fu0AChtmNqekiz2MR3skOpTmtPff WROhDRy8ilJkW4ZwUupoSQSvfV+Vo6hBBPgs5+JIanMczEyq+s5zVjPTky3iOoClOw9b J6HGTDsV4y5g2Ha52UxTBTN4pLbYKYHwrMfE/g7JIHOUn9L2gx8v7zBlpEyEFOHV41py vmcL7r99LUs/mYNuvVwABNAB9UAgQML0pCeiOb2XWEsYUWz+fGOXqhn074UE4MOcxNvE 9+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cae9601w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si3760457plr.51.2019.05.03.11.14.45; Fri, 03 May 2019 11:15:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cae9601w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728871AbfECRv4 (ORCPT + 99 others); Fri, 3 May 2019 13:51:56 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:40797 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728820AbfECRvn (ORCPT ); Fri, 3 May 2019 13:51:43 -0400 Received: by mail-lf1-f65.google.com with SMTP id o16so4986114lfl.7; Fri, 03 May 2019 10:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v/LR8SgjCFeSasZGBO3FAtfYGfrjDhMD48wHn2t6CEQ=; b=cae9601wLSgRgqYUW45HHj8WE00Rab3oTgbbv7YEKZ7iWuBEXqVcvBvBFDC+Lj2rdF kxx5F4fsKKh+497U9XtItDjTmZ62zzgTWNSYrCQcMslr1pmTmJr8enHEs86QHdIV57uU hLlKQP6tr3OOlH9naxjGISBIjanifWnb7VUAVTXD0u5EVuSlo9FpA81YGfhpCnN+qY5w QofuZIULE2XmBTGzzy2a4of6xPWOzqC1p9gRvMT16chmiUccDlYQ6mtRwvw+544Fa3qv Z4LpBQwqFfR8w7EGMu50RdlZxXPR0yn9ZEkSeeuvdtft5vgKAU7FrZUB0SdPUl4efqW4 oVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v/LR8SgjCFeSasZGBO3FAtfYGfrjDhMD48wHn2t6CEQ=; b=g/2BGS8qWtdsCB0vlJfMAt0KS2y9VbVVB5RONiZfcXrD2b7Imqew+bIRSMkEG6Ivi7 SvLidOU0UMqWXh49sRZMdHKey3ichsx6BQjrViEOXYSxHMhZzwadF1ZkTK7FNgmoW+BK UHGprCoFDhSQDBqRfDkNxR9UaovcB4KXpjZBLdj1yvoR4r/bst75T6H9nzxpebyi/46B GBEKjAvl7g/I4IImYUbOl53wQRdWHz7afcYUHMgBBqy3X7fb9msgC7CC+mb7QJf4Csbf zpWDqr0SjA+WN9GGj85rGlakynIvCm0CCbI4CDMP2siIqPza50KZjSYXr2IdRkJsu80w XM1w== X-Gm-Message-State: APjAAAUe4Zu/WYejTGL7URR+a79Cd8xQMEsPbkU7Rimc0hfT5LFCcGN2 MfE+I/OvQCHriRivEWnLfmM= X-Received: by 2002:ac2:44b2:: with SMTP id c18mr5577711lfm.86.1556905901150; Fri, 03 May 2019 10:51:41 -0700 (PDT) Received: from localhost.localdomain ([5.164.217.122]) by smtp.gmail.com with ESMTPSA id z30sm533435lfb.87.2019.05.03.10.51.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 10:51:40 -0700 (PDT) From: Serge Semin To: Ralf Baechle , Paul Burton , James Hogan , Mike Rapoport , Andrew Morton , Michal Hocko , Greg Kroah-Hartman , Thomas Bogendoerfer , Huacai Chen , Stefan Agner , Stephen Rothwell , Alexandre Belloni , Juergen Gross Cc: Serge Semin , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] mips: Make sure dt memory regions are valid Date: Fri, 3 May 2019 20:50:40 +0300 Message-Id: <20190503175041.7949-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190503175041.7949-1-fancer.lancer@gmail.com> References: <20190503175041.7949-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are situations when memory regions coming from dts may be too big for the platform physical address space. This especially concerns XPA-capable systems. Bootloader may determine more than 4GB memory available and pass it to the kernel over dts memory node, while kernel is built without XPA/64BIT support. In this case the region may either simply be truncated by add_memory_region() method or by u64->phys_addr_t type casting. But in worst case the method can even drop the memory region if it exceeds PHYS_ADDR_MAX size. So lets make sure the retrieved from dts memory regions are valid, and if some of them aren't, just manually truncate them with a warning printed out. Signed-off-by: Serge Semin --- arch/mips/kernel/prom.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c index 437a174e3ef9..28bf01961bb2 100644 --- a/arch/mips/kernel/prom.c +++ b/arch/mips/kernel/prom.c @@ -41,7 +41,19 @@ char *mips_get_machine_name(void) #ifdef CONFIG_USE_OF void __init early_init_dt_add_memory_arch(u64 base, u64 size) { - return add_memory_region(base, size, BOOT_MEM_RAM); + if (base >= PHYS_ADDR_MAX) { + pr_warn("Trying to add an invalid memory region, skipped\n"); + return; + } + + /* Truncate the passed memory region instead of type casting */ + if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) { + pr_warn("Truncate memory region %llx @ %llx to size %llx\n", + size, base, PHYS_ADDR_MAX - base); + size = PHYS_ADDR_MAX - base; + } + + add_memory_region(base, size, BOOT_MEM_RAM); } int __init early_init_dt_reserve_memory_arch(phys_addr_t base, -- 2.21.0