commit dea8281ba91abe4baa2f87fb3db2c1bc9b8fb30f
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Tue Jun 30 00:33:39 2026 +0200

    ahci: Avoid running two flushes in parallel on the same port
    
    Otherwise the timer gets mangled.

diff --git a/linux/dev/drivers/block/ahci.c b/linux/dev/drivers/block/ahci.c
index 3ec89767..a74b6d72 100644
--- a/linux/dev/drivers/block/ahci.c
+++ b/linux/dev/drivers/block/ahci.c
@@ -467,11 +467,15 @@ static int ahci_do_flush(struct port *port)
 
 	command[slot].opts = sizeof(*fis_h2d) / sizeof(u32);
 
-	port->flush = 1;
-
 	save_flags(flags);
 	cli();
 
+	while (port->flush)
+		/* Another flush is pending, wait for it.  */
+		sleep_on(&port->q);
+
+	port->flush = 1;
+
 	/* Make sure main memory buffers are up to date */
 	mb();
 	/* Issue command */
@@ -494,9 +498,10 @@ static int ahci_do_flush(struct port *port)
 		sleep_on(&port->q);
 	}
 	del_timer(&port->command_timer);
-	restore_flags(flags);
 
 	port->flush = 0;
+	wake_up(&port->q);
+	restore_flags(flags);
 
 	return 0;
 }
