Commit ee8520fe authored by Dan Williams's avatar Dan Williams

tools/testing/nvdimm: replace CONFIG_DMA_CMA dependency with vmalloc()

DMA_CMA is incompatible with SWIOTLB used in enterprise distro
configurations.  Switch to vmalloc() allocations for all resources.
Acked-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent f295e53b
...@@ -11,6 +11,8 @@ ldflags-y += --wrap=__devm_release_region ...@@ -11,6 +11,8 @@ ldflags-y += --wrap=__devm_release_region
ldflags-y += --wrap=__request_region ldflags-y += --wrap=__request_region
ldflags-y += --wrap=__release_region ldflags-y += --wrap=__release_region
ldflags-y += --wrap=devm_memremap_pages ldflags-y += --wrap=devm_memremap_pages
ldflags-y += --wrap=insert_resource
ldflags-y += --wrap=remove_resource
DRIVERS := ../../../drivers DRIVERS := ../../../drivers
NVDIMM_SRC := $(DRIVERS)/nvdimm NVDIMM_SRC := $(DRIVERS)/nvdimm
......
...@@ -21,14 +21,26 @@ long pmem_direct_access(struct block_device *bdev, sector_t sector, ...@@ -21,14 +21,26 @@ long pmem_direct_access(struct block_device *bdev, sector_t sector,
struct pmem_device *pmem = bdev->bd_queue->queuedata; struct pmem_device *pmem = bdev->bd_queue->queuedata;
resource_size_t offset = sector * 512 + pmem->data_offset; resource_size_t offset = sector * 512 + pmem->data_offset;
/* disable DAX for nfit_test pmem devices */ if (unlikely(is_bad_pmem(&pmem->bb, sector, size)))
if (get_nfit_res(pmem->phys_addr + offset)) {
dev_info_once(pmem->bb.dev, "dax is disabled for nfit_test\n");
return -EIO; return -EIO;
/*
* Limit dax to a single page at a time given vmalloc()-backed
* in the nfit_test case.
*/
if (get_nfit_res(pmem->phys_addr + offset)) {
struct page *page;
*kaddr = pmem->virt_addr + offset;
page = vmalloc_to_page(pmem->virt_addr + offset);
*pfn = page_to_pfn_t(page);
dev_dbg_ratelimited(disk_to_dev(bdev->bd_disk)->parent,
"%s: sector: %#llx pfn: %#lx\n", __func__,
(unsigned long long) sector, page_to_pfn(page));
return PAGE_SIZE;
} }
if (unlikely(is_bad_pmem(&pmem->bb, sector, size)))
return -EIO;
*kaddr = pmem->virt_addr + offset; *kaddr = pmem->virt_addr + offset;
*pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
......
...@@ -230,6 +230,22 @@ struct resource *__wrap___request_region(struct resource *parent, ...@@ -230,6 +230,22 @@ struct resource *__wrap___request_region(struct resource *parent,
} }
EXPORT_SYMBOL(__wrap___request_region); EXPORT_SYMBOL(__wrap___request_region);
int __wrap_insert_resource(struct resource *parent, struct resource *res)
{
if (get_nfit_res(res->start))
return 0;
return insert_resource(parent, res);
}
EXPORT_SYMBOL(__wrap_insert_resource);
int __wrap_remove_resource(struct resource *res)
{
if (get_nfit_res(res->start))
return 0;
return remove_resource(res);
}
EXPORT_SYMBOL(__wrap_remove_resource);
struct resource *__wrap___devm_request_region(struct device *dev, struct resource *__wrap___devm_request_region(struct device *dev,
struct resource *parent, resource_size_t start, struct resource *parent, resource_size_t start,
resource_size_t n, const char *name) resource_size_t n, const char *name)
......
...@@ -470,11 +470,7 @@ static void release_nfit_res(void *data) ...@@ -470,11 +470,7 @@ static void release_nfit_res(void *data)
list_del(&nfit_res->list); list_del(&nfit_res->list);
spin_unlock(&nfit_test_lock); spin_unlock(&nfit_test_lock);
if (is_vmalloc_addr(nfit_res->buf))
vfree(nfit_res->buf); vfree(nfit_res->buf);
else
dma_free_coherent(nfit_res->dev, resource_size(res),
nfit_res->buf, res->start);
kfree(res); kfree(res);
kfree(nfit_res); kfree(nfit_res);
} }
...@@ -507,9 +503,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, ...@@ -507,9 +503,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
return nfit_res->buf; return nfit_res->buf;
err: err:
if (buf && !is_vmalloc_addr(buf)) if (buf)
dma_free_coherent(dev, size, buf, *dma);
else if (buf)
vfree(buf); vfree(buf);
kfree(res); kfree(res);
kfree(nfit_res); kfree(nfit_res);
...@@ -524,15 +518,6 @@ static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) ...@@ -524,15 +518,6 @@ static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma)
return __test_alloc(t, size, dma, buf); return __test_alloc(t, size, dma, buf);
} }
static void *test_alloc_coherent(struct nfit_test *t, size_t size,
dma_addr_t *dma)
{
struct device *dev = &t->pdev.dev;
void *buf = dma_alloc_coherent(dev, size, dma, GFP_KERNEL);
return __test_alloc(t, size, dma, buf);
}
static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr)
{ {
int i; int i;
...@@ -592,15 +577,15 @@ static int nfit_test0_alloc(struct nfit_test *t) ...@@ -592,15 +577,15 @@ static int nfit_test0_alloc(struct nfit_test *t)
return -ENOMEM; return -ENOMEM;
t->nfit_size = nfit_size; t->nfit_size = nfit_size;
t->spa_set[0] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[0]); t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]);
if (!t->spa_set[0]) if (!t->spa_set[0])
return -ENOMEM; return -ENOMEM;
t->spa_set[1] = test_alloc_coherent(t, SPA1_SIZE, &t->spa_set_dma[1]); t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]);
if (!t->spa_set[1]) if (!t->spa_set[1])
return -ENOMEM; return -ENOMEM;
t->spa_set[2] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[2]); t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]);
if (!t->spa_set[2]) if (!t->spa_set[2])
return -ENOMEM; return -ENOMEM;
...@@ -639,7 +624,7 @@ static int nfit_test1_alloc(struct nfit_test *t) ...@@ -639,7 +624,7 @@ static int nfit_test1_alloc(struct nfit_test *t)
return -ENOMEM; return -ENOMEM;
t->nfit_size = nfit_size; t->nfit_size = nfit_size;
t->spa_set[0] = test_alloc_coherent(t, SPA2_SIZE, &t->spa_set_dma[0]); t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]);
if (!t->spa_set[0]) if (!t->spa_set[0])
return -ENOMEM; return -ENOMEM;
...@@ -1523,12 +1508,6 @@ static struct platform_driver nfit_test_driver = { ...@@ -1523,12 +1508,6 @@ static struct platform_driver nfit_test_driver = {
.id_table = nfit_test_id, .id_table = nfit_test_id,
}; };
#ifdef CONFIG_CMA_SIZE_MBYTES
#define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES
#else
#define CMA_SIZE_MBYTES 0
#endif
static __init int nfit_test_init(void) static __init int nfit_test_init(void)
{ {
int rc, i; int rc, i;
...@@ -1538,7 +1517,6 @@ static __init int nfit_test_init(void) ...@@ -1538,7 +1517,6 @@ static __init int nfit_test_init(void)
for (i = 0; i < NUM_NFITS; i++) { for (i = 0; i < NUM_NFITS; i++) {
struct nfit_test *nfit_test; struct nfit_test *nfit_test;
struct platform_device *pdev; struct platform_device *pdev;
static int once;
nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL);
if (!nfit_test) { if (!nfit_test) {
...@@ -1577,20 +1555,6 @@ static __init int nfit_test_init(void) ...@@ -1577,20 +1555,6 @@ static __init int nfit_test_init(void)
goto err_register; goto err_register;
instances[i] = nfit_test; instances[i] = nfit_test;
if (!once++) {
dma_addr_t dma;
void *buf;
buf = dma_alloc_coherent(&pdev->dev, SZ_128M, &dma,
GFP_KERNEL);
if (!buf) {
rc = -ENOMEM;
dev_warn(&pdev->dev, "need 128M of free cma\n");
goto err_register;
}
dma_free_coherent(&pdev->dev, SZ_128M, buf, dma);
}
} }
rc = platform_driver_register(&nfit_test_driver); rc = platform_driver_register(&nfit_test_driver);
......
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