Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp303985lqo; Thu, 9 May 2024 23:29:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWcykw9YW2zUE/IwYyMtCUkMwTocmuCac+MFeEXE5R13BCV+z1laJHUbOxxZ0jRvm3PqY9FrjZA/ltvxeDkG0iYyfBiFsQfwzLeGTrU/w== X-Google-Smtp-Source: AGHT+IGCqWJHisRVAHQFTmB5ZnI1nlVLfq4YycxV/2jxNbBgh3wH5xkZIR0rXbFpyLaIgF9Fn4J+ X-Received: by 2002:a05:6a00:1826:b0:6f4:4b35:d7b5 with SMTP id d2e1a72fcca58-6f4c908b5e0mr8283359b3a.1.1715322553068; Thu, 09 May 2024 23:29:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715322553; cv=pass; d=google.com; s=arc-20160816; b=Lzu7PU/j4BrQEsbCh/67uq5MqqiiNkkgDeV8gdXDjtBod58Lv0r2ASZTq+ns4Sv2MX KqxiOdN9TdOABo2MWh2m05hQg2rLfnB6n0dgbF2ObqArMx0CsllLaDVNPhkul70mABAH vGE7Vth9EXIzlIsORD9OAhw9hF9IaBpV0YUUsHVTVK6sYbg04iyRsDDgR94YMQbO9o64 /D8ZIgAmR14fsP+XLsoLYy40GP1fK1RUtBbLqBWX5ZoeV5KhSxmMpTUjh2ilHOebOMjw itEiQ+BV+S5slx3Q7GEeQd62T7SmSujj/P14nVLH1MJkEjj/YbKdS7GqR6SntefX0Wlq KFfw== 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:cc:to:dkim-signature:dkim-signature:from; bh=eHgttoFFWFRLkchEo2QfX0lB112yKyL9eNSmZIo3a+8=; fh=8eVhtEKG9nNQVrYy5mUyY8MxQMB5T6hiievcYor8Kok=; b=QiJRTXcjGQTRATuNd2lLPrDE11djD5r0L8rnDJ/5GjoSeYv8EpNyv+Y5r5amurcwfL 5ZMwLjtzw9tuHAnX3ALivXotfzMVnQ/Xea6eZImsWi9xiT/ODb8Q4aJzu3O7IE5Ct3sX AwPHsfxmJk3DStKY+RxCFjWtkg41VzmnAKAuCYe1dSeiqUOYrZR7XVGM7m+zhYP14VHN nek1WvdwhZxisDTiAI3e+rLFQ7UMcLj6c13RG3B+cDWDG2sTUguVCuY/1SQ8Jszh/oBU usy2aKnNMHa3ik6zmZLToIewMrseu4b14XBEgQR5MGgYxqTFOhy0OQhiOVsCZV+8P4UI XW0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rym64PB+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-175324-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175324-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-63409e81784si2892629a12.116.2024.05.09.23.29.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 23:29:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175324-linux.lists.archive=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=@linutronix.de header.s=2020 header.b=rym64PB+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-175324-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175324-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 A6567B210F7 for ; Fri, 10 May 2024 06:29:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CDBF1607A0; Fri, 10 May 2024 06:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rym64PB+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0PkNmo9a" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A1FB224DE for ; Fri, 10 May 2024 06:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715322535; cv=none; b=UILyXEKL6Oix4NcnRLPoWKhN5YL9+17T+ALsUrSJeM077+eUbkzE1h2knD05/hnLq+qi/A7q2lbNGapeM1jzmIcOeWiubQK+2p/Xksqg8apGofNrxyVTZ0Unkq9fFlbVosG/rId8qfPlLa2pjbKsG33APDHeGfj4joC0IOAx3+I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715322535; c=relaxed/simple; bh=jPNszMR3zfL+4GPIAPOJiKNbXrv9nPfVt/IsRIaEyBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ixPoORxJLJ/79xPCuApGFqrIsx2zMYvQ3Xsd+pTTQ2rkvZbM842n/0lMc6sM0gps447oVVFgn6KOS4a74AnkWw5ISopBWzuHMj/szA+2fSivvaxwCYQ+Hkuco+zuJNFClzpYfmlpfxc4SkauHJ3XtH/Vn/hXFvMSPSSVmPuruIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rym64PB+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0PkNmo9a; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1715322531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eHgttoFFWFRLkchEo2QfX0lB112yKyL9eNSmZIo3a+8=; b=rym64PB+TVDtCShFhxpKTOgaRSwibgR7yFlmNFd4PvRAuUrYMc2UEwlsOKr+TaA2X44nKV /BGxJK9Lz4G67Y++lwd+9styGjOi3EJMSAckZSpmyt1Q6ailUw3Xf3l2DOiF40V1U/JZJp 9AfXnueGo9xcQGlawkeXI+cpmV6+WRVdB0bp2GqbzI1z+8tL21tnqud3yB/gzQw8aO0caN X6WpDnfSbqejhpXjrUfApK8jWG8/z+mvSS9iT+CL20f0h1woOwJc3FdR4h2bsGR4C3aCOj Nvl2zdqa1AWxKEuUTTZlLL+QlcecxyhlgNYw14dGuhq5uJ0d3zgrfyRCfNPCxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1715322531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eHgttoFFWFRLkchEo2QfX0lB112yKyL9eNSmZIo3a+8=; b=0PkNmo9aY3VUVjYwMRi7xLx59JUldrS/CLbglWFZDpVhxTuy5/Erscv7pKrXKonLZoj7mR 7fDp+5SrNKk0kuDA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 1/7] riscv: cleanup XIP_FIXUP macro Date: Fri, 10 May 2024 08:28:39 +0200 Message-Id: <19e63324d7a099f561c4a2e55f7df051bd5b8a6f.1715286093.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The XIP_FIXUP macro is used to fix addresses early during boot before MMU: generated code "thinks" the data section is in ROM while it is actually in RAM. So this macro correct the addresses in the data section. This macro determines if the address needs to be fixed by checking if it is within the range startting of ROM address up to the size of 2 * XIP_OFFSET This means addresses within the .text section would incorrectly get fixed. Also if the kernel size if bigger than (2 * XIP_OFFSET), some addresses would not be fixed up. XIP kernel can still work if the above 2 cases do not happen. But this macro is obviously incorrect. Rewrite this macro to only fix up addresses within the data section. Signed-off-by: Nam Cao --- arch/riscv/include/asm/pgtable.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 58fd7b70b903..fbf342f4afee 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -139,11 +139,14 @@ #ifdef CONFIG_XIP_KERNEL #define XIP_FIXUP(addr) ({ \ + extern char _sdata[], _start[], _end[]; \ + uintptr_t __rom_start_data = CONFIG_XIP_PHYS_ADDR \ + + (uintptr_t)&_sdata - (uintptr_t)&_start; \ + uintptr_t __rom_end_data = CONFIG_XIP_PHYS_ADDR \ + + (uintptr_t)&_end - (uintptr_t)&_start; \ uintptr_t __a = (uintptr_t)(addr); \ - (__a >= CONFIG_XIP_PHYS_ADDR && \ - __a < CONFIG_XIP_PHYS_ADDR + XIP_OFFSET * 2) ? \ - __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\ - __a; \ + (__a >= __rom_start_data && __a < __rom_end_data) ? \ + __a - __rom_start_data + CONFIG_PHYS_RAM_BASE : __a; \ }) #else #define XIP_FIXUP(addr) (addr) -- 2.39.2