From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B3C23224B04; Fri, 10 Jul 2026 02:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783650717; cv=none; b=tyE272IAVJQgMgqOJ6ifXZagpWD1c+QKylhxZHekUOgmO0bV/2BXAfTYBQaEs4kkLOdVy/EZ0gK9nPf//xOI7Q2jDDs9TfUnmDQ5MvSRPpV7NHtaLmC1CEjt1EwrV92DdSeVPgVovToWX/H/06MKzaUrrYxCtT7DveYlUNiYyLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783650717; c=relaxed/simple; bh=OZl/pOxovyRa8FYhD4CGWyx4UocLjGqfpDIJbizbRwA=; h=Date:To:From:Subject:Message-Id; b=LTnTD/sWnUrYMqA1ga00sgQBNp44Nfzflz4LkupL+TkocUxUGlQiuWHPjQ3Wl5JZgPwl6RrTdsG+ohUaeGA63wdZYb1cP2sA/+8iJhZ2RPK2HqdCNNV9UyJyOt+4gcYf6IEO7ur5vElmBRZRvInr/CiazlqSxLwesCQnV3NnoFo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Yk2R5VlR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Yk2R5VlR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 328021F000E9; Fri, 10 Jul 2026 02:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783650715; bh=14ZvpJishve1TB2QfFEw/MzMNEN7+RrHDWhnVlZEg0s=; h=Date:To:From:Subject; b=Yk2R5VlRlfvRIqxuyQy+Y2vDzPoVYYNiGKEO49W4czZSjaxJmIvOiyHmSMaEuI7ja 0pKVWH1xF1G4JUQCMwqHHPongab3bwgSrRd41RX7BYCru+BXpDsuiJhC9QMDVWWvBM VWvovmey9tySV/Luw0TJi+OxF7rR2BOnZ312t0KU= Date: Thu, 09 Jul 2026 19:31:54 -0700 To: mm-commits@vger.kernel.org,ziy@nvidia.com,ying.huang@linux.alibaba.com,stable@vger.kernel.org,rakie.kim@sk.com,matthew.brost@intel.com,joshua.hahnjy@gmail.com,gourry@gourry.net,david@kernel.org,byungchul@sk.com,balbirs@nvidia.com,apopple@nvidia.com,wangkefeng.wang@huawei.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-migrate_device-fix-pte_pfn-pte_dirty-called-on-non-present-pte.patch added to mm-hotfixes-unstable branch Message-Id: <20260710023155.328021F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm: migrate_device: fix pte_pfn/pte_dirty called on non-present PTE has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-migrate_device-fix-pte_pfn-pte_dirty-called-on-non-present-pte.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-migrate_device-fix-pte_pfn-pte_dirty-called-on-non-present-pte.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Kefeng Wang Subject: mm: migrate_device: fix pte_pfn/pte_dirty called on non-present PTE Date: Mon, 6 Jul 2026 19:19:58 +0800 pte_pfn() and pte_dirty() have undefined behaviour when called on a non-present PTE. In migrate_vma_collect_pmd(), these functions may be invoked on non-present entries (e.g., device-private entries), leading to potential crashes from pte_pfn() or incorrect dirty folio accounting from pte_dirty(). Fix both by guarding with pte_present() checks. Link: https://lore.kernel.org/20260708003955.4024340-1-wangkefeng.wang@huawei.com Link: https://lore.kernel.org/20260706111958.3649651-1-wangkefeng.wang@huawei.com Fixes: fd35ca3d12cc ("mm/migrate_device.c: copy pte dirty bit to page") Fixes: 6c287605fd56 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Kefeng Wang Reviewed-by: Balbir Singh Acked-by: Zi Yan Cc: Alistair Popple Cc: Byungchul Park Cc: David Hildenbrand Cc: Gregory Price Cc: "Huang, Ying" Cc: Joshua Hahn Cc: Matthew Brost Cc: Rakie Kim Cc: Ying Huang Cc: Signed-off-by: Andrew Morton --- mm/migrate_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/migrate_device.c~mm-migrate_device-fix-pte_pfn-pte_dirty-called-on-non-present-pte +++ a/mm/migrate_device.c @@ -401,7 +401,8 @@ again: bool anon_exclusive; pte_t swp_pte; - flush_cache_page(vma, addr, pte_pfn(pte)); + if (pte_present(pte)) + flush_cache_page(vma, addr, pte_pfn(pte)); anon_exclusive = folio_test_anon(folio) && PageAnonExclusive(page); if (anon_exclusive) { @@ -422,7 +423,7 @@ again: migrate->cpages++; /* Set the dirty flag on the folio now the pte is gone. */ - if (pte_dirty(pte)) + if (pte_present(pte) && pte_dirty(pte)) folio_mark_dirty(folio); /* Setup special migration page table entry */ _ Patches currently in -mm which might be from wangkefeng.wang@huawei.com are mm-migrate_device-fix-pte_pfn-pte_dirty-called-on-non-present-pte.patch mm-remove-pagetranscompound.patch mm-mincore-use-walk_page_range_vma-in-do_mincore.patch mm-mprotect-use-walk_page_range_vma-in-mprotect_fixup.patch mm-mlock-use-walk_page_range_vma-in-mlock_vma_pages_range.patch mm-migrate_device-use-walk_page_range_vma-in-migrate_vma_collect.patch