Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1280592lqt; Fri, 7 Jun 2024 13:22:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWP0VsbuRe2dybnW5YrxO8hFaiPNxhs7rEuyYi1o5t8yWtitqDAleqIN87Hte5M0/GL/CfsgwF7wUzjdG3gyr/yAkpVuDSkpd5UrAOGig== X-Google-Smtp-Source: AGHT+IEWWCAPzPwYIZIxJpZ+jvVYLVfmOn+LVCBSJBo+BiLCTr8xLriHLm/3jiqBiEroFb1HCWGM X-Received: by 2002:a17:906:4ec4:b0:a68:c721:1c7a with SMTP id a640c23a62f3a-a6cd665eb3cmr249498266b.22.1717791751164; Fri, 07 Jun 2024 13:22:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717791751; cv=pass; d=google.com; s=arc-20160816; b=mtaEWo2XErB4Wtuglnx7wj1/Tm6fDCx7u2I4UqUIUUGbk8ov+PRpGltMntvIRijkpe uvxVJhOTWNr5NbbkEgmNe/MQOZM30xolHN0teWVBbRkEwajlTokyhTJLg8kR0etnvCWs g+YaDFlMlR+HF8Pv6w9ysLUZBlrdwXobwFDPriHWwbl5uXOGr+JKDqTN7LygNQD9fpBv Ka916/JqFCzjTFfa4cxA43A/vmKgUWYXf7/cXNQAzI4g4cM2gQaT/mZHeRDmZEYdHH0a OMyAW2dV6NM+Y8RxzBttnmTpG/quGgPnaAFzt0PnCZ5Nx9tdkD2tT/sxcS++wOuwiAug EFEw== 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:dkim-signature:dkim-signature:from; bh=9qZuhyf1lQhZt5s3eJFi8xrQOgugcSrfCBUJNf59gow=; fh=NjSy9ELbZGh6EjCqOzE+qeF+VS4OABBeZf5VHCmpp/4=; b=aTKzYB3yNyC5TzvkqC/OQqyj577G6vG4EHeO6lvp0+7ZsVSfphgRo2I8lPf+g6R0iQ fiWOYUnKrg1moSwL2yCsTjgxOwpiLeM4ccxkzh6l76AoE7kIOXr3uqUkD+aijXuRoS9r l7d/RACsmDP7zbXBhJmIQvXvflgtEOOXwNP6d+JHm6in3VCF4TVRKLAQPFsWMCmg1eJu yUnr0ljgciVITbe9T9eoRELIMpWShyCWhQTfHKm29v+wAj2o0aL9tuartXDLHJNZ/Dxm o3AzYOMqzvyWI5g2YWKEMYnBS6R0oJsmq0jMY1RCz6aspRJcy7AUSrv0FsOkniMA3//B svMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zVDZmWbz; 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-206693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c807484b7si205901666b.915.2024.06.07.13.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 13:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zVDZmWbz; 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-206693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206693-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D9D4B1F23109 for ; Fri, 7 Jun 2024 20:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 663C114F127; Fri, 7 Jun 2024 20:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zVDZmWbz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gO8J18Er" 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 1CE3913D29E for ; Fri, 7 Jun 2024 20:22:15 +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=1717791737; cv=none; b=FV0UwOv9rfnvA9/Dz91EpuDVCmpnYghILkQujJf9OwANBQ4B0TW4b8jIjDMFb42f4T2iRUtTSl9lCdu7Sy3qq+sQxk23+i6Vd7Wz8rTvcyV5If+9cG0wXiJS6pkuoMQwDxd/XjiOuUWBSKWrxVdAjrQVEblaohcj1ZzoCPmqVqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717791737; c=relaxed/simple; bh=NRwjMMW1NpcsWO7RJK+bpTO7Rv+OtExdexlMAAkxYns=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uh0oVCigxfnWRQb0lpplr6w80RWVe5uwg6Lj2VllR+94Sh1p9FcwZUoRf21cTuqLZ0qDVdMMhK5Pw7MzMmWSUXfZq4dmOGH5mAqKo2h2kIle64GgVjHOw6mEok0VP7PS+uO20A1CHPdxm+gSV5Ml6xrGoaObNkeePp8xSa6Ugmg= 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=zVDZmWbz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gO8J18Er; 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=1717791734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qZuhyf1lQhZt5s3eJFi8xrQOgugcSrfCBUJNf59gow=; b=zVDZmWbztBHi/M21/7J+Y5FeFxkTdBDatbLJyQAc/z8s1fHROXf0zBSzAL/ulQstFpGyrg zfRyUsZci059OwtCvS4pPWPeybEYXmpYcl9KeVkQu3D0dYr0+ETILmKDEpVxQoF8CRCx2B sgtVFRsKdkiMvSQy+OvKMhL1FQfSyJE4OtbAw0xLHV7tu+ob99ohN3mARhPZGooCxxsUo4 ojVMsEJt0VI0ymsM0cqCF8hlbGz5FeazRfVXsJj4cRo8eNrFYN/l3pWMIMby3HtBU6WTZ7 OJkRVLCe8REVuuhkiXTne8T9cvBMoyFqfw5HrwgNpo4eqoyRdtqGWelHmpJgkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717791734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qZuhyf1lQhZt5s3eJFi8xrQOgugcSrfCBUJNf59gow=; b=gO8J18EreVY72dp9ASgoYtgplWRm+hThsi87epU0keVDaiDb0vsxg5HPVyY/g/jh5RcHeY CVYR7vY5j36RVlBQ== To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/8] riscv: cleanup XIP_FIXUP macro Date: Fri, 7 Jun 2024 22:22:06 +0200 Message-Id: <95f50a4ec8204ec4fcbf2a80c9addea0e0609e3b.1717789719.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 corrects the addresses in the data section. This macro determines if the address needs to be fixed by checking if it is within the range starting from ROM address up to the size of (2 * XIP_OFFSET). This means if the kernel size is bigger than (2 * XIP_OFFSET), some addresses would not be fixed up. XIP kernel can still work if the above scenario does 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 Reviewed-by: Alexandre Ghiti --- 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 aad8b8ca51f1..1bc103aa9b74 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -142,11 +142,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