Skip to content

Commit e3f5df7

Browse files
committed
tools/testing/nvdimm: Align test resources to 128M
In preparation for libnvdimm growing new restrictions to detect section conflicts between persistent memory regions, enable nfit_test to allocate aligned resources. Use a gen_pool to allocate nfit_test's fake resources in a separate address space from the virtual translation of the same. Reviewed-by: Vishal Verma <vishal.l.verma@intel.com> Tested-by: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 9ff0119 commit e3f5df7

File tree

1 file changed

+33
-2
lines changed
  • tools/testing/nvdimm/test

1 file changed

+33
-2
lines changed

tools/testing/nvdimm/test/nfit.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/dma-mapping.h>
1616
#include <linux/workqueue.h>
1717
#include <linux/libnvdimm.h>
18+
#include <linux/genalloc.h>
1819
#include <linux/vmalloc.h>
1920
#include <linux/device.h>
2021
#include <linux/module.h>
@@ -215,6 +216,8 @@ struct nfit_test {
215216

216217
static struct workqueue_struct *nfit_wq;
217218

219+
static struct gen_pool *nfit_pool;
220+
218221
static struct nfit_test *to_nfit_test(struct device *dev)
219222
{
220223
struct platform_device *pdev = to_platform_device(dev);
@@ -1132,6 +1135,9 @@ static void release_nfit_res(void *data)
11321135
list_del(&nfit_res->list);
11331136
spin_unlock(&nfit_test_lock);
11341137

1138+
if (resource_size(&nfit_res->res) >= DIMM_SIZE)
1139+
gen_pool_free(nfit_pool, nfit_res->res.start,
1140+
resource_size(&nfit_res->res));
11351141
vfree(nfit_res->buf);
11361142
kfree(nfit_res);
11371143
}
@@ -1144,7 +1150,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
11441150
GFP_KERNEL);
11451151
int rc;
11461152

1147-
if (!buf || !nfit_res)
1153+
if (!buf || !nfit_res || !*dma)
11481154
goto err;
11491155
rc = devm_add_action(dev, release_nfit_res, nfit_res);
11501156
if (rc)
@@ -1164,6 +1170,8 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
11641170

11651171
return nfit_res->buf;
11661172
err:
1173+
if (*dma && size >= DIMM_SIZE)
1174+
gen_pool_free(nfit_pool, *dma, size);
11671175
if (buf)
11681176
vfree(buf);
11691177
kfree(nfit_res);
@@ -1172,9 +1180,16 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
11721180

11731181
static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma)
11741182
{
1183+
struct genpool_data_align data = {
1184+
.align = SZ_128M,
1185+
};
11751186
void *buf = vmalloc(size);
11761187

1177-
*dma = (unsigned long) buf;
1188+
if (size >= DIMM_SIZE)
1189+
*dma = gen_pool_alloc_algo(nfit_pool, size,
1190+
gen_pool_first_fit_align, &data);
1191+
else
1192+
*dma = (unsigned long) buf;
11781193
return __test_alloc(t, size, dma, buf);
11791194
}
11801195

@@ -2839,6 +2854,17 @@ static __init int nfit_test_init(void)
28392854
goto err_register;
28402855
}
28412856

2857+
nfit_pool = gen_pool_create(ilog2(SZ_4M), NUMA_NO_NODE);
2858+
if (!nfit_pool) {
2859+
rc = -ENOMEM;
2860+
goto err_register;
2861+
}
2862+
2863+
if (gen_pool_add(nfit_pool, SZ_4G, SZ_4G, NUMA_NO_NODE)) {
2864+
rc = -ENOMEM;
2865+
goto err_register;
2866+
}
2867+
28422868
for (i = 0; i < NUM_NFITS; i++) {
28432869
struct nfit_test *nfit_test;
28442870
struct platform_device *pdev;
@@ -2894,6 +2920,9 @@ static __init int nfit_test_init(void)
28942920
return 0;
28952921

28962922
err_register:
2923+
if (nfit_pool)
2924+
gen_pool_destroy(nfit_pool);
2925+
28972926
destroy_workqueue(nfit_wq);
28982927
for (i = 0; i < NUM_NFITS; i++)
28992928
if (instances[i])
@@ -2917,6 +2946,8 @@ static __exit void nfit_test_exit(void)
29172946
platform_driver_unregister(&nfit_test_driver);
29182947
nfit_test_teardown();
29192948

2949+
gen_pool_destroy(nfit_pool);
2950+
29202951
for (i = 0; i < NUM_NFITS; i++)
29212952
put_device(&instances[i]->pdev.dev);
29222953
class_destroy(nfit_test_dimm);

0 commit comments

Comments
 (0)