Skip to contentSkip to conversation

Make platform profiles firmware independent

PATCH Superseded Daniel Lezcano 4 participants 9 messages Oct 19

Subsystems (8)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Make platform profiles firmware independent

Make platform profile selection independent of ACPI firmware.

The provider API already uses struct device, profile enums and callbacks; it does not require an ACPI handle or firmware node. However, the core is built under drivers/acpi/, its Kconfig symbol depends implicitly on ACPI, and initialization fails when ACPI is disabled, preventing non-ACPI providers from using the existing firmware-independent class interface.

This series moves the core to drivers/platform/profile/ and introduces CONFIG_PLATFORM_PROFILE, updating all existing provider selectors. It retains the tristate configuration and platform_profile module name. Firmware-specific discovery and profile operations remain with providers. The core can also be selected directly through its Kconfig prompt.

An optional ACPI adapter obtains the legacy sysfs kobject and is linked into the same module. The generic core contains no ACPI types or symbols and initializes without ACPI support or with ACPI disabled at boot. The existing /sys/firmware/acpi/platform_profile and /sys/firmware/acpi/platform_profile_choices attributes remain available on active ACPI systems.

CONFIG_PLATFORM_PROFILE_LEGACY controls the backwards-compatible aggregate sysfs interface. It defaults to enabled to preserve existing userspace. Disabling it omits the legacy sysfs callbacks and ACPI adapter while retaining class devices and kernel profile cycling. New userspace should discover and control individual class devices instead.
The interface is deprecated, with removal intended after the 2028 LTS kernel once userspace migration is complete. A shared pr_notice_once() warns on legacy attribute access rather than on merely loading the core. The default remains enabled while userspace adopts released class-device support; this series does not claim that ecosystem migration is complete.

The existing firmware-independent interface remains:

/sys/class/platform-profile/platform-profile-X/name /sys/class/platform-profile/platform-profile-X/choices /sys/class/platform-profile/platform-profile-X/profile

Non-ACPI userspace controls providers individually through these class devices. Aggregate selection remains available through the legacy ACPI attributes, and aggregate profile cycling remains available to kernel callers. No new sysfs directory or userspace ABI is introduced.

The first patch fixes the lock/lifetime boundary: sysfs teardown must not drain callbacks while holding the mutex those callbacks need. A separate registration mutex serializes lifecycle
changes, while a profile-lock-protected handler list determines aggregate membership independently of the class device's teardown state.

The second patch extracts the core and uses subsys_initcall_sync() so it initializes after ACPI and before built-in thermal and CPUFreq consumers. The third completes notifications on direct class-device writes and restores aggregate visibility after registration failure. The fourth documents the existing interfaces and extends maintainer coverage. The fifth makes the legacy ACPI aggregate interface optional.

Validation:

- ARM64 built-in core with CONFIG_ACPI=n: W=1 build and sparse.
- x86 modular core with CONFIG_ACPI=y: W=1 object build and sparse. Both CONFIG_PLATFORM_PROFILE_LEGACY=y and =n are covered.
- Full x86 kernel link and QEMU boot with lockdep and list debugging, with active ACPI and with acpi=off.
- Firmware-less providers exercising common and hidden choices, profile reads/writes, invalid input, mixed profiles, cycling, partial callback failures and POLLPRI on the class and legacy ACPI interfaces. With acpi=off, class get/set, notifications and kernel cycling are exercised. Both runs check that no new aggregate sysfs directory is created.
- Concurrent sysfs I/O with two persistent providers while a third provider is registered and removed 200 times, last-provider attribute removal and repeated provider module reloads.
- QEMU with active ACPI and CONFIG_PLATFORM_PROFILE_LEGACY=n: verify the legacy attributes are absent, class get/set and notifications work, and kernel cycling and registration/removal stress pass.

The provider API and profile names are unchanged. Aggregate writes retain their sequential, non-transactional behavior: a failing callback does not roll back providers already updated.

Changes in v2:
- Add the Fixes tag to patch 1 and explain how the mutex-guard conversion reintroduced the teardown deadlock previously fixed in 041142d7d252, and how class-device support subsequently extended the affected paths.
- Drop the proposed /sys/kernel/platform_profile/ aggregate interface and its ABI documentation. Use the existing firmware-independent /sys/class/platform-profile/platform-profile-X/ devices instead.
- Preserve aggregate selection through the legacy ACPI attributes and retain internal aggregation for kernel profile cycling.
- Refocus patch 3 on class-device notifications for direct writes and restoring aggregate visibility after failed registration.
- Update the Kconfig help and documentation to describe the existing class interface and distinguish it from ACPI aggregate selection.
- Revalidate class controls and notifications with acpi=off, legacy aggregation with ACPI active, and the absence of a new aggregate ABI.
- Add CONFIG_PLATFORM_PROFILE_LEGACY (default y) to make legacy aggregate sysfs code optional, independently of class devices and kernel cycling.
- Mark the legacy ABI deprecated and describe removal after the 2028 LTS kernel, conditional on userspace migration. Emit one shared notice on legacy attribute access; retain the enabled default during migration.
- Move the legacy ACPI ABI documentation from testing/ to obsolete/, document the replacement class attributes and update MAINTAINERS.

Changes in v1:
- Initial series extracting the core from ACPI, separating handler locking from sysfs lifetime operations and retaining the legacy ABI.
- Proposed a firmware-neutral aggregate sysfs interface alongside the existing per-provider class devices (removed in v2).

Daniel Lezcano (5):
platform profile: Separate handler locking from sysfs lifetime platform profile: Extract the core from ACPI
platform profile: Complete class notifications and registration cleanup platform profile: Document firmware-independent profile selection platform profile: Make legacy ACPI aggregate interface optional

 .../{testing => obsolete}/sysfs-platform_profile   |  12 ++
 .../ABI/testing/sysfs-class-platform-profile       |   2 +-
 .../userspace-api/sysfs-platform_profile.rst       |  55 ++++--
 MAINTAINERS                                        |   5 +
 drivers/acpi/Kconfig                               |   3 -
 drivers/acpi/Makefile                              |   1 -
 drivers/cpufreq/Kconfig.x86                        |   2 +-
 drivers/platform/Kconfig                           |  35 ++++
 drivers/platform/Makefile                          |   2 +
 drivers/platform/profile/Makefile                  |   5 +
 drivers/platform/profile/acpi.c                    |  15 ++
 .../platform_profile.c => platform/profile/core.c} | 195 +++++++++++++++------
 drivers/platform/profile/profile.h                 |  17 ++
 drivers/platform/surface/Kconfig                   |   6 +-
 drivers/platform/x86/Kconfig                       |  10 +-
 drivers/platform/x86/amd/pmf/Kconfig               |   2 +-
 drivers/platform/x86/dell/Kconfig                  |   4 +-
 drivers/platform/x86/hp/Kconfig                    |   2 +-
 drivers/platform/x86/lenovo/Kconfig                |   6 +-
 drivers/thermal/intel/int340x_thermal/Kconfig      |   2 +-
 include/linux/platform_profile.h                   |   3 +
 21 files changed, 296 insertions(+), 88 deletions(-)

base-commit: d0cd1e850e1602729dd60dc3c5fd96f80e0cdc5d

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/5 platform profile: Separate handler locking from sysfs lifetime

Registration and removal currently hold profile_lock across device_unregister() and sysfs_update_group(). These operations can remove sysfs attributes and wait for their active callbacks to finish. The profile read and write callbacks acquire profile_lock themselves, so a concurrent access can deadlock:

  Removal/update path             Active sysfs callback
  -------------------             ---------------------
  acquire profile_lock            hold kernfs active reference

remove a sysfs attribute wait for profile_lock
wait for its active references

The removal path cannot finish until the callback returns, and the callback cannot return until the removal path releases profile_lock. This applies both to per-provider device teardown and to updates of the legacy aggregate attribute group.

