mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernel/sched: fix KMSAN uninit-value error
@ 2022-09-05  2:37 Bernard Zhao
  2022-09-05  6:41 ` Chengming Zhou
  2022-09-05 15:14 ` Steven Rostedt
  0 siblings, 2 replies; 4+ messages in thread
From: Bernard Zhao @ 2022-09-05  2:37 UTC (permalink / raw)
  To: Johannes Weiner, Suren Baghdasaryan, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Daniel Bristot de Oliveira,
	Valentin Schneider, linux-kernel
  Cc: zhaojunkui2008, Bernard Zhao

This patch try to fix syzbot error:
=====================================================
BUG: KMSAN: uninit-value in update_triggers kernel/sched/psi.c:525 [inline]
BUG: KMSAN: uninit-value in psi_poll_work kernel/sched/psi.c:626 [inline]
BUG: KMSAN: uninit-value in psi_poll_worker+0x972/0x16a0 kernel/sched/psi.c:648
 update_triggers kernel/sched/psi.c:525 [inline]
 psi_poll_work kernel/sched/psi.c:626 [inline]
 psi_poll_worker+0x972/0x16a0 kernel/sched/psi.c:648
 kthread+0x31b/0x430 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30

Uninit was stored to memory at:
 collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
 psi_poll_work kernel/sched/psi.c:604 [inline]
 psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
 kthread+0x31b/0x430 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30

Uninit was stored to memory at:
 collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
 psi_poll_work kernel/sched/psi.c:604 [inline]
 psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
 kthread+0x31b/0x430 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30

Uninit was stored to memory at:
 collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
 psi_poll_work kernel/sched/psi.c:604 [inline]
 psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
 kthread+0x31b/0x430 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30

Uninit was created at:
 slab_post_alloc_hook mm/slab.h:732 [inline]
 slab_alloc_node mm/slub.c:3258 [inline]
 slab_alloc mm/slub.c:3266 [inline]
 kmem_cache_alloc_trace+0x696/0xdf0 mm/slub.c:3297
 kmalloc include/linux/slab.h:600 [inline]
 psi_cgroup_alloc+0x83/0x250 kernel/sched/psi.c:960
 cgroup_create kernel/cgroup/cgroup.c:5430 [inline]
 cgroup_mkdir+0x10a3/0x3080 kernel/cgroup/cgroup.c:5550
 kernfs_iop_mkdir+0x2ba/0x520 fs/kernfs/dir.c:1185
 vfs_mkdir+0x62a/0x870 fs/namei.c:4013
 do_mkdirat+0x466/0x7b0 fs/namei.c:4038
 __do_sys_mkdirat fs/namei.c:4053 [inline]
 __se_sys_mkdirat fs/namei.c:4051 [inline]
 __x64_sys_mkdirat+0xc4/0x120 fs/namei.c:4051
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

syzbot link:
https://syzkaller.appspot.com/bug?id=d04c5407207d11e46007775517b97764174bc45d

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 kernel/sched/psi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index ecb4b4ff4ce0..46f048121520 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -195,6 +195,9 @@ static void group_init(struct psi_group *group)
 	init_waitqueue_head(&group->poll_wait);
 	timer_setup(&group->poll_timer, poll_timer_fn, 0);
 	rcu_assign_pointer(group->poll_task, NULL);
+	memset(group->avg_total, 0, sizeof(group->avg_total));
+	memset(group->total, 0, sizeof(group->total));
+	memset(group->avg, 0, sizeof(group->avg));
 }
 
 void __init psi_init(void)
-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kernel/sched: fix KMSAN uninit-value error
  2022-09-05  2:37 [PATCH] kernel/sched: fix KMSAN uninit-value error Bernard Zhao
