]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.61/powerpc-don-t-try-to-fix-up-misaligned-load-with-reservation-instructions.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.4.61 / powerpc-don-t-try-to-fix-up-misaligned-load-with-reservation-instructions.patch
CommitLineData
381a4dca
GKH
1From 48fe9e9488743eec9b7c1addd3c93f12f2123d54 Mon Sep 17 00:00:00 2001
2From: Paul Mackerras <paulus@ozlabs.org>
3Date: Tue, 4 Apr 2017 14:56:05 +1000
4Subject: powerpc: Don't try to fix up misaligned load-with-reservation instructions
5
6From: Paul Mackerras <paulus@ozlabs.org>
7
8commit 48fe9e9488743eec9b7c1addd3c93f12f2123d54 upstream.
9
10In the past, there was only one load-with-reservation instruction,
11lwarx, and if a program attempted a lwarx on a misaligned address, it
12would take an alignment interrupt and the kernel handler would emulate
13it as though it was lwzx, which was not really correct, but benign since
14it is loading the right amount of data, and the lwarx should be paired
15with a stwcx. to the same address, which would also cause an alignment
16interrupt which would result in a SIGBUS being delivered to the process.
17
18We now have 5 different sizes of load-with-reservation instruction. Of
19those, lharx and ldarx cause an immediate SIGBUS by luck since their
20entries in aligninfo[] overlap instructions which were not fixed up, but
21lqarx overlaps with lhz and will be emulated as such. lbarx can never
22generate an alignment interrupt since it only operates on 1 byte.
23
24To straighten this out and fix the lqarx case, this adds code to detect
25the l[hwdq]arx instructions and return without fixing them up, resulting
26in a SIGBUS being delivered to the process.
27
28Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
29Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
30Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32---
33 arch/powerpc/kernel/align.c | 27 +++++++++++++++++++--------
34 1 file changed, 19 insertions(+), 8 deletions(-)
35
36--- a/arch/powerpc/kernel/align.c
37+++ b/arch/powerpc/kernel/align.c
38@@ -808,14 +808,25 @@ int fix_alignment(struct pt_regs *regs)
39 nb = aligninfo[instr].len;
40 flags = aligninfo[instr].flags;
41
42- /* ldbrx/stdbrx overlap lfs/stfs in the DSISR unfortunately */
43- if (IS_XFORM(instruction) && ((instruction >> 1) & 0x3ff) == 532) {
44- nb = 8;
45- flags = LD+SW;
46- } else if (IS_XFORM(instruction) &&
47- ((instruction >> 1) & 0x3ff) == 660) {
48- nb = 8;
49- flags = ST+SW;
50+ /*
51+ * Handle some cases which give overlaps in the DSISR values.
52+ */
53+ if (IS_XFORM(instruction)) {
54+ switch (get_xop(instruction)) {
55+ case 532: /* ldbrx */
56+ nb = 8;
57+ flags = LD+SW;
58+ break;
59+ case 660: /* stdbrx */
60+ nb = 8;
61+ flags = ST+SW;
62+ break;
63+ case 20: /* lwarx */
64+ case 84: /* ldarx */
65+ case 116: /* lharx */
66+ case 276: /* lqarx */
67+ return 0; /* not emulated ever */
68+ }
69 }
70
71 /* Byteswap little endian loads and stores */