Skip to content

Commit e657d8f

Browse files
Michael HolzheuMartin Schwidefsky
authored andcommitted
s390/sclp: Determine HSA size dynamically for zfcpdump
Currently we have hardcoded the HSA size to 32 MiB. With this patch the HSA size is determined dynamically via SCLP in early.c. Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent f8049e3 commit e657d8f

10 files changed

Lines changed: 142 additions & 32 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ bool sclp_has_vt220(void);
5757
int sclp_pci_configure(u32 fid);
5858
int sclp_pci_deconfigure(u32 fid);
5959
int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode);
60+
void sclp_hsa_size_detect(void);
61+
unsigned long sclp_get_hsa_size(void);
6062

6163
#endif /* _ASM_S390_SCLP_H */

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
107107
#define MACHINE_HAS_RRBM (S390_lowcore.machine_flags & MACHINE_FLAG_RRBM)
108108
#endif /* CONFIG_64BIT */
109109

110-
#define ZFCPDUMP_HSA_SIZE (32UL<<20)
111-
#define ZFCPDUMP_HSA_SIZE_MAX (64UL<<20)
112-
113110
/*
114111
* Console mode. Override with conmode=
115112
*/

‎arch/s390/kernel/crash_dump.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ static void *elfcorehdr_newmem;
9595
/*
9696
* Copy one page from zfcpdump "oldmem"
9797
*
98-
* For pages below ZFCPDUMP_HSA_SIZE memory from the HSA is copied. Otherwise
98+
* For pages below HSA size memory from the HSA is copied. Otherwise
9999
* real memory copy is used.
100100
*/
101101
static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
102102
unsigned long src, int userbuf)
103103
{
104104
int rc;
105105

106-
if (src < ZFCPDUMP_HSA_SIZE) {
106+
if (src < sclp_get_hsa_size()) {
107107
rc = memcpy_hsa(buf, src, csize, userbuf);
108108
} else {
109109
if (userbuf)
@@ -188,18 +188,19 @@ static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
188188
/*
189189
* Remap "oldmem" for zfcpdump
190190
*
191-
* We only map available memory above ZFCPDUMP_HSA_SIZE. Memory below
192-
* ZFCPDUMP_HSA_SIZE is read on demand using the copy_oldmem_page() function.
191+
* We only map available memory above HSA size. Memory below HSA size
192+
* is read on demand using the copy_oldmem_page() function.
193193
*/
194194
static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
195195
unsigned long from,
196196
unsigned long pfn,
197197
unsigned long size, pgprot_t prot)
198198
{
199+
unsigned long hsa_end = sclp_get_hsa_size();
199200
unsigned long size_hsa;
200201

201-
if (pfn < ZFCPDUMP_HSA_SIZE >> PAGE_SHIFT) {
202-
size_hsa = min(size, ZFCPDUMP_HSA_SIZE - (pfn << PAGE_SHIFT));
202+
if (pfn < hsa_end >> PAGE_SHIFT) {
203+
size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
203204
if (size == size_hsa)
204205
return 0;
205206
size -= size_hsa;
@@ -238,9 +239,9 @@ int copy_from_oldmem(void *dest, void *src, size_t count)
238239
return rc;
239240
}
240241
} else {
241-
if ((unsigned long) src < ZFCPDUMP_HSA_SIZE) {
242-
copied = min(count,
243-
ZFCPDUMP_HSA_SIZE - (unsigned long) src);
242+
unsigned long hsa_end = sclp_get_hsa_size();
243+
if ((unsigned long) src < hsa_end) {
244+
copied = min(count, hsa_end - (unsigned long) src);
244245
rc = memcpy_hsa(dest, (unsigned long) src, copied, 0);
245246
if (rc)
246247
return rc;
@@ -580,6 +581,9 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
580581
/* If elfcorehdr= has been passed via cmdline, we use that one */
581582
if (elfcorehdr_addr != ELFCORE_ADDR_MAX)
582583
return 0;
584+
/* If we cannot get HSA size for zfcpdump return error */
585+
if (ipl_info.type == IPL_TYPE_FCP_DUMP && !sclp_get_hsa_size())
586+
return -ENODEV;
583587
mem_chunk_cnt = get_mem_chunk_cnt();
584588

585589
alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +

‎arch/s390/kernel/early.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ void __init startup_init(void)
484484
detect_machine_facilities();
485485
setup_topology();
486486
sclp_facilities_detect();
487+
sclp_hsa_size_detect();
487488
#ifdef CONFIG_DYNAMIC_FTRACE
488489
S390_lowcore.ftrace_func = (unsigned long)ftrace_caller;
489490
#endif

‎arch/s390/kernel/setup.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ static void __init setup_memory_end(void)
471471

472472

473473
#ifdef CONFIG_ZFCPDUMP
474-
if (ipl_info.type == IPL_TYPE_FCP_DUMP && !OLDMEM_BASE) {
475-
memory_end = ZFCPDUMP_HSA_SIZE;
474+
if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
475+
!OLDMEM_BASE && sclp_get_hsa_size()) {
476+
memory_end = sclp_get_hsa_size();
476477
memory_end_set = 1;
477478
}
478479
#endif
@@ -586,7 +587,7 @@ static unsigned long __init find_crash_base(unsigned long crash_size,
586587
crash_base = (chunk->addr + chunk->size) - crash_size;
587588
if (crash_base < crash_size)
588589
continue;
589-
if (crash_base < ZFCPDUMP_HSA_SIZE_MAX)
590+
if (crash_base < sclp_get_hsa_size())
590591
continue;
591592
if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
592593
continue;

‎drivers/s390/char/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#
44

55
obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \
6-
sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o
6+
sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o \
7+
sclp_early.o
78

89
obj-$(CONFIG_TN3270) += raw3270.o
910
obj-$(CONFIG_TN3270_CONSOLE) += con3270.o

‎drivers/s390/char/sclp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ int sclp_deactivate(void);
172172
int sclp_reactivate(void);
173173
int sclp_service_call(sclp_cmdw_t command, void *sccb);
174174
int sclp_sync_request(sclp_cmdw_t command, void *sccb);
175+
int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb);
175176

176177
int sclp_sdias_init(void);
177178
void sclp_sdias_exit(void);

‎drivers/s390/char/sclp_cmd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static u8 sclp_fac84;
5959
static unsigned long long rzm;
6060
static unsigned long long rnmax;
6161

62-
static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
62+
int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
6363
{
6464
int rc;
6565

‎drivers/s390/char/sclp_early.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* SCLP early driver
3+
*
4+
* Copyright IBM Corp. 2013
5+
*/
6+
7+
#define KMSG_COMPONENT "sclp_early"
8+
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9+
10+
#include <asm/sclp.h>
11+
#include <asm/ipl.h>
12+
#include "sclp_sdias.h"
13+
#include "sclp.h"
14+
15+
static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE);
16+
static unsigned long sclp_hsa_size;
17+
18+
static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
19+
{
20+
int rc;
21+
22+
do {
23+
rc = sclp_cmd_sync_early(cmd, sccb);
24+
} while (rc == -EBUSY);
25+
26+
if (rc)
27+
return -EIO;
28+
if (((struct sccb_header *) sccb)->response_code != 0x0020)
29+
return -EIO;
30+
return 0;
31+
}
32+
33+
static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
34+
{
35+
memset(sccb, 0, sizeof(*sccb));
36+
37+
sccb->hdr.length = sizeof(*sccb);
38+
sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
39+
sccb->evbuf.hdr.type = EVTYP_SDIAS;
40+
sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
41+
sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
42+
sccb->evbuf.event_id = 4712;
43+
sccb->evbuf.dbs = 1;
44+
}
45+
46+
static int __init sclp_set_event_mask(unsigned long receive_mask,
47+
unsigned long send_mask)
48+
{
49+
struct init_sccb *sccb = (void *) &sccb_early;
50+
51+
memset(sccb, 0, sizeof(*sccb));
52+
sccb->header.length = sizeof(*sccb);
53+
sccb->mask_length = sizeof(sccb_mask_t);
54+
sccb->receive_mask = receive_mask;
55+
sccb->send_mask = send_mask;
56+
return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
57+
}
58+
59+
static long __init sclp_hsa_size_init(void)
60+
{
61+
struct sdias_sccb *sccb = (void *) &sccb_early;
62+
63+
sccb_init_eq_size(sccb);
64+
if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
65+
return -EIO;
66+
if (sccb->evbuf.blk_cnt != 0)
67+
return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
68+
return 0;
69+
}
70+
71+
static long __init sclp_hsa_copy_wait(void)
72+
{
73+
struct sccb_header *sccb = (void *) &sccb_early;
74+
75+
memset(sccb, 0, PAGE_SIZE);
76+
sccb->length = PAGE_SIZE;
77+
if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
78+
return -EIO;
79+
return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
80+
}
81+
82+
unsigned long sclp_get_hsa_size(void)
83+
{
84+
return sclp_hsa_size;
85+
}
86+
87+
void __init sclp_hsa_size_detect(void)
88+
{
89+
long size;
90+
91+
/* First try synchronous interface (LPAR) */
92+
if (sclp_set_event_mask(0, 0x40000010))
93+
return;
94+
size = sclp_hsa_size_init();
95+
if (size < 0)
96+
return;
97+
if (size != 0)
98+
goto out;
99+
/* Then try asynchronous interface (z/VM) */
100+
if (sclp_set_event_mask(0x00000010, 0x40000010))
101+
return;
102+
size = sclp_hsa_size_init();
103+
if (size < 0)
104+
return;
105+
size = sclp_hsa_copy_wait();
106+
if (size < 0)
107+
return;
108+
out:
109+
sclp_set_event_mask(0, 0);
110+
sclp_hsa_size = size;
111+
}

‎drivers/s390/char/zcore.c‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
328328
mem_offs = 0;
329329

330330
/* Copy from HSA data */
331-
if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
332-
size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
333-
- mem_start));
331+
if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
332+
size = min((count - hdr_count),
333+
(size_t) (sclp_get_hsa_size() - mem_start));
334334
rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
335335
if (rc)
336336
goto fail;
@@ -490,7 +490,7 @@ static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
490490
static char str[18];
491491

492492
if (hsa_available)
493-
snprintf(str, sizeof(str), "%lx\n", ZFCPDUMP_HSA_SIZE);
493+
snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
494494
else
495495
snprintf(str, sizeof(str), "0\n");
496496
return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
@@ -584,17 +584,9 @@ static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
584584

585585
static int __init check_sdias(void)
586586
{
587-
int rc, act_hsa_size;
588-
589-
rc = sclp_sdias_blk_count();
590-
if (rc < 0) {
587+
if (!sclp_get_hsa_size()) {
591588
TRACE("Could not determine HSA size\n");
592-
return rc;
593-
}
594-
act_hsa_size = (rc - 1) * PAGE_SIZE;
595-
if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
596-
TRACE("HSA size too small: %i\n", act_hsa_size);
597-
return -EINVAL;
589+
return -ENODEV;
598590
}
599591
return 0;
600592
}
@@ -662,7 +654,7 @@ static int __init zcore_reipl_init(void)
662654
ipl_block = (void *) __get_free_page(GFP_KERNEL);
663655
if (!ipl_block)
664656
return -ENOMEM;
665-
if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
657+
if (ipib_info.ipib < sclp_get_hsa_size())
666658
rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
667659
else
668660
rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);

0 commit comments

Comments
 (0)