From nobody Sat Oct 4 00:26:58 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 E82952773FC for ; Fri, 22 Aug 2025 04:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836345; cv=none; b=YP0ePgknCeHR5iHWUTLPkRReG6p5FgCAcptmyO2C/Vg7HhLS4epqGkLMvS84UUZjtVH+SgO8a3O9MTueVJif/bkDevGtx7bbqqJynlDe8FQcRtkT6K877A+S5Er9cuQ0Irnjexed8Tg2G1MDNsPAvZeCkPdiNTqEsfPYNf+Hq20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836345; c=relaxed/simple; bh=GIZugSgwf/IBguNIs/OK7zQTIvb/FRn9sZYfy6LkexM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hwjRckUyPL/jpiPJgaqmfwbwZuhyU/FQODFa3uW/Bn98yWIw7h1EPu9GT255kox7Zc1i4ncEr8rYjInB1Cru0Pg4GG5YZv4HJcGtOR/92SWp9rVfbaj51QLFU7qObfCVQF3SKzNZmVROcjIhaogu4M4eeW9/9BW9Tb7/8tg2iIw= 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=IkdMWD3w; arc=none smtp.client-ip=209.85.214.180 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="IkdMWD3w" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-245f3784edcso16470555ad.1 for ; Thu, 21 Aug 2025 21:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755836343; x=1756441143; 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=IkdMWD3wfRgALWgAGQAIvEQ4DdBnkwpMjqB8fGVUqJRL7OTSRYkV+PbbxuSQShDhi2 YsqC4hbJ8VNdrH0UZOtTrwGY1CNtwBPYyfd1ZzloJp4s59A/p15jL0sNBw4th+x5OgUf QkwxYQl7Xn0KA3ITKPDZfZSHedMiQi5Ck2UfwwAuSA7PYYofLVE2ieTeBz8WE6+PeKmw gDs3jvk5FoVDqGDP48OSjaQ9IZFq+trQu2Kr28p08jNtuGeDAZ/6gVIWNmj3KACd1CHu O4YarMvY99sG52otCXVzsVhr3WB6ZOKXDb+j2MfhwxBpdJBj3hGeCzrdxTMZf8TcLcnV 9Maw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755836343; x=1756441143; 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=Nq+cxhcNM9LFzcSU6Q+fsgVL+5O2aI82MtmDfB4XqJyPn5cPOp0/o8sbVRqxIh5IAb aCipaMXgOBhQU/vosu/nJg1CTNfJVtEO/mW1PwfU8v0QBT22ps3kYJv9sZ0uNMEWAWWb Ky69y9VjZfnkAtZZHfdxMnBRg1STA3QsYuYW+5ZNPPDrMEoHAmg7LZBCzdz42hT4nDww WX4qgGT2f3Gg4HfkcjeutWNASJ7KGEmNwrjG4DYE5N+VwpHSOaexk829UdF8A/382/xM QfOzrvpd6TxxsZSJzlfO5qHXkPYZNb4J5T/wGB+dCdJscOOiI36IIPwnT2uc6smB0keh zKiw== X-Forwarded-Encrypted: i=1; AJvYcCUHQRD6+GqXDemggpdlkghqqfqkXIZJfDTnbwDaAZ4jjqsuyRyD/ejtSEv4fKCHPFWq0U6/JQnaqYTLnb0=@vger.kernel.org X-Gm-Message-State: AOJu0YwBuKhx6MskU5ImVtvpHmS2e+uSYbMbXbmhGCmIolSTz4hC8EQA QVEFwDqkA8h2ql2ILjEEHHb14zJsqSdoY/yiCzY4m8D1gWcaTrSav45n X-Gm-Gg: ASbGncuHeftSQYZlpOx4XlNvRqcJ+QO/D+X68sOUkOQhPX2v3M5a3W+nkmerXb2LI27 zCNjS+W5/rPAAeURFuKrDsLQcM2hWY4iN8btsAoagvQYITrBTCh/+BF3iH6EovsoZNOeFzm2JnK XFT00jCYR+ZW1h+1voK8VPtCGCoqzFx68VIqwjN0nRl2pm8UNtc4+b+N5LXFEeDhCgSH3snJgpU x1o8nXuaO+1i/nkESYjJIqSHa5tNcMua5OMd0t0dBTk1aNVhWjdimiRZQDGnlYdSOhGplYhZN9Q ReY5jiAKG1Y5H28GKyF2wiTKw4kTBohWsHgsL9+Xi7UmiDApuaqqt6TUXsW5lto8//uW2rhZ8FJ aqXQwqcX0O5NkQU2lSJZAWRJL/x/T9FtOOjsmQdMHZUoTRpgFYfYg9nn4SuNwUA== X-Google-Smtp-Source: AGHT+IHNKJplTG9Jy38Tlom7qmiWaoZeBRK6WRgraG0jbKbTwm9Axuv3DgJMIKeBlkJFFWOqnZNZLg== X-Received: by 2002:a17:902:db0c:b0:240:483:dc3a with SMTP id d9443c01a7336-2462edee860mr24421865ad.12.1755836343119; Thu, 21 Aug 2025 21:19:03 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:ba38:b533:dcf5:1e7a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e7d1375a3sm9534559b3a.43.2025.08.21.21.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 21:19:02 -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 1/3] arm64: mm: Cast start/end markers to char *, not u64 Date: Thu, 21 Aug 2025 21:15:36 -0700 Message-ID: <20250822041538.467514-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250822041538.467514-1-CFSworks@gmail.com> References: <20250822041538.467514-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 Sat Oct 4 00:26:58 2025 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 420EC2874FE for ; Fri, 22 Aug 2025 04:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836346; cv=none; b=ZZ9n2OeUCLz0xj0QR3au6DB1opeTgCfNIWHG+NBBhPna9bCoB9GCYpSXDi0RqcxzUtpuYATBP0XfpxPKsCb0V+9+KN/6O5o1xpEBPDrfBK9IQY7ObQYlqxwDRX4HOfVDRNjbweNDp5N7qGGdECTaiDhlOAFC0vjPk/8ulUA6YuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836346; c=relaxed/simple; bh=tWp6hE3wqtzBGGf1wcrFiqMq81hqBs2TkYqcSSLJN80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WGHAIU1QagqzydEYwglGrSZbmIfEGfw4/2CVSZEq/xc2tpRuytIBNs4XFw+Kwu3evLHYP3We4Mhe7Y5/RgOP2MtcFxrYjuDZAJZe7VqDUORSftPQ8C7jnBL3uTAsPX14LpjCHkgQMWrmQ9D4v4SV8XyuF+WMNh3cZ3HvwMY2EBQ= 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=DjOIaMxO; arc=none smtp.client-ip=209.85.210.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="DjOIaMxO" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-76e2e88c6a6so1565647b3a.1 for ; Thu, 21 Aug 2025 21:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755836344; x=1756441144; 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=DjOIaMxOH4BHCBdBEvugzvlJMn5H2hU0/wxXXklm6jaQFxYzGz+Nz1L5mT9MsbnGui YbymGtAJZZ3ZGbtRKu38ort+wryyq/Zhk8K4qzfbIxWtR3woQ+3haHGg0YstatgkTqlK whyrFAQR3TU9a6agWKrWUYyFk5ztMYEPwe/CNo4tQnkVW0g8L1gosErusrypIzz/9OVF EuZ2Y9Vz+4EPVtB2AuQUi0BTqXWMRTP0BQ6HEFb4ZrMmDML+wu1Xev5nOaZyIl9+80TU VzzCaSuCVTTQZpYMXLA7Un11f2tZHsUmIKRhlxoQtl20dGg/6ctR/IAw4NHpdcr+YTN6 GyEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755836344; x=1756441144; 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=SPB7hAbmucSTHnksETJ4grWhmMetlZZjFILvziAG3ngTyb5XFjrHOZ3Fmp8PPGuL6A jqN6GSX2w0uUw3Uvlg3ggnTP7oGapq2XbYILnbyMq4J7Gbmyc6bb5mNnsI9MMhnpD2B2 8SI//w9VcD4peLn9+VYFbecaBuWwKPFzj4bVMIwvOdeSR8rct/5CZVz3GxoF77Mdy4GX LH/i9waRrqz8v68xX6nx/ioK4pI+03seY2uJM7KGbcCyGX+no7T2SQR/fNJc10rObmB8 5TC0HByfP5UP+KfyTAsOryZ73C9jNk6buOEONSYBWW0domniylU6tQWYZKIDNpnAMHV9 PiJA== X-Forwarded-Encrypted: i=1; AJvYcCWbONh6W3UonJezYuY+4mww674b/xRcl4E8RsvICzQAxftYh8ldJukuzpUYp7Q6AhQyffPnxffLEFBn1wA=@vger.kernel.org X-Gm-Message-State: AOJu0YzdAKLNJtpkdTFtYC6RGvMY3v+9wvAMYxDaG3rpg6IzoEhbRyYa 73HB6ZVnVbaa+UBajtnVmHR29aK1giufBYBec2EHWtp+w+ZqKjmZncBv X-Gm-Gg: ASbGncs8HSIKqpQ5r1QeKXvaCUpaGipMc3A6ePZV6doMfkXxmD9l8UQpBdn74ZIB1sT 2Pn1MwgelhUTv6+YhTJENM0VR55ObmRXRrQBNICuYjF5ET1S9QkfIykRHGJj5zr6k5C/sE8JvhH mDvP+maboMWOn4OYeBDIWBGiF34fN4kGMLFQwTO5xv90rtrtV3tUuy0RsQ8DZtzWOMNt+UDKAtB KsSsHyPm1EkSY3JK7CY1kOoDwU1VhjtHoHzhmC//X29FLMahezqFoXeEl5CJAHQwkVr6XD3wSHQ O5syBQkxKfVThvFWUa/YJZzT8wknXcpZRkwb+vMQMUOmASUK+7HXtRzyCAIzAE9bXanfpx2Tden qASPZ8PjGOf4S14cD20mG19PkUQFUStz5tneiRN6NbBv/yt5eAKQo2MXjZ5SwKg== X-Google-Smtp-Source: AGHT+IEli5jcECjFb9Oq0WbfZLt07FMhg6/dC/kxKv6cWdo3v9Z2pQFAHs+/6NRV69eweeHR/lMWFg== X-Received: by 2002:a05:6a00:3c87:b0:76e:3a11:d23a with SMTP id d2e1a72fcca58-7702fa0f07dmr2276936b3a.4.1755836344270; Thu, 21 Aug 2025 21:19:04 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:ba38:b533:dcf5:1e7a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e7d1375a3sm9534559b3a.43.2025.08.21.21.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 21:19:03 -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 2/3] arm64: mm: Make map_fdt() return mapped pointer Date: Thu, 21 Aug 2025 21:15:37 -0700 Message-ID: <20250822041538.467514-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250822041538.467514-1-CFSworks@gmail.com> References: <20250822041538.467514-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 Sat Oct 4 00:26:58 2025 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 607EC28C878 for ; Fri, 22 Aug 2025 04:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836348; cv=none; b=k9VtCy88LCxmK8ZSRFSUl8bL9x3gwXF7yWmRylQr0gtnMIQC4O9NflDt6QTpVxl8NSA6pLIVYgLjyM83Fyu/Joly9Vd3ymNWFEl5mG6CJyXMSLaY9I3ORJ0O4q0MIUENxRlRgUqFhCEPX+ZGZggK1++V8tPpId0xR2kdeEHO79I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755836348; c=relaxed/simple; bh=57QzwA7Fd6AsftIWENPip3kRvCH+AoAdRE1Aa9JfmUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PA7RMps1wMhFsJGOVTXGekLMBG6d3FivCQcKlrebz0lqaynsuSb3L56XCbnqbqRx6eEuF/b8UHBkStw+Yg9+pNimkxlt0IQs8ZHw0BLHOnuyjejxZc3+jte3EguilJ+htjFsVKa5HhpLrkrUHLAin9fuY3i5zmHZa+hQ44DDp8o= 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=Jdl4CyyM; arc=none smtp.client-ip=209.85.216.42 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="Jdl4CyyM" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-32326e67c95so1922277a91.3 for ; Thu, 21 Aug 2025 21:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755836345; x=1756441145; 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=zcM18VY1tENoNDxX/DPNjvebKkwkKLOrpMH6jQw8TJM=; b=Jdl4CyyMFrwdduR987l4LAsmPgwBluPk69lRdX9e9djYpFBZYwu/YQCMLjyDY9duNh C8NPj3SFVBXc5n800Fkr2PQ4iTLSRWE9mkwIhYbUAnv/2DntLguC5/OKEw90QIcinK69 PWHr8Hs9jG5BAdGXxYAsKY5Z3OBVSGomB+L764dz17iaVGmNCsBSHIUouCbuqpbEvnmt fIeUHlpkXT6D32U6F4/dxcqHng6BXRHvjgosRGXHk1eC1Bb3pjLv0TRD5BWwGV/CC+gl brqFz9AugdDFsYixnuO92RnkeU9/EJCEzhH2fwQILnzAv+H4mKGnHs81VXvDc5jZMdBA tNOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755836345; x=1756441145; 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=zcM18VY1tENoNDxX/DPNjvebKkwkKLOrpMH6jQw8TJM=; b=adtM/Bg9d9cNZ3pI+/w4iNxJzHJ4/zBaEPn0G6bvFhDZXsvuZUP9tjMZYhJsGdTfn4 4lxvb0qraBcV5KRRQMuqKY6jCJDo0rJ8a9fFV7QdONE4v89RRWp2uduBKrHtflVFnJL7 q04tSwjWwgCjYoay/3IyZsPNJcf4lQs/6Byax1c2bZLFEnHoS5DsH+Fwm8nEUAVQsLrQ qhOY48uxrO9O3tZJv2zHnjUmXKuGguIOp4LBeScGa4OwSMtUuDKxjXsS/hEsDRUUspVt f71ShyWs7gNeHDx5QVuTlED3xIuwJcjzsc++8BTdsb6wSbSXxpI2yRC5qZOrs7tUHm/w Ek3Q== X-Forwarded-Encrypted: i=1; AJvYcCXvzaZR+e/3hdzni2wKeKGXdNQ9UHNSwB5X7slmD8EtFeO4/yhRKcL6knyYzPsSTAL/Oe4fxkuNBBpan/0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx55Rg4NPa7WmFfJytt3gIggOJQyyam4bsCFMNw7xSYnvSp+CQH UnrBBvMpNttee5VuaJE5LubKPJ0eVmtt+BcjRw0CUXaZrNbf7vZC2L0NHQxwWSBD49E= X-Gm-Gg: ASbGncsJi0Re4N6S8ekNVfH8s/tOE8lmP5aspV+fnKQF35Pns1tbUw+NtJXdAsd43Fg WgC6ZUh97OHrCVJ5CTfEN3kNdRu3ajBdgLdu7bsY6AD2s21etQZNzfr62sbDXo/dJUhhO/VM3ud SbA1BG5E28nSMmoVZytSyYittDJrToXTFg7/0a7ybHx0/leo86zjK3bycyaKVghcgygMM77F+wp bAsMz2oXoij2rDK6sXtx3cvAMn5oBXW4cvNSUThoGwRcqNlz4TVOM0KiN1ubonSMAAscem3C1Ga HUvrb9AhR03iz9ILlGfsWzmbsnz2hiNpKSgH4FXMLZsqscnRPR7WlsU7YYN8lmECsEKdywSweuw NQEbWqJEU80jcDu+XhZChIn6CN7/rjq4QhMBhkhL0fUqjsYITCII1d+VND4q1Fw== X-Google-Smtp-Source: AGHT+IHIfEZOEC0dksw3gI4Fl8FoMSKbicJ0AzsNuk/fKbqFNpOqq7Ob9OmAurZWLS5oTpjVRA2aEA== X-Received: by 2002:a17:90b:1d06:b0:321:2f06:d3ab with SMTP id 98e67ed59e1d1-32515eab619mr2529581a91.21.1755836345417; Thu, 21 Aug 2025 21:19:05 -0700 (PDT) Received: from luna.turtle.lan ([2601:1c2:c184:dc00:ba38:b533:dcf5:1e7a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e7d1375a3sm9534559b3a.43.2025.08.21.21.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Aug 2025 21:19:04 -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 3/3] arm64: mm: Represent physical memory with phys_addr_t and resource_size_t Date: Thu, 21 Aug 2025 21:15:38 -0700 Message-ID: <20250822041538.467514-4-CFSworks@gmail.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250822041538.467514-1-CFSworks@gmail.com> References: <20250822041538.467514-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..deb15074d289 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; /* Stack is idmapped */ =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