@ 2022-09-05  6:41 ` Chengming Zhou
  2022-09-05  7:12   ` 答复: " 赵军奎
  2022-09-05 15:14 ` Steven Rostedt
  1 sibling, 1 reply; 4+ messages in thread
From: Chengming Zhou @ 2022-09-05  6:41 UTC (permalink / raw)
  To: Bernard Zhao
  Cc: zhaojunkui2008, Johannes Weiner, Suren Baghdasaryan, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel

On 2022/9/5 10:37, Bernard Zhao wrote:
> This patch try to fix syzbot error:
> =====================================================
> BUG: KMSAN: uninit-value in update_triggers kernel/sched/psi.c:525 [inline]
> BUG: KMSAN: uninit-value in psi_poll_work kernel/sched/psi.c:626 [inline]
> BUG: KMSAN: uninit-value in psi_poll_worker+0x972/0x16a0 kernel/sched/psi.c:648

Hello,

Did you test with the latest PSI code using linux-next branch that include
the commit 2b97cf76289a ("sched/psi: Zero the memory of struct psi_group")?

Thanks.


>  update_triggers kernel/sched/psi.c:525 [inline]
>  psi_poll_work kernel/sched/psi.c:626 [inline]
>  psi_poll_worker+0x972/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
> 
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
>  psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
> 
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
>  psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
> 
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355
>  psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
> 
> Uninit was created at:
>  slab_post_alloc_hook mm/slab.h:732 [inline]
>  slab_alloc_node mm/slub.c:3258 [inline]
>  slab_alloc mm/slub.c:3266 [inline]
>  kmem_cache_alloc_trace+0x696/0xdf0 mm/slub.c:3297
>  kmalloc include/linux/slab.h:600 [inline]
>  psi_cgroup_alloc+0x83/0x250 kernel/sched/psi.c:960
>  cgroup_create kernel/cgroup/cgroup.c:5430 [inline]
>  cgroup_mkdir+0x10a3/0x3080 kernel/cgroup/cgroup.c:5550
>  kernfs_iop_mkdir+0x2ba/0x520 fs/kernfs/dir.c:1185
>  vfs_mkdir+0x62a/0x870 fs/namei.c:4013
>  do_mkdirat+0x466/0x7b0 fs/namei.c:4038
>  __do_sys_mkdirat fs/namei.c:4053 [inline]
>  __se_sys_mkdirat fs/namei.c:4051 [inline]
>  __x64_sys_mkdirat+0xc4/0x120 fs/namei.c:4051
>  do_syscall_x64 arch/x86/entry/common.c:50 [inline]
>  do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
>  entry_SYSCALL_64_after_hwframe+0x63/0xcd
> 
> syzbot link:
> https://syzkaller.appspot.com/bug?id=d04c5407207d11e46007775517b97764174bc45d
> 
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  kernel/sched/psi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index ecb4b4ff4ce0..46f048121520 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -195,6 +195,9 @@ static void group_init(struct psi_group *group)
>  	init_waitqueue_head(&group->poll_wait);
>  	timer_setup(&group->poll_timer, poll_timer_fn, 0);
>  	rcu_assign_pointer(group->poll_task, NULL);
> +	memset(group->avg_total, 0, sizeof(group->avg_total));
> +	memset(group->total, 0, sizeof(group->total));
> +	memset(group->avg, 0, sizeof(group->avg));
>  }
>  
>  void __init psi_init(void)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* 答复: [PATCH] kernel/sched: fix KMSAN uninit-value error
  2022-09-05  6:41 ` Chengming Zhou
@ 2022-09-05  7:12   ` 赵军奎
  0 siblings, 0 replies; 4+ messages in thread
From: 赵军奎 @ 2022-09-05  7:12 UTC (permalink / raw)
  To: Chengming Zhou
  Cc: zhaojunkui2008, Johannes Weiner, Suren Baghdasaryan, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel

Hi Chengming:

For KMSAN issue, syzbot does not support patch verification from Linux-main or Linux-next branch.
Currently, only Google's own kmsan.git can be used for KMSAN issue`s verification. The warning like this:
KMSAN bugs can only be tested on https://github.com/google/kmsan.git tree because KMSAN tool is not upstreamed yet.
See https://goo.gl/tpsmEJ#kmsan-bugs for details.

It seems that Google's code has not sync with the latest code of Linux-next.
This patch doesn't seem to be needed if the commit 2b97cf76289a has been submitted, thanks!

BR//Bernard

-----邮件原件-----
发件人: Chengming Zhou <zhouchengming@bytedance.com> 
发送时间: 2022年9月5日 14:42
收件人: 赵军奎 <bernard@vivo.com>
抄送: zhaojunkui2008@126.com; Johannes Weiner <hannes@cmpxchg.org>; Suren Baghdasaryan <surenb@google.com>; Ingo Molnar <mingo@redhat.com>; Peter Zijlstra <peterz@infradead.org>; Juri Lelli <juri.lelli@redhat.com>; Vincent Guittot <vincent.guittot@linaro.org>; Dietmar Eggemann <dietmar.eggemann@arm.com>; Steven Rostedt <rostedt@goodmis.org>; Ben Segall <bsegall@google.com>; Mel Gorman <mgorman@suse.de>; Daniel Bristot de Oliveira <bristot@redhat.com>; Valentin Schneider <vschneid@redhat.com>; linux-kernel@vger.kernel.org
主题: Re: [PATCH] kernel/sched: fix KMSAN uninit-value error

