Skip to content

Commit 7f0bf65

Browse files
Michael HolzheuMartin Schwidefsky
authored andcommitted
[S390] Add real memory access functions
Add access function for real memory needed by s390 kdump backend. Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 1943f53 commit 7f0bf65

3 files changed

Lines changed: 60 additions & 18 deletions

File tree

‎arch/s390/include/asm/system.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ extern void pfault_fini(void);
114114
extern void cmma_init(void);
115115
extern int memcpy_real(void *, void *, size_t);
116116
extern void copy_to_absolute_zero(void *dest, void *src, size_t count);
117+
extern int copy_to_user_real(void __user *dest, void *src, size_t count);
118+
extern int copy_from_user_real(void *dest, void __user *src, size_t count);
117119

118120
#define finish_arch_switch(prev) do { \
119121
set_fs(current->thread.mm_segment); \

‎arch/s390/mm/maccess.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/kernel.h>
1212
#include <linux/types.h>
1313
#include <linux/errno.h>
14+
#include <linux/gfp.h>
1415
#include <asm/system.h>
1516

1617
/*
@@ -60,6 +61,9 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
6061
return copied < 0 ? -EFAULT : 0;
6162
}
6263

64+
/*
65+
* Copy memory in real mode (kernel to kernel)
66+
*/
6367
int memcpy_real(void *dest, void *src, size_t count)
6468
{
6569
register unsigned long _dest asm("2") = (unsigned long) dest;
@@ -101,3 +105,55 @@ void copy_to_absolute_zero(void *dest, void *src, size_t count)
101105
__ctl_load(cr0, 0, 0);
102106
preempt_enable();
103107
}
108+
109+
/*
110+
* Copy memory from kernel (real) to user (virtual)
111+
*/
112+
int copy_to_user_real(void __user *dest, void *src, size_t count)
113+
{
114+
int offs = 0, size, rc;
115+
char *buf;
116+
117+
buf = (char *) __get_free_page(GFP_KERNEL);
118+
if (!buf)
119+
return -ENOMEM;
120+
rc = -EFAULT;
121+
while (offs < count) {
122+
size = min(PAGE_SIZE, count - offs);
123+
if (memcpy_real(buf, src + offs, size))
124+
goto out;
125+
if (copy_to_user(dest + offs, buf, size))
126+
goto out;
127+
offs += size;
128+
}
129+
rc = 0;
130+
out:
131+
free_page((unsigned long) buf);
132+
return rc;
133+
}
134+
135+
/*
136+
* Copy memory from user (virtual) to kernel (real)
137+
*/
138+
int copy_from_user_real(void *dest, void __user *src, size_t count)
139+
{
140+
int offs = 0, size, rc;
141+
char *buf;
142+
143+
buf = (char *) __get_free_page(GFP_KERNEL);
144+
if (!buf)
145+
return -ENOMEM;
146+
rc = -EFAULT;
147+
while (offs < count) {
148+
size = min(PAGE_SIZE, count - offs);
149+
if (copy_from_user(buf, src + offs, size))
150+
goto out;
151+
if (memcpy_real(dest + offs, buf, size))
152+
goto out;
153+
offs += size;
154+
}
155+
rc = 0;
156+
out:
157+
free_page((unsigned long) buf);
158+
return rc;
159+
}

‎drivers/s390/char/zcore.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,6 @@ static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
142142
return memcpy_hsa(dest, src, count, TO_KERNEL);
143143
}
144144

145-
static int memcpy_real_user(void __user *dest, unsigned long src, size_t count)
146-
{
147-
static char buf[4096];
148-
int offs = 0, size;
149-
150-
while (offs < count) {
151-
size = min(sizeof(buf), count - offs);
152-
if (memcpy_real(buf, (void *) src + offs, size))
153-
return -EFAULT;
154-
if (copy_to_user(dest + offs, buf, size))
155-
return -EFAULT;
156-
offs += size;
157-
}
158-
return 0;
159-
}
160-
161145
static int __init init_cpu_info(enum arch_id arch)
162146
{
163147
struct save_area *sa;
@@ -346,8 +330,8 @@ static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
346330

347331
/* Copy from real mem */
348332
size = count - mem_offs - hdr_count;
349-
rc = memcpy_real_user(buf + hdr_count + mem_offs, mem_start + mem_offs,
350-
size);
333+
rc = copy_to_user_real(buf + hdr_count + mem_offs,
334+
(void *) mem_start + mem_offs, size);
351335
if (rc)
352336
goto fail;
353337

0 commit comments

Comments
 (0)