Skip to content

Commit a80313f

Browse files
gerald-schaeferMartin Schwidefsky
authored andcommitted
s390/kernel: introduce .dma sections
With a relocatable kernel that could reside at any place in memory, code and data that has to stay below 2 GB needs special handling. This patch introduces .dma sections for such text, data and ex_table. The sections will be part of the decompressor kernel, so they will not be relocated and stay below 2 GB. Their location is passed over to the decompressed / relocated kernel via the .boot.preserved.data section. The duald and aste for control register setup also need to stay below 2 GB, so move the setup code from arch/s390/kernel/head64.S to arch/s390/boot/head.S. The duct and linkage_stack could reside above 2 GB, but their content has to be preserved for the decompresed kernel, so they are also moved into the .dma section. The start and end address of the .dma sections is added to vmcoreinfo, for crash support, to help debugging in case the kernel crashed there. Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Reviewed-by: Philipp Rudo <prudo@linux.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 087c4d7 commit a80313f

24 files changed

Lines changed: 334 additions & 188 deletions

‎arch/s390/boot/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
3030

3131
obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o
3232
obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
33-
obj-y += ctype.o
33+
obj-y += ctype.o text_dma.o
3434
obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o
3535
obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o
3636
targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)

‎arch/s390/boot/compressed/vmlinux.lds.S‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ SECTIONS
3333
*(.data.*)
3434
_edata = . ;
3535
}
36+
/*
37+
* .dma section for code, data, ex_table that need to stay below 2 GB,
38+
* even when the kernel is relocate: above 2 GB.
39+
*/
40+
_sdma = .;
41+
.dma.text : {
42+
. = ALIGN(PAGE_SIZE);
43+
_stext_dma = .;
44+
*(.dma.text)
45+
. = ALIGN(PAGE_SIZE);
46+
_etext_dma = .;
47+
}
48+
. = ALIGN(16);
49+
.dma.ex_table : {
50+
_start_dma_ex_table = .;
51+
KEEP(*(.dma.ex_table))
52+
_stop_dma_ex_table = .;
53+
}
54+
.dma.data : { *(.dma.data) }
55+
_edma = .;
56+
3657
BOOT_DATA
3758
BOOT_DATA_PRESERVED
3859

‎arch/s390/boot/head.S‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ ENTRY(startup_kdump)
305305
xc 0x300(256),0x300
306306
xc 0xe00(256),0xe00
307307
xc 0xf00(256),0xf00
308-
lctlg %c0,%c15,0x200(%r0) # initialize control registers
308+
lctlg %c0,%c15,.Lctl-.LPG0(%r13) # load control registers
309309
stcke __LC_BOOT_CLOCK
310310
mvc __LC_LAST_UPDATE_CLOCK(8),__LC_BOOT_CLOCK+1
311311
spt 6f-.LPG0(%r13)
@@ -319,6 +319,36 @@ ENTRY(startup_kdump)
319319
.align 8
320320
6: .long 0x7fffffff,0xffffffff
321321

322+
.Lctl: .quad 0x04040000 # cr0: AFP registers & secondary space
323+
.quad 0 # cr1: primary space segment table
324+
.quad .Lduct # cr2: dispatchable unit control table
325+
.quad 0 # cr3: instruction authorization
326+
.quad 0xffff # cr4: instruction authorization
327+
.quad .Lduct # cr5: primary-aste origin
328+
.quad 0 # cr6: I/O interrupts
329+
.quad 0 # cr7: secondary space segment table
330+
.quad 0 # cr8: access registers translation
331+
.quad 0 # cr9: tracing off
332+
.quad 0 # cr10: tracing off
333+
.quad 0 # cr11: tracing off
334+
.quad 0 # cr12: tracing off
335+
.quad 0 # cr13: home space segment table
336+
.quad 0xc0000000 # cr14: machine check handling off
337+
.quad .Llinkage_stack # cr15: linkage stack operations
338+
339+
.section .dma.data,"aw",@progbits
340+
.Lduct: .long 0,.Laste,.Laste,0,.Lduald,0,0,0
341+
.long 0,0,0,0,0,0,0,0
342+
.Llinkage_stack:
343+
.long 0,0,0x89000000,0,0,0,0x8a000000,0
344+
.align 64
345+
.Laste: .quad 0,0xffffffffffffffff,0,0,0,0,0,0
346+
.align 128
347+
.Lduald:.rept 8
348+
.long 0x80000000,0,0,0 # invalid access-list entries
349+
.endr
350+
.previous
351+
322352
#include "head_kdump.S"
323353

