From patchwork Thu Sep 21 18:07:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13306E7D0AC for ; Thu, 21 Sep 2023 20:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbjIUU6H (ORCPT ); Thu, 21 Sep 2023 16:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232186AbjIUU5u (ORCPT ); Thu, 21 Sep 2023 16:57:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42AF9B0107; Thu, 21 Sep 2023 11:08:03 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66F50C433C8; Thu, 21 Sep 2023 18:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319682; bh=asDx0T4s+LbQmNhOXwa63Ba7iiWwHgF4S/53gy1xpPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvKZlRtGRXWf+v+kdKOjPd4DNjfaFdeYdLqxh6UzysxKYoVHxTxZ8OMweNqCvvodk wbv0REDIXmTcWL71AcAwKwpunfj3tccNCa9tcmVnbGflj3ufIln5nRhN+XBfXsJAKU 1/IPF9sfa3Hqpr6ioFiDGjL2TrWlYOjdgwaay5Lj5RpHrHRZ4vgha6BvtIaNduVF1/ ywv7lGPZYzSTrzEict0roGAMejswCZzFKMaGH5uOxcb6w2A5RBOUbOfLP6erm6P/cK yYEKMJ5a8M0e/OzjDasuZa70aZkrS3WLCOLzfbwFLC6GDeKRxFlxMSOqX7Ts+o0cZY yMQh6kaTdmFXQ== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 01/23] ata: libata-core: Fix ata_port_request_pm() locking Date: Fri, 22 Sep 2023 03:07:36 +0900 Message-ID: <20230921180758.955317-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 --- drivers/ata/libata-core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 0072e0f9ad39..732f3d0b4fd9 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5037,17 +5037,19 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, 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) { @@ -5059,10 +5061,8 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, spin_unlock_irqrestore(ap->lock, flags); - if (!async) { + if (!async) ata_port_wait_eh(ap); - WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); - } } /* From patchwork Thu Sep 21 18:07:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0C15E7D0A2 for ; Thu, 21 Sep 2023 18:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjIUSgi (ORCPT ); Thu, 21 Sep 2023 14:36:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjIUSgM (ORCPT ); Thu, 21 Sep 2023 14:36:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19137B010A; Thu, 21 Sep 2023 11:08:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB8DC433C9; Thu, 21 Sep 2023 18:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319684; bh=yIuYqI2DOC5wZ+yWw5W7Z9M+ZrB9G96DR1SWzBWoM6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbQCoMEZzBSm1HxAQLnW5Ecsn0AyJxkKOZ6HQPBjXq/yc1jwBjFeo2aD8OUeR9Sg8 lr4/ook3NYkbKxbWBioXBdggenoMwHXkNrR/eT2OWRZpWGN6tRvK4u/BNHYktQbBjF F8tb4gwV3hxCK2LmdJmOXulC/X6p2oiTamiI63QpLQ4v1FlziA5t7PDsuFAGELPL0/ Nd3A/1GtNTYn42ZGSeZdm9Zv3pwhOgVpdyef2iADFKN6ckH2CyebDZJZYqmAp8I8BZ yjW3OBqlBWBSBQ12HCoOPZCxrfxIckDsY2fh8jFsl/PyEOY0+e1m7PrSr6mDXqv3dK rPoACUYIbhlyA== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 02/23] ata: libata-core: Fix port and device removal Date: Fri, 22 Sep 2023 03:07:37 +0900 Message-ID: <20230921180758.955317-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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. Also delete the WAR_ON() call checking that the ATA_PFLAG_UNLOADING flag was cleared as that is done without holding the port lock. 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 --- drivers/ata/libata-core.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 732f3d0b4fd9..8e35afe5e560 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5948,11 +5948,30 @@ static void ata_port_detach(struct ata_port *ap) struct ata_link *link; struct ata_device *dev; - /* 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); From patchwork Thu Sep 21 18:07:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35984E7D0AB for ; Thu, 21 Sep 2023 20:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjIUUda (ORCPT ); Thu, 21 Sep 2023 16:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbjIUUdJ (ORCPT ); Thu, 21 Sep 2023 16:33:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A56CB0115; Thu, 21 Sep 2023 11:08:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1444CC433C8; Thu, 21 Sep 2023 18:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319686; bh=8hABsLOS+0tD/beZ7PSGfLZG49udVrK1JwN5r0pQTUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GL++TrZI777gfrkj4X9e0RO5ZiSLJqoT6YCq6S3funyLjNycWWnJNk9GJs2/1rtJq 8ANtLdTh5EYUpAnu6AyFvJ+MbP+6hg4IZMZYs8rb6S4RGXrWaug73VOUkfvY2TzlXm k0Td0OMKGiT/OluvVMKdQNUUDO5T13xjq6fO19VpGK5LASdhrMlsV6ZmlsBjuBWWv3 TWdd9cnX57reVO6Rkka9eq5UrMG3cE05MLX+n6tpZgleWz/oEIiMeS+yrGNQuMt0au B+c8X1J3qoiNmKo0rwNOf1mhaDI+DpzO3003CPNHQdhrk4jN+Hs31K/uTsuhi/V5Wt NVy6TyeCfFAoQ== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 03/23] ata: libata-scsi: link ata port and scsi device Date: Fri, 22 Sep 2023 03:07:38 +0900 Message-ID: <20230921180758.955317-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no direct device ancestry defined between an ata_device and its scsi device which prevents the power management code from correctly ordering suspend and resume operations. Create such ancestry with the ata device as the parent to ensure that the scsi device (child) is suspended before the ata device and that resume handles the ata device before the scsi device. The parent-child (supplier-consumer) relationship is established between the ata_port (parent) and the scsi device (child) with the function device_add_link(). The parent used is not the ata_device as the PM operations are defined per port and the status of all devices connected through that port is controlled from the port operations. The device link is established with the new function ata_scsi_slave_alloc(), and this function is used to define the ->slave_alloc callback of the scsi host template of all ata drivers. Fixes: a19a93e4c6a9 ("scsi: core: pm: Rely on the device driver core for async power management") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Niklas Cassel Tested-by: Geert Uytterhoeven Reviewed-by: John Garry --- drivers/ata/libata-scsi.c | 45 ++++++++++++++++++++++++++++++++++----- include/linux/libata.h | 2 ++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index fb73c145b49a..8b43290ca2cd 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1089,6 +1089,42 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) return 0; } +/** + * ata_scsi_slave_alloc - Early setup of SCSI device + * @sdev: SCSI device to examine + * + * This is called from scsi_alloc_sdev() when the scsi device + * associated with an ATA device is scanned on a port. + * + * LOCKING: + * Defined by SCSI layer. We don't really care. + */ + +int ata_scsi_slave_alloc(struct scsi_device *sdev) +{ + struct ata_port *ap = ata_shost_to_port(sdev->host); + struct device_link *link; + + ata_scsi_sdev_config(sdev); + + /* + * Create a link from the ata_port device to the scsi device to ensure + * that PM does suspend/resume in the correct order: the scsi device is + * consumer (child) and the ata port the supplier (parent). + */ + link = device_link_add(&sdev->sdev_gendev, &ap->tdev, + DL_FLAG_STATELESS | + DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE); + if (!link) { + ata_port_err(ap, "Failed to create link to scsi device %s\n", + dev_name(&sdev->sdev_gendev)); + return -ENODEV; + } + + return 0; +} +EXPORT_SYMBOL_GPL(ata_scsi_slave_alloc); + /** * ata_scsi_slave_config - Set SCSI device attributes * @sdev: SCSI device to examine @@ -1105,14 +1141,11 @@ int ata_scsi_slave_config(struct scsi_device *sdev) { struct ata_port *ap = ata_shost_to_port(sdev->host); struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); - int rc = 0; - - ata_scsi_sdev_config(sdev); if (dev) - rc = ata_scsi_dev_config(sdev, dev); + return ata_scsi_dev_config(sdev, dev); - return rc; + return 0; } EXPORT_SYMBOL_GPL(ata_scsi_slave_config); @@ -1136,6 +1169,8 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev) unsigned long flags; struct ata_device *dev; + device_link_remove(&sdev->sdev_gendev, &ap->tdev); + spin_lock_irqsave(ap->lock, flags); dev = __ata_scsi_find_dev(ap, sdev); if (dev && dev->sdev) { diff --git a/include/linux/libata.h b/include/linux/libata.h index bf4913f4d7ac..4ece1b7a2a5b 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1148,6 +1148,7 @@ extern int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]); extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev); +extern int ata_scsi_slave_alloc(struct scsi_device *sdev); extern int ata_scsi_slave_config(struct scsi_device *sdev); extern void ata_scsi_slave_destroy(struct scsi_device *sdev); extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, @@ -1396,6 +1397,7 @@ extern const struct attribute_group *ata_common_sdev_groups[]; .this_id = ATA_SHT_THIS_ID, \ .emulated = ATA_SHT_EMULATED, \ .proc_name = drv_name, \ + .slave_alloc = ata_scsi_slave_alloc, \ .slave_destroy = ata_scsi_slave_destroy, \ .bios_param = ata_std_bios_param, \ .unlock_native_capacity = ata_scsi_unlock_native_capacity,\ From patchwork Thu Sep 21 18:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36EB4E7D0B0 for ; Thu, 21 Sep 2023 21:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjIUVBE (ORCPT ); Thu, 21 Sep 2023 17:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbjIUVAc (ORCPT ); Thu, 21 Sep 2023 17:00:32 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FADB011B; Thu, 21 Sep 2023 11:08:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEA6FC433CA; Thu, 21 Sep 2023 18:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319688; bh=CaHDCAJ6vsukCHAdmmNiv+GUt0TZ+hNSKWGgeY+UqaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UThv9yF8cXNQ6Qmbt2EUvWB06OG0fahTqEBJ2FXfe26DzvlSgtX5tpUHHYkFBSvai scnUjIUHqiK6kLGBFgJbKrtasew3drjgoaTp31xavLqEhhKHe2d90VgvhcGRXX4ZI1 Lk9quCXDZxHv3bjAikc4QmW2QyhFcXmARk//F5TiMhb/JkTzqI/A3ZsNv83bB6KsLo dzsu94R/N4P4LsbltT8zD318xIghD82bPxUbojAq6c/cFw6q1CdTRbL0cgTgp8NnwD SKFfU3HC/EhAeIN+rFN0sTPF8Tn4iVgpKNvk42EXPneVjJMzgRUJToilVyIGIkQPMA PHdpXkNDhE9aw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 04/23] scsi: sd: Differentiate system and runtime start/stop management Date: Fri, 22 Sep 2023 03:07:39 +0900 Message-ID: <20230921180758.955317-5-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The underlying device and driver of a scsi disk may have different system and runtime power mode control requirements. This is because runtime power management affects only the scsi disk, while sustem level power management affects all devices, including the controller for the scsi disk. For instance, issuing a START STOP UNIT command when a scsi disk is runtime suspended and resumed is fine: the command is translated to a STANDBY IMMEDIATE command to spin down the ATA disk and to a VERIFY command to wake it up. The scsi disk runtime operations have no effect on the ata port device used to connect the ATA disk. However, for system suspend/resume operations, the ATA port used to connect the device will also be suspended and resumed, with the resum operation requiring re-validating the device link and the device itseld. In this case, issuing a VERIFY command to spinup the disk must be done before starting to revalidate the device, when the ata port is being resumed. In such case, we must not allow the scsi disk driver to issue START STOP UNIT commands. Allow a low level driver to refine the scsi disk start/stop management by differentiating system and runtime cases with two new scsi device flags: manage_system_start_stop and manage_runtime_start_stop. These new flags replace the current manage_start_stop flag. Drivers setting the manage_start_stop are modifed to set both new flags, thus preserving the existing start/stop management behavior. Fixes: 0a8589055936 ("ata,scsi: do not issue START STOP UNIT on resume") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Geert Uytterhoeven --- drivers/ata/libata-scsi.c | 3 +- drivers/firewire/sbp2.c | 9 +++-- drivers/scsi/sd.c | 78 ++++++++++++++++++++++++++++---------- include/scsi/scsi_device.h | 3 +- 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 8b43290ca2cd..58777d4485a1 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1056,7 +1056,8 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) * will be woken up by ata_port_pm_resume() with a port reset * and device revalidation. */ - sdev->manage_start_stop = 1; + sdev->manage_system_start_stop = 1; + sdev->manage_runtime_start_stop = 1; sdev->no_start_on_resume = 1; } diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c index 26db5b8dfc1e..f759e26241d3 100644 --- a/drivers/firewire/sbp2.c +++ b/drivers/firewire/sbp2.c @@ -81,7 +81,8 @@ MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device " * * - power condition * Set the power condition field in the START STOP UNIT commands sent by - * sd_mod on suspend, resume, and shutdown (if manage_start_stop is on). + * sd_mod on suspend, resume, and shutdown (if manage_system_start_stop or + * manage_runtime_start_stop is on). * Some disks need this to spin down or to resume properly. * * - override internal blacklist @@ -1517,8 +1518,10 @@ static int sbp2_scsi_slave_configure(struct scsi_device *sdev) sdev->use_10_for_rw = 1; - if (sbp2_param_exclusive_login) - sdev->manage_start_stop = 1; + if (sbp2_param_exclusive_login) { + sdev->manage_system_start_stop = 1; + sdev->manage_runtime_start_stop = 1; + } if (sdev->type == TYPE_ROM) sdev->use_10_for_ms = 1; diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c92a317ba547..1d106c8ad5af 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -201,18 +201,50 @@ cache_type_store(struct device *dev, struct device_attribute *attr, } static ssize_t -manage_start_stop_show(struct device *dev, struct device_attribute *attr, - char *buf) +manage_system_start_stop_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct scsi_disk *sdkp = to_scsi_disk(dev); struct scsi_device *sdp = sdkp->device; - return sprintf(buf, "%u\n", sdp->manage_start_stop); + return sprintf(buf, "%u\n", sdp->manage_system_start_stop); } static ssize_t -manage_start_stop_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +manage_system_start_stop_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_disk *sdkp = to_scsi_disk(dev); + struct scsi_device *sdp = sdkp->device; + bool v; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (kstrtobool(buf, &v)) + return -EINVAL; + + sdp->manage_system_start_stop = v; + + return count; +} +static DEVICE_ATTR_RW(manage_system_start_stop); + +static ssize_t +manage_runtime_start_stop_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct scsi_disk *sdkp = to_scsi_disk(dev); + struct scsi_device *sdp = sdkp->device; + + return sprintf(buf, "%u\n", sdp->manage_runtime_start_stop); +} + +static ssize_t +manage_runtime_start_stop_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct scsi_disk *sdkp = to_scsi_disk(dev); struct scsi_device *sdp = sdkp->device; @@ -224,11 +256,11 @@ manage_start_stop_store(struct device *dev, struct device_attribute *attr, if (kstrtobool(buf, &v)) return -EINVAL; - sdp->manage_start_stop = v; + sdp->manage_runtime_start_stop = v; return count; } -static DEVICE_ATTR_RW(manage_start_stop); +static DEVICE_ATTR_RW(manage_runtime_start_stop); static ssize_t allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -559,7 +591,8 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_cache_type.attr, &dev_attr_FUA.attr, &dev_attr_allow_restart.attr, - &dev_attr_manage_start_stop.attr, + &dev_attr_manage_system_start_stop.attr, + &dev_attr_manage_runtime_start_stop.attr, &dev_attr_protection_type.attr, &dev_attr_protection_mode.attr, &dev_attr_app_tag_own.attr, @@ -3771,13 +3804,20 @@ static void sd_shutdown(struct device *dev) sd_sync_cache(sdkp, NULL); } - if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { + if (system_state != SYSTEM_RESTART && + sdkp->device->manage_system_start_stop) { sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); sd_start_stop_device(sdkp, 0); } } -static int sd_suspend_common(struct device *dev, bool ignore_stop_errors) +static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime) +{ + return (sdev->manage_system_start_stop && !runtime) || + (sdev->manage_runtime_start_stop && runtime); +} + +static int sd_suspend_common(struct device *dev, bool runtime) { struct scsi_disk *sdkp = dev_get_drvdata(dev); struct scsi_sense_hdr sshdr; @@ -3809,12 +3849,12 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors) } } - if (sdkp->device->manage_start_stop) { + if (sd_do_start_stop(sdkp->device, runtime)) { if (!sdkp->device->silence_suspend) sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); /* an error is not worth aborting a system sleep */ ret = sd_start_stop_device(sdkp, 0); - if (ignore_stop_errors) + if (!runtime) ret = 0; } @@ -3826,23 +3866,23 @@ static int sd_suspend_system(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - return sd_suspend_common(dev, true); + return sd_suspend_common(dev, false); } static int sd_suspend_runtime(struct device *dev) { - return sd_suspend_common(dev, false); + return sd_suspend_common(dev, true); } -static int sd_resume(struct device *dev) +static int sd_resume(struct device *dev, bool runtime) { struct scsi_disk *sdkp = dev_get_drvdata(dev); - int ret = 0; + int ret; if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */ return 0; - if (!sdkp->device->manage_start_stop) + if (!sd_do_start_stop(sdkp->device, runtime)) return 0; if (!sdkp->device->no_start_on_resume) { @@ -3860,7 +3900,7 @@ static int sd_resume_system(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - return sd_resume(dev); + return sd_resume(dev, false); } static int sd_resume_runtime(struct device *dev) @@ -3887,7 +3927,7 @@ static int sd_resume_runtime(struct device *dev) "Failed to clear sense data\n"); } - return sd_resume(dev); + return sd_resume(dev, true); } static const struct dev_pm_ops sd_pm_ops = { diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index b9230b6add04..b7df1e6da969 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -193,7 +193,8 @@ struct scsi_device { unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */ unsigned no_start_on_add:1; /* do not issue start on add */ unsigned allow_restart:1; /* issue START_UNIT in error handler */ - unsigned manage_start_stop:1; /* Let HLD (sd) manage start/stop */ + unsigned manage_system_start_stop:1; /* Let HLD (sd) manage system start/stop */ + unsigned manage_runtime_start_stop:1; /* Let HLD (sd) manage runtime start/stop */ unsigned no_start_on_resume:1; /* Do not issue START_STOP_UNIT on resume */ unsigned start_stop_pwr_cond:1; /* Set power cond. in START_STOP_UNIT */ unsigned no_uld_attach:1; /* disable connecting to upper level drivers */ From patchwork Thu Sep 21 18:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9ECEE7D0AC for ; Thu, 21 Sep 2023 20:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232032AbjIUU6Y (ORCPT ); Thu, 21 Sep 2023 16:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231871AbjIUU6D (ORCPT ); Thu, 21 Sep 2023 16:58:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BCEFB0122; Thu, 21 Sep 2023 11:08:10 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B45BEC433C7; Thu, 21 Sep 2023 18:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319690; bh=Ykmr0m37Ms0U7IaLonr7YDkxDiTRAMQDXAHe4znh4aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SFoM56C3iIqUihfi2XHC9GF6YoFGLbP6gX5E3EFBvEn6s9Dq+k/DgWhYlBEVCXjoZ u5enBxAxwU4aBGQLlZJraVdVpis+8kHy8xyUv7jYYTlFnUTbDNGZpLMN3RbwGTMhjq SIzddZmGB+9X9oKGvRbRzvD9Njd9uVxpuE3P7TZsS1e7faoXuiKDzjW8/y1asgNmEd 3h69P3d6KlhTgV9Mytsqx6DumITyRz4lzovlXY+ejjOjA62lVZfeQG7fMcRwvlamXU 7lfvw/xKm6UCwv2rdcYNfkVbNSjnqZ3islWfYkFCTDemt20LUk9sxr4sbA3HLndfbb lq1d805rtRwdw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 05/23] ata: libata-scsi: Disable scsi device manage_system_start_stop Date: Fri, 22 Sep 2023 03:07:40 +0900 Message-ID: <20230921180758.955317-6-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The introduction of a device link to create a consumer/supplier relationship between the scsi device of an ATA device and the ATA port of that ATA device fixes the ordering of system suspend and resume operations. For suspend, the scsi device is suspended first and the ata port after it. This is fine as this allows the synchronize cache and START STOP UNIT commands issued by the scsi disk driver to be executed before the ata port is disabled. For resume operations, the ata port is resumed first, followed by the scsi device. This allows having the request queue of the scsi device to be unfrozen after the ata port resume is scheduled in EH, thus avoiding to see new requests prematurely issued to the ATA device. Since libata sets manage_system_start_stop to 1, the scsi disk resume operation also results in issuing a START STOP UNIT command to the device being resumed so that the device exits standby power mode. However, restoring the ATA device to the active power mode must be synchronized with libata EH processing of the port resume operation to avoid either 1) seeing the start stop unit command being received too early when the port is not yet resumed and ready to accept commands, or after the port resume process issues commands such as IDENTIFY to revalidate the device. In this last case, the risk is that the device revalidation fails with timeout errors as the drive is still spun down. Commit 0a8589055936 ("ata,scsi: do not issue START STOP UNIT on resume") disabled issuing the START STOP UNIT command to avoid issues with it. But this is incorrect as transitioning a device to the active power mode from the standby power mode set on suspend requires a media access command. The IDENTIFY, READ LOG and SET FEATURES commands executed in libata EH context triggered by the ata port resume operation may thus fail. Fix these synchronization issues is by handling a device power mode transitions for system suspend and resume directly in libata EH context, without relying on the scsi disk driver management triggered with the manage_system_start_stop flag. To do this, the following libata helper functions are introduced: 1) ata_dev_power_set_standby(): This function issues a STANDBY IMMEDIATE command to transitiom a device to the standby power mode. For HDDs, this spins down the disks. This function applies only to ATA and ZAC devices and does nothing otherwise. This function also does nothing for devices that have the ATA_FLAG_NO_POWEROFF_SPINDOWN or ATA_FLAG_NO_HIBERNATE_SPINDOWN flag set. For suspend, call ata_dev_power_set_standby() in ata_eh_handle_port_suspend() before the port is disabled and frozen. ata_eh_unload() is also modified to transition all enabled devices to the standby power mode when the system is shutdown or devices removed. 2) ata_dev_power_set_active() and This function applies to ATA or ZAC devices and issues a VERIFY command for 1 sector at LBA 0 to transition the device to the active power mode. For HDDs, since this function will complete only once the disk spin up. Its execution uses the same timeouts as for reset, to give the drive enough time to complete spinup without triggering a command timeout. For resume, call ata_dev_power_set_active() in ata_eh_revalidate_and_attach() after the port has been enabled and before any other command is issued to the device. With these changes, the manage_system_start_stop and no_start_on_resume scsi device flags do not need to be set in ata_scsi_dev_config(). The flag manage_runtime_start_stop is still set to allow the sd driver to spinup/spindown a disk through the sd runtime operations. Fixes: 0a8589055936 ("ata,scsi: do not issue START STOP UNIT on resume") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 90 +++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-eh.c | 46 +++++++++++++++++++- drivers/ata/libata-scsi.c | 16 +++---- drivers/ata/libata.h | 2 + include/linux/libata.h | 6 ++- 5 files changed, 148 insertions(+), 12 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 8e35afe5e560..a0bc01606b30 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1972,6 +1972,96 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, return rc; } +/** + * ata_dev_power_set_standby - Set a device power mode to standby + * @dev: target device + * + * Issue a STANDBY IMMEDIATE command to set a device power mode to standby. + * For an HDD device, this spins down the disks. + * + * LOCKING: + * Kernel thread context (may sleep). + */ +void ata_dev_power_set_standby(struct ata_device *dev) +{ + unsigned long ap_flags = dev->link->ap->flags; + struct ata_taskfile tf; + unsigned int err_mask; + + /* Issue STANDBY IMMEDIATE command only if supported by the device */ + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + return; + + /* + * Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5) + * causing some drives to spin up and down again. For these, do nothing + * if we are being called on shutdown. + */ + if ((ap_flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && + system_state == SYSTEM_POWER_OFF) + return; + + if ((ap_flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && + system_entering_hibernation()) + return; + + ata_tf_init(dev, &tf); + tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; + tf.protocol = ATA_PROT_NODATA; + tf.command = ATA_CMD_STANDBYNOW1; + + ata_dev_notice(dev, "Entering standby power mode\n"); + + err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); + if (err_mask) + ata_dev_err(dev, "STANDBY IMMEDIATE failed (err_mask=0x%x)\n", + err_mask); +} + +/** + * ata_dev_power_set_active - Set a device power mode to active + * @dev: target device + * + * Issue a VERIFY command to enter to ensure that the device is in the + * active power mode. For a spun-down HDD (standby or idle power mode), + * the VERIFY command will complete after the disk spins up. + * + * LOCKING: + * Kernel thread context (may sleep). + */ +void ata_dev_power_set_active(struct ata_device *dev) +{ + struct ata_taskfile tf; + unsigned int err_mask; + + /* + * Issue READ VERIFY SECTORS command for 1 sector at lba=0 only + * if supported by the device. + */ + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + return; + + ata_tf_init(dev, &tf); + tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; + tf.protocol = ATA_PROT_NODATA; + tf.command = ATA_CMD_VERIFY; + tf.nsect = 1; + if (dev->flags & ATA_DFLAG_LBA) { + tf.flags |= ATA_TFLAG_LBA; + tf.device |= ATA_LBA; + } else { + /* CHS */ + tf.lbal = 0x1; /* sect */ + } + + ata_dev_notice(dev, "Entering active power mode\n"); + + err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); + if (err_mask) + ata_dev_err(dev, "VERIFY failed (err_mask=0x%x)\n", + err_mask); +} + /** * ata_read_log_page - read a specific log page * @dev: target device diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 4cf4f57e57b8..b1b2c276371e 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -147,6 +147,8 @@ ata_eh_cmd_timeout_table[ATA_EH_CMD_TIMEOUT_TABLE_SIZE] = { .timeouts = ata_eh_other_timeouts, }, { .commands = CMDS(ATA_CMD_FLUSH, ATA_CMD_FLUSH_EXT), .timeouts = ata_eh_flush_timeouts }, + { .commands = CMDS(ATA_CMD_VERIFY), + .timeouts = ata_eh_reset_timeouts }, }; #undef CMDS @@ -498,7 +500,19 @@ static void ata_eh_unload(struct ata_port *ap) struct ata_device *dev; unsigned long flags; - /* Restore SControl IPM and SPD for the next driver and + /* + * Unless we are restarting, transition all enabled devices to + * standby power mode. + */ + if (system_state != SYSTEM_RESTART) { + ata_for_each_link(link, ap, PMP_FIRST) { + ata_for_each_dev(dev, link, ENABLED) + ata_dev_power_set_standby(dev); + } + } + + /* + * Restore SControl IPM and SPD for the next driver and * disable attached devices. */ ata_for_each_link(link, ap, PMP_FIRST) { @@ -684,6 +698,10 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap) ehc->saved_xfer_mode[devno] = dev->xfer_mode; if (ata_ncq_enabled(dev)) ehc->saved_ncq_enabled |= 1 << devno; + + /* If we are resuming, wake up the device */ + if (ap->pflags & ATA_PFLAG_RESUMING) + ehc->i.dev_action[devno] |= ATA_EH_SET_ACTIVE; } } @@ -743,6 +761,8 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap) /* clean up */ spin_lock_irqsave(ap->lock, flags); + ap->pflags &= ~ATA_PFLAG_RESUMING; + if (ap->pflags & ATA_PFLAG_LOADING) ap->pflags &= ~ATA_PFLAG_LOADING; else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) && @@ -1218,6 +1238,13 @@ void ata_eh_detach_dev(struct ata_device *dev) struct ata_eh_context *ehc = &link->eh_context; unsigned long flags; + /* + * If the device is still enabled, transition it to standby power mode + * (i.e. spin down HDDs). + */ + if (ata_dev_enabled(dev)) + ata_dev_power_set_standby(dev); + ata_dev_disable(dev); spin_lock_irqsave(ap->lock, flags); @@ -3016,6 +3043,15 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link, if (ehc->i.flags & ATA_EHI_DID_RESET) readid_flags |= ATA_READID_POSTRESET; + /* + * When resuming, before executing any command, make sure to + * transition the device to the active power mode. + */ + if ((action & ATA_EH_SET_ACTIVE) && ata_dev_enabled(dev)) { + ata_dev_power_set_active(dev); + ata_eh_done(link, dev, ATA_EH_SET_ACTIVE); + } + if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { WARN_ON(dev->class == ATA_DEV_PMP); @@ -3989,6 +4025,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap) unsigned long flags; int rc = 0; struct ata_device *dev; + struct ata_link *link; /* are we suspending? */ spin_lock_irqsave(ap->lock, flags); @@ -4001,6 +4038,12 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap) WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); + /* Set all devices attached to the port in standby mode */ + ata_for_each_link(link, ap, HOST_FIRST) { + ata_for_each_dev(dev, link, ENABLED) + ata_dev_power_set_standby(dev); + } + /* * If we have a ZPODD attached, check its zero * power ready status before the port is frozen. @@ -4083,6 +4126,7 @@ static void ata_eh_handle_port_resume(struct ata_port *ap) /* update the flags */ spin_lock_irqsave(ap->lock, flags); ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); + ap->pflags |= ATA_PFLAG_RESUMING; spin_unlock_irqrestore(ap->lock, flags); } #endif /* CONFIG_PM */ diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 58777d4485a1..a69d63e7b919 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1050,15 +1050,13 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) } } else { sdev->sector_size = ata_id_logical_sector_size(dev->id); + /* - * Stop the drive on suspend but do not issue START STOP UNIT - * on resume as this is not necessary and may fail: the device - * will be woken up by ata_port_pm_resume() with a port reset - * and device revalidation. + * Ask the sd driver to issue START STOP UNIT on runtime suspend + * and resume only. For system level suspend/resume, devices + * power state is handled directly by libata EH. */ - sdev->manage_system_start_stop = 1; sdev->manage_runtime_start_stop = 1; - sdev->no_start_on_resume = 1; } /* @@ -1231,7 +1229,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) } if (cdb[4] & 0x1) { - tf->nsect = 1; /* 1 sector, lba=0 */ + tf->nsect = 1; /* 1 sector, lba=0 */ if (qc->dev->flags & ATA_DFLAG_LBA) { tf->flags |= ATA_TFLAG_LBA; @@ -1247,7 +1245,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) tf->lbah = 0x0; /* cyl high */ } - tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ + tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ } else { /* Some odd clown BIOSen issue spindown on power off (ACPI S4 * or S5) causing some drives to spin up and down again. @@ -1257,7 +1255,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) goto skip; if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && - system_entering_hibernation()) + system_entering_hibernation()) goto skip; /* Issue ATA STANDBY IMMEDIATE command */ diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 6e7d352803bd..820299bd9d06 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -60,6 +60,8 @@ extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags); extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, unsigned int readid_flags); extern int ata_dev_configure(struct ata_device *dev); +extern void ata_dev_power_set_standby(struct ata_device *dev); +extern void ata_dev_power_set_active(struct ata_device *dev); extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); extern unsigned int ata_dev_set_feature(struct ata_device *dev, diff --git a/include/linux/libata.h b/include/linux/libata.h index 4ece1b7a2a5b..00b4a2b7819a 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -192,6 +192,7 @@ enum { ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */ ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */ + ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */ ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */ ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */ ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */ @@ -318,9 +319,10 @@ enum { ATA_EH_ENABLE_LINK = (1 << 3), ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */ ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */ + ATA_EH_SET_ACTIVE = (1 << 7), /* Set a device to active power mode */ ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK | - ATA_EH_GET_SUCCESS_SENSE, + ATA_EH_GET_SUCCESS_SENSE | ATA_EH_SET_ACTIVE, ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET | ATA_EH_ENABLE_LINK, @@ -357,7 +359,7 @@ enum { /* This should match the actual table size of * ata_eh_cmd_timeout_table in libata-eh.c. */ - ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 7, + ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8, /* Horkage types. May be set by libata or controller on drives (some horkage may be drive/controller pair dependent */ From patchwork Thu Sep 21 18:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D51D0E7D0AB for ; Thu, 21 Sep 2023 20:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232244AbjIUU5f (ORCPT ); Thu, 21 Sep 2023 16:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232145AbjIUU5W (ORCPT ); Thu, 21 Sep 2023 16:57:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3250DB0129; Thu, 21 Sep 2023 11:08:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B221C433C9; Thu, 21 Sep 2023 18:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319692; bh=9R02ooJRIGAO910Ao7dxldyVJ6mm4+mDCWu7Vrp2rsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYEvEci5elfemTrd1B6GJDmQ1S5lWe/jJYOBv1+Br29rcV1WGgNR+GY31ATGfWR+U 34LlIh3uZcVYaUNaaAZDpslRs9LnAv2vh2aKlZXyUE646oXGa2sRv3nzSoW7bOJYB4 WotIPUs1+HjwIEd8DNtwXwt2/v5J+0F/U8emCGFuLEkp6JebSuWkNkS1l5yMFKmv0I M5m82O2EhqRj5+UJ8oFN7E9yQuilUbLniUi3JQChMaOUTDmfXjRmn4QTfpzQR7LzNG Kc3md0NtEiAq0fTKbnm8I/3ZOTflIozdynoHxLHKGg4nlW4nD+sCKyJe1yG0ze6B0W FFMp7ppC9j/6A== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 06/23] scsi: Do not attempt to rescan suspended devices Date: Fri, 22 Sep 2023 03:07:41 +0900 Message-ID: <20230921180758.955317-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_rescan_device() takes a scsi device lock before executing a device handler and device driver rescan methods. Waiting for the completion of any command issued to the device by these methods will thus be done with the device lock held. As a result, there is a risk of deadlocking within the power management code if scsi_rescan_device() is called to handle a device resume with the associated scsi device not yet resumed. Avoid such situation by checking that the target scsi device is in the running state, that is, fully capable of executing commands, before proceeding with the rescan and bailout returning -EWOULDBLOCK otherwise. With this error return, the caller can retry rescaning the device after a delay. The state check is done with the device lock held and is thus safe against incoming suspend power management operations. Fixes: 6aa0365a3c85 ("ata: libata-scsi: Avoid deadlock on rescan after device resume") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Niklas Cassel Tested-by: Geert Uytterhoeven --- drivers/scsi/scsi_scan.c | 18 +++++++++++++++++- include/scsi/scsi_host.h | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 52014b2d39e1..3db4d31a03a1 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1619,12 +1619,24 @@ int scsi_add_device(struct Scsi_Host *host, uint channel, } EXPORT_SYMBOL(scsi_add_device); -void scsi_rescan_device(struct scsi_device *sdev) +int scsi_rescan_device(struct scsi_device *sdev) { struct device *dev = &sdev->sdev_gendev; + int ret = 0; device_lock(dev); + /* + * Bail out if the device is not running. Otherwise, the rescan may + * block waiting for commands to be executed, with us holding the + * device lock. This can result in a potential deadlock in the power + * management core code when system resume is on-going. + */ + if (sdev->sdev_state != SDEV_RUNNING) { + ret = -EWOULDBLOCK; + goto unlock; + } + scsi_attach_vpd(sdev); scsi_cdl_check(sdev); @@ -1638,7 +1650,11 @@ void scsi_rescan_device(struct scsi_device *sdev) drv->rescan(dev); module_put(dev->driver->owner); } + +unlock: device_unlock(dev); + + return ret; } EXPORT_SYMBOL(scsi_rescan_device); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 49f768d0ff37..4c2dc8150c6d 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -764,7 +764,7 @@ scsi_template_proc_dir(const struct scsi_host_template *sht); #define scsi_template_proc_dir(sht) NULL #endif extern void scsi_scan_host(struct Scsi_Host *); -extern void scsi_rescan_device(struct scsi_device *); +extern int scsi_rescan_device(struct scsi_device *sdev); extern void scsi_remove_host(struct Scsi_Host *); extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *); extern int scsi_host_busy(struct Scsi_Host *shost); From patchwork Thu Sep 21 18:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48130E7D0A6 for ; Thu, 21 Sep 2023 18:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbjIUSeb (ORCPT ); Thu, 21 Sep 2023 14:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjIUSe2 (ORCPT ); Thu, 21 Sep 2023 14:34:28 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 070A7B0130; Thu, 21 Sep 2023 11:08:14 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 602AEC433CA; Thu, 21 Sep 2023 18:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319693; bh=rJW129HUEI+i7sEOi+MwFJDKZiE3wWYKpSxhauMI17E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D3us8PrAXFEoGq+DaSyZkF1xTjM6wIWqXQTyWcOVLoJEEhGOWDU+hNE3fv27IUWlw pl7UYmPh6jBm4uBDUnXE0B/5P+zLDEZWP+OqVBogRUpAAO0jAtABuBvYQO6quJGJSn 3Iex73oLQ4e4/caniuR+JLKumVRd3JA/B2Xf+x5WSYc+W/MyPqvOEh9PMIyntkPL8D ueQi/Cb6BjjCPjgWa12tROlKQSY7aNl5fCqYM8blzfruEf6GYtLoqRJy7V9ZNCKouJ v1c6Su+y2ugjWQJ8D+fFTTuLYam1jxOItrxANHrGF+grg7y0wcmU/f7dMYF7DB4IIc /8eS+bGmyJErQ== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 07/23] ata: libata-scsi: Fix delayed scsi_rescan_device() execution Date: Fri, 22 Sep 2023 03:07:42 +0900 Message-ID: <20230921180758.955317-8-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit 6aa0365a3c85 ("ata: libata-scsi: Avoid deadlock on rescan after device resume") modified ata_scsi_dev_rescan() to check the scsi device "is_suspended" power field to ensure that the scsi device associated with an ATA device is fully resumed when scsi_rescan_device() is executed. However, this fix is problematic as: 1) It relies on a PM internal field that should not be used without PM device locking protection. 2) The check for is_suspended and the call to scsi_rescan_device() are not atomic and a suspend PM event may be triggered between them, casuing scsi_rescan_device() to be called on a suspended device and in that function blocking while holding the scsi device lock. This would deadlock a following resume operation. These problems can trigger PM deadlocks on resume, especially with resume operations triggered quickly after or during suspend operations. E.g., a simple bash script like: for (( i=0; i<10; i++ )); do echo "+2 > /sys/class/rtc/rtc0/wakealarm echo mem > /sys/power/state done that triggers a resume 2 seconds after starting suspending a system can quickly lead to a PM deadlock preventing the system from correctly resuming. Fix this by replacing the check on is_suspended with a check on the return value given by scsi_rescan_device() as that function will fail if called against a suspended device. Also make sure rescan tasks already scheduled are first cancelled before suspending an ata port. Fixes: 6aa0365a3c85 ("ata: libata-scsi: Avoid deadlock on rescan after device resume") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Niklas Cassel Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 16 ++++++++++++++++ drivers/ata/libata-scsi.c | 33 +++++++++++++++------------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index a0bc01606b30..092372334e92 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5168,11 +5168,27 @@ static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) { + /* + * We are about to suspend the port, so we do not care about + * scsi_rescan_device() calls scheduled by previous resume operations. + * The next resume will schedule the rescan again. So cancel any rescan + * that is not done yet. + */ + cancel_delayed_work_sync(&ap->scsi_rescan_task); + ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false); } static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg) { + /* + * We are about to suspend the port, so we do not care about + * scsi_rescan_device() calls scheduled by previous resume operations. + * The next resume will schedule the rescan again. So cancel any rescan + * that is not done yet. + */ + cancel_delayed_work_sync(&ap->scsi_rescan_task); + ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true); } diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a69d63e7b919..576bb51cb480 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -4756,7 +4756,7 @@ void ata_scsi_dev_rescan(struct work_struct *work) struct ata_link *link; struct ata_device *dev; unsigned long flags; - bool delay_rescan = false; + int ret = 0; mutex_lock(&ap->scsi_scan_mutex); spin_lock_irqsave(ap->lock, flags); @@ -4765,37 +4765,34 @@ void ata_scsi_dev_rescan(struct work_struct *work) ata_for_each_dev(dev, link, ENABLED) { struct scsi_device *sdev = dev->sdev; + /* + * If the port was suspended before this was scheduled, + * bail out. + */ + if (ap->pflags & ATA_PFLAG_SUSPENDED) + goto unlock; + if (!sdev) continue; if (scsi_device_get(sdev)) continue; - /* - * If the rescan work was scheduled because of a resume - * event, the port is already fully resumed, but the - * SCSI device may not yet be fully resumed. In such - * case, executing scsi_rescan_device() may cause a - * deadlock with the PM code on device_lock(). Prevent - * this by giving up and retrying rescan after a short - * delay. - */ - delay_rescan = sdev->sdev_gendev.power.is_suspended; - if (delay_rescan) { - scsi_device_put(sdev); - break; - } - spin_unlock_irqrestore(ap->lock, flags); - scsi_rescan_device(sdev); + ret = scsi_rescan_device(sdev); scsi_device_put(sdev); spin_lock_irqsave(ap->lock, flags); + + if (ret) + goto unlock; } } +unlock: spin_unlock_irqrestore(ap->lock, flags); mutex_unlock(&ap->scsi_scan_mutex); - if (delay_rescan) + /* Reschedule with a delay if scsi_rescan_device() returned an error */ + if (ret) schedule_delayed_work(&ap->scsi_rescan_task, msecs_to_jiffies(5)); } From patchwork Thu Sep 21 18:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF2AE7D0B1 for ; Thu, 21 Sep 2023 21:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232484AbjIUVFx (ORCPT ); Thu, 21 Sep 2023 17:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233157AbjIUVF2 (ORCPT ); Thu, 21 Sep 2023 17:05:28 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA6D5B0136; Thu, 21 Sep 2023 11:08:15 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35BB9C433C7; Thu, 21 Sep 2023 18:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319695; bh=yFVI3XiHN91xLLgttKoQE8a4FI+N6bOu1WdRwo4jr2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBA+X+7nVQQCpEn19dj73lrOfTA527ctByOEgq8G7G8ALb7zNJVhuIOfl58j8VIVC 8Pw+bwHrlUm59yITCEDvMkoY0MC1EQ+DAxJS2mu37Xbo9sMo4tnbi494WM4ZaZR6yX 2hMrhwBummYJTzSye/vkMAlSFGs4US7R9pCsRJV1NIJhbBGhn3s+RuVopZxrIi9tUo mMNw2ETKp7wJ+5Avsy3tzzg1Ym99h74hkLbYPl6jg5KNm/v11q4E1etkC99pC4j2Bh wU7oZokKzA1LBxUUXDYWFr+4AJMCVWfOvN48DzLnzbTnD8gmA3okz8G//kzfw1upqb Fqq31zZm4ZwRw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 08/23] ata: libata-core: Do not register PM operations for SAS ports Date: Fri, 22 Sep 2023 03:07:43 +0900 Message-ID: <20230921180758.955317-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 --- drivers/ata/libata-core.c | 2 +- drivers/ata/libata-transport.c | 9 ++++++++- drivers/ata/libata.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 092372334e92..261445c1851b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5335,7 +5335,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 diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index e4fb9d1b9b39..3e49a877500e 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -266,6 +266,10 @@ void ata_tport_delete(struct ata_port *ap) 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); diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 820299bd9d06..05ac80da8ebc 100644 --- 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; From patchwork Thu Sep 21 18:07:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394804 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0817AE7D0AB for ; Thu, 21 Sep 2023 22:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbjIUWMU (ORCPT ); Thu, 21 Sep 2023 18:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233003AbjIUWL5 (ORCPT ); Thu, 21 Sep 2023 18:11:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F0AB0138; Thu, 21 Sep 2023 11:08:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AC05C433C8; Thu, 21 Sep 2023 18:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319697; bh=O7oF0hNk00rZAS4qiKFR+aE3J/ZVsOyz8wvJQD0MWAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQ3bcOz5jQb5XhY57ROY9l6yu0YImQhMZ76XS87mFLmjXHDmz0XS/LvYu7r2Ta/7D 7yE5Z6vMWD/qz13kJn6y5d0HbDcUKCecJBXIFvyPWESPIT5OLpuy9TMUAdVwiVhkAh 7Y5OHAVnUVHToPVSEk3k5o9JZLyGH/S758xPmyYzCNszfK00tPY6YrDedy4wAMkdjd duda1i7/HcfaLv3UdVBwmqkrRXsvJ3H04P3+zLhXYPir2Du9rWe02QD8VFxX8vFGwL I3KnlMNkOIZI/y6ODzRXDUIqRMG5C2FFzffe6c30uk3JJtXBmc9RYxQk4ydbGfeFUU DV1hn1hb8+vbw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 09/23] scsi: sd: Do not issue commands to suspended disks on shutdown Date: Fri, 22 Sep 2023 03:07:44 +0900 Message-ID: <20230921180758.955317-10-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If an error occurs when resuming a host adapter before the devices attached to the adapter are resumed, the adapter low level driver may remove the scsi host, resulting in a call to sd_remove() for the disks of the host. This in turn results in a call to sd_shutdown() which will issue a synchronize cache command and a start stop unit command to spindown the disk. sd_shutdown() issues the commands only if the device is not already suspended but does not check the power state for system-wide suspend/resume. That is, the commands may be issued with the device in a suspended state, which causes PM resume to hang, forcing a reset of the machine to recover. Fix this by not calling sd_shutdown() in sd_remove() if the device is not running. Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Bart Van Assche Tested-by: Geert Uytterhoeven --- drivers/scsi/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 1d106c8ad5af..d86306d42445 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3727,7 +3727,8 @@ static int sd_remove(struct device *dev) device_del(&sdkp->disk_dev); del_gendisk(sdkp->disk); - sd_shutdown(dev); + if (sdkp->device->sdev_state == SDEV_RUNNING) + sd_shutdown(dev); put_disk(sdkp->disk); return 0; From patchwork Thu Sep 21 18:07:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 763ADE7D0AB for ; Thu, 21 Sep 2023 22:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232983AbjIUWLP (ORCPT ); Thu, 21 Sep 2023 18:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjIUWK5 (ORCPT ); Thu, 21 Sep 2023 18:10:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EB52B013A; Thu, 21 Sep 2023 11:08:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4053C433CA; Thu, 21 Sep 2023 18:08:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319699; bh=G7myf7/7kymZWUjrZz61j4PQ6SQiep0pKQ5dhdCyLtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ghlKenue/uvvjvH0a5PRtuN2WL2FBzb9jmZpzloX2p0QG2wM81S2S1DqGIqyIIQou 5SMKpnBBmrPkI1S60d8mZLOIy/kncFtsREyb0eHZyjfFmwhH9xc1/R1HKZGVA9rQ9j J/iHdaVR//UhEZmLdnuFk3Jyv6RXklqUlj/cUc+eX7lVc2XFp9Qg1boj+cLnypcMLi vFdBQg16ZYWLb1kl1lhwOqwvFhyOFbhrVdLSBTGkKqi/Q/dsIVFP22+N4jtXEqmEVX DCsS+I3xNMe37ZIRTjPSgBa2zc+zQdtQtuftz6xzPf0Wj6NjN1bqpmcYh7FplTINLi 1zW9pTJzy7h3w== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 10/23] ata: libata-core: Fix compilation warning in ata_dev_config_ncq() Date: Fri, 22 Sep 2023 03:07:45 +0900 Message-ID: <20230921180758.955317-11-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The 24 bytes length allocated to the ncq_desc string in ata_dev_config_lba() for ata_dev_config_ncq() to use is too short, causing the following gcc compilation warnings when compiling with W=1: drivers/ata/libata-core.c: In function ‘ata_dev_configure’: drivers/ata/libata-core.c:2378:56: warning: ‘%d’ directive output may be truncated writing between 1 and 2 bytes into a region of size between 1 and 11 [-Wformat-truncation=] 2378 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth, | ^~ In function ‘ata_dev_config_ncq’, inlined from ‘ata_dev_config_lba’ at drivers/ata/libata-core.c:2649:8, inlined from ‘ata_dev_configure’ at drivers/ata/libata-core.c:2952:9: drivers/ata/libata-core.c:2378:41: note: directive argument in the range [1, 32] 2378 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth, | ^~~~~~~~~~~~~~~~~~~~~ drivers/ata/libata-core.c:2378:17: note: ‘snprintf’ output between 16 and 31 bytes into a destination of size 24 2378 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2379 | ddepth, aa_desc); | ~~~~~~~~~~~~~~~~ Avoid these warnings and the potential truncation by changing the size of the ncq_desc string to 32 characters. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 261445c1851b..d8cc1e27a125 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2619,7 +2619,7 @@ static int ata_dev_config_lba(struct ata_device *dev) { const u16 *id = dev->id; const char *lba_desc; - char ncq_desc[24]; + char ncq_desc[32]; int ret; dev->flags |= ATA_DFLAG_LBA; From patchwork Thu Sep 21 18:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFB35E7D0AE for ; Thu, 21 Sep 2023 21:01:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232391AbjIUVBH (ORCPT ); Thu, 21 Sep 2023 17:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbjIUVAi (ORCPT ); Thu, 21 Sep 2023 17:00:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D4B4B013B; Thu, 21 Sep 2023 11:08:21 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABF5AC433C7; Thu, 21 Sep 2023 18:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319701; bh=ClHV0GWD00piISaODu4sGP0323PoYQkSONnwrIEED3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/4m0YuJBPPFYUdeJtHh/aEjYUxsdkrgWC6pOvORsEyYKRtEzUsg630cML+0DfJiZ uobOXEI0BzOLCHeIbSQtAddiEiSOFJAADLfu14XFjBq4Djyx1sESG0WunfKM4dQ6tf S4x+fyQSfYpltPHpWvf+/GK6s/fX1XGfG/6aqzfu0q47mA9rGstxaPnIpYyXW3FErb igpw38ZYBTgkyG6btB5TZNGhc/PDdc1vTfYK4j5JjyK3nZ4WNpWIKOx4hVkuIPZmcm ysMtNFujoRhikavfVM/ZxuPnQKjRGQzobJGfOcVesKnkhfSkYwLm9/Y9pYcEGGZJGo YaO/orFEihKFw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 11/23] ata: libata-eh: Fix compilation warning in ata_eh_link_report() Date: Fri, 22 Sep 2023 03:07:46 +0900 Message-ID: <20230921180758.955317-12-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The 6 bytes length of the tries_buf string in ata_eh_link_report() is too short and results in a gcc compilation warning with W-!: drivers/ata/libata-eh.c: In function ‘ata_eh_link_report’: drivers/ata/libata-eh.c:2371:59: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=] 2371 | snprintf(tries_buf, sizeof(tries_buf), " t%d", | ^~ drivers/ata/libata-eh.c:2371:56: note: directive argument in the range [-2147483648, 4] 2371 | snprintf(tries_buf, sizeof(tries_buf), " t%d", | ^~~~~~ drivers/ata/libata-eh.c:2371:17: note: ‘snprintf’ output between 4 and 14 bytes into a destination of size 6 2371 | snprintf(tries_buf, sizeof(tries_buf), " t%d", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2372 | ap->eh_tries); | ~~~~~~~~~~~~~ Avoid this warning by increasing the string size to 16B. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Geert Uytterhoeven --- drivers/ata/libata-eh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index b1b2c276371e..5686353e442c 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -2332,7 +2332,7 @@ static void ata_eh_link_report(struct ata_link *link) struct ata_eh_context *ehc = &link->eh_context; struct ata_queued_cmd *qc; const char *frozen, *desc; - char tries_buf[6] = ""; + char tries_buf[16] = ""; int tag, nr_failed = 0; if (ehc->i.flags & ATA_EHI_QUIET) From patchwork Thu Sep 21 18:07:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 822EBE7D0B5 for ; Thu, 21 Sep 2023 22:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbjIUWG5 (ORCPT ); Thu, 21 Sep 2023 18:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232947AbjIUWGi (ORCPT ); Thu, 21 Sep 2023 18:06:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB3FB058A; Thu, 21 Sep 2023 11:08:23 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 874CEC433C8; Thu, 21 Sep 2023 18:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319703; bh=l887FWy982+b8+dc5o3XhtTTM99Br2AApyXv7V0jC3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5SKkJs29gGux657up+KDjbWaq8Kiu59yyLjTmp4x5aHwgqqNd1EmlXrQbytCm4FR DlBicEjNqxGhRv4NcELziR03kv59oh49tC06b8eh3yk/z3oKbxAcK+86mE36OI+Azl I+fh4Of7inyZO3AQDPe4GN6lX53oOOLUf7b6Yb+nsMdDttipUp2vAcwDpnXDkMKFVE 7lU1TdQnxH/RRR8FZX92r5WADEdIuoI8Wbq/dNfdYhC3jSNaj8iWV8cJm4RvjKzTAE 8s2HdGsy1dqyM83qrJ7VuIrFqmgX5IoBXYsveSj5F3DsZlG/wRjNYVnSgSAo6lfBR/ qwziMMw8bssIw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 12/23] scsi: Remove scsi device no_start_on_resume flag Date: Fri, 22 Sep 2023 03:07:47 +0900 Message-ID: <20230921180758.955317-13-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The scsi device flag no_start_on_resume is not set by any scsi low level driver. Remove it. This reverts the changes introduced by commit 0a8589055936 ("ata,scsi: do not issue START STOP UNIT on resume"). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/scsi/sd.c | 7 ++----- include/scsi/scsi_device.h | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index d86306d42445..49e9b4ce2e33 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3886,11 +3886,8 @@ static int sd_resume(struct device *dev, bool runtime) if (!sd_do_start_stop(sdkp->device, runtime)) return 0; - if (!sdkp->device->no_start_on_resume) { - sd_printk(KERN_NOTICE, sdkp, "Starting disk\n"); - ret = sd_start_stop_device(sdkp, 1); - } - + sd_printk(KERN_NOTICE, sdkp, "Starting disk\n"); + ret = sd_start_stop_device(sdkp, 1); if (!ret) opal_unlock_from_suspend(sdkp->opal_dev); return ret; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index b7df1e6da969..8db0c88cf48e 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -195,7 +195,6 @@ struct scsi_device { unsigned allow_restart:1; /* issue START_UNIT in error handler */ unsigned manage_system_start_stop:1; /* Let HLD (sd) manage system start/stop */ unsigned manage_runtime_start_stop:1; /* Let HLD (sd) manage runtime start/stop */ - unsigned no_start_on_resume:1; /* Do not issue START_STOP_UNIT on resume */ unsigned start_stop_pwr_cond:1; /* Set power cond. in START_STOP_UNIT */ unsigned no_uld_attach:1; /* disable connecting to upper level drivers */ unsigned select_no_atn:1; From patchwork Thu Sep 21 18:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93926E7D0A2 for ; Thu, 21 Sep 2023 18:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbjIUSfH (ORCPT ); Thu, 21 Sep 2023 14:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjIUSep (ORCPT ); Thu, 21 Sep 2023 14:34:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02E88B058C; Thu, 21 Sep 2023 11:08:25 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D09FC433C9; Thu, 21 Sep 2023 18:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319704; bh=K53psrarMmyE+9oT2jvLK5EdxWh6n+tkA6hBRvDkc3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iOzVUR/zuKyI/tBjNhw+pNsN96PKmsI53J9gWvZ4sMS1p5vvwWasgu88vsZm9iUmp fZzD9dunN4Uus4Z3oH9ds3Dgb+HC4Kp/nEQg4UuqgUOh1jIGV8fN0NSu0aBNXAQESz mZkbNlVlGUc6ZMkL+JB+kFgs/ueF7B17OFTBBNO33CaRu7bleKmO1WtdxcKpGOeb0F qoJ19YidwvVHSnYHCK1cZCxvCln/wJcNaNraXlztbNnUC0mwwhsi2h7Y30rUUFNdam 3+Qzyw4xOA+ISnOgi82EUBaDcY0xNefqS1ATyaVpS1OFkF9tW2ESPV2Np1hrKgo9qz piF9zt5EwYqMQ== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 13/23] ata: libata-scsi: Cleanup ata_scsi_start_stop_xlat() Date: Fri, 22 Sep 2023 03:07:48 +0900 Message-ID: <20230921180758.955317-14-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Now that libata does its own internal device power mode management through libata EH, the scsi disk driver will not issue START STOP UNIT commands anymore. We can receive this command only from user passthrough operations. So there is no need to consider the system state and ATA port flags for suspend to translate the command. Since setting up the taskfile for the verify and standby immediate commands is the same as done in ata_dev_power_set_active() and ata_dev_power_set_standby(), factor out this code into the helper function ata_dev_power_init_tf() to simplify ata_scsi_start_stop_xlat() as well as ata_dev_power_set_active() and ata_dev_power_set_standby(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 55 +++++++++++++++++++++++---------------- drivers/ata/libata-scsi.c | 53 +++++++------------------------------ drivers/ata/libata.h | 2 ++ 3 files changed, 44 insertions(+), 66 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index d8cc1e27a125..8e326a445765 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1972,6 +1972,35 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, return rc; } +bool ata_dev_power_init_tf(struct ata_device *dev, struct ata_taskfile *tf, + bool set_active) +{ + /* Only applies to ATA and ZAC devices */ + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + return false; + + ata_tf_init(dev, tf); + tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; + tf->protocol = ATA_PROT_NODATA; + + if (set_active) { + /* VERIFY for 1 sector at lba=0 */ + tf->command = ATA_CMD_VERIFY; + tf->nsect = 1; + if (dev->flags & ATA_DFLAG_LBA) { + tf->flags |= ATA_TFLAG_LBA; + tf->device |= ATA_LBA; + } else { + /* CHS */ + tf->lbal = 0x1; /* sect */ + } + } else { + tf->command = ATA_CMD_STANDBYNOW1; + } + + return true; +} + /** * ata_dev_power_set_standby - Set a device power mode to standby * @dev: target device @@ -1988,10 +2017,6 @@ void ata_dev_power_set_standby(struct ata_device *dev) struct ata_taskfile tf; unsigned int err_mask; - /* Issue STANDBY IMMEDIATE command only if supported by the device */ - if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) - return; - /* * Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5) * causing some drives to spin up and down again. For these, do nothing @@ -2005,10 +2030,9 @@ void ata_dev_power_set_standby(struct ata_device *dev) system_entering_hibernation()) return; - ata_tf_init(dev, &tf); - tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf.protocol = ATA_PROT_NODATA; - tf.command = ATA_CMD_STANDBYNOW1; + /* Issue STANDBY IMMEDIATE command only if supported by the device */ + if (!ata_dev_power_init_tf(dev, &tf, false)) + return; ata_dev_notice(dev, "Entering standby power mode\n"); @@ -2038,22 +2062,9 @@ void ata_dev_power_set_active(struct ata_device *dev) * Issue READ VERIFY SECTORS command for 1 sector at lba=0 only * if supported by the device. */ - if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + if (!ata_dev_power_init_tf(dev, &tf, true)) return; - ata_tf_init(dev, &tf); - tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf.protocol = ATA_PROT_NODATA; - tf.command = ATA_CMD_VERIFY; - tf.nsect = 1; - if (dev->flags & ATA_DFLAG_LBA) { - tf.flags |= ATA_TFLAG_LBA; - tf.device |= ATA_LBA; - } else { - /* CHS */ - tf.lbal = 0x1; /* sect */ - } - ata_dev_notice(dev, "Entering active power mode\n"); err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 576bb51cb480..ad6dbb31a163 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1202,7 +1202,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) { struct scsi_cmnd *scmd = qc->scsicmd; - struct ata_taskfile *tf = &qc->tf; const u8 *cdb = scmd->cmnd; u16 fp; u8 bp = 0xff; @@ -1212,54 +1211,24 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) goto invalid_fld; } - tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf->protocol = ATA_PROT_NODATA; - if (cdb[1] & 0x1) { - ; /* ignore IMMED bit, violates sat-r05 */ - } + /* LOEJ bit set not supported */ if (cdb[4] & 0x2) { fp = 4; bp = 1; - goto invalid_fld; /* LOEJ bit set not supported */ + goto invalid_fld; } + + /* Power conditions not supported */ if (((cdb[4] >> 4) & 0xf) != 0) { fp = 4; bp = 3; - goto invalid_fld; /* power conditions not supported */ + goto invalid_fld; } - if (cdb[4] & 0x1) { - tf->nsect = 1; /* 1 sector, lba=0 */ - - if (qc->dev->flags & ATA_DFLAG_LBA) { - tf->flags |= ATA_TFLAG_LBA; - - tf->lbah = 0x0; - tf->lbam = 0x0; - tf->lbal = 0x0; - tf->device |= ATA_LBA; - } else { - /* CHS */ - tf->lbal = 0x1; /* sect */ - tf->lbam = 0x0; /* cyl low */ - tf->lbah = 0x0; /* cyl high */ - } - - tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ - } else { - /* Some odd clown BIOSen issue spindown on power off (ACPI S4 - * or S5) causing some drives to spin up and down again. - */ - if ((qc->ap->flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && - system_state == SYSTEM_POWER_OFF) - goto skip; - - if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && - system_entering_hibernation()) - goto skip; - - /* Issue ATA STANDBY IMMEDIATE command */ - tf->command = ATA_CMD_STANDBYNOW1; + /* Ignore IMMED bit (cdb[1] & 0x1), violates sat-r05 */ + if (!ata_dev_power_init_tf(qc->dev, &qc->tf, cdb[4] & 0x1)) { + ata_scsi_set_sense(qc->dev, scmd, ABORTED_COMMAND, 0, 0); + return 1; } /* @@ -1274,12 +1243,8 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) invalid_fld: ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); return 1; - skip: - scmd->result = SAM_STAT_GOOD; - return 1; } - /** * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command * @qc: Storage for translated ATA taskfile diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 05ac80da8ebc..5c685bb1939e 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -62,6 +62,8 @@ extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags); extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, unsigned int readid_flags); extern int ata_dev_configure(struct ata_device *dev); +extern bool ata_dev_power_init_tf(struct ata_device *dev, + struct ata_taskfile *tf, bool set_active); extern void ata_dev_power_set_standby(struct ata_device *dev); extern void ata_dev_power_set_active(struct ata_device *dev); extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); From patchwork Thu Sep 21 18:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07C1DE7D0AE for ; Thu, 21 Sep 2023 21:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232409AbjIUVFw (ORCPT ); Thu, 21 Sep 2023 17:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232717AbjIUVEt (ORCPT ); Thu, 21 Sep 2023 17:04:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC870B0591; Thu, 21 Sep 2023 11:08:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32187C433C7; Thu, 21 Sep 2023 18:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319706; bh=ppb7nxzr/j9CNCzkeE3W0KsRJrVXxnoD+Up1RAuza+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IrY86cpwVSG71w6rJlFX7+17Tx57L9IoKXlOE6xkd1VLa9lz/ZJy0fiqm6wSnq8JE SHIG2g0s/qSTKEv0xx9xZkZTrHSo2m67nkAy0Ed2k0mck/k4krtJOEwhBstH/gWdeX MkHZ78OVoCv1spCGQVvJ1J06QyFqrZ+qcEsq7x6silvPuhiCgbbH5iT0ANRdTSpJmg nv1CF35iGsco3jWfsTJGuMgTvjrXHn/v40Vxx7ejR/wlFUWNQWM46oPVyyY/KSWk8q frdEQAiEguP+Gys25Ce2iwfID7Sjz6txPKyocYxObsE+XUbW5aSuivdhtRO82/G4hG Jd1G9G8IPitmg== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 14/23] ata: libata-core: Synchronize ata_port_detach() with hotplug Date: Fri, 22 Sep 2023 03:07:49 +0900 Message-ID: <20230921180758.955317-15-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The call to async_synchronize_cookie() to synchronize a port removal and hotplug probe is done in ata_host_detach() right before calling ata_port_detach(). Move this call at the beginning of ata_port_detach() to ensure that this operation is always synchronized with probe. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 8e326a445765..de661780a31e 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6065,6 +6065,9 @@ static void ata_port_detach(struct ata_port *ap) struct ata_link *link; struct ata_device *dev; + /* Ensure ata_port probe has completed */ + async_synchronize_cookie(ap->cookie + 1); + /* Wait for any ongoing EH */ ata_port_wait_eh(ap); @@ -6129,11 +6132,8 @@ void ata_host_detach(struct ata_host *host) { int i; - for (i = 0; i < host->n_ports; i++) { - /* Ensure ata_port probe has completed */ - async_synchronize_cookie(host->ports[i]->cookie + 1); + for (i = 0; i < host->n_ports; i++) ata_port_detach(host->ports[i]); - } /* the host is dead now, dissociate ACPI */ ata_acpi_dissociate(host); From patchwork Thu Sep 21 18:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1165E7D0B9 for ; Thu, 21 Sep 2023 21:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbjIUVFu (ORCPT ); Thu, 21 Sep 2023 17:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233023AbjIUVFT (ORCPT ); Thu, 21 Sep 2023 17:05:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3B12B0598; Thu, 21 Sep 2023 11:08:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07BD4C433CA; Thu, 21 Sep 2023 18:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319708; bh=flFAd8DdULULocs8cxL0Hlh1zT/I0HWgfXuDa6s6GKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RDwGQlJ2OgC64uxH4SBsGUcCxZdr4brlxXU/H0gtjrlIQveZrhdqX+5oETXMySFWI Bjed7fmomcQXbpXRj/OFJDPitLJITeDlbtPHc51StAutKgqk08MXj/0f63leQ0us+A SlxhSf8cPWl2xZZBMyx2Ey0n2BXK0/1+L8TO44Fh7aauneJc4/4w2Ua50Okghwu8c1 8DT7Ka8aTyHekzWnCgOuemwBuIskccDRqDQe5UNxrkPq7IblWhvgnlHo/YDuLyb+Os QJN8oVy/BjUVRR32k4TYF+7dscd7soGdSQyOoEYCOCJR1Ijj9NmWfdkEAx3aqfMkNE 14oA8mZmpjPcg== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 15/23] ata: libata-core: Detach a port devices on shutdown Date: Fri, 22 Sep 2023 03:07:50 +0900 Message-ID: <20230921180758.955317-16-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Modify ata_pci_shutdown_one() to schedule EH to unload a port devices before freezing and thawing the port. This ensures that drives are cleanly disabled and transitioned to standby power mode when a PCI adapter is removed or the system is powered off. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index de661780a31e..6b38ebaad019 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6164,10 +6164,24 @@ EXPORT_SYMBOL_GPL(ata_pci_remove_one); void ata_pci_shutdown_one(struct pci_dev *pdev) { struct ata_host *host = pci_get_drvdata(pdev); + struct ata_port *ap; + unsigned long flags; int i; + /* Tell EH to disable all devices */ for (i = 0; i < host->n_ports; i++) { - struct ata_port *ap = host->ports[i]; + ap = host->ports[i]; + spin_lock_irqsave(ap->lock, flags); + ap->pflags |= ATA_PFLAG_UNLOADING; + ata_port_schedule_eh(ap); + spin_unlock_irqrestore(ap->lock, flags); + } + + for (i = 0; i < host->n_ports; i++) { + ap = host->ports[i]; + + /* Wait for EH to complete before freezing the port */ + ata_port_wait_eh(ap); ap->pflags |= ATA_PFLAG_FROZEN; From patchwork Thu Sep 21 18:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F207EE7D0AB for ; Thu, 21 Sep 2023 21:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232564AbjIUVEJ (ORCPT ); Thu, 21 Sep 2023 17:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjIUVDe (ORCPT ); Thu, 21 Sep 2023 17:03:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4552B059D; Thu, 21 Sep 2023 11:08:30 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D14E9C433C8; Thu, 21 Sep 2023 18:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319710; bh=aVS3y4jtoIw5j7YaMOaU7VO6tVyp+33R8jEFMVus02g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KL28eWgJis+1EntXKcjzUlh9hkbAxEbH4IJKOnEOSS/aym9rEmAKbwWchuIChjNk8 zSzrKzDCKj3kusdCBNDzBtdzrMviUJQ1PhCZvmgRv5WkyJWHiRBCi50/Eo2H0SepvH lIRx0RMKsNOl55AXSepefp3qHSarLpXyvTY7MH2FJQDdQIO3ReBUp+sVp7MqjK9lMu CjmDeH33ZocmviaZK0rQUUUNnMpTRj04FONjkkelYyr4hcfu+JwCRadfzBguKx9/tG HLn4aN5kgsyT6LvAR2MMz99c3Xqxt+ELdVRRaKFO+Oz5MurCTw9QZkwjdgFDKiMPg2 vmBaPW49xLCeA== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 16/23] ata: libata-core: Remove ata_port_suspend_async() Date: Fri, 22 Sep 2023 03:07:51 +0900 Message-ID: <20230921180758.955317-17-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org ata_port_suspend_async() is only called by ata_sas_port_suspend(). Modify ata_port_suspend() with an additional bool argument indicating an asynchronous or synchronous suspend to allow removing that helper function. With this change, the variable ata_port_resume_ehi can also be removed and its value (ATA_EHI_XXX flags passed directly to ata_port_request_pm(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 46 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 6b38ebaad019..b3615862ea30 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5166,18 +5166,8 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, ata_port_wait_eh(ap); } -/* - * On some hardware, device fails to respond after spun down for suspend. As - * the device won't be used before being resumed, we don't need to touch the - * device. Ask EH to skip the usual stuff and proceed directly to suspend. - * - * http://thread.gmane.org/gmane.linux.ide/46764 - */ -static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET - | ATA_EHI_NO_AUTOPSY - | ATA_EHI_NO_RECOVERY; - -static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) +static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg, + bool async) { /* * We are about to suspend the port, so we do not care about @@ -5187,20 +5177,18 @@ static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) */ cancel_delayed_work_sync(&ap->scsi_rescan_task); - ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false); -} - -static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg) -{ /* - * We are about to suspend the port, so we do not care about - * scsi_rescan_device() calls scheduled by previous resume operations. - * The next resume will schedule the rescan again. So cancel any rescan - * that is not done yet. + * On some hardware, device fails to respond after spun down for + * suspend. As the device wil not t be used until being resumed, we + * do not need to touch the device. Ask EH to skip the usual stuff + * and proceed directly to suspend. + * + * http://thread.gmane.org/gmane.linux.ide/46764 */ - cancel_delayed_work_sync(&ap->scsi_rescan_task); - - ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true); + ata_port_request_pm(ap, mesg, 0, + ATA_EHI_QUIET | ATA_EHI_NO_AUTOPSY | + ATA_EHI_NO_RECOVERY, + async); } static int ata_port_pm_suspend(struct device *dev) @@ -5210,7 +5198,7 @@ static int ata_port_pm_suspend(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - ata_port_suspend(ap, PMSG_SUSPEND); + ata_port_suspend(ap, PMSG_SUSPEND, false); return 0; } @@ -5221,13 +5209,13 @@ static int ata_port_pm_freeze(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - ata_port_suspend(ap, PMSG_FREEZE); + ata_port_suspend(ap, PMSG_FREEZE, false); return 0; } static int ata_port_pm_poweroff(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE); + ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); return 0; } @@ -5279,7 +5267,7 @@ static int ata_port_runtime_idle(struct device *dev) static int ata_port_runtime_suspend(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND); + ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND, false); return 0; } @@ -5309,7 +5297,7 @@ static const struct dev_pm_ops ata_port_pm_ops = { */ void ata_sas_port_suspend(struct ata_port *ap) { - ata_port_suspend_async(ap, PMSG_SUSPEND); + ata_port_suspend(ap, PMSG_SUSPEND, true); } EXPORT_SYMBOL_GPL(ata_sas_port_suspend); From patchwork Thu Sep 21 18:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3170BE7D0AD for ; Thu, 21 Sep 2023 21:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231789AbjIUVBC (ORCPT ); Thu, 21 Sep 2023 17:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbjIUVAe (ORCPT ); Thu, 21 Sep 2023 17:00:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8144DB059E; Thu, 21 Sep 2023 11:08:32 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7DBFC433C7; Thu, 21 Sep 2023 18:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319712; bh=szrB09d6ekRwrhFAKNFo1LSTF8bHYrUX/YyYXKmbyGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C16LntCSNUbIN56nJNzHYbjtGGOgozOxsl05FkpIyeUvYLmw0Met+CrzTR4h/QYhL kaqWbxxjyDalYNSny7RKsSvyy9a8Ja9v4akxVTsNx7GgkvxZ3+gnUmI2MtyUVXBEaU CDnLATFclPfgPtDWqTXj7hT/0oLi1aIzEUvI/MHjQIJ7wWoog/sBkvyPhl1NnU/0TE fYwEnRMRz/2tR7nKlebIUd8adGKUEUye0OJV/nDRzBEE3an7+xbl417J94r//qUPQV mjXZyv7ie7D8syKaC8PS2LQsG73LY7yDkzd2o2eOYsqS5wIzvmN2t+O9k0K33oeWo7 QTjJ9Ae7ZLmbA== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 17/23] ata: libata-core: Remove ata_port_resume_async() Date: Fri, 22 Sep 2023 03:07:52 +0900 Message-ID: <20230921180758.955317-18-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Remove ata_port_resume_async() and replace it with a modified ata_port_resume() taking an additional bool argument indicating if ata EH resume operation should be executed synchronously or asynchronously. With this change, the variable ata_port_resume_ehi is not longer necessary and its value (ATA_EHI_XXX flags) passed directly to ata_port_request_pm(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b3615862ea30..b46980fe69b4 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5219,22 +5219,17 @@ static int ata_port_pm_poweroff(struct device *dev) return 0; } -static const unsigned int ata_port_resume_ehi = ATA_EHI_NO_AUTOPSY - | ATA_EHI_QUIET; - -static void ata_port_resume(struct ata_port *ap, pm_message_t mesg) +static void ata_port_resume(struct ata_port *ap, pm_message_t mesg, + bool async) { - ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, false); -} - -static void ata_port_resume_async(struct ata_port *ap, pm_message_t mesg) -{ - ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, true); + ata_port_request_pm(ap, mesg, ATA_EH_RESET, + ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, + async); } static int ata_port_pm_resume(struct device *dev) { - ata_port_resume_async(to_ata_port(dev), PMSG_RESUME); + ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -5273,7 +5268,7 @@ static int ata_port_runtime_suspend(struct device *dev) static int ata_port_runtime_resume(struct device *dev) { - ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME); + ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME, false); return 0; } @@ -5303,7 +5298,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_suspend); void ata_sas_port_resume(struct ata_port *ap) { - ata_port_resume_async(ap, PMSG_RESUME); + ata_port_resume(ap, PMSG_RESUME, true); } EXPORT_SYMBOL_GPL(ata_sas_port_resume); From patchwork Thu Sep 21 18:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02550E7D0A2 for ; Thu, 21 Sep 2023 18:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229473AbjIUSgE (ORCPT ); Thu, 21 Sep 2023 14:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjIUSff (ORCPT ); Thu, 21 Sep 2023 14:35:35 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D3EB05A1; Thu, 21 Sep 2023 11:08:34 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CDA5C433C9; Thu, 21 Sep 2023 18:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319714; bh=GTW29Tbo2vbr6MXSdFJhe+fVerKvAHx6guP8pG4B20I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9xjB7o0jOzbqwk57rIT09TZjHTN0XwA14WHPRqogmqjSJx1ryhH/nUfREujR73nn 4BDgQ/JoishRJX81XlLCgiSKL5TG9SIOb6mI5JpLE3wc9fmXvBqUr9mQPaEFCiG6fu 9AFsucINDFc5GfGYAPKpAZvExCflsmHEmBi1jhaF6z7cen8ThNzMVhNJSAJjhRsplr x7FfG9308wNXqawp5iQ/6Bgg0sbZCZrVlfWEbYEdyxA2jt8F9XPIV5YPow49COiUZ9 95qeZXvprI5kzIQjpp8JPjMu7eXLfrUhnW43EK75I9DYanV3MF0RkDVsVVnRNoMd9F 6zomXlZ6Xbrew== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 18/23] ata: libata-core: Do not poweroff runtime suspended ports Date: Fri, 22 Sep 2023 03:07:53 +0900 Message-ID: <20230921180758.955317-19-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When powering off, there is no need to suspend a port that has already been runtime suspended. Skip the EH PM request in ata_port_pm_poweroff() in this case. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index b46980fe69b4..35112f9e482d 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5215,7 +5215,8 @@ static int ata_port_pm_freeze(struct device *dev) static int ata_port_pm_poweroff(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); + if (!pm_runtime_suspended(dev)) + ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); return 0; } From patchwork Thu Sep 21 18:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0724E7D0A2 for ; Thu, 21 Sep 2023 20:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjIUUcM (ORCPT ); Thu, 21 Sep 2023 16:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231877AbjIUUbs (ORCPT ); Thu, 21 Sep 2023 16:31:48 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28ADFB05A5; Thu, 21 Sep 2023 11:08:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5235DC433C8; Thu, 21 Sep 2023 18:08:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319715; bh=uvMbiXNNIjl/dA+3/T/1VF15D65NW5iWk83KkwR7epg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oieQdGBh1TIVcXf+RWlxuUHcRldwIWOUmxyvhOg+lmx0rYhyletewYD3iHHqa/kf4 KziWTHP+Q4cy6S9Hs2Jz9i3hUF8K0rlZL/fcJ6EU5rYj2XQY2dIkjiz6EPxvFdQO/1 svnUFg5OLKMMvAdc6TDeZV9yZ8MRJcWQYaJ0qL3VZWxYAsp9qQ/g2LoU+3guKjR+pP AoQEHjy1MxcUub32C5jSwSuujxUNcLIVDPJQJp01U1Gfge7ug2+G4O6eTTOLKyCg7d rumt0RM9/fR5cJ45WPBdRG1UeSTpwPJ1Oy/UvZO3hBWrkqfC99PVaNKWiyN9ZfldFi pjsvqnj40VXcg== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 19/23] ata: libata-core: Do not resume runtime suspended ports Date: Fri, 22 Sep 2023 03:07:54 +0900 Message-ID: <20230921180758.955317-20-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The scsi disk driver does not resume disks that have been runtime suspended by the user. To be consistent with this behavior, do the same for ata ports and skip the PM request in ata_port_pm_resume() if the port was already runtime suspended. With this change, it is no longer necessary to force the PM state of the port to ACTIVE as the PM core code will take care of that when handling runtime resume. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 35112f9e482d..e0973f5614b0 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5230,10 +5230,8 @@ static void ata_port_resume(struct ata_port *ap, pm_message_t mesg, static int ata_port_pm_resume(struct device *dev) { - ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + if (!pm_runtime_suspended(dev)) + ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); return 0; } From patchwork Thu Sep 21 18:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62C14E7D0AE for ; Thu, 21 Sep 2023 21:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjIUVIC (ORCPT ); Thu, 21 Sep 2023 17:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjIUVHs (ORCPT ); Thu, 21 Sep 2023 17:07:48 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F193FB05AB; Thu, 21 Sep 2023 11:08:37 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2762DC433C7; Thu, 21 Sep 2023 18:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319717; bh=lluOKqw7tLNV/kxgRi98Hm7XDhcmRwFMDXZzXCgSCAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UGAL7/3nv9GDFco2lMzFYE5japtR9Xzg9LfuVaGFBn4d6oIPi5qXWkTcbIjWcrhuu CqIQYcT3F+dZNpUhagWOo+48qQXkLhQFoL/iqLQE9S0uTlff7WKCq4Hotuv4PBF/mJ Jn+zl5OVTIhzostqtnRTU7UYUavcTdiYoTxonRTf6RPivXrvyiOyZbBHzBe4hirL3m 1KKMTxfgr1xj7MTXeDjAeezQrI7kJeSTnmnOWnlv0rXNxrpfrsW8qicPNRMb7bcw6j gBjqPl7pBIxMR6i8nHdkDra04RhbuzwCDgqpZtUfxxFcP1PaRgFmVEEv0K4OXgnrHY /PcztrUVGCnjw== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 20/23] ata: libata-sata: Improve ata_sas_slave_configure() Date: Fri, 22 Sep 2023 03:07:55 +0900 Message-ID: <20230921180758.955317-21-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Change ata_sas_slave_configure() to return the return value of ata_scsi_dev_config() to ensure that any error from that function is propagated to libsas. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: John Garry Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-sata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index a701e1538482..83a9497e48e1 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1182,8 +1182,8 @@ EXPORT_SYMBOL_GPL(ata_sas_tport_delete); int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap) { ata_scsi_sdev_config(sdev); - ata_scsi_dev_config(sdev, ap->link.device); - return 0; + + return ata_scsi_dev_config(sdev, ap->link.device); } EXPORT_SYMBOL_GPL(ata_sas_slave_configure); From patchwork Thu Sep 21 18:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5702E7D0AD for ; Thu, 21 Sep 2023 21:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbjIUVCa (ORCPT ); Thu, 21 Sep 2023 17:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbjIUVBy (ORCPT ); Thu, 21 Sep 2023 17:01:54 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A35BB05AE; Thu, 21 Sep 2023 11:08:39 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0BB0C433C9; Thu, 21 Sep 2023 18:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319719; bh=v+gYEK1rbQqzg3/TKGCS1gzTm+Sa5IIqlODyrx0gJiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLKkjNlNr64IhfNUoeXAIK5SFibu3fm59IJ+Eq3gaRPTFB7Bi015QQq6d4t8s9jmp +JXJX67esmTRultQAzmiu0jbEemWmMP8b/saHsZRkI1Z+4wk5sb+KdnRh/nv4S6w51 Eo17lx5UlRKR2WpiGQLYTGKIKfCpcGr/IYJl/5IOHhzG09A/XaaMn8uL6+TUtfDv2b 0qqfB/fALZfUB8oGDt38CCWbKnTORf15F0Aez8ze5DBMRXoBdYROWCGK/yHEe0fgoM MhVhRRo41IT5zE63NaHWU6SUI4Sd3vMdoN8klgfeG1t3MrS625AWgzLjz7yxRnvcYC 6VIovUR6eh8Og== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 21/23] ata: libata-eh: Improve reset error messages Date: Fri, 22 Sep 2023 03:07:56 +0900 Message-ID: <20230921180758.955317-22-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Some drives are really slow to spinup on resume, resulting is a very slow response to COMRESET and to error messages such as: ata1: COMRESET failed (errno=-16) ata1: link is slow to respond, please be patient (ready=0) ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata1.00: configured for UDMA/133 Given that the slowness of the response is indicated with the message "link is slow to respond..." and that resets are retried until the device is detected as online after up to 1min (ata_eh_reset_timeouts), there is no point in printing the "COMRESET failed" error message. Let's not scare the user with non fatal errors and only warn about reset failures in ata_eh_reset() when all reset retries have been exhausted. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-eh.c | 2 ++ drivers/ata/libata-sata.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 5686353e442c..67387d602735 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -2909,6 +2909,8 @@ int ata_eh_reset(struct ata_link *link, int classify, */ if (ata_is_host_link(link)) ata_eh_thaw_port(ap); + ata_link_warn(link, "%s failed\n", + reset == hardreset ? "hardreset" : "softreset"); goto out; } diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 83a9497e48e1..b6656c287175 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -621,7 +621,6 @@ int sata_link_hardreset(struct ata_link *link, const unsigned int *timing, /* online is set iff link is online && reset succeeded */ if (online) *online = false; - ata_link_err(link, "COMRESET failed (errno=%d)\n", rc); } return rc; } From patchwork Thu Sep 21 18:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF7CCE7D0AB for ; Thu, 21 Sep 2023 20:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbjIUU7F (ORCPT ); Thu, 21 Sep 2023 16:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbjIUU6m (ORCPT ); Thu, 21 Sep 2023 16:58:42 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D0E3B05AF; Thu, 21 Sep 2023 11:08:41 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5BA6C433CA; Thu, 21 Sep 2023 18:08:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319721; bh=Sq6E9bjA1ZIF0QNv/u0hbvoBqHCxusrxEbAxfDUhCCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZgSegz2xp+vu5yhjN8uaCrek6iKOft2x0Q0pmwIgjyFv3pG8CTWp+Oj5eNRNniOYd vVvplE/+jeA1//7wGYlsJlHojCAuY333cD9hr9NNJr+Kd0sYHu+AjxhzWplrEBFWFu Ri2ujwbk1aMXmpSETZACplCpOsjKc6wihPVj35w5a7jpXZ/S3Nvl5JVyrsTkMMaPUx vSy1NLAwA091/0K+jIHhGd/RSmCazQKjDDkWG2vC4jcZSJqj8HQnOI6jMesguxI8eF 84NW/CRFggUnHN9gb8aEMqkejLYjOWmRCn+NWVHoQ1nfGC4lOcGYhoOR5AVUK+11bY 1Emul/J9/RKaQ== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 22/23] ata: libata-eh: Reduce "disable device" message verbosity Date: Fri, 22 Sep 2023 03:07:57 +0900 Message-ID: <20230921180758.955317-23-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no point in warning about a device being disabled when we expect it to be, that is, on suspend, shutdown or when detaching the device. Suppress the message "disable device" for these cases by introducing the EH static function ata_eh_dev_disable() and by using it in ata_eh_unload() and ata_eh_detach_dev(). ata_dev_disable() code is modified to call this new function after printing the "disable device" message. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- drivers/ata/libata-eh.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 67387d602735..945675f6b822 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -494,6 +494,18 @@ void ata_eh_release(struct ata_port *ap) mutex_unlock(&ap->host->eh_mutex); } +static void ata_eh_dev_disable(struct ata_device *dev) +{ + ata_acpi_on_disable(dev); + ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET); + dev->class++; + + /* From now till the next successful probe, ering is used to + * track probe failures. Clear accumulated device error info. + */ + ata_ering_clear(&dev->ering); +} + static void ata_eh_unload(struct ata_port *ap) { struct ata_link *link; @@ -517,8 +529,8 @@ static void ata_eh_unload(struct ata_port *ap) */ ata_for_each_link(link, ap, PMP_FIRST) { sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); - ata_for_each_dev(dev, link, ALL) - ata_dev_disable(dev); + ata_for_each_dev(dev, link, ENABLED) + ata_eh_dev_disable(dev); } /* freeze and set UNLOADED */ @@ -1211,14 +1223,8 @@ void ata_dev_disable(struct ata_device *dev) return; ata_dev_warn(dev, "disable device\n"); - ata_acpi_on_disable(dev); - ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET); - dev->class++; - /* From now till the next successful probe, ering is used to - * track probe failures. Clear accumulated device error info. - */ - ata_ering_clear(&dev->ering); + ata_eh_dev_disable(dev); } EXPORT_SYMBOL_GPL(ata_dev_disable); @@ -1240,12 +1246,12 @@ void ata_eh_detach_dev(struct ata_device *dev) /* * If the device is still enabled, transition it to standby power mode - * (i.e. spin down HDDs). + * (i.e. spin down HDDs) and disable it. */ - if (ata_dev_enabled(dev)) + if (ata_dev_enabled(dev)) { ata_dev_power_set_standby(dev); - - ata_dev_disable(dev); + ata_eh_dev_disable(dev); + } spin_lock_irqsave(ap->lock, flags); From patchwork Thu Sep 21 18:07:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13394621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF328E7D0AA for ; Thu, 21 Sep 2023 21:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231524AbjIUVAP (ORCPT ); Thu, 21 Sep 2023 17:00:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232448AbjIUU7p (ORCPT ); Thu, 21 Sep 2023 16:59:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72273B05B1; Thu, 21 Sep 2023 11:08:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AAC3C433C7; Thu, 21 Sep 2023 18:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695319723; bh=NzckH9m2rphuFI2v2F3MbPasIB1cMwXqdnfzrb7mEPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n630gAVYT5YfcZPDULc/OinMltsEN2ZQEhHUl/jf3AAwik26e/Jfo+LWSSN3aBgTS cYK5FxbPJ3qPEVGr9sPPLizdYUEoMTqPu9QGnHniBC0Zdj/ojynJEXrZwWHkZgSLqq 0Ax5RSoCfbKZ8AzuyjK+uqfp1r/adZP0CLlOaJOyDbvmUBoWk3E10E3a3oL1C7oBfM 8D+97fU73oRA4aCMAn8IMV2cExzzBzmkXJCX09S7prFgOXdyPe50ilbADg1IcGeQ6o SnSAqwrBPEmHYh7k3wD7/Gdmr3tafGfv0/VDgYN1H69tPbOJ65F8ba5Coc44BwwGvi PfIa3LuBEnB1Q== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer , Geert Uytterhoeven , Chia-Lin Kao Subject: [PATCH v5 23/23] ata: libata: Cleanup inline DMA helper functions Date: Fri, 22 Sep 2023 03:07:58 +0900 Message-ID: <20230921180758.955317-24-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921180758.955317-1-dlemoal@kernel.org> References: <20230921180758.955317-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Simplify the inline DMA helper functions ata_using_mwdma(), ata_using_udma() and ata_dma_enabled() to directly return as a boolean the result of their test condition. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven --- include/linux/libata.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/linux/libata.h b/include/linux/libata.h index 00b4a2b7819a..3c0fd04b0035 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1881,23 +1881,21 @@ static inline unsigned long ata_deadline(unsigned long from_jiffies, change in future hardware and specs, secondly 0xFF means 'no DMA' but is > UDMA_0. Dyma ddreigiau */ -static inline int ata_using_mwdma(struct ata_device *adev) +static inline bool ata_using_mwdma(struct ata_device *adev) { - if (adev->dma_mode >= XFER_MW_DMA_0 && adev->dma_mode <= XFER_MW_DMA_4) - return 1; - return 0; + return adev->dma_mode >= XFER_MW_DMA_0 && + adev->dma_mode <= XFER_MW_DMA_4; } -static inline int ata_using_udma(struct ata_device *adev) +static inline bool ata_using_udma(struct ata_device *adev) { - if (adev->dma_mode >= XFER_UDMA_0 && adev->dma_mode <= XFER_UDMA_7) - return 1; - return 0; + return adev->dma_mode >= XFER_UDMA_0 && + adev->dma_mode <= XFER_UDMA_7; } -static inline int ata_dma_enabled(struct ata_device *adev) +static inline bool ata_dma_enabled(struct ata_device *adev) { - return (adev->dma_mode == 0xFF ? 0 : 1); + return adev->dma_mode != 0xFF; } /**************************************************************************