All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/migrate_device: fix double unlock and remove dead code
@ 2026-04-13 13:09 Sunny Patel
  2026-04-13 19:38 ` David Hildenbrand (Arm)
  2026-04-13 23:30 ` Matthew Brost
  0 siblings, 2 replies; 9+ messages in thread
From: Sunny Patel @ 2026-04-13 13:09 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Zi Yan, Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park,
	Gregory Price, Ying Huang, Alistair Popple, linux-mm,
	linux-kernel, Sunny Patel

Fix two bugs in device migration paths:

1) migrate_vma_collect_huge_pmd() calls spin_unlock after
   softleaf_entry_wait_on_locked(), which already releases the ptl.

2) migrate_vma_insert_huge_pmd_page() has a dead else-if branch and this
   branch is always unreachable.

Signed-off-by: Sunny Patel <nueralspacetech@gmail.com>
---
 mm/migrate_device.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 8079676c8f1f..0e005c26ee88 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -177,7 +177,6 @@ static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,
 
 		if (softleaf_is_migration(entry)) {
 			softleaf_entry_wait_on_locked(entry, ptl);
-			spin_unlock(ptl);
 			return -EAGAIN;
 		}
 
@@ -869,8 +868,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
 		if (!is_huge_zero_pmd(*pmdp))
 			goto unlock_abort;
 		flush = true;
-	} else if (!pmd_none(*pmdp))
-		goto unlock_abort;
+	}
 
 	add_mm_counter(vma->vm_mm, MM_ANONPAGES, HPAGE_PMD_NR);
 	folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Re: [PATCH] mm/migrate_device: fix double unlock and remove dead code
@ 2026-04-14 19:53 kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2026-04-14 19:53 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260413130927.13263-1-nueralspacetech@gmail.com>
References: <20260413130927.13263-1-nueralspacetech@gmail.com>
TO: Sunny Patel <nueralspacetech@gmail.com>
TO: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
TO: David Hildenbrand <david@kernel.org>
CC: Zi Yan <ziy@nvidia.com>
CC: Matthew Brost <matthew.brost@intel.com>
CC: Joshua Hahn <joshua.hahnjy@gmail.com>
CC: Rakie Kim <rakie.kim@sk.com>
CC: Byungchul Park <byungchul@sk.com>
CC: Gregory Price <gourry@gourry.net>
CC: Ying Huang <ying.huang@linux.alibaba.com>
CC: Alistair Popple <apopple@nvidia.com>
CC: linux-kernel@vger.kernel.org
CC: Sunny Patel <nueralspacetech@gmail.com>

