1 // SPDX-License-Identifier: GPL-1.0+
3 * zcore module to export memory content and register sets for creating system
4 * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
5 * dump format as s390 standalone dumps.
7 * For more information please refer to Documentation/s390/zfcpdump.rst
9 * Copyright IBM Corp. 2003, 2008
10 * Author(s): Michael Holzheu
13 #define KMSG_COMPONENT "zdump"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/debugfs.h>
19 #include <linux/memblock.h>
21 #include <asm/asm-offsets.h>
24 #include <asm/setup.h>
25 #include <linux/uaccess.h>
26 #include <asm/debug.h>
27 #include <asm/processor.h>
28 #include <asm/irqflags.h>
29 #include <asm/checksum.h>
30 #include <asm/os_info.h>
31 #include <asm/switch_to.h>
34 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
36 #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
46 } __attribute__((packed
));
48 static struct debug_info
*zcore_dbf
;
49 static int hsa_available
;
50 static struct dentry
*zcore_dir
;
51 static struct dentry
*zcore_memmap_file
;
52 static struct dentry
*zcore_reipl_file
;
53 static struct dentry
*zcore_hsa_file
;
54 static struct ipl_parameter_block
*zcore_ipl_block
;
56 static char hsa_buf
[PAGE_SIZE
] __aligned(PAGE_SIZE
);
59 * Copy memory from HSA to user memory (not reentrant):
61 * @dest: User buffer where memory should be copied to
62 * @src: Start address within HSA where data should be copied
63 * @count: Size of buffer, which should be copied
65 int memcpy_hsa_user(void __user
*dest
, unsigned long src
, size_t count
)
67 unsigned long offset
, bytes
;
73 if (sclp_sdias_copy(hsa_buf
, src
/ PAGE_SIZE
+ 2, 1)) {
74 TRACE("sclp_sdias_copy() failed\n");
77 offset
= src
% PAGE_SIZE
;
78 bytes
= min(PAGE_SIZE
- offset
, count
);
79 if (copy_to_user(dest
, hsa_buf
+ offset
, bytes
))
89 * Copy memory from HSA to kernel memory (not reentrant):
91 * @dest: Kernel or user buffer where memory should be copied to
92 * @src: Start address within HSA where data should be copied
93 * @count: Size of buffer, which should be copied
95 int memcpy_hsa_kernel(void *dest
, unsigned long src
, size_t count
)
97 unsigned long offset
, bytes
;
103 if (sclp_sdias_copy(hsa_buf
, src
/ PAGE_SIZE
+ 2, 1)) {
104 TRACE("sclp_sdias_copy() failed\n");
107 offset
= src
% PAGE_SIZE
;
108 bytes
= min(PAGE_SIZE
- offset
, count
);
109 memcpy(dest
, hsa_buf
+ offset
, bytes
);
117 static int __init
init_cpu_info(void)
119 struct save_area
*sa
;
121 /* get info for boot cpu from lowcore, stored in the HSA */
122 sa
= save_area_boot_cpu();
125 if (memcpy_hsa_kernel(hsa_buf
, __LC_FPREGS_SAVE_AREA
, 512) < 0) {
126 TRACE("could not copy from HSA\n");
129 save_area_add_regs(sa
, hsa_buf
); /* vx registers are saved in smp.c */
136 static void release_hsa(void)
138 diag308(DIAG308_REL_HSA
, NULL
);
142 static ssize_t
zcore_memmap_read(struct file
*filp
, char __user
*buf
,
143 size_t count
, loff_t
*ppos
)
145 return simple_read_from_buffer(buf
, count
, ppos
, filp
->private_data
,
146 memblock
.memory
.cnt
* CHUNK_INFO_SIZE
);
149 static int zcore_memmap_open(struct inode
*inode
, struct file
*filp
)
151 struct memblock_region
*reg
;
155 buf
= kcalloc(memblock
.memory
.cnt
, CHUNK_INFO_SIZE
, GFP_KERNEL
);
159 for_each_memblock(memory
, reg
) {
160 sprintf(buf
+ (i
++ * CHUNK_INFO_SIZE
), "%016llx %016llx ",
161 (unsigned long long) reg
->base
,
162 (unsigned long long) reg
->size
);
164 filp
->private_data
= buf
;
165 return nonseekable_open(inode
, filp
);
168 static int zcore_memmap_release(struct inode
*inode
, struct file
*filp
)
170 kfree(filp
->private_data
);
174 static const struct file_operations zcore_memmap_fops
= {
175 .owner
= THIS_MODULE
,
176 .read
= zcore_memmap_read
,
177 .open
= zcore_memmap_open
,
178 .release
= zcore_memmap_release
,
182 static ssize_t
zcore_reipl_write(struct file
*filp
, const char __user
*buf
,
183 size_t count
, loff_t
*ppos
)
185 if (zcore_ipl_block
) {
186 diag308(DIAG308_SET
, zcore_ipl_block
);
187 diag308(DIAG308_LOAD_CLEAR
, NULL
);
192 static int zcore_reipl_open(struct inode
*inode
, struct file
*filp
)
194 return stream_open(inode
, filp
);
197 static int zcore_reipl_release(struct inode
*inode
, struct file
*filp
)
202 static const struct file_operations zcore_reipl_fops
= {
203 .owner
= THIS_MODULE
,
204 .write
= zcore_reipl_write
,
205 .open
= zcore_reipl_open
,
206 .release
= zcore_reipl_release
,
210 static ssize_t
zcore_hsa_read(struct file
*filp
, char __user
*buf
,
211 size_t count
, loff_t
*ppos
)
216 snprintf(str
, sizeof(str
), "%lx\n", sclp
.hsa_size
);
218 snprintf(str
, sizeof(str
), "0\n");
219 return simple_read_from_buffer(buf
, count
, ppos
, str
, strlen(str
));
222 static ssize_t
zcore_hsa_write(struct file
*filp
, const char __user
*buf
,
223 size_t count
, loff_t
*ppos
)
229 if (copy_from_user(&value
, buf
, 1))
237 static const struct file_operations zcore_hsa_fops
= {
238 .owner
= THIS_MODULE
,
239 .write
= zcore_hsa_write
,
240 .read
= zcore_hsa_read
,
241 .open
= nonseekable_open
,
245 static int __init
check_sdias(void)
247 if (!sclp
.hsa_size
) {
248 TRACE("Could not determine HSA size\n");
255 * Provide IPL parameter information block from either HSA or memory
258 static int __init
zcore_reipl_init(void)
260 struct ipib_info ipib_info
;
263 rc
= memcpy_hsa_kernel(&ipib_info
, __LC_DUMP_REIPL
, sizeof(ipib_info
));
266 if (ipib_info
.ipib
== 0)
268 zcore_ipl_block
= (void *) __get_free_page(GFP_KERNEL
);
269 if (!zcore_ipl_block
)
271 if (ipib_info
.ipib
< sclp
.hsa_size
)
272 rc
= memcpy_hsa_kernel(zcore_ipl_block
, ipib_info
.ipib
,
275 rc
= memcpy_real(zcore_ipl_block
, (void *) ipib_info
.ipib
,
277 if (rc
|| (__force u32
)csum_partial(zcore_ipl_block
, zcore_ipl_block
->hdr
.len
, 0) !=
278 ipib_info
.checksum
) {
279 TRACE("Checksum does not match\n");
280 free_page((unsigned long) zcore_ipl_block
);
281 zcore_ipl_block
= NULL
;
286 static int __init
zcore_init(void)
291 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
296 zcore_dbf
= debug_register("zcore", 4, 1, 4 * sizeof(long));
297 debug_register_view(zcore_dbf
, &debug_sprintf_view
);
298 debug_set_level(zcore_dbf
, 6);
300 TRACE("devno: %x\n", ipl_info
.data
.fcp
.dev_id
.devno
);
301 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.wwpn
);
302 TRACE("lun: %llx\n", (unsigned long long) ipl_info
.data
.fcp
.lun
);
304 rc
= sclp_sdias_init();
313 rc
= memcpy_hsa_kernel(&arch
, __LC_AR_MODE_ID
, 1);
317 if (arch
== ARCH_S390
) {
318 pr_alert("The 64-bit dump tool cannot be used for a "
324 pr_alert("The dump process started for a 64-bit operating system\n");
325 rc
= init_cpu_info();
329 rc
= zcore_reipl_init();
333 zcore_dir
= debugfs_create_dir("zcore" , NULL
);
338 zcore_memmap_file
= debugfs_create_file("memmap", S_IRUSR
, zcore_dir
,
339 NULL
, &zcore_memmap_fops
);
340 if (!zcore_memmap_file
) {
344 zcore_reipl_file
= debugfs_create_file("reipl", S_IRUSR
, zcore_dir
,
345 NULL
, &zcore_reipl_fops
);
346 if (!zcore_reipl_file
) {
348 goto fail_memmap_file
;
350 zcore_hsa_file
= debugfs_create_file("hsa", S_IRUSR
|S_IWUSR
, zcore_dir
,
351 NULL
, &zcore_hsa_fops
);
352 if (!zcore_hsa_file
) {
354 goto fail_reipl_file
;
359 debugfs_remove(zcore_reipl_file
);
361 debugfs_remove(zcore_memmap_file
);
363 debugfs_remove(zcore_dir
);
365 diag308(DIAG308_REL_HSA
, NULL
);
368 subsys_initcall(zcore_init
);