Commit 041142d7d252 ("ACPI: platform-profile: Fix possible deadlock in platform_profile_remove()") previously fixed this lock ordering by moving sysfs_remove_group() outside profile_lock. Commit 55b1e68134bf ("ACPI:
platform_profile: Use guard(mutex) for register/unregister") reintroduced the issue by extending the mutex guard over sysfs_remove_group(). Later, commit 77be5cacb2c2 ("ACPI: platform_profile: Create class for ACPI platform profile") replaced that teardown with device_unregister() and sysfs_update_group(), still under the same mutex, extending the problem to class-device teardown and aggregate attribute updates.

Simply dropping profile_lock around these operations is insufficient. Aggregate operations currently discover providers through the class device list. A provider being unregistered could therefore still be selected for an aggregate read, write or cycle while its sysfs files are being torn down. Concurrent registrations and removals would also race when updating aggregate attribute visibility.

Introduce profile_registration_lock to serialize registration, removal and aggregate sysfs updates. Sysfs callbacks never acquire this mutex. Retain profile_lock for profile operations and use it to protect an explicit list of handlers participating in the aggregate interface.

Add a handler to that list only after device_register() succeeds. On removal, unlink it under profile_lock before calling device_unregister(). Acquiring profile_lock first waits for any aggregate operation already using the handler to complete; unlinking prevents later aggregate operations from finding it. Release profile_lock before draining sysfs callbacks, allowing active per-provider callbacks to complete before the device is released. Apply the same unlink-before-unregister ordering to registration error cleanup.

Walk this list for aggregate reads, writes and profile cycling, and use its emptiness to determine aggregate attribute visibility. The class devices remain the per-provider userspace interface.

There can now be an interval between removing the last handler from the list and removing the aggregate attributes. Explicitly reject choices reads and writes during that interval: the intersection bitmap starts with every bit set, so an empty traversal must not advertise all profiles or report a successful write without updating a provider.

This separates aggregate membership from class device teardown while preserving the existing class and ACPI sysfs interfaces.

Fixes 55b1e68134bf ("ACPI: platform_profile: Use guard(mutex) for register/unregister")
Assisted-by OpenCode:gpt-6.1-sol
---
 drivers/acpi/platform_profile.c | 75 ++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 33 deletions(-)
drivers/acpi/platform_profile.c +42 -33
index 79d2e92e5c28..f98ce4cda02c 100644
@@ -8,6 +8,7 @@
 #include <linux/bits.h>
 #include <linux/cleanup.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/platform_profile.h>
 #include <linux/sysfs.h>
@@ -15,8 +16,12 @@
 #define to_pprof_handler(d)	(container_of(d, struct platform_profile_handler, dev))
 
 static DEFINE_MUTEX(profile_lock);
+/* Serialize registration and sysfs updates without blocking sysfs callbacks. */
+static DEFINE_MUTEX(profile_registration_lock);
+static LIST_HEAD(profile_handlers);
 
 struct platform_profile_handler {
+	struct list_head node;
 	const char *name;
 	struct device dev;
 	int minor;
@@ -44,6 +49,22 @@ static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST);
 
 static DEFINE_IDA(platform_profile_ida);
 
+static int profile_walk_handlers(void *data,
+				 int (*fn)(struct device *dev, void *data))
+{
+	struct platform_profile_handler *handler;
+	int ret;
+
+	lockdep_assert_held(&profile_lock);
+	list_for_each_entry(handler, &profile_handlers, node) {
+		ret = fn(&handler->dev, data);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 /**
  * _commmon_choices_show - Show the available profile choices
  * @choices: The available profile choices
@@ -306,20 +327,18 @@ static ssize_t platform_profile_choices_show(struct kobject *kobj,
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		err = profile_walk_handlers(&data, _aggregate_choices);
 		if (err)
 			return err;
 		if (data.count == 1) {
-			err = class_for_each_device(&platform_profile_class, NULL,
-						    &data, _remove_hidden_choices);
+			err = profile_walk_handlers(&data, _remove_hidden_choices);
 			if (err)
 				return err;
 		}
 	}
 
 	/* no profile handler registered any more */
-	if (bitmap_empty(data.aggregate, PLATFORM_PROFILE_LAST))
+	if (!data.count || bitmap_empty(data.aggregate, PLATFORM_PROFILE_LAST))
 		return -EINVAL;
 
 	return _commmon_choices_show(data.aggregate, buf);
@@ -384,8 +403,7 @@ static ssize_t platform_profile_show(struct kobject *kobj,
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &profile, _aggregate_profiles);
+		err = profile_walk_handlers(&profile, _aggregate_profiles);
 		if (err)
 			return err;
 	}
@@ -423,15 +441,13 @@ static ssize_t platform_profile_store(struct kobject *kobj,
 		return -EINVAL;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		ret = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		ret = profile_walk_handlers(&data, _aggregate_choices);
 		if (ret)
 			return ret;
-		if (!test_bit(i, data.aggregate))
+		if (!data.count || !test_bit(i, data.aggregate))
 			return -EOPNOTSUPP;
 
-		ret = class_for_each_device(&platform_profile_class, NULL, &i,
-					    _store_and_notify);
+		ret = profile_walk_handlers(&i, _store_and_notify);
 		if (ret)
 			return ret;
 	}
@@ -450,22 +466,11 @@ static struct attribute *platform_profile_attrs[] = {
 	NULL
 };
 
-static int profile_class_registered(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 static umode_t profile_class_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
 {
-	struct device *dev;
-
-	dev = class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered);
-	if (!dev)
-		return 0;
-
-	put_device(dev);
+	guard(mutex)(&profile_lock);
 
-	return attr->mode;
+	return list_empty(&profile_handlers) ? 0 : attr->mode;
 }
 
 static const struct attribute_group platform_profile_group = {
@@ -502,8 +507,7 @@ int platform_profile_cycle(void)
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &profile, _aggregate_profiles);
+		err = profile_walk_handlers(&profile, _aggregate_profiles);
 		if (err)
 			return err;
 
@@ -512,8 +516,7 @@ int platform_profile_cycle(void)
 		    profile == PLATFORM_PROFILE_LAST)
 			return -EINVAL;
 
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		err = profile_walk_handlers(&data, _aggregate_choices);
 		if (err)
 			return err;
 
@@ -525,8 +528,7 @@ int platform_profile_cycle(void)
 					  PLATFORM_PROFILE_LAST,
 					  profile + 1);
 
-		err = class_for_each_device(&platform_profile_class, NULL, &next,
-					    _store_and_notify);
+		err = profile_walk_handlers(&next, _store_and_notify);
 
 		if (err)
 			return err;
@@ -583,7 +585,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 		}
 	}
 
-	guard(mutex)(&profile_lock);
+	guard(mutex)(&profile_registration_lock);
 
 	/* create class interface for individual handler */
 	minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
@@ -604,6 +606,8 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 		put_device(ppdev);
 		goto cleanup_ida;
 	}
+	scoped_guard(mutex, &profile_lock)
+		list_add_tail(&to_pprof_handler(ppdev)->node, &profile_handlers);
 
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
 
@@ -614,6 +618,8 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 	return ppdev;
 
 cleanup_cur:
+	scoped_guard(mutex, &profile_lock)
+		list_del(&to_pprof_handler(ppdev)->node);
 	device_unregister(ppdev);
 
 cleanup_ida:
@@ -636,7 +642,10 @@ void platform_profile_remove(struct device *dev)
 
 	pprof = to_pprof_handler(dev);
 
-	guard(mutex)(&profile_lock);
+	guard(mutex)(&profile_registration_lock);
+
+	scoped_guard(mutex, &profile_lock)
+		list_del(&pprof->node);
 
 	ida_free(&platform_profile_ida, pprof->minor);
 	device_unregister(&pprof->dev);
Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 2/5 platform profile: Extract the core from ACPI

In reply to Daniel Lezcano

Platform profile providers already use device-based callbacks and do not need ACPI types. The core is nevertheless confined to the ACPI build and refuses to initialize when ACPI is disabled.

Move the implementation to drivers/platform/profile and introduce the firmware-independent PLATFORM_PROFILE symbol. Update all provider selectors. Keep provider-specific ACPI dependencies and the platform_profile module name.

Isolate access to the legacy ACPI kobject in an optional compatibility object linked into the same module. Retain the legacy ABI on active ACPI systems, and initialize the class even when ACPI is absent or disabled.

Use subsys_initcall_sync so the class is ready before built-in thermal and CPUFreq providers, but after ACPI has initialized its compatibility kobject.

Assisted-by OpenCode:gpt-6.1-sol
---
 drivers/acpi/Kconfig                          |  3 -
 drivers/acpi/Makefile                         |  1 -
 drivers/cpufreq/Kconfig.x86                   |  2 +-
 drivers/platform/Kconfig                      | 16 +++++
 drivers/platform/Makefile                     |  2 +
 drivers/platform/profile/Makefile             |  5 ++
 drivers/platform/profile/acpi.c               | 15 +++++
 .../profile/core.c}                           | 64 +++++++++++++------
 drivers/platform/profile/profile.h            | 17 +++++
 drivers/platform/surface/Kconfig              |  6 +-
 drivers/platform/x86/Kconfig                  | 10 +--
 drivers/platform/x86/amd/pmf/Kconfig          |  2 +-
 drivers/platform/x86/dell/Kconfig             |  4 +-
 drivers/platform/x86/hp/Kconfig               |  2 +-
 drivers/platform/x86/lenovo/Kconfig           |  6 +-
 drivers/thermal/intel/int340x_thermal/Kconfig |  2 +-
 16 files changed, 118 insertions(+), 39 deletions(-)
 create mode 100644 drivers/platform/profile/Makefile
 create mode 100644 drivers/platform/profile/acpi.c
 rename drivers/{acpi/platform_profile.c => platform/profile/core.c} (94%)
 create mode 100644 drivers/platform/profile/profile.h
