forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/s390/char/zcore.c
....@@ -1,10 +1,9 @@
11 // SPDX-License-Identifier: GPL-1.0+
22 /*
33 * 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.
4
+ * dumps on SCSI/NVMe disks (zfcp/nvme dump).
65 *
7
- * For more information please refer to Documentation/s390/zfcpdump.txt
6
+ * For more information please refer to Documentation/s390/zfcpdump.rst
87 *
98 * Copyright IBM Corp. 2003, 2008
109 * Author(s): Michael Holzheu
....@@ -16,7 +15,6 @@
1615 #include <linux/init.h>
1716 #include <linux/slab.h>
1817 #include <linux/debugfs.h>
19
-#include <linux/memblock.h>
2018
2119 #include <asm/asm-offsets.h>
2220 #include <asm/ipl.h>
....@@ -33,8 +31,6 @@
3331
3432 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
3533
36
-#define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
37
-
3834 enum arch_id {
3935 ARCH_S390 = 0,
4036 ARCH_S390X = 1,
....@@ -48,11 +44,11 @@
4844 static struct debug_info *zcore_dbf;
4945 static int hsa_available;
5046 static struct dentry *zcore_dir;
51
-static struct dentry *zcore_memmap_file;
5247 static struct dentry *zcore_reipl_file;
5348 static struct dentry *zcore_hsa_file;
54
-static struct ipl_parameter_block *ipl_block;
49
+static struct ipl_parameter_block *zcore_ipl_block;
5550
51
+static DEFINE_MUTEX(hsa_buf_mutex);
5652 static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE);
5753
5854 /*
....@@ -69,19 +65,24 @@
6965 if (!hsa_available)
7066 return -ENODATA;
7167
68
+ mutex_lock(&hsa_buf_mutex);
7269 while (count) {
7370 if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
7471 TRACE("sclp_sdias_copy() failed\n");
72
+ mutex_unlock(&hsa_buf_mutex);
7573 return -EIO;
7674 }
7775 offset = src % PAGE_SIZE;
7876 bytes = min(PAGE_SIZE - offset, count);
79
- if (copy_to_user(dest, hsa_buf + offset, bytes))
77
+ if (copy_to_user(dest, hsa_buf + offset, bytes)) {
78
+ mutex_unlock(&hsa_buf_mutex);
8079 return -EFAULT;
80
+ }
8181 src += bytes;
8282 dest += bytes;
8383 count -= bytes;
8484 }
85
+ mutex_unlock(&hsa_buf_mutex);
8586 return 0;
8687 }
8788
....@@ -99,9 +100,11 @@
99100 if (!hsa_available)
100101 return -ENODATA;
101102
103
+ mutex_lock(&hsa_buf_mutex);
102104 while (count) {
103105 if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
104106 TRACE("sclp_sdias_copy() failed\n");
107
+ mutex_unlock(&hsa_buf_mutex);
105108 return -EIO;
106109 }
107110 offset = src % PAGE_SIZE;
....@@ -111,6 +114,7 @@
111114 dest += bytes;
112115 count -= bytes;
113116 }
117
+ mutex_unlock(&hsa_buf_mutex);
114118 return 0;
115119 }
116120
....@@ -139,51 +143,11 @@
139143 hsa_available = 0;
140144 }
141145
142
-static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
143
- size_t count, loff_t *ppos)
144
-{
145
- return simple_read_from_buffer(buf, count, ppos, filp->private_data,
146
- memblock.memory.cnt * CHUNK_INFO_SIZE);
147
-}
148
-
149
-static int zcore_memmap_open(struct inode *inode, struct file *filp)
150
-{
151
- struct memblock_region *reg;
152
- char *buf;
153
- int i = 0;
154
-
155
- buf = kcalloc(memblock.memory.cnt, CHUNK_INFO_SIZE, GFP_KERNEL);
156
- if (!buf) {
157
- return -ENOMEM;
158
- }
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);
163
- }
164
- filp->private_data = buf;
165
- return nonseekable_open(inode, filp);
166
-}
167
-
168
-static int zcore_memmap_release(struct inode *inode, struct file *filp)
169
-{
170
- kfree(filp->private_data);
171
- return 0;
172
-}
173
-
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,
179
- .llseek = no_llseek,
180
-};
181
-
182146 static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
183147 size_t count, loff_t *ppos)
184148 {
185
- if (ipl_block) {
186
- diag308(DIAG308_SET, ipl_block);
149
+ if (zcore_ipl_block) {
150
+ diag308(DIAG308_SET, zcore_ipl_block);
187151 diag308(DIAG308_LOAD_CLEAR, NULL);
188152 }
189153 return count;
....@@ -191,7 +155,7 @@
191155
192156 static int zcore_reipl_open(struct inode *inode, struct file *filp)
193157 {
194
- return nonseekable_open(inode, filp);
158
+ return stream_open(inode, filp);
195159 }
196160
197161 static int zcore_reipl_release(struct inode *inode, struct file *filp)
....@@ -265,18 +229,20 @@
265229 return rc;
266230 if (ipib_info.ipib == 0)
267231 return 0;
268
- ipl_block = (void *) __get_free_page(GFP_KERNEL);
269
- if (!ipl_block)
232
+ zcore_ipl_block = (void *) __get_free_page(GFP_KERNEL);
233
+ if (!zcore_ipl_block)
270234 return -ENOMEM;
271235 if (ipib_info.ipib < sclp.hsa_size)
272
- rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
236
+ rc = memcpy_hsa_kernel(zcore_ipl_block, ipib_info.ipib,
237
+ PAGE_SIZE);
273238 else
274
- rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
275
- if (rc || (__force u32)csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
239
+ rc = memcpy_real(zcore_ipl_block, (void *) ipib_info.ipib,
240
+ PAGE_SIZE);
241
+ if (rc || (__force u32)csum_partial(zcore_ipl_block, zcore_ipl_block->hdr.len, 0) !=
276242 ipib_info.checksum) {
277243 TRACE("Checksum does not match\n");
278
- free_page((unsigned long) ipl_block);
279
- ipl_block = NULL;
244
+ free_page((unsigned long) zcore_ipl_block);
245
+ zcore_ipl_block = NULL;
280246 }
281247 return 0;
282248 }
....@@ -286,7 +252,7 @@
286252 unsigned char arch;
287253 int rc;
288254
289
- if (ipl_info.type != IPL_TYPE_FCP_DUMP)
255
+ if (!is_ipl_type_dump())
290256 return -ENODATA;
291257 if (OLDMEM_BASE)
292258 return -ENODATA;
....@@ -295,9 +261,16 @@
295261 debug_register_view(zcore_dbf, &debug_sprintf_view);
296262 debug_set_level(zcore_dbf, 6);
297263
298
- TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
299
- TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
300
- TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
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);
273
+ }
301274
302275 rc = sclp_sdias_init();
303276 if (rc)
....@@ -333,17 +306,11 @@
333306 rc = -ENOMEM;
334307 goto fail;
335308 }
336
- zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
337
- NULL, &zcore_memmap_fops);
338
- if (!zcore_memmap_file) {
339
- rc = -ENOMEM;
340
- goto fail_dir;
341
- }
342309 zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
343310 NULL, &zcore_reipl_fops);
344311 if (!zcore_reipl_file) {
345312 rc = -ENOMEM;
346
- goto fail_memmap_file;
313
+ goto fail_dir;
347314 }
348315 zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
349316 NULL, &zcore_hsa_fops);
....@@ -355,8 +322,6 @@
355322
356323 fail_reipl_file:
357324 debugfs_remove(zcore_reipl_file);
358
-fail_memmap_file:
359
- debugfs_remove(zcore_memmap_file);
360325 fail_dir:
361326 debugfs_remove(zcore_dir);
362327 fail: