From b02b1396c5e9033203bf242c022092e432f91e37 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 23 Aug 2021 12:40:31 +0200 Subject: [PATCH 1/3] utils: Add "tainting" detection Throw a warning if custom fan curves are used on Asus systems as those could potentially be setup in such a way as to not match intended workloads, eg. it could make the performance profile have very little cooling and throttling in a way that would be expected of a "quiet" platform_profile. See https://patchwork.kernel.org/project/platform-driver-x86/patch/20210820095726.14131-2-luke@ljones.dev/#24397127 --- src/ppd-utils.c | 35 +++++++++++++++++++++++++++++++++++ src/ppd-utils.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/ppd-utils.c b/src/ppd-utils.c index 553a1e0..ac8c7d9 100644 --- a/src/ppd-utils.c +++ b/src/ppd-utils.c @@ -115,3 +115,38 @@ ppd_utils_find_device (const char *subsystem, return ret; } + +/* Custom fan curves used in asus-wmi module */ +#define ENABLED_FAN_CURVE_PROFILES "/sys/devices/platform/asus-nb-wmi/enabled_fan_curve_profiles" + +gboolean +ppd_utils_can_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + gboolean ret; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + ret = g_file_test (fan_curves_file, G_FILE_TEST_IS_REGULAR); + g_debug ("%s %s: %s taint", ret ? "Detected" : "Didn't detect", + ENABLED_FAN_CURVE_PROFILES, ret ? "can" : "cannot"); + return ret; +} + +gboolean +ppd_utils_try_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + g_autofree char *contents = NULL; + g_autoptr(GError) error = NULL; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + if (g_file_get_contents (fan_curves_file, &contents, NULL, &error)) { + if (g_strcmp0 (g_strchomp (contents), "") != 0) { + g_warning ("Custom fan curves are in use, please revert to defaults before reporting any problems"); + return TRUE; + } + } else { + g_debug ("Failed to open %s: %s", ENABLED_FAN_CURVE_PROFILES, error->message); + } + return FALSE; +} diff --git a/src/ppd-utils.h b/src/ppd-utils.h index 9b12e5b..3e32fc3 100644 --- a/src/ppd-utils.h +++ b/src/ppd-utils.h @@ -26,3 +26,6 @@ GFileMonitor *ppd_utils_monitor_sysfs_attr (GUdevDevice *device, GUdevDevice *ppd_utils_find_device (const char *subsystem, GCompareFunc func, gpointer user_data); + +gboolean ppd_utils_can_taint (void); +gboolean ppd_utils_try_taint (void); -- GitLab From 9788313c746594f1c2644d9c4d799ec2f720f500 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 23 Aug 2021 13:16:44 +0200 Subject: [PATCH 2/3] platform-profile: Check for tainting when reading profiles Check for tainting just before reading profiles, so warnings can be thrown if we detect situations we don't want to support. --- src/ppd-driver-platform-profile.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ppd-driver-platform-profile.c b/src/ppd-driver-platform-profile.c index 8111251..79820a3 100644 --- a/src/ppd-driver-platform-profile.c +++ b/src/ppd-driver-platform-profile.c @@ -29,6 +29,9 @@ struct _PpdDriverPlatformProfile GFileMonitor *lapmode_mon; GFileMonitor *acpi_platform_profile_mon; guint acpi_platform_profile_changed_id; + + gboolean can_taint; + gboolean tainted; }; G_DEFINE_TYPE (PpdDriverPlatformProfile, ppd_driver_platform_profile, PPD_TYPE_DRIVER) @@ -174,6 +177,9 @@ update_acpi_platform_profile_state (PpdDriverPlatformProfile *self) { PpdProfile new_profile; + if (self->can_taint && !self->tainted) + self->tainted = ppd_utils_try_taint (); + new_profile = read_platform_profile (); if (new_profile == PPD_PROFILE_UNSET || new_profile == self->acpi_platform_profile) @@ -291,6 +297,9 @@ ppd_driver_platform_profile_probe (PpdDriver *driver) return self->probe_result; } + /* Check for customisation that would invalidate our work */ + self->can_taint = ppd_utils_can_taint (); + /* Lenovo-specific proximity sensor */ self->device = ppd_utils_find_device ("platform", (GCompareFunc) find_dytc, -- GitLab From 3fc28d199f5d2e0b7fa5899ea910d1fe93961bfa Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 23 Aug 2021 13:18:48 +0200 Subject: [PATCH 3/3] tests: Add tests for tainting --- tests/integration-test.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/integration-test.py b/tests/integration-test.py index a073e6e..969deab 100755 --- a/tests/integration-test.py +++ b/tests/integration-test.py @@ -778,6 +778,43 @@ class Tests(dbusmock.DBusTestCase): self.stop_daemon() + def test_tainting(self): + '''check that custom fan curves throw a tainting warning''' + + self.create_platform_profile() + fan_curves_dir = os.path.join(self.testbed.get_root_dir(), "sys/devices/platform/asus-nb-wmi/") + os.makedirs(fan_curves_dir) + fan_curves_path = os.path.join(fan_curves_dir, "enabled_fan_curve_profiles") + with open(fan_curves_path, 'w') as curves: + curves.write("profile here\n") + + self.start_daemon() + self.assertEventually(lambda: self.have_text_in_log('Custom fan curves are in use')) + self.stop_daemon() + + os.remove(fan_curves_path) + os.removedirs(fan_curves_dir) + self.remove_platform_profile() + + def test_not_tainting(self): + '''check that fan curves don't throw a tainting warning if unset''' + + self.create_platform_profile() + fan_curves_dir = os.path.join(self.testbed.get_root_dir(), "sys/devices/platform/asus-nb-wmi/") + os.makedirs(fan_curves_dir) + fan_curves_path = os.path.join(fan_curves_dir, "enabled_fan_curve_profiles") + with open(fan_curves_path, 'w') as curves: + curves.write("\n") + + self.start_daemon() + self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced') + self.assertEqual(self.count_text_in_log('Custom fan curves are in use'), 0) + self.stop_daemon() + + os.remove(fan_curves_path) + os.removedirs(fan_curves_dir) + self.remove_platform_profile() + # # Helper methods # -- GitLab