ata: libata-core: Fix ata_port_request_pm() locking
authorDamien Le Moal <dlemoal@kernel.org>
Mon, 4 Sep 2023 11:38:13 +0000 (20:38 +0900)
committerDamien Le Moal <dlemoal@kernel.org>
Thu, 28 Sep 2023 12:22:50 +0000 (21:22 +0900)
commit3b8e0af4a7a331d1510e963b8fd77e2fca0a77f1
treecc83250e1b49a59a3cf462bbb53d6eb7432ab759
parent753a4d531bc518633ea88ac0ed02b25a16823d51
ata: libata-core: Fix ata_port_request_pm() locking

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 <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Tested-by: Chia-Lin Kao (AceLan) <acelan.kao@canonical.com>
Reviewed-by: Niklas Cassel <niklas.cassel@wdc.com>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
drivers/ata/libata-core.c