Message ID | 20221116141511.3695680-1-qiang1.zhang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp159926wru; Wed, 16 Nov 2022 06:11:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Gxf42KPFibTClAIIndco21IK7iacb7a/gxhJ3FSfELvZq4tQTBceFXDBi6z0d0myGiGQh X-Received: by 2002:a63:d016:0:b0:45f:b2a7:2659 with SMTP id z22-20020a63d016000000b0045fb2a72659mr21234849pgf.132.1668607867778; Wed, 16 Nov 2022 06:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668607867; cv=none; d=google.com; s=arc-20160816; b=a8Zw+c6nrVrzcFCEglX6shbmNszN8RuRQ9qlFfWA/RNlzqwgfow+GJDTgtHmv/2fN9 dWH/snriytHE2swdMvPvSIQv/DvIB+m6H/vqNJoPEDdCrn2bV+zPnZSE7rttEXnyL9t3 PMPoVdz2eE9TtzPzg7GMgBlyQJgasF1oSo8iVN4qJAZi0JrkLXulZGidzGLCj9wSnmiR w/0oB/khMRTPq3ywqQ9ie5iFsXwgJTRCsC2nKFTDmaBBUiJLUehv86BVFk3Tuu6VARyx lar8xitZcE3++J/pExP36LFfPPOlDSSE8YbxJEviNO6/M8p2Edf9AAcTAIq6IRGFO2Kn FqWg== 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:cc:to:from:dkim-signature; bh=/ioez8VUcSlWVNbQjB1Und5UiIzaRNAJj9DXCBJHb9M=; b=A7kMJpr3YZTKLPrQz6Bw2Qc4xq+gs5hNQhi6jq+tCOfeAG9mc5W2+LsY4KaT0dYQKX 55jJBGgLe50CcQYyLuej1TeGCHlWq9fo4clofRhHKJBhZN5BHdyztWpZe1z52uPVmS6u kFWDyhUlLkDqrceZRKK73xha0SHnmuJ/LG9dmut1doMMqqcYr5Zt2sFeLp5bSeQLiQiH Qi/WHTMqDUHyaBtI4DnHvGTgNQDqxbnDXX8PCOmonRrKXBfClQhulihf7zMQrML7RJFm vnHXQEcOuPLbfVXPTxmOK8qMpdumUgJ/5KzHX80kmXHYyHCXyGuFIU3qpi3HW6kufMVO Qvyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=APgYikfU; 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 cm9-20020a056a00338900b0056bdae22580si14464350pfb.338.2022.11.16.06.10.44; Wed, 16 Nov 2022 06:11:07 -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=APgYikfU; 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 S232971AbiKPOK0 (ORCPT <rfc822;just.gull.subs@gmail.com> + 99 others); Wed, 16 Nov 2022 09:10:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbiKPOKE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 16 Nov 2022 09:10:04 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85051FD0A; Wed, 16 Nov 2022 06:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668607757; x=1700143757; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1OaOIu1mrFQ4zu6rv6sozmi4ljbU3P7SVUDNEHsGdgY=; b=APgYikfU4pRYnFkFlzeAVLk7WIx5bduobAqn5JPXoLAdis8nxfpgnn2R s4GBaSVR4ERyF3xWBEJpQrXVsk/fxbgZWbIBIdwIunnM2tARGKWJlUpuB zwU3C8/6LKcX9DkvnOCaJpRLa5uScVaaREJ4gaFq2GY9AH6qDYSiPtvmH DmgPt3lC+Z1sRq7WW6axIra+tGvqVq3d+1MYtZJu/y2bv+V1VHIicF6v+ KuBWfPK10xRexvEQmKGk7hdz+VcdAkJRi3UEwyTpaAUHLPZXpdMQXxx2t CkXUAUXPgwdDRcPvi1TV+HzDyUqXn7iQTesb5GatFaFJ4LGkxsJjOtOO7 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="312556931" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="312556931" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 06:09:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="814096692" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="814096692" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.129]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 06:09:15 -0800 From: Zqiang <qiang1.zhang@intel.com> To: paulmck@kernel.org, frederic@kernel.org, joel@joelfernandes.org, thunder.leizhen@huawei.com Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu: Make vmalloc_dump_obj() call in a preemptible context Date: Wed, 16 Nov 2022 22:15:11 +0800 Message-Id: <20221116141511.3695680-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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1749662163463489078?= X-GMAIL-MSGID: =?utf-8?q?1749662163463489078?= |
Series |
rcu: Make vmalloc_dump_obj() call in a preemptible context
|
|
Commit Message
Zqiang
Nov. 16, 2022, 2:15 p.m. UTC
Currently, the mem_dump_obj() is invoked in call_rcu(), the
call_rcu() is maybe invoked in non-preemptive code segment,
for object allocated from vmalloc(), the following scenarios
may occur:
CPU 0
tasks context
spin_lock(&vmap_area_lock)
Interrupt context
call_rcu()
mem_dump_obj
vmalloc_dump_obj
spin_lock(&vmap_area_lock) <--deadlock
and for PREEMPT-RT kernel, the spinlock will convert to sleepable
lock, it also make vmap_area_lock spinlock can not acquire in
non-preemptive code segment. therefore, this commit make the
vmalloc_dump_obj() call in a preemptible context.
Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
mm/util.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
Comments
On 2022/11/16 22:15, Zqiang wrote: > Currently, the mem_dump_obj() is invoked in call_rcu(), the Plan to call mem_dump_obj() in rcu_do_batch(). > call_rcu() is maybe invoked in non-preemptive code segment, > for object allocated from vmalloc(), the following scenarios > may occur: > > CPU 0 > tasks context > spin_lock(&vmap_area_lock) > Interrupt context > call_rcu() > mem_dump_obj > vmalloc_dump_obj > spin_lock(&vmap_area_lock) <--deadlock > > and for PREEMPT-RT kernel, the spinlock will convert to sleepable > lock, it also make vmap_area_lock spinlock can not acquire in > non-preemptive code segment. therefore, this commit make the > vmalloc_dump_obj() call in a preemptible context. > > Signed-off-by: Zqiang <qiang1.zhang@intel.com> > --- > mm/util.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/util.c b/mm/util.c > index 12984e76767e..465f8b8824ca 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object) > return; > } > > - if (vmalloc_dump_obj(object)) > - return; > + if (is_vmalloc_addr(object)) { > + if (preemptible() && vmalloc_dump_obj(object)) preemptible() --> !in_interrupt()? > + return; > + type = "vmalloc memory"; > + goto end; > + } Move into vmalloc_dump_obj()? > > if (virt_addr_valid(object)) > type = "non-slab/vmalloc memory"; > @@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) > type = "zero-size pointer"; > else > type = "non-paged memory"; > - > +end: > pr_cont(" %s\n", type); > } > EXPORT_SYMBOL_GPL(mem_dump_obj); >
On 2022/11/16 22:15, Zqiang wrote: > Currently, the mem_dump_obj() is invoked in call_rcu(), the > >Plan to call mem_dump_obj() in rcu_do_batch(). > > call_rcu() is maybe invoked in non-preemptive code segment, > for object allocated from vmalloc(), the following scenarios > may occur: > > CPU 0 > tasks context > spin_lock(&vmap_area_lock) > Interrupt context > call_rcu() > mem_dump_obj > vmalloc_dump_obj > spin_lock(&vmap_area_lock) <--deadlock > > and for PREEMPT-RT kernel, the spinlock will convert to sleepable > lock, it also make vmap_area_lock spinlock can not acquire in > non-preemptive code segment. therefore, this commit make the > vmalloc_dump_obj() call in a preemptible context. > > Signed-off-by: Zqiang <qiang1.zhang@intel.com> > --- > mm/util.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/util.c b/mm/util.c > index 12984e76767e..465f8b8824ca 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object) > return; > } > > - if (vmalloc_dump_obj(object)) > - return; > + if (is_vmalloc_addr(object)) { > + if (preemptible() && vmalloc_dump_obj(object)) > >preemptible() --> !in_interrupt()? Hi Leizhen !in_interrupt() not include following scenario: task context: local_irq_save() or preempt_disable(); call_rcu() mem_dump_obj() vmalloc_dump_obj() spin_lock(&vmap_area_lock) local_irq_restore() or preempt_denable(); for PREEMPT-RT kernel, spinlock will convert to sleepable lock. > > + return; > + type = "vmalloc memory"; > + goto end; > + } > >Move into vmalloc_dump_obj()? you mean move preemptible() into vmalloc_dump_obj()? Thanks Zqiang > > > if (virt_addr_valid(object)) > type = "non-slab/vmalloc memory"; > @@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) > type = "zero-size pointer"; > else > type = "non-paged memory"; > - > +end: > pr_cont(" %s\n", type); > } > EXPORT_SYMBOL_GPL(mem_dump_obj); > -- Regards, Zhen Lei
On 2022/11/17 13:20, Zhang, Qiang1 wrote: > > > On 2022/11/16 22:15, Zqiang wrote: >> Currently, the mem_dump_obj() is invoked in call_rcu(), the >> >> Plan to call mem_dump_obj() in rcu_do_batch(). >> >> call_rcu() is maybe invoked in non-preemptive code segment, >> for object allocated from vmalloc(), the following scenarios >> may occur: >> >> CPU 0 >> tasks context >> spin_lock(&vmap_area_lock) >> Interrupt context >> call_rcu() >> mem_dump_obj >> vmalloc_dump_obj >> spin_lock(&vmap_area_lock) <--deadlock >> >> and for PREEMPT-RT kernel, the spinlock will convert to sleepable >> lock, it also make vmap_area_lock spinlock can not acquire in >> non-preemptive code segment. therefore, this commit make the >> vmalloc_dump_obj() call in a preemptible context. >> >> Signed-off-by: Zqiang <qiang1.zhang@intel.com> >> --- >> mm/util.c | 10 +++++++--- >> 1 file changed, 7 insertions(+), 3 deletions(-) >> >> diff --git a/mm/util.c b/mm/util.c >> index 12984e76767e..465f8b8824ca 100644 >> --- a/mm/util.c >> +++ b/mm/util.c >> @@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object) >> return; >> } >> >> - if (vmalloc_dump_obj(object)) >> - return; >> + if (is_vmalloc_addr(object)) { >> + if (preemptible() && vmalloc_dump_obj(object)) >> >> preemptible() --> !in_interrupt()? > > Hi Leizhen > > !in_interrupt() not include following scenario: > > task context: > > local_irq_save() or preempt_disable(); > call_rcu() > mem_dump_obj() > vmalloc_dump_obj() > spin_lock(&vmap_area_lock) > local_irq_restore() or preempt_denable(); > > for PREEMPT-RT kernel, spinlock will convert to sleepable lock. OK. > >> >> + return; >> + type = "vmalloc memory"; >> + goto end; >> + } >> >> Move into vmalloc_dump_obj()? > > you mean move preemptible() into vmalloc_dump_obj()? Move all? Currently, vmalloc_dump_obj() is invoked only by mem_dump_obj(). The encapsulation is a little better in my opinion. > > Thanks > Zqiang > >> >> >> if (virt_addr_valid(object)) >> type = "non-slab/vmalloc memory"; >> @@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) >> type = "zero-size pointer"; >> else >> type = "non-paged memory"; >> - >> +end: >> pr_cont(" %s\n", type); >> } >> EXPORT_SYMBOL_GPL(mem_dump_obj); >> >
diff --git a/mm/util.c b/mm/util.c index 12984e76767e..465f8b8824ca 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1124,8 +1124,12 @@ void mem_dump_obj(void *object) return; } - if (vmalloc_dump_obj(object)) - return; + if (is_vmalloc_addr(object)) { + if (preemptible() && vmalloc_dump_obj(object)) + return; + type = "vmalloc memory"; + goto end; + } if (virt_addr_valid(object)) type = "non-slab/vmalloc memory"; @@ -1135,7 +1139,7 @@ void mem_dump_obj(void *object) type = "zero-size pointer"; else type = "non-paged memory"; - +end: pr_cont(" %s\n", type); } EXPORT_SYMBOL_GPL(mem_dump_obj);