drivers/acpi/Kconfig +0 -3
index f165d14cf61a..dd00312217de 100644
@@ -351,9 +351,6 @@ config ACPI_THERMAL
 	  To compile this driver as a module, choose M here:
 	  the module will be called thermal.
 
-config ACPI_PLATFORM_PROFILE
-	tristate
-
 config ACPI_CUSTOM_DSDT_FILE
 	string "Custom DSDT Table file to include"
 	default ""
drivers/acpi/Makefile +0 -1
index d1b0affb844f..f8af27341805 100644
@@ -91,7 +91,6 @@ obj-$(CONFIG_ACPI_PROCESSOR)	+= processor.o
 obj-$(CONFIG_ACPI)		+= container.o
 obj-$(CONFIG_ACPI_THERMAL_LIB)	+= thermal_lib.o
 obj-$(CONFIG_ACPI_THERMAL)	+= thermal.o
-obj-$(CONFIG_ACPI_PLATFORM_PROFILE) 	+= platform_profile.o
 obj-$(CONFIG_ACPI_NFIT)		+= nfit/
 obj-$(CONFIG_ACPI_NHLT)		+= nhlt.o
 obj-$(CONFIG_ACPI_NUMA)		+= numa/
drivers/cpufreq/Kconfig.x86 +1 -1
index d6190b8dde4b..9e1e3391a084 100644
@@ -39,7 +39,7 @@ config X86_AMD_PSTATE
 	select ACPI_PROCESSOR
 	select ACPI_CPPC_LIB if X86_64
 	select CPU_FREQ_GOV_SCHEDUTIL if SMP
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select POWER_SUPPLY
 	help
 	  This driver adds a CPUFreq driver which utilizes a fine grain
drivers/platform/Kconfig +16 -0
index 312788f249c9..395b75f2edf0 100644
@@ -1,4 +1,20 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config PLATFORM_PROFILE
+	tristate "Platform profile support"
+	help
+	  Provide a common sysfs interface for selecting platform power,
+	  performance and cooling profiles. Platform-specific provider drivers
+	  map their operating modes onto standard profile names, independently
+	  of the firmware interface they use.
+
+	  The core exposes per-provider controls under /sys/class/platform-profile/.
+	  A provider driver must register before profile attributes become
+	  available. ACPI is not required; on ACPI systems the legacy system-wide
+	  interface under /sys/firmware/acpi/ is also provided.
+
+	  To compile this as a module, choose M here: the module will be called
+	  platform_profile.
+
 source "drivers/platform/mips/Kconfig"
 
 source "drivers/platform/loongarch/Kconfig"
drivers/platform/Makefile +2 -0
index fa322e7f8716..b6732f2f3c85 100644
@@ -3,6 +3,8 @@
 # Makefile for linux/drivers/platform
 #
 
+obj-$(CONFIG_PLATFORM_PROFILE)	+= profile/
+
 obj-$(CONFIG_X86)		+= x86/
 obj-$(CONFIG_LOONGARCH)		+= loongarch/
 obj-$(CONFIG_MELLANOX_PLATFORM)	+= mellanox/
drivers/platform/profile/Makefile new file +5 -0
new file mode 100644
index 000000000000..ae95ba09383c
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PLATFORM_PROFILE) += platform_profile.o
+
+platform_profile-y := core.o
+platform_profile-$(CONFIG_ACPI) += acpi.o
drivers/platform/profile/acpi.c new file +15 -0
new file mode 100644
index 000000000000..ff925dedacaf
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Compatibility with the original ACPI platform profile sysfs ABI. */
+
+#include <linux/acpi.h>
+#include <linux/kobject.h>
+
+#include "profile.h"
+
+struct kobject *platform_profile_compat_kobj(void)
+{
+	if (acpi_disabled)
+		return NULL;
+
+	return kobject_get(acpi_kobj);
+}
drivers/platform/profile/core.c renamed from drivers/acpi/platform_profile.c +46 -18

146 lines not on this page · raw message

drivers/platform/profile/profile.h new file +17 -0
new file mode 100644
index 000000000000..910c9f7da6a0
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _PLATFORM_PROFILE_INTERNAL_H
+#define _PLATFORM_PROFILE_INTERNAL_H
+
+#include <linux/kconfig.h>
+#include <linux/kobject.h>
+
+#ifdef CONFIG_ACPI
+struct kobject *platform_profile_compat_kobj(void);
+#else
+static inline struct kobject *platform_profile_compat_kobj(void)
+{
+	return NULL;
+}
+#endif
+
+#endif
drivers/platform/surface/Kconfig +3 -3
index f775c6ca1ec1..08f15f72f8ed 100644
@@ -203,12 +203,12 @@ config SURFACE_PLATFORM_PROFILE
 	tristate "Surface Platform Profile Driver"
 	depends on ACPI
 	depends on SURFACE_AGGREGATOR_REGISTRY
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
-	  Provides support for the ACPI platform profile on 5th- and later
+	  Provides support for platform profiles on 5th- and later
 	  generation Microsoft Surface devices.
 
-	  More specifically, this driver provides ACPI platform profile support
+	  More specifically, this driver provides platform profile support
 	  on Microsoft Surface devices with a Surface System Aggregator Module
 	  (SSAM) connected via the Surface Serial Hub (SSH / SAM-over-SSH). In
 	  other words, this driver provides platform profile support on the
drivers/platform/x86/Kconfig +5 -5
index b54b5212b204..76b42f68c9cc 100644
@@ -120,7 +120,7 @@ config BITLAND_MIFS_WMI
 	depends on INPUT
 	depends on LEDS_CLASS
 	depends on POWER_SUPPLY
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	help
 	  This is a driver for Bitland MiInterface based laptops.
@@ -180,7 +180,7 @@ config ACER_WMI
 	select INPUT_SPARSEKMAP
 	select LEDS_CLASS
 	select NEW_LEDS
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
 	  This is a driver for newer Acer (and Wistron) laptops. It adds
 	  wireless radio and bluetooth control, and on some laptops,
@@ -279,7 +279,7 @@ config ASUS_WMI
 	select INPUT_SPARSEKMAP
 	select LEDS_CLASS
 	select NEW_LEDS
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
 	  Say Y here if you have a WMI aware Asus laptop (like Eee PCs or new
 	  Asus Notebooks).
@@ -646,7 +646,7 @@ config SAMSUNG_GALAXYBOOK
 	depends on INPUT
 	depends on LEDS_CLASS
 	depends on SERIO_I8042
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select FW_ATTR_CLASS
 	help
 	  This is a driver for Samsung Galaxy Book series notebooks. It adds
@@ -906,7 +906,7 @@ config TOUCHSCREEN_DMI
 config INSPUR_PLATFORM_PROFILE
 	tristate "Inspur WMI platform profile driver"
 	depends on ACPI_WMI
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
 	This will allow users to determine and control the platform modes
 	between low-power, balanced and performance modes.
drivers/platform/x86/amd/pmf/Kconfig +1 -1
index 25b8f7ae3abd..a0bdd85db6a0 100644
@@ -8,7 +8,7 @@ config AMD_PMF
 	depends on ACPI && PCI
 	depends on POWER_SUPPLY
 	depends on AMD_NODE
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	depends on TEE && AMDTEE
 	depends on AMD_SFH_HID
 	depends on HAS_IOMEM
drivers/platform/x86/dell/Kconfig +2 -2
index 9f0016056d7e..f6acf1cc2a2f 100644
@@ -44,7 +44,7 @@ config ALIENWARE_WMI_WMAX
 	bool "Alienware WMAX WMI device driver"
 	default y
 	depends on ALIENWARE_WMI
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
 	 Alienware WMI driver with AlienFX LED, HDMI, amplifier, deep sleep and
 	 AWCC thermal control capabilities.
@@ -120,7 +120,7 @@ config DELL_PC
 	depends on ACPI
 	depends on DMI
 	depends on DELL_SMBIOS
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	help
 	This driver adds support for controlling the fan modes via platform_profile
 	on supported Dell systems regardless of formfactor.
drivers/platform/x86/hp/Kconfig +1 -1
index dd51491b9bcd..81a52194ff42 100644
@@ -43,7 +43,7 @@ config HP_WMI
 	depends on RFKILL || RFKILL = n
 	select POWER_SUPPLY
 	select INPUT_SPARSEKMAP
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select HWMON
 	help
 	  Say Y here if you want to support WMI-based hotkeys on HP laptops and
drivers/platform/x86/lenovo/Kconfig +3 -3
index 4443f40ef8aa..c8606ad56139 100644
@@ -12,7 +12,7 @@ config IDEAPAD_LAPTOP
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
 	depends on ACPI_WMI || ACPI_WMI = n
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
 	select LEDS_CLASS
@@ -63,7 +63,7 @@ config THINKPAD_ACPI
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on I2C
 	depends on DRM
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select DRM_PRIVACY_SCREEN
 	select HWMON
 	select NVRAM
