Commit f894ddd5 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jason Gunthorpe

memremap: add an owner field to struct dev_pagemap

Add a new opaque owner field to struct dev_pagemap, which will allow the
hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, and
refuse to work on mappings not owned by the calling entity.

Link: https://lore.kernel.org/r/20200316193216.920734-2-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarRalph Campbell <rcampbell@nvidia.com>
Tested-by: default avatarBharata B Rao <bharata@linux.ibm.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 5a0c38d3
...@@ -779,6 +779,8 @@ int kvmppc_uvmem_init(void) ...@@ -779,6 +779,8 @@ int kvmppc_uvmem_init(void)
kvmppc_uvmem_pgmap.type = MEMORY_DEVICE_PRIVATE; kvmppc_uvmem_pgmap.type = MEMORY_DEVICE_PRIVATE;
kvmppc_uvmem_pgmap.res = *res; kvmppc_uvmem_pgmap.res = *res;
kvmppc_uvmem_pgmap.ops = &kvmppc_uvmem_ops; kvmppc_uvmem_pgmap.ops = &kvmppc_uvmem_ops;
/* just one global instance: */
kvmppc_uvmem_pgmap.owner = &kvmppc_uvmem_pgmap;
addr = memremap_pages(&kvmppc_uvmem_pgmap, NUMA_NO_NODE); addr = memremap_pages(&kvmppc_uvmem_pgmap, NUMA_NO_NODE);
if (IS_ERR(addr)) { if (IS_ERR(addr)) {
ret = PTR_ERR(addr); ret = PTR_ERR(addr);
......
...@@ -526,6 +526,7 @@ nouveau_dmem_init(struct nouveau_drm *drm) ...@@ -526,6 +526,7 @@ nouveau_dmem_init(struct nouveau_drm *drm)
drm->dmem->pagemap.type = MEMORY_DEVICE_PRIVATE; drm->dmem->pagemap.type = MEMORY_DEVICE_PRIVATE;
drm->dmem->pagemap.res = *res; drm->dmem->pagemap.res = *res;
drm->dmem->pagemap.ops = &nouveau_dmem_pagemap_ops; drm->dmem->pagemap.ops = &nouveau_dmem_pagemap_ops;
drm->dmem->pagemap.owner = drm->dev;
if (IS_ERR(devm_memremap_pages(device, &drm->dmem->pagemap))) if (IS_ERR(devm_memremap_pages(device, &drm->dmem->pagemap)))
goto out_free; goto out_free;
......
...@@ -103,6 +103,9 @@ struct dev_pagemap_ops { ...@@ -103,6 +103,9 @@ struct dev_pagemap_ops {
* @type: memory type: see MEMORY_* in memory_hotplug.h * @type: memory type: see MEMORY_* in memory_hotplug.h
* @flags: PGMAP_* flags to specify defailed behavior * @flags: PGMAP_* flags to specify defailed behavior
* @ops: method table * @ops: method table
* @owner: an opaque pointer identifying the entity that manages this
* instance. Used by various helpers to make sure that no
* foreign ZONE_DEVICE memory is accessed.
*/ */
struct dev_pagemap { struct dev_pagemap {
struct vmem_altmap altmap; struct vmem_altmap altmap;
...@@ -113,6 +116,7 @@ struct dev_pagemap { ...@@ -113,6 +116,7 @@ struct dev_pagemap {
enum memory_type type; enum memory_type type;
unsigned int flags; unsigned int flags;
const struct dev_pagemap_ops *ops; const struct dev_pagemap_ops *ops;
void *owner;
}; };
static inline struct vmem_altmap *pgmap_altmap(struct dev_pagemap *pgmap) static inline struct vmem_altmap *pgmap_altmap(struct dev_pagemap *pgmap)
......
...@@ -181,6 +181,10 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) ...@@ -181,6 +181,10 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
WARN(1, "Missing migrate_to_ram method\n"); WARN(1, "Missing migrate_to_ram method\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
if (!pgmap->owner) {
WARN(1, "Missing owner\n");
return ERR_PTR(-EINVAL);
}
break; break;
case MEMORY_DEVICE_FS_DAX: case MEMORY_DEVICE_FS_DAX:
if (!IS_ENABLED(CONFIG_ZONE_DEVICE) || if (!IS_ENABLED(CONFIG_ZONE_DEVICE) ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment