.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* align.c - handle alignment exceptions for the Power PC. |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> |
---|
.. | .. |
---|
10 | 11 | * Copyright (c) 2005 Benjamin Herrenschmidt, IBM Corp |
---|
11 | 12 | * <benh@kernel.crashing.org> |
---|
12 | 13 | * Merge ppc32 and ppc64 implementations |
---|
13 | | - * |
---|
14 | | - * This program is free software; you can redistribute it and/or |
---|
15 | | - * modify it under the terms of the GNU General Public License |
---|
16 | | - * as published by the Free Software Foundation; either version |
---|
17 | | - * 2 of the License, or (at your option) any later version. |
---|
18 | 14 | */ |
---|
19 | 15 | |
---|
20 | 16 | #include <linux/kernel.h> |
---|
.. | .. |
---|
28 | 24 | #include <asm/disassemble.h> |
---|
29 | 25 | #include <asm/cpu_has_feature.h> |
---|
30 | 26 | #include <asm/sstep.h> |
---|
| 27 | +#include <asm/inst.h> |
---|
31 | 28 | |
---|
32 | 29 | struct aligninfo { |
---|
33 | 30 | unsigned char len; |
---|
.. | .. |
---|
108 | 105 | * so we don't need the address swizzling. |
---|
109 | 106 | */ |
---|
110 | 107 | static int emulate_spe(struct pt_regs *regs, unsigned int reg, |
---|
111 | | - unsigned int instr) |
---|
| 108 | + struct ppc_inst ppc_instr) |
---|
112 | 109 | { |
---|
113 | 110 | int ret; |
---|
114 | 111 | union { |
---|
.. | .. |
---|
119 | 116 | } data, temp; |
---|
120 | 117 | unsigned char __user *p, *addr; |
---|
121 | 118 | unsigned long *evr = ¤t->thread.evr[reg]; |
---|
122 | | - unsigned int nb, flags; |
---|
| 119 | + unsigned int nb, flags, instr; |
---|
123 | 120 | |
---|
| 121 | + instr = ppc_inst_val(ppc_instr); |
---|
124 | 122 | instr = (instr >> 1) & 0x1f; |
---|
125 | 123 | |
---|
126 | 124 | /* DAR has the operand effective address */ |
---|
.. | .. |
---|
131 | 129 | |
---|
132 | 130 | /* Verify the address of the operand */ |
---|
133 | 131 | if (unlikely(user_mode(regs) && |
---|
134 | | - !access_ok((flags & ST ? VERIFY_WRITE : VERIFY_READ), |
---|
135 | | - addr, nb))) |
---|
| 132 | + !access_ok(addr, nb))) |
---|
136 | 133 | return -EFAULT; |
---|
137 | 134 | |
---|
138 | 135 | /* userland only */ |
---|
.. | .. |
---|
181 | 178 | ret |= __get_user_inatomic(temp.v[1], p++); |
---|
182 | 179 | ret |= __get_user_inatomic(temp.v[2], p++); |
---|
183 | 180 | ret |= __get_user_inatomic(temp.v[3], p++); |
---|
| 181 | + fallthrough; |
---|
184 | 182 | case 4: |
---|
185 | 183 | ret |= __get_user_inatomic(temp.v[4], p++); |
---|
186 | 184 | ret |= __get_user_inatomic(temp.v[5], p++); |
---|
| 185 | + fallthrough; |
---|
187 | 186 | case 2: |
---|
188 | 187 | ret |= __get_user_inatomic(temp.v[6], p++); |
---|
189 | 188 | ret |= __get_user_inatomic(temp.v[7], p++); |
---|
.. | .. |
---|
264 | 263 | ret |= __put_user_inatomic(data.v[1], p++); |
---|
265 | 264 | ret |= __put_user_inatomic(data.v[2], p++); |
---|
266 | 265 | ret |= __put_user_inatomic(data.v[3], p++); |
---|
| 266 | + fallthrough; |
---|
267 | 267 | case 4: |
---|
268 | 268 | ret |= __put_user_inatomic(data.v[4], p++); |
---|
269 | 269 | ret |= __put_user_inatomic(data.v[5], p++); |
---|
| 270 | + fallthrough; |
---|
270 | 271 | case 2: |
---|
271 | 272 | ret |= __put_user_inatomic(data.v[6], p++); |
---|
272 | 273 | ret |= __put_user_inatomic(data.v[7], p++); |
---|
.. | .. |
---|
294 | 295 | |
---|
295 | 296 | int fix_alignment(struct pt_regs *regs) |
---|
296 | 297 | { |
---|
297 | | - unsigned int instr; |
---|
| 298 | + struct ppc_inst instr; |
---|
298 | 299 | struct instruction_op op; |
---|
299 | 300 | int r, type; |
---|
300 | 301 | |
---|
.. | .. |
---|
304 | 305 | */ |
---|
305 | 306 | CHECK_FULL_REGS(regs); |
---|
306 | 307 | |
---|
307 | | - if (unlikely(__get_user(instr, (unsigned int __user *)regs->nip))) |
---|
| 308 | + if (unlikely(__get_user_instr(instr, (void __user *)regs->nip))) |
---|
308 | 309 | return -EFAULT; |
---|
309 | 310 | if ((regs->msr & MSR_LE) != (MSR_KERNEL & MSR_LE)) { |
---|
310 | 311 | /* We don't handle PPC little-endian any more... */ |
---|
311 | 312 | if (cpu_has_feature(CPU_FTR_PPC_LE)) |
---|
312 | 313 | return -EIO; |
---|
313 | | - instr = swab32(instr); |
---|
| 314 | + instr = ppc_inst_swab(instr); |
---|
314 | 315 | } |
---|
315 | 316 | |
---|
316 | 317 | #ifdef CONFIG_SPE |
---|
317 | | - if ((instr >> 26) == 0x4) { |
---|
318 | | - int reg = (instr >> 21) & 0x1f; |
---|
| 318 | + if (ppc_inst_primary_opcode(instr) == 0x4) { |
---|
| 319 | + int reg = (ppc_inst_val(instr) >> 21) & 0x1f; |
---|
319 | 320 | PPC_WARN_ALIGNMENT(spe, regs); |
---|
320 | 321 | return emulate_spe(regs, reg, instr); |
---|
321 | 322 | } |
---|
.. | .. |
---|
332 | 333 | * when pasting to a co-processor. Furthermore, paste_last is the |
---|
333 | 334 | * synchronisation point for preceding copy/paste sequences. |
---|
334 | 335 | */ |
---|
335 | | - if ((instr & 0xfc0006fe) == (PPC_INST_COPY & 0xfc0006fe)) |
---|
| 336 | + if ((ppc_inst_val(instr) & 0xfc0006fe) == (PPC_INST_COPY & 0xfc0006fe)) |
---|
336 | 337 | return -EIO; |
---|
337 | 338 | |
---|
338 | 339 | r = analyse_instr(&op, regs, instr); |
---|