memory.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * Memory subsystem support
  3. *
  4. * Written by Matt Tolentino <matthew.e.tolentino@intel.com>
  5. * Dave Hansen <haveblue@us.ibm.com>
  6. *
  7. * This file provides the necessary infrastructure to represent
  8. * a SPARSEMEM-memory-model system's physical memory in /sysfs.
  9. * All arch-independent code that assumes MEMORY_HOTPLUG requires
  10. * SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/topology.h>
  15. #include <linux/capability.h>
  16. #include <linux/device.h>
  17. #include <linux/memory.h>
  18. #include <linux/kobject.h>
  19. #include <linux/memory_hotplug.h>
  20. #include <linux/mm.h>
  21. #include <linux/mutex.h>
  22. #include <linux/stat.h>
  23. #include <linux/slab.h>
  24. #include <linux/atomic.h>
  25. #include <asm/uaccess.h>
  26. static DEFINE_MUTEX(mem_sysfs_mutex);
  27. #define MEMORY_CLASS_NAME "memory"
  28. static int sections_per_block;
  29. static inline int base_memory_block_id(int section_nr)
  30. {
  31. return section_nr / sections_per_block;
  32. }
  33. static struct bus_type memory_subsys = {
  34. .name = MEMORY_CLASS_NAME,
  35. .dev_name = MEMORY_CLASS_NAME,
  36. };
  37. static BLOCKING_NOTIFIER_HEAD(memory_chain);
  38. int register_memory_notifier(struct notifier_block *nb)
  39. {
  40. return blocking_notifier_chain_register(&memory_chain, nb);
  41. }
  42. EXPORT_SYMBOL(register_memory_notifier);
  43. void unregister_memory_notifier(struct notifier_block *nb)
  44. {
  45. blocking_notifier_chain_unregister(&memory_chain, nb);
  46. }
  47. EXPORT_SYMBOL(unregister_memory_notifier);
  48. static ATOMIC_NOTIFIER_HEAD(memory_isolate_chain);
  49. int register_memory_isolate_notifier(struct notifier_block *nb)
  50. {
  51. return atomic_notifier_chain_register(&memory_isolate_chain, nb);
  52. }
  53. EXPORT_SYMBOL(register_memory_isolate_notifier);
  54. void unregister_memory_isolate_notifier(struct notifier_block *nb)
  55. {
  56. atomic_notifier_chain_unregister(&memory_isolate_chain, nb);
  57. }
  58. EXPORT_SYMBOL(unregister_memory_isolate_notifier);
  59. /*
  60. * register_memory - Setup a sysfs device for a memory block
  61. */
  62. static
  63. int register_memory(struct memory_block *memory)
  64. {
  65. int error;
  66. memory->dev.bus = &memory_subsys;
  67. memory->dev.id = memory->start_section_nr / sections_per_block;
  68. error = device_register(&memory->dev);
  69. return error;
  70. }
  71. static void
  72. unregister_memory(struct memory_block *memory)
  73. {
  74. BUG_ON(memory->dev.bus != &memory_subsys);
  75. /* drop the ref. we got in remove_memory_block() */
  76. kobject_put(&memory->dev.kobj);
  77. device_unregister(&memory->dev);
  78. }
  79. unsigned long __weak memory_block_size_bytes(void)
  80. {
  81. return MIN_MEMORY_BLOCK_SIZE;
  82. }
  83. static unsigned long get_memory_block_size(void)
  84. {
  85. unsigned long block_sz;
  86. block_sz = memory_block_size_bytes();
  87. /* Validate blk_sz is a power of 2 and not less than section size */
  88. if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) {
  89. WARN_ON(1);
  90. block_sz = MIN_MEMORY_BLOCK_SIZE;
  91. }
  92. return block_sz;
  93. }
  94. /*
  95. * use this as the physical section index that this memsection
  96. * uses.
  97. */
  98. static ssize_t show_mem_start_phys_index(struct device *dev,
  99. struct device_attribute *attr, char *buf)
  100. {
  101. struct memory_block *mem =
  102. container_of(dev, struct memory_block, dev);
  103. unsigned long phys_index;
  104. phys_index = mem->start_section_nr / sections_per_block;
  105. return sprintf(buf, "%08lx\n", phys_index);
  106. }
  107. static ssize_t show_mem_end_phys_index(struct device *dev,
  108. struct device_attribute *attr, char *buf)
  109. {
  110. struct memory_block *mem =
  111. container_of(dev, struct memory_block, dev);
  112. unsigned long phys_index;
  113. phys_index = mem->end_section_nr / sections_per_block;
  114. return sprintf(buf, "%08lx\n", phys_index);
  115. }
  116. /*
  117. * Show whether the section of memory is likely to be hot-removable
  118. */
  119. static ssize_t show_mem_removable(struct device *dev,
  120. struct device_attribute *attr, char *buf)
  121. {
  122. unsigned long i, pfn;
  123. int ret = 1;
  124. struct memory_block *mem =
  125. container_of(dev, struct memory_block, dev);
  126. for (i = 0; i < sections_per_block; i++) {
  127. pfn = section_nr_to_pfn(mem->start_section_nr + i);
  128. ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
  129. }
  130. return sprintf(buf, "%d\n", ret);
  131. }
  132. /*
  133. * online, offline, going offline, etc.
  134. */
  135. static ssize_t show_mem_state(struct device *dev,
  136. struct device_attribute *attr, char *buf)
  137. {
  138. struct memory_block *mem =
  139. container_of(dev, struct memory_block, dev);
  140. ssize_t len = 0;
  141. /*
  142. * We can probably put these states in a nice little array
  143. * so that they're not open-coded
  144. */
  145. switch (mem->state) {
  146. case MEM_ONLINE:
  147. len = sprintf(buf, "online\n");
  148. break;
  149. case MEM_OFFLINE:
  150. len = sprintf(buf, "offline\n");
  151. break;
  152. case MEM_GOING_OFFLINE:
  153. len = sprintf(buf, "going-offline\n");
  154. break;
  155. default:
  156. len = sprintf(buf, "ERROR-UNKNOWN-%ld\n",
  157. mem->state);
  158. WARN_ON(1);
  159. break;
  160. }
  161. return len;
  162. }
  163. int memory_notify(unsigned long val, void *v)
  164. {
  165. return blocking_notifier_call_chain(&memory_chain, val, v);
  166. }
  167. int memory_isolate_notify(unsigned long val, void *v)
  168. {
  169. return atomic_notifier_call_chain(&memory_isolate_chain, val, v);
  170. }
  171. /*
  172. * The probe routines leave the pages reserved, just as the bootmem code does.
  173. * Make sure they're still that way.
  174. */
  175. static bool pages_correctly_reserved(unsigned long start_pfn,
  176. unsigned long nr_pages)
  177. {
  178. int i, j;
  179. struct page *page;
  180. unsigned long pfn = start_pfn;
  181. /*
  182. * memmap between sections is not contiguous except with
  183. * SPARSEMEM_VMEMMAP. We lookup the page once per section
  184. * and assume memmap is contiguous within each section
  185. */
  186. for (i = 0; i < sections_per_block; i++, pfn += PAGES_PER_SECTION) {
  187. if (WARN_ON_ONCE(!pfn_valid(pfn)))
  188. return false;
  189. page = pfn_to_page(pfn);
  190. for (j = 0; j < PAGES_PER_SECTION; j++) {
  191. if (PageReserved(page + j))
  192. continue;
  193. printk(KERN_WARNING "section number %ld page number %d "
  194. "not reserved, was it already online?\n",
  195. pfn_to_section_nr(pfn), j);
  196. return false;
  197. }
  198. }
  199. return true;
  200. }
  201. /*
  202. * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
  203. * OK to have direct references to sparsemem variables in here.
  204. */
  205. static int
  206. memory_block_action(unsigned long phys_index, unsigned long action)
  207. {
  208. unsigned long start_pfn;
  209. unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
  210. struct page *first_page;
  211. int ret;
  212. first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT);
  213. start_pfn = page_to_pfn(first_page);
  214. switch (action) {
  215. case MEM_ONLINE:
  216. if (!pages_correctly_reserved(start_pfn, nr_pages))
  217. return -EBUSY;
  218. ret = online_pages(start_pfn, nr_pages);
  219. break;
  220. case MEM_OFFLINE:
  221. ret = offline_pages(start_pfn, nr_pages);
  222. break;
  223. default:
  224. WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
  225. "%ld\n", __func__, phys_index, action, action);
  226. ret = -EINVAL;
  227. }
  228. return ret;
  229. }
  230. static int __memory_block_change_state(struct memory_block *mem,
  231. unsigned long to_state, unsigned long from_state_req)
  232. {
  233. int ret = 0;
  234. if (mem->state != from_state_req) {
  235. ret = -EINVAL;
  236. goto out;
  237. }
  238. if (to_state == MEM_OFFLINE)
  239. mem->state = MEM_GOING_OFFLINE;
  240. ret = memory_block_action(mem->start_section_nr, to_state);
  241. if (ret) {
  242. mem->state = from_state_req;
  243. goto out;
  244. }
  245. mem->state = to_state;
  246. switch (mem->state) {
  247. case MEM_OFFLINE:
  248. kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE);
  249. break;
  250. case MEM_ONLINE:
  251. kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE);
  252. break;
  253. default:
  254. break;
  255. }
  256. out:
  257. return ret;
  258. }
  259. static int memory_block_change_state(struct memory_block *mem,
  260. unsigned long to_state, unsigned long from_state_req)
  261. {
  262. int ret;
  263. mutex_lock(&mem->state_mutex);
  264. ret = __memory_block_change_state(mem, to_state, from_state_req);
  265. mutex_unlock(&mem->state_mutex);
  266. return ret;
  267. }
  268. static ssize_t
  269. store_mem_state(struct device *dev,
  270. struct device_attribute *attr, const char *buf, size_t count)
  271. {
  272. struct memory_block *mem;
  273. int ret = -EINVAL;
  274. mem = container_of(dev, struct memory_block, dev);
  275. if (!strncmp(buf, "online", min((int)count, 6)))
  276. ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
  277. else if(!strncmp(buf, "offline", min((int)count, 7)))
  278. ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
  279. if (ret)
  280. return ret;
  281. return count;
  282. }
  283. /*
  284. * phys_device is a bad name for this. What I really want
  285. * is a way to differentiate between memory ranges that
  286. * are part of physical devices that constitute
  287. * a complete removable unit or fru.
  288. * i.e. do these ranges belong to the same physical device,
  289. * s.t. if I offline all of these sections I can then
  290. * remove the physical device?
  291. */
  292. static ssize_t show_phys_device(struct device *dev,
  293. struct device_attribute *attr, char *buf)
  294. {
  295. struct memory_block *mem =
  296. container_of(dev, struct memory_block, dev);
  297. return sprintf(buf, "%d\n", mem->phys_device);
  298. }
  299. static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
  300. static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
  301. static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
  302. static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
  303. static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
  304. #define mem_create_simple_file(mem, attr_name) \
  305. device_create_file(&mem->dev, &dev_attr_##attr_name)
  306. #define mem_remove_simple_file(mem, attr_name) \
  307. device_remove_file(&mem->dev, &dev_attr_##attr_name)
  308. /*
  309. * Block size attribute stuff
  310. */
  311. static ssize_t
  312. print_block_size(struct device *dev, struct device_attribute *attr,
  313. char *buf)
  314. {
  315. return sprintf(buf, "%lx\n", get_memory_block_size());
  316. }
  317. static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
  318. static int block_size_init(void)
  319. {
  320. return device_create_file(memory_subsys.dev_root,
  321. &dev_attr_block_size_bytes);
  322. }
  323. /*
  324. * Some architectures will have custom drivers to do this, and
  325. * will not need to do it from userspace. The fake hot-add code
  326. * as well as ppc64 will do all of their discovery in userspace
  327. * and will require this interface.
  328. */
  329. #ifdef CONFIG_ARCH_MEMORY_PROBE
  330. static ssize_t
  331. memory_probe_store(struct device *dev, struct device_attribute *attr,
  332. const char *buf, size_t count)
  333. {
  334. u64 phys_addr;
  335. int nid;
  336. int i, ret;
  337. unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block;
  338. phys_addr = simple_strtoull(buf, NULL, 0);
  339. if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
  340. return -EINVAL;
  341. for (i = 0; i < sections_per_block; i++) {
  342. nid = memory_add_physaddr_to_nid(phys_addr);
  343. ret = add_memory(nid, phys_addr,
  344. PAGES_PER_SECTION << PAGE_SHIFT);
  345. if (ret)
  346. goto out;
  347. phys_addr += MIN_MEMORY_BLOCK_SIZE;
  348. }
  349. ret = count;
  350. out:
  351. return ret;
  352. }
  353. static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
  354. static int memory_probe_init(void)
  355. {
  356. return device_create_file(memory_subsys.dev_root, &dev_attr_probe);
  357. }
  358. #else
  359. static inline int memory_probe_init(void)
  360. {
  361. return 0;
  362. }
  363. #endif
  364. #ifdef CONFIG_MEMORY_FAILURE
  365. /*
  366. * Support for offlining pages of memory
  367. */
  368. /* Soft offline a page */
  369. static ssize_t
  370. store_soft_offline_page(struct device *dev,
  371. struct device_attribute *attr,
  372. const char *buf, size_t count)
  373. {
  374. int ret;
  375. u64 pfn;
  376. if (!capable(CAP_SYS_ADMIN))
  377. return -EPERM;
  378. if (strict_strtoull(buf, 0, &pfn) < 0)
  379. return -EINVAL;
  380. pfn >>= PAGE_SHIFT;
  381. if (!pfn_valid(pfn))
  382. return -ENXIO;
  383. ret = soft_offline_page(pfn_to_page(pfn), 0);
  384. return ret == 0 ? count : ret;
  385. }
  386. /* Forcibly offline a page, including killing processes. */
  387. static ssize_t
  388. store_hard_offline_page(struct device *dev,
  389. struct device_attribute *attr,
  390. const char *buf, size_t count)
  391. {
  392. int ret;
  393. u64 pfn;
  394. if (!capable(CAP_SYS_ADMIN))
  395. return -EPERM;
  396. if (strict_strtoull(buf, 0, &pfn) < 0)
  397. return -EINVAL;
  398. pfn >>= PAGE_SHIFT;
  399. ret = memory_failure(pfn, 0, 0);
  400. return ret ? ret : count;
  401. }
  402. static DEVICE_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
  403. static DEVICE_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
  404. static __init int memory_fail_init(void)
  405. {
  406. int err;
  407. err = device_create_file(memory_subsys.dev_root,
  408. &dev_attr_soft_offline_page);
  409. if (!err)
  410. err = device_create_file(memory_subsys.dev_root,
  411. &dev_attr_hard_offline_page);
  412. return err;
  413. }
  414. #else
  415. static inline int memory_fail_init(void)
  416. {
  417. return 0;
  418. }
  419. #endif
  420. /*
  421. * Note that phys_device is optional. It is here to allow for
  422. * differentiation between which *physical* devices each
  423. * section belongs to...
  424. */
  425. int __weak arch_get_memory_phys_device(unsigned long start_pfn)
  426. {
  427. return 0;
  428. }
  429. /*
  430. * A reference for the returned object is held and the reference for the
  431. * hinted object is released.
  432. */
  433. struct memory_block *find_memory_block_hinted(struct mem_section *section,
  434. struct memory_block *hint)
  435. {
  436. int block_id = base_memory_block_id(__section_nr(section));
  437. struct device *hintdev = hint ? &hint->dev : NULL;
  438. struct device *dev;
  439. dev = subsys_find_device_by_id(&memory_subsys, block_id, hintdev);
  440. if (hint)
  441. put_device(&hint->dev);
  442. if (!dev)
  443. return NULL;
  444. return container_of(dev, struct memory_block, dev);
  445. }
  446. /*
  447. * For now, we have a linear search to go find the appropriate
  448. * memory_block corresponding to a particular phys_index. If
  449. * this gets to be a real problem, we can always use a radix
  450. * tree or something here.
  451. *
  452. * This could be made generic for all device subsystems.
  453. */
  454. struct memory_block *find_memory_block(struct mem_section *section)
  455. {
  456. return find_memory_block_hinted(section, NULL);
  457. }
  458. static int init_memory_block(struct memory_block **memory,
  459. struct mem_section *section, unsigned long state)
  460. {
  461. struct memory_block *mem;
  462. unsigned long start_pfn;
  463. int scn_nr;
  464. int ret = 0;
  465. mem = kzalloc(sizeof(*mem), GFP_KERNEL);
  466. if (!mem)
  467. return -ENOMEM;
  468. scn_nr = __section_nr(section);
  469. mem->start_section_nr =
  470. base_memory_block_id(scn_nr) * sections_per_block;
  471. mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
  472. mem->state = state;
  473. mem->section_count++;
  474. mutex_init(&mem->state_mutex);
  475. start_pfn = section_nr_to_pfn(mem->start_section_nr);
  476. mem->phys_device = arch_get_memory_phys_device(start_pfn);
  477. ret = register_memory(mem);
  478. if (!ret)
  479. ret = mem_create_simple_file(mem, phys_index);
  480. if (!ret)
  481. ret = mem_create_simple_file(mem, end_phys_index);
  482. if (!ret)
  483. ret = mem_create_simple_file(mem, state);
  484. if (!ret)
  485. ret = mem_create_simple_file(mem, phys_device);
  486. if (!ret)
  487. ret = mem_create_simple_file(mem, removable);
  488. *memory = mem;
  489. return ret;
  490. }
  491. static int add_memory_section(int nid, struct mem_section *section,
  492. struct memory_block **mem_p,
  493. unsigned long state, enum mem_add_context context)
  494. {
  495. struct memory_block *mem = NULL;
  496. int scn_nr = __section_nr(section);
  497. int ret = 0;
  498. mutex_lock(&mem_sysfs_mutex);
  499. if (context == BOOT) {
  500. /* same memory block ? */
  501. if (mem_p && *mem_p)
  502. if (scn_nr >= (*mem_p)->start_section_nr &&
  503. scn_nr <= (*mem_p)->end_section_nr) {
  504. mem = *mem_p;
  505. kobject_get(&mem->dev.kobj);
  506. }
  507. } else
  508. mem = find_memory_block(section);
  509. if (mem) {
  510. mem->section_count++;
  511. kobject_put(&mem->dev.kobj);
  512. } else {
  513. ret = init_memory_block(&mem, section, state);
  514. /* store memory_block pointer for next loop */
  515. if (!ret && context == BOOT)
  516. if (mem_p)
  517. *mem_p = mem;
  518. }
  519. if (!ret) {
  520. if (context == HOTPLUG &&
  521. mem->section_count == sections_per_block)
  522. ret = register_mem_sect_under_node(mem, nid);
  523. }
  524. mutex_unlock(&mem_sysfs_mutex);
  525. return ret;
  526. }
  527. int remove_memory_block(unsigned long node_id, struct mem_section *section,
  528. int phys_device)
  529. {
  530. struct memory_block *mem;
  531. mutex_lock(&mem_sysfs_mutex);
  532. mem = find_memory_block(section);
  533. unregister_mem_sect_under_nodes(mem, __section_nr(section));
  534. mem->section_count--;
  535. if (mem->section_count == 0) {
  536. mem_remove_simple_file(mem, phys_index);
  537. mem_remove_simple_file(mem, end_phys_index);
  538. mem_remove_simple_file(mem, state);
  539. mem_remove_simple_file(mem, phys_device);
  540. mem_remove_simple_file(mem, removable);
  541. unregister_memory(mem);
  542. kfree(mem);
  543. } else
  544. kobject_put(&mem->dev.kobj);
  545. mutex_unlock(&mem_sysfs_mutex);
  546. return 0;
  547. }
  548. /*
  549. * need an interface for the VM to add new memory regions,
  550. * but without onlining it.
  551. */
  552. int register_new_memory(int nid, struct mem_section *section)
  553. {
  554. return add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG);
  555. }
  556. int unregister_memory_section(struct mem_section *section)
  557. {
  558. if (!present_section(section))
  559. return -EINVAL;
  560. return remove_memory_block(0, section, 0);
  561. }
  562. /*
  563. * offline one memory block. If the memory block has been offlined, do nothing.
  564. */
  565. int offline_memory_block(struct memory_block *mem)
  566. {
  567. int ret = 0;
  568. mutex_lock(&mem->state_mutex);
  569. if (mem->state != MEM_OFFLINE)
  570. ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
  571. mutex_unlock(&mem->state_mutex);
  572. return ret;
  573. }
  574. /*
  575. * Initialize the sysfs support for memory devices...
  576. */
  577. int __init memory_dev_init(void)
  578. {
  579. unsigned int i;
  580. int ret;
  581. int err;
  582. unsigned long block_sz;
  583. struct memory_block *mem = NULL;
  584. ret = subsys_system_register(&memory_subsys, NULL);
  585. if (ret)
  586. goto out;
  587. block_sz = get_memory_block_size();
  588. sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
  589. /*
  590. * Create entries for memory sections that were found
  591. * during boot and have been initialized
  592. */
  593. for (i = 0; i < NR_MEM_SECTIONS; i++) {
  594. if (!present_section_nr(i))
  595. continue;
  596. /* don't need to reuse memory_block if only one per block */
  597. err = add_memory_section(0, __nr_to_section(i),
  598. (sections_per_block == 1) ? NULL : &mem,
  599. MEM_ONLINE,
  600. BOOT);
  601. if (!ret)
  602. ret = err;
  603. }
  604. err = memory_probe_init();
  605. if (!ret)
  606. ret = err;
  607. err = memory_fail_init();
  608. if (!ret)
  609. ret = err;
  610. err = block_size_init();
  611. if (!ret)
  612. ret = err;
  613. out:
  614. if (ret)
  615. printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
  616. return ret;
  617. }