@@ -250,7 +250,7 @@ config LENOVO_WMI_GAMEZONE
 	tristate "Lenovo GameZone WMI Driver"
 	depends on ACPI_WMI
 	depends on DMI
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select LENOVO_WMI_EVENTS
 	select LENOVO_WMI_HELPERS
 	help
drivers/thermal/intel/int340x_thermal/Kconfig +1 -1
index 4ced7bdcd62c..3026a0a8d073 100644
@@ -12,7 +12,7 @@ config INT340X_THERMAL
 	select ACPI_THERMAL_LIB
 	select INTEL_SOC_DTS_IOSF_CORE
 	select INTEL_TCC
-	select ACPI_PLATFORM_PROFILE
+	select PLATFORM_PROFILE
 	select PROC_THERMAL_MMIO_RAPL if POWERCAP
 	help
 	  Newer laptops and tablets that use ACPI may have thermal sensors and
Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 3/5 platform profile: Complete class notifications and registration cleanup

In reply to Daniel Lezcano

The class profile attribute documents POLLPRI notifications for changes made through userspace writes as well as changes reported by providers. However, a direct write currently notifies only the legacy ACPI aggregate attribute, leaving listeners on the provider's own profile attribute unaware of the change.

Notify the class device after a successful direct write, using the same helper as aggregate writes and provider-originated notifications. This also makes notifications available when ACPI is absent or disabled.

Restore aggregate attribute visibility after unlinking a handler whose registration failed during a sysfs group update. Keep aggregation exposed only through the existing ACPI interface; the existing class devices provide firmware-independent userspace access.

Assisted-by OpenCode:gpt-6.1-sol
---
 drivers/platform/profile/core.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/platform/profile/core.c +8 -6
index f18fd96b942c..320a5a964fea 100644
@@ -250,6 +250,7 @@ static ssize_t profile_store(struct device *dev,
 		ret = _store_class_profile(dev, &index);
 		if (ret)
 			return ret;
+		_notify_class_profile(dev, NULL);
 	}
 
 	profile_notify();
@@ -324,7 +325,7 @@ static int _remove_hidden_choices(struct device *dev, void *arg)
 }
 
 /**
- * platform_profile_choices_show - Show the available profile choices for legacy sysfs interface
+ * platform_profile_choices_show - Show the aggregate profile choices
  * @kobj: The kobject
  * @attr: The attribute
  * @buf: The buffer to write to
@@ -360,7 +361,7 @@ static ssize_t platform_profile_choices_show(struct kobject *kobj,
 }
 
 /**
- * _aggregate_profiles - Aggregate the profiles for legacy sysfs interface
+ * _aggregate_profiles - Aggregate the profiles across providers
  * @dev: The device
  * @data: The profile to return
  *
@@ -385,7 +386,7 @@ static int _aggregate_profiles(struct device *dev, void *data)
 }
 
 /**
- * _store_and_notify - Store and notify a class from legacy sysfs interface
+ * _store_and_notify - Store and notify a provider from an aggregate write
  * @dev: The device
  * @data: The profile to return
  *
@@ -403,7 +404,7 @@ static int _store_and_notify(struct device *dev, void *data)
 }
 
 /**
- * platform_profile_show - Show the current profile for legacy sysfs interface
+ * platform_profile_show - Show the current aggregate profile
  * @kobj: The kobject
  * @attr: The attribute
  * @buf: The buffer to write to
@@ -431,7 +432,7 @@ static ssize_t platform_profile_show(struct kobject *kobj,
 }
 
 /**
- * platform_profile_store - Set the profile for legacy sysfs interface
+ * platform_profile_store - Set the profile across all providers
  * @kobj: The kobject
  * @attr: The attribute
  * @buf: The buffer to read from
@@ -502,7 +503,7 @@ static int profile_update(void)
 }
 
 /**
- * platform_profile_notify - Notify class device and legacy sysfs interface
+ * platform_profile_notify - Notify the provider and aggregate sysfs interfaces
  * @dev: The class device
  */
 void platform_profile_notify(struct device *dev)
@@ -643,6 +644,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 cleanup_cur:
 	scoped_guard(mutex, &profile_lock)
 		list_del(&to_pprof_handler(ppdev)->node);
+	profile_update();
 	device_unregister(ppdev);
 
 cleanup_ida:
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 4/5 platform profile: Document firmware-independent profile selection

In reply to Daniel Lezcano

Describe the existing per-provider class devices as the firmware-neutral userspace interface. Explain that providers can use any firmware transport or implement profiles in software, without an ACPI companion or firmware node on their parent device.

Retain the ACPI paths as compatibility interfaces for aggregate selection. Clarify that non-ACPI userspace selects individual providers and document the sequential application of aggregate writes and their partial-failure behavior. No new userspace ABI is introduced.

Correct the per-provider choices attribute reference and extend existing ACPI maintainer coverage to the extracted core and its interfaces.

Assisted-by OpenCode:gpt-6.1-sol
---
 .../ABI/testing/sysfs-class-platform-profile  |  2 +-
 .../userspace-api/sysfs-platform_profile.rst  | 46 ++++++++++++++-----
 MAINTAINERS                                   |  5 ++
 include/linux/platform_profile.h              |  3 ++
 4 files changed, 43 insertions(+), 13 deletions(-)
Documentation/ABI/testing/sysfs-class-platform-profile +1 -1
index fcab26894ec3..75e0f6e2c128 100644
@@ -35,7 +35,7 @@ Date:		March 2025
 KernelVersion:	6.14
 Description:	Reading this file gives the current selected profile for this
 		device. Writing this file with one of the strings from
-		platform_profile_choices changes the profile to the new value.
+		choices changes the profile to the new value.
 
 		This file can be monitored for changes by polling for POLLPRI,
 		POLLPRI will be signaled on any changes, independent of those
Documentation/userspace-api/sysfs-platform_profile.rst +34 -12

69 lines not on this page · raw message

MAINTAINERS +5 -0
index 8014b9f8253e..929e1e095f17 100644
@@ -285,10 +285,14 @@ B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
 F:	Documentation/ABI/testing/configfs-acpi
 F:	Documentation/ABI/testing/sysfs-bus-acpi
+F:	Documentation/ABI/testing/sysfs-class-platform-profile
+F:	Documentation/ABI/testing/sysfs-platform_profile
 F:	Documentation/firmware-guide/acpi/
+F:	Documentation/userspace-api/sysfs-platform_profile.rst
 F:	arch/x86/kernel/acpi/
 F:	arch/x86/pci/acpi.c
 F:	drivers/acpi/
+F:	drivers/platform/profile/
 F:	drivers/pci/*/*acpi*
 F:	drivers/pci/*acpi*
 F:	drivers/pnp/pnpacpi/
@@ -296,6 +300,7 @@ F:	include/acpi/
 F:	include/linux/acpi.h
 F:	include/linux/fwnode.h
 F:	include/linux/fw_table.h
+F:	include/linux/platform_profile.h
 F:	lib/fw_table.c
 F:	rust/helpers/acpi.c
 F:	rust/kernel/acpi.rs
include/linux/platform_profile.h +3 -0
index 855b28340e95..f23f9827eac6 100644
@@ -2,6 +2,9 @@
 /*
  * Platform profile sysfs interface
  *
+ * Providers may use any firmware interface or implement profiles in software.
+ * The parent device does not need an ACPI companion or a firmware node.
+ *
  * See Documentation/userspace-api/sysfs-platform_profile.rst for more
  * information.
  */
Signature · 1 line
2.43.0
#7 lore raw

PATCH v2 5/5 platform profile: Make legacy ACPI aggregate interface optional

In reply to Daniel Lezcano

The aggregate attributes under /sys/firmware/acpi/ are retained for backwards compatibility. Firmware-independent userspace can already discover providers through /sys/class/platform-profile/ and control each provider using its choices and profile attributes.

Add PLATFORM_PROFILE_LEGACY, a boolean depending on PLATFORM_PROFILE and ACPI, to control the legacy aggregate sysfs interface. Default it to y so existing userspace continues to work when updating its configuration.

Compile the ACPI adapter and legacy sysfs callbacks only when the option is enabled. Keep common aggregation helpers in the core because kernel hotkey users still need platform_profile_cycle(). Class devices and their notifications remain available regardless of the legacy option.

Document the compatibility option and recommend individual class devices for new userspace. No daemon changes are included in this kernel series. Move the legacy ABI documentation to obsolete/, retain its original creation dates and attribute descriptions, identify the replacement class attributes, and update its MAINTAINERS entry.

Mark the legacy ABI deprecated and document removal after the 2028 LTS kernel, conditional on userspace migration. Keep the enabled default until class-device support has been released and deployed in userspace. Emit one shared pr_notice_once() when either legacy attribute is read or the profile is written, identifying actual legacy use rather than warning merely because the compatibility code was loaded.

Validate ARM64 without ACPI and x86 module builds with the option enabled and disabled. With ACPI active and the option disabled, QEMU tests confirm that the legacy attributes are absent while class controls, notifications, kernel cycling and concurrent registration/removal continue to work.

