region_devs.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*
  2. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. #include <linux/scatterlist.h>
  14. #include <linux/highmem.h>
  15. #include <linux/sched.h>
  16. #include <linux/slab.h>
  17. #include <linux/hash.h>
  18. #include <linux/sort.h>
  19. #include <linux/io.h>
  20. #include <linux/nd.h>
  21. #include "nd-core.h"
  22. #include "nd.h"
  23. /*
  24. * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is
  25. * irrelevant.
  26. */
  27. #include <linux/io-64-nonatomic-hi-lo.h>
  28. static DEFINE_IDA(region_ida);
  29. static DEFINE_PER_CPU(int, flush_idx);
  30. static int nvdimm_map_flush(struct device *dev, struct nvdimm *nvdimm, int dimm,
  31. struct nd_region_data *ndrd)
  32. {
  33. int i, j;
  34. dev_dbg(dev, "%s: map %d flush address%s\n", nvdimm_name(nvdimm),
  35. nvdimm->num_flush, nvdimm->num_flush == 1 ? "" : "es");
  36. for (i = 0; i < (1 << ndrd->hints_shift); i++) {
  37. struct resource *res = &nvdimm->flush_wpq[i];
  38. unsigned long pfn = PHYS_PFN(res->start);
  39. void __iomem *flush_page;
  40. /* check if flush hints share a page */
  41. for (j = 0; j < i; j++) {
  42. struct resource *res_j = &nvdimm->flush_wpq[j];
  43. unsigned long pfn_j = PHYS_PFN(res_j->start);
  44. if (pfn == pfn_j)
  45. break;
  46. }
  47. if (j < i)
  48. flush_page = (void __iomem *) ((unsigned long)
  49. ndrd_get_flush_wpq(ndrd, dimm, j)
  50. & PAGE_MASK);
  51. else
  52. flush_page = devm_nvdimm_ioremap(dev,
  53. PFN_PHYS(pfn), PAGE_SIZE);
  54. if (!flush_page)
  55. return -ENXIO;
  56. ndrd_set_flush_wpq(ndrd, dimm, i, flush_page
  57. + (res->start & ~PAGE_MASK));
  58. }
  59. return 0;
  60. }
  61. int nd_region_activate(struct nd_region *nd_region)
  62. {
  63. int i, j, num_flush = 0;
  64. struct nd_region_data *ndrd;
  65. struct device *dev = &nd_region->dev;
  66. size_t flush_data_size = sizeof(void *);
  67. nvdimm_bus_lock(&nd_region->dev);
  68. for (i = 0; i < nd_region->ndr_mappings; i++) {
  69. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  70. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  71. /* at least one null hint slot per-dimm for the "no-hint" case */
  72. flush_data_size += sizeof(void *);
  73. num_flush = min_not_zero(num_flush, nvdimm->num_flush);
  74. if (!nvdimm->num_flush)
  75. continue;
  76. flush_data_size += nvdimm->num_flush * sizeof(void *);
  77. }
  78. nvdimm_bus_unlock(&nd_region->dev);
  79. ndrd = devm_kzalloc(dev, sizeof(*ndrd) + flush_data_size, GFP_KERNEL);
  80. if (!ndrd)
  81. return -ENOMEM;
  82. dev_set_drvdata(dev, ndrd);
  83. if (!num_flush)
  84. return 0;
  85. ndrd->hints_shift = ilog2(num_flush);
  86. for (i = 0; i < nd_region->ndr_mappings; i++) {
  87. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  88. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  89. int rc = nvdimm_map_flush(&nd_region->dev, nvdimm, i, ndrd);
  90. if (rc)
  91. return rc;
  92. }
  93. /*
  94. * Clear out entries that are duplicates. This should prevent the
  95. * extra flushings.
  96. */
  97. for (i = 0; i < nd_region->ndr_mappings - 1; i++) {
  98. /* ignore if NULL already */
  99. if (!ndrd_get_flush_wpq(ndrd, i, 0))
  100. continue;
  101. for (j = i + 1; j < nd_region->ndr_mappings; j++)
  102. if (ndrd_get_flush_wpq(ndrd, i, 0) ==
  103. ndrd_get_flush_wpq(ndrd, j, 0))
  104. ndrd_set_flush_wpq(ndrd, j, 0, NULL);
  105. }
  106. return 0;
  107. }
  108. static void nd_region_release(struct device *dev)
  109. {
  110. struct nd_region *nd_region = to_nd_region(dev);
  111. u16 i;
  112. for (i = 0; i < nd_region->ndr_mappings; i++) {
  113. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  114. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  115. put_device(&nvdimm->dev);
  116. }
  117. free_percpu(nd_region->lane);
  118. ida_simple_remove(&region_ida, nd_region->id);
  119. if (is_nd_blk(dev))
  120. kfree(to_nd_blk_region(dev));
  121. else
  122. kfree(nd_region);
  123. }
  124. static struct device_type nd_blk_device_type = {
  125. .name = "nd_blk",
  126. .release = nd_region_release,
  127. };
  128. static struct device_type nd_pmem_device_type = {
  129. .name = "nd_pmem",
  130. .release = nd_region_release,
  131. };
  132. static struct device_type nd_volatile_device_type = {
  133. .name = "nd_volatile",
  134. .release = nd_region_release,
  135. };
  136. bool is_nd_pmem(struct device *dev)
  137. {
  138. return dev ? dev->type == &nd_pmem_device_type : false;
  139. }
  140. bool is_nd_blk(struct device *dev)
  141. {
  142. return dev ? dev->type == &nd_blk_device_type : false;
  143. }
  144. bool is_nd_volatile(struct device *dev)
  145. {
  146. return dev ? dev->type == &nd_volatile_device_type : false;
  147. }
  148. struct nd_region *to_nd_region(struct device *dev)
  149. {
  150. struct nd_region *nd_region = container_of(dev, struct nd_region, dev);
  151. WARN_ON(dev->type->release != nd_region_release);
  152. return nd_region;
  153. }
  154. EXPORT_SYMBOL_GPL(to_nd_region);
  155. struct device *nd_region_dev(struct nd_region *nd_region)
  156. {
  157. if (!nd_region)
  158. return NULL;
  159. return &nd_region->dev;
  160. }
  161. EXPORT_SYMBOL_GPL(nd_region_dev);
  162. struct nd_blk_region *to_nd_blk_region(struct device *dev)
  163. {
  164. struct nd_region *nd_region = to_nd_region(dev);
  165. WARN_ON(!is_nd_blk(dev));
  166. return container_of(nd_region, struct nd_blk_region, nd_region);
  167. }
  168. EXPORT_SYMBOL_GPL(to_nd_blk_region);
  169. void *nd_region_provider_data(struct nd_region *nd_region)
  170. {
  171. return nd_region->provider_data;
  172. }
  173. EXPORT_SYMBOL_GPL(nd_region_provider_data);
  174. void *nd_blk_region_provider_data(struct nd_blk_region *ndbr)
  175. {
  176. return ndbr->blk_provider_data;
  177. }
  178. EXPORT_SYMBOL_GPL(nd_blk_region_provider_data);
  179. void nd_blk_region_set_provider_data(struct nd_blk_region *ndbr, void *data)
  180. {
  181. ndbr->blk_provider_data = data;
  182. }
  183. EXPORT_SYMBOL_GPL(nd_blk_region_set_provider_data);
  184. /**
  185. * nd_region_to_nstype() - region to an integer namespace type
  186. * @nd_region: region-device to interrogate
  187. *
  188. * This is the 'nstype' attribute of a region as well, an input to the
  189. * MODALIAS for namespace devices, and bit number for a nvdimm_bus to match
  190. * namespace devices with namespace drivers.
  191. */
  192. int nd_region_to_nstype(struct nd_region *nd_region)
  193. {
  194. if (is_memory(&nd_region->dev)) {
  195. u16 i, alias;
  196. for (i = 0, alias = 0; i < nd_region->ndr_mappings; i++) {
  197. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  198. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  199. if (test_bit(NDD_ALIASING, &nvdimm->flags))
  200. alias++;
  201. }
  202. if (alias)
  203. return ND_DEVICE_NAMESPACE_PMEM;
  204. else
  205. return ND_DEVICE_NAMESPACE_IO;
  206. } else if (is_nd_blk(&nd_region->dev)) {
  207. return ND_DEVICE_NAMESPACE_BLK;
  208. }
  209. return 0;
  210. }
  211. EXPORT_SYMBOL(nd_region_to_nstype);
  212. static ssize_t size_show(struct device *dev,
  213. struct device_attribute *attr, char *buf)
  214. {
  215. struct nd_region *nd_region = to_nd_region(dev);
  216. unsigned long long size = 0;
  217. if (is_memory(dev)) {
  218. size = nd_region->ndr_size;
  219. } else if (nd_region->ndr_mappings == 1) {
  220. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  221. size = nd_mapping->size;
  222. }
  223. return sprintf(buf, "%llu\n", size);
  224. }
  225. static DEVICE_ATTR_RO(size);
  226. static ssize_t deep_flush_show(struct device *dev,
  227. struct device_attribute *attr, char *buf)
  228. {
  229. struct nd_region *nd_region = to_nd_region(dev);
  230. /*
  231. * NOTE: in the nvdimm_has_flush() error case this attribute is
  232. * not visible.
  233. */
  234. return sprintf(buf, "%d\n", nvdimm_has_flush(nd_region));
  235. }
  236. static ssize_t deep_flush_store(struct device *dev, struct device_attribute *attr,
  237. const char *buf, size_t len)
  238. {
  239. bool flush;
  240. int rc = strtobool(buf, &flush);
  241. struct nd_region *nd_region = to_nd_region(dev);
  242. if (rc)
  243. return rc;
  244. if (!flush)
  245. return -EINVAL;
  246. nvdimm_flush(nd_region);
  247. return len;
  248. }
  249. static DEVICE_ATTR_RW(deep_flush);
  250. static ssize_t mappings_show(struct device *dev,
  251. struct device_attribute *attr, char *buf)
  252. {
  253. struct nd_region *nd_region = to_nd_region(dev);
  254. return sprintf(buf, "%d\n", nd_region->ndr_mappings);
  255. }
  256. static DEVICE_ATTR_RO(mappings);
  257. static ssize_t nstype_show(struct device *dev,
  258. struct device_attribute *attr, char *buf)
  259. {
  260. struct nd_region *nd_region = to_nd_region(dev);
  261. return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region));
  262. }
  263. static DEVICE_ATTR_RO(nstype);
  264. static ssize_t set_cookie_show(struct device *dev,
  265. struct device_attribute *attr, char *buf)
  266. {
  267. struct nd_region *nd_region = to_nd_region(dev);
  268. struct nd_interleave_set *nd_set = nd_region->nd_set;
  269. ssize_t rc = 0;
  270. if (is_memory(dev) && nd_set)
  271. /* pass, should be precluded by region_visible */;
  272. else
  273. return -ENXIO;
  274. /*
  275. * The cookie to show depends on which specification of the
  276. * labels we are using. If there are not labels then default to
  277. * the v1.1 namespace label cookie definition. To read all this
  278. * data we need to wait for probing to settle.
  279. */
  280. device_lock(dev);
  281. nvdimm_bus_lock(dev);
  282. wait_nvdimm_bus_probe_idle(dev);
  283. if (nd_region->ndr_mappings) {
  284. struct nd_mapping *nd_mapping = &nd_region->mapping[0];
  285. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  286. if (ndd) {
  287. struct nd_namespace_index *nsindex;
  288. nsindex = to_namespace_index(ndd, ndd->ns_current);
  289. rc = sprintf(buf, "%#llx\n",
  290. nd_region_interleave_set_cookie(nd_region,
  291. nsindex));
  292. }
  293. }
  294. nvdimm_bus_unlock(dev);
  295. device_unlock(dev);
  296. if (rc)
  297. return rc;
  298. return sprintf(buf, "%#llx\n", nd_set->cookie1);
  299. }
  300. static DEVICE_ATTR_RO(set_cookie);
  301. resource_size_t nd_region_available_dpa(struct nd_region *nd_region)
  302. {
  303. resource_size_t blk_max_overlap = 0, available, overlap;
  304. int i;
  305. WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
  306. retry:
  307. available = 0;
  308. overlap = blk_max_overlap;
  309. for (i = 0; i < nd_region->ndr_mappings; i++) {
  310. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  311. struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
  312. /* if a dimm is disabled the available capacity is zero */
  313. if (!ndd)
  314. return 0;
  315. if (is_memory(&nd_region->dev)) {
  316. available += nd_pmem_available_dpa(nd_region,
  317. nd_mapping, &overlap);
  318. if (overlap > blk_max_overlap) {
  319. blk_max_overlap = overlap;
  320. goto retry;
  321. }
  322. } else if (is_nd_blk(&nd_region->dev))
  323. available += nd_blk_available_dpa(nd_region);
  324. }
  325. return available;
  326. }
  327. resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region)
  328. {
  329. resource_size_t available = 0;
  330. int i;
  331. if (is_memory(&nd_region->dev))
  332. available = PHYS_ADDR_MAX;
  333. WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
  334. for (i = 0; i < nd_region->ndr_mappings; i++) {
  335. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  336. if (is_memory(&nd_region->dev))
  337. available = min(available,
  338. nd_pmem_max_contiguous_dpa(nd_region,
  339. nd_mapping));
  340. else if (is_nd_blk(&nd_region->dev))
  341. available += nd_blk_available_dpa(nd_region);
  342. }
  343. if (is_memory(&nd_region->dev))
  344. return available * nd_region->ndr_mappings;
  345. return available;
  346. }
  347. static ssize_t available_size_show(struct device *dev,
  348. struct device_attribute *attr, char *buf)
  349. {
  350. struct nd_region *nd_region = to_nd_region(dev);
  351. unsigned long long available = 0;
  352. /*
  353. * Flush in-flight updates and grab a snapshot of the available
  354. * size. Of course, this value is potentially invalidated the
  355. * memory nvdimm_bus_lock() is dropped, but that's userspace's
  356. * problem to not race itself.
  357. */
  358. nvdimm_bus_lock(dev);
  359. wait_nvdimm_bus_probe_idle(dev);
  360. available = nd_region_available_dpa(nd_region);
  361. nvdimm_bus_unlock(dev);
  362. return sprintf(buf, "%llu\n", available);
  363. }
  364. static DEVICE_ATTR_RO(available_size);
  365. static ssize_t max_available_extent_show(struct device *dev,
  366. struct device_attribute *attr, char *buf)
  367. {
  368. struct nd_region *nd_region = to_nd_region(dev);
  369. unsigned long long available = 0;
  370. nvdimm_bus_lock(dev);
  371. wait_nvdimm_bus_probe_idle(dev);
  372. available = nd_region_allocatable_dpa(nd_region);
  373. nvdimm_bus_unlock(dev);
  374. return sprintf(buf, "%llu\n", available);
  375. }
  376. static DEVICE_ATTR_RO(max_available_extent);
  377. static ssize_t init_namespaces_show(struct device *dev,
  378. struct device_attribute *attr, char *buf)
  379. {
  380. struct nd_region_data *ndrd = dev_get_drvdata(dev);
  381. ssize_t rc;
  382. nvdimm_bus_lock(dev);
  383. if (ndrd)
  384. rc = sprintf(buf, "%d/%d\n", ndrd->ns_active, ndrd->ns_count);
  385. else
  386. rc = -ENXIO;
  387. nvdimm_bus_unlock(dev);
  388. return rc;
  389. }
  390. static DEVICE_ATTR_RO(init_namespaces);
  391. static ssize_t namespace_seed_show(struct device *dev,
  392. struct device_attribute *attr, char *buf)
  393. {
  394. struct nd_region *nd_region = to_nd_region(dev);
  395. ssize_t rc;
  396. nvdimm_bus_lock(dev);
  397. if (nd_region->ns_seed)
  398. rc = sprintf(buf, "%s\n", dev_name(nd_region->ns_seed));
  399. else
  400. rc = sprintf(buf, "\n");
  401. nvdimm_bus_unlock(dev);
  402. return rc;
  403. }
  404. static DEVICE_ATTR_RO(namespace_seed);
  405. static ssize_t btt_seed_show(struct device *dev,
  406. struct device_attribute *attr, char *buf)
  407. {
  408. struct nd_region *nd_region = to_nd_region(dev);
  409. ssize_t rc;
  410. nvdimm_bus_lock(dev);
  411. if (nd_region->btt_seed)
  412. rc = sprintf(buf, "%s\n", dev_name(nd_region->btt_seed));
  413. else
  414. rc = sprintf(buf, "\n");
  415. nvdimm_bus_unlock(dev);
  416. return rc;
  417. }
  418. static DEVICE_ATTR_RO(btt_seed);
  419. static ssize_t pfn_seed_show(struct device *dev,
  420. struct device_attribute *attr, char *buf)
  421. {
  422. struct nd_region *nd_region = to_nd_region(dev);
  423. ssize_t rc;
  424. nvdimm_bus_lock(dev);
  425. if (nd_region->pfn_seed)
  426. rc = sprintf(buf, "%s\n", dev_name(nd_region->pfn_seed));
  427. else
  428. rc = sprintf(buf, "\n");
  429. nvdimm_bus_unlock(dev);
  430. return rc;
  431. }
  432. static DEVICE_ATTR_RO(pfn_seed);
  433. static ssize_t dax_seed_show(struct device *dev,
  434. struct device_attribute *attr, char *buf)
  435. {
  436. struct nd_region *nd_region = to_nd_region(dev);
  437. ssize_t rc;
  438. nvdimm_bus_lock(dev);
  439. if (nd_region->dax_seed)
  440. rc = sprintf(buf, "%s\n", dev_name(nd_region->dax_seed));
  441. else
  442. rc = sprintf(buf, "\n");
  443. nvdimm_bus_unlock(dev);
  444. return rc;
  445. }
  446. static DEVICE_ATTR_RO(dax_seed);
  447. static ssize_t read_only_show(struct device *dev,
  448. struct device_attribute *attr, char *buf)
  449. {
  450. struct nd_region *nd_region = to_nd_region(dev);
  451. return sprintf(buf, "%d\n", nd_region->ro);
  452. }
  453. static ssize_t read_only_store(struct device *dev,
  454. struct device_attribute *attr, const char *buf, size_t len)
  455. {
  456. bool ro;
  457. int rc = strtobool(buf, &ro);
  458. struct nd_region *nd_region = to_nd_region(dev);
  459. if (rc)
  460. return rc;
  461. nd_region->ro = ro;
  462. return len;
  463. }
  464. static DEVICE_ATTR_RW(read_only);
  465. static ssize_t region_badblocks_show(struct device *dev,
  466. struct device_attribute *attr, char *buf)
  467. {
  468. struct nd_region *nd_region = to_nd_region(dev);
  469. ssize_t rc;
  470. device_lock(dev);
  471. if (dev->driver)
  472. rc = badblocks_show(&nd_region->bb, buf, 0);
  473. else
  474. rc = -ENXIO;
  475. device_unlock(dev);
  476. return rc;
  477. }
  478. static DEVICE_ATTR(badblocks, 0444, region_badblocks_show, NULL);
  479. static ssize_t resource_show(struct device *dev,
  480. struct device_attribute *attr, char *buf)
  481. {
  482. struct nd_region *nd_region = to_nd_region(dev);
  483. return sprintf(buf, "%#llx\n", nd_region->ndr_start);
  484. }
  485. static DEVICE_ATTR_RO(resource);
  486. static ssize_t persistence_domain_show(struct device *dev,
  487. struct device_attribute *attr, char *buf)
  488. {
  489. struct nd_region *nd_region = to_nd_region(dev);
  490. if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
  491. return sprintf(buf, "cpu_cache\n");
  492. else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
  493. return sprintf(buf, "memory_controller\n");
  494. else
  495. return sprintf(buf, "\n");
  496. }
  497. static DEVICE_ATTR_RO(persistence_domain);
  498. static struct attribute *nd_region_attributes[] = {
  499. &dev_attr_size.attr,
  500. &dev_attr_nstype.attr,
  501. &dev_attr_mappings.attr,
  502. &dev_attr_btt_seed.attr,
  503. &dev_attr_pfn_seed.attr,
  504. &dev_attr_dax_seed.attr,
  505. &dev_attr_deep_flush.attr,
  506. &dev_attr_read_only.attr,
  507. &dev_attr_set_cookie.attr,
  508. &dev_attr_available_size.attr,
  509. &dev_attr_max_available_extent.attr,
  510. &dev_attr_namespace_seed.attr,
  511. &dev_attr_init_namespaces.attr,
  512. &dev_attr_badblocks.attr,
  513. &dev_attr_resource.attr,
  514. &dev_attr_persistence_domain.attr,
  515. NULL,
  516. };
  517. static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)
  518. {
  519. struct device *dev = container_of(kobj, typeof(*dev), kobj);
  520. struct nd_region *nd_region = to_nd_region(dev);
  521. struct nd_interleave_set *nd_set = nd_region->nd_set;
  522. int type = nd_region_to_nstype(nd_region);
  523. if (!is_memory(dev) && a == &dev_attr_pfn_seed.attr)
  524. return 0;
  525. if (!is_memory(dev) && a == &dev_attr_dax_seed.attr)
  526. return 0;
  527. if (!is_nd_pmem(dev) && a == &dev_attr_badblocks.attr)
  528. return 0;
  529. if (a == &dev_attr_resource.attr) {
  530. if (is_nd_pmem(dev))
  531. return 0400;
  532. else
  533. return 0;
  534. }
  535. if (a == &dev_attr_deep_flush.attr) {
  536. int has_flush = nvdimm_has_flush(nd_region);
  537. if (has_flush == 1)
  538. return a->mode;
  539. else if (has_flush == 0)
  540. return 0444;
  541. else
  542. return 0;
  543. }
  544. if (a == &dev_attr_persistence_domain.attr) {
  545. if ((nd_region->flags & (BIT(ND_REGION_PERSIST_CACHE)
  546. | BIT(ND_REGION_PERSIST_MEMCTRL))) == 0)
  547. return 0;
  548. return a->mode;
  549. }
  550. if (a != &dev_attr_set_cookie.attr
  551. && a != &dev_attr_available_size.attr)
  552. return a->mode;
  553. if ((type == ND_DEVICE_NAMESPACE_PMEM
  554. || type == ND_DEVICE_NAMESPACE_BLK)
  555. && a == &dev_attr_available_size.attr)
  556. return a->mode;
  557. else if (is_memory(dev) && nd_set)
  558. return a->mode;
  559. return 0;
  560. }
  561. struct attribute_group nd_region_attribute_group = {
  562. .attrs = nd_region_attributes,
  563. .is_visible = region_visible,
  564. };
  565. EXPORT_SYMBOL_GPL(nd_region_attribute_group);
  566. u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
  567. struct nd_namespace_index *nsindex)
  568. {
  569. struct nd_interleave_set *nd_set = nd_region->nd_set;
  570. if (!nd_set)
  571. return 0;
  572. if (nsindex && __le16_to_cpu(nsindex->major) == 1
  573. && __le16_to_cpu(nsindex->minor) == 1)
  574. return nd_set->cookie1;
  575. return nd_set->cookie2;
  576. }
  577. u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region)
  578. {
  579. struct nd_interleave_set *nd_set = nd_region->nd_set;
  580. if (nd_set)
  581. return nd_set->altcookie;
  582. return 0;
  583. }
  584. void nd_mapping_free_labels(struct nd_mapping *nd_mapping)
  585. {
  586. struct nd_label_ent *label_ent, *e;
  587. lockdep_assert_held(&nd_mapping->lock);
  588. list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) {
  589. list_del(&label_ent->list);
  590. kfree(label_ent);
  591. }
  592. }
  593. /*
  594. * Upon successful probe/remove, take/release a reference on the
  595. * associated interleave set (if present), and plant new btt + namespace
  596. * seeds. Also, on the removal of a BLK region, notify the provider to
  597. * disable the region.
  598. */
  599. static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus,
  600. struct device *dev, bool probe)
  601. {
  602. struct nd_region *nd_region;
  603. if (!probe && is_nd_region(dev)) {
  604. int i;
  605. nd_region = to_nd_region(dev);
  606. for (i = 0; i < nd_region->ndr_mappings; i++) {
  607. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  608. struct nvdimm_drvdata *ndd = nd_mapping->ndd;
  609. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  610. mutex_lock(&nd_mapping->lock);
  611. nd_mapping_free_labels(nd_mapping);
  612. mutex_unlock(&nd_mapping->lock);
  613. put_ndd(ndd);
  614. nd_mapping->ndd = NULL;
  615. if (ndd)
  616. atomic_dec(&nvdimm->busy);
  617. }
  618. }
  619. if (dev->parent && is_nd_region(dev->parent) && probe) {
  620. nd_region = to_nd_region(dev->parent);
  621. nvdimm_bus_lock(dev);
  622. if (nd_region->ns_seed == dev)
  623. nd_region_create_ns_seed(nd_region);
  624. nvdimm_bus_unlock(dev);
  625. }
  626. if (is_nd_btt(dev) && probe) {
  627. struct nd_btt *nd_btt = to_nd_btt(dev);
  628. nd_region = to_nd_region(dev->parent);
  629. nvdimm_bus_lock(dev);
  630. if (nd_region->btt_seed == dev)
  631. nd_region_create_btt_seed(nd_region);
  632. if (nd_region->ns_seed == &nd_btt->ndns->dev)
  633. nd_region_create_ns_seed(nd_region);
  634. nvdimm_bus_unlock(dev);
  635. }
  636. if (is_nd_pfn(dev) && probe) {
  637. struct nd_pfn *nd_pfn = to_nd_pfn(dev);
  638. nd_region = to_nd_region(dev->parent);
  639. nvdimm_bus_lock(dev);
  640. if (nd_region->pfn_seed == dev)
  641. nd_region_create_pfn_seed(nd_region);
  642. if (nd_region->ns_seed == &nd_pfn->ndns->dev)
  643. nd_region_create_ns_seed(nd_region);
  644. nvdimm_bus_unlock(dev);
  645. }
  646. if (is_nd_dax(dev) && probe) {
  647. struct nd_dax *nd_dax = to_nd_dax(dev);
  648. nd_region = to_nd_region(dev->parent);
  649. nvdimm_bus_lock(dev);
  650. if (nd_region->dax_seed == dev)
  651. nd_region_create_dax_seed(nd_region);
  652. if (nd_region->ns_seed == &nd_dax->nd_pfn.ndns->dev)
  653. nd_region_create_ns_seed(nd_region);
  654. nvdimm_bus_unlock(dev);
  655. }
  656. }
  657. void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev)
  658. {
  659. nd_region_notify_driver_action(nvdimm_bus, dev, true);
  660. }
  661. void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev)
  662. {
  663. nd_region_notify_driver_action(nvdimm_bus, dev, false);
  664. }
  665. static ssize_t mappingN(struct device *dev, char *buf, int n)
  666. {
  667. struct nd_region *nd_region = to_nd_region(dev);
  668. struct nd_mapping *nd_mapping;
  669. struct nvdimm *nvdimm;
  670. if (n >= nd_region->ndr_mappings)
  671. return -ENXIO;
  672. nd_mapping = &nd_region->mapping[n];
  673. nvdimm = nd_mapping->nvdimm;
  674. return sprintf(buf, "%s,%llu,%llu,%d\n", dev_name(&nvdimm->dev),
  675. nd_mapping->start, nd_mapping->size,
  676. nd_mapping->position);
  677. }
  678. #define REGION_MAPPING(idx) \
  679. static ssize_t mapping##idx##_show(struct device *dev, \
  680. struct device_attribute *attr, char *buf) \
  681. { \
  682. return mappingN(dev, buf, idx); \
  683. } \
  684. static DEVICE_ATTR_RO(mapping##idx)
  685. /*
  686. * 32 should be enough for a while, even in the presence of socket
  687. * interleave a 32-way interleave set is a degenerate case.
  688. */
  689. REGION_MAPPING(0);
  690. REGION_MAPPING(1);
  691. REGION_MAPPING(2);
  692. REGION_MAPPING(3);
  693. REGION_MAPPING(4);
  694. REGION_MAPPING(5);
  695. REGION_MAPPING(6);
  696. REGION_MAPPING(7);
  697. REGION_MAPPING(8);
  698. REGION_MAPPING(9);
  699. REGION_MAPPING(10);
  700. REGION_MAPPING(11);
  701. REGION_MAPPING(12);
  702. REGION_MAPPING(13);
  703. REGION_MAPPING(14);
  704. REGION_MAPPING(15);
  705. REGION_MAPPING(16);
  706. REGION_MAPPING(17);
  707. REGION_MAPPING(18);
  708. REGION_MAPPING(19);
  709. REGION_MAPPING(20);
  710. REGION_MAPPING(21);
  711. REGION_MAPPING(22);
  712. REGION_MAPPING(23);
  713. REGION_MAPPING(24);
  714. REGION_MAPPING(25);
  715. REGION_MAPPING(26);
  716. REGION_MAPPING(27);
  717. REGION_MAPPING(28);
  718. REGION_MAPPING(29);
  719. REGION_MAPPING(30);
  720. REGION_MAPPING(31);
  721. static umode_t mapping_visible(struct kobject *kobj, struct attribute *a, int n)
  722. {
  723. struct device *dev = container_of(kobj, struct device, kobj);
  724. struct nd_region *nd_region = to_nd_region(dev);
  725. if (n < nd_region->ndr_mappings)
  726. return a->mode;
  727. return 0;
  728. }
  729. static struct attribute *mapping_attributes[] = {
  730. &dev_attr_mapping0.attr,
  731. &dev_attr_mapping1.attr,
  732. &dev_attr_mapping2.attr,
  733. &dev_attr_mapping3.attr,
  734. &dev_attr_mapping4.attr,
  735. &dev_attr_mapping5.attr,
  736. &dev_attr_mapping6.attr,
  737. &dev_attr_mapping7.attr,
  738. &dev_attr_mapping8.attr,
  739. &dev_attr_mapping9.attr,
  740. &dev_attr_mapping10.attr,
  741. &dev_attr_mapping11.attr,
  742. &dev_attr_mapping12.attr,
  743. &dev_attr_mapping13.attr,
  744. &dev_attr_mapping14.attr,
  745. &dev_attr_mapping15.attr,
  746. &dev_attr_mapping16.attr,
  747. &dev_attr_mapping17.attr,
  748. &dev_attr_mapping18.attr,
  749. &dev_attr_mapping19.attr,
  750. &dev_attr_mapping20.attr,
  751. &dev_attr_mapping21.attr,
  752. &dev_attr_mapping22.attr,
  753. &dev_attr_mapping23.attr,
  754. &dev_attr_mapping24.attr,
  755. &dev_attr_mapping25.attr,
  756. &dev_attr_mapping26.attr,
  757. &dev_attr_mapping27.attr,
  758. &dev_attr_mapping28.attr,
  759. &dev_attr_mapping29.attr,
  760. &dev_attr_mapping30.attr,
  761. &dev_attr_mapping31.attr,
  762. NULL,
  763. };
  764. struct attribute_group nd_mapping_attribute_group = {
  765. .is_visible = mapping_visible,
  766. .attrs = mapping_attributes,
  767. };
  768. EXPORT_SYMBOL_GPL(nd_mapping_attribute_group);
  769. int nd_blk_region_init(struct nd_region *nd_region)
  770. {
  771. struct device *dev = &nd_region->dev;
  772. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
  773. if (!is_nd_blk(dev))
  774. return 0;
  775. if (nd_region->ndr_mappings < 1) {
  776. dev_dbg(dev, "invalid BLK region\n");
  777. return -ENXIO;
  778. }
  779. return to_nd_blk_region(dev)->enable(nvdimm_bus, dev);
  780. }
  781. /**
  782. * nd_region_acquire_lane - allocate and lock a lane
  783. * @nd_region: region id and number of lanes possible
  784. *
  785. * A lane correlates to a BLK-data-window and/or a log slot in the BTT.
  786. * We optimize for the common case where there are 256 lanes, one
  787. * per-cpu. For larger systems we need to lock to share lanes. For now
  788. * this implementation assumes the cost of maintaining an allocator for
  789. * free lanes is on the order of the lock hold time, so it implements a
  790. * static lane = cpu % num_lanes mapping.
  791. *
  792. * In the case of a BTT instance on top of a BLK namespace a lane may be
  793. * acquired recursively. We lock on the first instance.
  794. *
  795. * In the case of a BTT instance on top of PMEM, we only acquire a lane
  796. * for the BTT metadata updates.
  797. */
  798. unsigned int nd_region_acquire_lane(struct nd_region *nd_region)
  799. {
  800. unsigned int cpu, lane;
  801. cpu = get_cpu();
  802. if (nd_region->num_lanes < nr_cpu_ids) {
  803. struct nd_percpu_lane *ndl_lock, *ndl_count;
  804. lane = cpu % nd_region->num_lanes;
  805. ndl_count = per_cpu_ptr(nd_region->lane, cpu);
  806. ndl_lock = per_cpu_ptr(nd_region->lane, lane);
  807. if (ndl_count->count++ == 0)
  808. spin_lock(&ndl_lock->lock);
  809. } else
  810. lane = cpu;
  811. return lane;
  812. }
  813. EXPORT_SYMBOL(nd_region_acquire_lane);
  814. void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane)
  815. {
  816. if (nd_region->num_lanes < nr_cpu_ids) {
  817. unsigned int cpu = get_cpu();
  818. struct nd_percpu_lane *ndl_lock, *ndl_count;
  819. ndl_count = per_cpu_ptr(nd_region->lane, cpu);
  820. ndl_lock = per_cpu_ptr(nd_region->lane, lane);
  821. if (--ndl_count->count == 0)
  822. spin_unlock(&ndl_lock->lock);
  823. put_cpu();
  824. }
  825. put_cpu();
  826. }
  827. EXPORT_SYMBOL(nd_region_release_lane);
  828. static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
  829. struct nd_region_desc *ndr_desc, struct device_type *dev_type,
  830. const char *caller)
  831. {
  832. struct nd_region *nd_region;
  833. struct device *dev;
  834. void *region_buf;
  835. unsigned int i;
  836. int ro = 0;
  837. for (i = 0; i < ndr_desc->num_mappings; i++) {
  838. struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
  839. struct nvdimm *nvdimm = mapping->nvdimm;
  840. if ((mapping->start | mapping->size) % SZ_4K) {
  841. dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
  842. caller, dev_name(&nvdimm->dev), i);
  843. return NULL;
  844. }
  845. if (test_bit(NDD_UNARMED, &nvdimm->flags))
  846. ro = 1;
  847. }
  848. if (dev_type == &nd_blk_device_type) {
  849. struct nd_blk_region_desc *ndbr_desc;
  850. struct nd_blk_region *ndbr;
  851. ndbr_desc = to_blk_region_desc(ndr_desc);
  852. ndbr = kzalloc(sizeof(*ndbr) + sizeof(struct nd_mapping)
  853. * ndr_desc->num_mappings,
  854. GFP_KERNEL);
  855. if (ndbr) {
  856. nd_region = &ndbr->nd_region;
  857. ndbr->enable = ndbr_desc->enable;
  858. ndbr->do_io = ndbr_desc->do_io;
  859. }
  860. region_buf = ndbr;
  861. } else {
  862. nd_region = kzalloc(sizeof(struct nd_region)
  863. + sizeof(struct nd_mapping)
  864. * ndr_desc->num_mappings,
  865. GFP_KERNEL);
  866. region_buf = nd_region;
  867. }
  868. if (!region_buf)
  869. return NULL;
  870. nd_region->id = ida_simple_get(&region_ida, 0, 0, GFP_KERNEL);
  871. if (nd_region->id < 0)
  872. goto err_id;
  873. nd_region->lane = alloc_percpu(struct nd_percpu_lane);
  874. if (!nd_region->lane)
  875. goto err_percpu;
  876. for (i = 0; i < nr_cpu_ids; i++) {
  877. struct nd_percpu_lane *ndl;
  878. ndl = per_cpu_ptr(nd_region->lane, i);
  879. spin_lock_init(&ndl->lock);
  880. ndl->count = 0;
  881. }
  882. for (i = 0; i < ndr_desc->num_mappings; i++) {
  883. struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
  884. struct nvdimm *nvdimm = mapping->nvdimm;
  885. nd_region->mapping[i].nvdimm = nvdimm;
  886. nd_region->mapping[i].start = mapping->start;
  887. nd_region->mapping[i].size = mapping->size;
  888. nd_region->mapping[i].position = mapping->position;
  889. INIT_LIST_HEAD(&nd_region->mapping[i].labels);
  890. mutex_init(&nd_region->mapping[i].lock);
  891. get_device(&nvdimm->dev);
  892. }
  893. nd_region->ndr_mappings = ndr_desc->num_mappings;
  894. nd_region->provider_data = ndr_desc->provider_data;
  895. nd_region->nd_set = ndr_desc->nd_set;
  896. nd_region->num_lanes = ndr_desc->num_lanes;
  897. nd_region->flags = ndr_desc->flags;
  898. nd_region->ro = ro;
  899. nd_region->numa_node = ndr_desc->numa_node;
  900. ida_init(&nd_region->ns_ida);
  901. ida_init(&nd_region->btt_ida);
  902. ida_init(&nd_region->pfn_ida);
  903. ida_init(&nd_region->dax_ida);
  904. dev = &nd_region->dev;
  905. dev_set_name(dev, "region%d", nd_region->id);
  906. dev->parent = &nvdimm_bus->dev;
  907. dev->type = dev_type;
  908. dev->groups = ndr_desc->attr_groups;
  909. dev->of_node = ndr_desc->of_node;
  910. nd_region->ndr_size = resource_size(ndr_desc->res);
  911. nd_region->ndr_start = ndr_desc->res->start;
  912. nd_device_register(dev);
  913. return nd_region;
  914. err_percpu:
  915. ida_simple_remove(&region_ida, nd_region->id);
  916. err_id:
  917. kfree(region_buf);
  918. return NULL;
  919. }
  920. struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
  921. struct nd_region_desc *ndr_desc)
  922. {
  923. ndr_desc->num_lanes = ND_MAX_LANES;
  924. return nd_region_create(nvdimm_bus, ndr_desc, &nd_pmem_device_type,
  925. __func__);
  926. }
  927. EXPORT_SYMBOL_GPL(nvdimm_pmem_region_create);
  928. struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
  929. struct nd_region_desc *ndr_desc)
  930. {
  931. if (ndr_desc->num_mappings > 1)
  932. return NULL;
  933. ndr_desc->num_lanes = min(ndr_desc->num_lanes, ND_MAX_LANES);
  934. return nd_region_create(nvdimm_bus, ndr_desc, &nd_blk_device_type,
  935. __func__);
  936. }
  937. EXPORT_SYMBOL_GPL(nvdimm_blk_region_create);
  938. struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
  939. struct nd_region_desc *ndr_desc)
  940. {
  941. ndr_desc->num_lanes = ND_MAX_LANES;
  942. return nd_region_create(nvdimm_bus, ndr_desc, &nd_volatile_device_type,
  943. __func__);
  944. }
  945. EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create);
  946. /**
  947. * nvdimm_flush - flush any posted write queues between the cpu and pmem media
  948. * @nd_region: blk or interleaved pmem region
  949. */
  950. void nvdimm_flush(struct nd_region *nd_region)
  951. {
  952. struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
  953. int i, idx;
  954. /*
  955. * Try to encourage some diversity in flush hint addresses
  956. * across cpus assuming a limited number of flush hints.
  957. */
  958. idx = this_cpu_read(flush_idx);
  959. idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8));
  960. /*
  961. * The first wmb() is needed to 'sfence' all previous writes
  962. * such that they are architecturally visible for the platform
  963. * buffer flush. Note that we've already arranged for pmem
  964. * writes to avoid the cache via memcpy_flushcache(). The final
  965. * wmb() ensures ordering for the NVDIMM flush write.
  966. */
  967. wmb();
  968. for (i = 0; i < nd_region->ndr_mappings; i++)
  969. if (ndrd_get_flush_wpq(ndrd, i, 0))
  970. writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
  971. wmb();
  972. }
  973. EXPORT_SYMBOL_GPL(nvdimm_flush);
  974. /**
  975. * nvdimm_has_flush - determine write flushing requirements
  976. * @nd_region: blk or interleaved pmem region
  977. *
  978. * Returns 1 if writes require flushing
  979. * Returns 0 if writes do not require flushing
  980. * Returns -ENXIO if flushing capability can not be determined
  981. */
  982. int nvdimm_has_flush(struct nd_region *nd_region)
  983. {
  984. int i;
  985. /* no nvdimm or pmem api == flushing capability unknown */
  986. if (nd_region->ndr_mappings == 0
  987. || !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
  988. return -ENXIO;
  989. for (i = 0; i < nd_region->ndr_mappings; i++) {
  990. struct nd_mapping *nd_mapping = &nd_region->mapping[i];
  991. struct nvdimm *nvdimm = nd_mapping->nvdimm;
  992. /* flush hints present / available */
  993. if (nvdimm->num_flush)
  994. return 1;
  995. }
  996. /*
  997. * The platform defines dimm devices without hints, assume
  998. * platform persistence mechanism like ADR
  999. */
  1000. return 0;
  1001. }
  1002. EXPORT_SYMBOL_GPL(nvdimm_has_flush);
  1003. int nvdimm_has_cache(struct nd_region *nd_region)
  1004. {
  1005. return is_nd_pmem(&nd_region->dev) &&
  1006. !test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags);
  1007. }
  1008. EXPORT_SYMBOL_GPL(nvdimm_has_cache);
  1009. struct conflict_context {
  1010. struct nd_region *nd_region;
  1011. resource_size_t start, size;
  1012. };
  1013. static int region_conflict(struct device *dev, void *data)
  1014. {
  1015. struct nd_region *nd_region;
  1016. struct conflict_context *ctx = data;
  1017. resource_size_t res_end, region_end, region_start;
  1018. if (!is_memory(dev))
  1019. return 0;
  1020. nd_region = to_nd_region(dev);
  1021. if (nd_region == ctx->nd_region)
  1022. return 0;
  1023. res_end = ctx->start + ctx->size;
  1024. region_start = nd_region->ndr_start;
  1025. region_end = region_start + nd_region->ndr_size;
  1026. if (ctx->start >= region_start && ctx->start < region_end)
  1027. return -EBUSY;
  1028. if (res_end > region_start && res_end <= region_end)
  1029. return -EBUSY;
  1030. return 0;
  1031. }
  1032. int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
  1033. resource_size_t size)
  1034. {
  1035. struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
  1036. struct conflict_context ctx = {
  1037. .nd_region = nd_region,
  1038. .start = start,
  1039. .size = size,
  1040. };
  1041. return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict);
  1042. }
  1043. void __exit nd_region_devs_exit(void)
  1044. {
  1045. ida_destroy(&region_ida);
  1046. }