From: Peter Zijlstra <peterz@infradead.org>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Wanpeng Li <wanpengli@tencent.com>,
Thomas Gleixner <tglx@linutronix.de>,
Rik van Riel <riel@redhat.com>
Subject: Re: [PATCH] sched/vtime: Fix guest/system mis-accounting on task switch
Date: Thu, 26 Sep 2019 10:14:00 +0200 [thread overview]
Message-ID: <20190926081400.GH4553@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190925214242.21873-1-frederic@kernel.org>
On Wed, Sep 25, 2019 at 11:42:42PM +0200, Frederic Weisbecker wrote:
> 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.
>
> Fixes: 2a42eb9594a1 ("sched/cputime: Accumulate vtime on top of nsec clocksource")
> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Rik van Riel <riel@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Wanpeng Li <wanpengli@tencent.com>
> Cc: Ingo Molnar <mingo@kernel.org>
Thanks!
next prev parent reply other threads:[~2019-09-26 8:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 21:42 [PATCH] sched/vtime: Fix guest/system mis-accounting on task switch Frederic Weisbecker
2019-09-26 8:14 ` Peter Zijlstra [this message]
2019-10-09 12:59 ` [tip: sched/urgent] " tip-bot2 for Frederic Weisbecker
2019-10-09 12:59 ` [tip: sched/core] " tip-bot2 for Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190926081400.GH4553@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=riel@redhat.com \
--cc=tglx@linutronix.de \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).