From nobody Wed Oct 8 04:08:34 2025 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 907022E49B1 for ; Thu, 3 Jul 2025 11:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542074; cv=none; b=Ipxjix8Jw33ORa195eV8Y+KRs1FL66p/VRTrfu39jQJq/vsv6ez6+114qG0QInhGectymb+NEE6xxoLyQV6zZfGM9hKXkHCfxtI0CXZV8KB8QNJSIpxFwrSs7egIPA9svA16KUUQjtGem+SgnJHhR3M1v33PtCOQmhh3FjklF8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542074; c=relaxed/simple; bh=X1Oyr9vFTxLX3A2BuvfxXazNPEQYM31gD4YJTucU+Z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QLa1EVPzPzIDlfZ6YE5nzrkO85/Llykwz79hfXIhmhFFgXfBxAHlSn4HV7kEOV1vv8IhtDBQpag6i2ue/NXI6JdsUWCffXREghDYZWq6Q77KYXm2BRgi5UDXUWzEVlb17GXCe6pmaI29BWyYrAAUgGrJ8/8Hgu0fsHnowpeKVu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=NWaPrfeM; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="NWaPrfeM" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-ae3c5f666bfso272674766b.3 for ; Thu, 03 Jul 2025 04:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1751542070; x=1752146870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cTGALKZoVheypQ1QT5i2+A3Y7/0VfJ5YTQvSLmEPSq0=; b=NWaPrfeMNu6lzcL6odLfZsNPLmYpVaPVg30El2x0eGSaccOcXkGqo1EdMEBm1zC5GI UWaqm6d88selempizMTQdl90luJ/o+HoxhIRBcnWkeaVoOAWZ5OPgM2yecuG97Pr3HJk qS96Ys4Ra3HzmYQX/1A68bF3kcz0O6hpK2bGHsmMkmPhgrbC18rNVDAvvopGIFVsu/1D LZHIOwrOvbHodHlqKABBqMCqB/qUr4Ndf25U9wWhGVeY6W8qK6Zb1JmladgI6A9GLm8M hHIviZwE4iTBFIbTFTNuii2SNcEwqd8Jb01yMnVWxLifPGewD6MrP5QTZ1wX5YqjBED6 GrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751542070; x=1752146870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cTGALKZoVheypQ1QT5i2+A3Y7/0VfJ5YTQvSLmEPSq0=; b=DV15SdLivaYiLB/zJpcgxkTL8+lsYTp/l3J6qZbs8dHQv9xtZG+rodW26V4WGVCIVd Sl4og8Rs0wGzsS2yMLoafr3K1fqMMLo7ehVmy8Y/zSQftkUwdS/6+VtM0twFcevXxWb4 uoVSjh/g0Bt2LRs+2QJIgfhiopflTfyIh4CvD5WhDSIS6HyziiWQGyxFmP0oaM7UcTkc xmugMDL4h1oRwbbsrlyxKHHicsADKuYdFugv+5lL74ru9rFucg5zhNjyjCEkDfy+v1T7 Ud4rz1nQkJeFx3G1nY1onMX2dDm5GVaTv7J5UqRX2dM+xQlA/9YDuqz2HOHqcQeEsgr4 HeHA== X-Forwarded-Encrypted: i=1; AJvYcCVFFTYWyM7OcypzKpv1zeTqonFmSs+sKnou4XbQUXudOgea6SgojTOKUGHZUPhVM5s6a80cvbTokwUJlM8=@vger.kernel.org X-Gm-Message-State: AOJu0YwjWrro9A29sOWtRA4BW02y5fT7R3s+CXcdNF4wgs/nR/ESMpBV 5lPQvpr6IJ3LoIs8PaUaHp+dC+cqvOMaQujsY24KTj6LRn/b1MqMeHaFQGJkexynDQg= X-Gm-Gg: ASbGnctn0x7r5A54p3ka2v8MxVrnAx7kWwJQSlGrFefPtf8ah1OwVv88mwIDmHeo6t8 9xE5d9ku1ReF4pEBSdYtIQzpBDKWvsHUDhX56+gMUcyxhuvJHTGBnLtGIkHrRrBEpdoA8yjRQZF 4RDpSyUwlN7wFdoEsW2kgBgU0H3dU+/Mgi8sL6Z5JgUarr9HLLZUAs6koCclIuXfzYO8awDoaIA +zQGBksJuBCO7I2xpL6Bl0Cfu5iODjAP3cAKJRpKNQBEMv0fzJLaSIp0nllK3KqlAAYZEZB6K/P 4qHYZ27XiE2rD78Rpc5nb+cD6L13jsVTqS66vjR6E2IvFpv4+fFYlnqZr/4yIRjRWYZc1OuQax7 sm6Aaf2aNkMAIMlw= X-Google-Smtp-Source: AGHT+IFkYQwbGErnKmAXbXp56IWazGm9DvxurIRdNCD1GAvBXxqd+zW8SE1e2XD1WudHDmEIZdYoAw== X-Received: by 2002:a17:907:1ca7:b0:ae3:6b52:f7dd with SMTP id a640c23a62f3a-ae3c2d69de4mr612468566b.46.1751542069470; Thu, 03 Jul 2025 04:27:49 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.83]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35365a75fsm1247016966b.67.2025.07.03.04.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 04:27:49 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: linux@armlinux.org.uk, gregkh@linuxfoundation.org, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, rafael@kernel.org, dakr@kernel.org, len.brown@intel.com, pavel@kernel.org, andersson@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, wsa+renesas@sang-engineering.com, ulf.hansson@linaro.org, mathieu.poirier@linaro.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, broonie@kernel.org, robh@kernel.org, jirislaby@kernel.org, saravanak@google.com, jic23@kernel.org, dmitry.torokhov@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, linux-mmc@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-sound@vger.kernel.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, bhelgaas@google.com, geert@linux-m68k.org, linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, fabrizio.castro.jz@renesas.com, Claudiu Beznea Subject: [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup() Date: Thu, 3 Jul 2025 14:27:07 +0300 Message-ID: <20250703112708.1621607-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> References: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The dev_pm_domain_attach() function is typically used in bus code alongside dev_pm_domain_detach(), often following patterns like: static int bus_probe(struct device *_dev) { struct bus_driver *drv =3D to_bus_driver(dev->driver); struct bus_device *dev =3D to_bus_device(_dev); int ret; // ... ret =3D dev_pm_domain_attach(_dev, true); if (ret) return ret; if (drv->probe) ret =3D drv->probe(dev); // ... } static void bus_remove(struct device *_dev) { struct bus_driver *drv =3D to_bus_driver(dev->driver); struct bus_device *dev =3D to_bus_device(_dev); if (drv->remove) drv->remove(dev); dev_pm_domain_detach(_dev); } When the driver's probe function uses devres-managed resources that depend on the power domain state, those resources are released later during device_unbind_cleanup(). Releasing devres-managed resources that depend on the power domain state after detaching the device from its PM domain can cause failures. For example, if the driver uses devm_pm_runtime_enable() in its probe function, and the device's clocks are managed by the PM domain, then during removal the runtime PM is disabled in device_unbind_cleanup() after the clocks have been removed from the PM domain. It may happen that the devm_pm_runtime_enable() action causes the device to be runtime-resumed. If the driver specific runtime PM APIs access registers directly, this will lead to accessing device registers without clocks being enabled. Similar issues may occur with other devres actions that access device registers. Add detach_power_off member to struct dev_pm_info, to be used later in device_unbind_cleanup() as the power_off argument for dev_pm_domain_detach(). This is a preparatory step toward removing dev_pm_domain_detach() calls from bus remove functions. Since the current PM domain detach functions (genpd_dev_pm_detach() and acpi_dev_pm_detach()) already set dev->pm_domain =3D NULL, there should be no issues with bus drivers that still call dev_pm_domain_detach() in their remove functions. Signed-off-by: Claudiu Beznea --- Changes in v5: - added flags argument to dev_pm_domain_attach_attach() - added description for struct dev_pm_info::detach_power_off; @Rafael: I kept the detach_power_off flag outside of CONFIG_PM as it is used unconditionally in device_unbind_cleanup() Changes in v4: - save dev->power.detach_power_off in dev_pm_domain_attach() and use it in device_unbind_cleanup() when detaching - adjusted patch description Changes in v3: - dropped devm_pm_domain_detach_off(), devm_pm_domain_detach_on() and use a single function devm_pm_domain_detach() Changes in v2: - none; this patch is new drivers/base/dd.c | 2 ++ drivers/base/power/common.c | 3 +++ include/linux/pm.h | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index b526e0e0f52d..13ab98e033ea 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -552,6 +553,7 @@ static void device_unbind_cleanup(struct device *dev) dev->dma_range_map =3D NULL; device_set_driver(dev, NULL); dev_set_drvdata(dev, NULL); + dev_pm_domain_detach(dev, dev->power.detach_power_off); if (dev->pm_domain && dev->pm_domain->dismiss) dev->pm_domain->dismiss(dev); pm_runtime_reinit(dev); diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index fecb85fa85ac..6ecf9ce4a4e6 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -111,6 +111,9 @@ int dev_pm_domain_attach(struct device *dev, u32 flags) if (!ret) ret =3D genpd_dev_pm_attach(dev); =20 + if (dev->pm_domain) + dev->power.detach_power_off =3D !!(flags & PD_FLAG_DETACH_POWER_OFF); + return ret < 0 ? ret : 0; } EXPORT_SYMBOL_GPL(dev_pm_domain_attach); diff --git a/include/linux/pm.h b/include/linux/pm.h index f0bd8fbae4f2..be824dfc8577 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -720,6 +720,7 @@ struct dev_pm_info { struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ void (*set_latency_tolerance)(struct device *, s32); struct dev_pm_qos *qos; + bool detach_power_off:1; /* Owned by the driver core */ }; =20 extern int dev_pm_get_subsys_data(struct device *dev); --=20 2.43.0