>From a547687db03ecfe13ddc74e452357df78f880255 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Fri, 1 Aug 2025 09:17:04 -0400 Subject: [PATCH 2/2] LoongArch: fix kmap_local_page() LIFO ordering in copy_user_highpage() The current implementation violates kmap_local_page()'s LIFO ordering requirement by unmapping the pages in the same order they were mapped. This was introduced by commit 477a0ebec101 ("LoongArch: Replace kmap_atomic() with kmap_local_page() in copy_user_highpage()") when converting from kmap_atomic() to kmap_local_page(). The original code correctly unmapped in reverse order, but the conversion swapped the mapping order while keeping the unmapping order unchanged, resulting in a LIFO violation. kmap_local_page() requires unmapping to be done in reverse order (Last-In-First-Out). Currently we map vfrom and then vto, but unmap vfrom and then vto, which is incorrect. This patch corrects it to unmap vto first, then vfrom. This issue was detected by the kmap_local_lifo.cocci semantic patch. Fixes: 477a0ebec101 ("LoongArch: Replace kmap_atomic() with kmap_local_page() in copy_user_highpage()") Co-developed-by: Claude claude-opus-4-20250514 Signed-off-by: Sasha Levin --- arch/loongarch/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c index c3e4586a7975..01c43f455486 100644 --- a/arch/loongarch/mm/init.c +++ b/arch/loongarch/mm/init.c @@ -47,8 +47,8 @@ void copy_user_highpage(struct page *to, struct page *from, vfrom = kmap_local_page(from); vto = kmap_local_page(to); copy_page(vto, vfrom); - kunmap_local(vfrom); kunmap_local(vto); + kunmap_local(vfrom); /* Make sure this page is cleared on other CPU's too before using it */ smp_wmb(); } -- 2.39.5