Skip to contentSkip to conversation

mm: fix migrate_vma_setup() src_owner and normal pages

PATCH RESEND In review Ralph Campbell 2 participants 4 messages Jun 22, 2020 – Jun 24, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 mm: fix migrate_vma_setup() src_owner and normal pages

The caller of migrate_vma_setup() does not know what type of page is stored in the CPU's page tables. Pages within the specified range are free to be swapped out, migrated, or freed until after migrate_vma_setup() returns. The caller needs to set struct migrate_vma.src_owner in case a page is a ZONE device private page that the device owns and might want to migrate. However, the current code skips normal anonymous pages if src_owner is set, thus preventing those pages from being migrated. Remove the src_owner check for normal pages since src_owner only applies to device private pages and allow a range of normal and device private pages to be migrated.

Fixes 800bb1c8dc80 ("mm: handle multiple owners of device private pages in migrate_vma")

---

This is based on 5.8.0-rc2 for Andrew Morton's mm tree. I believe it can be queued for 5.8-rcX after being reviewed. This was part of a larger series but I'm resending it separately as suggested by Jason Gunthorpe.
https://lore.kernel.org/linux-mm/[email protected]/

 mm/migrate.c | 2 --
 1 file changed, 2 deletions(-)
mm/migrate.c +0 -2
index f37729673558..24535281cea3 100644
@@ -2295,8 +2295,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 			if (is_write_device_private_entry(entry))
 				mpfn |= MIGRATE_PFN_WRITE;
 		} else {
-			if (migrate->src_owner)
-				goto next;
 			pfn = pte_pfn(pte);
 			if (is_zero_pfn(pfn)) {
 				mpfn = MIGRATE_PFN_MIGRATE;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Ralph Campbell

The caller of migrate_vma_setup() does not know what type of page is stored in the CPU's page tables. Pages within the specified range are free to be swapped out, migrated, or freed until after migrate_vma_setup() returns. The caller needs to set struct migrate_vma.src_owner in case a page is a ZONE device private page that the device owns and might want to migrate. However, the current code skips normal anonymous pages if src_owner is set, thus preventing those pages from being migrated. Remove the src_owner check for normal pages since src_owner only applies to device private pages and allow a range of normal and device private pages to be migrated.

src_owner being set means we want to migrate from device private memory to normal host DRAM. What kind of problem do you see of not touching already present pages in that path?

#2 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Ralph Campbell

The caller of migrate_vma_setup() does not know what type of page is stored in the CPU's page tables. Pages within the specified range are free to be swapped out, migrated, or freed until after migrate_vma_setup() returns. The caller needs to set struct migrate_vma.src_owner in case a page is a ZONE device private page that the device owns and might want to migrate. However, the current code skips normal anonymous pages if src_owner is set, thus preventing those pages from being migrated. Remove the src_owner check for normal pages since src_owner only applies to device private pages and allow a range of normal and device private pages to be migrated.

Quoted 4 lines

src_owner being set means we want to migrate from device private memory to normal host DRAM. What kind of problem do you see of not touching already present pages in that path?

The problem is that migrate_vma_setup() invalidates the address range so any previously migrated pages to device private memory have to be faulted in again. By having the PFN of those device private pages in the src array, the driver can reinstate the device MMU mappings and avoid the page faults.

#3 lore raw
Quoted 19 lines · Ralph Campbell
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Ralph Campbell

The caller of migrate_vma_setup() does not know what type of page is stored in the CPU's page tables. Pages within the specified range are free to be swapped out, migrated, or freed until after migrate_vma_setup() returns. The caller needs to set struct migrate_vma.src_owner in case a page is a ZONE device private page that the device owns and might want to migrate. However, the current code skips normal anonymous pages if src_owner is set, thus preventing those pages from being migrated. Remove the src_owner check for normal pages since src_owner only applies to device private pages and allow a range of normal and device private pages to be migrated.

Quoted 4 lines

src_owner being set means we want to migrate from device private memory to normal host DRAM. What kind of problem do you see of not touching already present pages in that path?

Quoted 4 lines

The problem is that migrate_vma_setup() invalidates the address range so any previously migrated pages to device private memory have to be faulted in again. By having the PFN of those device private pages in the src array, the driver can reinstate the device MMU mappings and avoid the page faults.

Maybe add that to the changelog?