Skip to content
  • Frederic Weisbecker's avatar
    sched/vtime: Fix guest/system mis-accounting on task switch · 68e7a4d6
    Frederic Weisbecker authored and Ingo Molnar's avatar Ingo Molnar committed
    
    
    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: default avatarFrederic Weisbecker <frederic@kernel.org>
    Signed-off-by: default avatarPeter 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: 2a42eb95 ("sched/cputime: Accumulate vtime on top of nsec clocksource")
    Link: https://lkml.kernel.org/r/20190925214242.21873-1-frederic@kernel.org
    
    
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    68e7a4d6