All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Harith George <harith.g@alifsemi.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6 26/82] ARM: 9419/1: mm: Fix kernel memory mapping for xip kernels
Date: Wed, 20 Nov 2024 13:56:36 +0100	[thread overview]
Message-ID: <20241120125630.199562959@linuxfoundation.org> (raw)
In-Reply-To: <20241120125629.623666563@linuxfoundation.org>

6.6-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Harith G <harith.g@alifsemi.com>

[ Upstream commit ed6cbe6e5563452f305e89c15846820f2874e431 ]

The patchset introducing kernel_sec_start/end variables to separate the
kernel/lowmem memory mappings, broke the mapping of the kernel memory
for xipkernels.

kernel_sec_start/end variables are in RO area before the MMU is switched
on for xipkernels.
So these cannot be set early in boot in head.S. Fix this by setting these
after MMU is switched on.
xipkernels need two different mappings for kernel text (starting at
CONFIG_XIP_PHYS_ADDR) and data (starting at CONFIG_PHYS_OFFSET).
Also, move the kernel code mapping from devicemaps_init() to map_kernel().

Fixes: a91da5457085 ("ARM: 9089/1: Define kernel physical section start and end")
Signed-off-by: Harith George <harith.g@alifsemi.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/arm/kernel/head.S |  8 ++++++--
 arch/arm/mm/mmu.c      | 34 +++++++++++++++++++++-------------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 1ec35f065617e..28873cda464f5 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -252,11 +252,15 @@ __create_page_tables:
 	 */
 	add	r0, r4, #KERNEL_OFFSET >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
 	ldr	r6, =(_end - 1)
+
+	/* For XIP, kernel_sec_start/kernel_sec_end are currently in RO memory */
+#ifndef CONFIG_XIP_KERNEL
 	adr_l	r5, kernel_sec_start		@ _pa(kernel_sec_start)
 #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
 	str	r8, [r5, #4]			@ Save physical start of kernel (BE)
 #else
 	str	r8, [r5]			@ Save physical start of kernel (LE)
+#endif
 #endif
 	orr	r3, r8, r7			@ Add the MMU flags
 	add	r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
@@ -264,6 +268,7 @@ __create_page_tables:
 	add	r3, r3, #1 << SECTION_SHIFT
 	cmp	r0, r6
 	bls	1b
+#ifndef CONFIG_XIP_KERNEL
 	eor	r3, r3, r7			@ Remove the MMU flags
 	adr_l	r5, kernel_sec_end		@ _pa(kernel_sec_end)
 #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
@@ -271,8 +276,7 @@ __create_page_tables:
 #else
 	str	r3, [r5]			@ Save physical end of kernel (LE)
 #endif
-
-#ifdef CONFIG_XIP_KERNEL
+#else
 	/*
 	 * Map the kernel image separately as it is not located in RAM.
 	 */
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 674ed71573a84..073de5b24560d 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1402,18 +1402,6 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
 		create_mapping(&map);
 	}
 
-	/*
-	 * Map the kernel if it is XIP.
-	 * It is always first in the modulearea.
-	 */
-#ifdef CONFIG_XIP_KERNEL
-	map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
-	map.virtual = MODULES_VADDR;
-	map.length = ((unsigned long)_exiprom - map.virtual + ~SECTION_MASK) & SECTION_MASK;
-	map.type = MT_ROM;
-	create_mapping(&map);
-#endif
-
 	/*
 	 * Map the cache flushing regions.
 	 */
@@ -1603,12 +1591,27 @@ static void __init map_kernel(void)
 	 * This will only persist until we turn on proper memory management later on
 	 * and we remap the whole kernel with page granularity.
 	 */
+#ifdef CONFIG_XIP_KERNEL
+	phys_addr_t kernel_nx_start = kernel_sec_start;
+#else
 	phys_addr_t kernel_x_start = kernel_sec_start;
 	phys_addr_t kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
 	phys_addr_t kernel_nx_start = kernel_x_end;
+#endif
 	phys_addr_t kernel_nx_end = kernel_sec_end;
 	struct map_desc map;
 
