Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1281108lqt; Fri, 7 Jun 2024 13:23:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5Uiwjl1FqnSj2a/P/wARlyOdNM3GABT7DupM3eAtiOE/rFTx8EGe/HSUb6U2cKy6qn+s9ui8xMd7VnfjKvg0HFjwORIYbMswBZD9UmA== X-Google-Smtp-Source: AGHT+IHHTjOIew8YVcFdfR3vyeQjJksXZf9ym8z0lEZ+iCP0QOAc6TU13j05iCDefCxXYLCwBdvY X-Received: by 2002:a50:8e54:0:b0:57a:2a56:8a37 with SMTP id 4fb4d7f45d1cf-57c549edc3dmr1743476a12.13.1717791818698; Fri, 07 Jun 2024 13:23:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717791818; cv=pass; d=google.com; s=arc-20160816; b=wOyIQ7ESCl6PfTk1dGug5EjUdasXx9iB/5foGVfsV4ruYXE9dmDpbnDlcQGDM5x0pi YH4lkXKvt6I+s2TtvYRv8p8rJ5XxITAYsdInNGh6oyzt6tVU5zZQZWqfvN3KDCwHw7Ae //ebPZvcs3sSxidjR8Fo8y7OUc7PAojBcTrsO6tTa+9egzktQvxfOBS3TROm4LX7udKJ N7r13ER4URAMin1OlXJBSvMwmcsaeDSdtzXcAhHSdzLxmWnO+Drgga3bNH51I+2DoTsP nriqVzppxTnVpbg2q+iiVnnps628cU+A8bp4w+b380fsyGHvH/VOarsbvKqvhQMEjxBT wDnA== 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=y4FmsaK4U8owu4NlSDzmS6G8DVihDPJxkQgSL8xnqno=; fh=NjSy9ELbZGh6EjCqOzE+qeF+VS4OABBeZf5VHCmpp/4=; b=UqQ5IjEhmqTQetdlwSjRMXeMaEItBwmnQtsSz1fm9aqFwCA0IDQT43hEzEJEQu3jWS 687N68DiJORLGUDGcynGYXBkDUd8KQvFR+2zMUiMGBGIeoaJSjUIdxwBt/dsFTDvNkif cvshD1TGEN4INca5FG+wsGZ4nuy9GV6tYPlgAVp/PZNqmYCizDazW/p7rCudkaLXO37D EMzXE41srVsrbrZsUCczymmYgiJG83QbQ1zXUKo/o1A6r1324V7SUXTFuL9kvj0hSreP lQTPQMUr7ADg69G6yBIh5yWp7a8NS++8xVtFCIQP1UGLigPxqzXC5KFsX5eoQK8bWint leZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jV4r27iO; 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-206699-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206699-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 4fb4d7f45d1cf-57aae2361d6si2155119a12.470.2024.06.07.13.23.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 13:23:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206699-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=jV4r27iO; 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-206699-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206699-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 6A7731F2123B for ; Fri, 7 Jun 2024 20:23:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC5CB1553A6; Fri, 7 Jun 2024 20:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jV4r27iO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qenheITo" 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 22506153BC3 for ; Fri, 7 Jun 2024 20:22:18 +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=1717791740; cv=none; b=RRgA9GuU6Wv4bT3pPcDf4vl49djAO8ZfdmW4gKvlT+3I5tleRvcG7q92viLjKiY0uwCu+VMoBDd1dwTiamggvpljLx0IlLSht753+O1jrkeRwgGnpx+dLkOL6JKbdta3WXaLXeenPb50SjHMKnFppvGBhm7geCb0yOZjy4gs+J4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717791740; c=relaxed/simple; bh=CnPSiJoSkTaS4DgxuVepbWdO7rowLFCL7+5optFOhBE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mEwJyXvKejkh+LbUip1cWXghIQX6ToZJTl2yyFKWAkgbE4N0ISkAg2nrNOQXVYAmeKU4MiSYX2aD79QO0VCF0eqlCc+KbY4TwJKR7/4woJ49dI35sVSS4GZkl+R80aB030579qhtENbKFOardCkjZjtAXCaNj9EWxnMghsWEzSI= 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=jV4r27iO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qenheITo; 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=y4FmsaK4U8owu4NlSDzmS6G8DVihDPJxkQgSL8xnqno=; b=jV4r27iONhJVERHB641eznAaftrwZ3nE682uV9gC1aGX3evxbgEtI3+I/GGIFZOgjpwiHX jrivhNjIULLbcTEF1ebUWj0KfocGBOpUnJ089SgjLwdKHrT3YqY/Eg0SXgoahKrD73OQPD GIPo3UKx7rqQ8OQfdvFUdf7X8OHayoEhJvPcmX6BDOlSxCWNVz6CkE8p3Fk92DtWshTiPF dt03h8kY0i0/VeSoJX638ThLxRh0Z3R5ck0NRVVs8N5T4i5pkp03gk2RhX4GYCP2ODf4pk b/rBf/p5UzcV/U6PLxXYHL0ZFnOUVb7oknY6vFnqE2fmMzHNT9Mjn98ZwcXy8Q== 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=y4FmsaK4U8owu4NlSDzmS6G8DVihDPJxkQgSL8xnqno=; b=qenheITowqvS4kQkmh3FtMet7WUSPFv4Sdzt965PbpQbng2mrMAKUNPxeXEZyrFEa0dnT6 byAMvr7yCjRM4vBg== To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/8] riscv: drop the use of XIP_OFFSET in create_kernel_page_table() Date: Fri, 7 Jun 2024 22:22:12 +0200 Message-Id: <4ea3f222a7eb9f91c04b155ff2e4d3ef19158acc.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 XIP_OFFSET is the hard-coded offset of writable data section within the kernel. By hard-coding this value, the read-only section of the kernel (which is placed before the writable data section) is restricted in size. As a preparation to remove this hard-coded value entirely, stop using XIP_OFFSET in create_kernel_page_table(). Instead use _sdata and _start to do the same thing. Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 313459329d16..b7b6affd4b79 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -911,7 +911,7 @@ static void __init relocate_kernel(void) static void __init create_kernel_page_table(pgd_t *pgdir, __always_unused bool early) { - uintptr_t va, end_va; + uintptr_t va, start_va, end_va; /* Map the flash resident part */ end_va = kernel_map.virt_addr + kernel_map.xiprom_sz; @@ -921,10 +921,11 @@ static void __init create_kernel_page_table(pgd_t *pgdir, PMD_SIZE, PAGE_KERNEL_EXEC); /* Map the data in RAM */ + start_va = kernel_map.virt_addr + (uintptr_t)&_sdata - (uintptr_t)&_start; end_va = kernel_map.virt_addr + kernel_map.size; - for (va = kernel_map.virt_addr + XIP_OFFSET; va < end_va; va += PMD_SIZE) + for (va = start_va; va < end_va; va += PMD_SIZE) create_pgd_mapping(pgdir, va, - kernel_map.phys_addr + (va - (kernel_map.virt_addr + XIP_OFFSET)), + kernel_map.phys_addr + (va - start_va), PMD_SIZE, PAGE_KERNEL); } #else -- 2.39.2