Skip to content

Commit 5143192

Browse files
Ralph Campbelljgunthorpe
authored andcommitted
mm/migrate: add a flags parameter to migrate_vma
The src_owner field in struct migrate_vma is being used for two purposes, it acts as a selection filter for which types of pages are to be migrated and it identifies device private pages owned by the caller. Split this into separate parameters so the src_owner field can be used just to identify device private pages owned by the caller of migrate_vma_setup(). Rename the src_owner field to pgmap_owner to reflect it is now used only to identify which device private pages to migrate. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ralph Campbell <[email protected]> Reviewed-by: Bharata B Rao <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1a77dec commit 5143192

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

arch/powerpc/kvm/book3s_hv_uvmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ kvmppc_svm_page_in(struct vm_area_struct *vma, unsigned long start,
400400
mig.end = end;
401401
mig.src = &src_pfn;
402402
mig.dst = &dst_pfn;
403+
mig.flags = MIGRATE_VMA_SELECT_SYSTEM;
403404

404405
/*
405406
* We come here with mmap_lock write lock held just for
@@ -577,7 +578,8 @@ kvmppc_svm_page_out(struct vm_area_struct *vma, unsigned long start,
577578
mig.end = end;
578579
mig.src = &src_pfn;
579580
mig.dst = &dst_pfn;
580-
mig.src_owner = &kvmppc_uvmem_pgmap;
581+
mig.pgmap_owner = &kvmppc_uvmem_pgmap;
582+
mig.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE;
581583

582584
mutex_lock(&kvm->arch.uvmem_lock);
583585
/* The requested page is already paged-out, nothing to do */

drivers/gpu/drm/nouveau/nouveau_dmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf)
182182
.end = vmf->address + PAGE_SIZE,
183183
.src = &src,
184184
.dst = &dst,
185-
.src_owner = drm->dev,
185+
.pgmap_owner = drm->dev,
186+
.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE,
186187
};
187188

188189
/*
@@ -615,6 +616,7 @@ nouveau_dmem_migrate_vma(struct nouveau_drm *drm,
615616
struct migrate_vma args = {
616617
.vma = vma,
617618
.start = start,
619+
.flags = MIGRATE_VMA_SELECT_SYSTEM,
618620
};
619621
unsigned long i;
620622
u64 *pfns;

include/linux/migrate.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ static inline unsigned long migrate_pfn(unsigned long pfn)
180180
return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
181181
}
182182

183+
enum migrate_vma_direction {
184+
MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
185+
MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
186+
};
187+
183188
struct migrate_vma {
184189
struct vm_area_struct *vma;
185190
/*
@@ -199,11 +204,11 @@ struct migrate_vma {
199204

200205
/*
201206
* Set to the owner value also stored in page->pgmap->owner for
202-
* migrating out of device private memory. If set only device
203-
* private pages with this owner are migrated. If not set
204-
* device private pages are not migrated at all.
207+
* migrating out of device private memory. The flags also need to
208+
* be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
205209
*/
206-
void *src_owner;
210+
void *pgmap_owner;
211+
unsigned long flags;
207212
};
208213

209214
int migrate_vma_setup(struct migrate_vma *args);

lib/test_hmm.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,6 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args,
585585
*/
586586
spage = migrate_pfn_to_page(*src);
587587

588-
/*
589-
* Don't migrate device private pages from our own driver or
590-
* others. For our own we would do a device private memory copy
591-
* not a migration and for others, we would need to fault the
592-
* other device's page into system memory first.
593-
*/
594-
if (spage && is_zone_device_page(spage))
595-
continue;
596-
597588
dpage = dmirror_devmem_alloc_page(mdevice);
598589
if (!dpage)
599590
continue;
@@ -702,7 +693,8 @@ static int dmirror_migrate(struct dmirror *dmirror,
702693
args.dst = dst_pfns;
703694
args.start = addr;
704695
args.end = next;
705-
args.src_owner = NULL;
696+
args.pgmap_owner = NULL;
697+
args.flags = MIGRATE_VMA_SELECT_SYSTEM;
706698
ret = migrate_vma_setup(&args);
707699
if (ret)
708700
goto out;
@@ -1053,7 +1045,8 @@ static vm_fault_t dmirror_devmem_fault(struct vm_fault *vmf)
10531045
args.end = args.start + PAGE_SIZE;
10541046
args.src = &src_pfns;
10551047
args.dst = &dst_pfns;
1056-
args.src_owner = dmirror->mdevice;
1048+
args.pgmap_owner = dmirror->mdevice;
1049+
args.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE;
10571050

10581051
if (migrate_vma_setup(&args))
10591052
return VM_FAULT_SIGBUS;

mm/migrate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,15 +2287,17 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
22872287
goto next;
22882288

22892289
page = device_private_entry_to_page(entry);
2290-
if (page->pgmap->owner != migrate->src_owner)
2290+
if (!(migrate->flags &
2291+
MIGRATE_VMA_SELECT_DEVICE_PRIVATE) ||
2292+
page->pgmap->owner != migrate->pgmap_owner)
22912293
goto next;
22922294

22932295
mpfn = migrate_pfn(page_to_pfn(page)) |
22942296
MIGRATE_PFN_MIGRATE;
22952297
if (is_write_device_private_entry(entry))
22962298
mpfn |= MIGRATE_PFN_WRITE;
22972299
} else {
2298-
if (migrate->src_owner)
2300+
if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM))
22992301
goto next;
23002302
pfn = pte_pfn(pte);
23012303
if (is_zero_pfn(pfn)) {

0 commit comments

Comments
 (0)