From nobody Thu Dec 25 07:01:24 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 ED5245788D for ; Fri, 19 Jan 2024 20:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705695256; cv=none; b=T7v7gqe8kRAQb4lWf6sgFHqUzli++ukOFpC6DFPBz+G/s71eedCEMzEK5CR7cyyXcgRu5YYFhyDjZaPMCUy9cN5p4vF0N1KPQXug87uS36oYoSKP13QumtKu8aagM3A3DK0INy6Etj07R0FhEACdERArktrnydJwHbqDqo3SiLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705695256; c=relaxed/simple; bh=JxFs1rbHTLTpSL80XNLyDexMpSKcJsmi17aOK7u7oFE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LKb4Eo0C+5PKaMWNaqZEQcwK1bx5WqpZHZbQIULixa8KqObXZ4V6ivESKoFVP0feAcVYvq1092YyjeFaUMEmWbd5hKKYBnZSe8zcd1p8UEwrEptwovCPndtMWuPdhxFocBjqEPHyHMSOvcrF1rP2tF4x1vtZqoy5EugeXbGeBCY= 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=OGRnptxy; arc=none smtp.client-ip=209.85.221.51 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OGRnptxy" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-336c5b5c163so752976f8f.1 for ; Fri, 19 Jan 2024 12:14:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705695250; x=1706300050; 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=e35XnQv7+JeMDazmnVaku5/bw/ATFIlRQ/6xz7OKU3s=; b=OGRnptxynB6Mq+fBHTGbLaSOoyClsV9w28SPGfSqge01kSuQSJ3GZjTd6ejp+mq0G/ LVXeLKeli4gvJ3H+TyrUM3/WtGz1oFKlOtICHiGVbvOiYtaccEhy+3OOrE6NeBmDFPKF o4vZ/4sZZ/srp/K9d7oqq9FssrKfhiQqNYBA3sr8RHOv5ZA2bRKmDcBMMeOWgfT/BkIB dIToUe/M9ocnJpnov9qYux0J9LnACZl9dTpVIoVlag0elTTL/6z4ZEzBX5BBFyx2JPxL zuehgd1CuyMTW8neMGUlUZ9Z1katciZCdYNVNSfmckJFIMt9cKw8xaE0ZIjBIkT7CS/C cjSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705695250; x=1706300050; 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=e35XnQv7+JeMDazmnVaku5/bw/ATFIlRQ/6xz7OKU3s=; b=qIGVCO72rRtTcoSwHrhU5CjbmkTc4LgxDCY373GvYgtWEfwyF27HD/UwtWIrQ0LM7C hoGkBktlFoJP7VkI1fUja9F1ZhOscSZxpXL1WYG5wWYeiLnM7iZPxCV+A1b1QrAYRQ2W EJZzI+7S0eOOG1BunZqLi9P+6wVnkeJJfMNr3DS42pwQu/s1/IiKEoY+7jdu37MBY/05 PmiACE9xmv3etEFGkXX845c4i+cqCShbqWATVhbDxjywieNPiYGjBeCc+F67hTPDZPo/ 5IvWLhuTUdS3OxoYEm27a3IUkY6SQ6qRJeHSERjWeVgnsgYA9qxnuzDRCIBifk0feSIb yrJw== X-Gm-Message-State: AOJu0Yx5IxaQaxcYzqL2HIUI7i8XmJk7aTgL0hhhHOMBiRzsV9cZ0uft d/KnukGVUZqV697uShWHtaNIQRo9n5rnNKFu+TQ/7Vq8aAtifKQe X-Google-Smtp-Source: AGHT+IFwN1VEXA51pQLlXmt/K6R/WGzdCtBOcilbAPksqwEOjCe5BbskxHNB7jfp5oXi4o+U0z8Wrw== X-Received: by 2002:adf:fdcd:0:b0:337:d85d:87f2 with SMTP id i13-20020adffdcd000000b00337d85d87f2mr977177wrs.8.1705695249639; Fri, 19 Jan 2024 12:14:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 12:14:09 -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 1/2] ARM: decompressor: support memory start validation for appended DTB Date: Fri, 19 Jan 2024 21:12:44 +0100 Message-ID: <20240119201356.7903-2-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is currently a problem with a very specific sets of kernel config and AUTO_ZRELADDR. For the most common case AUTO_ZRELADDR check the PC register and calculate the start of the physical memory. Then fdt_check_mem_start is called to make sure the detected value makes sense by comparing it with what is present in DTB in the memory nodes and if additional fixup are required with the use of linux,usable-memory-range in the chosen node to hardcode usable memory range in case some reserved space needs to be addressed. With the help of this function the right address is calculated and the kernel correctly decompress and loads. Things starts to become problematic when in the mix, CONFIG_ARM_APPENDED_DTB is used. This is a particular kernel config is used when legacy systems doesn't support passing a DTB directly and a DTB is appended at the end of the image. In such case, fdt_check_mem_start is skipped in AUTO_ZRELADDR iteration as the appended DTB can be augumented later with ATAGS passed from the bootloader (if CONFIG_ARM_ATAG_DTB_COMPAT is enabled). The main problem and what this patch address is the fact that fdt_check_mem_start is never called later when the appended DTB is augumented, hence any fixup and validation is not done making AUTO_ZRELADDR detection inconsistent and most of the time wrong. Add support in head.S for this by checking if AUTO_ZRELADDR is enabled and calling fdt_check_mem_start with the appended DTB and the augumented values permitting legacy device to provide info in DTB instead of disabling AUTO_ZRELADDR and hardcoding the physical address offsets. Signed-off-by: Christian Marangi Reviewed-by: Geert Uytterhoeven Reviewed-by: Linus Walleij --- arch/arm/boot/compressed/head.S | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/hea= d.S index 9f406e9c0ea6..2ff38a8df1f0 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -443,6 +443,28 @@ restart: adr r0, LC1 add r6, r6, r5 add r10, r10, r5 add sp, sp, r5 + +#ifdef CONFIG_AUTO_ZRELADDR + /* + * Validate calculated start of physical memory with appended DTB. + * In the first iteration for physical memory start calculation, + * we skipped validating it as it could have been augumented by + * ATAGS stored at an offset from the same start of physical memory. + * + * We now have parsed them and augumented the appended DTB if asked + * so we can finally validate the start of physical memory. + * + * This is needed to apply additional fixup with + * linux,usable-memory-range or to make sure AUTO_ZRELADDR detected + * the correct value. + */ + sub r0, r4, #TEXT_OFFSET @ revert to base address + mov r1, r8 @ use appended DTB + bl fdt_check_mem_start + + /* Determine final kernel image address. */ + add r4, r0, #TEXT_OFFSET +#endif dtb_check_done: #endif =20 --=20 2.43.0 From nobody Thu Dec 25 07:01:24 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TP+emgSi" 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-Google-Smtp-Source: AGHT+IFOTbdL41cPmnp9k4iSwF+mjvZLoMetREkJ8ghXgjbgzt/oHLxO7qTkVIPVPM4SNAVG2Qk5Pw== 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Linus Walleij --- 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. =20 +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/compre= ssed/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 =20 +#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 =20 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 =3D=3D ATAG_MEM) { + /* Bootloader MEM ATAG are broken and should be ignored */ + if (do_ignore_mem) + continue; + if (memcount >=3D sizeof(mem_reg_property)/4) continue; if (!atag->u.mem.size) --=20 2.43.0