Assisted-by OpenCode:gpt-6.1-sol
---
 .../{testing => obsolete}/sysfs-platform_profile   | 12 ++++
 .../userspace-api/sysfs-platform_profile.rst       | 17 +++--
 MAINTAINERS                                        |  2 +-
 drivers/platform/Kconfig                           | 23 ++++++-
 drivers/platform/profile/Makefile                  |  2 +-
 drivers/platform/profile/core.c                    | 72 ++++++++++++++++++----
 drivers/platform/profile/profile.h                 |  2 +-
 7 files changed, 109 insertions(+), 21 deletions(-)
Documentation/ABI/obsolete/sysfs-platform_profile renamed from Documentation/ABI/testing/sysfs-platform_profile +12 -0
similarity index 70%
rename from Documentation/ABI/testing/sysfs-platform_profile
rename to Documentation/ABI/obsolete/sysfs-platform_profile
index 125324ab53a9..c001c8641a3a 100644
@@ -2,6 +2,12 @@ What:		/sys/firmware/acpi/platform_profile_choices
 Date:		October 2020
 Contact:	Hans de Goede <[email protected]>
 Description:	This file contains a space-separated list of profiles supported for this device.
+		Available with CONFIG_PLATFORM_PROFILE_LEGACY on active ACPI
+		systems for backwards compatibility. New userspace should use
+		/sys/class/platform-profile/platform-profile-X/choices instead.
+		This interface is deprecated, with removal intended after the
+		2028 LTS kernel once userspace migration is complete. Accessing
+		either legacy attribute emits a one-time deprecation notice.
 
 		Drivers must use the following standard profile-names:
 
@@ -27,6 +33,12 @@ Description:	Reading this file gives the current selected profile for this
 		device. Writing this file with one of the strings from
 		platform_profile_choices changes the profile to the new value.
 
+		This legacy interface requires CONFIG_PLATFORM_PROFILE_LEGACY.
+		Individual class devices remain available without that option.
+		Use /sys/class/platform-profile/platform-profile-X/profile
+		instead. This interface is deprecated, with removal intended
+		after the 2028 LTS kernel once userspace migration is complete.
+
 		This file can be monitored for changes by polling for POLLPRI,
 		POLLPRI will be signalled on any changes, independent of those
 		changes coming from a userspace write; or coming from another
Documentation/userspace-api/sysfs-platform_profile.rst +13 -4
index a85ede3fb8e5..a3fc1ee20832 100644
@@ -26,11 +26,20 @@ The firmware-independent userspace interface is available under
 ``/sys/class/platform-profile/platform-profile-X/``, with ``name``,
 ``choices`` and ``profile`` attributes for each registered provider.
 
-On ACPI systems, ``/sys/firmware/acpi/platform_profile_choices`` and
+On ACPI systems with ``CONFIG_PLATFORM_PROFILE_LEGACY`` enabled,
+``/sys/firmware/acpi/platform_profile_choices`` and
 ``/sys/firmware/acpi/platform_profile`` remain available as compatibility
 interfaces for aggregate profile selection across registered providers.
-On non-ACPI systems, userspace selects profiles through the individual
-provider class devices.
+New userspace should select profiles through the individual provider class
+devices. These remain available when the legacy interface is disabled and
+on non-ACPI systems. Kernel profile cycling also remains available without
+the legacy interface.
+
+The legacy aggregate interface is deprecated. Removal is intended after the
+2028 LTS kernel, once userspace has migrated to released software using the
+class devices. Compatibility remains enabled by default during the migration;
+the date alone does not trigger removal. Accessing either legacy attribute
+emits a one-time kernel notice directing userspace to the class interface.
 
 Note that this API is only for selecting the platform profile, it is
 NOT a goal of this API to allow monitoring the resulting performance
@@ -70,7 +79,7 @@ Multiple driver support
 When multiple drivers on a system advertise a platform profile handler, the
 platform profile handler core will only advertise the profiles that are
 common between all drivers to the ``/sys/firmware/acpi`` interfaces, when
-ACPI is active.
+ACPI is active and ``CONFIG_PLATFORM_PROFILE_LEGACY`` is enabled.
 
 This is to ensure there is no ambiguity on what the profile names mean when
 all handlers don't support a profile.
MAINTAINERS +1 -1
index 929e1e095f17..47b7724f20ea 100644
@@ -283,10 +283,10 @@ S:	Supported
 Q:	https://patchwork.kernel.org/project/linux-acpi/list/
 B:	https://bugzilla.kernel.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
+F:	Documentation/ABI/obsolete/sysfs-platform_profile
 F:	Documentation/ABI/testing/configfs-acpi
 F:	Documentation/ABI/testing/sysfs-bus-acpi
 F:	Documentation/ABI/testing/sysfs-class-platform-profile
-F:	Documentation/ABI/testing/sysfs-platform_profile
 F:	Documentation/firmware-guide/acpi/
 F:	Documentation/userspace-api/sysfs-platform_profile.rst
 F:	arch/x86/kernel/acpi/
drivers/platform/Kconfig +21 -2
index 395b75f2edf0..7270f24a3b6e 100644
@@ -9,12 +9,31 @@ config PLATFORM_PROFILE
 
 	  The core exposes per-provider controls under /sys/class/platform-profile/.
 	  A provider driver must register before profile attributes become
-	  available. ACPI is not required; on ACPI systems the legacy system-wide
-	  interface under /sys/firmware/acpi/ is also provided.
+	  available. ACPI is not required. The legacy system-wide interface under
+	  /sys/firmware/acpi/ can be enabled separately for existing userspace.
 
 	  To compile this as a module, choose M here: the module will be called
 	  platform_profile.
 
+config PLATFORM_PROFILE_LEGACY
+	bool "Legacy ACPI platform profile sysfs interface (DEPRECATED)"
+	depends on PLATFORM_PROFILE && ACPI
+	default y
+	help
+	  Expose platform_profile and platform_profile_choices under
+	  /sys/firmware/acpi/ for compatibility with existing userspace. These
+	  attributes aggregate the profiles of all registered providers.
+
+	  This interface is deprecated and is intended for removal after the
+	  2028 LTS kernel, once userspace has migrated to the class interface.
+	  It remains enabled by default until replacement userspace releases
+	  are available and have had time to reach users.
+
+	  New userspace should use the individual devices under
+	  /sys/class/platform-profile/ instead. Disabling this option removes
+	  the legacy sysfs interface but retains class devices and kernel
+	  profile cycling. If unsure, say Y to preserve compatibility.
+
 source "drivers/platform/mips/Kconfig"
 
 source "drivers/platform/loongarch/Kconfig"
drivers/platform/profile/Makefile +1 -1
index ae95ba09383c..787fc9bc961a 100644
@@ -2,4 +2,4 @@
 obj-$(CONFIG_PLATFORM_PROFILE) += platform_profile.o
 
 platform_profile-y := core.o
-platform_profile-$(CONFIG_ACPI) += acpi.o
+platform_profile-$(CONFIG_PLATFORM_PROFILE_LEGACY) += acpi.o
drivers/platform/profile/core.c +60 -12

138 lines not on this page · raw message

drivers/platform/profile/profile.h +1 -1
index 910c9f7da6a0..362eb8cc4592 100644
@@ -5,7 +5,7 @@
 #include <linux/kconfig.h>
 #include <linux/kobject.h>
 
-#ifdef CONFIG_ACPI
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
 struct kobject *platform_profile_compat_kobj(void);
 #else
 static inline struct kobject *platform_profile_compat_kobj(void)
maintainer
#2 lore raw

Re: [PATCH v2 1/5] platform profile: Separate handler locking from sysfs lifetime

In reply to Daniel Lezcano
Quoted 81 lines · Daniel Lezcano

Registration and removal currently hold profile_lock across device_unregister() and sysfs_update_group(). These operations can remove sysfs attributes and wait for their active callbacks to finish. The profile read and write callbacks acquire profile_lock themselves, so a concurrent access can deadlock:

  Removal/update path             Active sysfs callback
  -------------------             ---------------------
  acquire profile_lock            hold kernfs active reference

remove a sysfs attribute wait for profile_lock
wait for its active references

The removal path cannot finish until the callback returns, and the callback cannot return until the removal path releases profile_lock. This applies both to per-provider device teardown and to updates of the legacy aggregate attribute group.

