From 6d00e13239a0be71f301a63da8189265b8f767a5 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 8 Feb 2021 13:47:25 +0100 Subject: [PATCH] 4.9-stable patches added patches: acpi-thermal-do-not-call-acpi_thermal_check-directly.patch input-xpad-sync-supported-devices-with-fork-on-github.patch iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch --- ...not-call-acpi_thermal_check-directly.patch | 175 ++++++++++++++++++ ...upported-devices-with-fork-on-github.patch | 69 +++++++ ...-flush-queue-when-caching-mode-is-on.patch | 76 ++++++++ queue-4.9/series | 3 + 4 files changed, 323 insertions(+) create mode 100644 queue-4.9/acpi-thermal-do-not-call-acpi_thermal_check-directly.patch create mode 100644 queue-4.9/input-xpad-sync-supported-devices-with-fork-on-github.patch create mode 100644 queue-4.9/iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch diff --git a/queue-4.9/acpi-thermal-do-not-call-acpi_thermal_check-directly.patch b/queue-4.9/acpi-thermal-do-not-call-acpi_thermal_check-directly.patch new file mode 100644 index 00000000000..3b223bba9c8 --- /dev/null +++ b/queue-4.9/acpi-thermal-do-not-call-acpi_thermal_check-directly.patch @@ -0,0 +1,175 @@ +From 81b704d3e4674e09781d331df73d76675d5ad8cb Mon Sep 17 00:00:00 2001 +From: "Rafael J. Wysocki" +Date: Thu, 14 Jan 2021 19:34:22 +0100 +Subject: ACPI: thermal: Do not call acpi_thermal_check() directly + +From: Rafael J. Wysocki + +commit 81b704d3e4674e09781d331df73d76675d5ad8cb upstream. + +Calling acpi_thermal_check() from acpi_thermal_notify() directly +is problematic if _TMP triggers Notify () on the thermal zone for +which it has been evaluated (which happens on some systems), because +it causes a new acpi_thermal_notify() invocation to be queued up +every time and if that takes place too often, an indefinite number of +pending work items may accumulate in kacpi_notify_wq over time. + +Besides, it is not really useful to queue up a new invocation of +acpi_thermal_check() if one of them is pending already. + +For these reasons, rework acpi_thermal_notify() to queue up a thermal +check instead of calling acpi_thermal_check() directly and only allow +one thermal check to be pending at a time. Moreover, only allow one +acpi_thermal_check_fn() instance at a time to run +thermal_zone_device_update() for one thermal zone and make it return +early if it sees other instances running for the same thermal zone. + +While at it, fold acpi_thermal_check() into acpi_thermal_check_fn(), +as it is only called from there after the other changes made here. + +[This issue appears to have been exposed by commit 6d25be5782e4 + ("sched/core, workqueues: Distangle worker accounting from rq + lock"), but it is unclear why it was not visible earlier.] + +BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=208877 +Reported-by: Stephen Berman +Diagnosed-by: Sebastian Andrzej Siewior +Signed-off-by: Rafael J. Wysocki +Reviewed-by: Sebastian Andrzej Siewior +Tested-by: Stephen Berman +Cc: All applicable +[bigeasy: Backported to v4.9.y, use atomic_t instead of refcount_t] +Signed-off-by: Sebastian Andrzej Siewior +Signed-off-by: Greg Kroah-Hartman +--- + drivers/acpi/thermal.c | 55 +++++++++++++++++++++++++++++++++---------------- + 1 file changed, 38 insertions(+), 17 deletions(-) + +--- a/drivers/acpi/thermal.c ++++ b/drivers/acpi/thermal.c +@@ -188,6 +188,8 @@ struct acpi_thermal { + int tz_enabled; + int kelvin_offset; + struct work_struct thermal_check_work; ++ struct mutex thermal_check_lock; ++ atomic_t thermal_check_count; + }; + + /* -------------------------------------------------------------------------- +@@ -513,17 +515,6 @@ static int acpi_thermal_get_trip_points( + return 0; + } + +-static void acpi_thermal_check(void *data) +-{ +- struct acpi_thermal *tz = data; +- +- if (!tz->tz_enabled) +- return; +- +- thermal_zone_device_update(tz->thermal_zone, +- THERMAL_EVENT_UNSPECIFIED); +-} +- + /* sys I/F for generic thermal sysfs support */ + + static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) +@@ -557,6 +548,8 @@ static int thermal_get_mode(struct therm + return 0; + } + ++static void acpi_thermal_check_fn(struct work_struct *work); ++ + static int thermal_set_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) + { +@@ -582,7 +575,7 @@ static int thermal_set_mode(struct therm + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%s kernel ACPI thermal control\n", + tz->tz_enabled ? "Enable" : "Disable")); +- acpi_thermal_check(tz); ++ acpi_thermal_check_fn(&tz->thermal_check_work); + } + return 0; + } +@@ -951,6 +944,12 @@ static void acpi_thermal_unregister_ther + Driver Interface + -------------------------------------------------------------------------- */ + ++static void acpi_queue_thermal_check(struct acpi_thermal *tz) ++{ ++ if (!work_pending(&tz->thermal_check_work)) ++ queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); ++} ++ + static void acpi_thermal_notify(struct acpi_device *device, u32 event) + { + struct acpi_thermal *tz = acpi_driver_data(device); +@@ -961,17 +960,17 @@ static void acpi_thermal_notify(struct a + + switch (event) { + case ACPI_THERMAL_NOTIFY_TEMPERATURE: +- acpi_thermal_check(tz); ++ acpi_queue_thermal_check(tz); + break; + case ACPI_THERMAL_NOTIFY_THRESHOLDS: + acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); +- acpi_thermal_check(tz); ++ acpi_queue_thermal_check(tz); + acpi_bus_generate_netlink_event(device->pnp.device_class, + dev_name(&device->dev), event, 0); + break; + case ACPI_THERMAL_NOTIFY_DEVICES: + acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); +- acpi_thermal_check(tz); ++ acpi_queue_thermal_check(tz); + acpi_bus_generate_netlink_event(device->pnp.device_class, + dev_name(&device->dev), event, 0); + break; +@@ -1071,7 +1070,27 @@ static void acpi_thermal_check_fn(struct + { + struct acpi_thermal *tz = container_of(work, struct acpi_thermal, + thermal_check_work); +- acpi_thermal_check(tz); ++ ++ if (!tz->tz_enabled) ++ return; ++ /* ++ * In general, it is not sufficient to check the pending bit, because ++ * subsequent instances of this function may be queued after one of them ++ * has started running (e.g. if _TMP sleeps). Avoid bailing out if just ++ * one of them is running, though, because it may have done the actual ++ * check some time ago, so allow at least one of them to block on the ++ * mutex while another one is running the update. ++ */ ++ if (!atomic_add_unless(&tz->thermal_check_count, -1, 1)) ++ return; ++ ++ mutex_lock(&tz->thermal_check_lock); ++ ++ thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); ++ ++ atomic_inc(&tz->thermal_check_count); ++ ++ mutex_unlock(&tz->thermal_check_lock); + } + + static int acpi_thermal_add(struct acpi_device *device) +@@ -1103,6 +1122,8 @@ static int acpi_thermal_add(struct acpi_ + if (result) + goto free_memory; + ++ atomic_set(&tz->thermal_check_count, 3); ++ mutex_init(&tz->thermal_check_lock); + INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); + + pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), +@@ -1168,7 +1189,7 @@ static int acpi_thermal_resume(struct de + tz->state.active |= tz->trips.active[i].flags.enabled; + } + +- queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); ++ acpi_queue_thermal_check(tz); + + return AE_OK; + } diff --git a/queue-4.9/input-xpad-sync-supported-devices-with-fork-on-github.patch b/queue-4.9/input-xpad-sync-supported-devices-with-fork-on-github.patch new file mode 100644 index 00000000000..b4b78df0808 --- /dev/null +++ b/queue-4.9/input-xpad-sync-supported-devices-with-fork-on-github.patch @@ -0,0 +1,69 @@ +From 9bbd77d5bbc9aff8cb74d805c31751f5f0691ba8 Mon Sep 17 00:00:00 2001 +From: Benjamin Valentin +Date: Thu, 21 Jan 2021 19:24:17 -0800 +Subject: Input: xpad - sync supported devices with fork on GitHub + +From: Benjamin Valentin + +commit 9bbd77d5bbc9aff8cb74d805c31751f5f0691ba8 upstream. + +There is a fork of this driver on GitHub [0] that has been updated +with new device IDs. + +Merge those into the mainline driver, so the out-of-tree fork is not +needed for users of those devices anymore. + +[0] https://github.com/paroj/xpad + +Signed-off-by: Benjamin Valentin +Link: https://lore.kernel.org/r/20210121142523.1b6b050f@rechenknecht2k11 +Signed-off-by: Dmitry Torokhov +Signed-off-by: Greg Kroah-Hartman +--- + drivers/input/joystick/xpad.c | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +--- a/drivers/input/joystick/xpad.c ++++ b/drivers/input/joystick/xpad.c +@@ -232,9 +232,17 @@ static const struct xpad_device { + { 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, + { 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, + { 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE }, +- { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE }, + { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE }, + { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE }, ++ { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE }, + { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 }, + { 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE }, + { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 }, +@@ -313,6 +321,9 @@ static const struct xpad_device { + { 0x1bad, 0xfa01, "MadCatz GamePad", 0, XTYPE_XBOX360 }, + { 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 }, + { 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 }, ++ { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE }, ++ { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 }, ++ { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE }, + { 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, + { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 }, + { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 }, +@@ -446,8 +457,12 @@ static const struct usb_device_id xpad_t + XPAD_XBOX360_VENDOR(0x162e), /* Joytech X-Box 360 controllers */ + XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */ + XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */ ++ XPAD_XBOX360_VENDOR(0x20d6), /* PowerA Controllers */ ++ XPAD_XBOXONE_VENDOR(0x20d6), /* PowerA Controllers */ + XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */ + XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA Controllers */ ++ XPAD_XBOXONE_VENDOR(0x2e24), /* Hyperkin Duke X-Box One pad */ ++ XPAD_XBOX360_VENDOR(0x2f24), /* GameSir Controllers */ + { } + }; + diff --git a/queue-4.9/iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch b/queue-4.9/iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch new file mode 100644 index 00000000000..8d680b87793 --- /dev/null +++ b/queue-4.9/iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch @@ -0,0 +1,76 @@ +From 29b32839725f8c89a41cb6ee054c85f3116ea8b5 Mon Sep 17 00:00:00 2001 +From: Nadav Amit +Date: Wed, 27 Jan 2021 09:53:17 -0800 +Subject: iommu/vt-d: Do not use flush-queue when caching-mode is on + +From: Nadav Amit + +commit 29b32839725f8c89a41cb6ee054c85f3116ea8b5 upstream. + +When an Intel IOMMU is virtualized, and a physical device is +passed-through to the VM, changes of the virtual IOMMU need to be +propagated to the physical IOMMU. The hypervisor therefore needs to +monitor PTE mappings in the IOMMU page-tables. Intel specifications +provide "caching-mode" capability that a virtual IOMMU uses to report +that the IOMMU is virtualized and a TLB flush is needed after mapping to +allow the hypervisor to propagate virtual IOMMU mappings to the physical +IOMMU. To the best of my knowledge no real physical IOMMU reports +"caching-mode" as turned on. + +Synchronizing the virtual and the physical IOMMU tables is expensive if +the hypervisor is unaware which PTEs have changed, as the hypervisor is +required to walk all the virtualized tables and look for changes. +Consequently, domain flushes are much more expensive than page-specific +flushes on virtualized IOMMUs with passthrough devices. The kernel +therefore exploited the "caching-mode" indication to avoid domain +flushing and use page-specific flushing in virtualized environments. See +commit 78d5f0f500e6 ("intel-iommu: Avoid global flushes with caching +mode.") + +This behavior changed after commit 13cf01744608 ("iommu/vt-d: Make use +of iova deferred flushing"). Now, when batched TLB flushing is used (the +default), full TLB domain flushes are performed frequently, requiring +the hypervisor to perform expensive synchronization between the virtual +TLB and the physical one. + +Getting batched TLB flushes to use page-specific invalidations again in +such circumstances is not easy, since the TLB invalidation scheme +assumes that "full" domain TLB flushes are performed for scalability. + +Disable batched TLB flushes when caching-mode is on, as the performance +benefit from using batched TLB invalidations is likely to be much +smaller than the overhead of the virtual-to-physical IOMMU page-tables +synchronization. + +Fixes: 13cf01744608 ("iommu/vt-d: Make use of iova deferred flushing") +Signed-off-by: Nadav Amit +Cc: David Woodhouse +Cc: Lu Baolu +Cc: Joerg Roedel +Cc: Will Deacon +Cc: stable@vger.kernel.org +Acked-by: Lu Baolu +Link: https://lore.kernel.org/r/20210127175317.1600473-1-namit@vmware.com +Signed-off-by: Joerg Roedel +Signed-off-by: Nadav Amit +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/iommu/intel-iommu.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/drivers/iommu/intel-iommu.c ++++ b/drivers/iommu/intel-iommu.c +@@ -3323,6 +3323,12 @@ static int __init init_dmars(void) + + if (!ecap_pass_through(iommu->ecap)) + hw_pass_through = 0; ++ ++ if (!intel_iommu_strict && cap_caching_mode(iommu->cap)) { ++ pr_info("Disable batched IOTLB flush due to virtualization"); ++ intel_iommu_strict = 1; ++ } ++ + #ifdef CONFIG_INTEL_IOMMU_SVM + if (pasid_enabled(iommu)) + intel_svm_alloc_pasid_tables(iommu); diff --git a/queue-4.9/series b/queue-4.9/series index 23fbc2b44d8..3a85ed42898 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -37,3 +37,6 @@ mm-hugetlb-remove-vm_bug_on_page-from-page_huge_active.patch mm-thp-fix-madv_remove-deadlock-on-shmem-thp.patch x86-build-disable-cet-instrumentation-in-the-kernel.patch x86-apic-add-extra-serialization-for-non-serializing-msrs.patch +input-xpad-sync-supported-devices-with-fork-on-github.patch +acpi-thermal-do-not-call-acpi_thermal_check-directly.patch +iommu-vt-d-do-not-use-flush-queue-when-caching-mode-is-on.patch -- 2.47.3