Commit 98d7f839 authored by Andrew Morton's avatar Andrew Morton Committed by Luis Henriques

mm/vmpressure.c: fix race in vmpressure_work_fn()

commit 91b57191 upstream.

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: default avatarji_ang <ji_ang@163.com>
Cc: Anton Vorontsov <anton.vorontsov@linaro.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent c153b494
...@@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work) ...@@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work)
unsigned long scanned; unsigned long scanned;
unsigned long reclaimed; unsigned long reclaimed;
spin_lock(&vmpr->sr_lock);
/* /*
* Several contexts might be calling vmpressure(), so it is * Several contexts might be calling vmpressure(), so it is
* possible that the work was rescheduled again before the old * possible that the work was rescheduled again before the old
...@@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work) ...@@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work)
* here. No need for any locks here since we don't care if * here. No need for any locks here since we don't care if
* vmpr->reclaimed is in sync. * vmpr->reclaimed is in sync.
*/ */
if (!vmpr->scanned) scanned = vmpr->scanned;
if (!scanned) {
spin_unlock(&vmpr->sr_lock);
return; return;
}
spin_lock(&vmpr->sr_lock);
scanned = vmpr->scanned;
reclaimed = vmpr->reclaimed; reclaimed = vmpr->reclaimed;
vmpr->scanned = 0; vmpr->scanned = 0;
vmpr->reclaimed = 0; vmpr->reclaimed = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment