From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796443614; b=x10POPvm530lHwLwirct1dO+7PmxOrD9Gvx0QRjDkJMj0QY8RnDWFpowMX03bfxDXbEP PynkSexAPmHH7BacpUwLStRkI0MfplYbYK107VFIevtIqc3oX+LU1WiBSh2JkEaLYU7KH etCllVKRSoCEw8SlMzGnuwOpOciLMFd1RhIhk/5v8ywdwRCNN2fRu+MSHUtPB30gQvKOy AK8QgqSGUWSLPJbaAB4ySq48QtlNlDI7wBDtAV3w8YWG/6rnd8r+xSVX7yeZAqb2mXrfZ MU3h49biZGw86z7xdOA9ey0OfED/70SXAwPIEixkMF5TFeOiyznfJrwkT9Djkptlwyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443614; 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=DbJJ8xRy1QSoEL8OCwikSQ8joUdXMfvVNbnYUoA3bwoogPCRsf9xhXTeHUDE+vAh3icQ Z5nMm3W32+O4oYrTDxJcw2GV5fWqOM310IbQRIE4Mrwr7hXiPVXXywATyScpwtRwh1WpS n4D/5KnM5wrxfGc8ibZxkhcicqfAVG1pJZihAyglrCL74GnTcveUXStiIXXTWb5oXF/YP NcTVfjysewTVOyUBbNOvfeIsYVk4wxzMZuZps7l4LK6bR3ZpRz3eeE72nWeiInyj6dWze G6okcbrOYxgl3pxeQcdCvecnFWf7AKbC9GymqJwH/gyEMif0Gf0l+BJ7c/AhrZsiBmA== 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=95.215.58.113 Received: from mta1.migadu.com (out-113.mta1.migadu.com [95.215.58.113]) (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 E0567606A682 for ; Sat, 5 Dec 2026 04:06:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E0567606A682 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: stable@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: stable@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: stable@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