]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.133/s390-add-assembler-macros-for-cpu-alternatives.patch
Remove duplicated commits
[thirdparty/kernel/stable-queue.git] / releases / 4.4.133 / s390-add-assembler-macros-for-cpu-alternatives.patch
1 From foo@baz Wed May 23 19:42:20 CEST 2018
2 From: Martin Schwidefsky <schwidefsky@de.ibm.com>
3 Date: Wed, 23 May 2018 18:21:28 +0200
4 Subject: s390: add assembler macros for CPU alternatives
5 To: stable@vger.kernel.org
6 Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
7 Message-ID: <1527092496-24207-2-git-send-email-schwidefsky@de.ibm.com>
8
9 From: Martin Schwidefsky <schwidefsky@de.ibm.com>
10
11 [ Upstream commit fba9eb7946251d6e420df3bdf7bc45195be7be9a ]
12
13 Add a header with macros usable in assembler files to emit alternative
14 code sequences. It works analog to the alternatives for inline assmeblies
15 in C files, with the same restrictions and capabilities.
16 The syntax is
17
18 ALTERNATIVE "<default instructions sequence>", \
19 "<alternative instructions sequence>", \
20 "<features-bit>"
21 and
22
23 ALTERNATIVE_2 "<default instructions sequence>", \
24 "<alternative instructions sqeuence #1>", \
25 "<feature-bit #1>",
26 "<alternative instructions sqeuence #2>", \
27 "<feature-bit #2>"
28
29 Reviewed-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
30 Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32 ---
33 arch/s390/include/asm/alternative-asm.h | 108 ++++++++++++++++++++++++++++++++
34 1 file changed, 108 insertions(+)
35 create mode 100644 arch/s390/include/asm/alternative-asm.h
36
37 --- /dev/null
38 +++ b/arch/s390/include/asm/alternative-asm.h
39 @@ -0,0 +1,108 @@
40 +/* SPDX-License-Identifier: GPL-2.0 */
41 +#ifndef _ASM_S390_ALTERNATIVE_ASM_H
42 +#define _ASM_S390_ALTERNATIVE_ASM_H
43 +
44 +#ifdef __ASSEMBLY__
45 +
46 +/*
47 + * Check the length of an instruction sequence. The length may not be larger
48 + * than 254 bytes and it has to be divisible by 2.
49 + */
50 +.macro alt_len_check start,end
51 + .if ( \end - \start ) > 254
52 + .error "cpu alternatives does not support instructions blocks > 254 bytes\n"
53 + .endif
54 + .if ( \end - \start ) % 2
55 + .error "cpu alternatives instructions length is odd\n"
56 + .endif
57 +.endm
58 +
59 +/*
60 + * Issue one struct alt_instr descriptor entry (need to put it into
61 + * the section .altinstructions, see below). This entry contains
62 + * enough information for the alternatives patching code to patch an
63 + * instruction. See apply_alternatives().
64 + */
65 +.macro alt_entry orig_start, orig_end, alt_start, alt_end, feature
66 + .long \orig_start - .
67 + .long \alt_start - .
68 + .word \feature
69 + .byte \orig_end - \orig_start
70 + .byte \alt_end - \alt_start
71 +.endm
72 +
73 +/*
74 + * Fill up @bytes with nops. The macro emits 6-byte nop instructions
75 + * for the bulk of the area, possibly followed by a 4-byte and/or
76 + * a 2-byte nop if the size of the area is not divisible by 6.
77 + */
78 +.macro alt_pad_fill bytes
79 + .fill ( \bytes ) / 6, 6, 0xc0040000
80 + .fill ( \bytes ) % 6 / 4, 4, 0x47000000
81 + .fill ( \bytes ) % 6 % 4 / 2, 2, 0x0700
82 +.endm
83 +
84 +/*
85 + * Fill up @bytes with nops. If the number of bytes is larger
86 + * than 6, emit a jg instruction to branch over all nops, then
87 + * fill an area of size (@bytes - 6) with nop instructions.
88 + */
89 +.macro alt_pad bytes
90 + .if ( \bytes > 0 )
91 + .if ( \bytes > 6 )
92 + jg . + \bytes
93 + alt_pad_fill \bytes - 6
94 + .else
95 + alt_pad_fill \bytes
96 + .endif
97 + .endif
98 +.endm
99 +
100 +/*
101 + * Define an alternative between two instructions. If @feature is
102 + * present, early code in apply_alternatives() replaces @oldinstr with
103 + * @newinstr. ".skip" directive takes care of proper instruction padding
104 + * in case @newinstr is longer than @oldinstr.
105 + */
106 +.macro ALTERNATIVE oldinstr, newinstr, feature
107 + .pushsection .altinstr_replacement,"ax"
108 +770: \newinstr
109 +771: .popsection
110 +772: \oldinstr
111 +773: alt_len_check 770b, 771b
112 + alt_len_check 772b, 773b
113 + alt_pad ( ( 771b - 770b ) - ( 773b - 772b ) )
114 +774: .pushsection .altinstructions,"a"
115 + alt_entry 772b, 774b, 770b, 771b, \feature
116 + .popsection
117 +.endm
118 +
119 +/*
120 + * Define an alternative between two instructions. If @feature is
121 + * present, early code in apply_alternatives() replaces @oldinstr with
122 + * @newinstr. ".skip" directive takes care of proper instruction padding
123 + * in case @newinstr is longer than @oldinstr.
124 + */
125 +.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
126 + .pushsection .altinstr_replacement,"ax"
127 +770: \newinstr1
128 +771: \newinstr2
129 +772: .popsection
130 +773: \oldinstr
131 +774: alt_len_check 770b, 771b
132 + alt_len_check 771b, 772b
133 + alt_len_check 773b, 774b
134 + .if ( 771b - 770b > 772b - 771b )
135 + alt_pad ( ( 771b - 770b ) - ( 774b - 773b ) )
136 + .else
137 + alt_pad ( ( 772b - 771b ) - ( 774b - 773b ) )
138 + .endif
139 +775: .pushsection .altinstructions,"a"
140 + alt_entry 773b, 775b, 770b, 771b,\feature1
141 + alt_entry 773b, 775b, 771b, 772b,\feature2
142 + .popsection
143 +.endm
144 +
145 +#endif /* __ASSEMBLY__ */
146 +
147 +#endif /* _ASM_S390_ALTERNATIVE_ASM_H */