Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07a154b2 authored by Michal Schmidt's avatar Michal Schmidt Committed by Linus Torvalds
Browse files

proc: loadavg reading race



The avenrun[] values are supposed to be protected by xtime_lock.
loadavg_read_proc does not use it.  Theoretically this may result in an
occasional glitch when the value read from /proc/loadavg would be as much
as 1<<11 times higher than it should be.

Signed-off-by: default avatarMichal Schmidt <mschmidt@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0a76fe8e
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -84,10 +84,15 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
{
	int a, b, c;
	int len;
	unsigned long seq;

	do {
		seq = read_seqbegin(&xtime_lock);
		a = avenrun[0] + (FIXED_1/200);
		b = avenrun[1] + (FIXED_1/200);
		c = avenrun[2] + (FIXED_1/200);
	} while (read_seqretry(&xtime_lock, seq));

	len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
		LOAD_INT(a), LOAD_FRAC(a),
		LOAD_INT(b), LOAD_FRAC(b),