Debian Codegraph @

vmtest/patches/s390-crash-fix-proc-vmcore-reads.patch

raw
1 From 531194bfade3a8fb9f5ed25fe3b615219d92996c Mon Sep 17 00:00:00 2001
2 Message-ID: <531194bfade3a8fb9f5ed25fe3b615219d92996c.1710188478.git.osandov@osandov.com>
3 From: Omar Sandoval <[email protected]>
4 Date: Mon, 11 Mar 2024 13:08:27 -0700
5 Subject: [PATCH] s390/crash: fix /proc/vmcore reads
6
7 Squashed backport of the following upstream commits:
8
9 7190d84966b3 ("s390/mm: remove unused tprot() function")
10 d6da67378198 ("s390/crash: move copy_to_user_real() to crash_dump.c")
11 6d2e5a4a13da ("s390/crash: use static swap buffer for copy_to_user_real()")
12 ebbc95701691 ("s390/crash: support multi-segment iterators")
13
14 Signed-off-by: Omar Sandoval <[email protected]>
15 ---
16 arch/s390/include/asm/mmu.h | 14 ----
17 arch/s390/include/asm/os_info.h | 17 ++++-
18 arch/s390/include/asm/sclp.h | 4 +-
19 arch/s390/include/asm/uaccess.h | 1 -
20 arch/s390/kernel/crash_dump.c | 118 ++++++++------------------------
21 arch/s390/mm/maccess.c | 26 -------
22 drivers/s390/char/zcore.c | 58 +++++++---------
23 7 files changed, 70 insertions(+), 168 deletions(-)
24
25 diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
26 index 82aae78e1315..bc254bce48fa 100644
27 --- a/arch/s390/include/asm/mmu.h
28 +++ b/arch/s390/include/asm/mmu.h
29 @@ -42,18 +42,4 @@ typedef struct {
30 .context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
31 .context.gmap_list = LIST_HEAD_INIT(name.context.gmap_list),
32
33 -static inline int tprot(unsigned long addr)
34 -{
35 - int rc = -EFAULT;
36 -
37 - asm volatile(
38 - " tprot 0(%1),0\n"
39 - "0: ipm %0\n"
40 - " srl %0,28\n"
41 - "1:\n"
42 - EX_TABLE(0b,1b)
43 - : "+d" (rc) : "a" (addr) : "cc");
44 - return rc;
45 -}
46 -
47 #endif
48 diff --git a/arch/s390/include/asm/os_info.h b/arch/s390/include/asm/os_info.h
49 index 147a8d547ef9..85248d8fee0c 100644
50 --- a/arch/s390/include/asm/os_info.h
51 +++ b/arch/s390/include/asm/os_info.h
52 @@ -8,6 +8,8 @@
53 #ifndef _ASM_S390_OS_INFO_H
54 #define _ASM_S390_OS_INFO_H
55
56 +#include <linux/uio.h>
57 +
58 #define OS_INFO_VERSION_MAJOR 1
59 #define OS_INFO_VERSION_MINOR 1
60 #define OS_INFO_MAGIC 0x4f53494e464f535aULL /* OSINFOSZ */
61 @@ -39,7 +41,20 @@ u32 os_info_csum(struct os_info *os_info);
62
63 #ifdef CONFIG_CRASH_DUMP
64 void *os_info_old_entry(int nr, unsigned long *size);
65 -int copy_oldmem_kernel(void *dst, unsigned long src, size_t count);
66 +size_t copy_oldmem_iter(struct iov_iter *iter, unsigned long src, size_t count);
67 +
68 +static inline int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)
69 +{
70 + struct iov_iter iter;
71 + struct kvec kvec;
72 +
73 + kvec.iov_base = dst;
74 + kvec.iov_len = count;
75 + iov_iter_kvec(&iter, WRITE, &kvec, 1, count);
76 + if (copy_oldmem_iter(&iter, src, count) < count)
77 + return -EFAULT;
78 + return 0;
79 +}
80 #else
81 static inline void *os_info_old_entry(int nr, unsigned long *size)
82 {
83 diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h
84 index 236b34b75ddb..24ee532fab84 100644
85 --- a/arch/s390/include/asm/sclp.h
86 +++ b/arch/s390/include/asm/sclp.h
87 @@ -17,6 +17,7 @@
88 #define EXT_SCCB_READ_CPU (3 * PAGE_SIZE)
89
90 #ifndef __ASSEMBLY__
91 +#include <linux/uio.h>
92 #include <asm/chpid.h>
93 #include <asm/cpu.h>
94
95 @@ -142,8 +143,7 @@ int sclp_pci_deconfigure(u32 fid);
96 int sclp_ap_configure(u32 apid);
97 int sclp_ap_deconfigure(u32 apid);
98 int sclp_pci_report(struct zpci_report_error_header *report, u32 fh, u32 fid);
99 -int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count);
100 -int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count);
101 +size_t memcpy_hsa_iter(struct iov_iter *iter, unsigned long src, size_t count);
102 void sclp_ocf_cpc_name_copy(char *dst);
103
104 static inline int sclp_get_core_info(struct sclp_core_info *info, int early)
105 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
106 index f4511e21d646..2a067315fe59 100644
107 --- a/arch/s390/include/asm/uaccess.h
108 +++ b/arch/s390/include/asm/uaccess.h
109 @@ -285,7 +285,6 @@ static inline unsigned long __must_check clear_user(void __user *to, unsigned lo
110 return __clear_user(to, n);
111 }
112
113 -int copy_to_user_real(void __user *dest, unsigned long src, unsigned long count);
114 void *s390_kernel_write(void *dst, const void *src, size_t size);
115
116 int __noreturn __put_kernel_bad(void);
117 diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
118 index f8ebdd70dd31..49c035e5b75d 100644
119 --- a/arch/s390/kernel/crash_dump.c
120 +++ b/arch/s390/kernel/crash_dump.c
121 @@ -53,6 +53,8 @@ struct save_area {
122 };
123
124 static LIST_HEAD(dump_save_areas);
125 +static DEFINE_MUTEX(memcpy_real_mutex);
126 +static char memcpy_real_buf[PAGE_SIZE];
127
128 /*
129 * Allocate a save area
130 @@ -114,38 +116,35 @@ void __init save_area_add_vxrs(struct save_area *sa, __vector128 *vxrs)
131 memcpy(sa->vxrs_high, vxrs + 16, 16 * sizeof(__vector128));
132 }
133
134 -/*
135 - * Return physical address for virtual address
136 - */
137 -static inline void *load_real_addr(void *addr)
138 +static size_t copy_to_iter_real(struct iov_iter *iter, unsigned long src, size_t count)
139 {
140 - unsigned long real_addr;
141 + size_t len, copied, res = 0;
142
143 - asm volatile(
144 - " lra %0,0(%1)\n"
145 - " jz 0f\n"
146 - " la %0,0\n"
147 - "0:"
148 - : "=a" (real_addr) : "a" (addr) : "cc");
149 - return (void *)real_addr;
150 + mutex_lock(&memcpy_real_mutex);
151 + while (count) {
152 + len = min(PAGE_SIZE, count);
153 + if (memcpy_real(memcpy_real_buf, src, len))
154 + break;
155 + copied = copy_to_iter(memcpy_real_buf, len, iter);
156 + count -= copied;
157 + src += copied;
158 + res += copied;
159 + if (copied < len)
160 + break;
161 + }
162 + mutex_unlock(&memcpy_real_mutex);
163 + return res;
164 }
165
166 -/*
167 - * Copy memory of the old, dumped system to a kernel space virtual address
168 - */
169 -int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)
170 +size_t copy_oldmem_iter(struct iov_iter *iter, unsigned long src, size_t count)
171 {
172 - unsigned long len;
173 - void *ra;
174 - int rc;
175 + size_t len, copied, res = 0;
176
177 while (count) {
178 if (!oldmem_data.start && src < sclp.hsa_size) {
179 /* Copy from zfcp/nvme dump HSA area */
180 len = min(count, sclp.hsa_size - src);
181 - rc = memcpy_hsa_kernel(dst, src, len);
182 - if (rc)
183 - return rc;
184 + copied = memcpy_hsa_iter(iter, src, len);
185 } else {
186 /* Check for swapped kdump oldmem areas */
187 if (oldmem_data.start && src - oldmem_data.start < oldmem_data.size) {
188 @@ -157,57 +156,15 @@ int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)
189 } else {
190 len = count;
191 }
192 - if (is_vmalloc_or_module_addr(dst)) {
193 - ra = load_real_addr(dst);
194 - len = min(PAGE_SIZE - offset_in_page(ra), len);
195 - } else {
196 - ra = dst;
197 - }
198 - if (memcpy_real(ra, src, len))
199 - return -EFAULT;
200 + copied = copy_to_iter_real(iter, src, len);
201 }
202 - dst += len;
203 - src += len;
204 - count -= len;
205 + count -= copied;
206 + src += copied;
207 + res += copied;
208 + if (copied < len)
209 + break;
210 }
211 - return 0;
212 -}
213 -
214 -/*
215 - * Copy memory of the old, dumped system to a user space virtual address
216 - */
217 -static int copy_oldmem_user(void __user *dst, unsigned long src, size_t count)
218 -{
219 - unsigned long len;
220 - int rc;
221 -
222 - while (count) {
223 - if (!oldmem_data.start && src < sclp.hsa_size) {
224 - /* Copy from zfcp/nvme dump HSA area */
225 - len = min(count, sclp.hsa_size - src);
226 - rc = memcpy_hsa_user(dst, src, len);
227 - if (rc)
228 - return rc;
229 - } else {
230 - /* Check for swapped kdump oldmem areas */
231 - if (oldmem_data.start && src - oldmem_data.start < oldmem_data.size) {
232 - src -= oldmem_data.start;
233 - len = min(count, oldmem_data.size - src);
234 - } else if (oldmem_data.start && src < oldmem_data.size) {
235 - len = min(count, oldmem_data.size - src);
236 - src += oldmem_data.start;
237 - } else {
238 - len = count;
239 - }
240 - rc = copy_to_user_real(dst, src, len);
241 - if (rc)
242 - return rc;
243 - }
244 - dst += len;
245 - src += len;
246 - count -= len;
247 - }
248 - return 0;
249 + return res;
250 }
251
252 /*
253 @@ -217,26 +174,9 @@ ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn, size_t csize,
254 unsigned long offset)
255 {
256 unsigned long src;
257 - int rc;
258
259 - if (!(iter_is_iovec(iter) || iov_iter_is_kvec(iter)))
260 - return -EINVAL;
261 - /* Multi-segment iterators are not supported */
262 - if (iter->nr_segs > 1)
263 - return -EINVAL;
264 - if (!csize)
265 - return 0;
266 src = pfn_to_phys(pfn) + offset;
267 -
268 - /* XXX: pass the iov_iter down to a common function */
269 - if (iter_is_iovec(iter))
270 - rc = copy_oldmem_user(iter->iov->iov_base, src, csize);
271 - else
272 - rc = copy_oldmem_kernel(iter->kvec->iov_base, src, csize);
273 - if (rc < 0)
274 - return rc;
275 - iov_iter_advance(iter, csize);
276 - return csize;
277 + return copy_oldmem_iter(iter, src, csize);
278 }
279
280 /*
281 diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
282 index 421efa46946b..d6d84e02f35a 100644
283 --- a/arch/s390/mm/maccess.c
284 +++ b/arch/s390/mm/maccess.c
285 @@ -171,32 +171,6 @@ void memcpy_absolute(void *dest, void *src, size_t count)
286 arch_local_irq_restore(flags);
287 }
288
289 -/*
290 - * Copy memory from kernel (real) to user (virtual)
291 - */
292 -int copy_to_user_real(void __user *dest, unsigned long src, unsigned long count)
293 -{
294 - int offs = 0, size, rc;
295 - char *buf;
296 -
297 - buf = (char *) __get_free_page(GFP_KERNEL);
298 - if (!buf)
299 - return -ENOMEM;
300 - rc = -EFAULT;
301 - while (offs < count) {
302 - size = min(PAGE_SIZE, count - offs);
303 - if (memcpy_real(buf, src + offs, size))
304 - goto out;
305 - if (copy_to_user(dest + offs, buf, size))
306 - goto out;
307 - offs += size;
308 - }
309 - rc = 0;
310 -out:
311 - free_page((unsigned long) buf);
312 - return rc;
313 -}
314 -
315 /*
316 * Check if physical address is within prefix or zero page
317 */
318 diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c
319 index 92b32ce645b9..f6da215ccf9f 100644
320 --- a/drivers/s390/char/zcore.c
321 +++ b/drivers/s390/char/zcore.c
322 @@ -17,6 +17,7 @@
323 #include <linux/debugfs.h>
324 #include <linux/panic_notifier.h>
325 #include <linux/reboot.h>
326 +#include <linux/uio.h>
327
328 #include <asm/asm-offsets.h>
329 #include <asm/ipl.h>
330 @@ -54,38 +55,37 @@ static DEFINE_MUTEX(hsa_buf_mutex);
331 static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE);
332
333 /*
334 - * Copy memory from HSA to user memory (not reentrant):
335 + * Copy memory from HSA to iterator (not reentrant):
336 *
337 - * @dest: User buffer where memory should be copied to
338 + * @iter: Iterator where memory should be copied to
339 * @src: Start address within HSA where data should be copied
340 * @count: Size of buffer, which should be copied
341 */
342 -int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
343 +size_t memcpy_hsa_iter(struct iov_iter *iter, unsigned long src, size_t count)
344 {
345 - unsigned long offset, bytes;
346 + size_t bytes, copied, res = 0;
347 + unsigned long offset;
348
349 if (!hsa_available)
350 - return -ENODATA;
351 + return 0;
352
353 mutex_lock(&hsa_buf_mutex);
354 while (count) {
355 if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
356 TRACE("sclp_sdias_copy() failed\n");
357 - mutex_unlock(&hsa_buf_mutex);
358 - return -EIO;
359 + break;
360 }
361 offset = src % PAGE_SIZE;
362 bytes = min(PAGE_SIZE - offset, count);
363 - if (copy_to_user(dest, hsa_buf + offset, bytes)) {
364 - mutex_unlock(&hsa_buf_mutex);
365 - return -EFAULT;
366 - }
367 - src += bytes;
368 - dest += bytes;
369 - count -= bytes;
370 + copied = copy_to_iter(hsa_buf + offset, bytes, iter);
371 + count -= copied;
372 + src += copied;
373 + res += copied;
374 + if (copied < bytes)
375 + break;
376 }
377 mutex_unlock(&hsa_buf_mutex);
378 - return 0;
379 + return res;
380 }
381
382 /*
383 @@ -95,28 +95,16 @@ int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
384 * @src: Start address within HSA where data should be copied
385 * @count: Size of buffer, which should be copied
386 */
387 -int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
388 +static inline int memcpy_hsa_kernel(void *dst, unsigned long src, size_t count)
389 {
390 - unsigned long offset, bytes;
391 + struct iov_iter iter;
392 + struct kvec kvec;
393
394 - if (!hsa_available)
395 - return -ENODATA;
396 -
397 - mutex_lock(&hsa_buf_mutex);
398 - while (count) {
399 - if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) {
400 - TRACE("sclp_sdias_copy() failed\n");
401 - mutex_unlock(&hsa_buf_mutex);
402 - return -EIO;
403 - }
404 - offset = src % PAGE_SIZE;
405 - bytes = min(PAGE_SIZE - offset, count);
406 - memcpy(dest, hsa_buf + offset, bytes);
407 - src += bytes;
408 - dest += bytes;
409 - count -= bytes;
410 - }
411 - mutex_unlock(&hsa_buf_mutex);
412 + kvec.iov_base = dst;
413 + kvec.iov_len = count;
414 + iov_iter_kvec(&iter, WRITE, &kvec, 1, count);
415 + if (memcpy_hsa_iter(&iter, src, count) < count)
416 + return -EIO;
417 return 0;
418 }
419
420 --
421 2.44.0
422