ata: libata-scsi: Fix get identity data failed
Subsystems (3)
PATCH 1/1 ata: libata-scsi: Fix get identity data failed
The function ata_get_identity() uses the helper ata_scsi_find_dev() to get the ata_device structure of a scsi device. However, when the ata device is managed by libsas, ata_scsi_find_dev() returns NULL, turning ata_get_identity() into a nop and always returns -ENOMSG.
Fix this by replacing the pointer to the scsi_device struct argument with a pointer to the ata_device struct in ata_sas_scsi_ioctl() and ata_get_identity(). This pointer is provided by ata_scsi_ioctl() using ata_scsi_find_dev() in the case of a libata managed device and by sas_ioctl() using sas_to_ata_dev() in the case of a libsas managed ata device.
--- drivers/ata/libata-scsi.c | 22 +++++++++++----------- drivers/scsi/libsas/sas_scsi_host.c | 3 ++- include/linux/libata.h | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-)
drivers/ata/libata-scsi.c +11 -11
@@ -327,8 +327,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);/** * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl -* @ap: target port -* @sdev: SCSI device to get identify data for +* @dev: ATA device to get identify data for * @arg: User buffer area for identify data * * LOCKING:
@@ -337,10 +336,8 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);* RETURNS: * Zero on success, negative errno on error. */ -static int ata_get_identity (struct ata_port *ap,struct scsi_device *sdev, -void __user *arg) +static int ata_get_identity (struct ata_device *dev,void __user *arg) { -struct ata_device *dev =ata_scsi_find_dev (ap, sdev);u16 __user *dst = arg;char buf[40 ];
@@ -573,7 +570,7 @@ static bool ata_ioc32(struct ata_port *ap)* This handles both native and compat commands, so anything added * here must have a compatible argument, or check in_compat_syscall() */ -int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *scsidev, +int ata_sas_scsi_ioctl (struct ata_port *ap,struct ata_device *dev,unsigned int cmd,void __user *arg) {unsigned long val;
@@ -608,17 +605,17 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev,return rc;case HDIO_GET_IDENTITY : -return ata_get_identity (ap, scsidev, arg); +return ata_get_identity (dev, arg);case HDIO_DRIVE_CMD :if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; -return ata_cmd_ioctl (scsidev, arg); +return ata_cmd_ioctl (dev->sdev, arg);case HDIO_DRIVE_TASK :if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; -return ata_task_ioctl (scsidev, arg); +return ata_task_ioctl (dev->sdev, arg);default : rc = -ENOTTY ;
@@ -632,8 +629,11 @@ EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl);int ata_scsi_ioctl (struct scsi_device *scsidev,unsigned int cmd,void __user *arg) { -return ata_sas_scsi_ioctl (ata_shost_to_port (scsidev->host), - scsidev, cmd, arg); +struct ata_port *ap =ata_shost_to_port (scsidev->host); + +return ata_sas_scsi_ioctl (ap, +ata_scsi_find_dev (ap, scsidev), + cmd, arg); }EXPORT_SYMBOL_GPL (ata_scsi_ioctl);
drivers/scsi/libsas/sas_scsi_host.c +2 -1
@@ -789,7 +789,8 @@ int sas_ioctl(struct scsi_device *sdev, unsigned int cmd, void __user *arg)struct domain_device *dev =sdev_to_domain_dev (sdev);if (dev_is_sata (dev)) -return ata_sas_scsi_ioctl (dev->sata_dev.ap, sdev, cmd, arg); +return ata_sas_scsi_ioctl (dev->sata_dev.ap, +sas_to_ata_dev (dev), cmd, arg);return -EINVAL ; }
include/linux/libata.h +1 -1
@@ -1085,7 +1085,7 @@ bool ata_scsi_dma_need_drain(struct request *rq);#else #define ata_scsi_dma_need_drain NULL#endif -extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *dev, +extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct ata_device *dev,unsigned int cmd,void __user *arg);extern bool ata_link_online (struct ata_link *link);extern bool ata_link_offline (struct ata_link *link);
Signature · 1 line
2.17.1
John Garry
reviewerQuoted 11 lines · Xingui Yang
The function
ata_get_identity()uses the helperata_scsi_find_dev()to get theata_devicestructure of a scsi device. However, when the ata device is managed by libsas,ata_scsi_find_dev()returns NULL, turningata_get_identity()into a nop and always returns-ENOMSG.Fix this by replacing the pointer to the
scsi_devicestruct argument with a pointer to theata_devicestruct inata_sas_scsi_ioctl()andata_get_identity(). This pointer is provided byata_scsi_ioctl()usingata_scsi_find_dev()in the case of a libata managed device and bysas_ioctl()usingsas_to_ata_dev()in the case of a libsas managed ata device.
We made a similar change in commit 141f3d6256e5 ("ata: libata-sata: Fix device queue depth control"). Is there some better way to do this to make it all more scalable such that we don't need to keep replacing calls to ata_scsi_find_dev()?
This was discussed earlier, along with queue depth issue (which does not seem fixed, AFAIK):
https://lore.kernel.org/linux-scsi/[email protected]/
Thanks,
John
Quoted 105 lines
Signed-off-by Xingui Yang <[email protected]>--- drivers/ata/libata-scsi.c | 22 +++++++++++----------- drivers/scsi/libsas/sas_scsi_host.c | 3 ++- include/linux/libata.h | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-)drivers/ata/libata-scsi.c +11
-11@@ -327,8 +327,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);/** * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl -* @ap: target port -* @sdev: SCSI device to get identify data for +* @dev: ATA device to get identify data for * @arg: User buffer area for identify data * * LOCKING: @@ -337,10 +336,8 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);* RETURNS: * Zero on success, negative errno on error. */ -static int ata_get_identity (struct ata_port *ap,struct scsi_device *sdev, -void __user *arg) +static int ata_get_identity (struct ata_device *dev,void __user *arg) { -struct ata_device *dev =ata_scsi_find_dev (ap, sdev);u16 __user *dst = arg;char buf[40 ];@@ -573,7 +570,7 @@ static bool ata_ioc32(struct ata_port *ap)* This handles both native and compat commands, so anything added * here must have a compatible argument, or check in_compat_syscall() */ -int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *scsidev, +int ata_sas_scsi_ioctl (struct ata_port *ap,struct ata_device *dev,unsigned int cmd,void __user *arg) {unsigned long val;@@ -608,17 +605,17 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev,return rc;case HDIO_GET_IDENTITY : -return ata_get_identity (ap, scsidev, arg); +return ata_get_identity (dev, arg);case HDIO_DRIVE_CMD :if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; -return ata_cmd_ioctl (scsidev, arg); +return ata_cmd_ioctl (dev->sdev, arg);case HDIO_DRIVE_TASK :if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; -return ata_task_ioctl (scsidev, arg); +return ata_task_ioctl (dev->sdev, arg);default : rc = -ENOTTY ;@@ -632,8 +629,11 @@ EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl);int ata_scsi_ioctl (struct scsi_device *scsidev,unsigned int cmd,void __user *arg) { -return ata_sas_scsi_ioctl (ata_shost_to_port (scsidev->host), - scsidev, cmd, arg); +struct ata_port *ap =ata_shost_to_port (scsidev->host); + +return ata_sas_scsi_ioctl (ap, +ata_scsi_find_dev (ap, scsidev), + cmd, arg); }EXPORT_SYMBOL_GPL (ata_scsi_ioctl);drivers/scsi/libsas/sas_scsi_host.c +2
-1@@ -789,7 +789,8 @@ int sas_ioctl(struct scsi_device *sdev, unsigned int cmd, void __user *arg)struct domain_device *dev =sdev_to_domain_dev (sdev);if (dev_is_sata (dev)) -return ata_sas_scsi_ioctl (dev->sata_dev.ap, sdev, cmd, arg); +return ata_sas_scsi_ioctl (dev->sata_dev.ap, +sas_to_ata_dev (dev), cmd, arg);return -EINVAL ; }include/linux/libata.h +1
-1@@ -1085,7 +1085,7 @@ bool ata_scsi_dma_need_drain(struct request *rq);#else #define ata_scsi_dma_need_drain NULL#endif -extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *dev, +extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct ata_device *dev,unsigned int cmd,void __user *arg);extern bool ata_link_online (struct ata_link *link);extern bool ata_link_offline (struct ata_link *link);
Quoted 6 lines · John Garry
Quoted 5 lines · Xingui Yang
The function
ata_get_identity()uses the helperata_scsi_find_dev()to get theata_devicestructure of a scsi device. However, when the ata device is managed by libsas,ata_scsi_find_dev()returns NULL, turningata_get_identity()into a nop and always returns-ENOMSG.
Quoted 9 lines
Quoted 6 lines
Fix this by replacing the pointer to the
scsi_devicestruct argument with a pointer to theata_devicestruct inata_sas_scsi_ioctl()andata_get_identity(). This pointer is provided byata_scsi_ioctl()usingata_scsi_find_dev()in the case of a libata managed device and bysas_ioctl()usingsas_to_ata_dev()in the case of a libsas managed ata device.We made a similar change in commit
141f3d6256e5("ata: libata-sata: Fix device queue depth control"). Is there some better way to do this to make it all more scalable such that we don't need to keep replacing calls toata_scsi_find_dev()?
Yes, We do have a way to return the correct value in ata_scsi_find_dev(), and we don't need to keep replacing calls to ata_scsi_find_dev(). I'll update with a new version.
Thanks,
Xingui
Quoted 111 lines
This was discussed earlier, along with queue depth issue (which does not seem fixed, AFAIK):
https://lore.kernel.org/linux-scsi/[email protected]/Thanks,
JohnQuoted 99 lines
Signed-off-by Xingui Yang <[email protected]>---
drivers/ata/libata-scsi.c | 22 +++++++++++-----------drivers/scsi/libsas/sas_scsi_host.c| 3 ++- include/linux/libata.h | 2 +-3 files changed, 14 insertions(+), 13 deletions(-)drivers/ata/libata-scsi.c +3
-6@@ -327,8 +327,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity); /*** ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl -* @ap: target port -* @sdev: SCSI device to get identify data for +* @dev: ATA device to get identify data for * @arg: User buffer area for identify data * * LOCKING: @@ -337,10 +336,8 @@ EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);* RETURNS: * Zero on success, negative errno on error. */ -static int ata_get_identity (struct ata_port *ap,struct scsi_device *sdev, - void __user *arg) +static int ata_get_identity(struct ata_device *dev, void __user *arg) { - struct ata_device *dev = ata_scsi_find_dev(ap, sdev); u16 __user *dst = arg; char buf[40];@@ -573,7 +570,7 @@ static bool ata_ioc32(struct ata_port *ap)* This handles both native and compat commands, so anything added * here must have a compatible argument, or check in_compat_syscall() */ -int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *scsidev, +int ata_sas_scsi_ioctl (struct ata_port *ap,struct ata_device *dev, unsigned int cmd, void __user *arg) { unsigned long val;@@ -608,17 +605,17 @@ int ata_sas_scsi_ioctl(struct ata_port *ap,struct scsi_device *scsidev, return rc;case
HDIO_GET_IDENTITY:
- returnata_get_identity(ap, scsidev, arg);
+ returnata_get_identity(dev, arg);
caseHDIO_DRIVE_CMD:
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return-EACCES;
- returnata_cmd_ioctl(scsidev, arg);
+ returnata_cmd_ioctl(dev->sdev, arg);
caseHDIO_DRIVE_TASK:
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return-EACCES;
- returnata_task_ioctl(scsidev, arg);
+ returnata_task_ioctl(dev->sdev, arg); default:
rc =-ENOTTY;drivers/ata/libata-scsi.c +5
-2@@ -632,8 +629,11 @@ EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl); int ata_scsi_ioctl(struct scsi_device *scsidev, unsigned int cmd, void __user *arg) { - return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), - scsidev, cmd, arg); + struct ata_port *ap = ata_shost_to_port(scsidev->host); + + return ata_sas_scsi_ioctl(ap, + ata_scsi_find_dev(ap, scsidev), + cmd, arg); } EXPORT_SYMBOL_GPL(ata_scsi_ioctl);drivers/scsi/libsas/sas_scsi_host.c +2
-1@@ -789,7 +789,8 @@ int sas_ioctl(struct scsi_device *sdev, unsigned int cmd, void __user *arg) struct domain_device *dev = sdev_to_domain_dev(sdev); if (dev_is_sata(dev)) - return ata_sas_scsi_ioctl(dev->sata_dev.ap, sdev, cmd, arg); + return ata_sas_scsi_ioctl(dev->sata_dev.ap, + sas_to_ata_dev(dev), cmd, arg); return -EINVAL; }include/linux/libata.h +1
-1@@ -1085,7 +1085,7 @@ bool ata_scsi_dma_need_drain(struct request *rq); #else #define ata_scsi_dma_need_drain NULL #endif -extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *dev, +extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct ata_device *dev, unsigned int cmd, void __user *arg);Quoted 2 lines
extern bool
ata_link_online(struct ata_link *link); extern boolata_link_offline(struct ata_link *link);.