memremap: move dev_pagemap callbacks into a separate structure

The dev_pagemap is a growing too many callbacks.  Move them into a
separate ops structure so that they are not duplicated for multiple
instances, and an attacker can't easily overwrite them.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Logan Gunthorpe <[email protected]>
Reviewed-by: Jason Gunthorpe <[email protected]>
Reviewed-by: Dan Williams <[email protected]>
Tested-by: Dan Williams <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
This commit is contained in:
Christoph Hellwig 2019-06-26 14:27:08 +02:00 • committed by Jason Gunthorpe
commit 1e240e8d4a
8 changed files with 65 additions and 46 deletions

View file

@ -36,9 +36,8 @@ static void dev_dax_percpu_exit(struct percpu_ref *ref)
percpu_ref_exit(ref);
}
static void dev_dax_percpu_kill(struct percpu_ref *data)
static void dev_dax_percpu_kill(struct percpu_ref *ref)
{
struct percpu_ref *ref = data;
struct dev_dax *dev_dax = ref_to_dev_dax(ref);
dev_dbg(&dev_dax->dev, "%s\n", __func__);
@ -442,6 +441,11 @@ static void dev_dax_kill(void *dev_dax)
kill_dev_dax(dev_dax);
}
static const struct dev_pagemap_ops dev_dax_pagemap_ops = {
.kill = dev_dax_percpu_kill,
.cleanup = dev_dax_percpu_exit,
};
int dev_dax_probe(struct device *dev)
{
struct dev_dax *dev_dax = to_dev_dax(dev);
@ -466,9 +470,8 @@ int dev_dax_probe(struct device *dev)
return rc;
dev_dax->pgmap.ref = &dev_dax->ref;
dev_dax->pgmap.kill = dev_dax_percpu_kill;
dev_dax->pgmap.cleanup = dev_dax_percpu_exit;
dev_dax->pgmap.type = MEMORY_DEVICE_DEVDAX;
dev_dax->pgmap.ops = &dev_dax_pagemap_ops;
addr = devm_memremap_pages(dev, &dev_dax->pgmap);
if (IS_ERR(addr))
return PTR_ERR(addr);

View file

@ -16,7 +16,7 @@ struct dev_dax *__dax_pmem_probe(struct device *dev, enum dev_dax_subsys subsys)
struct dev_dax *dev_dax;
struct nd_namespace_io *nsio;
struct dax_region *dax_region;
struct dev_pagemap pgmap = { 0 };
struct dev_pagemap pgmap = { };
struct nd_namespace_common *ndns;
struct nd_dax *nd_dax = to_nd_dax(dev);
struct nd_pfn *nd_pfn = &nd_dax->nd_pfn;