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: 13524673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88659C47DB7 for ; Sun, 21 Jan 2024 20:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nDoB+RYgAwfhAzu47MOPyYEplYa4vq6euLQzUOdQveQ=; b=JbmDFtSi01hQKI +aP59X8nrIn/yZhnCxpsI53/oGy49ZKyVn/iuC9N0JFQZLaTrLYtEaXVUDN9lodWulM9YSBP6m2XY uAesHM5TJhOOG0csH1UmdiYSeSoK579t5oh35bRX6Ge8+98HYdSyqLL/3FC7ZAzk6DATyCrXn5fUn bPmQnxzcfY+PKEmn0wB7PdAtMlR1APpA5hc5i/4N1wDux5jxDTAcxXsOs4vQRrmZ99SRLLv3VFx0H M2zUjs+Oq9VnmDrdFBou2a78GA4MdGdFNvi7Ey6yY8JYZ1eoRmc/7faM/Cw5iKOToriIvmSRxR/0E 1/W49wiqWtSOmoiChe0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rReSh-00A0CB-1d; Sun, 21 Jan 2024 20:30:35 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rReSb-00A0AT-1m for linux-arm-kernel@lists.infradead.org; Sun, 21 Jan 2024 20:30:30 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e779f030aso14472825e9.0 for ; Sun, 21 Jan 2024 12:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705869024; x=1706473824; darn=lists.infradead.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=Y8chlGSjYcOr0QCnxtMwUKIUJZnKmpCSrU5fpwO6nuqaNlX5bsHCM5OzkXZtqsmvEc htZD+8SSiPo6Miui8tql6mdd8ohkzndAwfdFCPPgOkljLLg6SviDD69zxhs2nwlDnzKz uEyzxl+wMqT2zLKPNnNw4Odz1CdcRwgzTEhTIC8Exdurfl+rqOqCAIdQPJ9zraMyhMIA lMRTPHTysBdt768OX4WTlgiF9r1uZyHWsh2U/YKp5FglsBzZQWKF2PJM5gOa4rXWCGsB Fu/aH0JROv7OYYFzy/w8ORZGtnmWRaUobc19PaFP74FZaFTJ/oiSCx+7TegGkmZh5ckV Qbwg== 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=HZjm+vlI7Bk0JNi/kuF5bBdQMQd941lf8N9xcKmjbd8BdWuZJwKiDGoa8nrkuOwRqg g044oOJynmY3F8NN/4jP+1D2dEnEFidCKi2KFAk4oVTvJLVFREx4lg7pXXvNKRGHg2NK J1RRO/+PWFKTNVyXl/urfarjOwt+dvM4HzA3O11DDIQe9HQBgf2Aytxj6reeQpaB2bN+ y8Jsa/vHDK+QcdedJXS0ikwnhkreAKZXvtIUrR+/7ksU5KXtY7YjNmUnMyKCE9ltDN92 dSzA0jLsI8dNlcPauKsN/g860pDX15ohJ38czrV0bHZdVAiwpMTquz8a2HEkVLLFnrp6 mB5g== X-Gm-Message-State: AOJu0Yy6hyUphiEgJo7przdXsierKH/toIUUT8hxRFIhq4ThOOrg+OcY 8WquFDAI79Eid5hGf19jC3t7bSJIojfl5f+NIp+DuOk/NdnclApn X-Google-Smtp-Source: AGHT+IGa17ieGCLLHAfKtw0851dG8rPii45/t1n8te6xVLjBjl/hUzn13sgCBWZnrl1l/bWLAvPPLw== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240121_123029_591553_C82C9329 X-CRM114-Status: GOOD ( 27.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Tested-by: Geert Uytterhoeven --- 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