From patchwork Sat Oct 26 17:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852303 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 20979D10C00 for ; Sat, 26 Oct 2024 17:14:59 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mZKPezOIL271EbmDvgY/wrFjzlxDRIjo4vr8x6XuhS8=; b=B54gvP8LgOyXOF t+4dy9izNZg2F89Rj7i6rE/HNC9rIw2ubR1lZ9YYOQ2wy8eRML+1xcPgWFr/3uOKAphxPMNVo1/Uh /t/++Yn8fIE0erOPOFwevL+J8p2iCIm4OP+E2/xUHGUFG18embWLRYLTEExjBH+pAwhQ+Q/La8lVJ /Ypxiw+H08lWDMAgSZfKUDWoIxUMEtv7Zf+GO9/o0X3ubstRkCJypqKylRGis73m7YWcH0O/Ii/ZR hPsRu8FFDlGqWW+HV91kmHQ5oOGM70QEAwUpi5hinngzkmAA/XdABZMgYx3LOc/fN+jPGDGzFc0uF 1g01vFUwl2zRgEBK2mXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNH-00000006x8I-3gnb; Sat, 26 Oct 2024 17:14:51 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNC-00000006x6B-1ED1 for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:47 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2e3d523a24dso2326608a91.0 for ; Sat, 26 Oct 2024 10:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962885; x=1730567685; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IgTekunG0cQy0vjVyXRBRATW95KVtugkqgihcshjjxQ=; b=iidOnM+jJd+rUs9T03PtHjjrlKKmoyshMJ4Xnf9yd3lxMtflTUp5WUSf5r9UImK5Om xugS+t/fsizHyUGNgRde3wbwskrb9USyyoLv17WBAqiCQKbta4Gfye50SkpY92LAYN2G GNS+sT5Zd3E7Iw50cbB3eEzDBk8h05dW3UGR3ZYmtFqwrNn1qfM7xksR5eH745jxnjm7 MlsPLnqxkbzGbEIOKP05H4+1DMDI9jLll5YD3K5K8R251mafUnuxwLbz7Gp0UtCkGNry zMdd78iy0nODtW46wTdZyI8HfxYrEPOM/wLDmjoclLaetk6tfxxURzYe4F0xMou9N+hm IWeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962885; x=1730567685; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IgTekunG0cQy0vjVyXRBRATW95KVtugkqgihcshjjxQ=; b=vYn9VV+zSW/4oMp2uNhTquybgwudeh0b6zjMUgoewHuQul70DjzlJtztZwdqPT4O+j klX1DHQr2cPFZ6BSU1tSkJ2J83OfV94m2GD8vgzbA0tYmuyOOHXHtKjC4CfAt6QE6YtM tY//Tqh1/zuZlg2QhNsbyQRjeqniM70OQ2qSbWITNue9DpMiKCRVayShX/mixJhcV4ic cyHHPuwR2YJZy8Tuhq9qi//WJpg1iyEM4APuZ4jB6mQzE3RloEG3hN6zCShIZVx7PkXz C+OC96GKv21cJpFMQ4ZXaYPwr7DO8zw/Kck1fZorCZSu62drFf5XDMe40ZI1xzMJHSkO bF4A== X-Forwarded-Encrypted: i=1; AJvYcCUiwcij7gL7p5ixLtOI9mdnIVff00lBpXpOum+PV/eoXWT3rdhPTk159N02UVodH6xhPSGgV9S2hoqQmw==@lists.infradead.org X-Gm-Message-State: AOJu0YyIxahmAXo+niSCXHt300KCWv6hZaopfsQIBDyRIAVbHWLBuWru SGaJXxQwzBUcliMCD9LPNyIy6nq2yLLvI1ousNKZZ3yGotdrzDKlekVF9OHrhZU= X-Google-Smtp-Source: AGHT+IHMFAwANT/EZuDl4La1BmNjmSNtM9o3wF8CMwHklFBsWwrPxYwZlipAsFiUTL+gnWOt/QYKpg== X-Received: by 2002:a17:90a:b111:b0:2e2:d16e:8769 with SMTP id 98e67ed59e1d1-2e8f106926emr4001679a91.15.1729962885304; Sat, 26 Oct 2024 10:14:45 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:44 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 1/6] riscv: Remove duplicate CONFIG_PAGE_OFFSET definition Date: Sat, 26 Oct 2024 10:13:53 -0700 Message-ID: <20241026171441.3047904-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101446_480440_81D26794 X-CRM114-Status: UNSURE ( 9.11 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This definition is already provided by include/generated/autoconf.h, so it does not need to be provided on the command line. Signed-off-by: Samuel Holland Reviewed-by: Jesse Taube --- arch/riscv/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index d469db9f46f4..6ff2cbde5296 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -92,7 +92,6 @@ KBUILD_AFLAGS += -march=$(riscv-march-y) CC_FLAGS_FPU := -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/') KBUILD_CFLAGS += -mno-save-restore -KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) ifeq ($(CONFIG_CMODEL_MEDLOW),y) KBUILD_CFLAGS += -mcmodel=medlow From patchwork Sat Oct 26 17:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852301 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 7D9F8D0C604 for ; Sat, 26 Oct 2024 17:14:57 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/psCW2xxPz0+dxHAm0x/113RbF0Y/ofVpFXeZDlLGPA=; b=4iWa8yN648/m9e 7AcRXvnh6QGElOFC2xd4zzNVubfGkiqoKd3WBahZKBGJ23S0wNZy+vBnjGjv7AZ2csO2qPc4US7b1 SyEV21jM5Mcv1Z1cjZVXfbVO3cX/y+xSVM5GZKSsvoQiZCbsKwVCNcVw3ZPOsQm93x2TV5JchWi1K 14JgK4s2Qw/I0WY+XHPRlwjqmkCSlRgm3gzVxBc23KhD51hSSShHtf0ni+GKvBndU9k1U381HkolZ jvb5DukKh79OT/IooDFz1gaYFSFxLW7dysx9M+O64SyAV0CUepeBri3J/qzdLOQTybagAqVdtaH+K bzThPOidCEBtnUviE3YA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNI-00000006x8l-2ovZ; Sat, 26 Oct 2024 17:14:52 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kND-00000006x6Z-2nHw for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:49 +0000 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2e2fb304e7dso2429923a91.1 for ; Sat, 26 Oct 2024 10:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962886; x=1730567686; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qyKlYhyoQTsAn4L5ymM1gqMGEqmqMMy28NtniO4HhLo=; b=VZGj+EsB1FzJVg0Ws9LRujr0zhwJwjhmu3MJwK+p/7b1dYQZzgzV8bO5FPCw8o/kWB wYZRbsU6G/KdRjm920p98jjzWqCHy+yEozGmht93TWcRWNoCtiGuexrUJtX1mnoqtw8t B13kzAfSgmQuXmDflYmVAJy0SqYv/wosMkTyrvtudnqy400TrCId6eoRzlYEVjm37MO3 B5pwU/Yn5EuUjU+AMpnwb4xfFmNObgRGb+6xwHdaLbHcRyKjF/Jx+Q/GEjSR+kTCE2Ci gn2hk4KXw80EOOegGYaDCiyzM+QxIC6GbGw0ioAJdPPb0rXr1bGAVvBGvbSkH/UftVk0 +VKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962886; x=1730567686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qyKlYhyoQTsAn4L5ymM1gqMGEqmqMMy28NtniO4HhLo=; b=Oi7R2cJWMlA/NZWvU/J98DkfH3xr7JMZ4V6V+diG3VoRpMRGAah4e7RTfC1/vktgq+ 12+3nc/s4WeNkedQt5kKl+yYvNz5qib3u9hD0qeH0JPICaTAIhNsOOczz+3GyrwtZGzT sKUGJcbVV2QIgKCJavMbfm6ZL8HdoCseo9fCgIiUMcDILPfHoBvDcgnvyNe6ix46C9Ze Swpzuh8Ah9T2OIBsCdQ0CWv8n6diFi/+4IGG3XfMmBuaM+rKwUua53TgdCzbbYgHcxWj 4H87m3EtpG/nj7YFHUfWjX/aahsGTHxcixZ2us7nCR89Q2kRH9HG0/6JYRvLOyaxUqQs nvkQ== X-Forwarded-Encrypted: i=1; AJvYcCVc7VOmuMj/XfIvhLwuC2U6EKEvtnZGvtVUfAJT8Gja3ivCrSBAF4Ntune2iAYWhTzqR0xSYte83Qv2fA==@lists.infradead.org X-Gm-Message-State: AOJu0Yzk6fjClVs0/s6vS1AYElg3adfvvI4yAJJJXU9gd8Be62tgzXEH Im6iRyhvkLykJjLULjOXReOHDJnnmaBhPaefIBWU2LLjpWaYbx1AJAdm5x2IJP8= X-Google-Smtp-Source: AGHT+IGjNDukwViDngFMKYKbWwFFp9ljp4jqD+5ryDjxC8VoVYiX7cXbg3yZQRK0W4GSuzVMjeVSBQ== X-Received: by 2002:a17:90a:7847:b0:2e2:c69b:669 with SMTP id 98e67ed59e1d1-2e8f10a6f5bmr4102476a91.27.1729962886541; Sat, 26 Oct 2024 10:14:46 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:46 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 2/6] riscv: Allow NOMMU kernels to access all of RAM Date: Sat, 26 Oct 2024 10:13:54 -0700 Message-ID: <20241026171441.3047904-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101447_729810_EFB2D72A X-CRM114-Status: GOOD ( 13.21 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org NOMMU kernels currently cannot access memory below the kernel link address. Remove this restriction by setting PAGE_OFFSET to the actual start of RAM, as determined from the devicetree. The kernel link address must be a constant, so keep using CONFIG_PAGE_OFFSET for that purpose. Signed-off-by: Samuel Holland Reviewed-by: Jesse Taube --- arch/riscv/include/asm/page.h | 12 ++++-------- arch/riscv/include/asm/pgtable.h | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 32d308a3355f..24d1ac052609 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -26,12 +26,9 @@ * When not using MMU this corresponds to the first free page in * physical memory (aligned on a page boundary). */ -#ifdef CONFIG_64BIT #ifdef CONFIG_MMU +#ifdef CONFIG_64BIT #define PAGE_OFFSET kernel_map.page_offset -#else -#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) -#endif /* * By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so * define the PAGE_OFFSET value for SV48 and SV39. @@ -41,6 +38,9 @@ #else #define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) #endif /* CONFIG_64BIT */ +#else +#define PAGE_OFFSET ((unsigned long)phys_ram_base) +#endif /* CONFIG_MMU */ #ifndef __ASSEMBLY__ @@ -97,11 +97,7 @@ typedef struct page *pgtable_t; #define MIN_MEMBLOCK_ADDR 0 #endif -#ifdef CONFIG_MMU #define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) -#else -#define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) -#endif /* CONFIG_MMU */ struct kernel_mapping { unsigned long page_offset; diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index e79f15293492..e224ac66e635 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -12,7 +12,7 @@ #include #ifndef CONFIG_MMU -#define KERNEL_LINK_ADDR PAGE_OFFSET +#define KERNEL_LINK_ADDR _AC(CONFIG_PAGE_OFFSET, UL) #define KERN_VIRT_SIZE (UL(-1)) #else From patchwork Sat Oct 26 17:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852304 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 C3B3FD10C03 for ; Sat, 26 Oct 2024 17:14:59 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B9bJvlztqavCGLi54uRcWuJTYuHHbrRhh2AXHA+F39Y=; b=ygajtfrMC1Ckgz VVBGegdB0Eab0pw1Sd64B/qh/Or689sj3mIkZCYJA0nd97A1MNYRy51o7Q2aKFYavUOvQdWz/fZHs IDOR4IbcZFQ8TWRg7B4Hb7zf90ulBAzykMQAGEjXgFuBLVZYbTlSJVDLlT7FrcOvroUMmkRogwETj Lqru9n9iBHmRsZOZ+ewzWbDv6iWc4ODseHQlsDT3hFMNDp4FFtBXIgbSUHwlmyx+NazhbJ+z5QLdi vQRvvlipbAjm677l7omTZ/bESrvbEe+YUOdDt7BIifSzfhbmVL5F/F5cARhzo7VgYfusELCf0BuwA z94v3VVWfv/cXCK1lIag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNJ-00000006x9g-2rcn; Sat, 26 Oct 2024 17:14:53 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNE-00000006x6z-3SPL for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:50 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2e2a97c2681so2189271a91.2 for ; Sat, 26 Oct 2024 10:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962888; x=1730567688; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IiHFo4DmtdeXVJSdAkSejNf62f3o6R3z/nVT/XM/LXQ=; b=mvrygMWUA6BngWr0BJ8vizpKc4fJ/PTzPgGYgmgTMRvAwRrLcoVlqRn7jo4up+GLd1 LreYlotQ9TA+Tmk2UVw/HqjTcXNFuB+vtJ7T6z6bT1Ib/+Rv2J13FfbDHZBlhxMNfxvh GIOIsGa4RpznnMH0RRhOGD40l7y23BBIp6IfRxQPklZbYBCc1AWJ9BvN29o8Z70zzLIy 1ukwR6DPCXLMBQI6XfzPo+g7ALIIYZJ6OK9lbGzTLX5oC2xL/U0G4tW1wMrk5zxkCBz6 Awf0cw1MWscRk/nAPWOgyZUv7NSE2ecc5rE/spgxvUjMMXbufIGCzqKvGTbtgwFXa3xB 2LGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962888; x=1730567688; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IiHFo4DmtdeXVJSdAkSejNf62f3o6R3z/nVT/XM/LXQ=; b=w0UPmzGume39VAVdsnTkVaND/gArZhzW0l75C/hq75YaDikSLzwRp7SaO6uo38W9IC yahKG1fL7ksGUK7OyQpPMqkhXnTVUZWn9iS47jPsNmNqtuIV2lMEKnaTGqeRHLdG0lSV MK9VuJBpJiuHgTz0HPXeVhJLFphejG6fbQFWF59EuB7P6NJ+VSGI/qNNaCH5bgEE8HgE r00Z+3Rq6y2Htn3Q/ElUkV3hO7KUHk+8+FvCtDlFGXn3lwD/aByFzdy5Pt3jQmNyqd8L HDXvSEqHpJplLu4IwS517hnzpA9r72Blra5Q8NFF2J/q6FnWUJC/MxdoFvBUlJ9WIN4I spag== X-Forwarded-Encrypted: i=1; AJvYcCU3YVSNe/SgtjDSF3JMBmcshdxh+QGtNbwIIBVffMcy7NpPBKwOo/85VblTVMJ2ll0eTHM4XdXb+9YSaw==@lists.infradead.org X-Gm-Message-State: AOJu0Yx/Z8JWadlFaEcNvqxwj0kaTOo0eae7oSOTBGH1BEw9GV2Sn+jP 2QtKF+rHrcnIqsRSVe3oFrzt+0rPD+zNMZY/8jh8X7ygYshSDOCaTIE0btBKoAc= X-Google-Smtp-Source: AGHT+IEzN1IbGCkMVdSp3rlof3XN99qFbQm4PDAwtLCkE/kwbj+tFrZvPVcsHIV6RGdY5SSQlNI55A== X-Received: by 2002:a17:90b:1202:b0:2e2:bbcd:6cbb with SMTP id 98e67ed59e1d1-2e8f105081dmr3625438a91.6.1729962887736; Sat, 26 Oct 2024 10:14:47 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:47 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 3/6] riscv: Support CONFIG_RELOCATABLE on NOMMU Date: Sat, 26 Oct 2024 10:13:55 -0700 Message-ID: <20241026171441.3047904-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101448_895736_3FD61852 X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Move relocate_kernel() out of the CONFIG_MMU block so it can be called from the NOMMU version of setup_vm(). Set some offsets in kernel_map so relocate_kernel() does not need to be modified. Relocatable NOMMU kernels can be loaded to any physical memory address; they no longer depend on CONFIG_PAGE_OFFSET. Signed-off-by: Samuel Holland --- arch/riscv/Kconfig | 2 +- arch/riscv/include/asm/pgtable.h | 4 ++ arch/riscv/mm/init.c | 82 +++++++++++++++++--------------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 62545946ecf4..4420419e7054 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -934,7 +934,7 @@ config PARAVIRT_TIME_ACCOUNTING config RELOCATABLE bool "Build a relocatable kernel" - depends on MMU && 64BIT && !XIP_KERNEL + depends on 64BIT && !XIP_KERNEL select MODULE_SECTIONS if MODULES help This builds a kernel as a Position Independent Executable (PIE), diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index e224ac66e635..d0190ee9b2e4 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -12,7 +12,11 @@ #include #ifndef CONFIG_MMU +#ifdef CONFIG_RELOCATABLE +#define KERNEL_LINK_ADDR UL(0) +#else #define KERNEL_LINK_ADDR _AC(CONFIG_PAGE_OFFSET, UL) +#endif #define KERN_VIRT_SIZE (UL(-1)) #else diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 0e8c20adcd98..a74e28367f9f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -307,6 +307,44 @@ static void __init setup_bootmem(void) hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); } +#ifdef CONFIG_RELOCATABLE +extern unsigned long __rela_dyn_start, __rela_dyn_end; + +static void __init relocate_kernel(void) +{ + Elf64_Rela *rela = (Elf64_Rela *)&__rela_dyn_start; + /* + * This holds the offset between the linked virtual address and the + * relocated virtual address. + */ + uintptr_t reloc_offset = kernel_map.virt_addr - KERNEL_LINK_ADDR; + /* + * This holds the offset between kernel linked virtual address and + * physical address. + */ + uintptr_t va_kernel_link_pa_offset = KERNEL_LINK_ADDR - kernel_map.phys_addr; + + for ( ; rela < (Elf64_Rela *)&__rela_dyn_end; rela++) { + Elf64_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); + Elf64_Addr relocated_addr = rela->r_addend; + + if (rela->r_info != R_RISCV_RELATIVE) + continue; + + /* + * Make sure to not relocate vdso symbols like rt_sigreturn + * which are linked from the address 0 in vmlinux since + * vdso symbol addresses are actually used as an offset from + * mm->context.vdso in VDSO_OFFSET macro. + */ + if (relocated_addr >= KERNEL_LINK_ADDR) + relocated_addr += reloc_offset; + + *(Elf64_Addr *)addr = relocated_addr; + } +} +#endif /* CONFIG_RELOCATABLE */ + #ifdef CONFIG_MMU struct pt_alloc_ops pt_ops __meminitdata; @@ -877,44 +915,6 @@ static __init void set_satp_mode(uintptr_t dtb_pa) #error "setup_vm() is called from head.S before relocate so it should not use absolute addressing." #endif -#ifdef CONFIG_RELOCATABLE -extern unsigned long __rela_dyn_start, __rela_dyn_end; - -static void __init relocate_kernel(void) -{ - Elf64_Rela *rela = (Elf64_Rela *)&__rela_dyn_start; - /* - * This holds the offset between the linked virtual address and the - * relocated virtual address. - */ - uintptr_t reloc_offset = kernel_map.virt_addr - KERNEL_LINK_ADDR; - /* - * This holds the offset between kernel linked virtual address and - * physical address. - */ - uintptr_t va_kernel_link_pa_offset = KERNEL_LINK_ADDR - kernel_map.phys_addr; - - for ( ; rela < (Elf64_Rela *)&__rela_dyn_end; rela++) { - Elf64_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); - Elf64_Addr relocated_addr = rela->r_addend; - - if (rela->r_info != R_RISCV_RELATIVE) - continue; - - /* - * Make sure to not relocate vdso symbols like rt_sigreturn - * which are linked from the address 0 in vmlinux since - * vdso symbol addresses are actually used as an offset from - * mm->context.vdso in VDSO_OFFSET macro. - */ - if (relocated_addr >= KERNEL_LINK_ADDR) - relocated_addr += reloc_offset; - - *(Elf64_Addr *)addr = relocated_addr; - } -} -#endif /* CONFIG_RELOCATABLE */ - #ifdef CONFIG_XIP_KERNEL static void __init create_kernel_page_table(pgd_t *pgdir, __always_unused bool early) @@ -1359,6 +1359,12 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) { dtb_early_va = (void *)dtb_pa; dtb_early_pa = dtb_pa; + +#ifdef CONFIG_RELOCATABLE + kernel_map.virt_addr = (uintptr_t)_start; + kernel_map.phys_addr = (uintptr_t)_start; + relocate_kernel(); +#endif } static inline void setup_vm_final(void) From patchwork Sat Oct 26 17:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852305 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 59A5DD0C604 for ; Sat, 26 Oct 2024 17:15:03 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KO9OeoAIMNwWD4j+6fpLCnTOp6VvED3Q5WsY0ekR25M=; b=jVp/s10vZSfweJ gUnCUDnKkVl6CYCnivmqvr/VOjee+MkxI8Il08B4RK7Zprp5KlO2vxnXq30x7awMnKLg5qCyRz3BU JDV8ayngujQshiJTbfNq94UUpIgVxrqg138w1/fiyvfOeEU66gOq3oBdXVNtlqXmjLnFZU4SVmk2E 6IxdgI2LzRhAoZzVAlQBTDXrRasd/FqJBcLpmJ7tGENv52pEijZlK9tPrkpOed6hPpJueq55A3nOj WiC7fXk+FeDHfe8yTVP3aaAqqpfijSsCkD+ntknPN1MkgsnI49hL0mHAxXhoarK3QrGWfFhdfHfGT 1RwCVvFd5oqxrDMonQlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNN-00000006xBp-37cr; Sat, 26 Oct 2024 17:14:57 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNF-00000006x7T-3ut0 for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:51 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso1951209a12.3 for ; Sat, 26 Oct 2024 10:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962889; x=1730567689; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wv7+Dx0EhtdMcX+vS16ls1Tc801PV63GFkQzeGMvPJc=; b=ncKITJrjWXcSw+g+uXfh2XHj4a4pd5OQ4OFzhBwLOdpJn3wGWxUdbwKlESvPWp1Hff zYYb6g7a3BWRzJZigcEju4EWncMEAu3YS6HlvdSPaE5kb13afq7Ox2RmPS6fcUlCN1VS z3yDNaJy5Xj2DnblaRp2VQE3YDU9NMzyqHpavLh2SF34Sct+p8+GmJtQdDucmQaelh/l LKPwFhV0RBs1FDqD31h9pkObBHSXOcuCQXjaiPPWvy+MOi+v3iKAXLkVD4/Wpsp/eyk7 dagf3im96P6uWjUnt8zyQx/SVyZ8IpPCIqjw0He0UjTuZeBdvV5dB58myhsYuOz2gfRj 9IVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962889; x=1730567689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wv7+Dx0EhtdMcX+vS16ls1Tc801PV63GFkQzeGMvPJc=; b=lxLYiLH7PE1B3TpcFJnLo1rea9E7smMpRAxtVe/XOMJ0y7tjI4BKWUV9OHkM0HCZYu qiVjNndJwJVf5speTwb2ouWnJXzLconGhXiLrW3jSr+92yqAWKjgu6k2eyqebbOsJmIV iBT8V8+ccW6YTgwWxCEqUBJNeZYU0Pi2jJQUNWQiDjBcYn16KjrAb2j0hfp0TbHLmNJt HZzNJsbakUN+AZ5vMZ17XaNyLCaTJi9XQd3A9plp3h8Qg8B8CSKf6dXXnmE3l0fo+NC8 kkCmn+DqPynT8Di155nEJrKCCO4ohoyyyMG448JnxyeDUE0vPIKvdmgv+GOTRv/oXnaq mVlg== X-Forwarded-Encrypted: i=1; AJvYcCVspXmNaTVWKNz1AvPDVhnQNgFrvif6EOeNRGS/7L1536lWJU5TBmIvMmrabZTudgUs7IF5goVWRe4esw==@lists.infradead.org X-Gm-Message-State: AOJu0YwotdkcoK8OScWTMKV67hpwNwEHvA1f4WzULePI2cS9wJVZfUTL Gvxq/YY9SL55vemWVROnqC35RGS4pE1MZWeR0d4fk+TJP+XjGlC4fhofycqM3AA= X-Google-Smtp-Source: AGHT+IEjLY5x3N7GeCdbR6UpuMygbezclirV4ORscEH6CuiNkRrH5F4MjYIKgmPWwSgRogFjiRq95g== X-Received: by 2002:a17:90a:d807:b0:2da:9115:15ce with SMTP id 98e67ed59e1d1-2e8f106d6bdmr4079277a91.15.1729962888814; Sat, 26 Oct 2024 10:14:48 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:48 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 4/6] asm-generic: Always define Elf_Rel and Elf_Rela Date: Sat, 26 Oct 2024 10:13:56 -0700 Message-ID: <20241026171441.3047904-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101449_990256_788653E2 X-CRM114-Status: UNSURE ( 9.00 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org These definitions are useful for relocating the kernel image as well, regardless of the type of relocations used for modules. Signed-off-by: Samuel Holland --- include/asm-generic/module.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/asm-generic/module.h b/include/asm-generic/module.h index 98e1541b72b7..a8622501b975 100644 --- a/include/asm-generic/module.h +++ b/include/asm-generic/module.h @@ -19,12 +19,8 @@ struct mod_arch_specific #define Elf_Dyn Elf64_Dyn #define Elf_Ehdr Elf64_Ehdr #define Elf_Addr Elf64_Addr -#ifdef CONFIG_MODULES_USE_ELF_REL #define Elf_Rel Elf64_Rel -#endif -#ifdef CONFIG_MODULES_USE_ELF_RELA #define Elf_Rela Elf64_Rela -#endif #define ELF_R_TYPE(X) ELF64_R_TYPE(X) #define ELF_R_SYM(X) ELF64_R_SYM(X) @@ -36,12 +32,8 @@ struct mod_arch_specific #define Elf_Dyn Elf32_Dyn #define Elf_Ehdr Elf32_Ehdr #define Elf_Addr Elf32_Addr -#ifdef CONFIG_MODULES_USE_ELF_REL #define Elf_Rel Elf32_Rel -#endif -#ifdef CONFIG_MODULES_USE_ELF_RELA #define Elf_Rela Elf32_Rela -#endif #define ELF_R_TYPE(X) ELF32_R_TYPE(X) #define ELF_R_SYM(X) ELF32_R_SYM(X) #endif From patchwork Sat Oct 26 17:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852306 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 E3863D10C00 for ; Sat, 26 Oct 2024 17:15:03 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9+sGStaqmkMbEO93AG7rFgaYaxV0BWeX+YxM5MoAGnU=; b=iVAgeQiIxXXYaY etRsGXj2IsMyiWPdLIYqlhJLNqAiK//YnEBkU26PrY6E8zuCwapIWK0MttE0lFKAVU1ZzhMPu/ZbL iVqqgE/qVu55bieaVp5hWKKvd/9xGjpG30R48DSFbDnFQMGetpAjjQgdsgMs8mzpdCYllgV1VrSAt CYNpqS5TC7dHCTPtfpmDTgjoR1FkPifwqk7vPydEcjuX3RyF6mCZZx3QW+DIMGPHDFaLy8WKGdFTe JfvcITsFb8+DJesapkgcOmsYyGvSvrRiQfDkLFWlgmt5rNxl3fXsicpDUZalq7vJ/eeRiH8t5syiK qj+64up/B96NtvZDzLtA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNP-00000006xD6-0wvz; Sat, 26 Oct 2024 17:14:59 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNH-00000006x7l-01oU for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:52 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-7ed9c16f687so2271320a12.0 for ; Sat, 26 Oct 2024 10:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962890; x=1730567690; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=32SXpWlDW0kkamANJs274cWuCXV1jWs6Ch/GFZy2syA=; b=OCm/w7P1RJxKJQUkYlEvfgP0swcc5rpK4ArTCkw1N06OdzYlzW1vayR3RpSTUZfFLC 1fv7zrP2lG4eWZIEw5BaeTtzsFWw72MDqUFrMX7COhjzVejBzvGCM26qzacZYzn78p+u o+iLrdmKQiY9L5xcE7YvZh35XbPhDs2abB+s2TTp5MHd6Wr/oqSRpnAKHk4txLwo5M8D /dQmhN2ucuhBS4lb4SMl1MHCSZJoSwTMpuyQ+N1HZZ0VWkbs9W2M4XnZhGPBGwCdTNeQ 9yPf0HL3MSNt+XB2FO6PUoH6vlEIpcT1zbh70QFmenI4Rm6Gm/QJ23VxPIidCtRvCwk5 +Dyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962890; x=1730567690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=32SXpWlDW0kkamANJs274cWuCXV1jWs6Ch/GFZy2syA=; b=UZpTrOrhZv10gVZQQnd1bRokV0dNiWFu7uG8sATO9hu0xn8ODUde4fyuSf3fIpG/P5 rAiuI3mYPUEDwyK7ynUPMPhPWljotBfZD7cCjWphxSwo/GRyy3yUNwAh4A5G1NavreNs +WEHgvTPl86USbJEMguoRTFRMu5obAZlGDqzIIJ26glcNlMMsJxV5Fq59rmujCr0QehK zP0tA+8yOJkL4LJk+ILjSnImM9zciQglyDxzLp1fnxVtNosrS/Hw+zNR3pX2/67yyNrW RI9S1u+oavz8F9GijuWAzysKWUFHSe1IILPf55wJe96dbivdDVTPPHqUQEugkcXuBz+k r0Vw== X-Forwarded-Encrypted: i=1; AJvYcCUgd5TtLULEG/rBu8YzySqtpFkxiL9MBRNyb53l+k3r4SCgRa5fqjKs7edFSc2t/R2v+m4prErC4Uoc1A==@lists.infradead.org X-Gm-Message-State: AOJu0YxB3pyaHhex5LEs+ZsqgzV1nWHhORW6gaN9PfkgBExXCyJd8CnX A9r+H4fygE2bxI00FjnEoG8kKfMDPxVybXVk4tEdV2q4d+PqGrpmE2ibATwY01+LxheO18mD6K0 k X-Google-Smtp-Source: AGHT+IHuE/xLTvkb+BU83DmMK1Bc6hhBs45MKVg/zLV/CvtM1d0wHjLI0sEZOu1+WLDNR8rdwiJXEw== X-Received: by 2002:a17:90a:5e07:b0:2e2:eacc:3227 with SMTP id 98e67ed59e1d1-2e8f107c664mr4417836a91.23.1729962889947; Sat, 26 Oct 2024 10:14:49 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:49 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 5/6] riscv: Support CONFIG_RELOCATABLE on riscv32 Date: Sat, 26 Oct 2024 10:13:57 -0700 Message-ID: <20241026171441.3047904-6-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101451_069041_E3E39BBA X-CRM114-Status: GOOD ( 15.80 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When adjusted to use the correctly-sized ELF types, relocate_kernel() works on riscv32 as well. The caveat about crossing an intermediate page table boundary does not apply to riscv32, since for Sv32 the early kernel mapping uses only PGD entries. Since KASLR is not yet supported on riscv32, this option is mostly useful for NOMMU. Signed-off-by: Samuel Holland --- arch/riscv/Kconfig | 2 +- arch/riscv/mm/init.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4420419e7054..33aa79d84021 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -934,7 +934,7 @@ config PARAVIRT_TIME_ACCOUNTING config RELOCATABLE bool "Build a relocatable kernel" - depends on 64BIT && !XIP_KERNEL + depends on !XIP_KERNEL select MODULE_SECTIONS if MODULES help This builds a kernel as a Position Independent Executable (PIE), diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index a74e28367f9f..0aad925848a4 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -20,15 +20,13 @@ #include #include #include -#ifdef CONFIG_RELOCATABLE -#include -#endif #include #include #include #include #include +#include #include #include #include @@ -312,7 +310,7 @@ extern unsigned long __rela_dyn_start, __rela_dyn_end; static void __init relocate_kernel(void) { - Elf64_Rela *rela = (Elf64_Rela *)&__rela_dyn_start; + Elf_Rela *rela = (Elf_Rela *)&__rela_dyn_start; /* * This holds the offset between the linked virtual address and the * relocated virtual address. @@ -324,9 +322,9 @@ static void __init relocate_kernel(void) */ uintptr_t va_kernel_link_pa_offset = KERNEL_LINK_ADDR - kernel_map.phys_addr; - for ( ; rela < (Elf64_Rela *)&__rela_dyn_end; rela++) { - Elf64_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); - Elf64_Addr relocated_addr = rela->r_addend; + for ( ; rela < (Elf_Rela *)&__rela_dyn_end; rela++) { + Elf_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); + Elf_Addr relocated_addr = rela->r_addend; if (rela->r_info != R_RISCV_RELATIVE) continue; @@ -340,7 +338,7 @@ static void __init relocate_kernel(void) if (relocated_addr >= KERNEL_LINK_ADDR) relocated_addr += reloc_offset; - *(Elf64_Addr *)addr = relocated_addr; + *(Elf_Addr *)addr = relocated_addr; } } #endif /* CONFIG_RELOCATABLE */ @@ -1155,7 +1153,8 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) * makes the kernel cross over a PUD_SIZE boundary, raise a bug * since a part of the kernel would not get mapped. */ - BUG_ON(PUD_SIZE - (kernel_map.virt_addr & (PUD_SIZE - 1)) < kernel_map.size); + if (IS_ENABLED(CONFIG_64BIT)) + BUG_ON(PUD_SIZE - (kernel_map.virt_addr & (PUD_SIZE - 1)) < kernel_map.size); relocate_kernel(); #endif From patchwork Sat Oct 26 17:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13852307 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 BC884D10C01 for ; Sat, 26 Oct 2024 17:15:04 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DuI2mOjIp1P9JIi4ZO6uU6qnzMCRxUOER9OE5+0b8No=; b=4S2Jd+/Ny71RkP KqBpk9JaRWv6x0LVSNw1GneBQsC9R1Z4IlqY9Rw/GBJY2bRSj0fGLjPt5LytypLe46fblFJvBU3zx DzgVuhU/FTvJ7WDcEF4EeBVNdV/svJkmXeShPwHVr7HUz1b4sMt4PwBi4zKzIb+tPAh3pedZ5WG1C aHOekvXnFKbq3FSkDNedrXZHGy8kEC8rN2fLfv6HeTxwP/eXTj6LkIy+a9Cv0qEdUTLC3CsxZyN9b Jv2ggGvuK0lo/Rg8+ecpRjNfDbs3LhR2Hc2Xrk6UwxhyvNpxp02xUMCNG2LDLveVEnGWkYLoDa7lx uVtxhZRdupzRBttmTHdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNQ-00000006xDx-0vt1; Sat, 26 Oct 2024 17:15:00 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4kNI-00000006x8G-1GAy for linux-riscv@lists.infradead.org; Sat, 26 Oct 2024 17:14:53 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2e30116efc9so2423163a91.2 for ; Sat, 26 Oct 2024 10:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729962891; x=1730567691; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3iilPE9PRtO5dgnEVdYwMDgO0cR2NihKQ5GAqyVmi0I=; b=bPmhZsTMq5/mfSxPae5gqDUkFoyPUkOzTJQ40AUg68b8rKG0L/OMX7PhjB1847ZqFs z5WYdanmRbLGercITXjhY6hhVQzwkuLH6pR/ZhVP/JdvuZA8bPK9MmU6FJ+9IOKq+5Qx hFdeGfWCew5+6svyVYBxfDwqVP2ol5REAwpy1UAO8//RovMVr7fyJ1STHolxx2WdEodn HI4js2kFzefvRiWtckNJNrV6edpTSpaM1z71dlyNC4MEVDZUNa4+p7aKpxEJJu6/TE4W AdwGWmWGhP3FRUZqeWeDuZwqhiF7WUoztkup6jHLylD3V5bEi8SxOUi2gpHtzCJoiH5S 0M1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729962891; x=1730567691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3iilPE9PRtO5dgnEVdYwMDgO0cR2NihKQ5GAqyVmi0I=; b=Md/QlvRlsVm5QJArMxTqCoWavdIM33sEvM+sD5KLIMJsyhfx4KGxQCmcV6wr+1zuXp DvS8RG+eG6aH77na7CcJvpjqOkrkZ0YGw9E6Y4xUPNmCP5c24sH0pKiNat2edlzrgt39 P2QCMZYXQh+QQwGECcMsanaN5AZgK0aSFHHwemFCNAtyTmcWQcUVK5lGiN+tazRpmzpK KWEidahwCfC9cNv3R+NXdwquehxeM5fDeShVCwmNJT1IhM9tOWC/daqsDPYXTGejhd73 IEklo8mKbmgZPh95ZOZDOnN+w/BGH1Zrfs5S5ZvRKc74ImSOeuTvIS7AZ5rJ4D00coPI ovzg== X-Forwarded-Encrypted: i=1; AJvYcCUeFqo9lwembht9HZTElyfrN+gjg3BnzTVNDkCaLH7+gwKoLf/8keD6qb31O11de2QV5QyGUyDqnZW5Zw==@lists.infradead.org X-Gm-Message-State: AOJu0YwAC+w3lbBCSlp5VU4yF2qhlHtzYPDKCZkNArCtWHB/PT6JpXfr hiQYaEKybF9JUUtmKJa0iuQcCH0FzD/mPRMEpBteB3IMc9VHlaaF5Z6CX7rDfDY= X-Google-Smtp-Source: AGHT+IHKHWEssFZ3dU4bK/XFfhtDHlaKTxMDsGGVAwitWxfjevjp7X7a3fieuNlFSdnYzB2SDFDTOA== X-Received: by 2002:a17:90a:3d0a:b0:2e2:c252:f861 with SMTP id 98e67ed59e1d1-2e8f10a7298mr4016154a91.28.1729962891258; Sat, 26 Oct 2024 10:14:51 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e558114sm5663762a91.36.2024.10.26.10.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 10:14:50 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Andrew Morton , Arnd Bergmann , Alexandre Ghiti , Samuel Holland Subject: [PATCH 6/6] riscv: Remove CONFIG_PAGE_OFFSET Date: Sat, 26 Oct 2024 10:13:58 -0700 Message-ID: <20241026171441.3047904-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241026171441.3047904-1-samuel.holland@sifive.com> References: <20241026171441.3047904-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241026_101452_385790_C84C1ED9 X-CRM114-Status: GOOD ( 16.69 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The current definition of CONFIG_PAGE_OFFSET is problematic for a couple of reasons: 1) The value is misleading for normal 64-bit kernels, where it is overridden at runtime if Sv48 or Sv39 is chosen. This is especially the case for XIP kernels, which always use Sv39. 2) The option is not user-visible, but for NOMMU kernels it must be a valid RAM address, and for !RELOCATABLE it must additionally be the exact address where the kernel is loaded. Fix both of these by removing the option. 1) For MMU kernels, drop the indirection through Kconfig. Additionally, for XIP, drop the indirection through kernel_map. 2) For NOMMU kernels, use the user-visible physical RAM base if provided. Otherwise, force the kernel to be relocatable. Signed-off-by: Samuel Holland Reviewed-by: Jesse Taube --- arch/riscv/Kconfig | 8 +------- arch/riscv/include/asm/page.h | 15 ++++++++------- arch/riscv/include/asm/pgtable.h | 2 +- arch/riscv/mm/init.c | 8 ++------ 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 33aa79d84021..297ccbf4b5ce 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -195,6 +195,7 @@ config RISCV select PCI_DOMAINS_GENERIC if PCI select PCI_ECAM if (ACPI && PCI) select PCI_MSI if PCI + select RELOCATABLE if !MMU && !PHYS_RAM_BASE_FIXED select RISCV_ALTERNATIVE if !XIP_KERNEL select RISCV_APLIC select RISCV_IMSIC @@ -282,13 +283,6 @@ config MMU Select if you want MMU-based virtualised addressing space support by paged memory management. If unsure, say 'Y'. -config PAGE_OFFSET - hex - default 0x80000000 if !MMU && RISCV_M_MODE - default 0x80200000 if !MMU - default 0xc0000000 if 32BIT - default 0xff60000000000000 if 64BIT - config KASAN_SHADOW_OFFSET hex depends on KASAN_GENERIC diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 24d1ac052609..d1acd1efe0dc 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -28,15 +28,16 @@ */ #ifdef CONFIG_MMU #ifdef CONFIG_64BIT -#define PAGE_OFFSET kernel_map.page_offset -/* - * By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so - * define the PAGE_OFFSET value for SV48 and SV39. - */ +#define PAGE_OFFSET_L5 _AC(0xff60000000000000, UL) #define PAGE_OFFSET_L4 _AC(0xffffaf8000000000, UL) #define PAGE_OFFSET_L3 _AC(0xffffffd600000000, UL) +#ifdef CONFIG_XIP_KERNEL +#define PAGE_OFFSET PAGE_OFFSET_L3 #else -#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) +#define PAGE_OFFSET kernel_map.page_offset +#endif /* CONFIG_XIP_KERNEL */ +#else +#define PAGE_OFFSET _AC(0xc0000000, UL) #endif /* CONFIG_64BIT */ #else #define PAGE_OFFSET ((unsigned long)phys_ram_base) @@ -100,7 +101,6 @@ typedef struct page *pgtable_t; #define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) struct kernel_mapping { - unsigned long page_offset; unsigned long virt_addr; unsigned long virt_offset; uintptr_t phys_addr; @@ -114,6 +114,7 @@ struct kernel_mapping { uintptr_t xiprom; uintptr_t xiprom_sz; #else + unsigned long page_offset; unsigned long va_kernel_pa_offset; #endif }; diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index d0190ee9b2e4..b8125c3aa85d 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -15,7 +15,7 @@ #ifdef CONFIG_RELOCATABLE #define KERNEL_LINK_ADDR UL(0) #else -#define KERNEL_LINK_ADDR _AC(CONFIG_PAGE_OFFSET, UL) +#define KERNEL_LINK_ADDR _AC(CONFIG_PHYS_RAM_BASE, UL) #endif #define KERN_VIRT_SIZE (UL(-1)) #else diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 0aad925848a4..a1a185e6faf0 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -843,6 +843,8 @@ static __init void set_satp_mode(uintptr_t dtb_pa) uintptr_t set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK; u64 satp_mode_cmdline = __pi_set_satp_mode_from_cmdline(dtb_pa); + kernel_map.page_offset = PAGE_OFFSET_L5; + if (satp_mode_cmdline == SATP_MODE_57) { disable_pgtable_l5(); } else if (satp_mode_cmdline == SATP_MODE_48) { @@ -1090,11 +1092,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset; #ifdef CONFIG_XIP_KERNEL -#ifdef CONFIG_64BIT - kernel_map.page_offset = PAGE_OFFSET_L3; -#else - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); -#endif kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR; kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom); @@ -1106,7 +1103,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.va_kernel_xip_data_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr + (uintptr_t)&_sdata - (uintptr_t)&_start; #else - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); kernel_map.phys_addr = (uintptr_t)(&_start); kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr; kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;