Hi Sunny,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Sunny-Patel/mm-migrate_device-fix-double-unlock-and-remove-dead-code/20260414-011221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20260413130927.13263-1-nueralspacetech%40gmail.com
patch subject: [PATCH] mm/migrate_device: fix double unlock and remove dead code
:::::: branch date: 27 hours ago
:::::: commit date: 27 hours ago
config: x86_64-randconfig-161-20260414 (https://download.01.org/0day-ci/archive/20260415/202604150314.JzBIroDK-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
smatch: v0.5.0-9007-gcf3ea02b

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202604150314.JzBIroDK-lkp@intel.com/

smatch warnings:
mm/migrate_device.c:243 migrate_vma_collect_huge_pmd() warn: inconsistent returns 'ptl'.

vim +/ptl +243 mm/migrate_device.c

022a12deda53c98 Balbir Singh            2025-10-01  123  
a30b48bf1b244f1 Balbir Singh            2025-10-01  124  /** migrate_vma_collect_huge_pmd - collect THP pages without splitting the
a30b48bf1b244f1 Balbir Singh            2025-10-01  125   * folio for device private pages.
a30b48bf1b244f1 Balbir Singh            2025-10-01  126   * @pmdp: pointer to pmd entry
a30b48bf1b244f1 Balbir Singh            2025-10-01  127   * @start: start address of the range for migration
a30b48bf1b244f1 Balbir Singh            2025-10-01  128   * @end: end address of the range for migration
a30b48bf1b244f1 Balbir Singh            2025-10-01  129   * @walk: mm_walk callback structure
a30b48bf1b244f1 Balbir Singh            2025-10-01  130   * @fault_folio: folio associated with the fault if any
a30b48bf1b244f1 Balbir Singh            2025-10-01  131   *
a30b48bf1b244f1 Balbir Singh            2025-10-01  132   * Collect the huge pmd entry at @pmdp for migration and set the
a30b48bf1b244f1 Balbir Singh            2025-10-01  133   * MIGRATE_PFN_COMPOUND flag in the migrate src entry to indicate that
a30b48bf1b244f1 Balbir Singh            2025-10-01  134   * migration will occur at HPAGE_PMD granularity
a30b48bf1b244f1 Balbir Singh            2025-10-01  135   */
a30b48bf1b244f1 Balbir Singh            2025-10-01  136  static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,
a30b48bf1b244f1 Balbir Singh            2025-10-01  137  					unsigned long end, struct mm_walk *walk,
a30b48bf1b244f1 Balbir Singh            2025-10-01  138  					struct folio *fault_folio)
76cbbead253ddca Christoph Hellwig       2022-02-16  139  {
a30b48bf1b244f1 Balbir Singh            2025-10-01  140  	struct mm_struct *mm = walk->mm;
a30b48bf1b244f1 Balbir Singh            2025-10-01  141  	struct folio *folio;
76cbbead253ddca Christoph Hellwig       2022-02-16  142  	struct migrate_vma *migrate = walk->private;
76cbbead253ddca Christoph Hellwig       2022-02-16  143  	spinlock_t *ptl;
a30b48bf1b244f1 Balbir Singh            2025-10-01  144  	int ret;
a30b48bf1b244f1 Balbir Singh            2025-10-01  145  	unsigned long write = 0;
76cbbead253ddca Christoph Hellwig       2022-02-16  146  
a30b48bf1b244f1 Balbir Singh            2025-10-01  147  	ptl = pmd_lock(mm, pmdp);
a30b48bf1b244f1 Balbir Singh            2025-10-01  148  	if (pmd_none(*pmdp)) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  149  		spin_unlock(ptl);
76cbbead253ddca Christoph Hellwig       2022-02-16  150  		return migrate_vma_collect_hole(start, end, -1, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  151  	}
76cbbead253ddca Christoph Hellwig       2022-02-16  152  
76cbbead253ddca Christoph Hellwig       2022-02-16  153  	if (pmd_trans_huge(*pmdp)) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  154  		if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) {
76cbbead253ddca Christoph Hellwig       2022-02-16  155  			spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  156  			return migrate_vma_collect_skip(start, end, walk);
76cbbead253ddca Christoph Hellwig       2022-02-16  157  		}
76cbbead253ddca Christoph Hellwig       2022-02-16  158  
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  159) 		folio = pmd_folio(*pmdp);
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  160) 		if (is_huge_zero_folio(folio)) {
76cbbead253ddca Christoph Hellwig       2022-02-16  161  			spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  162  			return migrate_vma_collect_hole(start, end, -1, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  163  		}
a30b48bf1b244f1 Balbir Singh            2025-10-01  164  		if (pmd_write(*pmdp))
a30b48bf1b244f1 Balbir Singh            2025-10-01  165  			write = MIGRATE_PFN_WRITE;
a30b48bf1b244f1 Balbir Singh            2025-10-01  166  	} else if (!pmd_present(*pmdp)) {
0ac881efe164685 Lorenzo Stoakes         2025-11-10  167  		const softleaf_t entry = softleaf_from_pmd(*pmdp);
a30b48bf1b244f1 Balbir Singh            2025-10-01  168  
0ac881efe164685 Lorenzo Stoakes         2025-11-10  169  		folio = softleaf_to_folio(entry);
0ac881efe164685 Lorenzo Stoakes         2025-11-10  170  
0ac881efe164685 Lorenzo Stoakes         2025-11-10  171  		if (!softleaf_is_device_private(entry) ||
a30b48bf1b244f1 Balbir Singh            2025-10-01  172  			!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PRIVATE) ||
a30b48bf1b244f1 Balbir Singh            2025-10-01  173  			(folio->pgmap->owner != migrate->pgmap_owner)) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  174  			spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  175  			return migrate_vma_collect_skip(start, end, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  176  		}
a30b48bf1b244f1 Balbir Singh            2025-10-01  177  
0ac881efe164685 Lorenzo Stoakes         2025-11-10  178  		if (softleaf_is_migration(entry)) {
b570f37a2ce480b Thomas Hellström        2026-02-10  179  			softleaf_entry_wait_on_locked(entry, ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  180  			return -EAGAIN;
a30b48bf1b244f1 Balbir Singh            2025-10-01  181  		}
a30b48bf1b244f1 Balbir Singh            2025-10-01  182  
0ac881efe164685 Lorenzo Stoakes         2025-11-10  183  		if (softleaf_is_device_private_write(entry))
a30b48bf1b244f1 Balbir Singh            2025-10-01  184  			write = MIGRATE_PFN_WRITE;
76cbbead253ddca Christoph Hellwig       2022-02-16  185  	} else {
a30b48bf1b244f1 Balbir Singh            2025-10-01  186  		spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  187  		return -EAGAIN;
a30b48bf1b244f1 Balbir Singh            2025-10-01  188  	}
76cbbead253ddca Christoph Hellwig       2022-02-16  189  
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  190) 	folio_get(folio);
a30b48bf1b244f1 Balbir Singh            2025-10-01  191  	if (folio != fault_folio && unlikely(!folio_trylock(folio))) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  192  		spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  193  		folio_put(folio);
a30b48bf1b244f1 Balbir Singh            2025-10-01  194  		return migrate_vma_collect_skip(start, end, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  195  	}
a30b48bf1b244f1 Balbir Singh            2025-10-01  196  
a30b48bf1b244f1 Balbir Singh            2025-10-01  197  	if (thp_migration_supported() &&
a30b48bf1b244f1 Balbir Singh            2025-10-01  198  		(migrate->flags & MIGRATE_VMA_SELECT_COMPOUND) &&
a30b48bf1b244f1 Balbir Singh            2025-10-01  199  		(IS_ALIGNED(start, HPAGE_PMD_SIZE) &&
a30b48bf1b244f1 Balbir Singh            2025-10-01  200  		 IS_ALIGNED(end, HPAGE_PMD_SIZE))) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  201  
a30b48bf1b244f1 Balbir Singh            2025-10-01  202  		struct page_vma_mapped_walk pvmw = {
a30b48bf1b244f1 Balbir Singh            2025-10-01  203  			.ptl = ptl,
a30b48bf1b244f1 Balbir Singh            2025-10-01  204  			.address = start,
a30b48bf1b244f1 Balbir Singh            2025-10-01  205  			.pmd = pmdp,
a30b48bf1b244f1 Balbir Singh            2025-10-01  206  			.vma = walk->vma,
a30b48bf1b244f1 Balbir Singh            2025-10-01  207  		};
a30b48bf1b244f1 Balbir Singh            2025-10-01  208  
a30b48bf1b244f1 Balbir Singh            2025-10-01  209  		unsigned long pfn = page_to_pfn(folio_page(folio, 0));
a30b48bf1b244f1 Balbir Singh            2025-10-01  210  
a30b48bf1b244f1 Balbir Singh            2025-10-01  211  		migrate->src[migrate->npages] = migrate_pfn(pfn) | write
a30b48bf1b244f1 Balbir Singh            2025-10-01  212  						| MIGRATE_PFN_MIGRATE
a30b48bf1b244f1 Balbir Singh            2025-10-01  213  						| MIGRATE_PFN_COMPOUND;
a30b48bf1b244f1 Balbir Singh            2025-10-01  214  		migrate->dst[migrate->npages++] = 0;
a30b48bf1b244f1 Balbir Singh            2025-10-01  215  		migrate->cpages++;
a30b48bf1b244f1 Balbir Singh            2025-10-01  216  		ret = set_pmd_migration_entry(&pvmw, folio_page(folio, 0));
a30b48bf1b244f1 Balbir Singh            2025-10-01  217  		if (ret) {
a30b48bf1b244f1 Balbir Singh            2025-10-01  218  			migrate->npages--;
a30b48bf1b244f1 Balbir Singh            2025-10-01  219  			migrate->cpages--;
a30b48bf1b244f1 Balbir Singh            2025-10-01  220  			migrate->src[migrate->npages] = 0;
a30b48bf1b244f1 Balbir Singh            2025-10-01  221  			migrate->dst[migrate->npages] = 0;
a30b48bf1b244f1 Balbir Singh            2025-10-01  222  			goto fallback;
a30b48bf1b244f1 Balbir Singh            2025-10-01  223  		}
a30b48bf1b244f1 Balbir Singh            2025-10-01  224  		migrate_vma_collect_skip(start + PAGE_SIZE, end, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  225  		spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  226  		return 0;
a30b48bf1b244f1 Balbir Singh            2025-10-01  227  	}
a30b48bf1b244f1 Balbir Singh            2025-10-01  228  
a30b48bf1b244f1 Balbir Singh            2025-10-01  229  fallback:
76cbbead253ddca Christoph Hellwig       2022-02-16  230  	spin_unlock(ptl);
a30b48bf1b244f1 Balbir Singh            2025-10-01  231  	if (!folio_test_large(folio))
a30b48bf1b244f1 Balbir Singh            2025-10-01  232  		goto done;
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  233) 	ret = split_folio(folio);
1afaeb8293c9add Matthew Brost           2025-03-05  234  	if (fault_folio != folio)
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  235) 		folio_unlock(folio);
b002a7b0a58acea Matthew Wilcox (Oracle  2024-03-26  236) 	folio_put(folio);
76cbbead253ddca Christoph Hellwig       2022-02-16  237  	if (ret)
a30b48bf1b244f1 Balbir Singh            2025-10-01  238  		return migrate_vma_collect_skip(start, end, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  239  	if (pmd_none(pmdp_get_lockless(pmdp)))
a30b48bf1b244f1 Balbir Singh            2025-10-01  240  		return migrate_vma_collect_hole(start, end, -1, walk);
a30b48bf1b244f1 Balbir Singh            2025-10-01  241  
a30b48bf1b244f1 Balbir Singh            2025-10-01  242  done:
a30b48bf1b244f1 Balbir Singh            2025-10-01 @243  	return -ENOENT;
76cbbead253ddca Christoph Hellwig       2022-02-16  244  }
a30b48bf1b244f1 Balbir Singh            2025-10-01  245  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-14 19:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-13 13:09 [PATCH] mm/migrate_device: fix double unlock and remove dead code Sunny Patel
2026-04-13 19:38 ` David Hildenbrand (Arm)
2026-04-13 20:03   ` Zi Yan
2026-04-14  9:51     ` David Hildenbrand (Arm)
2026-04-14 14:21       ` Sunny Patel
2026-04-13 22:21   ` Sunny Patel
2026-04-13 23:30 ` Matthew Brost
2026-04-14  9:46   ` David Hildenbrand (Arm)
  -- strict thread matches above, loose matches on Subject: below --
2026-04-14 19:53 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.