Message ID | 20230330121238.176534-1-chenzhongjin@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1086035vqo; Thu, 30 Mar 2023 05:25:46 -0700 (PDT) X-Google-Smtp-Source: AKy350b6tW65s+hQ1ArCbvUOokcxFMcI60SvAKxtfOZjMUVl+j48zvj0Ufn/4IKR6yYDTGC8ihoZ X-Received: by 2002:a17:906:36d7:b0:93d:cffb:80ba with SMTP id b23-20020a17090636d700b0093dcffb80bamr24617415ejc.66.1680179146335; Thu, 30 Mar 2023 05:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680179146; cv=none; d=google.com; s=arc-20160816; b=ASsbIBlSSGc+GKM2KiE62Bs3IQ+ePs8kK4O+/kDXobN+fc0CSQZPUAGR9i1pj40ra1 JALbDv0se4ExezMCWd16rGd0lXKWI5Yyb4qu+OSXXgvQxTcXoxvXUIrVXQmf74JGA+dA Ll7PW274GinKDKgQ+xKwdeIq79SfsHpiO4pXlXjNtwWWzU52MpRPKQbfSfUNSCrs/G0b mi8HudI4iEVY3Rl3OtUDhsCbtc0dTiPZZ1pmI7eDJMUFGROCYcv9UspJupMlrGpELRF8 b+6sfDokABEWyfKqJ9Bxi+bXxGOWQEwnkbtATd13etSBNto/V01y8T24hgNKyP0rnCbn 5jeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=uO+FZbC3QQWvw0UHKe7WnKjdk7Q/WQiO1fiOXsbuPP0=; b=FY71B0gvRZsseOCDergUHuRW4vjmW9xBFnaPIN4sfj4/66WQWN9v2+ChZeV1bRMfVX x21xqS5JaDbUyKW94XV/CkmOZpZYnqMxzAS3bzZSUJSRuAT8aXwzZXgo/x4Kiyg50AUT 9coAeFzN/85BcEOR7KuCRN1/x5IZi8gQJ2yFmyIOcy1JuMjugs+n6/AgFhfoUrO4vGAs fT1SMmqPrANj5n7htUdK9nrwxvG4JLsCaoSQMtW1FunYnyuvgIOCA6usn3G37TLdmLpP a6QylfIx0nHHUtmOsP6P4AE9+XuaqjmANgX0oTYWOu9XfJKgalH/W8dlIQMrkpl4n1fX 83BA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vv1-20020a170907a68100b0093626311338si27291388ejc.936.2023.03.30.05.25.20; Thu, 30 Mar 2023 05:25:46 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231482AbjC3MO2 (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Thu, 30 Mar 2023 08:14:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbjC3MO1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Mar 2023 08:14:27 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CE5A5240 for <linux-kernel@vger.kernel.org>; Thu, 30 Mar 2023 05:14:26 -0700 (PDT) Received: from dggpemm500013.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PnMhV0k1RzgZgq; Thu, 30 Mar 2023 20:11:06 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 20:14:23 +0800 From: Chen Zhongjin <chenzhongjin@huawei.com> To: <linux-kernel@vger.kernel.org> CC: <chenzhongjin@huawei.com>, <mingo@redhat.com>, <peterz@infradead.org>, <juri.lelli@redhat.com>, <vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>, <rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>, <bristot@redhat.com>, <vschneid@redhat.com>, <rmk+kernel@armlinux.org.uk>, <geert@linux-m68k.org>, <keescook@chromium.org> Subject: [PATCH] wchan: Fix get_wchan() when task in schedule Date: Thu, 30 Mar 2023 20:12:37 +0800 Message-ID: <20230330121238.176534-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761795528479281274?= X-GMAIL-MSGID: =?utf-8?q?1761795528479281274?= |
Series |
wchan: Fix get_wchan() when task in schedule
|
|
Commit Message
Chen Zhongjin
March 30, 2023, 12:12 p.m. UTC
get_wchan() check task to unwind is not running or going to run by:
state != TASK_RUNNING && state != TASK_WAKING && !p->on_rq
However this cannot detect task which is going to be scheduled out.
For example, in this path:
__wait_for_common(x, schedule_timeout, timeout, TASK_UNINTERRUPTIBLE)
do_wait_for_common() // state == TASK_UNINTERRUPTIBLE
schedule_timeout()
__schedule()
deactivate_task() // on_rq = 0
After this point get_wchan() can be run on the task but it is still
running actually, and p->pi_lock doesn't work for this case.
It can trigger some warning when running stacktrace on a running task.
Also check p->on_cpu to promise task is really switched out can prevent
this.
Fixes: 42a20f86dc19 ("sched: Add wrapper for get_wchan() to keep task blocked")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
---
kernel/sched/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
Hi Chen, Thank you for the patch! Yet something to improve: [auto build test ERROR on tip/sched/core] [also build test ERROR on linus/master v6.3-rc4 next-20230330] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 patch link: https://lore.kernel.org/r/20230330121238.176534-1-chenzhongjin%40huawei.com patch subject: [PATCH] wchan: Fix get_wchan() when task in schedule config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20230330/202303302125.7Ku9P7v5-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 git checkout d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash kernel/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202303302125.7Ku9P7v5-lkp@intel.com/ All errors (new ones prefixed by >>): kernel/sched/core.c: In function 'get_wchan': >> kernel/sched/core.c:2060:28: error: 'struct task_struct' has no member named 'on_cpu' 2060 | !p->on_rq && !p->on_cpu) | ^~ vim +2060 kernel/sched/core.c 2046 2047 unsigned long get_wchan(struct task_struct *p) 2048 { 2049 unsigned long ip = 0; 2050 unsigned int state; 2051 2052 if (!p || p == current) 2053 return 0; 2054 2055 /* Only get wchan if task is blocked and we can keep it that way. */ 2056 raw_spin_lock_irq(&p->pi_lock); 2057 state = READ_ONCE(p->__state); 2058 smp_rmb(); /* see try_to_wake_up() */ 2059 if (state != TASK_RUNNING && state != TASK_WAKING && > 2060 !p->on_rq && !p->on_cpu) 2061 ip = __get_wchan(p); 2062 raw_spin_unlock_irq(&p->pi_lock); 2063 2064 return ip; 2065 } 2066
Hi Chen, Thank you for the patch! Yet something to improve: [auto build test ERROR on tip/sched/core] [also build test ERROR on linus/master v6.3-rc4 next-20230330] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 patch link: https://lore.kernel.org/r/20230330121238.176534-1-chenzhongjin%40huawei.com patch subject: [PATCH] wchan: Fix get_wchan() when task in schedule config: mips-randconfig-r006-20230329 (https://download.01.org/0day-ci/archive/20230331/202303310019.uMAqiUA4-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install mips cross compiling tool for clang build # apt-get install binutils-mipsel-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 git checkout d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash kernel/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202303310019.uMAqiUA4-lkp@intel.com/ All errors (new ones prefixed by >>): >> kernel/sched/core.c:2060:23: error: no member named 'on_cpu' in 'struct task_struct' !p->on_rq && !p->on_cpu) ~ ^ 1 error generated. vim +2060 kernel/sched/core.c 2046 2047 unsigned long get_wchan(struct task_struct *p) 2048 { 2049 unsigned long ip = 0; 2050 unsigned int state; 2051 2052 if (!p || p == current) 2053 return 0; 2054 2055 /* Only get wchan if task is blocked and we can keep it that way. */ 2056 raw_spin_lock_irq(&p->pi_lock); 2057 state = READ_ONCE(p->__state); 2058 smp_rmb(); /* see try_to_wake_up() */ 2059 if (state != TASK_RUNNING && state != TASK_WAKING && > 2060 !p->on_rq && !p->on_cpu) 2061 ip = __get_wchan(p); 2062 raw_spin_unlock_irq(&p->pi_lock); 2063 2064 return ip; 2065 } 2066
It seems because of !CONFIG_SMP. I'll push a new version. On 2023/3/30 21:53, kernel test robot wrote: > Hi Chen, > > Thank you for the patch! Yet something to improve: > > [auto build test ERROR on tip/sched/core] > [also build test ERROR on linus/master v6.3-rc4 next-20230330] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 > patch link: https://lore.kernel.org/r/20230330121238.176534-1-chenzhongjin%40huawei.com > patch subject: [PATCH] wchan: Fix get_wchan() when task in schedule > config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20230330/202303302125.7Ku9P7v5-lkp@intel.com/config) > compiler: sh4-linux-gcc (GCC) 12.1.0 > reproduce (this is a W=1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # https://github.com/intel-lab-lkp/linux/commit/d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review Chen-Zhongjin/wchan-Fix-get_wchan-when-task-in-schedule/20230330-201555 > git checkout d5fd727a071ab3c2241f858e77c2ae5bb3cec6f3 > # save the config file > mkdir build_dir && cp config build_dir/.config > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash kernel/ > > If you fix the issue, kindly add following tag where applicable > | Reported-by: kernel test robot <lkp@intel.com> > | Link: https://lore.kernel.org/oe-kbuild-all/202303302125.7Ku9P7v5-lkp@intel.com/ > > All errors (new ones prefixed by >>): > > kernel/sched/core.c: In function 'get_wchan': >>> kernel/sched/core.c:2060:28: error: 'struct task_struct' has no member named 'on_cpu' > 2060 | !p->on_rq && !p->on_cpu) > | ^~ > > > vim +2060 kernel/sched/core.c > > 2046 > 2047 unsigned long get_wchan(struct task_struct *p) > 2048 { > 2049 unsigned long ip = 0; > 2050 unsigned int state; > 2051 > 2052 if (!p || p == current) > 2053 return 0; > 2054 > 2055 /* Only get wchan if task is blocked and we can keep it that way. */ > 2056 raw_spin_lock_irq(&p->pi_lock); > 2057 state = READ_ONCE(p->__state); > 2058 smp_rmb(); /* see try_to_wake_up() */ > 2059 if (state != TASK_RUNNING && state != TASK_WAKING && >> 2060 !p->on_rq && !p->on_cpu) > 2061 ip = __get_wchan(p); > 2062 raw_spin_unlock_irq(&p->pi_lock); > 2063 > 2064 return ip; > 2065 } > 2066 >
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0d18c3969f90..2071d1c0eaca 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2041,7 +2041,8 @@ unsigned long get_wchan(struct task_struct *p) raw_spin_lock_irq(&p->pi_lock); state = READ_ONCE(p->__state); smp_rmb(); /* see try_to_wake_up() */ - if (state != TASK_RUNNING && state != TASK_WAKING && !p->on_rq) + if (state != TASK_RUNNING && state != TASK_WAKING && + !p->on_rq && !p->on_cpu) ip = __get_wchan(p); raw_spin_unlock_irq(&p->pi_lock);