lkml.org 
[lkml]   [2016]   [Apr]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] sched/cpuacct: Check for NULL when using task_pt_regs()
Hi Peter,

> Ah, so sometihng like:
>
> struct pt_regs *regs = task_pt_regs();
> int index = CPUACCT_USAGE_SYSTEM;
>
> if (regs && user_mode(regs))
> index = CPUACCT_USAGE_USER;
>
> should work, right?

Looks good, and the patch below does fix the oops for me.

Anton
--

task_pt_regs() can return NULL for kernel threads, so add a check.
This fixes an oops at boot on ppc64.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index df947e0..41f85c4 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -316,12 +316,11 @@ static struct cftype files[] = {
void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{
struct cpuacct *ca;
- int index;
+ int index = CPUACCT_USAGE_SYSTEM;
+ struct pt_regs *regs = task_pt_regs(tsk);

- if (user_mode(task_pt_regs(tsk)))
+ if (regs && user_mode(regs))
index = CPUACCT_USAGE_USER;
- else
- index = CPUACCT_USAGE_SYSTEM;

rcu_read_lock();

\
 
 \ /
  Last update: 2016-04-06 14:21    [W:0.228 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site