From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 C2B7F32BF58 for ; Mon, 22 Dec 2025 08:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766391818; cv=none; b=UDpnUDXpAO/JZy2BI9DOnyAlR7krI8yRTNqEXm546m6ch742i3DEwAU0gCYWzPlCOjrpS9xINtGx+mts7klvC4QSFtkyQ2eoa8E5JWKVPLH7+fVpliXJsjyQ14FukVuJaKKvBmv/Ze7ooBWpWZrKY3yYoI12ivN4DUlCddHrPJM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766391818; c=relaxed/simple; bh=fgSAPEHYxUdpoIpEGwcx+PRwjjvvQsol1vz88/CwPqQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cfk8mhB2VWCEFfYke9Qyg0SFl/4DeldmobDTtwXOVSB/eaoFcITv/eZ9MTQGYjO76JVqwP8ttLg2Sp/2O4qJQ4aMybE9qgo8x8wKW2Jhw1v8ocgvjZ9fXxTQ4pSHGC7fbL5JHuGq8BJRqBKPRkNDAbe0TXAvwXyGBEssMuek3mE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=faTvPAjT; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="faTvPAjT" Message-ID: <30e2087c-3bca-479c-9974-0681f0187cc2@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766391809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/c4zkGZ1j4uSjI4uDlaD2/g71zW9hroM6yOlK7PiRhQ=; b=faTvPAjTgnwnLkY+Lt1BQpsfXjUFyjt3PN87D3Dpx8fZWg7SfU/LFXh137t49CPRsKUJ2P lwBfiGbdDdj7FYmepEitJrEzp/DHGaOEIXSNb2yVDwRB8GUdXJ6c9swqV6GW5Rx0uQkyE6 yD4YJPRBuk0lEDeY0oBtLAZvArYtmRU= Date: Mon, 22 Dec 2025 16:23:13 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/ksm: fix pte_unmap_unlock of wrong address in break_ksm_pmd_entry To: Sasha Levin , akpm@linux-foundation.org, david@kernel.org Cc: xu.xin16@zte.com.cn, pedrodemargomes@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20251220202926.318366-1-sashal@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20251220202926.318366-1-sashal@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2025/12/21 04:29, Sasha Levin wrote: > On ARM32 with HIGHMEM/HIGHPTE, break_ksm_pmd_entry() triggers a BUG > during KSM unmerging because pte_unmap_unlock() is passed a pointer > that may be beyond the mapped PTE page. > > The issue occurs when the PTE iteration loop completes without finding > a KSM page. After the loop, 'ptep' has been incremented past the last > PTE entry. On ARM32 LPAE with 512 PTEs per page (512 * 8 = 4096 bytes), > this means ptep points to the next page, outside the kmap'd region. > > When pte_unmap_unlock(ptep, ptl) calls kunmap_local(ptep), it unmaps > the wrong page address, leaving the original kmap slot still mapped. > The next kmap_local then finds this slot unexpectedly occupied: > > WARNING: mm/highmem.c:622 kunmap_local_indexed (address mismatch) > kernel BUG at mm/highmem.c:564 __kmap_local_pfn_prot (slot not empty) > > Fix this by passing start_ptep to pte_unmap_unlock(), which always > points within the originally mapped PTE page. > > Reproducer: Run LTP ksm03 test on ARM32 with HIGHMEM enabled. The test > triggers KSM merging followed by unmerging (writing 0 then 2 to > /sys/kernel/mm/ksm/run), which exercises break_ksm_pmd_entry(). > > Fixes: 5d4939fc2258 ("ksm: perform a range-walk in break_ksm") > Assisted-by: claude-opus-4-5-20251101 > Signed-off-by: Sasha Levin Reviewed-by: Chengming Zhou Thanks. > --- > mm/ksm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index cfc182255c7b..2d89a7c8b4eb 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -650,7 +650,7 @@ static int break_ksm_pmd_entry(pmd_t *pmdp, unsigned long addr, unsigned long en > } > } > out_unlock: > - pte_unmap_unlock(ptep, ptl); > + pte_unmap_unlock(start_ptep, ptl); > return found; > } >