diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2014-12-02 18:59:28 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-02 20:32:07 -0500 |
commit | 91b57191cfd152c02ded0745250167d0263084f8 (patch) | |
tree | 677bb8c059094859904003cb7af01cbee1d9773e | |
parent | fb993fa1a2f669215fa03a09eed7848f2663e336 (diff) |
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>
-rw-r--r-- | mm/vmpressure.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/mm/vmpressure.c b/mm/vmpressure.c index d4042e75f7c7..c5afd573d7da 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c | |||
@@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work) | |||
165 | unsigned long scanned; | 165 | unsigned long scanned; |
166 | unsigned long reclaimed; | 166 | unsigned long reclaimed; |
167 | 167 | ||
168 | spin_lock(&vmpr->sr_lock); | ||
168 | /* | 169 | /* |
169 | * Several contexts might be calling vmpressure(), so it is | 170 | * Several contexts might be calling vmpressure(), so it is |
170 | * possible that the work was rescheduled again before the old | 171 | * possible that the work was rescheduled again before the old |
@@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work) | |||
173 | * here. No need for any locks here since we don't care if | 174 | * here. No need for any locks here since we don't care if |
174 | * vmpr->reclaimed is in sync. | 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 | return; | 180 | return; |
181 | } | ||
178 | 182 | ||
179 | spin_lock(&vmpr->sr_lock); | ||
180 | scanned = vmpr->scanned; | ||
181 | reclaimed = vmpr->reclaimed; | 183 | reclaimed = vmpr->reclaimed; |
182 | vmpr->scanned = 0; | 184 | vmpr->scanned = 0; |
183 | vmpr->reclaimed = 0; | 185 | vmpr->reclaimed = 0; |