]> git.baikalelectronics.ru Git - kernel.git/commit
sched/vtime: Fix guest/system mis-accounting on task switch
authorFrederic Weisbecker <frederic@kernel.org>
Wed, 25 Sep 2019 21:42:42 +0000 (23:42 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 9 Oct 2019 10:38:03 +0000 (12:38 +0200)
commitcebb4ed69837a3ea6db0c4ca98d33f4d4ae3f4e7
treed6f8e254d87856ab2ce6d8c1800a26ab3ef8cce2
parent4d72f6496ac4e3d2311eb1f7b8b59b9f64c3ccad
sched/vtime: Fix guest/system mis-accounting on task switch

vtime_account_system() assumes that the target task to account cputime
to is always the current task. This is most often true indeed except on
task switch where we call:

vtime_common_task_switch(prev)
vtime_account_system(prev)

Here prev is the scheduling-out task where we account the cputime to. It
doesn't match current that is already the scheduling-in task at this
stage of the context switch.

So we end up checking the wrong task flags to determine if we are
accounting guest or system time to the previous task.

As a result the wrong task is used to check if the target is running in
guest mode. We may then spuriously account or leak either system or
guest time on task switch.

Fix this assumption and also turn vtime_guest_enter/exit() to use the
task passed in parameter as well to avoid future similar issues.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wanpeng Li <wanpengli@tencent.com>
Fixes: 3d05681cd12b ("sched/cputime: Accumulate vtime on top of nsec clocksource")
Link: https://lkml.kernel.org/r/20190925214242.21873-1-frederic@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/cputime.c