From patchwork Sun Jan 21 20:29:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 189837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2229680dyb; Sun, 21 Jan 2024 12:30:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjP33fqtaxwcfTzZZY3vrzl3IILvOW3R0jutd+zGxAR4E2uLYdMEjKhA4Qq4wZ1papa7Tz X-Received: by 2002:a17:902:c211:b0:1d6:fd6e:d284 with SMTP id 17-20020a170902c21100b001d6fd6ed284mr3200841pll.108.1705869058869; Sun, 21 Jan 2024 12:30:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705869058; cv=pass; d=google.com; s=arc-20160816; b=mLoptjNoR9sFFivuNV9ozIbMTdBxFU4uPzq4vxc8JnKK/XK8KdNgpMuJTvRfBVnuD9 QhTgorwc34q5ksAWBc6h4cq0qSQvZ7be/k+I2TAvl4f3ERPPClz7MR6lU7KCvAXnF7Wt 7RvOo/OFiu3nROVxqdWNkAvkQUx0yPTeDTufSZjskKECP53EI8BlQsfPSv1vyPp40PiF aPe1tT4xb56zpBMnrOLYHvf5XnVSAnRXo2DVl1Sq2/Ar+UNNBTISgPNZUkqEI2B9Rx7w f9GY/SbtNCeT3UPPovbKE55nG4hEzluyMGnFBSheUmHFcVAm3fwD1jQIu3HH4afYByv4 7KHA== 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=MFOh+wFZ3gZL48mISx80VE5NCNzEFuaISyyYFrZmaso=; fh=8W6oR0xuLQV+BWL/p2seEhiW5fxTUbYjGlVe63WkZwo=; b=mZ7nychsHT1MwRQ69zLGvWagKbxU3NF/CF5bOw1f/QUYCogsmGNJied0YzF8txGlz7 O/F8kVDo4pcLYXwhiqrDoYfVq3NWcN0HInPdm15eyc5Ke/tCl+3N5Z60/qw0ILAqNQMq stvj6+iyga4jux1calo/l8HdMkOlIj+pb79gHDGq5BWrdFT3NoFHtskRY2OC47Cprqoo 7tH+Ytd22trvOUjCgjUrOjoqgLiM00HoWDH+emK13G35usCgQIBjvhXfsjwDeoYqiuay VCO7cK5wQB7/FIWZcA2tULSgEXN/58Gv6C/+A5A+Um9RN7lbj9HYt70cKK02J/xoWPyh nOYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H7v1UH+8; 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-32181-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32181-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m8-20020a170902bb8800b001d7195d8a0fsi5378111pls.117.2024.01.21.12.30.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:30:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32181-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H7v1UH+8; 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-32181-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32181-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 98D33281B66 for ; Sun, 21 Jan 2024 20:30:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E52D38F88; Sun, 21 Jan 2024 20:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H7v1UH+8" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 73EFCFC18 for ; Sun, 21 Jan 2024 20:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869028; cv=none; b=NGrCrGf1/FT7HHJJlJeLb8c4oEA863MN861Pc5p0CdGj2GEEmPSmb9EkH0kWtzm0AGcURRODwqFmJCJmeKEdVNz4+59Vbch7NeCf4AdDOe6pihJoIrDP4JUn3Q7Y3zR0REPdVpH5Dbrss//or5EKXDRQA60KSRoV8P58i5bgTvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869028; c=relaxed/simple; bh=lbVolXL2jsv30CBjCftFHgTQeUGMCTKUmhycYf9fn8U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IYmmNjRx8sp81W0f1B2CKZqUvYMOaviVJ692GY1/2o2XZFuxXrfqk4keRdp3iyw8UuaiYe7Zxn0RPr0SYTZWm9uHVTeAXI1ZsGnB9cWOvR+5KPdDNzjaQr0bmkUoyUzLtR5UVMDPHLVUvNN0nW5fL8S7bDcqYdd77Fsyu0KRRNs= 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=H7v1UH+8; arc=none smtp.client-ip=209.85.128.43 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-f43.google.com with SMTP id 5b1f17b1804b1-40e779f030aso14472795e9.0 for ; Sun, 21 Jan 2024 12:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705869024; x=1706473824; 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=MFOh+wFZ3gZL48mISx80VE5NCNzEFuaISyyYFrZmaso=; b=H7v1UH+8yJxlhZ4Amnb4qsTiceyE3SzGdVj0c43swB6HtcccS0LJdN2OyRCw8sjWvO RhUITNdim3zLivrQ7H0EcOJTOoVswqYZ/ZlkhPWRt3ncP+GJe8quY4b5Q6msvrK9JzLy L3uddwoEluJ0NknDGPnNRmL1vzjmLpXEBi4FiZygcZZUkq+X5SlTCRIP1Ffr5HjJMrjG CRy9jPvAqByJUqsISes7D29/W/qSgVr/P2xfEeQhjPXLctDitO9Kp0WFAV5rC8BZVTVq Hbn9ZJnVH71j0XbzSHWi1Dmm/rnHDjBKzu73twODD4yjgIeVa0VLJYwPmAyxHM3GM6Nd TVfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705869024; x=1706473824; 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=MFOh+wFZ3gZL48mISx80VE5NCNzEFuaISyyYFrZmaso=; b=dt31KLeUILApw0McP9gCcGX2VaFFMu5bUQxm3NrhoDYelzTeDmM2mHs6DJhpdVn4Iu y6vyfDogrZgevxM5s+YVirpM+9mMuBe83vdd6L4yqC4SEgr5T+3haLeJL0BieWmoxjee MYDEVnB+bDsAn8D2NU4vXKtwuNvIsVsvTrgnRy5n1f69mTnu+v4szEKyKewVMLVLIRtr zO1CsDnu+rhFA333BzP7Eq/szlUU4a3+bDlBOUoVKrvJDE1mXh63pB3haeq0d5v1rFz2 uO+quAA5VZScVWC1lT9kAQkavTMPuqiIK9BHp8VLNr1i+JOkf0uOXh08xx2wPQ4brQ4g 5/WA== X-Gm-Message-State: AOJu0Yw91kYvT4QZFOD0WPGKJ5N3Lu+XhRgFuYubPXWAALQZGzrFrxGN xXMvzOkYXUZXP9ElrbO7z5UUnLQjG5/2tV3fPPH4v84ptdVkTQR3 X-Received: by 2002:a05:600c:a06:b0:40e:44bd:dc39 with SMTP id z6-20020a05600c0a0600b0040e44bddc39mr1314341wmp.84.1705869024443; Sun, 21 Jan 2024 12:30:24 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j5-20020a05600c1c0500b0040e9f7dadc6sm9021967wms.25.2024.01.21.12.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:30:24 -0800 (PST) From: Christian Marangi To: Russell King , Arnd Bergmann , Andrew Morton , Geert Uytterhoeven , Linus Walleij , "Kirill A. Shutemov" , Thomas Gleixner , Jonathan Corbet , Marc Zyngier , Christian Marangi , "Mike Rapoport (IBM)" , Eric DeVolder , Nathan Chancellor , Kees Cook , "Russell King (Oracle)" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , John Crispin Subject: [PATCH v2 1/2] ARM: decompressor: support memory start validation for appended DTB Date: Sun, 21 Jan 2024 21:29:33 +0100 Message-ID: <20240121203009.9257-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240121203009.9257-1-ansuelsmth@gmail.com> References: <20240121203009.9257-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: 1788733354439881507 X-GMAIL-MSGID: 1788733354439881507 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/head.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 From patchwork Sun Jan 21 20:29:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 189838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2229738dyb; Sun, 21 Jan 2024 12:31:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHez0yMEFG2Vp2/g9IekCT+fVvwRQtAOhQT6DkioylHcp1nhR3K84zZzehqPvuAAIhSXOPE X-Received: by 2002:a05:6a21:998b:b0:19a:e201:6d7 with SMTP id ve11-20020a056a21998b00b0019ae20106d7mr1309184pzb.12.1705869068897; Sun, 21 Jan 2024 12:31:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705869068; cv=pass; d=google.com; s=arc-20160816; b=gzhJarxSq6ajnHsuqiJo8p654VdyAGOzhPzVHANGbGKd76KXthATvWGNtel+0osr1u AjGzLaGBbE/vkTIQNHcACOqoUTTY+Xj0vHJjYZw9HiUg38Bm2xxPesMscd1+GVn/yAk2 gXnLuUv+4N7y6AU/lmJx41ZD5lAGBH/MRU/beIDPuAA7M37zJODQTp/WRzlzIEA+6F+h X0eExIRge9LLyFrksHm9MUg1Dex/CWyIneH4Lm4ew/SyJiQO0F9Tus3N25CVYCOQjO4j 3cpCfO+S5CGp2zqSo4oPr4b0Dr3Z7OeHLlbWkhBH2Pqa4zJH43SMDL7wUuO5YyLLO7S4 ADvA== 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=njA8TuiX4/CIlcjU6qTOSBsn0Z7EKlFnGPhxFsmpsIY=; fh=8W6oR0xuLQV+BWL/p2seEhiW5fxTUbYjGlVe63WkZwo=; b=eotuGAvuGXx2Dto2KSO6Ct8qx2A2sILfTEIH7K1ce2FNzOTSbrrTT0mRnPY/g2KlM2 XWwKtZPvy1/AdMv9vV/mf3OW4DZEwbwytM1zvcOro5X/W1M95nKhpjsnDTPX7SpwyHzd 5T/lheZl9sCVIssZv7nHA06bgPLqJrbtRWvrXWGJVEWIM3OMrcMkT7sRwQmlg+BaJytF gSTcKlfQTYMyWGEk5f6REzjVt+Yh2hfSX2uqITl9K39dhi8ftlK0n6YpAPLYznBN0Lbx tFfFnkymiY7K2zAK55WBoQj5i9YpwR8nuKo574xgndX0W1g49YFRpeqQT9WyzvrmOmrr j92g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MCWEtf7A; 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-32182-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32182-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m11-20020a1709026bcb00b001d3e6b2ba3dsi6822808plt.312.2024.01.21.12.31.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:31:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32182-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MCWEtf7A; 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-32182-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32182-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A53A3281C14 for ; Sun, 21 Jan 2024 20:31:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BEC138FA4; Sun, 21 Jan 2024 20:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MCWEtf7A" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 84D0738DD3 for ; Sun, 21 Jan 2024 20:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869030; cv=none; b=uOLa4MlkdF1GjqXIOUPvQXg3jAl8NNcCISzjZvsYrlp864/oFJhWDNpP8Yry7jRbRysuhHZCKo1nlSsKA/Dv02l6ldoIl37A6otGQYMgJLg4VulzjSEQz1tcD3I7x+L2jmXOqAzlBIQc1hSZvB/eZgwtYtuXKMCLsAtT29t24U0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869030; c=relaxed/simple; bh=qd/WQekHV6Ik6ClIc99ynF3CW8rR0t1PzhaYDAk7+bU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jLDjgTEJwqvOuTcRAevAPSZAxLkNl0goPkyqEcJaN0cpc6ZK1laWtZY26OTOPZ3HlDof1W7mKv1idOCtF9BS3bHUEDMLHZFDnOE7HWqqqvKNYSu/I//0Yo4DSOMu3uVOtUqhNeBphcpIDEKA38zHvP7gSIsJISS8LneNj2CT/P0= 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=MCWEtf7A; arc=none smtp.client-ip=209.85.128.43 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-f43.google.com with SMTP id 5b1f17b1804b1-40e8fec0968so33533385e9.1 for ; Sun, 21 Jan 2024 12:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705869026; x=1706473826; 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=njA8TuiX4/CIlcjU6qTOSBsn0Z7EKlFnGPhxFsmpsIY=; b=MCWEtf7Al9wF1JaN7027hUf4lYh8zl5MDiMOSwjJUeCW33801a+bB+vB39hjrww9xT aURypKJuh/022AyGmXYyuqkR1H1o2P1kOebQO07YQg6FSQHJEDGsdMQzWpKLEOvjgE/N e1a3Dhvxi771D9iaOnj/BSKzqjiyPvNeP5wG1P+qYAwGCL4m443HiPVuC+yIjFlBLzR5 q3u3Ps7R4WY772BT/0e+lkUg65gZX0IfoQTSJpu44wPy3rPkf+LZR7na49YMzTORRJdz fJjfgDWx6f+6jK0QNT0hqTlYYkPo6x3BlWuE8GDGbJ7QcNYWlZnzLKhQTcXwCvlavpvH uyzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705869026; x=1706473826; 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=njA8TuiX4/CIlcjU6qTOSBsn0Z7EKlFnGPhxFsmpsIY=; b=dAQSa8gtUfs4fsN0JMyg8f/wZhE/j9PFAaNmT9waT+bOI/QjUUe+D/d9+x/avwRb5c liJ0EkV+GVX14HI8EjPoNUgRaOBI/NlDxksny81GDo8CfYVWIalPnyuw9Nfv2hy4cuFj 7NnFF4Rvqe+2oc6mi1dF12X3g9s/WipHrnb/BWfj2MEIG5oKQXnDoJa2+wDOebRhs/Wu exH4mHZn5y23dVPokwSZ1Wt3F7d0z1yGAvGaFTb6pce9RjUHFDfLKqq83zK7Yi9esSG1 edcry9DCnrz//IXfp5ZijPvZ+08O86SO2BfkjsXqFxXxFCXHjywSg9Fowvk3nmQPoQDn mBIg== X-Gm-Message-State: AOJu0Yz1a6x1KEhl0d1NuGbXoO8lsFLbYL5hsugX5lH3EXwPJk1W5H9V WeK7p4KpT09vuLCHaiNk8XZhp2L80V1hGxPYBBGIi5YqPkilI9OD X-Received: by 2002:a05:600c:6907:b0:40e:88a8:2185 with SMTP id fo7-20020a05600c690700b0040e88a82185mr1825036wmb.176.1705869025687; Sun, 21 Jan 2024 12:30:25 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j5-20020a05600c1c0500b0040e9f7dadc6sm9021967wms.25.2024.01.21.12.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:30:25 -0800 (PST) From: Christian Marangi To: Russell King , Arnd Bergmann , Andrew Morton , Geert Uytterhoeven , Linus Walleij , "Kirill A. Shutemov" , Thomas Gleixner , Jonathan Corbet , Marc Zyngier , Christian Marangi , "Mike Rapoport (IBM)" , Eric DeVolder , Nathan Chancellor , Kees Cook , "Russell King (Oracle)" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , John Crispin Subject: [PATCH v2 2/2] ARM: decompressor: add option to ignore MEM ATAGs Date: Sun, 21 Jan 2024 21:29:34 +0100 Message-ID: <20240121203009.9257-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240121203009.9257-1-ansuelsmth@gmail.com> References: <20240121203009.9257-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: 1788733364853717436 X-GMAIL-MSGID: 1788733364853717436 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 | 4 ++++ 2 files changed, 16 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..b5bce4dad321 100644 --- a/arch/arm/boot/compressed/atags_to_fdt.c +++ b/arch/arm/boot/compressed/atags_to_fdt.c @@ -170,6 +170,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 (IS_ENABLED(CONFIG_ARM_ATAG_DTB_COMPAT_IGNORE_MEM)) + continue; + if (memcount >= sizeof(mem_reg_property)/4) continue; if (!atag->u.mem.size)