PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/s390/char/zcore.c

https://github.com/gby/linux
C | 366 lines | 286 code | 47 blank | 33 comment | 39 complexity | fa45b41d21691df3787e2140146b3682 MD5 | raw file
  1. /*
  2. * zcore module to export memory content and register sets for creating system
  3. * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
  4. * dump format as s390 standalone dumps.
  5. *
  6. * For more information please refer to Documentation/s390/zfcpdump.txt
  7. *
  8. * Copyright IBM Corp. 2003, 2008
  9. * Author(s): Michael Holzheu
  10. * License: GPL
  11. */
  12. #define KMSG_COMPONENT "zdump"
  13. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  14. #include <linux/init.h>
  15. #include <linux/slab.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/memblock.h>
  18. #include <asm/asm-offsets.h>
  19. #include <asm/ipl.h>
  20. #include <asm/sclp.h>
  21. #include <asm/setup.h>
  22. #include <linux/uaccess.h>
  23. #include <asm/debug.h>
  24. #include <asm/processor.h>
  25. #include <asm/irqflags.h>
  26. #include <asm/checksum.h>
  27. #include <asm/os_info.h>
  28. #include <asm/switch_to.h>
  29. #include "sclp.h"
  30. #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
  31. #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
  32. enum arch_id {
  33. ARCH_S390 = 0,
  34. ARCH_S390X = 1,
  35. };
  36. struct ipib_info {
  37. unsigned long ipib;
  38. u32 checksum;
  39. } __attribute__((packed));
  40. static struct debug_info *zcore_dbf;
  41. static int hsa_available;
  42. static struct dentry *zcore_dir;
  43. static struct dentry *zcore_memmap_file;
  44. static struct dentry *zcore_reipl_file;
  45. static struct dentry *zcore_hsa_file;
  46. static struct ipl_parameter_block *ipl_block;
  47. static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE);
  48. /*
  49. * Copy memory from HSA to user memory (not reentrant):
  50. *
  51. * @dest: User buffer where memory should be copied to
  52. * @src: Start address within HSA where data should be copied
  53. * @count: Size of buffer, which should be copied
  54. */
  55. int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
  56. {
  57. unsigned long offset, bytes;
  58. if (!hsa_available)
  59. return -ENODATA;
  60. while (count) {
  61. if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
  62. TRACE("sclp_sdias_copy() failed\n");
  63. return -EIO;
  64. }
  65. offset = src % PAGE_SIZE;
  66. bytes = min(PAGE_SIZE - offset, count);
  67. if (copy_to_user(dest, hsa_buf + offset, bytes))
  68. return -EFAULT;
  69. src += bytes;
  70. dest += bytes;
  71. count -= bytes;
  72. }
  73. return 0;
  74. }
  75. /*
  76. * Copy memory from HSA to kernel memory (not reentrant):
  77. *
  78. * @dest: Kernel or user buffer where memory should be copied to
  79. * @src: Start address within HSA where data should be copied
  80. * @count: Size of buffer, which should be copied
  81. */
  82. int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
  83. {
  84. unsigned long offset, bytes;
  85. if (!hsa_available)
  86. return -ENODATA;
  87. while (count) {
  88. if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
  89. TRACE("sclp_sdias_copy() failed\n");
  90. return -EIO;
  91. }
  92. offset = src % PAGE_SIZE;
  93. bytes = min(PAGE_SIZE - offset, count);
  94. memcpy(dest, hsa_buf + offset, bytes);
  95. src += bytes;
  96. dest += bytes;
  97. count -= bytes;
  98. }
  99. return 0;
  100. }
  101. static int __init init_cpu_info(void)
  102. {
  103. struct save_area *sa;
  104. /* get info for boot cpu from lowcore, stored in the HSA */
  105. sa = save_area_boot_cpu();
  106. if (!sa)
  107. return -ENOMEM;
  108. if (memcpy_hsa_kernel(hsa_buf, __LC_FPREGS_SAVE_AREA, 512) < 0) {
  109. TRACE("could not copy from HSA\n");
  110. return -EIO;
  111. }
  112. save_area_add_regs(sa, hsa_buf); /* vx registers are saved in smp.c */
  113. return 0;
  114. }
  115. /*
  116. * Release the HSA
  117. */
  118. static void release_hsa(void)
  119. {
  120. diag308(DIAG308_REL_HSA, NULL);
  121. hsa_available = 0;
  122. }
  123. static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
  124. size_t count, loff_t *ppos)
  125. {
  126. return simple_read_from_buffer(buf, count, ppos, filp->private_data,
  127. memblock.memory.cnt * CHUNK_INFO_SIZE);
  128. }
  129. static int zcore_memmap_open(struct inode *inode, struct file *filp)
  130. {
  131. struct memblock_region *reg;
  132. char *buf;
  133. int i = 0;
  134. buf = kzalloc(memblock.memory.cnt * CHUNK_INFO_SIZE, GFP_KERNEL);
  135. if (!buf) {
  136. return -ENOMEM;
  137. }
  138. for_each_memblock(memory, reg) {
  139. sprintf(buf + (i++ * CHUNK_INFO_SIZE), "%016llx %016llx ",
  140. (unsigned long long) reg->base,
  141. (unsigned long long) reg->size);
  142. }
  143. filp->private_data = buf;
  144. return nonseekable_open(inode, filp);
  145. }
  146. static int zcore_memmap_release(struct inode *inode, struct file *filp)
  147. {
  148. kfree(filp->private_data);
  149. return 0;
  150. }
  151. static const struct file_operations zcore_memmap_fops = {
  152. .owner = THIS_MODULE,
  153. .read = zcore_memmap_read,
  154. .open = zcore_memmap_open,
  155. .release = zcore_memmap_release,
  156. .llseek = no_llseek,
  157. };
  158. static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
  159. size_t count, loff_t *ppos)
  160. {
  161. if (ipl_block) {
  162. diag308(DIAG308_SET, ipl_block);
  163. diag308(DIAG308_LOAD_CLEAR, NULL);
  164. }
  165. return count;
  166. }
  167. static int zcore_reipl_open(struct inode *inode, struct file *filp)
  168. {
  169. return nonseekable_open(inode, filp);
  170. }
  171. static int zcore_reipl_release(struct inode *inode, struct file *filp)
  172. {
  173. return 0;
  174. }
  175. static const struct file_operations zcore_reipl_fops = {
  176. .owner = THIS_MODULE,
  177. .write = zcore_reipl_write,
  178. .open = zcore_reipl_open,
  179. .release = zcore_reipl_release,
  180. .llseek = no_llseek,
  181. };
  182. static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
  183. size_t count, loff_t *ppos)
  184. {
  185. static char str[18];
  186. if (hsa_available)
  187. snprintf(str, sizeof(str), "%lx\n", sclp.hsa_size);
  188. else
  189. snprintf(str, sizeof(str), "0\n");
  190. return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
  191. }
  192. static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
  193. size_t count, loff_t *ppos)
  194. {
  195. char value;
  196. if (*ppos != 0)
  197. return -EPIPE;
  198. if (copy_from_user(&value, buf, 1))
  199. return -EFAULT;
  200. if (value != '0')
  201. return -EINVAL;
  202. release_hsa();
  203. return count;
  204. }
  205. static const struct file_operations zcore_hsa_fops = {
  206. .owner = THIS_MODULE,
  207. .write = zcore_hsa_write,
  208. .read = zcore_hsa_read,
  209. .open = nonseekable_open,
  210. .llseek = no_llseek,
  211. };
  212. static int __init check_sdias(void)
  213. {
  214. if (!sclp.hsa_size) {
  215. TRACE("Could not determine HSA size\n");
  216. return -ENODEV;
  217. }
  218. return 0;
  219. }
  220. /*
  221. * Provide IPL parameter information block from either HSA or memory
  222. * for future reipl
  223. */
  224. static int __init zcore_reipl_init(void)
  225. {
  226. struct ipib_info ipib_info;
  227. int rc;
  228. rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
  229. if (rc)
  230. return rc;
  231. if (ipib_info.ipib == 0)
  232. return 0;
  233. ipl_block = (void *) __get_free_page(GFP_KERNEL);
  234. if (!ipl_block)
  235. return -ENOMEM;
  236. if (ipib_info.ipib < sclp.hsa_size)
  237. rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
  238. else
  239. rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
  240. if (rc || (__force u32)csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
  241. ipib_info.checksum) {
  242. TRACE("Checksum does not match\n");
  243. free_page((unsigned long) ipl_block);
  244. ipl_block = NULL;
  245. }
  246. return 0;
  247. }
  248. static int __init zcore_init(void)
  249. {
  250. unsigned char arch;
  251. int rc;
  252. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  253. return -ENODATA;
  254. if (OLDMEM_BASE)
  255. return -ENODATA;
  256. zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
  257. debug_register_view(zcore_dbf, &debug_sprintf_view);
  258. debug_set_level(zcore_dbf, 6);
  259. TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
  260. TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
  261. TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
  262. rc = sclp_sdias_init();
  263. if (rc)
  264. goto fail;
  265. rc = check_sdias();
  266. if (rc)
  267. goto fail;
  268. hsa_available = 1;
  269. rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
  270. if (rc)
  271. goto fail;
  272. if (arch == ARCH_S390) {
  273. pr_alert("The 64-bit dump tool cannot be used for a "
  274. "32-bit system\n");
  275. rc = -EINVAL;
  276. goto fail;
  277. }
  278. pr_alert("The dump process started for a 64-bit operating system\n");
  279. rc = init_cpu_info();
  280. if (rc)
  281. goto fail;
  282. rc = zcore_reipl_init();
  283. if (rc)
  284. goto fail;
  285. zcore_dir = debugfs_create_dir("zcore" , NULL);
  286. if (!zcore_dir) {
  287. rc = -ENOMEM;
  288. goto fail;
  289. }
  290. zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
  291. NULL, &zcore_memmap_fops);
  292. if (!zcore_memmap_file) {
  293. rc = -ENOMEM;
  294. goto fail_dir;
  295. }
  296. zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
  297. NULL, &zcore_reipl_fops);
  298. if (!zcore_reipl_file) {
  299. rc = -ENOMEM;
  300. goto fail_memmap_file;
  301. }
  302. zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
  303. NULL, &zcore_hsa_fops);
  304. if (!zcore_hsa_file) {
  305. rc = -ENOMEM;
  306. goto fail_reipl_file;
  307. }
  308. return 0;
  309. fail_reipl_file:
  310. debugfs_remove(zcore_reipl_file);
  311. fail_memmap_file:
  312. debugfs_remove(zcore_memmap_file);
  313. fail_dir:
  314. debugfs_remove(zcore_dir);
  315. fail:
  316. diag308(DIAG308_REL_HSA, NULL);
  317. return rc;
  318. }
  319. subsys_initcall(zcore_init);