Message ID | 4874693.GXAFRqVoOG@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1657781dyb; Wed, 27 Dec 2023 12:42:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdlgwxF3pFZQWgynOYeQ7aheJ6kPS8cs5+aX/N5795sHcbB217V9kBdhXd7s1MyAPHUaSO X-Received: by 2002:a05:6870:6111:b0:203:c50f:6fc2 with SMTP id s17-20020a056870611100b00203c50f6fc2mr7535011oae.42.1703709745043; Wed, 27 Dec 2023 12:42:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703709745; cv=none; d=google.com; s=arc-20160816; b=jPyAe0OoC0u4Hjws5n9WXY3UUwQ1vt1k6vgYFx0VmPM6pdK8GLgIHXb3lSHYNWWUBB fdgzvCKTQWKzzwgFyhnej+L2QjMJuYPCsI3bU6N8u0leU2Rab7DPFLfMub0rDqUsSNVl J7R3bOC+J/zaT2z7WgI6acMfnRVPgu+TkQkAWyZy/R58u4VE+WkdgXYmS88k0wVkdup4 FCL/Iz47a0ei2kReoGsUJE9unoV0uh9Wl/9HgJ2jatr0Xl1s78q2CgV2u0mHazXlNtGz EtmR4kcyNCgqgMx3wN80zXaEFcLdkfccsfn6TSMqFxv1n0DwPrObxtU2JmGcQvlqN5St Kc1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=E3nP6v5M1BrosgMS9iWuOP0mDo+ITDGa7At8cr+WIdk=; fh=GJObpfi22GEDsdUJ/UPF0sV9R5wqW+3fN2C4DnWtGgw=; b=HjsmKCLKu4te1ZXVdNOWfi4HuqoB1EDJjK+Nj+A8VFRTrO7C0v5abS2HYD33jh7pf1 TOt5P4cgY3P/slRnq5tl+4fyn0lqMQI5plPc07mflcZ0y9xr5C/ceZvmMgy27SpZaHFT +8b3qB5C4N2g2u/rRCj4NUy3jQLtxeLq23AJ4lMuZZbatBHdyu8AH0wPsfnTE0t0ed1Q LAx3qE9SEYC9euQwPppQnyCs0QNFfW2jsK+QM0Smsbt95fbkRumGCSvJmd+kdTbpMlYl QuMMXauPI6tTIWQSudM5JUjLD5ITDb0+o+yU8SwFCcW72JcY8rgRXg1JEFLDbJE5pKhI lP3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x7-20020a05620a258700b007817145f9a5si371970qko.411.2023.12.27.12.42.24 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 12:42:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12245-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CD2061C225A9 for <ouuuleilei@gmail.com>; Wed, 27 Dec 2023 20:42:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6787B48798; Wed, 27 Dec 2023 20:41:49 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B56F747F64; Wed, 27 Dec 2023 20:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id de14cebbb85df213; Wed, 27 Dec 2023 21:41:43 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 23511668E17; Wed, 27 Dec 2023 21:41:43 +0100 (CET) From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Greg KH <gregkh@linuxfoundation.org>, linux-pm@vger.kernel.org Cc: Youngmin Nam <youngmin.nam@samsung.com>, rafael@kernel.org, linux-kernel@vger.kernel.org, d7271.choe@samsung.com, janghyuck.kim@samsung.com, hyesoo.yu@samsung.com, Alan Stern <stern@rowland.harvard.edu>, Ulf Hansson <ulf.hansson@linaro.org> Subject: [PATCH v1 2/3] async: Introduce async_schedule_dev_nocall() Date: Wed, 27 Dec 2023 21:38:23 +0100 Message-ID: <4874693.GXAFRqVoOG@kreacher> In-Reply-To: <6019796.lOV4Wx5bFT@kreacher> References: <CGME20231227084252epcas2p3b063f7852f81f82cd0a31afd7f404db4@epcas2p3.samsung.com> <5754861.DvuYhMxLoT@kreacher> <6019796.lOV4Wx5bFT@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvddvledgudegudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehgrhgvghhkhheslhhinhhugihfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopeihohhunhhgmhhinhdrnhgrmhesshgrmhhsuhhnghdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidq khgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepugejvdejuddrtghhohgvsehsrghmshhunhhgrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=10 Fuz1=10 Fuz2=10 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786469149502994083 X-GMAIL-MSGID: 1786469149502994083 |
Series |
PM: sleep: Fix possible device suspend-resume deadlocks
|
|
Commit Message
Rafael J. Wysocki
Dec. 27, 2023, 8:38 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> In preparation for subsequent changes, introduce a specialized variant of async_schedule_dev() that will not invoke the argument function synchronously when it cannot be scheduled for asynchronous execution. The new function, async_schedule_dev_nocall(), will be used for fixing possible deadlocks in the system-wide power management core code. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> --- drivers/base/power/main.c | 12 ++++++++---- include/linux/async.h | 2 ++ kernel/async.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-)
Comments
On Wed, Dec 27, 2023 at 09:38:23PM +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > In preparation for subsequent changes, introduce a specialized variant > of async_schedule_dev() that will not invoke the argument function > synchronously when it cannot be scheduled for asynchronous execution. > > The new function, async_schedule_dev_nocall(), will be used for fixing > possible deadlocks in the system-wide power management core code. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > --- > drivers/base/power/main.c | 12 ++++++++---- > include/linux/async.h | 2 ++ > kernel/async.c | 29 +++++++++++++++++++++++++++++ > 3 files changed, 39 insertions(+), 4 deletions(-) > > Index: linux-pm/kernel/async.c > =================================================================== > --- linux-pm.orig/kernel/async.c > +++ linux-pm/kernel/async.c > @@ -244,6 +244,35 @@ async_cookie_t async_schedule_node(async > EXPORT_SYMBOL_GPL(async_schedule_node); > > /** > + * async_schedule_dev_nocall - A simplified variant of async_schedule_dev() > + * @func: function to execute asynchronously > + * @dev: device argument to be passed to function > + * > + * @dev is used as both the argument for the function and to provide NUMA > + * context for where to run the function. > + * > + * If the asynchronous execution of @func is scheduled successfully, return > + * true. Otherwise, do nothing and return false, unlike async_schedule_dev() > + * that will run the function synchronously then. > + */ > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > +{ > + struct async_entry *entry; > + > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); Is GFP_KERNEL intended here ? I think it's not safe since will be called from device_resume_noirq() . Regards Stanislaw
On Fri, Dec 29, 2023 at 02:37:36PM +0100, Rafael J. Wysocki wrote: > > > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > > > +{ > > > + struct async_entry *entry; > > > + > > > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); > > > > Is GFP_KERNEL intended here ? > > Yes, it is. > > PM will be the only user of this, at least for now, and it all runs in > process context. > > > I think it's not safe since will > > be called from device_resume_noirq() . > > device_resume_noirq() runs in process context too. > > The name is somewhat confusing (sorry about that) and it means that > hardirq handlers (for the majority of IRQs) don't run in that resume > phase, but interrupts are enabled locally on all CPUs (this is > required for wakeup handling, among other things). Then my concern would be: if among devices with disabled IRQs are disk devices? Seems there are disk devices as well, and because GFP_KERNEL can start reclaiming memory by doing disk IO (write dirty pages for example), with disk driver interrupts disabled reclaiming process can not finish. I do not see how such possible infinite waiting for disk IO scenario is prevented here, did I miss something? Regards Stanislaw
On Fri, Dec 29, 2023 at 8:02 AM Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> wrote: > > On Wed, Dec 27, 2023 at 09:38:23PM +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > In preparation for subsequent changes, introduce a specialized variant > > of async_schedule_dev() that will not invoke the argument function > > synchronously when it cannot be scheduled for asynchronous execution. > > > > The new function, async_schedule_dev_nocall(), will be used for fixing > > possible deadlocks in the system-wide power management core code. > > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > --- > > drivers/base/power/main.c | 12 ++++++++---- > > include/linux/async.h | 2 ++ > > kernel/async.c | 29 +++++++++++++++++++++++++++++ > > 3 files changed, 39 insertions(+), 4 deletions(-) > > > > Index: linux-pm/kernel/async.c > > =================================================================== > > --- linux-pm.orig/kernel/async.c > > +++ linux-pm/kernel/async.c > > @@ -244,6 +244,35 @@ async_cookie_t async_schedule_node(async > > EXPORT_SYMBOL_GPL(async_schedule_node); > > > > /** > > + * async_schedule_dev_nocall - A simplified variant of async_schedule_dev() > > + * @func: function to execute asynchronously > > + * @dev: device argument to be passed to function > > + * > > + * @dev is used as both the argument for the function and to provide NUMA > > + * context for where to run the function. > > + * > > + * If the asynchronous execution of @func is scheduled successfully, return > > + * true. Otherwise, do nothing and return false, unlike async_schedule_dev() > > + * that will run the function synchronously then. > > + */ > > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > > +{ > > + struct async_entry *entry; > > + > > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); > > Is GFP_KERNEL intended here ? Yes, it is. PM will be the only user of this, at least for now, and it all runs in process context. > I think it's not safe since will > be called from device_resume_noirq() . device_resume_noirq() runs in process context too. The name is somewhat confusing (sorry about that) and it means that hardirq handlers (for the majority of IRQs) don't run in that resume phase, but interrupts are enabled locally on all CPUs (this is required for wakeup handling, among other things).
On Fri, Dec 29, 2023 at 3:54 PM Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> wrote: > > On Fri, Dec 29, 2023 at 02:37:36PM +0100, Rafael J. Wysocki wrote: > > > > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > > > > +{ > > > > + struct async_entry *entry; > > > > + > > > > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); > > > > > > Is GFP_KERNEL intended here ? > > > > Yes, it is. > > > > PM will be the only user of this, at least for now, and it all runs in > > process context. > > > > > I think it's not safe since will > > > be called from device_resume_noirq() . > > > > device_resume_noirq() runs in process context too. > > > > The name is somewhat confusing (sorry about that) and it means that > > hardirq handlers (for the majority of IRQs) don't run in that resume > > phase, but interrupts are enabled locally on all CPUs (this is > > required for wakeup handling, among other things). > > Then my concern would be: if among devices with disabled IRQs are > disk devices? Seems there are disk devices as well, and because > GFP_KERNEL can start reclaiming memory by doing disk IO (write > dirty pages for example), with disk driver interrupts disabled > reclaiming process can not finish. > > I do not see how such possible infinite waiting for disk IO > scenario is prevented here, did I miss something? Well, it is not a concern, because the suspend code already prevents the mm subsystem from trying too hard to find free memory. See the pm_restrict_gfp_mask() call in enter_state(). Otherwise, it would have been a problem for any GFP_KERNEL allocations made during system-wide suspend-resume, not just in the _noirq phases.
On Fri, Dec 29, 2023 at 05:36:01PM +0100, Rafael J. Wysocki wrote: > On Fri, Dec 29, 2023 at 3:54 PM Stanislaw Gruszka > <stanislaw.gruszka@linux.intel.com> wrote: > > > > On Fri, Dec 29, 2023 at 02:37:36PM +0100, Rafael J. Wysocki wrote: > > > > > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > > > > > +{ > > > > > + struct async_entry *entry; > > > > > + > > > > > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); > > > > > > > > Is GFP_KERNEL intended here ? > > > > > > Yes, it is. > > > > > > PM will be the only user of this, at least for now, and it all runs in > > > process context. > > > > > > > I think it's not safe since will > > > > be called from device_resume_noirq() . > > > > > > device_resume_noirq() runs in process context too. > > > > > > The name is somewhat confusing (sorry about that) and it means that > > > hardirq handlers (for the majority of IRQs) don't run in that resume > > > phase, but interrupts are enabled locally on all CPUs (this is > > > required for wakeup handling, among other things). > > > > Then my concern would be: if among devices with disabled IRQs are > > disk devices? Seems there are disk devices as well, and because > > GFP_KERNEL can start reclaiming memory by doing disk IO (write > > dirty pages for example), with disk driver interrupts disabled > > reclaiming process can not finish. > > > > I do not see how such possible infinite waiting for disk IO > > scenario is prevented here, did I miss something? > > Well, it is not a concern, because the suspend code already prevents > the mm subsystem from trying too hard to find free memory. See the > pm_restrict_gfp_mask() call in enter_state(). So that I missed :-) Thanks for explanations. Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> for the series.
On Tue, Jan 2, 2024 at 8:10 AM Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> wrote: > > On Fri, Dec 29, 2023 at 05:36:01PM +0100, Rafael J. Wysocki wrote: > > On Fri, Dec 29, 2023 at 3:54 PM Stanislaw Gruszka > > <stanislaw.gruszka@linux.intel.com> wrote: > > > > > > On Fri, Dec 29, 2023 at 02:37:36PM +0100, Rafael J. Wysocki wrote: > > > > > > +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) > > > > > > +{ > > > > > > + struct async_entry *entry; > > > > > > + > > > > > > + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); > > > > > > > > > > Is GFP_KERNEL intended here ? > > > > > > > > Yes, it is. > > > > > > > > PM will be the only user of this, at least for now, and it all runs in > > > > process context. > > > > > > > > > I think it's not safe since will > > > > > be called from device_resume_noirq() . > > > > > > > > device_resume_noirq() runs in process context too. > > > > > > > > The name is somewhat confusing (sorry about that) and it means that > > > > hardirq handlers (for the majority of IRQs) don't run in that resume > > > > phase, but interrupts are enabled locally on all CPUs (this is > > > > required for wakeup handling, among other things). > > > > > > Then my concern would be: if among devices with disabled IRQs are > > > disk devices? Seems there are disk devices as well, and because > > > GFP_KERNEL can start reclaiming memory by doing disk IO (write > > > dirty pages for example), with disk driver interrupts disabled > > > reclaiming process can not finish. > > > > > > I do not see how such possible infinite waiting for disk IO > > > scenario is prevented here, did I miss something? > > > > Well, it is not a concern, because the suspend code already prevents > > the mm subsystem from trying too hard to find free memory. See the > > pm_restrict_gfp_mask() call in enter_state(). > > So that I missed :-) Thanks for explanations. > > Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> for the series. Thank you!
Index: linux-pm/kernel/async.c =================================================================== --- linux-pm.orig/kernel/async.c +++ linux-pm/kernel/async.c @@ -244,6 +244,35 @@ async_cookie_t async_schedule_node(async EXPORT_SYMBOL_GPL(async_schedule_node); /** + * async_schedule_dev_nocall - A simplified variant of async_schedule_dev() + * @func: function to execute asynchronously + * @dev: device argument to be passed to function + * + * @dev is used as both the argument for the function and to provide NUMA + * context for where to run the function. + * + * If the asynchronous execution of @func is scheduled successfully, return + * true. Otherwise, do nothing and return false, unlike async_schedule_dev() + * that will run the function synchronously then. + */ +bool async_schedule_dev_nocall(async_func_t func, struct device *dev) +{ + struct async_entry *entry; + + entry = kzalloc(sizeof(struct async_entry), GFP_KERNEL); + + /* Give up if there is no memory or too much work. */ + if (!entry || atomic_read(&entry_count) > MAX_WORK) { + kfree(entry); + return false; + } + + __async_schedule_node_domain(func, dev, dev_to_node(dev), + &async_dfl_domain, entry); + return true; +} + +/** * async_synchronize_full - synchronize all asynchronous function calls * * This function waits until all asynchronous function calls have been done. Index: linux-pm/include/linux/async.h =================================================================== --- linux-pm.orig/include/linux/async.h +++ linux-pm/include/linux/async.h @@ -90,6 +90,8 @@ async_schedule_dev(async_func_t func, st return async_schedule_node(func, dev, dev_to_node(dev)); } +bool async_schedule_dev_nocall(async_func_t func, struct device *dev); + /** * async_schedule_dev_domain - A device specific version of async_schedule_domain * @func: function to execute asynchronously