From patchwork Fri Jan 19 20:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 189670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1261207dyb; Fri, 19 Jan 2024 12:16:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmM+O5/iiRigHnVZG91wb6kixlOyECq9PbsZvEnjINItRixlyEwUqo8urqdYbHKCK2dF05 X-Received: by 2002:a17:902:db06:b0:1d3:5b35:543a with SMTP id m6-20020a170902db0600b001d35b35543amr572736plx.109.1705695398393; Fri, 19 Jan 2024 12:16:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705695398; cv=pass; d=google.com; s=arc-20160816; b=IrRU73V6S4xRVzOX4/6zhWX4WDIFigR07EMLgnnS/HCDV3wpcyuRCa//NRLHfbRcAg AoYSB+MbT+Crwyjt0tuW3UZmi2/vubGtO3eIQd6hjJ5bvNSf+P50HRiXFKgqCfOUfJfS HOjEhYU31CYzddOyuZp+Rl22o4Of4fukLaBvbXNIpQOTADBH8XY5J0M+Pc5VUQgGhbIT 9yCv0jmDwSq5mg+hOZMPEgv0KD27nnpzaTVjkCyPoQZDIBxRBeitoBKUl6gOJX8lrb4z rdgLupwPgNTF6RzcHcdi6FeJEJdL5s5KPRTR2FPmPAWxBR1qpnezYaTL0uYgUBxg4ZTR D4pQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=cslHUuioJKZUdWZhA350tTceu4m4Qgt6DILKRrYZ0CA=; fh=AzxL8H9Nc+PoOc11FezgGVhkenvx72SZcZi/yiG9gaw=; b=v4vLJT4dEFWaR30p2kZED0Fus3N4QEYWwy4rXAKk6LqKWMc98sOayA7jLP1t/x7JrC k5hIGs46RZ71vnHcMKb3F1Ul35BbLiJkAz+sCC2UBxo95WKC7BVZgM3zQG4MxIFmiQiG DoVKXzxNaZSJXsWVeCpl27C2pABoPNU67WfRRMCI7NbV/9FCmNRPwq1dSIZws9d41aDd kuTdf8J3MBPQtrutAdRnOAzxLSLIWerYtXTjRAPd0/fLZd5bIXDJVKKyfNYOxXcmffn1 pWrr5rQD93PJo6501ndAT0IxuMTPJ4C/uGlg9GBX9RqQyPAxutUqYWeYWtTQj/4Yixgs rcGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TP+emgSi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-31538-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31538-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p21-20020a1709028a9500b001d5eb92221esi3757885plo.592.2024.01.19.12.16.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 12:16:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31538-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TP+emgSi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-31538-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31538-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2E290B24143 for ; Fri, 19 Jan 2024 20:14:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3033758231; Fri, 19 Jan 2024 20:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TP+emgSi" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F341B57873 for ; Fri, 19 Jan 2024 20:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705695255; cv=none; b=a5DaFVMq8oxp5+jjyRuJf8J4U5zT0TSENYkXqn5KsyhJPpD349PgW/SihzKYU5oIOO/y1CclkHCP1BDs9kzuJUsm9NitgptNwUoeJuwxPPl+HESKUxlcGo74GhuVsgFiYeeDU0AIt65G5vwyjgzbPtRi8fi4o0CyxHOXl7IpalE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705695255; c=relaxed/simple; bh=F9Ijc1dkn4LnIYgLJYdQeo8/xAlm6GZYuUki9yJ2hME=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ixJzJES2ex9/r/ZS6ZgPLSbTZ5+yRUYiS1EYCjKbdWV9e/ILcRBKatVddXerX28rcmDG0Haz4pd9SojrUezpJy8YBv3mOr8ydrBBnJZwhw4gpTzbEWuoooHYn0BxVudYv7R/M3oRCm5yfSs3UzUlUz92sunGycQfrhJYJC5zmgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TP+emgSi; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40e8801221cso10479895e9.1 for ; Fri, 19 Jan 2024 12:14:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705695251; x=1706300051; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cslHUuioJKZUdWZhA350tTceu4m4Qgt6DILKRrYZ0CA=; b=TP+emgSirsMxBcK31BpgZQs9B2cV6Xqdyn7U+yLygJylIirfAWFO07JRsReVegK9n1 3G2/CVAyG41/yHTtiqn0u2/b/TyDJ3Igoc2CgmWbNh10ypo+BZpNfxa0t4HpuzbaRAvd Czfb9gboYR95/YbWzYZuxgnU6K4pOHGKOa/j8/zexW7kzmOqP4+3p+7RpCIqyen+cWkK P56HPBaYrWyho8crCZHPD+ZO1E0es7hpzh8028HJaWvUZRhSqnlBMIFJVvZBRaeL6yZD OKpfnun/0VlHw6cVBe3l8goGDxu5KMVyTsbi/2naV4THanuaYguqeMH/j81A47eRDhbL /J0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705695251; x=1706300051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cslHUuioJKZUdWZhA350tTceu4m4Qgt6DILKRrYZ0CA=; b=Kwv/ePGjfo5qsqsm4f1ZmAMnF0G7v6tjO4znD/uIggL7Oof1dWEhVMSnqlfb3mQDXD KLz/b7uQWLV9is6Qh42bjZXiQTtIdNUJK1aT7dtlG4W3eMRxAW58co01Np/Z8C0rRFVt 6KoNHSZ2mlJ6jbyonQF75UpBSFJhDTwI/G3RGtwo9oJLm8BQiq20ZPwtRQE4CUONKlF3 PDQtQT/uKkocMFN8OZ+7i6kQ4PFKTSSku0cmMnuLtvHaRDgas+FWYdOkaxYPZmRAHACk vpmFwq+7RGH8CE/uZk6dJPRLG+fGXY0BdNobMycySv6cI/zJUWjo+bEr/zMKKOruU9b6 I0Zg== X-Gm-Message-State: AOJu0YxR/zKd2ofFUcou6WXCLnHoMJWzKc/1lMwjLdRP+QTAmLLq72eT PF+PTufK0Uqv4QPBiqJEI3A7sqEV8htFZtE8U0M+bcujeqQzvq0U X-Received: by 2002:a1c:7404:0:b0:40e:6b8e:5ab2 with SMTP id p4-20020a1c7404000000b0040e6b8e5ab2mr189320wmc.106.1705695250892; Fri, 19 Jan 2024 12:14:10 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id q5-20020adff505000000b00339214d70b5sm2084788wro.85.2024.01.19.12.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 12:14:10 -0800 (PST) From: Christian Marangi To: Russell King , Arnd Bergmann , Andrew Morton , Geert Uytterhoeven , "Kirill A. Shutemov" , Jonathan Corbet , Thomas Gleixner , Randy Dunlap , Christian Marangi , "Mike Rapoport (IBM)" , Eric DeVolder , Nathan Chancellor , "Russell King (Oracle)" , Kees Cook , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , Linus Walleij , John Crispin Subject: [PATCH 2/2] ARM: decompressor: add option to ignore MEM ATAGs Date: Fri, 19 Jan 2024 21:12:45 +0100 Message-ID: <20240119201356.7903-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119201356.7903-1-ansuelsmth@gmail.com> References: <20240119201356.7903-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788551257620374040 X-GMAIL-MSGID: 1788551257620374040 Some bootloaders can pass broken MEM ATAGs that provide hardcoded information about mounted RAM size and physical location. Example booloader provide RAM of size 1.7Gb but actual mounted RAM size is 512Mb causing kernel panic. Add option CONFIG_ARM_ATAG_DTB_COMPAT_IGNORE_MEM to ignore these ATAG and not augument appended DTB memory node. Signed-off-by: Christian Marangi --- arch/arm/Kconfig | 12 ++++++++++++ arch/arm/boot/compressed/atags_to_fdt.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index b2ab8db63c4b..6bb5c6b28106 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1549,6 +1549,18 @@ config ARM_ATAG_DTB_COMPAT bootloaders, this option allows zImage to extract the information from the ATAG list and store it at run time into the appended DTB. +config ARM_ATAG_DTB_COMPAT_IGNORE_MEM + bool "Ignore MEM ATAG information from bootloader" + depends on ARM_ATAG_DTB_COMPAT + help + Some bootloaders can pass broken MEM ATAGs that provide hardcoded + information about mounted RAM size and physical location. + Example booloader provide RAM of size 1.7Gb but actual mounted RAM + size is 512Mb causing kernel panic. + + Enable this option if MEM ATAGs should be ignored and the memory + node in the appended DTB should NOT be augumented. + choice prompt "Kernel command line type" if ARM_ATAG_DTB_COMPAT default ARM_ATAG_DTB_COMPAT_CMDLINE_FROM_BOOTLOADER diff --git a/arch/arm/boot/compressed/atags_to_fdt.c b/arch/arm/boot/compressed/atags_to_fdt.c index 627752f18661..189db9fc7fea 100644 --- a/arch/arm/boot/compressed/atags_to_fdt.c +++ b/arch/arm/boot/compressed/atags_to_fdt.c @@ -10,6 +10,12 @@ #define do_extend_cmdline 0 #endif +#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_IGNORE_MEM) +#define do_ignore_mem 1 +#else +#define do_ignore_mem 0 +#endif + #define NR_BANKS 16 static int node_offset(void *fdt, const char *node_path) @@ -170,6 +176,10 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) setprop_string(fdt, "/chosen", "bootargs", atag->u.cmdline.cmdline); } else if (atag->hdr.tag == ATAG_MEM) { + /* Bootloader MEM ATAG are broken and should be ignored */ + if (do_ignore_mem) + continue; + if (memcount >= sizeof(mem_reg_property)/4) continue; if (!atag->u.mem.size)