Commit 041142d7d252 ("ACPI: platform-profile: Fix possible deadlock in platform_profile_remove()") previously fixed this lock ordering by moving sysfs_remove_group() outside profile_lock. Commit 55b1e68134bf ("ACPI:
platform_profile: Use guard(mutex) for register/unregister") reintroduced the issue by extending the mutex guard over sysfs_remove_group(). Later, commit 77be5cacb2c2 ("ACPI: platform_profile: Create class for ACPI platform profile") replaced that teardown with device_unregister() and sysfs_update_group(), still under the same mutex, extending the problem to class-device teardown and aggregate attribute updates.

Simply dropping profile_lock around these operations is insufficient. Aggregate operations currently discover providers through the class device list. A provider being unregistered could therefore still be selected for an aggregate read, write or cycle while its sysfs files are being torn down. Concurrent registrations and removals would also race when updating aggregate attribute visibility.

Introduce profile_registration_lock to serialize registration, removal and aggregate sysfs updates. Sysfs callbacks never acquire this mutex. Retain profile_lock for profile operations and use it to protect an explicit list of handlers participating in the aggregate interface.

Add a handler to that list only after device_register() succeeds. On removal, unlink it under profile_lock before calling device_unregister(). Acquiring profile_lock first waits for any aggregate operation already using the handler to complete; unlinking prevents later aggregate operations from finding it. Release profile_lock before draining sysfs callbacks, allowing active per-provider callbacks to complete before the device is released. Apply the same unlink-before-unregister ordering to registration error cleanup.

Walk this list for aggregate reads, writes and profile cycling, and use its emptiness to determine aggregate attribute visibility. The class devices remain the per-provider userspace interface.

There can now be an interval between removing the last handler from the list and removing the aggregate attributes. Explicitly reject choices reads and writes during that interval: the intersection bitmap starts with every bit set, so an empty traversal must not advertise all profiles or report a successful write without updating a provider.

This separates aggregate membership from class device teardown while preserving the existing class and ACPI sysfs interfaces.

Fixes 55b1e68134bf ("ACPI: platform_profile: Use guard(mutex) for register/unregister")
Assisted-by OpenCode:gpt-6.1-sol
---
 drivers/acpi/platform_profile.c | 75 ++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 33 deletions(-)
drivers/acpi/platform_profile.c +1 -0
index 79d2e92e5c28..f98ce4cda02c 100644
@@ -8,6 +8,7 @@
 #include <linux/bits.h>
 #include <linux/cleanup.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/platform_profile.h>
 #include <linux/sysfs.h>

drivers/acpi/platform_profile.c line 18

Quoted 3 lines
drivers/acpi/platform_profile.c +0 -0
@@ -15,8 +16,12 @@
 #define to_pprof_handler(d)	(container_of(d, struct platform_profile_handler, dev))
 
 static DEFINE_MUTEX(profile_lock);

Should definitely add comment to this lock as well to explain what it protects.

Quoted 3 lines
drivers/acpi/platform_profile.c +3 -0
+/* Serialize registration and sysfs updates without blocking sysfs callbacks. */
+static DEFINE_MUTEX(profile_registration_lock);
+static LIST_HEAD(profile_handlers);
Signature · 1 line
 i.
Quoted 176 lines
drivers/acpi/platform_profile.c +38 -33
 struct platform_profile_handler {
+	struct list_head node;
 	const char *name;
 	struct device dev;
 	int minor;
@@ -44,6 +49,22 @@ static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST);
 
 static DEFINE_IDA(platform_profile_ida);
 
+static int profile_walk_handlers(void *data,
+				 int (*fn)(struct device *dev, void *data))
+{
+	struct platform_profile_handler *handler;
+	int ret;
+
+	lockdep_assert_held(&profile_lock);
+	list_for_each_entry(handler, &profile_handlers, node) {
+		ret = fn(&handler->dev, data);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 /**
  * _commmon_choices_show - Show the available profile choices
  * @choices: The available profile choices
@@ -306,20 +327,18 @@ static ssize_t platform_profile_choices_show(struct kobject *kobj,
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		err = profile_walk_handlers(&data, _aggregate_choices);
 		if (err)
 			return err;
 		if (data.count == 1) {
-			err = class_for_each_device(&platform_profile_class, NULL,
-						    &data, _remove_hidden_choices);
+			err = profile_walk_handlers(&data, _remove_hidden_choices);
 			if (err)
 				return err;
 		}
 	}
 
 	/* no profile handler registered any more */
-	if (bitmap_empty(data.aggregate, PLATFORM_PROFILE_LAST))
+	if (!data.count || bitmap_empty(data.aggregate, PLATFORM_PROFILE_LAST))
 		return -EINVAL;
 
 	return _commmon_choices_show(data.aggregate, buf);
@@ -384,8 +403,7 @@ static ssize_t platform_profile_show(struct kobject *kobj,
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &profile, _aggregate_profiles);
+		err = profile_walk_handlers(&profile, _aggregate_profiles);
 		if (err)
 			return err;
 	}
@@ -423,15 +441,13 @@ static ssize_t platform_profile_store(struct kobject *kobj,
 		return -EINVAL;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		ret = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		ret = profile_walk_handlers(&data, _aggregate_choices);
 		if (ret)
 			return ret;
-		if (!test_bit(i, data.aggregate))
+		if (!data.count || !test_bit(i, data.aggregate))
 			return -EOPNOTSUPP;
 
-		ret = class_for_each_device(&platform_profile_class, NULL, &i,
-					    _store_and_notify);
+		ret = profile_walk_handlers(&i, _store_and_notify);
 		if (ret)
 			return ret;
 	}
@@ -450,22 +466,11 @@ static struct attribute *platform_profile_attrs[] = {
 	NULL
 };
 
-static int profile_class_registered(struct device *dev, const void *data)
-{
-	return 1;
-}
-
 static umode_t profile_class_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
 {
-	struct device *dev;
-
-	dev = class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered);
-	if (!dev)
-		return 0;
-
-	put_device(dev);
+	guard(mutex)(&profile_lock);
 
-	return attr->mode;
+	return list_empty(&profile_handlers) ? 0 : attr->mode;
 }
 
 static const struct attribute_group platform_profile_group = {
@@ -502,8 +507,7 @@ int platform_profile_cycle(void)
 	int err;
 
 	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &profile, _aggregate_profiles);
+		err = profile_walk_handlers(&profile, _aggregate_profiles);
 		if (err)
 			return err;
 
@@ -512,8 +516,7 @@ int platform_profile_cycle(void)
 		    profile == PLATFORM_PROFILE_LAST)
 			return -EINVAL;
 
-		err = class_for_each_device(&platform_profile_class, NULL,
-					    &data, _aggregate_choices);
+		err = profile_walk_handlers(&data, _aggregate_choices);
 		if (err)
 			return err;
 
@@ -525,8 +528,7 @@ int platform_profile_cycle(void)
 					  PLATFORM_PROFILE_LAST,
 					  profile + 1);
 
-		err = class_for_each_device(&platform_profile_class, NULL, &next,
-					    _store_and_notify);
+		err = profile_walk_handlers(&next, _store_and_notify);
 
 		if (err)
 			return err;
@@ -583,7 +585,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 		}
 	}
 
-	guard(mutex)(&profile_lock);
+	guard(mutex)(&profile_registration_lock);
 
 	/* create class interface for individual handler */
 	minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
@@ -604,6 +606,8 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 		put_device(ppdev);
 		goto cleanup_ida;
 	}
+	scoped_guard(mutex, &profile_lock)
+		list_add_tail(&to_pprof_handler(ppdev)->node, &profile_handlers);
 
 	sysfs_notify(acpi_kobj, NULL, "platform_profile");
 
