From nobody Fri Oct 3 07:39:28 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B12DF14B977 for ; Thu, 4 Sep 2025 00:52:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947158; cv=none; b=PHRzd0No6nqP2lhSJ0WaM1hjP9f/fBtzu4Iwjnfgr2iKPtfQPt6RISzBbU/ymK9GsuAvInwHji+ELyD9CwcfPt8k1I2YtnxTp2/hRa4H/w6k00PaGnfxqILcoJyOzXaNZH/9UDN7N+ARsH4JcBTEJ0Nd2RzBM4ninICliKi8nuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947158; c=relaxed/simple; bh=GIZugSgwf/IBguNIs/OK7zQTIvb/FRn9sZYfy6LkexM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hIBNP1/SLmGA4+lQmwm64EiNr7q2AocYfV7OTav1OXYmZov8z0iwVehqwWkWZOSC796vHbjBoUpUwao1t6JlxOA7DjbrB0cDNJQNIrby3fO+Owtdi6UDB92VFanwbRUtrLAdmCQY9Ra3CVFtrvjB6Kt/0EbvEgfPJXWN7ajz8AA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jsx7ApRZ; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jsx7ApRZ" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-772301f8ae2so443764b3a.0 for ; Wed, 03 Sep 2025 17:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756947156; x=1757551956; darn=vger.kernel.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=d/PtowZWncD7g5yzTgjrgtYoRGlVEb75A6E0NAaBaiE=; b=jsx7ApRZkteAr076MZOm3LWed4IcQsWw8CaHNoJpMGRBgBmR4repnZ6l5RvMEdYVq1 6GCTS7XkUs08dxa8YecHJ+YkZHJPklf/JxDqcBBNMIpztSBy0fWGerCPzBGNGVVhR2i4 WJvms5m66E+dwmVH/UNRQ5zexohYojmZpUSqmJpvdA2/m/VQxJ5A1s1ZdwuBUMG49vGy Cf0bfrXHVCse/bK2uPf5r5Z1YSSlDVWje8clg79tkI3NIDbGvZYJj1/GX0ltD9QXj31W CmrcwDL1GRHLqjQsm/ARHR0KBmNoFWoWP1vyZxKK2ECWZ6oUfCKTfRsMOvqIu2UFftFO 84ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756947156; x=1757551956; 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=d/PtowZWncD7g5yzTgjrgtYoRGlVEb75A6E0NAaBaiE=; b=wr4QuJeevXMxMFVUFXXkQhuVfrA1iZkf56RpzexU73X+/P6QmCxCjOx4pUxltSJElS OqUtGNEUaH44d6cuWU40Qm9lPK1LSGkPWmIdYMKDQUnB6FXGra1aCCZuiAk3Wcw0Hd7n 1nneHh1ZuAeyowz0Vozs+fEUO183Cggcnpz+rdQuzIqb/hEfEN63PdcjYgW86hp6QeLn bLN1lBKpphOiITrU3gaq9C4QDXXaac7jDJbZGFB6e4tmKP7FyPVbefidxH1mFjqbF9bE alI+o0CbiZU7iN6GdGCWMATZT/68AHpWqZDCSx+dosS2Tn00fSChUR+QOZb3KMDL52Z5 XRvA== X-Forwarded-Encrypted: i=1; AJvYcCVgp5dmcLXldSntQ3U1wwl+BaO1ybIxEjxHmAEQt98XQ8kSq5mFhgappGzmvvvEbSB7y4GCf44/Oy/4ch0=@vger.kernel.org X-Gm-Message-State: AOJu0YznP8JuVQoCps5YCiVS8KW7/+yuokva9g5T3LqRw7pi/96iJqfg acO2877FH1L9SykzRDxkfLApEu8mJR1HAuNGWv4sA1ynpMV/zO7TZlTF X-Gm-Gg: ASbGncsm1lHef/5tw3EfrNpa8imNgFfABJ1UaMKHiPuXxULo3re1GSJwxBMFTX8ZeT4 6yIyvlcRrwQzrakkDtWFPV9WjIryZnvYZPxxRHXCaDnKxcnD5XP6JLf2YQo1EpQgvKtmIcPmh+g FCH4eNIstgHg2egSsBhoi6AMUYJXojL7msKTK3t8Brjm5KkPTT0xmTQjavVUVaPJ2v/ihMxdC/L o+z147frj3uhw9f5bD8ifJUAs1s3XBveCIkMdHVLZiip9UEPCvuuJrzkhPoCSg0Oma3TV33Ci3A c2bqgukxWMbJMM5UOaCxV9Hcdu2gG8+4nwlz10pIVLtaNYyNPpE4Gak1IBZYMR9MkLC931pbAkO wnTgCuhukZYzwvt+6AXsM3+9dyfRgnC3V+03RcHsXAIRPunU9zDh7jnj4i7ly+9oroLoIfU8= X-Google-Smtp-Source: AGHT+IGZaqd4bARj+mLl0wXBwvmUgoSDL0+9kDhmB01XllE5NOEa7P4aqnIE1ZquOyLN5o/MJ3L6Vw== X-Received: by 2002:a05:6a20:12c4:b0:249:1867:c905 with SMTP id adf61e73a8af0-24918864e0fmr5294229637.15.1756947155824; Wed, 03 Sep 2025 17:52:35 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:882:283c:10f0:c999]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd28b3849sm15748931a12.31.2025.09.03.17.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 17:52:35 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Catalin Marinas , Will Deacon , Marc Zyngier Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Ryan Roberts , Baruch Siach , Kevin Brodsky , Joey Gouly , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH v2 1/3] arm64: mm: Cast start/end markers to char *, not u64 Date: Wed, 3 Sep 2025 17:52:07 -0700 Message-ID: <20250904005209.1494370-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250904005209.1494370-1-CFSworks@gmail.com> References: <20250904005209.1494370-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are a few memset() calls in map_kernel.c that cast marker-symbol addresses to u64 in order to perform pointer subtraction (range size computation). Cast them with (char *) instead, aligning with idiomatic C pointer arithmetic. This patch provably has no effect at runtime: I have verified that .text of vmlinux is identical after this change. Signed-off-by: Sam Edwards --- arch/arm64/kernel/pi/map_kernel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_k= ernel.c index 0f4bd7771859..2b3047860230 100644 --- a/arch/arm64/kernel/pi/map_kernel.c +++ b/arch/arm64/kernel/pi/map_kernel.c @@ -179,7 +179,7 @@ static void __init remap_idmap_for_lpa2(void) * Don't bother with the FDT, we no longer need it after this. */ memset(init_idmap_pg_dir, 0, - (u64)init_idmap_pg_end - (u64)init_idmap_pg_dir); + (char *)init_idmap_pg_end - (char *)init_idmap_pg_dir); =20 create_init_idmap(init_idmap_pg_dir, mask); dsb(ishst); @@ -188,7 +188,7 @@ static void __init remap_idmap_for_lpa2(void) set_ttbr0_for_lpa2((u64)init_idmap_pg_dir); =20 /* wipe the temporary ID map from memory */ - memset(init_pg_dir, 0, (u64)init_pg_end - (u64)init_pg_dir); + memset(init_pg_dir, 0, (char *)init_pg_end - (char *)init_pg_dir); } =20 static void __init map_fdt(u64 fdt) @@ -242,7 +242,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status= , void *fdt) map_fdt((u64)fdt); =20 /* Clear BSS and the initial page tables */ - memset(__bss_start, 0, (u64)init_pg_end - (u64)__bss_start); + memset(__bss_start, 0, (char *)init_pg_end - (char *)__bss_start); =20 /* Parse the command line for CPU feature overrides */ chosen =3D fdt_path_offset(fdt, chosen_str); --=20 2.49.1 From nobody Fri Oct 3 07:39:28 2025 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0098029D0E for ; Thu, 4 Sep 2025 00:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947159; cv=none; b=lujUBP3y2oq4LCDYL3ClZQBL8ZNBejEzMOTU331MtUTG2xNf1JgWV9NkWsrMrnlfXPupqwPXcStD8OAdC7X80F9yiw1SR6ty4yVeXGI1RcqOInTGOG6QgrGwmIGneo8tzOu3rfQ53OGYlk5nZk21d1+hG9GXvnuhMqSFSIWge2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947159; c=relaxed/simple; bh=tWp6hE3wqtzBGGf1wcrFiqMq81hqBs2TkYqcSSLJN80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q7Ne9UH4wiByTvyNVethc5CdAzdFSlSKxqueoGxJZzJCAR3/bcEzZsEQ9+ryltqAkcFZOcTWGbyfvFmg3unvm/0k0FkPDCCHgejmia49A+bqTBuXy//MUGyglDdOxbhjNP79dDfJ4PWSy56nlRH9hvgiji0XX9FnMWx4Ijl4npY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kpr8od7W; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kpr8od7W" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-b4c738ee2fbso349662a12.3 for ; Wed, 03 Sep 2025 17:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756947157; x=1757551957; darn=vger.kernel.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=t/th4jop1O0kFuAVgwskLm3Kft+pDSyOKRwu3IMOkLA=; b=kpr8od7WitkMbzNkjit0+IGsDgt1hOCLNVsKUsDOL+F77Gbh0QwgJCM9LpAxSQt2tT RH26qHf8UpczWWd7wwaYvyML9QtTKNXlTXkG7BENw1BKf1+IWNT6ctfj3hSSA6dPYASu E81SGPYB96209v4ECUO2xBSnCbXmL+fdAudrGQjQmFH50ic0Ax7FP0XoYrynczft4kY9 kFtn7vq76v5OJFJENs2MsRhwlNeMQr5gl0pq29wNb0SVwMtHu8kURFTRIa6H8vJ2+FXQ Zr9FWUhBfR8Lg6cgRtco0nw/5dCGS5qc6UQZiRfspBvDiMcwpZup0KRKbBmeUIGxpvst rDBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756947157; x=1757551957; 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=t/th4jop1O0kFuAVgwskLm3Kft+pDSyOKRwu3IMOkLA=; b=Qs5zCWfsqMOJK/oxuZC1kMfu2VMnofYd1wDep4uV0xpfuNaU2wcbjhfsKo9qJ/g6YM NABgcHLAFIBQslSnDKMFthnMVdmfwt8KTzSURX3vA/xwjauvR2WXW/Z1HOX3swPzztAE 6UWJIo/ssiejpD61B1P+GoAS42djctZ+w24dFMnsqjIm74bNHlAQyBaH7p5959x5PgfW cte60Ex1h7/JuDAO3hDISROCNPszK+Wrj1+nxu/orHRcf1d3EcLeZSgUwjiUbtEGtoN7 jHmZjJFIcxOYkQJOyJH7sof4kK2lpAz2RgsZZxC9vidcH3ttXUZKKALtFMeoxRBhgFIg DVdw== X-Forwarded-Encrypted: i=1; AJvYcCX9Rrc2IXPDq3mL1nqZK6E/iqyHHpkBVyPFWCzbzuXWvLuzXPQqfzBlGNj2sEPrWTQcC0C7aFOz/FCzrw0=@vger.kernel.org X-Gm-Message-State: AOJu0YwyBL8AvGHthDLahr2JGJ+tgk2NeH3MerTX8UWOSUZMhuasQAoi RrjsEegnCw5txZimNnGVdnyFgwwpAGUzc6tl7Bjp8/FHDG0/L/d3m+1Y X-Gm-Gg: ASbGnctFWiEvLk5pzMorqruPzKCIcbRX6dG1/zLYjyK2VRv2PMxe937OCwU5Ca2q7gC 8ZS1W9NQRd+GXZ4DNsERfB7Hn3fLZ+RpqoDVEorZohhJPfwzineofnZzZSuTgYXqvp9JnMI+B+5 eWzh7aFSwCeCPK/MHSIUK0pe6tm/iF7F4CvXsv1B+VQeDeKbgpVg0gJqUSrNn0kigrLSByqbnzY adhED0hsNQs1LPTLMrPBE9SPSKsrBNDecwidMBy+sn0Zs43KTKenP+CgcQFN2XNQuVsZUKrsMAR hrnrUR5fEjP1icWSBf158S+mvwXokXAFUyvCoMI2mzCTlbLM4PYdQ7WqqFlHAwqURtIFf0ZhBo2 07jZ9ViLb2pe2fKcLcOxUMExvkMWTjtxKLkyAVssWTIk5CmBp6WQ6cmv/kw3P X-Google-Smtp-Source: AGHT+IHXTSNI5t71w5e+WgB8B52Hvu9vci+qQdskTPpSKSg3A5yenk7DiQMoYc/Whz1X4xBXi6xZAg== X-Received: by 2002:a17:903:2cf:b0:248:79d4:93b5 with SMTP id d9443c01a7336-24944a9d32bmr220968295ad.33.1756947157070; Wed, 03 Sep 2025 17:52:37 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:882:283c:10f0:c999]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd28b3849sm15748931a12.31.2025.09.03.17.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 17:52:36 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Catalin Marinas , Will Deacon , Marc Zyngier Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Ryan Roberts , Baruch Siach , Kevin Brodsky , Joey Gouly , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH v2 2/3] arm64: mm: Make map_fdt() return mapped pointer Date: Wed, 3 Sep 2025 17:52:08 -0700 Message-ID: <20250904005209.1494370-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250904005209.1494370-1-CFSworks@gmail.com> References: <20250904005209.1494370-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently map_fdt() accepts a physical address and relies on the caller to keep using the same value after mapping, since the implementation happens to install an identity mapping. This obscures the fact that the usable pointer is defined by the mapping, not by the input value. Since the mapping determines pointer validity, it is more natural to produce the pointer at mapping time. Change map_fdt() to return a void * pointing to the mapped FDT. This clarifies the data flow, removes the implicit identity assumption, and prepares for making map_fdt() accept a phys_addr_t in a follow-up change. Signed-off-by: Sam Edwards --- arch/arm64/kernel/pi/map_kernel.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_k= ernel.c index 2b3047860230..5dc4107b5a7f 100644 --- a/arch/arm64/kernel/pi/map_kernel.c +++ b/arch/arm64/kernel/pi/map_kernel.c @@ -191,7 +191,7 @@ static void __init remap_idmap_for_lpa2(void) memset(init_pg_dir, 0, (char *)init_pg_end - (char *)init_pg_dir); } =20 -static void __init map_fdt(u64 fdt) +static void *__init map_fdt(u64 fdt) { static u8 ptes[INIT_IDMAP_FDT_SIZE] __initdata __aligned(PAGE_SIZE); u64 efdt =3D fdt + MAX_FDT_SIZE; @@ -205,6 +205,8 @@ static void __init map_fdt(u64 fdt) fdt, PAGE_KERNEL, IDMAP_ROOT_LEVEL, (pte_t *)init_idmap_pg_dir, false, 0); dsb(ishst); + + return (void *)fdt; } =20 /* @@ -238,15 +240,14 @@ asmlinkage void __init early_map_kernel(u64 boot_stat= us, void *fdt) int root_level =3D 4 - CONFIG_PGTABLE_LEVELS; int va_bits =3D VA_BITS; int chosen; - - map_fdt((u64)fdt); + void *fdt_mapped =3D map_fdt((u64)fdt); =20 /* Clear BSS and the initial page tables */ memset(__bss_start, 0, (char *)init_pg_end - (char *)__bss_start); =20 /* Parse the command line for CPU feature overrides */ - chosen =3D fdt_path_offset(fdt, chosen_str); - init_feature_override(boot_status, fdt, chosen); + chosen =3D fdt_path_offset(fdt_mapped, chosen_str); + init_feature_override(boot_status, fdt_mapped, chosen); =20 if (IS_ENABLED(CONFIG_ARM64_64K_PAGES) && !cpu_has_lva()) { va_bits =3D VA_BITS_MIN; @@ -266,7 +267,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status= , void *fdt) * fill in the high bits from the seed. */ if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { - u64 kaslr_seed =3D kaslr_early_init(fdt, chosen); + u64 kaslr_seed =3D kaslr_early_init(fdt_mapped, chosen); =20 if (kaslr_seed && kaslr_requires_kpti()) arm64_use_ng_mappings =3D ng_mappings_allowed(); --=20 2.49.1 From nobody Fri Oct 3 07:39:28 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78E3C1A83FB for ; Thu, 4 Sep 2025 00:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947161; cv=none; b=H4GEb2HOq7mJIT35Q4TbnhznQY8HzKtAwls/22cHxfHMscdKDDyWijIPhopZhQTSnTtA40n+xAf2UznkoHPJQKDepEnWsVZcmJnDw2UDRJsH9WW6W0C5qvSphjv+174mQd1ex/0XWLS7FAIdXuXw7v7Su7bE4QICmm8UNUwgdqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756947161; c=relaxed/simple; bh=WpMe8biLwNqQumQW6P/WEzAXtw4mFoY2kXv2lN3d3YU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E10ETvSkfiS3nqt9IStu3Dr/uk6yf2MkKdF7evpqO0LZgbgEJpZTXA30GvTnmYfn2R5beeXAyTKKxofs8XEbAl0NPCi+hD4yXTuHTmpES9SzLYxyNstVDACBVK12aDDL7CfEHJCKvmTrGGkg0HY07VVK8ZgrqOa5wzvItJjQijk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H4Kx1AIO; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H4Kx1AIO" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-323266d6f57so512308a91.0 for ; Wed, 03 Sep 2025 17:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756947158; x=1757551958; darn=vger.kernel.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=B+SdkyD8EaHhN4WfiLsJb50fWJo9nRspmtjnVTNLB4Y=; b=H4Kx1AIOGKRN0PhUYhcjc4WF3pJ67caMHO04rWLdMPIPm9GxN8LoGn3Y7zV19/8woN DqJNMa6C3k6Aa5jPMq9WfaPVZVTYWbEuzxVONeqiYQm4yDATZGlPm7a2eYnotgJOuP9+ QIknhJxZjw2JmdcWTeDkOKQt2OhKJsf1fJVB10WtkG1XEKIhy3ig+9eSvHz/xY8QhSk3 TiHsELkuiuRf00ao5WBSOYWsdrS9IvmTAfMnS0KLbeixqSG0cPyG7473RM4EsOp2IRNJ kcyFSeSap1RXzcyGnDlK0Gl2DfrhW5orcaT1bLw0o91ODkKjU/EJLALqtxtCKZHukwPV g9Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756947158; x=1757551958; 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=B+SdkyD8EaHhN4WfiLsJb50fWJo9nRspmtjnVTNLB4Y=; b=WVDeWrK3Cc9yuPiHcwk5seXLuW88pNQsGMhdFbbZRy29ualSG5bwbtMp+/TsyL0HPn rh1gezY/JNq3f9H+TZhCC8RodiGnb5PyJwkcJmJnrVJsnHPXMuSxI8qBFeMIhrJFBtQS altcANg67e2S8gxC81b9eDY+hmSt2MHf+rMXlF35a8+FqE4TgngT/ul3X5Mo9VlJVKtr EQfMvPzXz8/3ujzkf4c+ki92hQ7QwCBV5V2UdW1jzVDK8XdWZfOeIdDXtrkQjWvi+3Cb xDmTwyWtmY5GTBpiOJYbRoDmz4HPRKDjGxRuZwSgvc1tL3/nvlh3Ls+1NowAutd7E3CN NHAA== X-Forwarded-Encrypted: i=1; AJvYcCWK0nyBVcK8VWauZQUESU+gBuABGaplvCclcqXVLIhioIrgjEc5fq31Y8obxurds2yWtz2B8LnqhYusJXA=@vger.kernel.org X-Gm-Message-State: AOJu0YwqYH8MKrsIybL1l3n1/RRy8PlSaFZKOMQR59yqD/7lcwrJabNz Cq15d7K5b/4wJ7wTuYDat2hdBA0wtI5zLifNZMS5DidqMyDiaGqryS3I X-Gm-Gg: ASbGncvK1XYNRwPdVI153kpK+nYCM6LG3aI2Jch6ynD+jZgChuzVYODSDJcgCUDftAN 8SzZHXlCzSDm4Kdtd8Le3OaBj6kxQGyvWBgOVv1JTka2pktYpzTh7s0jSe0Yfg8HJuvfiRO3nRv FL/AmrOuvYp8pb2N2rQFmpdaEeKSn6pk9bCnIRlzF1/Wa/imPYO2ofJwkziu/LmTJfdeC5NBUzU rv2z2yvCUFxrD1rV8H2wAI6pi7TfjgOCCRVMS/0ggXpi5Gzna32qKw70dzGpWUJnCgEOjmpZVTn UiOvCRF7YYSXK7nlRU76zObpSqCJUczFTEnlSf000hHsPg6lLQj+4wCBYIVVPJk2IlbIUWBAd68 Crm3rSj44tqn+Aek0JQ4ei1+s1Qmp5y6vcN5wTHsYLtF5WLnEBiSZ2iax1YYh X-Google-Smtp-Source: AGHT+IHyadE3jl5HQRtGbq1lFi6dmgfRxVUuU0Bz/rb8cf7dXnlVf2g0/qnidFpuclLnGJ7t8jfqHQ== X-Received: by 2002:a17:90b:52ce:b0:327:8c05:f8b6 with SMTP id 98e67ed59e1d1-328156df7b8mr20557946a91.28.1756947158160; Wed, 03 Sep 2025 17:52:38 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:882:283c:10f0:c999]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd28b3849sm15748931a12.31.2025.09.03.17.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 17:52:37 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Catalin Marinas , Will Deacon , Marc Zyngier Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Ryan Roberts , Baruch Siach , Kevin Brodsky , Joey Gouly , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH v2 3/3] arm64: mm: Represent physical memory with phys_addr_t and resource_size_t Date: Wed, 3 Sep 2025 17:52:09 -0700 Message-ID: <20250904005209.1494370-4-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250904005209.1494370-1-CFSworks@gmail.com> References: <20250904005209.1494370-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is a type-correctness cleanup to MMU/boot code that replaces several instances of void * and u64 with phys_addr_t (to represent addresses) and resource_size_t (to represent sizes) to emphasize that the code in question concerns physical memory specifically. The rationale for this change is to improve clarity and readability in a few modules that handle both types (physical and virtual) of address and differentiation is essential. I have left u64 in cases where the address may be either physical or virtual, where the address is exclusively virtual but used in heavy pointer arithmetic, and in cases I may have overlooked. I do not necessarily consider u64 the ideal type in those situations, but it avoids breaking existing semantics in this cleanup. This patch provably has no effect at runtime: I have verified that .text of vmlinux is identical after this change. Signed-off-by: Sam Edwards --- arch/arm64/kernel/pi/map_kernel.c | 26 +++++++++++++------------- arch/arm64/kernel/pi/map_range.c | 20 ++++++++++++-------- arch/arm64/kernel/pi/pi.h | 9 +++++---- arch/arm64/mm/init.c | 6 +++--- arch/arm64/mm/mmu.c | 17 +++++++++-------- 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_k= ernel.c index 5dc4107b5a7f..e6d35eff1486 100644 --- a/arch/arm64/kernel/pi/map_kernel.c +++ b/arch/arm64/kernel/pi/map_kernel.c @@ -18,9 +18,9 @@ =20 extern const u8 __eh_frame_start[], __eh_frame_end[]; =20 -extern void idmap_cpu_replace_ttbr1(void *pgdir); +extern void idmap_cpu_replace_ttbr1(phys_addr_t pgdir); =20 -static void __init map_segment(pgd_t *pg_dir, u64 *pgd, u64 va_offset, +static void __init map_segment(pgd_t *pg_dir, phys_addr_t *pgd, u64 va_off= set, void *start, void *end, pgprot_t prot, bool may_use_cont, int root_level) { @@ -40,7 +40,7 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_of= fset, int root_level) { bool enable_scs =3D IS_ENABLED(CONFIG_UNWIND_PATCH_PAC_INTO_SCS); bool twopass =3D IS_ENABLED(CONFIG_RELOCATABLE); - u64 pgdp =3D (u64)init_pg_dir + PAGE_SIZE; + phys_addr_t pgdp =3D (phys_addr_t)init_pg_dir + PAGE_SIZE; pgprot_t text_prot =3D PAGE_KERNEL_ROX; pgprot_t data_prot =3D PAGE_KERNEL; pgprot_t prot; @@ -90,7 +90,7 @@ static void __init map_kernel(u64 kaslr_offset, u64 va_of= fset, int root_level) true, root_level); dsb(ishst); =20 - idmap_cpu_replace_ttbr1(init_pg_dir); + idmap_cpu_replace_ttbr1((phys_addr_t)init_pg_dir); =20 if (twopass) { if (IS_ENABLED(CONFIG_RELOCATABLE)) @@ -129,10 +129,10 @@ static void __init map_kernel(u64 kaslr_offset, u64 v= a_offset, int root_level) /* Copy the root page table to its final location */ memcpy((void *)swapper_pg_dir + va_offset, init_pg_dir, PAGE_SIZE); dsb(ishst); - idmap_cpu_replace_ttbr1(swapper_pg_dir); + idmap_cpu_replace_ttbr1((phys_addr_t)swapper_pg_dir); } =20 -static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(u64 ttbr) +static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(phys_addr= _t ttbr) { u64 sctlr =3D read_sysreg(sctlr_el1); u64 tcr =3D read_sysreg(tcr_el1) | TCR_DS; @@ -172,7 +172,7 @@ static void __init remap_idmap_for_lpa2(void) */ create_init_idmap(init_pg_dir, mask); dsb(ishst); - set_ttbr0_for_lpa2((u64)init_pg_dir); + set_ttbr0_for_lpa2((phys_addr_t)init_pg_dir); =20 /* * Recreate the initial ID map with the same granularity as before. @@ -185,17 +185,17 @@ static void __init remap_idmap_for_lpa2(void) dsb(ishst); =20 /* switch back to the updated initial ID map */ - set_ttbr0_for_lpa2((u64)init_idmap_pg_dir); + set_ttbr0_for_lpa2((phys_addr_t)init_idmap_pg_dir); =20 /* wipe the temporary ID map from memory */ memset(init_pg_dir, 0, (char *)init_pg_end - (char *)init_pg_dir); } =20 -static void *__init map_fdt(u64 fdt) +static void *__init map_fdt(phys_addr_t fdt) { static u8 ptes[INIT_IDMAP_FDT_SIZE] __initdata __aligned(PAGE_SIZE); - u64 efdt =3D fdt + MAX_FDT_SIZE; - u64 ptep =3D (u64)ptes; + phys_addr_t efdt =3D fdt + MAX_FDT_SIZE; + phys_addr_t ptep =3D (phys_addr_t)ptes; /* We're idmapped when called */ =20 /* * Map up to MAX_FDT_SIZE bytes, but avoid overlap with @@ -232,7 +232,7 @@ static bool __init ng_mappings_allowed(void) return true; } =20 -asmlinkage void __init early_map_kernel(u64 boot_status, void *fdt) +asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt) { static char const chosen_str[] __initconst =3D "/chosen"; u64 va_base, pa_base =3D (u64)&_text; @@ -240,7 +240,7 @@ asmlinkage void __init early_map_kernel(u64 boot_status= , void *fdt) int root_level =3D 4 - CONFIG_PGTABLE_LEVELS; int va_bits =3D VA_BITS; int chosen; - void *fdt_mapped =3D map_fdt((u64)fdt); + void *fdt_mapped =3D map_fdt(fdt); =20 /* Clear BSS and the initial page tables */ memset(__bss_start, 0, (char *)init_pg_end - (char *)__bss_start); diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_ra= nge.c index 7982788e7b9a..de52cd85c691 100644 --- a/arch/arm64/kernel/pi/map_range.c +++ b/arch/arm64/kernel/pi/map_range.c @@ -26,8 +26,9 @@ * @va_offset: Offset between a physical page and its current mapping * in the VA space */ -void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot, - int level, pte_t *tbl, bool may_use_cont, u64 va_offset) +void __init map_range(phys_addr_t *pte, u64 start, u64 end, phys_addr_t pa, + pgprot_t prot, int level, pte_t *tbl, bool may_use_cont, + u64 va_offset) { u64 cmask =3D (level =3D=3D 3) ? CONT_PTE_SIZE - 1 : U64_MAX; ptdesc_t protval =3D pgprot_val(prot) & ~PTE_TYPE_MASK; @@ -87,19 +88,22 @@ void __init map_range(u64 *pte, u64 start, u64 end, u64= pa, pgprot_t prot, } } =20 -asmlinkage u64 __init create_init_idmap(pgd_t *pg_dir, ptdesc_t clrmask) +asmlinkage phys_addr_t __init create_init_idmap(pgd_t *pg_dir, ptdesc_t cl= rmask) { - u64 ptep =3D (u64)pg_dir + PAGE_SIZE; + phys_addr_t ptep =3D (phys_addr_t)pg_dir + PAGE_SIZE; /* MMU is off */ pgprot_t text_prot =3D PAGE_KERNEL_ROX; pgprot_t data_prot =3D PAGE_KERNEL; =20 pgprot_val(text_prot) &=3D ~clrmask; pgprot_val(data_prot) &=3D ~clrmask; =20 - map_range(&ptep, (u64)_stext, (u64)__initdata_begin, (u64)_stext, - text_prot, IDMAP_ROOT_LEVEL, (pte_t *)pg_dir, false, 0); - map_range(&ptep, (u64)__initdata_begin, (u64)_end, (u64)__initdata_begin, - data_prot, IDMAP_ROOT_LEVEL, (pte_t *)pg_dir, false, 0); + /* MMU is off; pointer casts to phys_addr_t are safe */ + map_range(&ptep, (u64)_stext, (u64)__initdata_begin, + (phys_addr_t)_stext, text_prot, IDMAP_ROOT_LEVEL, + (pte_t *)pg_dir, false, 0); + map_range(&ptep, (u64)__initdata_begin, (u64)_end, + (phys_addr_t)__initdata_begin, data_prot, IDMAP_ROOT_LEVEL, + (pte_t *)pg_dir, false, 0); =20 return ptep; } diff --git a/arch/arm64/kernel/pi/pi.h b/arch/arm64/kernel/pi/pi.h index 46cafee7829f..08ef9f80456b 100644 --- a/arch/arm64/kernel/pi/pi.h +++ b/arch/arm64/kernel/pi/pi.h @@ -29,9 +29,10 @@ u64 kaslr_early_init(void *fdt, int chosen); void relocate_kernel(u64 offset); int scs_patch(const u8 eh_frame[], int size); =20 -void map_range(u64 *pgd, u64 start, u64 end, u64 pa, pgprot_t prot, - int level, pte_t *tbl, bool may_use_cont, u64 va_offset); +void map_range(phys_addr_t *pte, u64 start, u64 end, phys_addr_t pa, + pgprot_t prot, int level, pte_t *tbl, bool may_use_cont, + u64 va_offset); =20 -asmlinkage void early_map_kernel(u64 boot_status, void *fdt); +asmlinkage void early_map_kernel(u64 boot_status, phys_addr_t fdt); =20 -asmlinkage u64 create_init_idmap(pgd_t *pgd, ptdesc_t clrmask); +asmlinkage phys_addr_t create_init_idmap(pgd_t *pgd, ptdesc_t clrmask); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index ea84a61ed508..70c2ca813c18 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -243,7 +243,7 @@ void __init arm64_memblock_init(void) */ if (memory_limit !=3D PHYS_ADDR_MAX) { memblock_mem_limit_remove_map(memory_limit); - memblock_add(__pa_symbol(_text), (u64)(_end - _text)); + memblock_add(__pa_symbol(_text), (resource_size_t)(_end - _text)); } =20 if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) { @@ -252,8 +252,8 @@ void __init arm64_memblock_init(void) * initrd to become inaccessible via the linear mapping. * Otherwise, this is a no-op */ - u64 base =3D phys_initrd_start & PAGE_MASK; - u64 size =3D PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base; + phys_addr_t base =3D phys_initrd_start & PAGE_MASK; + resource_size_t size =3D PAGE_ALIGN(phys_initrd_start + phys_initrd_size= ) - base; =20 /* * We can only add back the initrd memory if we don't end up diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 34e5d78af076..de463040582c 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -794,17 +794,18 @@ static void __init declare_kernel_vmas(void) declare_vma(&vmlinux_seg[4], _data, _end, 0); } =20 -void __pi_map_range(u64 *pgd, u64 start, u64 end, u64 pa, pgprot_t prot, - int level, pte_t *tbl, bool may_use_cont, u64 va_offset); +void __pi_map_range(phys_addr_t *pte, u64 start, u64 end, phys_addr_t pa, + pgprot_t prot, int level, pte_t *tbl, bool may_use_cont, + u64 va_offset); =20 static u8 idmap_ptes[IDMAP_LEVELS - 1][PAGE_SIZE] __aligned(PAGE_SIZE) __r= o_after_init, kpti_ptes[IDMAP_LEVELS - 1][PAGE_SIZE] __aligned(PAGE_SIZE) __ro_after_= init; =20 static void __init create_idmap(void) { - u64 start =3D __pa_symbol(__idmap_text_start); - u64 end =3D __pa_symbol(__idmap_text_end); - u64 ptep =3D __pa_symbol(idmap_ptes); + phys_addr_t start =3D __pa_symbol(__idmap_text_start); + phys_addr_t end =3D __pa_symbol(__idmap_text_end); + phys_addr_t ptep =3D __pa_symbol(idmap_ptes); =20 __pi_map_range(&ptep, start, end, start, PAGE_KERNEL_ROX, IDMAP_ROOT_LEVEL, (pte_t *)idmap_pg_dir, false, @@ -812,7 +813,7 @@ static void __init create_idmap(void) =20 if (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0) && !arm64_use_ng_mappings) { extern u32 __idmap_kpti_flag; - u64 pa =3D __pa_symbol(&__idmap_kpti_flag); + phys_addr_t pa =3D __pa_symbol(&__idmap_kpti_flag); =20 /* * The KPTI G-to-nG conversion code needs a read-write mapping @@ -1331,8 +1332,8 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsign= ed long start, u64 size) struct range arch_get_mappable_range(void) { struct range mhp_range; - u64 start_linear_pa =3D __pa(_PAGE_OFFSET(vabits_actual)); - u64 end_linear_pa =3D __pa(PAGE_END - 1); + phys_addr_t start_linear_pa =3D __pa(_PAGE_OFFSET(vabits_actual)); + phys_addr_t end_linear_pa =3D __pa(PAGE_END - 1); =20 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { /* --=20 2.49.1