Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4125329yba; Tue, 23 Apr 2019 15:51:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxehlEw/0H9HooxRtjdWLe/Kc53c0rqx7zDwuAfcJ21jbU0ctdFQzuyL3YikYGHZUzLzjuM X-Received: by 2002:a63:c54e:: with SMTP id g14mr27073192pgd.265.1556059881694; Tue, 23 Apr 2019 15:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556059881; cv=none; d=google.com; s=arc-20160816; b=wAEaIbt0kLX5XoAgZ0RRIF1n3BTDwERj8iO+BwSH22prhEgInuX3ASR/50lH0Y6bQr d5nBzSrhbMTQ7DeGPMA7eURVTcFFvQzu51F3Iq74opSYeJEot+rSlGVI975mGZT3QS7M 2S6RnY/SkiE3LTUT1ecNYnuc4oNEhBwPyHScNTwBQjvV4XdcGUCURxNFDdWaqobqL+Kp 72+4M87RJaLc8EpbGT3YjMQrlWUs6cd2+kP9nWwMAqcCoM3j0FoNYPEWlNBuVzyRzcDc ALnmPAN/Mlk1ZGLoNfIBLf1/G2Em0BLuturpz+Ii69NpkWGqEtRuMCWzzkK6FHNPdRpN z0+g== 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=VJ3xwWJXog1KPx7zXkBt+0FT1onV4wm00T3cYGUdK8o=; b=s6NVNQ8HmBQkgVEAH0xrVLeYtqoB5VPD9NhjhH7ejnnsVymltNQS8QAt5mg7044iv/ 4T0TMPG5PGAYoVDIC7E9W/oZCES77u5DqcwY0+F/Y12uWGtdGY7o/zJECWvnuBjs21TK aO7hAWmSZyaGJ0W5SiKHxYvb4QdpVThFn7ZLPmaX0mBMGz9G4OdmjNyioS2Zf1XQKAfb bkmPrO8CwRiYejGQpeJ8xOV9IX4hrd00+HTIvE3Q5zRknK+ag3hb0fuxY+AwwyMKz9ss NMxA6C2FJaMxuW0Gl8xX81ZklY++O4gCmRZ6ofpdcpjtwgFud3W0d2UJ582dI65JCAqg Xgyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="dfuEeI/x"; 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 30si16465774plb.235.2019.04.23.15.51.06; Tue, 23 Apr 2019 15:51:21 -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="dfuEeI/x"; 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 S1728864AbfDWWt6 (ORCPT + 99 others); Tue, 23 Apr 2019 18:49:58 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46699 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728647AbfDWWtm (ORCPT ); Tue, 23 Apr 2019 18:49:42 -0400 Received: by mail-lf1-f66.google.com with SMTP id k18so12985435lfj.13; Tue, 23 Apr 2019 15:49:40 -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=VJ3xwWJXog1KPx7zXkBt+0FT1onV4wm00T3cYGUdK8o=; b=dfuEeI/xqrZujHXykgX4UeKXjmUGMkHpprck0gZu6b9Bl+E4QQtmhiG0xc2Hno05dN 8NwdxoNghrzZa9uBXrKYxfALB8W0i2pkIt9A6r8VGoZIp4MJw/gte2dfoBfDvQaE9YoX 5qKAZfvywTQAZJ1LFEqWlqlbkL7uAqlkt/3kzxq16ZwCtG2CH8rNUjnacYPTjQHY4Q4T 5MBHpcQ6QrTZXh1oLEDtsPMmOGPJaHaSRO4wKCk389PNku/iR15uRauOVW2a/qWln0/y ScMdJNPbgjTei27drIJdmMnqPBQgtP3o4YsBPActjbdsufmqVipYWtTnNySptsptVU2V rvBg== 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=VJ3xwWJXog1KPx7zXkBt+0FT1onV4wm00T3cYGUdK8o=; b=bAGyEwtIF9JKMFfYJxnIqf/kbgITNZycpdv3ZWK2dDIkPK4u+d+sMvY6xyaTtQTBIf 33qCDv6PcskbPqRnxVIbKCob4WX6t/YOMhobcsLqmCdHLe124a5bh4ASFb2U/Of3uiTb pUoBplqTda/Jge84aJ0+YS5wcshNESiqp4dhlI8667HUr+EURMeOJbF/6sgelsmL4uEV IHqK8QDXnPZQZGgYN1IFZNtnmuSPYMw3Hd1IoRaJL7D0P2IU8Alcdm0jOknXJGaahJx8 fqUSCB/VwGx27Z8OYWs4aTAz/vcCskdPhyGApR8SuD9GrVWy8LfLzypjoRtsH13AxcV7 6ouA== X-Gm-Message-State: APjAAAWcYMTmqnJ9BDf+c7Z1hhaC/jK7xNoi/F9C0Hjnzo3sSMfQLUxD G4CLol9d6E/Xov9PP1MdkdM= X-Received: by 2002:a19:c216:: with SMTP id l22mr14887697lfc.112.1556059779541; Tue, 23 Apr 2019 15:49:39 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id w2sm4904722lfa.63.2019.04.23.15.49.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 15:49:38 -0700 (PDT) From: Serge Semin To: Ralf Baechle , Paul Burton , James Hogan , Matt Redfearn , Mike Rapoport , Andrew Morton , Michal Hocko , Greg Kroah-Hartman , Thomas Bogendoerfer , Huacai Chen , Stefan Agner , Stephen Rothwell , Alexandre Belloni , Juergen Gross Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Serge Semin Subject: [PATCH 11/12] mips: Make sure dt memory regions are valid Date: Wed, 24 Apr 2019 01:47:47 +0300 Message-Id: <20190423224748.3765-12-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423224748.3765-1-fancer.lancer@gmail.com> References: <20190423224748.3765-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. It especially concerns XPA-capable systems. Bootleader may determine more than 4GB memory available and pass it to the kernel over dts memory node, while kernel is built without XPA 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 exceedes PHYS_ADDR_MAX size. So lets make sure the retrieved from dts memory regions are valid, and if some of them isn't just manually truncate it 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