@@ -614,6 +618,8 @@ struct device *platform_profile_register(struct device *dev, const char *name,
 	return ppdev;
 
 cleanup_cur:
+	scoped_guard(mutex, &profile_lock)
+		list_del(&to_pprof_handler(ppdev)->node);
 	device_unregister(ppdev);
 
 cleanup_ida:
@@ -636,7 +642,10 @@ void platform_profile_remove(struct device *dev)
 
 	pprof = to_pprof_handler(dev);
 
-	guard(mutex)(&profile_lock);
+	guard(mutex)(&profile_registration_lock);
+
+	scoped_guard(mutex, &profile_lock)
+		list_del(&pprof->node);
 
 	ida_free(&platform_profile_ida, pprof->minor);
 	device_unregister(&pprof->dev);
#3 lore raw

Re: [PATCH v2 1/5] platform profile: Separate handler locking from sysfs lifetime

Quoted 86 lines · Ilpo Järvinen
Quoted 83 lines · Daniel Lezcano

Registration and removal currently hold profile_lock across device_unregister() and sysfs_update_group(). These operations can remove sysfs attributes and wait for their active callbacks to finish. The profile read and write callbacks acquire profile_lock themselves, so a concurrent access can deadlock:

  Removal/update path             Active sysfs callback
  -------------------             ---------------------
  acquire profile_lock            hold kernfs active reference

remove a sysfs attribute wait for profile_lock
wait for its active references

The removal path cannot finish until the callback returns, and the callback cannot return until the removal path releases profile_lock. This applies both to per-provider device teardown and to updates of the legacy aggregate attribute group.

Commit 041142d7d252 ("ACPI: platform-profile: Fix possible deadlock in platform_profile_remove()") previously fixed this lock ordering by moving sysfs_remove_group() outside profile_lock. Commit 55b1e68134bf ("ACPI:
platform_profile: Use guard(mutex) for register/unregister") reintroduced the issue by extending the mutex guard over sysfs_remove_group(). Later, commit 77be5cacb2c2 ("ACPI: platform_profile: Create class for ACPI platform profile") replaced that teardown with device_unregister() and sysfs_update_group(), still under the same mutex, extending the problem to class-device teardown and aggregate attribute updates.

Simply dropping profile_lock around these operations is insufficient. Aggregate operations currently discover providers through the class device list. A provider being unregistered could therefore still be selected for an aggregate read, write or cycle while its sysfs files are being torn down. Concurrent registrations and removals would also race when updating aggregate attribute visibility.

Introduce profile_registration_lock to serialize registration, removal and aggregate sysfs updates. Sysfs callbacks never acquire this mutex. Retain profile_lock for profile operations and use it to protect an explicit list of handlers participating in the aggregate interface.

Add a handler to that list only after device_register() succeeds. On removal, unlink it under profile_lock before calling device_unregister(). Acquiring profile_lock first waits for any aggregate operation already using the handler to complete; unlinking prevents later aggregate operations from finding it. Release profile_lock before draining sysfs callbacks, allowing active per-provider callbacks to complete before the device is released. Apply the same unlink-before-unregister ordering to registration error cleanup.

Walk this list for aggregate reads, writes and profile cycling, and use its emptiness to determine aggregate attribute visibility. The class devices remain the per-provider userspace interface.

There can now be an interval between removing the last handler from the list and removing the aggregate attributes. Explicitly reject choices reads and writes during that interval: the intersection bitmap starts with every bit set, so an empty traversal must not advertise all profiles or report a successful write without updating a provider.

This separates aggregate membership from class device teardown while preserving the existing class and ACPI sysfs interfaces.

Fixes 55b1e68134bf ("ACPI: platform_profile: Use guard(mutex) for register/unregister")
Assisted-by OpenCode:gpt-6.1-sol
---
 drivers/acpi/platform_profile.c | 75 ++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 33 deletions(-)
drivers/acpi/platform_profile.c +1 -0
index 79d2e92e5c28..f98ce4cda02c 100644
@@ -8,6 +8,7 @@
 #include <linux/bits.h>
 #include <linux/cleanup.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/platform_profile.h>
 #include <linux/sysfs.h>
@@ -15,8 +16,12 @@
 #define to_pprof_handler(d)  (container_of(d, struct platform_profile_handler, dev))
 
Quoted 4 lines

drivers/acpi/platform_profile.c line 18

Quoted 1 line
drivers/acpi/platform_profile.c +0 -0
 static DEFINE_MUTEX(profile_lock);

Should definitely add comment to this lock as well to explain what it protects.

+1

Quoted 3 lines

drivers/acpi/platform_profile.c line 21

Quoted 3 lines
drivers/acpi/platform_profile.c +3 -0
+/* Serialize registration and sysfs updates without blocking sysfs callbacks. */
+static DEFINE_MUTEX(profile_registration_lock);
+static LIST_HEAD(profile_handlers);

Also, I think that the rest of the series is not going to get into 7.4 in any shape or form, so my suggestion would be to address the above and send a new version of the $subject patch as a separate fix, and defer the other patches in the series until 7.4-rc1 is out.

#8 lore raw

Re: [PATCH v2 5/5] platform profile: Make legacy ACPI aggregate interface optional

In reply to Daniel Lezcano
Quoted 52 lines · Daniel Lezcano

The aggregate attributes under /sys/firmware/acpi/ are retained for backwards compatibility. Firmware-independent userspace can already discover providers through /sys/class/platform-profile/ and control each provider using its choices and profile attributes.

Add PLATFORM_PROFILE_LEGACY, a boolean depending on PLATFORM_PROFILE and ACPI, to control the legacy aggregate sysfs interface. Default it to y so existing userspace continues to work when updating its configuration.

Compile the ACPI adapter and legacy sysfs callbacks only when the option is enabled. Keep common aggregation helpers in the core because kernel hotkey users still need platform_profile_cycle(). Class devices and their notifications remain available regardless of the legacy option.

Document the compatibility option and recommend individual class devices for new userspace. No daemon changes are included in this kernel series. Move the legacy ABI documentation to obsolete/, retain its original creation dates and attribute descriptions, identify the replacement class attributes, and update its MAINTAINERS entry.

Mark the legacy ABI deprecated and document removal after the 2028 LTS kernel, conditional on userspace migration. Keep the enabled default until class-device support has been released and deployed in userspace. Emit one shared pr_notice_once() when either legacy attribute is read or the profile is written, identifying actual legacy use rather than warning merely because the compatibility code was loaded.

Validate ARM64 without ACPI and x86 module builds with the option enabled and disabled. With ACPI active and the option disabled, QEMU tests confirm that the legacy attributes are absent while class controls, notifications, kernel cycling and concurrent registration/removal continue to work.

Assisted-by OpenCode:gpt-6.1-sol
---
  .../{testing => obsolete}/sysfs-platform_profile   | 12 ++++
  .../userspace-api/sysfs-platform_profile.rst       | 17 +++--
  MAINTAINERS                                        |  2 +-
  drivers/platform/Kconfig                           | 23 ++++++-
  drivers/platform/profile/Makefile                  |  2 +-
  drivers/platform/profile/core.c                    | 72 ++++++++++++++++++----
  drivers/platform/profile/profile.h                 |  2 +-
  7 files changed, 109 insertions(+), 21 deletions(-)
Documentation/ABI/obsolete/sysfs-platform_profile renamed from Documentation/ABI/testing/sysfs-platform_profile +0 -0
similarity index 70%
rename from Documentation/ABI/testing/sysfs-platform_profile
rename to Documentation/ABI/obsolete/sysfs-platform_profile
index 125324ab53a9..c001c8641a3a 100644

Documentation/ABI/obsolete/sysfs-platform_profile What: /sys/firmware/acpi/platform_profile_choices · line 6

Quoted 5 lines
Documentation/ABI/obsolete/sysfs-platform_profile renamed from Documentation/ABI/testing/sysfs-platform_profile +2 -0
@@ -2,6 +2,12 @@ What:		/sys/firmware/acpi/platform_profile_choices
  Date:		October 2020
  Contact:	Hans de Goede <[email protected]>
  Description:	This file contains a space-separated list of profiles supported for this device.
+		Available with CONFIG_PLATFORM_PROFILE_LEGACY on active ACPI
+		systems for backwards compatibility. New userspace should use

I don't think "new" vs old is a good distinction for documentation.

Just say "Userspace should use"

Quoted 26 lines
Documentation/ABI/obsolete/sysfs-platform_profile renamed from Documentation/ABI/testing/sysfs-platform_profile +10 -0
+		/sys/class/platform-profile/platform-profile-X/choices instead.
+		This interface is deprecated, with removal intended after the
+		2028 LTS kernel once userspace migration is complete. Accessing
+		either legacy attribute emits a one-time deprecation notice.
 
  		Drivers must use the following standard profile-names:
 
@@ -27,6 +33,12 @@ Description:	Reading this file gives the current selected profile for this
  		device. Writing this file with one of the strings from
  		platform_profile_choices changes the profile to the new value.
 
+		This legacy interface requires CONFIG_PLATFORM_PROFILE_LEGACY.
+		Individual class devices remain available without that option.
+		Use /sys/class/platform-profile/platform-profile-X/profile
+		instead. This interface is deprecated, with removal intended
+		after the 2028 LTS kernel once userspace migration is complete.
+
  		This file can be monitored for changes by polling for POLLPRI,
  		POLLPRI will be signalled on any changes, independent of those
  		changes coming from a userspace write; or coming from another
Documentation/userspace-api/sysfs-platform_profile.rst +0 -0
index a85ede3fb8e5..a3fc1ee20832 100644
@@ -26,11 +26,20 @@ The firmware-independent userspace interface is available under
  ``/sys/class/platform-profile/platform-profile-X/``, with ``name``,

Documentation/userspace-api/sysfs-platform_profile.rst The firmware-independent userspace interface is available under · line 33

Quoted 10 lines
Documentation/userspace-api/sysfs-platform_profile.rst +3 -3
  ``choices`` and ``profile`` attributes for each registered provider.
 
-On ACPI systems, ``/sys/firmware/acpi/platform_profile_choices`` and
+On ACPI systems with ``CONFIG_PLATFORM_PROFILE_LEGACY`` enabled,
+``/sys/firmware/acpi/platform_profile_choices`` and
  ``/sys/firmware/acpi/platform_profile`` remain available as compatibility
  interfaces for aggregate profile selection across registered providers.
-On non-ACPI systems, userspace selects profiles through the individual
-provider class devices.
+New userspace should select profiles through the individual provider class

Similar comment.> +devices. These remain available when the legacy interface is disabled and

Quoted 106 lines
Documentation/userspace-api/sysfs-platform_profile.rst +9 -1
+on non-ACPI systems. Kernel profile cycling also remains available without
+the legacy interface.
+
+The legacy aggregate interface is deprecated. Removal is intended after the
+2028 LTS kernel, once userspace has migrated to released software using the
+class devices. Compatibility remains enabled by default during the migration;
+the date alone does not trigger removal. Accessing either legacy attribute
+emits a one-time kernel notice directing userspace to the class interface.
 
  Note that this API is only for selecting the platform profile, it is
  NOT a goal of this API to allow monitoring the resulting performance
@@ -70,7 +79,7 @@ Multiple driver support
  When multiple drivers on a system advertise a platform profile handler, the
  platform profile handler core will only advertise the profiles that are
  common between all drivers to the ``/sys/firmware/acpi`` interfaces, when
-ACPI is active.
+ACPI is active and ``CONFIG_PLATFORM_PROFILE_LEGACY`` is enabled.
 
  This is to ensure there is no ambiguity on what the profile names mean when
  all handlers don't support a profile.
MAINTAINERS +1 -1
index 929e1e095f17..47b7724f20ea 100644
@@ -283,10 +283,10 @@ S:	Supported
  Q:	https://patchwork.kernel.org/project/linux-acpi/list/
  B:	https://bugzilla.kernel.org
  T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
+F:	Documentation/ABI/obsolete/sysfs-platform_profile
  F:	Documentation/ABI/testing/configfs-acpi
  F:	Documentation/ABI/testing/sysfs-bus-acpi
  F:	Documentation/ABI/testing/sysfs-class-platform-profile
-F:	Documentation/ABI/testing/sysfs-platform_profile
  F:	Documentation/firmware-guide/acpi/
  F:	Documentation/userspace-api/sysfs-platform_profile.rst
  F:	arch/x86/kernel/acpi/
drivers/platform/Kconfig +21 -2
index 395b75f2edf0..7270f24a3b6e 100644
@@ -9,12 +9,31 @@ config PLATFORM_PROFILE
 
  	  The core exposes per-provider controls under /sys/class/platform-profile/.
  	  A provider driver must register before profile attributes become
-	  available. ACPI is not required; on ACPI systems the legacy system-wide
-	  interface under /sys/firmware/acpi/ is also provided.
+	  available. ACPI is not required. The legacy system-wide interface under
+	  /sys/firmware/acpi/ can be enabled separately for existing userspace.
 
  	  To compile this as a module, choose M here: the module will be called
  	  platform_profile.
 
+config PLATFORM_PROFILE_LEGACY
+	bool "Legacy ACPI platform profile sysfs interface (DEPRECATED)"
+	depends on PLATFORM_PROFILE && ACPI
+	default y
+	help
+	  Expose platform_profile and platform_profile_choices under
+	  /sys/firmware/acpi/ for compatibility with existing userspace. These
+	  attributes aggregate the profiles of all registered providers.
+
+	  This interface is deprecated and is intended for removal after the
+	  2028 LTS kernel, once userspace has migrated to the class interface.
+	  It remains enabled by default until replacement userspace releases
+	  are available and have had time to reach users.
+
+	  New userspace should use the individual devices under
+	  /sys/class/platform-profile/ instead. Disabling this option removes
+	  the legacy sysfs interface but retains class devices and kernel
+	  profile cycling. If unsure, say Y to preserve compatibility.
+
  source "drivers/platform/mips/Kconfig"
 
  source "drivers/platform/loongarch/Kconfig"
drivers/platform/profile/Makefile +1 -1
index ae95ba09383c..787fc9bc961a 100644
@@ -2,4 +2,4 @@
  obj-$(CONFIG_PLATFORM_PROFILE) += platform_profile.o
 
  platform_profile-y := core.o
-platform_profile-$(CONFIG_ACPI) += acpi.o
+platform_profile-$(CONFIG_PLATFORM_PROFILE_LEGACY) += acpi.o
drivers/platform/profile/core.c +4 -0
index 320a5a964fea..1bffca947157 100644
@@ -25,12 +25,16 @@ static DEFINE_MUTEX(profile_lock);
  /* Serialize registration and sysfs updates without blocking sysfs callbacks. */
  static DEFINE_MUTEX(profile_registration_lock);
  static LIST_HEAD(profile_handlers);
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
  static struct kobject *compat_kobj;
+#endif
 
  static void profile_notify(void)
  {
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
  	if (compat_kobj)
  		sysfs_notify(compat_kobj, NULL, "platform_profile");
+#endif
  }
 
  static int profile_update(void);

drivers/platform/profile/core.c static int _aggregate_choices(struct device *dev, void *arg) · line 314

Quoted 7 lines
drivers/platform/profile/core.c +4 -0
@@ -304,6 +308,12 @@ static int _aggregate_choices(struct device *dev, void *arg)
  	return 0;
  }
 
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
+static void profile_legacy_notice(void)
+{
+	pr_notice_once("The ACPI platform_profile sysfs interface is deprecated and planned for removal after the 2028 LTS kernel once userspace has migrated; use /sys/class/platform-profile/ instead\n");

I would just leave userspace out. Maybe just:

"The ACPI platform_profile sysfs interface is deprecated with a planned removal in 2028".

Quoted 135 lines
drivers/platform/profile/core.c +52 -12
+}
+
  /**
   * _remove_hidden_choices - Remove hidden choices from aggregate data
   * @dev: The device
@@ -342,6 +352,8 @@ static ssize_t platform_profile_choices_show(struct kobject *kobj,
  	};
  	int err;
 
+	profile_legacy_notice();
+
  	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  		err = profile_walk_handlers(&data, _aggregate_choices);
  		if (err)
@@ -359,6 +371,7 @@ static ssize_t platform_profile_choices_show(struct kobject *kobj,
 
  	return _commmon_choices_show(data.aggregate, buf);
  }
+#endif
 
  /**
   * _aggregate_profiles - Aggregate the profiles across providers
@@ -403,6 +416,7 @@ static int _store_and_notify(struct device *dev, void *data)
  	return _notify_class_profile(dev, NULL);
  }
 
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
  /**
   * platform_profile_show - Show the current aggregate profile
   * @kobj: The kobject
@@ -418,6 +432,8 @@ static ssize_t platform_profile_show(struct kobject *kobj,
  	enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
  	int err;
 
+	profile_legacy_notice();
+
  	scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  		err = profile_walk_handlers(&profile, _aggregate_profiles);
  		if (err)
@@ -451,6 +467,8 @@ static ssize_t platform_profile_store(struct kobject *kobj,
  	int ret;
  	int i;
 
+	profile_legacy_notice();
+
  	/* Scan for a matching profile */
  	i = sysfs_match_string(profile_names, buf);
  	if (i < 0 || i == PLATFORM_PROFILE_CUSTOM)
@@ -502,6 +520,44 @@ static int profile_update(void)
  	return 0;
  }
 
