Message ID | 20230210000021.1007853-1-qiang1.zhang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp648041wrn; Thu, 9 Feb 2023 16:04:16 -0800 (PST) X-Google-Smtp-Source: AK7set/Gjawd7iLBc3UFITYjXe+W4h4Q03iG9GA9U6R3dVZB2rulSSyp/2vMqMLWFr3bcAMdfrkC X-Received: by 2002:a17:907:6d19:b0:8af:4dad:a47c with SMTP id sa25-20020a1709076d1900b008af4dada47cmr522374ejc.29.1675987456788; Thu, 09 Feb 2023 16:04:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675987456; cv=none; d=google.com; s=arc-20160816; b=GrGzvndfgYFpqdeP2q1iL6ehsKjsQDUUbGVsDqXOE8I6Gx4TQe/nomiCuLxq2lc/k4 3FanbNoUGF37vcoOsMEDIr9cP+Ftf5Ce4Oh38+izPDu0WBCKkCCgvMxtoj+Pddr6endS 1dsAUJefg8+vjryh8M0OL5aX+VgoBxtm0umn1sVZSRyPwXEDAB2XOhe2eUyld/tWBPBA KffZz0CXEgUBPCm9ulouiQOsZAAcZsVMDg+hMH+SixWQfgigcBR0iTppDAm66Ewau9cs tLKjomcCNqjh2yKQbiYSCGOgV9tPFoW3vWuY0ikp5NOfToA+yG1MslazNvLS4AgYGnO8 1U9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=GMexjjjbYndeTJ27kU8lOnPTe7pJihdEneokyjpzuEY=; b=PGcZUeJdPyAuuSaPBudCfvoEzGsNjiv4HQ8NdfaAk2672/IsT3PmCrqvwrGyv7N3F4 Mu0WSvvtTFbI6bmlup2MA8sI3CrRDAGYVE8g4o9Ph5f+68++XBbFfoXNL1VlK5mmG3Tm JANIQt2x07nFwy+byoLYUqBsGMcN374E0NAexqiXBRL0WabK76GZKdNpgokQCz+/4Th3 hvp9Or+kFf9dTqt0wGE6PQ+oIrzfWZRb9mK8yoFuahgVKzZlqS8uHWz2ol+n723OpuUl W9+d0pRbDiEK2LyPd/2XufmzYBfA23/reCgO1RoxrZcQ7HOeVQA/hZX+Ws9aH96EgN1N t5Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="j/E0nXwX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fh18-20020a1709073a9200b0083b6e04f33esi3716962ejc.280.2023.02.09.16.03.54; Thu, 09 Feb 2023 16:04:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="j/E0nXwX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbjBIXz2 (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 9 Feb 2023 18:55:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjBIXz0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Feb 2023 18:55:26 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432D65BA69; Thu, 9 Feb 2023 15:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675986925; x=1707522925; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=xW/w7Z1rLzTj6SPg33pQoDkhmye+B/R371VjL8VHQgk=; b=j/E0nXwXUM4H/ntecAiN2OZCBALhLWyOjaitrDAOV4HvDKkpHEq/CfE7 Ns6TvEfXXki11HkIZPEA6jOfwzhnni9Tq7xiqGj5lAsV/1z51h2sYOQIU OM8s647d/nnmsMbL+MAvbmJ0qS4s5B4XKKGJYCyS9psVDY++nmFAt6FnD IhSOEbeFCSEz6b3aUIJvVOGW9dnaDMjov8RRirMXGNfeTMh1HtH+hOT/c Zp2U0bGIJ6NXd/ka+b6cnZS9emWgRuSkXzLx/wpwtlqPQxw1UzJFP1qcp 8SEUYGjLN0ODIoYYYYt9AUBZi0W6b04JMtqmvJR2gDl/Kwv66EAamRU75 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="310647092" X-IronPort-AV: E=Sophos;i="5.97,285,1669104000"; d="scan'208";a="310647092" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2023 15:55:24 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="731522787" X-IronPort-AV: E=Sophos;i="5.97,285,1669104000"; d="scan'208";a="731522787" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.129]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2023 15:55:19 -0800 From: Zqiang <qiang1.zhang@intel.com> To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, paulmck@kernel.org, frederic@kernel.org, joel@joelfernandes.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] sched/isolation: Fix illegal CPU value by housekeeping_any_cpu() return Date: Fri, 10 Feb 2023 08:00:21 +0800 Message-Id: <20230210000021.1007853-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757400223427539406?= X-GMAIL-MSGID: =?utf-8?q?1757400223427539406?= |
Series |
[v2] sched/isolation: Fix illegal CPU value by housekeeping_any_cpu() return
|
|
Commit Message
Zqiang
Feb. 10, 2023, midnight UTC
For kernels built with CONFIG_NO_HZ_FULL=y, running the following tests:
runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams=
"console=ttyS0 nohz_full=0,1 rcu_nocbs=0,1 sched_verbose" -d
root@qemux86-64:~# echo 0 > /sys/devices/system/cpu/cpu2/online
root@qemux86-64:~# echo 0 > /sys/devices/system/cpu/cpu3/online
[ 22.838290] BUG: unable to handle page fault for address: ffffffff84cd48c0
[ 22.839409] #PF: supervisor read access in kernel mode
[ 22.840215] #PF: error_code(0x0000) - not-present page
[ 22.841028] PGD 3e19067 P4D 3e19067 PUD 3e1a063 PMD 800ffffffb3ff062
[ 22.841889] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC KASAN PTI
[ 22.842175] CPU: 0 PID: 16 Comm: rcu_preempt Not tainted 6.2.0-rc1-yocto-standard+ #658
[ 22.842534] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009),
BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.o4
[ 22.843036] RIP: 0010:do_raw_spin_trylock+0x70/0x120
[ 22.843267] Code: 81 c7 00 f1 f1 f1 f1 c7 40 04 04 f3 f3 f3 65
48 8b 04 25 28 00 00 00 48 89 45 e0 31 c0 e8 b8 0
[ 22.844187] RSP: 0018:ffff8880072b7b30 EFLAGS: 00010046
[ 22.844429] RAX: 0000000000000000 RBX: ffffffff84cd48c0 RCX: dffffc0000000000
[ 22.844751] RDX: 0000000000000003 RSI: 0000000000000004 RDI: ffffffff84cd48c0
[ 22.845074] RBP: ffff8880072b7ba8 R08: ffffffff811daa20 R09: fffffbfff099a919
[ 22.845400] R10: ffffffff84cd48c3 R11: fffffbfff099a918 R12: 1ffff11000e56f66
[ 22.845719] R13: ffffffff84cd48d8 R14: ffffffff84cd48c0 R15: ffff8880072b7cd8
[ 22.846040] FS: 0000000000000000(0000) GS:ffff888035200000(0000) knlGS:0000000000000000
[ 22.846403] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 22.846667] CR2: ffffffff84cd48c0 CR3: 000000001036c000 CR4: 00000000001506f0
[ 22.846988] Call Trace:
[ 22.847105] <TASK>
[ 22.847208] ? __pfx_do_raw_spin_trylock+0x10/0x10
[ 22.847430] ? rcu_read_unlock+0x26/0x80
[ 22.847612] ? trace_preempt_off+0x2a/0x130
[ 22.847812] _raw_spin_lock+0x41/0x80
[ 22.847984] ? schedule_timeout+0x242/0x580
[ 22.848178] schedule_timeout+0x242/0x580
[ 22.848366] ? __pfx_schedule_timeout+0x10/0x10
[ 22.848575] ? __pfx_do_raw_spin_trylock+0x10/0x10
[ 22.848796] ? __pfx_process_timeout+0x10/0x10
[ 22.849005] ? _raw_spin_unlock_irqrestore+0x46/0x80
[ 22.849232] ? prepare_to_swait_event+0xb8/0x210
[ 22.849450] rcu_gp_fqs_loop+0x66e/0xe70
[ 22.849633] ? rcu_gp_init+0x87c/0x1130
[ 22.849813] ? __pfx_rcu_gp_fqs_loop+0x10/0x10
[ 22.850022] ? _raw_spin_unlock_irqrestore+0x46/0x80
[ 22.850251] ? finish_swait+0xce/0x100
[ 22.850429] rcu_gp_kthread+0x2ea/0x6b0
[ 22.850608] ? __pfx_do_raw_spin_trylock+0x10/0x10
[ 22.850829] ? __pfx_rcu_gp_kthread+0x10/0x10
[ 22.851039] ? __kasan_check_read+0x11/0x20
[ 22.851233] ? __kthread_parkme+0xe8/0x110
[ 22.851424] ? __pfx_rcu_gp_kthread+0x10/0x10
[ 22.851627] kthread+0x172/0x1a0
[ 22.851781] ? __pfx_kthread+0x10/0x10
[ 22.851956] ret_from_fork+0x2c/0x50
[ 22.852129] </TASK>
schedule_timeout()
->__mod_timer()
->get_target_base(base, timer->flags)
->get_timer_cpu_base(tflags, get_nohz_timer_target());
->cpu = get_nohz_timer_target()
->housekeeping_any_cpu(HK_TYPE_TIMER)
/*housekeeping.cpumasks[type] is 2-3*/
/*cpu_online_mask is 0-1*/
->cpu = cpumask_any_and(housekeeping.cpumasks[type],
cpu_online_mask);
/*cpu value is 4*/
->new_base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
/*new_base is illegal address*/
->if (base != new_base)
->raw_spin_lock(&new_base->lock); ==> trigger Oops
This commit therefore add checks for cpumask_any_and() return values
in housekeeping_any_cpu(), if cpumask_any_and() returns an illegal CPU
value, the housekeeping_any_cpu() will return current CPU number.
Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
kernel/sched/isolation.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Comments
Thanks for checking this! On Fri, Feb 10, 2023 at 08:00:21AM +0800, Zqiang wrote: > For kernels built with CONFIG_NO_HZ_FULL=y, running the following tests: > > runqemu kvm slirp nographic qemuparams="-m 1024 -smp 4" bootparams= > "console=ttyS0 nohz_full=0,1 rcu_nocbs=0,1 sched_verbose" -d Has this ever worked? Again I'm tempted to just: git revert 08ae95f4fd3b38b257f5dc7e6507e071c27ba0d5 > > root@qemux86-64:~# echo 0 > /sys/devices/system/cpu/cpu2/online > root@qemux86-64:~# echo 0 > /sys/devices/system/cpu/cpu3/online > > [ 22.838290] BUG: unable to handle page fault for address: ffffffff84cd48c0
On Thu, Feb 9, 2023 at 6:55 PM Zqiang <qiang1.zhang@intel.com> wrote: > > For kernels built with CONFIG_NO_HZ_FULL=y, running the following tests: > [...] > This commit therefore add checks for cpumask_any_and() return values > in housekeeping_any_cpu(), if cpumask_any_and() returns an illegal CPU > value, the housekeeping_any_cpu() will return current CPU number. > > Signed-off-by: Zqiang <qiang1.zhang@intel.com> > --- > kernel/sched/isolation.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c > index 373d42c707bc..534397ab7a36 100644 > --- a/kernel/sched/isolation.c > +++ b/kernel/sched/isolation.c > @@ -46,7 +46,11 @@ int housekeeping_any_cpu(enum hk_type type) > if (cpu < nr_cpu_ids) > return cpu; > > - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); > + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); > + if (cpu >= nr_cpu_ids) > + return smp_processor_id(); > + else > + return cpu; Nit: no need of "else", simply: return (cpu >= nr_cpuids ? smp_processor_id() : cpu); or if (cpu >= nr_cpu_ids) return smp_processor_id(); return cpu; Thanks.
> > For kernels built with CONFIG_NO_HZ_FULL=y, running the following tests: > [...] > This commit therefore add checks for cpumask_any_and() return values > in housekeeping_any_cpu(), if cpumask_any_and() returns an illegal CPU > value, the housekeeping_any_cpu() will return current CPU number. > > Signed-off-by: Zqiang <qiang1.zhang@intel.com> > --- > kernel/sched/isolation.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c > index 373d42c707bc..534397ab7a36 100644 > --- a/kernel/sched/isolation.c > +++ b/kernel/sched/isolation.c > @@ -46,7 +46,11 @@ int housekeeping_any_cpu(enum hk_type type) > if (cpu < nr_cpu_ids) > return cpu; > > - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); > + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); > + if (cpu >= nr_cpu_ids) > + return smp_processor_id(); > + else > + return cpu; > >Nit: no need of "else", simply: > >return (cpu >= nr_cpuids ? smp_processor_id() : cpu); Thanks Joel, I have done the same modification in v3 version, and this change is also related to a 08ae95f4fd3b, after revert it, this calltrace will disappear. Thanks Zqiang > >or > >if (cpu >= nr_cpu_ids) > return smp_processor_id(); >return cpu; > >Thanks.
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 373d42c707bc..534397ab7a36 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -46,7 +46,11 @@ int housekeeping_any_cpu(enum hk_type type) if (cpu < nr_cpu_ids) return cpu; - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + if (cpu >= nr_cpu_ids) + return smp_processor_id(); + else + return cpu; } } return smp_processor_id();