324354
#

‎arch/s390/boot/startup.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/string.h>
33
#include <linux/elf.h>
4+
#include <asm/sections.h>
45
#include <asm/setup.h>
56
#include <asm/kexec.h>
67
#include <asm/sclp.h>
8+
#include <asm/diag.h>
79
#include <asm/uv.h>
810
#include "compressed/decompressor.h"
911
#include "boot.h"
1012

1113
extern char __boot_data_start[], __boot_data_end[];
1214
extern char __boot_data_preserved_start[], __boot_data_preserved_end[];
1315

16+
/*
17+
* Some code and data needs to stay below 2 GB, even when the kernel would be
18+
* relocated above 2 GB, because it has to use 31 bit addresses.
19+
* Such code and data is part of the .dma section, and its location is passed
20+
* over to the decompressed / relocated kernel via the .boot.preserved.data
21+
* section.
22+
*/
23+
extern char _sdma[], _edma[];
24+
extern char _stext_dma[], _etext_dma[];
25+
extern struct exception_table_entry _start_dma_ex_table[];
26+
extern struct exception_table_entry _stop_dma_ex_table[];
27+
unsigned long __bootdata_preserved(__sdma) = __pa(&_sdma);
28+
unsigned long __bootdata_preserved(__edma) = __pa(&_edma);
29+
unsigned long __bootdata_preserved(__stext_dma) = __pa(&_stext_dma);
30+
unsigned long __bootdata_preserved(__etext_dma) = __pa(&_etext_dma);
31+
struct exception_table_entry *
32+
__bootdata_preserved(__start_dma_ex_table) = _start_dma_ex_table;
33+
struct exception_table_entry *
34+
__bootdata_preserved(__stop_dma_ex_table) = _stop_dma_ex_table;
35+
36+
int _diag210_dma(struct diag210 *addr);
37+
int _diag26c_dma(void *req, void *resp, enum diag26c_sc subcode);
38+
int _diag14_dma(unsigned long rx, unsigned long ry1, unsigned long subcode);
39+
void _diag0c_dma(struct hypfs_diag0c_entry *entry);
40+
void _diag308_reset_dma(void);
41+
struct diag_ops __bootdata_preserved(diag_dma_ops) = {
42+
.diag210 = _diag210_dma,
43+
.diag26c = _diag26c_dma,
44+
.diag14 = _diag14_dma,
45+
.diag0c = _diag0c_dma,
46+
.diag308_reset = _diag308_reset_dma
47+
};
48+
static struct diag210 _diag210_tmp_dma __section(".dma.data");
49+
struct diag210 *__bootdata_preserved(__diag210_tmp_dma) = &_diag210_tmp_dma;
50+
void _swsusp_reset_dma(void);
51+
unsigned long __bootdata_preserved(__swsusp_reset_dma) = __pa(_swsusp_reset_dma);
52+
1453
void error(char *x)
1554
{
1655
sclp_early_printk("\n\n");

‎arch/s390/boot/text_dma.S‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Code that needs to run below 2 GB.
4+
*
5+
* Copyright IBM Corp. 2019
6+
*/
7+
8+
#include <linux/linkage.h>
9+
#include <asm/errno.h>
10+
#include <asm/sigp.h>
11+
12+
.section .dma.text,"ax"
13+
/*
14+
* Simplified version of expoline thunk. The normal thunks can not be used here,
15+
* because they might be more than 2 GB away, and not reachable by the relative
16+
* branch. No comdat, exrl, etc. optimizations used here, because it only
17+
* affects a few functions that are not performance-relevant.
18+
*/
19+
.macro BR_EX_DMA_r14
20+
larl %r1,0f
21+
ex 0,0(%r1)
22+
j .
23+
0: br %r14
24+
.endm
25+
26+
/*
27+
* int _diag14_dma(unsigned long rx, unsigned long ry1, unsigned long subcode)
28+
*/
29+
ENTRY(_diag14_dma)
30+
lgr %r1,%r2
31+
lgr %r2,%r3
32+
lgr %r3,%r4
33+
lhi %r5,-EIO
34+
sam31
35+
diag %r1,%r2,0x14
36+
.Ldiag14_ex:
37+
ipm %r5
38+
srl %r5,28
39+
.Ldiag14_fault:
40+
sam64
41+
lgfr %r2,%r5
42+
BR_EX_DMA_r14
43+
EX_TABLE_DMA(.Ldiag14_ex, .Ldiag14_fault)
44+
45+
/*
46+
* int _diag210_dma(struct diag210 *addr)
47+
*/
48+
ENTRY(_diag210_dma)
49+
lgr %r1,%r2
50+
lhi %r2,-1
51+
sam31
52+
diag %r1,%r0,0x210
53+
.Ldiag210_ex:
54+
ipm %r2
55+
srl %r2,28
56+
.Ldiag210_fault:
57+
sam64
58+
lgfr %r2,%r2
59+
BR_EX_DMA_r14
60+
EX_TABLE_DMA(.Ldiag210_ex, .Ldiag210_fault)
61+
62+
/*
63+
* int _diag26c_dma(void *req, void *resp, enum diag26c_sc subcode)
64+
*/
65+
ENTRY(_diag26c_dma)
66+
lghi %r5,-EOPNOTSUPP
67+
sam31
68+
diag %r2,%r4,0x26c
69+
.Ldiag26c_ex:
70+
sam64
71+
lgfr %r2,%r5
72+
BR_EX_DMA_r14
73+
EX_TABLE_DMA(.Ldiag26c_ex, .Ldiag26c_ex)
74+
75+
/*
76+
* void _diag0c_dma(struct hypfs_diag0c_entry *entry)
77+
*/
78+
ENTRY(_diag0c_dma)
79+
sam31
80+
diag %r2,%r2,0x0c
81+
sam64
82+
BR_EX_DMA_r14
83+
84+
/*
85+
* void _swsusp_reset_dma(void)
86+
*/
87+
ENTRY(_swsusp_reset_dma)
88+
larl %r1,restart_entry
89+
larl %r2,.Lrestart_diag308_psw
90+
og %r1,0(%r2)
91+
stg %r1,0(%r0)
92+
lghi %r0,0
93+
diag %r0,%r0,0x308
94+
restart_entry:
95+
lhi %r1,1
96+
sigp %r1,%r0,SIGP_SET_ARCHITECTURE
97+
sam64
98+
BR_EX_DMA_r14
99+
100+
/*
101+
* void _diag308_reset_dma(void)
102+
*
103+
* Calls diag 308 subcode 1 and continues execution
104+
*/
105+
ENTRY(_diag308_reset_dma)
106+
larl %r4,.Lctlregs # Save control registers
107+
stctg %c0,%c15,0(%r4)
108+
lg %r2,0(%r4) # Disable lowcore protection
109+
nilh %r2,0xefff
110+
larl %r4,.Lctlreg0
111+
stg %r2,0(%r4)
112+
lctlg %c0,%c0,0(%r4)
113+
larl %r4,.Lfpctl # Floating point control register
114+
stfpc 0(%r4)
115+
larl %r4,.Lprefix # Save prefix register
116+
stpx 0(%r4)
117+
larl %r4,.Lprefix_zero # Set prefix register to 0
118+
spx 0(%r4)
119+
larl %r4,.Lcontinue_psw # Save PSW flags
120+
epsw %r2,%r3
121+
stm %r2,%r3,0(%r4)
122+
larl %r4,restart_part2 # Setup restart PSW at absolute 0
123+
larl %r3,.Lrestart_diag308_psw
124+
og %r4,0(%r3) # Save PSW
125+
lghi %r3,0
126+
sturg %r4,%r3 # Use sturg, because of large pages
127+
lghi %r1,1
128+
lghi %r0,0
129+
diag %r0,%r1,0x308
130+
restart_part2:
131+
lhi %r0,0 # Load r0 with zero
132+
lhi %r1,2 # Use mode 2 = ESAME (dump)
133+
sigp %r1,%r0,SIGP_SET_ARCHITECTURE # Switch to ESAME mode
134+
sam64 # Switch to 64 bit addressing mode
135+
larl %r4,.Lctlregs # Restore control registers
136+
lctlg %c0,%c15,0(%r4)
137+
larl %r4,.Lfpctl # Restore floating point ctl register
138+
lfpc 0(%r4)
139+
larl %r4,.Lprefix # Restore prefix register
140+
spx 0(%r4)
141+
larl %r4,.Lcontinue_psw # Restore PSW flags
142+
lpswe 0(%r4)
143+
.Lcontinue:
144+
BR_EX_DMA_r14
145+
146+
.section .dma.data,"aw",@progbits
147+
.align 8
148+
.Lrestart_diag308_psw:
149+
.long 0x00080000,0x80000000
150+
151+
.align 8
152+
.Lcontinue_psw:
153+
.quad 0,.Lcontinue
154+
155+
.align 8
156+
.Lctlreg0:
157+
.quad 0
158+
.Lctlregs:
159+
.rept 16
160+
.quad 0
161+
.endr
162+
.Lfpctl:
163+
.long 0
164+
.Lprefix:
165+
.long 0
166+
.Lprefix_zero:
167+
.long 0

‎arch/s390/hypfs/hypfs_diag0c.c‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,13 @@
1515

1616
#define DBFS_D0C_HDR_VERSION 0
1717

18-
/*
19-
* Execute diagnose 0c in 31 bit mode
20-
*/
21-
static void diag0c(struct hypfs_diag0c_entry *entry)
22-
{
23-
diag_stat_inc(DIAG_STAT_X00C);
24-
asm volatile (
25-
" sam31\n"
26-
" diag %0,%0,0x0c\n"
27-
" sam64\n"
28-
: /* no output register */
29-
: "a" (entry)
30-
: "memory");
31-
}
32-
3318
/*
3419
* Get hypfs_diag0c_entry from CPU vector and store diag0c data
3520
*/
3621
static void diag0c_fn(void *data)
3722
{
38-
diag0c(((void **) data)[smp_processor_id()]);
23+
diag_stat_inc(DIAG_STAT_X00C);
24+
diag_dma_ops.diag0c(((void **) data)[smp_processor_id()]);
3925
}
4026

4127
/*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,17 @@ union diag318_info {
308308
int diag204(unsigned long subcode, unsigned long size, void *addr);
309309
int diag224(void *ptr);
310310
int diag26c(void *req, void *resp, enum diag26c_sc subcode);
311+
312+
struct hypfs_diag0c_entry;
313+
314+
struct diag_ops {
315+
int (*diag210)(struct diag210 *addr);
316+
int (*diag26c)(void *req, void *resp, enum diag26c_sc subcode);
317+
int (*diag14)(unsigned long rx, unsigned long ry1, unsigned long subcode);
318+
void (*diag0c)(struct hypfs_diag0c_entry *entry);
319+
void (*diag308_reset)(void);
320+
};
321+
322+
extern struct diag_ops diag_dma_ops;
323+
extern struct diag210 *__diag210_tmp_dma;
311324
#endif /* _ASM_S390_DIAG_H */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ struct exception_table_entry
1919
int insn, fixup;
2020
};
2121

22+
extern struct exception_table_entry *__start_dma_ex_table;
23+
extern struct exception_table_entry *__stop_dma_ex_table;
24+
25+
const struct exception_table_entry *s390_search_extables(unsigned long addr);
26+
2227
static inline unsigned long extable_fixup(const struct exception_table_entry *x)
2328
{
2429
return (unsigned long)&x->fixup + x->fixup;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ enum diag308_rc {
127127
};
128128

129129
extern int diag308(unsigned long subcode, void *addr);
130-
extern void diag308_reset(void);
131130
extern void store_status(void (*fn)(void *), void *data);
132131
extern void lgr_info_log(void);
133132

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@
2828
.long (_target) - . ; \
2929
.previous
3030

31+
#define EX_TABLE_DMA(_fault, _target) \
32+
.section .dma.ex_table, "a" ; \
33+
.align 4 ; \
34+
.long (_fault) - . ; \
35+
.long (_target) - . ; \
36+
.previous
37+
3138
#endif /* __ASSEMBLY__ */
3239
#endif

0 commit comments

Comments
 (0)