+	/*
+	 * Map the kernel if it is XIP.
+	 * It is always first in the modulearea.
+	 */
+#ifdef CONFIG_XIP_KERNEL
+	map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
+	map.virtual = MODULES_VADDR;
+	map.length = ((unsigned long)_exiprom - map.virtual + ~SECTION_MASK) & SECTION_MASK;
+	map.type = MT_ROM;
+	create_mapping(&map);
+#else
 	map.pfn = __phys_to_pfn(kernel_x_start);
 	map.virtual = __phys_to_virt(kernel_x_start);
 	map.length = kernel_x_end - kernel_x_start;
@@ -1618,7 +1621,7 @@ static void __init map_kernel(void)
 	/* If the nx part is small it may end up covered by the tail of the RWX section */
 	if (kernel_x_end == kernel_nx_end)
 		return;
-
+#endif
 	map.pfn = __phys_to_pfn(kernel_nx_start);
 	map.virtual = __phys_to_virt(kernel_nx_start);
 	map.length = kernel_nx_end - kernel_nx_start;
@@ -1763,6 +1766,11 @@ void __init paging_init(const struct machine_desc *mdesc)
 {
 	void *zero_page;
 
+#ifdef CONFIG_XIP_KERNEL
+	/* Store the kernel RW RAM region start/end in these variables */
+	kernel_sec_start = CONFIG_PHYS_OFFSET & SECTION_MASK;
+	kernel_sec_end = round_up(__pa(_end), SECTION_SIZE);
+#endif
 	pr_debug("physical kernel sections: 0x%08llx-0x%08llx\n",
 		 kernel_sec_start, kernel_sec_end);
 
-- 
2.43.0




  parent reply	other threads:[~2024-11-20 12:59 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 12:56 [PATCH 6.6 00/82] 6.6.63-rc1 review Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 01/82] netlink: terminate outstanding dump on socket close Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 02/82] sctp: fix possible UAF in sctp_v6_available() Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 03/82] net: vertexcom: mse102x: Fix tx_bytes calculation Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 04/82] drm/rockchip: vop: Fix a dereferenced before check warning Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 05/82] mptcp: error out earlier on disconnect Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 06/82] mptcp: cope racing subflow creation in mptcp_rcv_space_adjust Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 07/82] net/mlx5: fs, lock FTE when checking if active Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 08/82] net/mlx5e: kTLS, Fix incorrect page refcounting Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 09/82] net/mlx5e: clear xdp features on non-uplink representors Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 10/82] net/mlx5e: CT: Fix null-ptr-deref in add rule err flow Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 11/82] virtio/vsock: Fix accept_queue memory leak Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 12/82] Revert "RDMA/core: Fix ENODEV error for iWARP test over vlan" Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 13/82] Bluetooth: hci_core: Fix calling mgmt_device_connected Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 14/82] Bluetooth: btintel: Direct exception event to bluetooth stack Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 15/82] net/sched: cls_u32: replace int refcounts with proper refcounts Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 16/82] net: sched: cls_u32: Fix u32s systematic failure to free IDR entries for hnodes Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 17/82] samples: pktgen: correct dev to DEV Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 18/82] net: stmmac: dwmac-mediatek: Fix inverted handling of mediatek,mac-wol Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 19/82] net: Make copy_safe_from_sockptr() match documentation Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 20/82] net: stmmac: dwmac-intel-plat: use devm_stmmac_probe_config_dt() Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 21/82] net: stmmac: dwmac-visconti: " Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 22/82] net: stmmac: rename stmmac_pltfr_remove_no_dt to stmmac_pltfr_remove Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 23/82] stmmac: dwmac-intel-plat: fix call balance of tx_clk handling routines Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 24/82] net: ti: icssg-prueth: Fix 1 PPS sync Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 25/82] bonding: add ns target multicast address to slave device Greg Kroah-Hartman
