1 |
From b7d6f44a0fa716a82969725516dc0b16bc7cd514 Mon Sep 17 00:00:00 2001 |
2 |
From: John David Anglin <dave.anglin@bell.net> |
3 |
Date: Wed, 26 Jan 2022 20:39:05 +0000 |
4 |
Subject: parisc: Fix data TLB miss in sba_unmap_sg |
5 |
|
6 |
From: John David Anglin <dave.anglin@bell.net> |
7 |
|
8 |
commit b7d6f44a0fa716a82969725516dc0b16bc7cd514 upstream. |
9 |
|
10 |
Rolf Eike Beer reported the following bug: |
11 |
|
12 |
[1274934.746891] Bad Address (null pointer deref?): Code=15 (Data TLB miss fault) at addr 0000004140000018 |
13 |
[1274934.746891] CPU: 3 PID: 5549 Comm: cmake Not tainted 5.15.4-gentoo-parisc64 #4 |
14 |
[1274934.746891] Hardware name: 9000/785/C8000 |
15 |
[1274934.746891] |
16 |
[1274934.746891] YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI |
17 |
[1274934.746891] PSW: 00001000000001001111111000001110 Not tainted |
18 |
[1274934.746891] r00-03 000000ff0804fe0e 0000000040bc9bc0 00000000406760e4 0000004140000000 |
19 |
[1274934.746891] r04-07 0000000040b693c0 0000004140000000 000000004a2b08b0 0000000000000001 |
20 |
[1274934.746891] r08-11 0000000041f98810 0000000000000000 000000004a0a7000 0000000000000001 |
21 |
[1274934.746891] r12-15 0000000040bddbc0 0000000040c0cbc0 0000000040bddbc0 0000000040bddbc0 |
22 |
[1274934.746891] r16-19 0000000040bde3c0 0000000040bddbc0 0000000040bde3c0 0000000000000007 |
23 |
[1274934.746891] r20-23 0000000000000006 000000004a368950 0000000000000000 0000000000000001 |
24 |
[1274934.746891] r24-27 0000000000001fff 000000000800000e 000000004a1710f0 0000000040b693c0 |
25 |
[1274934.746891] r28-31 0000000000000001 0000000041f988b0 0000000041f98840 000000004a171118 |
26 |
[1274934.746891] sr00-03 00000000066e5800 0000000000000000 0000000000000000 00000000066e5800 |
27 |
[1274934.746891] sr04-07 0000000000000000 0000000000000000 0000000000000000 0000000000000000 |
28 |
[1274934.746891] |
29 |
[1274934.746891] IASQ: 0000000000000000 0000000000000000 IAOQ: 00000000406760e8 00000000406760ec |
30 |
[1274934.746891] IIR: 48780030 ISR: 0000000000000000 IOR: 0000004140000018 |
31 |
[1274934.746891] CPU: 3 CR30: 00000040e3a9c000 CR31: ffffffffffffffff |
32 |
[1274934.746891] ORIG_R28: 0000000040acdd58 |
33 |
[1274934.746891] IAOQ[0]: sba_unmap_sg+0xb0/0x118 |
34 |
[1274934.746891] IAOQ[1]: sba_unmap_sg+0xb4/0x118 |
35 |
[1274934.746891] RP(r2): sba_unmap_sg+0xac/0x118 |
36 |
[1274934.746891] Backtrace: |
37 |
[1274934.746891] [<00000000402740cc>] dma_unmap_sg_attrs+0x6c/0x70 |
38 |
[1274934.746891] [<000000004074d6bc>] scsi_dma_unmap+0x54/0x60 |
39 |
[1274934.746891] [<00000000407a3488>] mptscsih_io_done+0x150/0xd70 |
40 |
[1274934.746891] [<0000000040798600>] mpt_interrupt+0x168/0xa68 |
41 |
[1274934.746891] [<0000000040255a48>] __handle_irq_event_percpu+0xc8/0x278 |
42 |
[1274934.746891] [<0000000040255c34>] handle_irq_event_percpu+0x3c/0xd8 |
43 |
[1274934.746891] [<000000004025ecb4>] handle_percpu_irq+0xb4/0xf0 |
44 |
[1274934.746891] [<00000000402548e0>] generic_handle_irq+0x50/0x70 |
45 |
[1274934.746891] [<000000004019a254>] call_on_stack+0x18/0x24 |
46 |
[1274934.746891] |
47 |
[1274934.746891] Kernel panic - not syncing: Bad Address (null pointer deref?) |
48 |
|
49 |
The bug is caused by overrunning the sglist and incorrectly testing |
50 |
sg_dma_len(sglist) before nents. Normally this doesn't cause a crash, |
51 |
but in this case sglist crossed a page boundary. This occurs in the |
52 |
following code: |
53 |
|
54 |
while (sg_dma_len(sglist) && nents--) { |
55 |
|
56 |
The fix is simply to test nents first and move the decrement of nents |
57 |
into the loop. |
58 |
|
59 |
Reported-by: Rolf Eike Beer <eike-kernel@sf-tec.de> |
60 |
Signed-off-by: John David Anglin <dave.anglin@bell.net> |
61 |
Cc: stable@vger.kernel.org |
62 |
Signed-off-by: Helge Deller <deller@gmx.de> |
63 |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
64 |
--- |
65 |
drivers/parisc/sba_iommu.c | 3 ++- |
66 |
1 file changed, 2 insertions(+), 1 deletion(-) |
67 |
|
68 |
--- a/drivers/parisc/sba_iommu.c |
69 |
+++ b/drivers/parisc/sba_iommu.c |
70 |
@@ -1047,7 +1047,7 @@ sba_unmap_sg(struct device *dev, struct |
71 |
spin_unlock_irqrestore(&ioc->res_lock, flags); |
72 |
#endif |
73 |
|
74 |
- while (sg_dma_len(sglist) && nents--) { |
75 |
+ while (nents && sg_dma_len(sglist)) { |
76 |
|
77 |
sba_unmap_page(dev, sg_dma_address(sglist), sg_dma_len(sglist), |
78 |
direction, 0); |
79 |
@@ -1056,6 +1056,7 @@ sba_unmap_sg(struct device *dev, struct |
80 |
ioc->usingle_calls--; /* kluge since call is unmap_sg() */ |
81 |
#endif |
82 |
++sglist; |
83 |
+ nents--; |
84 |
} |
85 |
|
86 |
DBG_RUN_SG("%s() DONE (nents %d)\n", __func__, nents); |