+static int profile_compat_init(void)
+{
+	int err;
+
+	compat_kobj = platform_profile_compat_kobj();
+	if (!compat_kobj)
+		return 0;
+
+	err = sysfs_create_group(compat_kobj, &platform_profile_group);
+	if (err)
+		kobject_put(compat_kobj);
+
+	return err;
+}
+
+static void profile_compat_exit(void)
+{
+	if (compat_kobj) {
+		sysfs_remove_group(compat_kobj, &platform_profile_group);
+		kobject_put(compat_kobj);
+	}
+}
+#else
+static int profile_update(void)
+{
+	return 0;
+}
+
+static int profile_compat_init(void)
+{
+	return 0;
+}
+
+static void profile_compat_exit(void)
+{
+}
+#endif
+
  /**
   * platform_profile_notify - Notify the provider and aggregate sysfs interfaces
   * @dev: The class device
@@ -728,24 +784,16 @@ static int __init platform_profile_init(void)
  	if (err)
  		return err;
 
-	compat_kobj = platform_profile_compat_kobj();
-	if (compat_kobj) {
-		err = sysfs_create_group(compat_kobj, &platform_profile_group);
-		if (err) {
-			kobject_put(compat_kobj);
-			class_unregister(&platform_profile_class);
-		}
-	}
+	err = profile_compat_init();
+	if (err)
+		class_unregister(&platform_profile_class);
 
  	return err;
  }
 
  static void __exit platform_profile_exit(void)
  {
-	if (compat_kobj) {
-		sysfs_remove_group(compat_kobj, &platform_profile_group);
-		kobject_put(compat_kobj);
-	}
+	profile_compat_exit();
  	class_unregister(&platform_profile_class);
  }
  subsys_initcall_sync(platform_profile_init);
drivers/platform/profile/profile.h +1 -1
index 910c9f7da6a0..362eb8cc4592 100644
@@ -5,7 +5,7 @@
  #include <linux/kconfig.h>
  #include <linux/kobject.h>
 
-#ifdef CONFIG_ACPI
+#ifdef CONFIG_PLATFORM_PROFILE_LEGACY
  struct kobject *platform_profile_compat_kobj(void);
  #else
  static inline struct kobject *platform_profile_compat_kobj(void)