ACPI: battery: create alarm sysfs attribute atomically
Subsystems (3)
Sasha Levin
maintainerPATCH 1/9 ACPI: battery: create alarm sysfs attribute atomically
From: Thomas Weißschuh <[email protected]>
[ Upstream commit a231eed10ed5a290129fda36ad7bcc263c53ff7d ]
Let the power supply core register the attribute. This ensures that the attribute is created before the device is announced to userspace, avoid a race condition.
--- drivers/acpi/battery.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/acpi/battery.c +12 -4
@@ -678,12 +678,18 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,return count; } -static const struct device_attribute alarm_attr = { +static struct device_attribute alarm_attr = { .attr = {.name ="alarm" , .mode =0644 }, .show = acpi_battery_alarm_show, .store = acpi_battery_alarm_store, }; +static struct attribute *acpi_battery_attrs[] = { + &alarm_attr.attr, +NULL +}; +ATTRIBUTE_GROUPS (acpi_battery); +/* * The Battery Hooking API *
@@ -823,7 +829,10 @@ static void __exit battery_hook_exit(void)static int sysfs_add_battery (struct acpi_battery *battery) { -struct power_supply_config psy_cfg = { .drv_data = battery, }; +struct power_supply_config psy_cfg = { + .drv_data = battery, + .attr_grp = acpi_battery_groups, + };bool full_cap_broken = false; if (!ACPI_BATTERY_CAPACITY_VALID(battery->full_charge_capacity) &&
@@ -868,7 +877,7 @@ static int sysfs_add_battery(struct acpi_battery *battery)return result; }battery_hook_add_battery (battery); -return device_create_file (&battery->bat->dev, &alarm_attr); +return 0 ; }static void sysfs_remove_battery (struct acpi_battery *battery)
@@ -879,7 +888,6 @@ static void sysfs_remove_battery(struct acpi_battery *battery)return ; }battery_hook_remove_battery (battery); -device_remove_file (&battery->bat->dev, &alarm_attr);power_supply_unregister (battery->bat); battery->bat =NULL ;mutex_unlock (&battery->sysfs_lock);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 2/9 ACPI: SBS: manage alarm sysfs attribute through psy core
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 6bad28cfc30988a845fb3f59a99f4b8a4ce8fe95 ]
Let the power supply core register the attribute.
This ensures that the attribute is created before the device is announced to userspace, avoiding a race condition.
--- drivers/acpi/sbs.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/acpi/sbs.c +12 -11
@@ -77,7 +77,6 @@ struct acpi_battery {u16 spec;u8 id; u8 present:1; - u8 have_sysfs_alarm:1; };#define to_acpi_battery (x) power_supply_get_drvdata(x)
@@ -462,12 +461,18 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,return count; } -static const struct device_attribute alarm_attr = { +static struct device_attribute alarm_attr = { .attr = {.name ="alarm" , .mode =0644 }, .show = acpi_battery_alarm_show, .store = acpi_battery_alarm_store, }; +static struct attribute *acpi_battery_attrs[] = { + &alarm_attr.attr, +NULL +}; +ATTRIBUTE_GROUPS (acpi_battery); +/* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */
@@ -518,7 +523,10 @@ static int acpi_battery_read(struct acpi_battery *battery)static int acpi_battery_add (struct acpi_sbs *sbs,int id) {struct acpi_battery *battery = &sbs->battery[id]; -struct power_supply_config psy_cfg = { .drv_data = battery, }; +struct power_supply_config psy_cfg = { + .drv_data = battery, + .attr_grp = acpi_battery_groups, + };int result; battery->id = id;
@@ -548,10 +556,6 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id) goto end; } - result =device_create_file (&battery->bat->dev, &alarm_attr); -if (result) - goto end; - battery->have_sysfs_alarm =1 ; end: pr_info("%s [%s]: Battery Slot [%s] (battery %s)\n", ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
@@ -563,11 +567,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id) {struct acpi_battery *battery = &sbs->battery[id]; -if (battery->bat) { -if (battery->have_sysfs_alarm) -device_remove_file (&battery->bat->dev, &alarm_attr); +if (battery->bat)power_supply_unregister (battery->bat); - } }static int acpi_charger_add (struct acpi_sbs *sbs)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 3/9 cpufreq: amd-pstate: Allow users to write 'default' EPP string
In reply to Sasha LevinFrom: Mario Limonciello <[email protected]>
[ Upstream commit fc6e0837264a8b2504b6160e63ec92eb012540f3 ]
The EPP string for 'default' represents what the firmware had configured as the default EPP value but once a user changes EPP to another string they can't reset it back to 'default'.
Cache the firmware EPP value and allow the user to write 'default' using this value.
--- drivers/cpufreq/amd-pstate.c | 8 +++----- drivers/cpufreq/amd-pstate.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/cpufreq/amd-pstate.c +3 -5
@@ -281,10 +281,8 @@ static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata,int epp = -EINVAL ;int ret; -if (!pref_index) { -pr_debug ("EPP pref_index is invalid\n" ); -return -EINVAL ; - } +if (!pref_index) + epp = cpudata->epp_default;if (epp == -EINVAL ) epp = epp_values[pref_index];
@@ -1436,7 +1434,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) policy->driver_data = cpudata; - cpudata->epp_cached =amd_pstate_get_epp (cpudata,0 ); + cpudata->epp_cached = cpudata->epp_default =amd_pstate_get_epp (cpudata,0 ); policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq;
drivers/cpufreq/amd-pstate.h +1 -0
@@ -99,6 +99,7 @@ struct amd_cpudata {u32 policy;u64 cppc_cap1_cached;bool suspended; + s16 epp_default; };#endif /* _LINUX_AMD_PSTATE_H */
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/9 cpufreq: amd-pstate: auto-load pstate driver by default
In reply to Sasha LevinFrom: Perry Yuan <[email protected]>
[ Upstream commit 4e4f600ee750facedf6a5dc97e8ae0b627ab4573 ]
If the amd-pstate driver is not loaded automatically by default, it is because the kernel command line parameter has not been added. To resolve this issue, it is necessary to call the amd_pstate_set_driver() function to enable the desired mode (passive/active/guided) before registering the driver instance.
This ensures that the driver is loaded correctly without relying on the kernel command line parameter.
When there is no parameter added to command line, Kernel config will provide the default mode to load.
Meanwhile, user can add driver mode in command line which will override the kernel config default option.
--- drivers/cpufreq/amd-pstate.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/cpufreq/amd-pstate.c +17 -7
@@ -1761,8 +1761,13 @@ static int __init amd_pstate_init(void)/* check if this machine need CPPC quirks */ dmi_check_system (amd_pstate_quirks_table); -switch (cppc_state) { -case AMD_PSTATE_UNDEFINED : +/* +* determine the driver mode from the command line or kernel config. +* If no command line input is provided, cppc_state will be AMD_PSTATE_UNDEFINED. +* command line options will override the kernel config settings. +*/ + +if (cppc_state ==AMD_PSTATE_UNDEFINED ) {/* Disable on the following configs by default: * 1. Undefined platforms * 2. Server platforms
@@ -1774,15 +1779,20 @@ static int __init amd_pstate_init(void)pr_info ("driver load is disabled, boot with specific mode to enable this\n" );return -ENODEV ; } - ret =amd_pstate_set_driver (CONFIG_X86_AMD_PSTATE_DEFAULT_MODE ); -if (ret) -return ret; -break ; +/* get driver mode from kernel config option [1:4] */ + cppc_state =CONFIG_X86_AMD_PSTATE_DEFAULT_MODE ; + } + +switch (cppc_state) {case AMD_PSTATE_DISABLE : +pr_info ("driver load is disabled, boot with specific mode to enable this\n" );return -ENODEV ;case AMD_PSTATE_PASSIVE :case AMD_PSTATE_ACTIVE :case AMD_PSTATE_GUIDED : + ret =amd_pstate_set_driver (cppc_state); +if (ret) +return ret;break ;default :return -EINVAL ;
@@ -1803,7 +1813,7 @@ static int __init amd_pstate_init(void)/* enable amd pstate feature */ ret =amd_pstate_enable (true);if (ret) { -pr_err ("failed to enable with return %d\n" , ret); +pr_err ("failed to enable driver mode(%d)\n" , cppc_state);return ret; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 5/9 soc: qcom: icc-bwmon: Allow for interrupts to be shared across instances
In reply to Sasha LevinFrom: Sibi Sankar <[email protected]>
[ Upstream commit dc18836435e7f8dda019db2c618c69194933157f ]
The multiple BWMONv4 instances available on the X1E80100 SoC use the same interrupt number. Mark them are shared to allow for re-use across instances.
Using IRQF_SHARED coupled with devm_request_threaded_irq implies that the irq can still trigger during/after bwmon_remove due to other active bwmon instances. Handle this race by relying on bwmon_disable to disable the interrupt and coupled with explicit request/free irqs.
--- drivers/soc/qcom/icc-bwmon.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/soc/qcom/icc-bwmon.c +9 -3
@@ -781,9 +781,14 @@ static int bwmon_probe(struct platform_device *pdev) bwmon->dev = dev;bwmon_disable (bwmon); - ret =devm_request_threaded_irq (dev, bwmon->irq, bwmon_intr, - bwmon_intr_thread, -IRQF_ONESHOT ,dev_name (dev), bwmon); + +/* +* SoCs with multiple cpu-bwmon instances can end up using a shared interrupt +* line. Using the devm_ variant might result in the IRQ handler being executed +* after bwmon_disable in bwmon_remove() +*/ + ret =request_threaded_irq (bwmon->irq, bwmon_intr, bwmon_intr_thread, +IRQF_ONESHOT |IRQF_SHARED ,dev_name (dev), bwmon);if (ret)return dev_err_probe (dev, ret,"failed to request IRQ\n" );
@@ -798,6 +803,7 @@ static void bwmon_remove(struct platform_device *pdev)struct icc_bwmon *bwmon =platform_get_drvdata (pdev);bwmon_disable (bwmon); +free_irq (bwmon->irq, bwmon); }static const struct icc_bwmon_data msm8998_bwmon_data = {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 6/9 xen: privcmd: Switch from mutex to spinlock for irqfds
In reply to Sasha LevinFrom: Viresh Kumar <[email protected]>
[ Upstream commit 1c682593096a487fd9aebc079a307ff7a6d054a3 ]
irqfd_wakeup() gets EPOLLHUP, when it is called by eventfd_release() by way of wake_up_poll(&ctx->wqh, EPOLLHUP), which gets called under spin_lock_irqsave(). We can't use a mutex here as it will lead to a deadlock.
Fix it by switching over to a spin lock.
--- drivers/xen/privcmd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/xen/privcmd.c +15 -10
@@ -845,7 +845,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file,#ifdef CONFIG_XEN_PRIVCMD_EVENTFD /* Irqfd support */ static struct workqueue_struct *irqfd_cleanup_wq; -static DEFINE_MUTEX (irqfds_lock); +static DEFINE_SPINLOCK (irqfds_lock);static LIST_HEAD (irqfds_list); struct privcmd_kernel_irqfd {
@@ -909,9 +909,11 @@ irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key)irqfd_inject (kirqfd);if (flags &EPOLLHUP ) { -mutex_lock (&irqfds_lock); +unsigned long flags; + +spin_lock_irqsave (&irqfds_lock, flags);irqfd_deactivate (kirqfd); -mutex_unlock (&irqfds_lock); +spin_unlock_irqrestore (&irqfds_lock, flags); }return 0 ;
@@ -929,6 +931,7 @@ irqfd_poll_func(struct file *file, wait_queue_head_t *wqh, poll_table *pt)static int privcmd_irqfd_assign (struct privcmd_irqfd *irqfd) {struct privcmd_kernel_irqfd *kirqfd, *tmp; +unsigned long flags;__poll_t events;struct fd f;void *dm_op;
@@ -968,18 +971,18 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)init_waitqueue_func_entry (&kirqfd->wait, irqfd_wakeup);init_poll_funcptr (&kirqfd->pt, irqfd_poll_func); -mutex_lock (&irqfds_lock); +spin_lock_irqsave (&irqfds_lock, flags);list_for_each_entry (tmp, &irqfds_list, list) {if (kirqfd->eventfd == tmp->eventfd) { ret = -EBUSY ; -mutex_unlock (&irqfds_lock); +spin_unlock_irqrestore (&irqfds_lock, flags); goto error_eventfd; } }list_add_tail (&kirqfd->list, &irqfds_list); -mutex_unlock (&irqfds_lock); +spin_unlock_irqrestore (&irqfds_lock, flags);/* * Check if there was an event already pending on the eventfd before we
@@ -1011,12 +1014,13 @@ static int privcmd_irqfd_deassign(struct privcmd_irqfd *irqfd) {struct privcmd_kernel_irqfd *kirqfd;struct eventfd_ctx *eventfd; +unsigned long flags; eventfd =eventfd_ctx_fdget (irqfd->fd);if (IS_ERR (eventfd))return PTR_ERR (eventfd); -mutex_lock (&irqfds_lock); +spin_lock_irqsave (&irqfds_lock, flags);list_for_each_entry (kirqfd, &irqfds_list, list) {if (kirqfd->eventfd == eventfd) {
@@ -1025,7 +1029,7 @@ static int privcmd_irqfd_deassign(struct privcmd_irqfd *irqfd) } } -mutex_unlock (&irqfds_lock); +spin_unlock_irqrestore (&irqfds_lock, flags);eventfd_ctx_put (eventfd);
@@ -1073,13 +1077,14 @@ static int privcmd_irqfd_init(void)static void privcmd_irqfd_exit (void ) {struct privcmd_kernel_irqfd *kirqfd, *tmp; +unsigned long flags; -mutex_lock (&irqfds_lock); +spin_lock_irqsave (&irqfds_lock, flags);list_for_each_entry_safe (kirqfd, tmp, &irqfds_list, list)irqfd_deactivate (kirqfd); -mutex_unlock (&irqfds_lock); +spin_unlock_irqrestore (&irqfds_lock, flags);destroy_workqueue (irqfd_cleanup_wq); }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 7/9 ACPI: resource: Skip IRQ override on Asus Vivobook Pro N6506MU
In reply to Sasha LevinFrom: Tamim Khan <[email protected]>
[ Upstream commit dc41751f9e07889d078e3f06adb6e892c80b7c10 ]
Like various other Asus laptops, the Asus Vivobook Pro N6506MV has a DSDT table that describes IRQ 1 as ActiveLow while the kernel is overriding it to Edge_High. This prevents the internal keyboard from working. This patch prevents this issue by adding this laptop to the override table that prevents the kernel from overriding this IRQ
--- drivers/acpi/resource.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/acpi/resource.c +7 -0
@@ -524,6 +524,13 @@ static const struct dmi_system_id irq1_level_low_skip_override[] = { DMI_MATCH(DMI_BOARD_NAME, "N6506MV"), }, }, + { +/* Asus Vivobook Pro N6506MU */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"ASUSTeK COMPUTER INC." ), + DMI_MATCH(DMI_BOARD_NAME, "N6506MU"), + }, + }, {/* LG Electronics 17U70P */ .matches = {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 8/9 ACPI: resource: Skip IRQ override on Asus Vivobook Pro N6506MJ
In reply to Sasha LevinFrom: Tamim Khan <[email protected]>
[ Upstream commit e2e7f037b400aebbb3892d8010fb3d9cae6f426e ]
Similar to other Asus Vivobooks, the Asus Vivobook Pro N6506MJ has a DSDT table that describes IRQ 1 as ActiveLow, whereas the kernel overrides it to Edge_High. This discrepancy prevents the internal keyboard from functioning properly. This patch resolves this issue by adding this laptop to the override table that prevents the kernel from overriding this IRQ.
--- drivers/acpi/resource.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/acpi/resource.c +7 -0
@@ -531,6 +531,13 @@ static const struct dmi_system_id irq1_level_low_skip_override[] = { DMI_MATCH(DMI_BOARD_NAME, "N6506MU"), }, }, + { +/* Asus Vivobook Pro N6506MJ */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"ASUSTeK COMPUTER INC." ), + DMI_MATCH(DMI_BOARD_NAME, "N6506MJ"), + }, + }, {/* LG Electronics 17U70P */ .matches = {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 9/9 thermal: intel: hfi: Give HFI instances package scope
In reply to Sasha LevinFrom: Zhang Rui <[email protected]>
[ Upstream commit b755367602d70deade956cbe0b8a3f5a12f569dc ]
The Intel Software Developer's Manual defines the scope of HFI (registers and memory buffer) as a package. Use package scope(*) in the software representation of an HFI instance.
Using die scope in HFI instances has the effect of creating multiple conflicting instances for the same package: each instance allocates its own memory buffer and configures the same package-level registers. Specifically, only one of the allocated memory buffers can be set in the MSR_IA32_HW_FEEDBACK_PTR register. CPUs get incorrect HFI data from the table.
The problem does not affect current HFI-capable platforms because they all have single-die processors.
(*) We used die scope for HFI instances because there had been
processors with packages enumerated as dies. None of those systems supported HFI, though. If such a system emerged, it would need to be quirked.
--- drivers/thermal/intel/intel_hfi.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/thermal/intel/intel_hfi.c +17 -13
@@ -401,10 +401,10 @@ static void hfi_disable(void)* intel_hfi_online() - Enable HFI on @cpu * @cpu: CPU in which the HFI will be enabled * -* Enable the HFI to be used in @cpu. The HFI is enabled at the die/package -* level. The first CPU in the die/package to come online does the full HFI +* Enable the HFI to be used in @cpu. The HFI is enabled at the package +* level. The first CPU in the package to come online does the full HFI * initialization. Subsequent CPUs will just link themselves to the HFI -* instance of their die/package. +* instance of their package. * * This function is called before enabling the thermal vector in the local APIC * in order to ensure that @cpu has an associated HFI instance when it receives
@@ -414,31 +414,31 @@ void intel_hfi_online(unsigned int cpu) {struct hfi_instance *hfi_instance;struct hfi_cpu_info *info; -u16 die_id; +u16 pkg_id;/* Nothing to do if hfi_instances are missing. */ if (!hfi_instances)return ;/* -* Link @cpu to the HFI instance of its package/die. It does not +* Link @cpu to the HFI instance of its package. It does not * matter whether the instance has been initialized. */ info = &per_cpu (hfi_cpu_info, cpu); - die_id =topology_logical_die_id (cpu); + pkg_id =topology_logical_package_id (cpu); hfi_instance = info->hfi_instance;if (!hfi_instance) { -if (die_id >= max_hfi_instances) +if (pkg_id >= max_hfi_instances)return ; - hfi_instance = &hfi_instances[die_id]; + hfi_instance = &hfi_instances[pkg_id]; info->hfi_instance = hfi_instance; }init_hfi_cpu_index (info);/* -* Now check if the HFI instance of the package/die of @cpu has been +* Now check if the HFI instance of the package of @cpu has been * initialized (by checking its header). In such case, all we have to * do is to add @cpu to this instance's cpumask and enable the instance * if needed.
@@ -504,7 +504,7 @@ void intel_hfi_online(unsigned int cpu)* * On some processors, hardware remembers previous programming settings even * after being reprogrammed. Thus, keep HFI enabled even if all CPUs in the -* die/package of @cpu are offline. See note in intel_hfi_online(). +* package of @cpu are offline. See note in intel_hfi_online(). */ void intel_hfi_offline (unsigned int cpu) {
@@ -674,9 +674,13 @@ void __init intel_hfi_init(void)if (hfi_parse_features ())return ; -/* There is one HFI instance per die/package. */ - max_hfi_instances =topology_max_packages () * -topology_max_dies_per_package (); +/* +* Note: HFI resources are managed at the physical package scope. +* There could be platforms that enumerate packages as Linux dies. +* Special handling would be needed if this happens on an HFI-capable +* platform. +*/ + max_hfi_instances =topology_max_packages ();/* * This allocation may fail. CPU hotplug callbacks must check
Signature · 1 line
2.43.0