From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796443613; b=exID4sPQOUekpMqY4sBTYPSBOALrt4wvUMhiLygMr3lJ87ruCT3iB4jigXvbDfSYiv9R OCnGBXTZ9lx+3CknPKVZ5AfB/H9uYzbtbxp0mK6S618oQFNLkMKXGcW06cRi3eFGdBlKT /MgD702SnBEx781sbyF/WvwPGdLt6bLf9yfb1IB2faeafYWjTB+Ya4Ii6OC0WfFbtLjax a5pUT/HNV3fD5fR8s60mOsdfIrbT+Pm9BiGbydRQpVGF+l7Isz7rU68v11DE7awlXDNWT RfPjhWCiSraC7mOE4t2zQIGYd/E2OuDh9ElMSsXXonmNVKWRnCi3Q39sFKNv7ntiCTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443613; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=pWvwEB7/4j6g6jHQVJzIuehGthaTqwlKZDMQWUCNPz4=; b=k4V4pK/RTjmAOOXZeEXsci/TZkrhiu3Bu58jlivnmK5LFzWhAfEYSOky/Wa3fq70WryP jCxkj9M60TowauvsZqF4N1rtqWqUiCFf2qWTxszdjMFm4ofwxEePTdGaa2lHt1rByAh+e 5/O3Fq6jDtpvACZDp7y4qhcc+vzfYp3Lk8HsYq++HDJSoX4zwGEWABdEkqmbiAYfs28vW RfM5DvNRO5Y8aBkiE8FvBdZopExLWMbx3jvhfwDY5VC13GD/YGAUEihUATDjrn1K26vfq tiLO5NKOCYOuM+U3Sqw5gdutmOaNxtSD0xBbz9cC/tBfU8bbR5NYP4NUNoUzU3H59sA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=gP6xd+3m; arc=none smtp.remote-ip=91.218.175.171 Received: from mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFE6E606A33F for ; Sat, 5 Dec 2026 04:06:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DFE6E606A33F 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=gP6xd+3m X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ZMMEf4YuR74i+ObrxBpWieBAJdPhJEETpD7gluptCc8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796443608; v=1; x=1797048408; b=gP6xd+3mjGLOh8peVMX1W7mqdgvQZQsHYr19SN5+qnzHl+PEXaeTNlsMpvvKjzvKUvb/QQOl 9s2wjkjSOtVQpZXMtybP3g1yhotAOYQCXtrQzeF3wp2JanBu2GbeszGUSycFiXfarXdUNDb+rTH Ne5umDlZb6+lF9drWrJfBtUg= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id e6d18f8230e7b0c4; Sat, 05 Dec 2026 04:06:48 +0000 X-Mizu-Trace-ID: e6d18f8230e7b0c4 X-Migadu-Flow: FLOW_OUT From: Lance Yang To: ziy@nvidia.com Cc: david@kernel.org, baolin.wang@linux.alibaba.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, riel@surriel.com, vbabka@kernel.org, harry@kernel.org, jannh@google.com, kylebot@openai.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, balbirs@nvidia.com, apopple@nvidia.com Subject: Re: [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry() Date: Sat, 5 Dec 2026 12:06:42 +0800 Message-ID: <20261205040642.59485-1-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20261203-anon_vma_uaf_fix-v2-1-3d4c746e8839@nvidia.com> References: <20261203-anon_vma_uaf_fix-v2-1-3d4c746e8839@nvidia.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Thu, Dec 03, 2026 at 11:17:49PM -0500, Zi Yan wrote: >A device private entry is never followed by GUP-fast, so there is no need >to clear the entry to avoid it. Furthermore, clearing the entry creates a >none PMD and a concurrent zap skips it. set_pmd_migration_entry() might not Nit: maybe "a concurrent zap or mremap" here :) >hold a VMA lock nor a mmap lock. As a result: > >1. When racing with munmap(), a "bad pmd" can appear, deposited page table > can be lost, and RSS stats can be off. >2. When racing with mremap(), the PMD is not moved, so the new address > faults and sees zeros instead of the original data. > >Fix it by not clearing device private entry. Right. Going straight to the migration entry without that none PMD in between: before: device-private PMD -> none PMD -> migration PMD after: device-private PMD -------------> migration PMD And, took a quick look at GUP-fast and folio_try_share_anon_rmap_pmd() too, and neither cares about keeping the entry around :D >Fixes: 65edfda6f3f2e ("mm/rmap: extend rmap and migration support device-private entries") >Cc: stable@vger.kernel.org >Signed-off-by: Zi Yan >To: David Hildenbrand >To: Zi Yan >To: Andrew Morton >Cc: Baolin Wang >Cc: "Liam R. Howlett" >Cc: Nico Pache >Cc: Ryan Roberts >Cc: Dev Jain >Cc: Barry Song >Cc: Lance Yang >Cc: Usama Arif >Cc: Kiryl Shutsemau >Cc: Balbir Singh >Cc: Alistair Popple >Cc: linux-mm@kvack.org >Cc: linux-kernel@vger.kernel.org >--- > mm/huge_memory.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > >diff --git a/mm/huge_memory.c b/mm/huge_memory.c >index 6305b4e2a6b68..91f3c7e7a044a 100644 >--- a/mm/huge_memory.c >+++ b/mm/huge_memory.c >@@ -5223,7 +5223,12 @@ int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw, > } else { > softleaf_t old_entry; > >- pmdval = pmdp_huge_get_and_clear(vma->vm_mm, address, pvmw->pmd); >+ /* >+ * The device private entry stays as is since GUP-fast >+ * never follows it and folio_try_share_anon_rmap_pmd() >+ * below never fails for it. >+ */ >+ pmdval = pmdp_get(pvmw->pmd); LGTM! Reviewed-by: Lance Yang