From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0038AC433EF for ; Thu, 21 Apr 2022 13:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C65A6B0072; Thu, 21 Apr 2022 09:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 775CF6B0073; Thu, 21 Apr 2022 09:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6642A6B0074; Thu, 21 Apr 2022 09:40:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 583B36B0072 for ; Thu, 21 Apr 2022 09:40:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 298A526AF5 for ; Thu, 21 Apr 2022 13:40:39 +0000 (UTC) X-FDA: 79380996198.08.D01FB0B Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by imf23.hostedemail.com (Postfix) with ESMTP id 2F8D2140026 for ; Thu, 21 Apr 2022 13:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1650548438; x=1682084438; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=kb/kfLaKYMZAbGLZYV5H19kevDDVjtLh3lr2MybQ66I=; b=R6e1IEdkyB1uhJLesTCFWigh6RmbPzBa5IQLeVm+MQCv7KcDXxIKeEiG ZlAi2TNKtDLdbFAqqy2ktftNywUT4Fri5wc+gRhZZr2gT+CAh/rfWt69j Hr+k/kyR7iwIle7+NYP4wB0xSnHrQbIluNBLMJqQrMe0GHlqNW6GfmwR9 Q=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 21 Apr 2022 06:40:37 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 06:40:37 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 21 Apr 2022 06:40:36 -0700 Received: from qian (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 21 Apr 2022 06:40:35 -0700 Date: Thu, 21 Apr 2022 09:40:33 -0400 From: Qian Cai To: Yixuan Cao CC: , , , , , , Subject: Re: [PATCH] mm/page_owner.c: use get_task_comm() to record task command name with the protection of task_lock() Message-ID: <20220421134033.GA74@qian> References: <20220420122817.67181-1-caoyixuan2019@email.szu.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20220420122817.67181-1-caoyixuan2019@email.szu.edu.cn> X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Rspam-User: X-Rspamd-Queue-Id: 2F8D2140026 X-Stat-Signature: i8hbrrjfcg98hqa85kth9brs3c8bkbu9 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=R6e1IEdk; spf=pass (imf23.hostedemail.com: domain of quic_qiancai@quicinc.com designates 199.106.114.38 as permitted sender) smtp.mailfrom=quic_qiancai@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Rspamd-Server: rspam01 X-HE-Tag: 1650548435-209549 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Apr 20, 2022 at 08:28:17PM +0800, Yixuan Cao wrote: > I noticed that it is advised to access task command name with > [gs]et_task_comm() in the comment of task_struct->comm, > which is safer with the protection of task_lock(). > > Relative comment in include/linux/sched.h is as follows: > > /* > * executable name, excluding path. > * > * - normally initialized setup_new_exec() > * - access it with [gs]et_task_comm() > * - lock it with task_lock() > */ > > Signed-off-by: Yixuan Cao > --- > mm/page_owner.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 2743062e92c2..bda8fe2660c0 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -171,8 +171,7 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext, > page_owner->pid = current->pid; > page_owner->tgid = current->tgid; > page_owner->ts_nsec = local_clock(); > - strlcpy(page_owner->comm, current->comm, > - sizeof(page_owner->comm)); > + get_task_comm(page_owner->comm, current); We can't call that thing here. WARNING: inconsistent lock state 5.18.0-rc3-next-20220421-dirty #22 Not tainted -------------------------------- inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage. swapper/4/0 [HC0[0]:SC1[1]:HE1:SE0] takes: ffff07ff89ad87f8 (&p->alloc_lock){+.?.}-{2:2}, at: __get_task_comm {SOFTIRQ-ON-W} state was registered at: __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock __set_task_comm kthreadd ret_from_fork irq event stamp: 50532 hardirqs last enabled at (50532): seqcount_lockdep_reader_access hardirqs last disabled at (50531): seqcount_lockdep_reader_access softirqs last enabled at (50306): __do_softirq softirqs last disabled at (50313): __irq_exit_rcu other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&p->alloc_lock); lock(&p->alloc_lock); *** DEADLOCK *** 1 lock held by swapper/4/0: #0: ffffce91c3d81da0 (rcu_callback){....}-{0:0}, at: rcu_do_batch stack backtrace: CPU: 4 PID: 0 Comm: swapper/4 Not tainted 5.18.0-rc3-next-20220421-dirty #22 Call trace: dump_backtrace show_stack dump_stack_lvl dump_stack print_usage_bug.part.0 mark_lock_irq mark_lock mark_usage __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock __get_task_comm __get_task_comm at fs/exec.c:1221 __set_page_owner arch___set_bit at include/asm-generic/bitops/non-atomic.h:22 (inlined by) __set_page_owner_handle at mm/page_owner.c:175 (inlined by) __set_page_owner at mm/page_owner.c:192 post_alloc_hook get_page_from_freelist __alloc_pages alloc_pages allocate_slab new_slab ___slab_alloc __slab_alloc.constprop.0 kmem_cache_alloc fill_pool __debug_object_init debug_object_activate call_rcu put_object __delete_object kmemleak_free slab_free_freelist_hook kmem_cache_free file_free_rcu rcu_do_batch rcu_core rcu_core_si __do_softirq __irq_exit_rcu irq_exit_rcu el1_interrupt el1h_64_irq_handler el1h_64_irq arch_local_irq_enable default_idle_call cpuidle_idle_call do_idle cpu_startup_entry secondary_start_kernel __secondary_switched