Commit 23c1ad5
x86/alternatives: Optimize optimize_nops()
Currently, optimize_nops() scans to see if the alternative starts with
NOPs. However, the emit pattern is:
141: \oldinstr
142: .skip (len-(142b-141b)), 0x90
That is, when 'oldinstr' is short, the tail is padded with NOPs. This case
never gets optimized.
Rewrite optimize_nops() to replace any trailing string of NOPs inside
the alternative to larger NOPs. Also run it irrespective of patching,
replacing NOPs in both the original and replaced code.
A direct consequence is that 'padlen' becomes superfluous, so remove it.
[ bp:
- Adjust commit message
- remove a stale comment about needing to pad
- add a comment in optimize_nops()
- exit early if the NOP verif. loop catches a mismatch - function
should not not add NOPs in that case
- fix the "optimized NOPs" offsets output ]
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20210326151259.442992235@infradead.org1 parent b1f480b commit 23c1ad5
3 files changed
Lines changed: 37 additions & 31 deletions
File tree
- arch/x86
- include/asm
- kernel
- tools/objtool/arch/x86/include/arch
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| |||
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
107 | | - | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
| |||
151 | 149 | | |
152 | 150 | | |
153 | 151 | | |
154 | | - | |
155 | | - | |
| 152 | + | |
156 | 153 | | |
157 | 154 | | |
158 | 155 | | |
| |||
224 | 221 | | |
225 | 222 | | |
226 | 223 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | 224 | | |
231 | 225 | | |
232 | 226 | | |
| |||
315 | 309 | | |
316 | 310 | | |
317 | 311 | | |
318 | | - | |
| 312 | + | |
319 | 313 | | |
320 | 314 | | |
321 | 315 | | |
322 | 316 | | |
323 | 317 | | |
324 | | - | |
325 | 318 | | |
326 | 319 | | |
327 | 320 | | |
| |||
338 | 331 | | |
339 | 332 | | |
340 | 333 | | |
341 | | - | |
| 334 | + | |
342 | 335 | | |
343 | 336 | | |
344 | 337 | | |
| |||
375 | 368 | | |
376 | 369 | | |
377 | 370 | | |
378 | | - | |
379 | | - | |
| 371 | + | |
| 372 | + | |
380 | 373 | | |
381 | 374 | | |
382 | 375 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
193 | 209 | | |
194 | | - | |
195 | | - | |
| 210 | + | |
| 211 | + | |
196 | 212 | | |
197 | 213 | | |
198 | 214 | | |
199 | 215 | | |
200 | | - | |
| 216 | + | |
201 | 217 | | |
202 | 218 | | |
203 | 219 | | |
204 | | - | |
| 220 | + | |
205 | 221 | | |
206 | 222 | | |
207 | 223 | | |
| |||
247 | 263 | | |
248 | 264 | | |
249 | 265 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 266 | + | |
| 267 | + | |
256 | 268 | | |
257 | | - | |
| 269 | + | |
258 | 270 | | |
259 | 271 | | |
260 | 272 | | |
261 | 273 | | |
262 | | - | |
| 274 | + | |
263 | 275 | | |
264 | 276 | | |
265 | 277 | | |
| |||
283 | 295 | | |
284 | 296 | | |
285 | 297 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
291 | 301 | | |
292 | 302 | | |
293 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
294 | 307 | | |
295 | 308 | | |
296 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
0 commit comments