From nobody Mon Feb 9 11:50:57 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (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 636B81F239B for ; Fri, 6 Feb 2026 07:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770362582; cv=none; b=V8w1Pzoj/ql1HH9+OSLhHFR+L7LmYYKkjN2hWhHV25MOWZ9/XMSAGV7Bw7jszR+XSoDFF9XwtStzxzxPukROStYb+I1Uf7oZ1idxLOWRVfbkWCY3NUCcJAMyK8wqPwx7KXKi6AvES6hUKLeDDjBeXeNXm4hNHaTKl0d3Z366hPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770362582; c=relaxed/simple; bh=o8Hy5LVShC3X872LUnf9vLO+tEVKtyn1Lvy19BOFUEI=; h=Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type; b=ZBY5iKpkXNzk6BXO7+dBmYYksqW37ojiLAJkTQk2DLzMzjfryD8dLHkP0XVHjGM+I6GI7oSnyldfba7X4AI+d8m/Dr6BjkRdbtR/PKwTFstIbQxzO/NQ0Z/mz2Xj590A7+6Gu4vxRnOxjCUUZCf//2P4xci2bzypRum3bGGzxGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4f6ltD52f3z8Xs76; Fri, 06 Feb 2026 15:23:00 +0800 (CST) Received: from xaxapp05.zte.com.cn ([10.99.98.109]) by mse-fl2.zte.com.cn with SMTP id 6167MqV2092085; Fri, 6 Feb 2026 15:22:53 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp01[null]) by mapi (Zmail) with MAPI id mid32; Fri, 6 Feb 2026 15:22:54 +0800 (CST) X-Zmail-TransId: 2af9698596ce468-f88b6 X-Mailer: Zmail v1.0 Message-ID: <202602061522548871ohgXN8z0qq87sTSX-yZc@zte.com.cn> Date: Fri, 6 Feb 2026 15:22:54 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , Cc: , , , , , Subject: =?UTF-8?B?a3NtOiBpbml0aWFsaXplIHJtYXAgdmFsdWVzIGRpcmVjdGx5IGFuZCBtYWtlIHRoZW0gY29uc3Q=?= X-MAIL: mse-fl2.zte.com.cn 6167MqV2092085 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.133 unknown Fri, 06 Feb 2026 15:23:00 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 698596D4.002/4f6ltD52f3z8Xs76 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: xu xin Considering that commit 06fbd555dea8 ("ksm: optimize rmap_walk_ksm by passi= ng a suitable addressrange") seems to have already been merged, this new patch= is proposed to address the issue raised by David at: https://lore.kernel.org/all/ba03780a-fd65-4a03-97de-bc0905106260@kernel.org/ This initialize rmap values (addr, pgoff_start, pgoff_end) directly and make them const to make code more robust. Besides, since KSM folios are alw= ays order-0, so folio_nr_pages(KSM folio) is always 1, so the line: "pgoff_end =3D pgoff_start + folio_nr_pages(folio) - 1;" becomes directly: "pgoff_end =3D pgoff_start;" The test reproducer of rmap_walk_ksm can be found at: https://lore.kernel.org/all/20260206151424734QIyWL_pA-1QeJPbJlUxsO@zte.com.= cn/ Fixes: 06fbd555dea8 ("ksm: optimize rmap_walk_ksm by passing a suitable add= ressrange") Signed-off-by: xu xin --- mm/ksm.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 031c17e4ada6..c7ca117024a4 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3171,8 +3171,11 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_= walk_control *rwc) struct anon_vma *anon_vma =3D rmap_item->anon_vma; struct anon_vma_chain *vmac; struct vm_area_struct *vma; - unsigned long addr; - pgoff_t pgoff_start, pgoff_end; + /* Ignore the stable/unstable/sqnr flags */ + const unsigned long addr =3D rmap_item->address & PAGE_MASK; + const pgoff_t pgoff_start =3D rmap_item->address >> PAGE_SHIFT; + /* KSM folios are always order-0 normal pages */ + const pgoff_t pgoff_end =3D pgoff_start; cond_resched(); if (!anon_vma_trylock_read(anon_vma)) { @@ -3183,12 +3186,6 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_= walk_control *rwc) anon_vma_lock_read(anon_vma); } - /* Ignore the stable/unstable/sqnr flags */ - addr =3D rmap_item->address & PAGE_MASK; - - pgoff_start =3D rmap_item->address >> PAGE_SHIFT; - pgoff_end =3D pgoff_start + folio_nr_pages(folio) - 1; - anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root, pgoff_start, pgoff_end) { --=20 2.25.1