Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10666492pxu; Wed, 30 Dec 2020 08:21:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrxTMDwuksTfnAj+jkJz3IkD0pkvyjIku0xzu82FVMYYtMMdEi2bHW8lfzvikq+QVl2RGl X-Received: by 2002:a05:6402:1803:: with SMTP id g3mr51954168edy.10.1609345289351; Wed, 30 Dec 2020 08:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609345289; cv=none; d=google.com; s=arc-20160816; b=SfWPMjIgbAghhlAFpMJIxuVcREwkuhAvzOf6ASv7NU6k232dz4h5H2BThmUcu4b4PV PrVrqj5Mlwb5hHY1F+UVb+VkZZgkNybG4tGi8OFh+6y8N/vosDFkSEQO8oxDsJ6QHU3F 0jd5xS9KJiO4DezCB6kXq8MVl2bxFA8WZG4zfYnVvS9jzIUwXslx6I33V5qVdKUBpUaB si3UCAxH3E0Z+RHvL/uV8P9yCuxETP34+MgxTHP3WXS3HEiq7St6eqIubW1HblCLOw3f 5bV/5WjCn21MtQqPXwNKAdvKJ7W4pn0ZjqrlcLxA2Vh+jAU/yhMKInTGgmKV9gHLT1Wr 7uag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0DSasYq5iqP1L4eWyAnI8exjFo65P8+LD5PXnx6alrU=; b=tTzvs6tg3lP4XLs7qa+EkBDUpKu0fvUMFChdfPJXaxGvUIQke8wuhfGuha6k46TZGo XxAjWYWbP9wZ6Xv89zFlFY3Ifa5V7eeQyFDEx29AocokcadZGTMjL1QAGRuTCNKfztVr WdaxDSHZ0WhlG83yujfzP0Na715sV7JUm2OvqyXQdikCdUKlFl3/+B2H7fhH3C01fToG Ayt4JZYX0KJXDjNt8aHQ+CBMCpqR9B+Lqx2acjoEYdtcjtuNZtsCmWVmPSVRUYXAfHjt h+Xd45cRD9y5UBJw2YUVOBnA+xaF0zEpGjE0q46pR2FgE2b1NOgmCgS0Nfl6exB/D3jJ m2AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mZx2bwe8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e24si20729834edc.290.2020.12.30.08.21.05; Wed, 30 Dec 2020 08:21:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mZx2bwe8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726617AbgL3QUW (ORCPT + 99 others); Wed, 30 Dec 2020 11:20:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:56512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgL3QUW (ORCPT ); Wed, 30 Dec 2020 11:20:22 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E78520780; Wed, 30 Dec 2020 16:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609345181; bh=2vjw4RXrbCn3wiC+56smANDAn4JwYaeUxrWOmYLCqHA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=mZx2bwe81KzjKjoCyzhwedHoV/DWN2b9UAp1IP5rOxoqlgF1e16P5m/J+Q83LHHvJ 1fDQtD4BascWH/UVExmuyYvbSJceB4vMhwnhl181tLpO488nN0L6tPZEch2f/u/TOl XaIQBVV56+sEu7Pg+WKIKc0NmiKVI+6ypkx0wOtq3f9EkwyA/HwgaFD/xatVUfvoB2 nmBpF/ZXmozfKfQ92DXyYSyK7tCNypL4h5Tm2BhNqYcuXxyvLGmoFNr8biwuzhF4Ui l8RYR8GSwTrbRu9Y5QzC6KTtkB0/MtaECDKwrXPpCiJDWfwaXTihco12/kl1dRQvKI JkUf4hOEybA4g== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 09AC335227F7; Wed, 30 Dec 2020 08:19:41 -0800 (PST) Date: Wed, 30 Dec 2020 08:19:41 -0800 From: "Paul E. McKenney" To: qiang.zhang@windriver.com Cc: akpm@linux-foundation.org, manfred@colorfullife.com, gustavoars@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ipc/sem.c: Convert kfree_rcu() to call_rcu() in freeary function Message-ID: <20201230161941.GN2657@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20201230120038.19489-1-qiang.zhang@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201230120038.19489-1-qiang.zhang@windriver.com> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 30, 2020 at 08:00:38PM +0800, qiang.zhang@windriver.com wrote: > From: Zqiang > > Due to freeary function is called with spinlock be held, > the synchronize_rcu function may be called in kfree_rcu > function, the schedule may be happen in spinlock critical > region, need to replace kfree_rcu() with call_rcu(). Except that the call to kfree_rcu() below has two arguments, and thus provides a link for queuing the callback. It will never directly invoke synchronize_rcu(). It is only the single-argument variant of kfree_rcu() that might invoke synchronize_rcu(). Or are you seeing lockdep or might-sleep failures with the current code? If so, please post the relevant portions of the console output. Thanx, Paul > Fixes: 693a8b6eecce ("ipc,rcu: Convert call_rcu(free_un) to kfree_rcu()") > Signed-off-by: Zqiang > --- > ipc/sem.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/ipc/sem.c b/ipc/sem.c > index f6c30a85dadf..12c3184347d9 100644 > --- a/ipc/sem.c > +++ b/ipc/sem.c > @@ -1132,6 +1132,13 @@ static int count_semcnt(struct sem_array *sma, ushort semnum, > return semcnt; > } > > +static void free_un(struct rcu_head *head) > +{ > + struct sem_undo *un = container_of(head, struct sem_undo, rcu); > + > + kfree(un); > +} > + > /* Free a semaphore set. freeary() is called with sem_ids.rwsem locked > * as a writer and the spinlock for this semaphore set hold. sem_ids.rwsem > * remains locked on exit. > @@ -1152,7 +1159,7 @@ static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) > un->semid = -1; > list_del_rcu(&un->list_proc); > spin_unlock(&un->ulp->lock); > - kfree_rcu(un, rcu); > + call_rcu(&un->rcu, free_un); > } > > /* Wake up all pending processes and let them fail with EIDRM. */ > -- > 2.17.1 >