[You don't often get email from zhouchengming@bytedance.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

On 2022/9/5 10:37, Bernard Zhao wrote:
> This patch try to fix syzbot error:
> =====================================================
> BUG: KMSAN: uninit-value in update_triggers kernel/sched/psi.c:525 
> [inline]
> BUG: KMSAN: uninit-value in psi_poll_work kernel/sched/psi.c:626 
> [inline]
> BUG: KMSAN: uninit-value in psi_poll_worker+0x972/0x16a0 
> kernel/sched/psi.c:648

Hello,

Did you test with the latest PSI code using linux-next branch that include the commit 2b97cf76289a ("sched/psi: Zero the memory of struct psi_group")?

Thanks.


>  update_triggers kernel/sched/psi.c:525 [inline]  psi_poll_work 
> kernel/sched/psi.c:626 [inline]
>  psi_poll_worker+0x972/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
>
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355  
> psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
>
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355  
> psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
>
> Uninit was stored to memory at:
>  collect_percpu_times+0x193d/0x19a0 kernel/sched/psi.c:355  
> psi_poll_work kernel/sched/psi.c:604 [inline]
>  psi_poll_worker+0x587/0x16a0 kernel/sched/psi.c:648
>  kthread+0x31b/0x430 kernel/kthread.c:376
>  ret_from_fork+0x1f/0x30
>
> Uninit was created at:
>  slab_post_alloc_hook mm/slab.h:732 [inline]  slab_alloc_node 
> mm/slub.c:3258 [inline]  slab_alloc mm/slub.c:3266 [inline]
>  kmem_cache_alloc_trace+0x696/0xdf0 mm/slub.c:3297  kmalloc 
> include/linux/slab.h:600 [inline]
>  psi_cgroup_alloc+0x83/0x250 kernel/sched/psi.c:960  cgroup_create 
> kernel/cgroup/cgroup.c:5430 [inline]
>  cgroup_mkdir+0x10a3/0x3080 kernel/cgroup/cgroup.c:5550
>  kernfs_iop_mkdir+0x2ba/0x520 fs/kernfs/dir.c:1185
>  vfs_mkdir+0x62a/0x870 fs/namei.c:4013
>  do_mkdirat+0x466/0x7b0 fs/namei.c:4038  __do_sys_mkdirat 
> fs/namei.c:4053 [inline]  __se_sys_mkdirat fs/namei.c:4051 [inline]
>  __x64_sys_mkdirat+0xc4/0x120 fs/namei.c:4051
>  do_syscall_x64 arch/x86/entry/common.c:50 [inline]
>  do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80  
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
>
> syzbot link:
> https://syzkaller.appspot.com/bug?id=d04c5407207d11e46007775517b977641
> 74bc45d
>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  kernel/sched/psi.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 
> ecb4b4ff4ce0..46f048121520 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -195,6 +195,9 @@ static void group_init(struct psi_group *group)
>       init_waitqueue_head(&group->poll_wait);
>       timer_setup(&group->poll_timer, poll_timer_fn, 0);
>       rcu_assign_pointer(group->poll_task, NULL);
> +     memset(group->avg_total, 0, sizeof(group->avg_total));
> +     memset(group->total, 0, sizeof(group->total));
> +     memset(group->avg, 0, sizeof(group->avg));
>  }
>
>  void __init psi_init(void)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kernel/sched: fix KMSAN uninit-value error
  2022-09-05  2:37 [PATCH] kernel/sched: fix KMSAN uninit-value error Bernard Zhao
  2022-09-05  6:41 ` Chengming Zhou
@ 2022-09-05 15:14 ` Steven Rostedt
  1 sibling, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2022-09-05 15:14 UTC (permalink / raw)
  To: Bernard Zhao
  Cc: Johannes Weiner, Suren Baghdasaryan, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Dietmar Eggemann, Ben Segall,
	Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider,
	linux-kernel, zhaojunkui2008

On Sun,  4 Sep 2022 19:37:14 -0700
Bernard Zhao <bernard@vivo.com> wrote:

> syzbot link:
> https://syzkaller.appspot.com/bug?id=d04c5407207d11e46007775517b97764174bc45d
> 
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>  kernel/sched/psi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index ecb4b4ff4ce0..46f048121520 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -195,6 +195,9 @@ static void group_init(struct psi_group *group)
>  	init_waitqueue_head(&group->poll_wait);
>  	timer_setup(&group->poll_timer, poll_timer_fn, 0);
>  	rcu_assign_pointer(group->poll_task, NULL);
> +	memset(group->avg_total, 0, sizeof(group->avg_total));
> +	memset(group->total, 0, sizeof(group->total));
> +	memset(group->avg, 0, sizeof(group->avg));
>  }

group_init() is only called in two places. One for a static variable which
will already have all the non-set fields initialized to zero. The other can
have kmalloc() converted to kzalloc() and not worry about zeroing any of
the fields in initialization.

-- Steve

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index ec66b40bdd40..00d62681ea6a 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -957,7 +957,7 @@ int psi_cgroup_alloc(struct cgroup *cgroup)
 	if (static_branch_likely(&psi_disabled))
 		return 0;
 
-	cgroup->psi = kmalloc(sizeof(struct psi_group), GFP_KERNEL);
+	cgroup->psi = kzalloc(sizeof(struct psi_group), GFP_KERNEL);
 	if (!cgroup->psi)
 		return -ENOMEM;
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-05 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05  2:37 [PATCH] kernel/sched: fix KMSAN uninit-value error Bernard Zhao
2022-09-05  6:41 ` Chengming Zhou
2022-09-05  7:12   ` 答复: " 赵军奎
2022-09-05 15:14 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®