2024-11-20 12:56 ` Greg Kroah-Hartman [this message]
2024-11-20 12:56 ` [PATCH 6.6 27/82] tools/mm: fix compile error Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 28/82] x86/mm: Fix a kdump kernel failure on SME system when CONFIG_IMA_KEXEC=y Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 29/82] mm: fix NULL pointer dereference in alloc_pages_bulk_noprof Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 30/82] ocfs2: uncache inode which has failed entering the group Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 31/82] mm: revert "mm: shmem: fix data-race in shmem_getattr()" Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 32/82] vdpa: solidrun: Fix UB bug with devres Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 33/82] vdpa/mlx5: Fix PA offset with unaligned starting iotlb map Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 34/82] vp_vdpa: fix id_table array not null terminated error Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 35/82] ima: fix buffer overrun in ima_eventdigest_init_common Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 36/82] KVM: nVMX: Treat vpid01 as current if L2 is active, but with VPID disabled Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 37/82] KVM: x86: Unconditionally set irr_pending when updating APICv state Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 38/82] KVM: VMX: Bury Intel PT virtualization (guest/host mode) behind CONFIG_BROKEN Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 39/82] nilfs2: fix null-ptr-deref in block_touch_buffer tracepoint Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 40/82] nommu: pass NULL argument to vma_iter_prealloc() Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 41/82] ALSA: hda/realtek - Fixed Clevo platform headset Mic issue Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 42/82] ALSA: hda/realtek: fix mute/micmute LEDs for a HP EliteBook 645 G10 Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 43/82] ocfs2: fix UBSAN warning in ocfs2_verify_volume() Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 44/82] nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 45/82] LoongArch: Fix early_numa_add_cpu() usage for FDT systems Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 46/82] LoongArch: Disable KASAN if PGDIR_SIZE is too large for cpu_vabits Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 47/82] LoongArch: Make KASAN work with 5-level page-tables Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 48/82] Revert "mmc: dw_mmc: Fix IDMAC operation with pages bigger than 4K" Greg Kroah-Hartman
2024-11-20 12:56 ` [PATCH 6.6 49/82] mmc: sunxi-mmc: Fix A100 compatible description Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 50/82] drm/bridge: tc358768: Fix DSI command tx Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 51/82] pmdomain: imx93-blk-ctrl: correct remove path Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 52/82] nouveau: fw: sync dma after setup is called Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 53/82] drm/amd: Fix initialization mistake for NBIO 7.7.0 Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 54/82] drm/amd/display: Adjust VSDB parser for replay feature Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 55/82] mm/damon/core: implement scheme-specific apply interval Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 56/82] mm/damon/core: handle zero {aggregation,ops_update} intervals Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 57/82] staging: vchiq_arm: Get the rid off struct vchiq_2835_state Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 58/82] staging: vchiq_arm: Use devm_kzalloc() for vchiq_arm_state allocation Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 59/82] lib/buildid: Fix build ID parsing logic Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 60/82] media: dvbdev: fix the logic when DVB_DYNAMIC_MINORS is not set Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 61/82] NFSD: initialize copy->cp_clp early in nfsd4_copy for use by trace point Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 62/82] NFSD: Async COPY result needs to return a write verifier Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 63/82] NFSD: Limit the number of concurrent async COPY operations Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 64/82] NFSD: Initialize struct nfsd4_copy earlier Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 65/82] NFSD: Never decrement pending_async_copies on error Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 66/82] mptcp: define more local variables sk Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 67/82] mptcp: add userspace_pm_lookup_addr_by_id helper Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 68/82] mptcp: update local address flags when setting it Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 69/82] mptcp: hold pm lock when deleting entry Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 70/82] mptcp: drop lookup_by_id in lookup_addr Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 71/82] mptcp: pm: use _rcu variant under rcu_read_lock Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 72/82] drm/amd/pm: Vangogh: Fix kernel memory out of bounds write Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 73/82] fs/9p: fix uninitialized values during inode evict Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 74/82] leds: mlxreg: Use devm_mutex_init() for mutex initialization Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 75/82] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 76/82] mm: unconditionally close VMAs on error Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 77/82] mm: refactor map_deny_write_exec() Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 78/82] mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 79/82] mm: resolve faulty mmap_region() error path behaviour Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 80/82] mm/damon/core: check apply interval in damon_do_apply_schemes() Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 81/82] mm/damon/core: handle zero schemes apply interval Greg Kroah-Hartman
2024-11-20 12:57 ` [PATCH 6.6 82/82] mm/damon/core: copy nr_accesses when splitting region Greg Kroah-Hartman
2024-11-20 16:44 ` [PATCH 6.6 00/82] 6.6.63-rc1 review Mark Brown
2024-11-20 17:02 ` SeongJae Park
2024-11-20 19:05 ` Florian Fainelli
2024-11-20 23:20 ` Shuah Khan
2024-11-21  4:20 ` Ron Economos
2024-11-21  7:37 ` Naresh Kamboju
2024-11-21 16:57 ` Hardik Garg
2024-11-21 19:39 ` Jon Hunter
2024-11-22  6:55 ` Muhammad Usama Anjum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241120125630.199562959@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=harith.g@alifsemi.com \
    --cc=linus.walleij@linaro.org \
    --cc=patches@lists.linux.dev \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.