Commit f8431b8
spi: spidev: fix lock inversion between spi_lock and buf_lock
[ Upstream commit 40534d1 ]
The spidev driver previously used two mutexes, spi_lock and buf_lock,
but acquired them in different orders depending on the code path:
write()/read(): buf_lock -> spi_lock
ioctl(): spi_lock -> buf_lock
This AB-BA locking pattern triggers lockdep warnings and can
cause real deadlocks:
WARNING: possible circular locking dependency detected
spidev_ioctl() -> mutex_lock(&spidev->buf_lock)
spidev_sync_write() -> mutex_lock(&spidev->spi_lock)
*** DEADLOCK ***
The issue is reproducible with a simple userspace program that
performs write() and SPI_IOC_WR_MAX_SPEED_HZ ioctl() calls from
separate threads on the same spidev file descriptor.
Fix this by simplifying the locking model and removing the lock
inversion entirely. spidev_sync() no longer performs any locking,
and all callers serialize access using spi_lock.
buf_lock is removed since its functionality is fully covered by
spi_lock, eliminating the possibility of lock ordering issues.
This removes the lock inversion and prevents deadlocks without
changing userspace ABI or behaviour.
Signed-off-by: Fabian Godehardt <fg@emlix.com>
Link: https://patch.msgid.link/20260211072616.489522-1-fg@emlix.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent b701db9 commit f8431b8
1 file changed
+22
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | 77 | | |
79 | 78 | | |
80 | 79 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | 104 | | |
124 | 105 | | |
125 | 106 | | |
| |||
132 | 113 | | |
133 | 114 | | |
134 | 115 | | |
135 | | - | |
| 116 | + | |
| 117 | + | |
136 | 118 | | |
137 | 119 | | |
138 | 120 | | |
| |||
147 | 129 | | |
148 | 130 | | |
149 | 131 | | |
150 | | - | |
| 132 | + | |
| 133 | + | |
151 | 134 | | |
152 | 135 | | |
153 | 136 | | |
| |||
157 | 140 | | |
158 | 141 | | |
159 | 142 | | |
160 | | - | |
| 143 | + | |
161 | 144 | | |
162 | 145 | | |
163 | 146 | | |
164 | 147 | | |
165 | 148 | | |
166 | 149 | | |
167 | 150 | | |
168 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
169 | 156 | | |
170 | 157 | | |
171 | 158 | | |
| |||
176 | 163 | | |
177 | 164 | | |
178 | 165 | | |
179 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
180 | 169 | | |
181 | 170 | | |
182 | 171 | | |
| |||
187 | 176 | | |
188 | 177 | | |
189 | 178 | | |
190 | | - | |
| 179 | + | |
191 | 180 | | |
192 | 181 | | |
193 | 182 | | |
| |||
196 | 185 | | |
197 | 186 | | |
198 | 187 | | |
199 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
200 | 193 | | |
201 | 194 | | |
202 | 195 | | |
203 | 196 | | |
204 | 197 | | |
205 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
206 | 201 | | |
207 | 202 | | |
208 | 203 | | |
| |||
379 | 374 | | |
380 | 375 | | |
381 | 376 | | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | 377 | | |
391 | 378 | | |
392 | 379 | | |
| |||
510 | 497 | | |
511 | 498 | | |
512 | 499 | | |
513 | | - | |
514 | 500 | | |
515 | 501 | | |
516 | 502 | | |
| |||
541 | 527 | | |
542 | 528 | | |
543 | 529 | | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | 530 | | |
548 | 531 | | |
549 | 532 | | |
| |||
564 | 547 | | |
565 | 548 | | |
566 | 549 | | |
567 | | - | |
568 | 550 | | |
569 | 551 | | |
570 | 552 | | |
| |||
790 | 772 | | |
791 | 773 | | |
792 | 774 | | |
793 | | - | |
794 | 775 | | |
795 | 776 | | |
796 | 777 | | |
| |||
0 commit comments