s390/crash: support multi-segment iterators
Alexander Gordeev
maintainerv4 cover s390/crash: support multi-segment iterators
Hi Matthew et al,
This series completes 5d8de293c224 ("vmcore: convert copy_oldmem_page() to take an iov_iter") for s390.
Changes since v3:
- concurrent access to HSA and oldmem swap buffers protected;
Changes since v2:
- Matthew Wilcox suggestion is adopted, with that...
- copy_to_iter() is used instead of custom implementation;
Changes since v1:
- number of bytes left to copy on fail fixed;
Thanks!
Alexander Gordeev (4):
s390/zcore: fix race when reading from hardware system area s390/crash: move copy_to_user_real() to crash_dump.c s390/crash: use static swap buffer for copy_to_user_real() s390/crash: support multi-segment iterators
arch/s390/include/asm/os_info.h | 17 ++++- arch/s390/include/asm/sclp.h | 4 +- arch/s390/include/asm/uaccess.h | 1 - arch/s390/kernel/crash_dump.c | 114 ++++++++------------------------ arch/s390/mm/maccess.c | 26 -------- drivers/s390/char/zcore.c | 55 ++++++++------- 6 files changed, 71 insertions(+), 146 deletions(-)
Signature · 1 line
2.34.1
Alexander Gordeev
maintainerPATCH v4 1/4 s390/zcore: fix race when reading from hardware system area
Memory buffer used for reading out data from hardware system area is not protected against concurrent access.
--- drivers/s390/char/zcore.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/s390/char/zcore.c +10 -1
@@ -50,6 +50,7 @@ static struct dentry *zcore_reipl_file;static struct dentry *zcore_hsa_file;static struct ipl_parameter_block *zcore_ipl_block; +static DEFINE_MUTEX (hsa_buf_mutex);static char hsa_buf[PAGE_SIZE ]__aligned(PAGE_SIZE) ;/*
@@ -66,19 +67,24 @@ int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)if (!hsa_available)return -ENODATA ; +mutex_lock (&hsa_buf_mutex);while (count) {if (sclp_sdias_copy (hsa_buf, src /PAGE_SIZE +2 ,1 )) {TRACE ("sclp_sdias_copy() failed\n" ); +mutex_unlock (&hsa_buf_mutex);return -EIO ; } offset = src %PAGE_SIZE ; bytes =min (PAGE_SIZE - offset, count); -if (copy_to_user (dest, hsa_buf + offset, bytes)) +if (copy_to_user (dest, hsa_buf + offset, bytes)) { +mutex_unlock (&hsa_buf_mutex);return -EFAULT ; + } src += bytes; dest += bytes; count -= bytes; } +mutex_unlock (&hsa_buf_mutex);return 0 ; }
@@ -96,9 +102,11 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)if (!hsa_available)return -ENODATA ; +mutex_lock (&hsa_buf_mutex);while (count) {if (sclp_sdias_copy (hsa_buf, src /PAGE_SIZE +2 ,1 )) {TRACE ("sclp_sdias_copy() failed\n" ); +mutex_unlock (&hsa_buf_mutex);return -EIO ; } offset = src %PAGE_SIZE ;
@@ -108,6 +116,7 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count) dest += bytes; count -= bytes; } +mutex_unlock (&hsa_buf_mutex);return 0 ; }
Signature · 1 line
2.34.1
Alexander Gordeev
maintainerPATCH v4 2/4 s390/crash: move copy_to_user_real() to crash_dump.c
In reply to Alexander GordeevFunction copy_to_user_real() does not really belong to maccess.c. It is only used for copying oldmem to user space, so let's move it to the friends.
--- arch/s390/include/asm/uaccess.h | 1 - arch/s390/kernel/crash_dump.c | 26 ++++++++++++++++++++++++++ arch/s390/mm/maccess.c | 26 -------------------------- 3 files changed, 26 insertions(+), 27 deletions(-)
arch/s390/include/asm/uaccess.h +0 -1
@@ -285,7 +285,6 @@ static inline unsigned long __must_check clear_user(void __user *to, unsigned loreturn __clear_user (to, n); } -int copy_to_user_real (void __user *dest,unsigned long src,unsigned long count);void *s390_kernel_write (void *dst,const void *src,size_t size);int __noreturn __put_kernel_bad (void );
arch/s390/kernel/crash_dump.c +26 -0
@@ -173,6 +173,32 @@ int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)return 0 ; } +/* +* Copy memory from kernel (real) to user (virtual) +*/ +static int copy_to_user_real (void __user *dest,unsigned long src,unsigned long count) +{ +int offs =0 , size, rc; +char *buf; + + buf = (char *)__get_free_page (GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + rc = -EFAULT ; +while (offs < count) { + size =min (PAGE_SIZE , count - offs); +if (memcpy_real (buf, src + offs, size)) + goto out; +if (copy_to_user (dest + offs, buf, size)) + goto out; + offs += size; + } + rc =0 ; +out: +free_page ((unsigned long )buf); +return rc; +} +/* * Copy memory of the old, dumped system to a user space virtual address */
arch/s390/mm/maccess.c +0 -26
@@ -171,32 +171,6 @@ void memcpy_absolute(void *dest, void *src, size_t count)arch_local_irq_restore (flags); } -/* -* Copy memory from kernel (real) to user (virtual) -*/ -int copy_to_user_real (void __user *dest,unsigned long src,unsigned long count) -{ -int offs =0 , size, rc; -char *buf; - - buf = (char *)__get_free_page (GFP_KERNEL ); -if (!buf) -return -ENOMEM ; - rc = -EFAULT ; -while (offs < count) { - size =min (PAGE_SIZE , count - offs); -if (memcpy_real (buf, src + offs, size)) - goto out; -if (copy_to_user (dest + offs, buf, size)) - goto out; - offs += size; - } - rc =0 ; -out: -free_page ((unsigned long ) buf); -return rc; -} -/* * Check if physical address is within prefix or zero page */
Signature · 1 line
2.34.1
Alexander Gordeev
maintainerPATCH v4 3/4 s390/crash: use static swap buffer for copy_to_user_real()
In reply to Alexander GordeevCurrently a temporary page-size buffer is allocated for copying oldmem to user space. That limits copy_to_user_real() operation only to stages when virtual memory is available and still makes it possible to fail while the system is being dumped.
Instead of reallocating single page on each copy_oldmem_page() iteration use a statically allocated buffer.
This also paves the way for a further memcpy_real() rework where no swap buffer is needed altogether.
--- arch/s390/kernel/crash_dump.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
arch/s390/kernel/crash_dump.c +12 -14
@@ -53,6 +53,8 @@ struct save_area { };static LIST_HEAD (dump_save_areas); +static DEFINE_MUTEX (memcpy_real_mutex); +static char memcpy_real_buf[PAGE_SIZE ];/* * Allocate a save area
@@ -178,25 +180,21 @@ int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)*/ static int copy_to_user_real (void __user *dest,unsigned long src,unsigned long count) { -int offs =0 , size, rc; -char *buf; +unsigned long offs =0 , size; - buf = (char *)__get_free_page (GFP_KERNEL ); -if (!buf) -return -ENOMEM ; - rc = -EFAULT ; +mutex_lock (&memcpy_real_mutex);while (offs < count) { size =min (PAGE_SIZE , count - offs); -if (memcpy_real (buf, src + offs, size)) - goto out; -if (copy_to_user (dest + offs, buf, size)) - goto out; +if (memcpy_real (memcpy_real_buf, src + offs, size)) +break ; +if (copy_to_user (dest + offs, memcpy_real_buf, size)) +break ; offs += size; } - rc =0 ; -out: -free_page ((unsigned long )buf); -return rc; +mutex_unlock (&memcpy_real_mutex); +if (offs < count) +return -EFAULT ; +return 0 ; }/*
Signature · 1 line
2.34.1
Alexander Gordeev
maintainerPATCH v4 4/4 s390/crash: support multi-segment iterators
In reply to Alexander GordeevMake it possible to handle not only single-, but also multi- segment iterators in copy_oldmem_iter() callback. Change the semantics of called functions to match the iterator model - instead of an error code the exact number of bytes copied is returned.
The swap page used to copy data to user space is adopted for kernel space too. That does not bring any performance impact.
--- arch/s390/include/asm/os_info.h | 17 ++++- arch/s390/include/asm/sclp.h | 4 +- arch/s390/kernel/crash_dump.c | 128 ++++++-------------------------- drivers/s390/char/zcore.c | 58 ++++++--------- 4 files changed, 63 insertions(+), 144 deletions(-)
arch/s390/include/asm/os_info.h +16 -1
@@ -8,6 +8,8 @@#ifndef _ASM_S390_OS_INFO_H#define _ASM_S390_OS_INFO_H +#include <linux/uio.h> +#define OS_INFO_VERSION_MAJOR 1#define OS_INFO_VERSION_MINOR 1#define OS_INFO_MAGIC 0x4f53494e464f535aULL/* OSINFOSZ */
@@ -39,7 +41,20 @@ u32 os_info_csum(struct os_info *os_info);#ifdef CONFIG_CRASH_DUMP void *os_info_old_entry (int nr,unsigned long *size); -int copy_oldmem_kernel (void *dst,unsigned long src,size_t count); +size_t copy_oldmem_iter (struct iov_iter *iter,unsigned long src,size_t count); + +static inline int copy_oldmem_kernel (void *dst,unsigned long src,size_t count) +{ +struct iov_iter iter; +struct kvec kvec; + + kvec.iov_base = dst; + kvec.iov_len = count; +iov_iter_kvec (&iter,WRITE , &kvec,1 , count); +if (copy_oldmem_iter (&iter, src, count) < count) +return -EFAULT ; +return 0 ; +}#else static inline void *os_info_old_entry (int nr,unsigned long *size) {
arch/s390/include/asm/sclp.h +2 -2
@@ -17,6 +17,7 @@#define EXT_SCCB_READ_CPU (3 * PAGE_SIZE)#ifndef __ASSEMBLY__ +#include <linux/uio.h> #include <asm/chpid.h> #include <asm/cpu.h>
@@ -146,8 +147,7 @@ int sclp_pci_deconfigure(u32 fid);int sclp_ap_configure (u32 apid);int sclp_ap_deconfigure (u32 apid);int sclp_pci_report (struct zpci_report_error_header *report,u32 fh,u32 fid); -int memcpy_hsa_kernel (void *dest,unsigned long src,size_t count); -int memcpy_hsa_user (void __user *dest,unsigned long src,size_t count); +size_t memcpy_hsa_iter (struct iov_iter *iter,unsigned long src,size_t count);void sclp_ocf_cpc_name_copy (char *dst);static inline int sclp_get_core_info (struct sclp_core_info *info,int early)
arch/s390/kernel/crash_dump.c +22 -106
165 lines not on this page · raw message
drivers/s390/char/zcore.c +23 -35
95 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 8 lines · Alexander Gordeev
Hi Matthew et al,
This series completes
5d8de293c224("vmcore: convertcopy_oldmem_page()to take aniov_iter") for s390.Changes since v3:
- concurrent access to HSA and oldmem swap buffers protected;
Quoted 6 lines
Changes since v2:
- Matthew Wilcox suggestion is adopted, with that...
-copy_to_iter()is used instead of custom implementation;Changes since v1:
- number of bytes left to copy on fail fixed;
OK... Do you prefer it to go through s390 tree? The thing is, I've stuff in iov_iter tree that conflicts with it; I'll gladly drop that bit (vfs.git #fixes-s390) in favour of your series (and drop s390 bits from "new iov_iter flavour - ITER_UBUF" in #work.iov_iter - they are not needed anymore).
I can put your series into replacement of #fixes-s390, or pull it from whatever static branch you put it into - up to you. Preferences?
Alexander Gordeev
maintainerQuoted 9 lines · Al Viro
OK... Do you prefer it to go through s390 tree? The thing is, I've stuff in
iov_itertree that conflicts with it; I'll gladly drop that bit (vfs.git #fixes-s390) in favour of your series (and drop s390 bits from "newiov_iterflavour -ITER_UBUF" in #work.iov_iter - they are not needed anymore).I can put your series into replacement of #fixes-s390, or pull it from whatever static branch you put it into - up to you. Preferences?
Hi Al,
I am preparing a branch for you.
Will retest it and let you know once it is done.
Thanks!
Alexander Gordeev
maintainerQuoted 3 lines · Al Viro
I can put your series into replacement of #fixes-s390, or pull it from whatever static branch you put it into - up to you. Preferences?
Hi Al,
Please find the changes since commit af2debd58bd769e38f538143f0d332e15d753396:
s390/crash: make copy_oldmem_page() return number of bytes copied
up to ebbc9570169147740aa39aee1d61b4cc5a631644:
s390/crash: support multi-segment iterators
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git vmcore-iov_iter
Please, note three (rather trivial) prereq commits to pull along:
f6749da17a34 s390/crash: fix incorrect number of bytes to copy to user space 86caa4b67895 s390/crash: remove redundant panic() on save area allocation failure 7190d84966b3 s390/mm: remove unused tprot() function
Thanks!
Quoted 17 lines · Alexander Gordeev
Quoted 3 lines · Al Viro
I can put your series into replacement of #fixes-s390, or pull it from whatever static branch you put it into - up to you. Preferences?
Hi Al,
Please find the changes since commit
af2debd58bd769e38f538143f0d332e15d753396:s390/crash: make
copy_oldmem_page()return number of bytes copiedup to
ebbc9570169147740aa39aee1d61b4cc5a631644:s390/crash: support multi-segment iterators
are available in the Git repository at:
Quoted 7 lines
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.gitvmcore-iov_iterPlease, note three (rather trivial) prereq commits to pull along:
f6749da17a34s390/crash: fix incorrect number of bytes to copy to user space86caa4b67895s390/crash: remove redundantpanic()on save area allocation failure7190d84966b3s390/mm: remove unusedtprot()function
Pulled.
Quoted 24 lines · Alexander Gordeev
Hi Matthew et al,
This series completes
5d8de293c224("vmcore: convertcopy_oldmem_page()to take aniov_iter") for s390.Changes since v3:
- concurrent access to HSA and oldmem swap buffers protected;Changes since v2:
- Matthew Wilcox suggestion is adopted, with that...
-copy_to_iter()is used instead of custom implementation;Changes since v1:
- number of bytes left to copy on fail fixed;Thanks!
Alexander Gordeev (4):
s390/zcore: fix race when reading from hardware system area s390/crash: movecopy_to_user_real()tocrash_dump.cs390/crash: use static swap buffer forcopy_to_user_real()s390/crash: support multi-segment iterators
Quoted 7 lines
arch/s390/include/asm/os_info.h | 17 ++++- arch/s390/include/asm/sclp.h | 4 +- arch/s390/include/asm/uaccess.h | 1 - arch/s390/kernel/crash_dump.c | 114 ++++++++------------------------ arch/s390/mm/maccess.c | 26 -------- drivers/s390/char/zcore.c | 55 ++++++++------- 6 files changed, 71 insertions(+), 146 deletions(-)
FWIW,
HI Alexander,
Quoted 24 lines · Alexander Gordeev
Hi Matthew et al,
This series completes
5d8de293c224("vmcore: convertcopy_oldmem_page()to take aniov_iter") for s390.Changes since v3:
- concurrent access to HSA and oldmem swap buffers protected;Changes since v2:
- Matthew Wilcox suggestion is adopted, with that...
-copy_to_iter()is used instead of custom implementation;Changes since v1:
- number of bytes left to copy on fail fixed;Thanks!
Alexander Gordeev (4):
s390/zcore: fix race when reading from hardware system area s390/crash: movecopy_to_user_real()tocrash_dump.cs390/crash: use static swap buffer forcopy_to_user_real()s390/crash: support multi-segment iterators
Quoted 10 lines
arch/s390/include/asm/os_info.h | 17 ++++- arch/s390/include/asm/sclp.h | 4 +- arch/s390/include/asm/uaccess.h | 1 - arch/s390/kernel/crash_dump.c | 114 ++++++++------------------------ arch/s390/mm/maccess.c | 26 -------- drivers/s390/char/zcore.c | 55 ++++++++------- 6 files changed, 71 insertions(+), 146 deletions(-)Signature · 1 line
2.34.1
all our kdump + makedumpfile (with CP as core collector as well) work with these patches applied.
Tested on LPAR and zVM.
With and w/o KASAN.
Regards
Alex