1 // SPDX-License-Identifier: GPL-1.0+
3 * zcore module to export memory content and register sets for creating system
4 * dumps on SCSI/NVMe disks (zfcp/nvme dump).
6 * For more information please refer to Documentation/s390/zfcpdump.rst
8 * Copyright IBM Corp. 2003, 2008
9 * Author(s): Michael Holzheu
12 #define KMSG_COMPONENT "zdump"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/debugfs.h>
19 #include <asm/asm-offsets.h>
22 #include <asm/setup.h>
23 #include <linux/uaccess.h>
24 #include <asm/debug.h>
25 #include <asm/processor.h>
26 #include <asm/irqflags.h>
27 #include <asm/checksum.h>
28 #include <asm/os_info.h>
29 #include <asm/switch_to.h>
32 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
42 } __attribute__((packed));
44 static struct debug_info *zcore_dbf;
45 static int hsa_available;
46 static struct dentry *zcore_dir;
47 static struct dentry *zcore_reipl_file;
48 static struct dentry *zcore_hsa_file;
49 static struct ipl_parameter_block *zcore_ipl_block;
51 static DEFINE_MUTEX(hsa_buf_mutex);
52 static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE);
55 * Copy memory from HSA to user memory (not reentrant):
57 * @dest: User buffer where memory should be copied to
58 * @src: Start address within HSA where data should be copied
59 * @count: Size of buffer, which should be copied
61 int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
63 unsigned long offset, bytes;
68 mutex_lock(&hsa_buf_mutex);
70 if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
71 TRACE("sclp_sdias_copy() failed\n");
72 mutex_unlock(&hsa_buf_mutex);
75 offset = src % PAGE_SIZE;
76 bytes = min(PAGE_SIZE - offset, count);
77 if (copy_to_user(dest, hsa_buf + offset, bytes)) {
78 mutex_unlock(&hsa_buf_mutex);
85 mutex_unlock(&hsa_buf_mutex);
90 * Copy memory from HSA to kernel memory (not reentrant):
92 * @dest: Kernel or user buffer where memory should be copied to
93 * @src: Start address within HSA where data should be copied
94 * @count: Size of buffer, which should be copied
96 int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
98 unsigned long offset, bytes;
103 mutex_lock(&hsa_buf_mutex);
105 if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
106 TRACE("sclp_sdias_copy() failed\n");
107 mutex_unlock(&hsa_buf_mutex);
110 offset = src % PAGE_SIZE;
111 bytes = min(PAGE_SIZE - offset, count);
112 memcpy(dest, hsa_buf + offset, bytes);
117 mutex_unlock(&hsa_buf_mutex);
121 static int __init init_cpu_info(void)
123 struct save_area *sa;
125 /* get info for boot cpu from lowcore, stored in the HSA */
126 sa = save_area_boot_cpu();
129 if (memcpy_hsa_kernel(hsa_buf, __LC_FPREGS_SAVE_AREA, 512) < 0) {
130 TRACE("could not copy from HSA\n");
133 save_area_add_regs(sa, hsa_buf); /* vx registers are saved in smp.c */
140 static void release_hsa(void)
142 diag308(DIAG308_REL_HSA, NULL);
146 static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
147 size_t count, loff_t *ppos)
149 if (zcore_ipl_block) {
150 diag308(DIAG308_SET, zcore_ipl_block);
151 diag308(DIAG308_LOAD_CLEAR, NULL);
156 static int zcore_reipl_open(struct inode *inode, struct file *filp)
158 return stream_open(inode, filp);
161 static int zcore_reipl_release(struct inode *inode, struct file *filp)
166 static const struct file_operations zcore_reipl_fops = {
167 .owner = THIS_MODULE,
168 .write = zcore_reipl_write,
169 .open = zcore_reipl_open,
170 .release = zcore_reipl_release,
174 static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
175 size_t count, loff_t *ppos)
180 snprintf(str, sizeof(str), "%lx\n", sclp.hsa_size);
182 snprintf(str, sizeof(str), "0\n");
183 return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
186 static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
187 size_t count, loff_t *ppos)
193 if (copy_from_user(&value, buf, 1))
201 static const struct file_operations zcore_hsa_fops = {
202 .owner = THIS_MODULE,
203 .write = zcore_hsa_write,
204 .read = zcore_hsa_read,
205 .open = nonseekable_open,
209 static int __init check_sdias(void)
211 if (!sclp.hsa_size) {
212 TRACE("Could not determine HSA size\n");
219 * Provide IPL parameter information block from either HSA or memory
222 static int __init zcore_reipl_init(void)
224 struct ipib_info ipib_info;
227 rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
230 if (ipib_info.ipib == 0)
232 zcore_ipl_block = (void *) __get_free_page(GFP_KERNEL);
233 if (!zcore_ipl_block)
235 if (ipib_info.ipib < sclp.hsa_size)
236 rc = memcpy_hsa_kernel(zcore_ipl_block, ipib_info.ipib,
239 rc = memcpy_real(zcore_ipl_block, (void *) ipib_info.ipib,
241 if (rc || (__force u32)csum_partial(zcore_ipl_block, zcore_ipl_block->hdr.len, 0) !=
242 ipib_info.checksum) {
243 TRACE("Checksum does not match\n");
244 free_page((unsigned long) zcore_ipl_block);
245 zcore_ipl_block = NULL;
250 static int __init zcore_init(void)
255 if (!is_ipl_type_dump())
260 zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
261 debug_register_view(zcore_dbf, &debug_sprintf_view);
262 debug_set_level(zcore_dbf, 6);
264 if (ipl_info.type == IPL_TYPE_FCP_DUMP) {
265 TRACE("type: fcp\n");
266 TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
267 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
268 TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
269 } else if (ipl_info.type == IPL_TYPE_NVME_DUMP) {
270 TRACE("type: nvme\n");
271 TRACE("fid: %x\n", ipl_info.data.nvme.fid);
272 TRACE("nsid: %x\n", ipl_info.data.nvme.nsid);
275 rc = sclp_sdias_init();
284 rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
288 if (arch == ARCH_S390) {
289 pr_alert("The 64-bit dump tool cannot be used for a "
295 pr_alert("The dump process started for a 64-bit operating system\n");
296 rc = init_cpu_info();
300 rc = zcore_reipl_init();
304 zcore_dir = debugfs_create_dir("zcore" , NULL);
309 zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
310 NULL, &zcore_reipl_fops);
311 if (!zcore_reipl_file) {
315 zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
316 NULL, &zcore_hsa_fops);
317 if (!zcore_hsa_file) {
319 goto fail_reipl_file;
324 debugfs_remove(zcore_reipl_file);
326 debugfs_remove(zcore_dir);
328 diag308(DIAG308_REL_HSA, NULL);
331 subsys_initcall(zcore_init);