From 8458e77cfc392eb29d88d66c9766eebe04af01d7 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 4 Oct 2023 18:04:50 +0200 Subject: [PATCH] 5.4-stable patches added patches: ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch ata-libata-core-fix-ata_port_request_pm-locking.patch ata-libata-core-fix-port-and-device-removal.patch ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch btrfs-properly-report-0-avail-for-very-full-file-systems.patch fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch ring-buffer-update-shortest_full-in-polling.patch --- ...register-pm-operations-for-sas-ports.patch | 82 +++++++++++++++++++ ...core-fix-ata_port_request_pm-locking.patch | 75 +++++++++++++++++ ...ata-core-fix-port-and-device-removal.patch | 81 ++++++++++++++++++ ...ata-increase-pmp-srst-timeout-to-10s.patch | 50 +++++++++++ ...t-0-avail-for-very-full-file-systems.patch | 43 ++++++++++ ..._efpic-fix-personality-for-elf-fdpic.patch | 63 ++++++++++++++ ...t-fix-tcpv6-gso-checksum-calculation.patch | 44 ++++++++++ ...ffer-update-shortest_full-in-polling.patch | 66 +++++++++++++++ queue-5.4/series | 8 ++ 9 files changed, 512 insertions(+) create mode 100644 queue-5.4/ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch create mode 100644 queue-5.4/ata-libata-core-fix-ata_port_request_pm-locking.patch create mode 100644 queue-5.4/ata-libata-core-fix-port-and-device-removal.patch create mode 100644 queue-5.4/ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch create mode 100644 queue-5.4/btrfs-properly-report-0-avail-for-very-full-file-systems.patch create mode 100644 queue-5.4/fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch create mode 100644 queue-5.4/net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch create mode 100644 queue-5.4/ring-buffer-update-shortest_full-in-polling.patch diff --git a/queue-5.4/ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch b/queue-5.4/ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch new file mode 100644 index 00000000000..573e94bc1a4 --- /dev/null +++ b/queue-5.4/ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch @@ -0,0 +1,82 @@ +From 75e2bd5f1ede42a2bc88aa34b431e1ace8e0bea0 Mon Sep 17 00:00:00 2001 +From: Damien Le Moal +Date: Fri, 8 Sep 2023 20:04:52 +0900 +Subject: ata: libata-core: Do not register PM operations for SAS ports + +From: Damien Le Moal + +commit 75e2bd5f1ede42a2bc88aa34b431e1ace8e0bea0 upstream. + +libsas does its own domain based power management of ports. For such +ports, libata should not use a device type defining power management +operations as executing these operations for suspend/resume in addition +to libsas calls to ata_sas_port_suspend() and ata_sas_port_resume() is +not necessary (and likely dangerous to do, even though problems are not +seen currently). + +Introduce the new ata_port_sas_type device_type for ports managed by +libsas. This new device type is used in ata_tport_add() and is defined +without power management operations. + +Fixes: 2fcbdcb4c802 ("[SCSI] libata: export ata_port suspend/resume infrastructure for sas") +Cc: stable@vger.kernel.org +Signed-off-by: Damien Le Moal +Reviewed-by: Hannes Reinecke +Tested-by: Chia-Lin Kao (AceLan) +Tested-by: Geert Uytterhoeven +Reviewed-by: John Garry +Reviewed-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/ata/libata-core.c | 2 +- + drivers/ata/libata-transport.c | 9 ++++++++- + drivers/ata/libata.h | 2 ++ + 3 files changed, 11 insertions(+), 2 deletions(-) + +--- a/drivers/ata/libata-core.c ++++ b/drivers/ata/libata-core.c +@@ -6002,7 +6002,7 @@ EXPORT_SYMBOL_GPL(ata_host_resume); + #endif + + const struct device_type ata_port_type = { +- .name = "ata_port", ++ .name = ATA_PORT_TYPE_NAME, + #ifdef CONFIG_PM + .pm = &ata_port_pm_ops, + #endif +--- a/drivers/ata/libata-transport.c ++++ b/drivers/ata/libata-transport.c +@@ -266,6 +266,10 @@ void ata_tport_delete(struct ata_port *a + put_device(dev); + } + ++static const struct device_type ata_port_sas_type = { ++ .name = ATA_PORT_TYPE_NAME, ++}; ++ + /** ata_tport_add - initialize a transport ATA port structure + * + * @parent: parent device +@@ -283,7 +287,10 @@ int ata_tport_add(struct device *parent, + struct device *dev = &ap->tdev; + + device_initialize(dev); +- dev->type = &ata_port_type; ++ if (ap->flags & ATA_FLAG_SAS_HOST) ++ dev->type = &ata_port_sas_type; ++ else ++ dev->type = &ata_port_type; + + dev->parent = parent; + ata_host_get(ap->host); +--- a/drivers/ata/libata.h ++++ b/drivers/ata/libata.h +@@ -30,6 +30,8 @@ enum { + ATA_DNXFER_QUIET = (1 << 31), + }; + ++#define ATA_PORT_TYPE_NAME "ata_port" ++ + extern atomic_t ata_print_id; + extern int atapi_passthru16; + extern int libata_fua; diff --git a/queue-5.4/ata-libata-core-fix-ata_port_request_pm-locking.patch b/queue-5.4/ata-libata-core-fix-ata_port_request_pm-locking.patch new file mode 100644 index 00000000000..d7688a42192 --- /dev/null +++ b/queue-5.4/ata-libata-core-fix-ata_port_request_pm-locking.patch @@ -0,0 +1,75 @@ +From 3b8e0af4a7a331d1510e963b8fd77e2fca0a77f1 Mon Sep 17 00:00:00 2001 +From: Damien Le Moal +Date: Mon, 4 Sep 2023 20:38:13 +0900 +Subject: ata: libata-core: Fix ata_port_request_pm() locking + +From: Damien Le Moal + +commit 3b8e0af4a7a331d1510e963b8fd77e2fca0a77f1 upstream. + +The function ata_port_request_pm() checks the port flag +ATA_PFLAG_PM_PENDING and calls ata_port_wait_eh() if this flag is set to +ensure that power management operations for a port are not scheduled +simultaneously. However, this flag check is done without holding the +port lock. + +Fix this by taking the port lock on entry to the function and checking +the flag under this lock. The lock is released and re-taken if +ata_port_wait_eh() needs to be called. The two WARN_ON() macros checking +that the ATA_PFLAG_PM_PENDING flag was cleared are removed as the first +call is racy and the second one done without holding the port lock. + +Fixes: 5ef41082912b ("ata: add ata port system PM callbacks") +Cc: stable@vger.kernel.org +Signed-off-by: Damien Le Moal +Reviewed-by: Hannes Reinecke +Tested-by: Chia-Lin Kao (AceLan) +Reviewed-by: Niklas Cassel +Tested-by: Geert Uytterhoeven +Reviewed-by: Martin K. Petersen +Reviewed-by: Bart Van Assche +Signed-off-by: Greg Kroah-Hartman +--- + drivers/ata/libata-core.c | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +--- a/drivers/ata/libata-core.c ++++ b/drivers/ata/libata-core.c +@@ -5809,17 +5809,19 @@ static void ata_port_request_pm(struct a + struct ata_link *link; + unsigned long flags; + +- /* Previous resume operation might still be in +- * progress. Wait for PM_PENDING to clear. ++ spin_lock_irqsave(ap->lock, flags); ++ ++ /* ++ * A previous PM operation might still be in progress. Wait for ++ * ATA_PFLAG_PM_PENDING to clear. + */ + if (ap->pflags & ATA_PFLAG_PM_PENDING) { ++ spin_unlock_irqrestore(ap->lock, flags); + ata_port_wait_eh(ap); +- WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); ++ spin_lock_irqsave(ap->lock, flags); + } + +- /* request PM ops to EH */ +- spin_lock_irqsave(ap->lock, flags); +- ++ /* Request PM operation to EH */ + ap->pm_mesg = mesg; + ap->pflags |= ATA_PFLAG_PM_PENDING; + ata_for_each_link(link, ap, HOST_FIRST) { +@@ -5831,10 +5833,8 @@ static void ata_port_request_pm(struct a + + spin_unlock_irqrestore(ap->lock, flags); + +- if (!async) { ++ if (!async) + ata_port_wait_eh(ap); +- WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); +- } + } + + /* diff --git a/queue-5.4/ata-libata-core-fix-port-and-device-removal.patch b/queue-5.4/ata-libata-core-fix-port-and-device-removal.patch new file mode 100644 index 00000000000..975e384400b --- /dev/null +++ b/queue-5.4/ata-libata-core-fix-port-and-device-removal.patch @@ -0,0 +1,81 @@ +From 84d76529c650f887f1e18caee72d6f0589e1baf9 Mon Sep 17 00:00:00 2001 +From: Damien Le Moal +Date: Sat, 26 Aug 2023 13:07:36 +0900 +Subject: ata: libata-core: Fix port and device removal + +From: Damien Le Moal + +commit 84d76529c650f887f1e18caee72d6f0589e1baf9 upstream. + +Whenever an ATA adapter driver is removed (e.g. rmmod), +ata_port_detach() is called repeatedly for all the adapter ports to +remove (unload) the devices attached to the port and delete the port +device itself. Removing of devices is done using libata EH with the +ATA_PFLAG_UNLOADING port flag set. This causes libata EH to execute +ata_eh_unload() which disables all devices attached to the port. + +ata_port_detach() finishes by calling scsi_remove_host() to remove the +scsi host associated with the port. This function will trigger the +removal of all scsi devices attached to the host and in the case of +disks, calls to sd_shutdown() which will flush the device write cache +and stop the device. However, given that the devices were already +disabled by ata_eh_unload(), the synchronize write cache command and +start stop unit commands fail. E.g. running "rmmod ahci" with first +removing sd_mod results in error messages like: + +ata13.00: disable device +sd 0:0:0:0: [sda] Synchronizing SCSI cache +sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK +sd 0:0:0:0: [sda] Stopping disk +sd 0:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK + +Fix this by removing all scsi devices of the ata devices connected to +the port before scheduling libata EH to disable the ATA devices. + +Fixes: 720ba12620ee ("[PATCH] libata-hp: update unload-unplug") +Cc: stable@vger.kernel.org +Signed-off-by: Damien Le Moal +Reviewed-by: Hannes Reinecke +Reviewed-by: Niklas Cassel +Tested-by: Chia-Lin Kao (AceLan) +Tested-by: Geert Uytterhoeven +Reviewed-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/ata/libata-core.c | 21 ++++++++++++++++++++- + 1 file changed, 20 insertions(+), 1 deletion(-) + +--- a/drivers/ata/libata-core.c ++++ b/drivers/ata/libata-core.c +@@ -6814,11 +6814,30 @@ static void ata_port_detach(struct ata_p + if (!ap->ops->error_handler) + goto skip_eh; + +- /* tell EH we're leaving & flush EH */ ++ /* Wait for any ongoing EH */ ++ ata_port_wait_eh(ap); ++ ++ mutex_lock(&ap->scsi_scan_mutex); + spin_lock_irqsave(ap->lock, flags); ++ ++ /* Remove scsi devices */ ++ ata_for_each_link(link, ap, HOST_FIRST) { ++ ata_for_each_dev(dev, link, ALL) { ++ if (dev->sdev) { ++ spin_unlock_irqrestore(ap->lock, flags); ++ scsi_remove_device(dev->sdev); ++ spin_lock_irqsave(ap->lock, flags); ++ dev->sdev = NULL; ++ } ++ } ++ } ++ ++ /* Tell EH to disable all devices */ + ap->pflags |= ATA_PFLAG_UNLOADING; + ata_port_schedule_eh(ap); ++ + spin_unlock_irqrestore(ap->lock, flags); ++ mutex_unlock(&ap->scsi_scan_mutex); + + /* wait till EH commits suicide */ + ata_port_wait_eh(ap); diff --git a/queue-5.4/ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch b/queue-5.4/ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch new file mode 100644 index 00000000000..93fa2e43a31 --- /dev/null +++ b/queue-5.4/ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch @@ -0,0 +1,50 @@ +From 753a4d531bc518633ea88ac0ed02b25a16823d51 Mon Sep 17 00:00:00 2001 +From: Matthias Schiffer +Date: Fri, 22 Sep 2023 22:55:16 +0200 +Subject: ata: libata-sata: increase PMP SRST timeout to 10s + +From: Matthias Schiffer + +commit 753a4d531bc518633ea88ac0ed02b25a16823d51 upstream. + +On certain SATA controllers, softreset fails after wakeup from S2RAM with +the message "softreset failed (1st FIS failed)", sometimes resulting in +drives not being detected again. With the increased timeout, this issue +is avoided. Instead, "softreset failed (device not ready)" is now +logged 1-2 times; this later failure seems to cause fewer problems +however, and the drives are detected reliably once they've spun up and +the probe is retried. + +The issue was observed with the primary SATA controller of the QNAP +TS-453B, which is an "Intel Corporation Celeron/Pentium Silver Processor +SATA Controller [8086:31e3] (rev 06)" integrated in the Celeron J4125 CPU, +and the following drives: + +- Seagate IronWolf ST12000VN0008 +- Seagate IronWolf ST8000NE0004 + +The SATA controller seems to be more relevant to this issue than the +drives, as the same drives are always detected reliably on the secondary +SATA controller on the same board (an ASMedia 106x) without any "softreset +failed" errors even without the increased timeout. + +Fixes: e7d3ef13d52a ("libata: change drive ready wait after hard reset to 5s") +Cc: stable@vger.kernel.org +Signed-off-by: Matthias Schiffer +Signed-off-by: Damien Le Moal +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/libata.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/include/linux/libata.h ++++ b/include/linux/libata.h +@@ -298,7 +298,7 @@ enum { + * advised to wait only for the following duration before + * doing SRST. + */ +- ATA_TMOUT_PMP_SRST_WAIT = 5000, ++ ATA_TMOUT_PMP_SRST_WAIT = 10000, + + /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might + * be a spurious PHY event, so ignore the first PHY event that diff --git a/queue-5.4/btrfs-properly-report-0-avail-for-very-full-file-systems.patch b/queue-5.4/btrfs-properly-report-0-avail-for-very-full-file-systems.patch new file mode 100644 index 00000000000..e338d681790 --- /dev/null +++ b/queue-5.4/btrfs-properly-report-0-avail-for-very-full-file-systems.patch @@ -0,0 +1,43 @@ +From 58bfe2ccec5f9f137b41dd38f335290dcc13cd5c Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Mon, 18 Sep 2023 10:34:51 -0400 +Subject: btrfs: properly report 0 avail for very full file systems + +From: Josef Bacik + +commit 58bfe2ccec5f9f137b41dd38f335290dcc13cd5c upstream. + +A user reported some issues with smaller file systems that get very +full. While investigating this issue I noticed that df wasn't showing +100% full, despite having 0 chunk space and having < 1MiB of available +metadata space. + +This turns out to be an overflow issue, we're doing: + + total_available_metadata_space - SZ_4M < global_block_rsv_size + +to determine if there's not enough space to make metadata allocations, +which overflows if total_available_metadata_space is < 4M. Fix this by +checking to see if our available space is greater than the 4M threshold. +This makes df properly report 100% usage on the file system. + +CC: stable@vger.kernel.org # 4.14+ +Signed-off-by: Josef Bacik +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/super.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -2135,7 +2135,7 @@ static int btrfs_statfs(struct dentry *d + * calculated f_bavail. + */ + if (!mixed && block_rsv->space_info->full && +- total_free_meta - thresh < block_rsv->size) ++ (total_free_meta < thresh || total_free_meta - thresh < block_rsv->size)) + buf->f_bavail = 0; + + buf->f_type = BTRFS_SUPER_MAGIC; diff --git a/queue-5.4/fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch b/queue-5.4/fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch new file mode 100644 index 00000000000..fae951a4dbc --- /dev/null +++ b/queue-5.4/fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch @@ -0,0 +1,63 @@ +From 7c3151585730b7095287be8162b846d31e6eee61 Mon Sep 17 00:00:00 2001 +From: Greg Ungerer +Date: Thu, 7 Sep 2023 11:18:08 +1000 +Subject: fs: binfmt_elf_efpic: fix personality for ELF-FDPIC + +From: Greg Ungerer + +commit 7c3151585730b7095287be8162b846d31e6eee61 upstream. + +The elf-fdpic loader hard sets the process personality to either +PER_LINUX_FDPIC for true elf-fdpic binaries or to PER_LINUX for normal ELF +binaries (in this case they would be constant displacement compiled with +-pie for example). The problem with that is that it will lose any other +bits that may be in the ELF header personality (such as the "bug +emulation" bits). + +On the ARM architecture the ADDR_LIMIT_32BIT flag is used to signify a +normal 32bit binary - as opposed to a legacy 26bit address binary. This +matters since start_thread() will set the ARM CPSR register as required +based on this flag. If the elf-fdpic loader loses this bit the process +will be mis-configured and crash out pretty quickly. + +Modify elf-fdpic loader personality setting so that it preserves the upper +three bytes by using the SET_PERSONALITY macro to set it. This macro in +the generic case sets PER_LINUX and preserves the upper bytes. +Architectures can override this for their specific use case, and ARM does +exactly this. + +The problem shows up quite easily running under qemu using the ARM +architecture, but not necessarily on all types of real ARM hardware. If +the underlying ARM processor does not support the legacy 26-bit addressing +mode then everything will work as expected. + +Link: https://lkml.kernel.org/r/20230907011808.2985083-1-gerg@kernel.org +Fixes: 1bde925d23547 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries") +Signed-off-by: Greg Ungerer +Cc: Al Viro +Cc: Christian Brauner +Cc: Eric W. Biederman +Cc: Greg Ungerer +Cc: Kees Cook +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + fs/binfmt_elf_fdpic.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +--- a/fs/binfmt_elf_fdpic.c ++++ b/fs/binfmt_elf_fdpic.c +@@ -345,10 +345,9 @@ static int load_elf_fdpic_binary(struct + /* there's now no turning back... the old userspace image is dead, + * defunct, deceased, etc. + */ ++ SET_PERSONALITY(exec_params.hdr); + if (elf_check_fdpic(&exec_params.hdr)) +- set_personality(PER_LINUX_FDPIC); +- else +- set_personality(PER_LINUX); ++ current->personality |= PER_LINUX_FDPIC; + if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) + current->personality |= READ_IMPLIES_EXEC; + diff --git a/queue-5.4/net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch b/queue-5.4/net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch new file mode 100644 index 00000000000..b26af3f0cd4 --- /dev/null +++ b/queue-5.4/net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch @@ -0,0 +1,44 @@ +From e0b65f9b81fef180cf5f103adecbe5505c961153 Mon Sep 17 00:00:00 2001 +From: Mika Westerberg +Date: Wed, 13 Sep 2023 08:26:47 +0300 +Subject: net: thunderbolt: Fix TCPv6 GSO checksum calculation + +From: Mika Westerberg + +commit e0b65f9b81fef180cf5f103adecbe5505c961153 upstream. + +Alex reported that running ssh over IPv6 does not work with +Thunderbolt/USB4 networking driver. The reason for that is that driver +should call skb_is_gso() before calling skb_is_gso_v6(), and it should +not return false after calculates the checksum successfully. This probably +was a copy paste error from the original driver where it was done properly. + +Reported-by: Alex Balcanquall +Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable") +Cc: stable@vger.kernel.org +Signed-off-by: Mika Westerberg +Reviewed-by: Eric Dumazet +Reviewed-by: Jiri Pirko +Reviewed-by: Jiri Pirko +Signed-off-by: David S. Miller +Signed-off-by: Greg Kroah-Hartman +--- + drivers/net/thunderbolt.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/drivers/net/thunderbolt.c ++++ b/drivers/net/thunderbolt.c +@@ -958,12 +958,11 @@ static bool tbnet_xmit_csum_and_map(stru + *tucso = ~csum_tcpudp_magic(ip_hdr(skb)->saddr, + ip_hdr(skb)->daddr, 0, + ip_hdr(skb)->protocol, 0); +- } else if (skb_is_gso_v6(skb)) { ++ } else if (skb_is_gso(skb) && skb_is_gso_v6(skb)) { + tucso = dest + ((void *)&(tcp_hdr(skb)->check) - data); + *tucso = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, + &ipv6_hdr(skb)->daddr, 0, + IPPROTO_TCP, 0); +- return false; + } else if (protocol == htons(ETH_P_IPV6)) { + tucso = dest + skb_checksum_start_offset(skb) + skb->csum_offset; + *tucso = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, diff --git a/queue-5.4/ring-buffer-update-shortest_full-in-polling.patch b/queue-5.4/ring-buffer-update-shortest_full-in-polling.patch new file mode 100644 index 00000000000..09eb67d0115 --- /dev/null +++ b/queue-5.4/ring-buffer-update-shortest_full-in-polling.patch @@ -0,0 +1,66 @@ +From 1e0cb399c7653462d9dadf8ab9425337c355d358 Mon Sep 17 00:00:00 2001 +From: "Steven Rostedt (Google)" +Date: Fri, 29 Sep 2023 18:01:13 -0400 +Subject: ring-buffer: Update "shortest_full" in polling + +From: Steven Rostedt (Google) + +commit 1e0cb399c7653462d9dadf8ab9425337c355d358 upstream. + +It was discovered that the ring buffer polling was incorrectly stating +that read would not block, but that's because polling did not take into +account that reads will block if the "buffer-percent" was set. Instead, +the ring buffer polling would say reads would not block if there was any +data in the ring buffer. This was incorrect behavior from a user space +point of view. This was fixed by commit 42fb0a1e84ff by having the polling +code check if the ring buffer had more data than what the user specified +"buffer percent" had. + +The problem now is that the polling code did not register itself to the +writer that it wanted to wait for a specific "full" value of the ring +buffer. The result was that the writer would wake the polling waiter +whenever there was a new event. The polling waiter would then wake up, see +that there's not enough data in the ring buffer to notify user space and +then go back to sleep. The next event would wake it up again. + +Before the polling fix was added, the code would wake up around 100 times +for a hackbench 30 benchmark. After the "fix", due to the constant waking +of the writer, it would wake up over 11,0000 times! It would never leave +the kernel, so the user space behavior was still "correct", but this +definitely is not the desired effect. + +To fix this, have the polling code add what it's waiting for to the +"shortest_full" variable, to tell the writer not to wake it up if the +buffer is not as full as it expects to be. + +Note, after this fix, it appears that the waiter is now woken up around 2x +the times it was before (~200). This is a tremendous improvement from the +11,000 times, but I will need to spend some time to see why polling is +more aggressive in its wakeups than the read blocking code. + +Link: https://lore.kernel.org/linux-trace-kernel/20230929180113.01c2cae3@rorschach.local.home + +Cc: stable@vger.kernel.org +Cc: Masami Hiramatsu +Cc: Mark Rutland +Fixes: 42fb0a1e84ff ("tracing/ring-buffer: Have polling block on watermark") +Reported-by: Julia Lawall +Tested-by: Julia Lawall +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Greg Kroah-Hartman +--- + kernel/trace/ring_buffer.c | 3 +++ + 1 file changed, 3 insertions(+) + +--- a/kernel/trace/ring_buffer.c ++++ b/kernel/trace/ring_buffer.c +@@ -742,6 +742,9 @@ __poll_t ring_buffer_poll_wait(struct ri + if (full) { + poll_wait(filp, &work->full_waiters, poll_table); + work->full_waiters_pending = true; ++ if (!cpu_buffer->shortest_full || ++ cpu_buffer->shortest_full > full) ++ cpu_buffer->shortest_full = full; + } else { + poll_wait(filp, &work->waiters, poll_table); + work->waiters_pending = true; diff --git a/queue-5.4/series b/queue-5.4/series index d08c5680f39..11b1f8c11c2 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -78,3 +78,11 @@ nilfs2-fix-potential-use-after-free-in-nilfs_gccache_submit_read_data.patch alsa-hda-disable-power-save-for-solving-pop-issue-on-lenovo-thinkcentre-m70q.patch ata-libata-scsi-ignore-reserved-bits-for-report-supported-operation-codes.patch i2c-i801-unregister-tco_pdev-in-i801_probe-error-path.patch +ring-buffer-update-shortest_full-in-polling.patch +btrfs-properly-report-0-avail-for-very-full-file-systems.patch +net-thunderbolt-fix-tcpv6-gso-checksum-calculation.patch +ata-libata-core-fix-ata_port_request_pm-locking.patch +ata-libata-core-fix-port-and-device-removal.patch +ata-libata-core-do-not-register-pm-operations-for-sas-ports.patch +ata-libata-sata-increase-pmp-srst-timeout-to-10s.patch +fs-binfmt_elf_efpic-fix-personality-for-elf-fdpic.patch -- 2.47.3