Commit 91b57191cfd152c02ded0745250167d0263084f8
Committed by
Linus Torvalds
1 parent
fb993fa1a2
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
mm/vmpressure.c: fix race in vmpressure_work_fn()
In some android devices, there will be a "divide by zero" exception. vmpr->scanned could be zero before spin_lock(&vmpr->sr_lock). Addresses https://bugzilla.kernel.org/show_bug.cgi?id=88051 [akpm@linux-foundation.org: neaten] Reported-by: ji_ang <ji_ang@163.com> Cc: Anton Vorontsov <anton.vorontsov@linaro.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 5 additions and 3 deletions Side-by-side Diff
mm/vmpressure.c
... | ... | @@ -165,6 +165,7 @@ |
165 | 165 | unsigned long scanned; |
166 | 166 | unsigned long reclaimed; |
167 | 167 | |
168 | + spin_lock(&vmpr->sr_lock); | |
168 | 169 | /* |
169 | 170 | * Several contexts might be calling vmpressure(), so it is |
170 | 171 | * possible that the work was rescheduled again before the old |
171 | 172 | |
172 | 173 | |
... | ... | @@ -173,11 +174,12 @@ |
173 | 174 | * here. No need for any locks here since we don't care if |
174 | 175 | * vmpr->reclaimed is in sync. |
175 | 176 | */ |
176 | - if (!vmpr->scanned) | |
177 | + scanned = vmpr->scanned; | |
178 | + if (!scanned) { | |
179 | + spin_unlock(&vmpr->sr_lock); | |
177 | 180 | return; |
181 | + } | |
178 | 182 | |
179 | - spin_lock(&vmpr->sr_lock); | |
180 | - scanned = vmpr->scanned; | |
181 | 183 | reclaimed = vmpr->reclaimed; |
182 | 184 | vmpr->scanned = 0; |
183 | 185 | vmpr->reclaimed = 0; |