linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: clear UAC before sending SG_IO
@ 2020-09-10 10:15 Randall Huang
  2020-09-10 14:36 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Randall Huang @ 2020-09-10 10:15 UTC (permalink / raw)
  To: dgilbert, jejb, martin.petersen, linux-scsi, linux-kernel; +Cc: huangrandall

Make sure UAC is clear before sending SG_IO.

Signed-off-by: Randall Huang <huangrandall@google.com>
---
 drivers/scsi/sg.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 20472aaaf630..ad11bca47ae8 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -922,6 +922,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
 	int result, val, read_only;
 	Sg_request *srp;
 	unsigned long iflags;
+	int _cmd;
 
 	SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
 				   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
@@ -933,6 +934,13 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
 			return -ENODEV;
 		if (!scsi_block_when_processing_errors(sdp->device))
 			return -ENXIO;
+
+		_cmd = SCSI_UFS_REQUEST_SENSE;
+		if (sdp->device->host->wlun_clr_uac) {
+			sdp->device->host->hostt->ioctl(sdp->device, _cmd, NULL);
+			sdp->device->host->wlun_clr_uac = false;
+		}
+
 		result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
 				 1, read_only, 1, &srp);
 		if (result < 0)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: clear UAC before sending SG_IO
  2020-09-10 10:15 [PATCH] scsi: clear UAC before sending SG_IO Randall Huang
@ 2020-09-10 14:36 ` kernel test robot
  2020-09-10 16:36 ` kernel test robot
  2020-09-10 17:43 ` Douglas Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-09-10 14:36 UTC (permalink / raw)
  To: Randall Huang, dgilbert, jejb, martin.petersen, linux-scsi, linux-kernel
  Cc: kbuild-all, huangrandall

[-- Attachment #1: Type: text/plain, Size: 10876 bytes --]

Hi Randall,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next v5.9-rc4 next-20200910]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Randall-Huang/scsi-clear-UAC-before-sending-SG_IO/20200910-181617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/sg.c: In function 'sg_ioctl_common':
>> drivers/scsi/sg.c:938:10: error: 'SCSI_UFS_REQUEST_SENSE' undeclared (first use in this function)
     938 |   _cmd = SCSI_UFS_REQUEST_SENSE;
         |          ^~~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/sg.c:938:10: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/scsi/sg.c:939:24: error: 'struct Scsi_Host' has no member named 'wlun_clr_uac'
     939 |   if (sdp->device->host->wlun_clr_uac) {
         |                        ^~
   drivers/scsi/sg.c:941:21: error: 'struct Scsi_Host' has no member named 'wlun_clr_uac'
     941 |    sdp->device->host->wlun_clr_uac = false;
         |                     ^~

# https://github.com/0day-ci/linux/commit/ff032a89412d0cf4592575b5e8f5385b223d2261
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Randall-Huang/scsi-clear-UAC-before-sending-SG_IO/20200910-181617
git checkout ff032a89412d0cf4592575b5e8f5385b223d2261
vim +/SCSI_UFS_REQUEST_SENSE +938 drivers/scsi/sg.c

   916	
   917	static long
   918	sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
   919			unsigned int cmd_in, void __user *p)
   920	{
   921		int __user *ip = p;
   922		int result, val, read_only;
   923		Sg_request *srp;
   924		unsigned long iflags;
   925		int _cmd;
   926	
   927		SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
   928					   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
   929		read_only = (O_RDWR != (filp->f_flags & O_ACCMODE));
   930	
   931		switch (cmd_in) {
   932		case SG_IO:
   933			if (atomic_read(&sdp->detaching))
   934				return -ENODEV;
   935			if (!scsi_block_when_processing_errors(sdp->device))
   936				return -ENXIO;
   937	
 > 938			_cmd = SCSI_UFS_REQUEST_SENSE;
 > 939			if (sdp->device->host->wlun_clr_uac) {
   940				sdp->device->host->hostt->ioctl(sdp->device, _cmd, NULL);
   941				sdp->device->host->wlun_clr_uac = false;
   942			}
   943	
   944			result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
   945					 1, read_only, 1, &srp);
   946			if (result < 0)
   947				return result;
   948			result = wait_event_interruptible(sfp->read_wait,
   949				(srp_done(sfp, srp) || atomic_read(&sdp->detaching)));
   950			if (atomic_read(&sdp->detaching))
   951				return -ENODEV;
   952			write_lock_irq(&sfp->rq_list_lock);
   953			if (srp->done) {
   954				srp->done = 2;
   955				write_unlock_irq(&sfp->rq_list_lock);
   956				result = sg_new_read(sfp, p, SZ_SG_IO_HDR, srp);
   957				return (result < 0) ? result : 0;
   958			}
   959			srp->orphan = 1;
   960			write_unlock_irq(&sfp->rq_list_lock);
   961			return result;	/* -ERESTARTSYS because signal hit process */
   962		case SG_SET_TIMEOUT:
   963			result = get_user(val, ip);
   964			if (result)
   965				return result;
   966			if (val < 0)
   967				return -EIO;
   968			if (val >= mult_frac((s64)INT_MAX, USER_HZ, HZ))
   969				val = min_t(s64, mult_frac((s64)INT_MAX, USER_HZ, HZ),
   970					    INT_MAX);
   971			sfp->timeout_user = val;
   972			sfp->timeout = mult_frac(val, HZ, USER_HZ);
   973	
   974			return 0;
   975		case SG_GET_TIMEOUT:	/* N.B. User receives timeout as return value */
   976					/* strange ..., for backward compatibility */
   977			return sfp->timeout_user;
   978		case SG_SET_FORCE_LOW_DMA:
   979			/*
   980			 * N.B. This ioctl never worked properly, but failed to
   981			 * return an error value. So returning '0' to keep compability
   982			 * with legacy applications.
   983			 */
   984			return 0;
   985		case SG_GET_LOW_DMA:
   986			return put_user((int) sdp->device->host->unchecked_isa_dma, ip);
   987		case SG_GET_SCSI_ID:
   988			{
   989				sg_scsi_id_t v;
   990	
   991				if (atomic_read(&sdp->detaching))
   992					return -ENODEV;
   993				memset(&v, 0, sizeof(v));
   994				v.host_no = sdp->device->host->host_no;
   995				v.channel = sdp->device->channel;
   996				v.scsi_id = sdp->device->id;
   997				v.lun = sdp->device->lun;
   998				v.scsi_type = sdp->device->type;
   999				v.h_cmd_per_lun = sdp->device->host->cmd_per_lun;
  1000				v.d_queue_depth = sdp->device->queue_depth;
  1001				if (copy_to_user(p, &v, sizeof(sg_scsi_id_t)))
  1002					return -EFAULT;
  1003				return 0;
  1004			}
  1005		case SG_SET_FORCE_PACK_ID:
  1006			result = get_user(val, ip);
  1007			if (result)
  1008				return result;
  1009			sfp->force_packid = val ? 1 : 0;
  1010			return 0;
  1011		case SG_GET_PACK_ID:
  1012			read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1013			list_for_each_entry(srp, &sfp->rq_list, entry) {
  1014				if ((1 == srp->done) && (!srp->sg_io_owned)) {
  1015					read_unlock_irqrestore(&sfp->rq_list_lock,
  1016							       iflags);
  1017					return put_user(srp->header.pack_id, ip);
  1018				}
  1019			}
  1020			read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1021			return put_user(-1, ip);
  1022		case SG_GET_NUM_WAITING:
  1023			read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1024			val = 0;
  1025			list_for_each_entry(srp, &sfp->rq_list, entry) {
  1026				if ((1 == srp->done) && (!srp->sg_io_owned))
  1027					++val;
  1028			}
  1029			read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1030			return put_user(val, ip);
  1031		case SG_GET_SG_TABLESIZE:
  1032			return put_user(sdp->sg_tablesize, ip);
  1033		case SG_SET_RESERVED_SIZE:
  1034			result = get_user(val, ip);
  1035			if (result)
  1036				return result;
  1037	                if (val < 0)
  1038	                        return -EINVAL;
  1039			val = min_t(int, val,
  1040				    max_sectors_bytes(sdp->device->request_queue));
  1041			mutex_lock(&sfp->f_mutex);
  1042			if (val != sfp->reserve.bufflen) {
  1043				if (sfp->mmap_called ||
  1044				    sfp->res_in_use) {
  1045					mutex_unlock(&sfp->f_mutex);
  1046					return -EBUSY;
  1047				}
  1048	
  1049				sg_remove_scat(sfp, &sfp->reserve);
  1050				sg_build_reserve(sfp, val);
  1051			}
  1052			mutex_unlock(&sfp->f_mutex);
  1053			return 0;
  1054		case SG_GET_RESERVED_SIZE:
  1055			val = min_t(int, sfp->reserve.bufflen,
  1056				    max_sectors_bytes(sdp->device->request_queue));
  1057			return put_user(val, ip);
  1058		case SG_SET_COMMAND_Q:
  1059			result = get_user(val, ip);
  1060			if (result)
  1061				return result;
  1062			sfp->cmd_q = val ? 1 : 0;
  1063			return 0;
  1064		case SG_GET_COMMAND_Q:
  1065			return put_user((int) sfp->cmd_q, ip);
  1066		case SG_SET_KEEP_ORPHAN:
  1067			result = get_user(val, ip);
  1068			if (result)
  1069				return result;
  1070			sfp->keep_orphan = val;
  1071			return 0;
  1072		case SG_GET_KEEP_ORPHAN:
  1073			return put_user((int) sfp->keep_orphan, ip);
  1074		case SG_NEXT_CMD_LEN:
  1075			result = get_user(val, ip);
  1076			if (result)
  1077				return result;
  1078			if (val > SG_MAX_CDB_SIZE)
  1079				return -ENOMEM;
  1080			sfp->next_cmd_len = (val > 0) ? val : 0;
  1081			return 0;
  1082		case SG_GET_VERSION_NUM:
  1083			return put_user(sg_version_num, ip);
  1084		case SG_GET_ACCESS_COUNT:
  1085			/* faked - we don't have a real access count anymore */
  1086			val = (sdp->device ? 1 : 0);
  1087			return put_user(val, ip);
  1088		case SG_GET_REQUEST_TABLE:
  1089			{
  1090				sg_req_info_t *rinfo;
  1091	
  1092				rinfo = kcalloc(SG_MAX_QUEUE, SZ_SG_REQ_INFO,
  1093						GFP_KERNEL);
  1094				if (!rinfo)
  1095					return -ENOMEM;
  1096				read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1097				sg_fill_request_table(sfp, rinfo);
  1098				read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1099		#ifdef CONFIG_COMPAT
  1100				if (in_compat_syscall())
  1101					result = put_compat_request_table(p, rinfo);
  1102				else
  1103		#endif
  1104					result = copy_to_user(p, rinfo,
  1105							      SZ_SG_REQ_INFO * SG_MAX_QUEUE);
  1106				result = result ? -EFAULT : 0;
  1107				kfree(rinfo);
  1108				return result;
  1109			}
  1110		case SG_EMULATED_HOST:
  1111			if (atomic_read(&sdp->detaching))
  1112				return -ENODEV;
  1113			return put_user(sdp->device->host->hostt->emulated, ip);
  1114		case SCSI_IOCTL_SEND_COMMAND:
  1115			if (atomic_read(&sdp->detaching))
  1116				return -ENODEV;
  1117			return sg_scsi_ioctl(sdp->device->request_queue, NULL, filp->f_mode, p);
  1118		case SG_SET_DEBUG:
  1119			result = get_user(val, ip);
  1120			if (result)
  1121				return result;
  1122			sdp->sgdebug = (char) val;
  1123			return 0;
  1124		case BLKSECTGET:
  1125			return put_user(max_sectors_bytes(sdp->device->request_queue),
  1126					ip);
  1127		case BLKTRACESETUP:
  1128			return blk_trace_setup(sdp->device->request_queue,
  1129					       sdp->disk->disk_name,
  1130					       MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
  1131					       NULL, p);
  1132		case BLKTRACESTART:
  1133			return blk_trace_startstop(sdp->device->request_queue, 1);
  1134		case BLKTRACESTOP:
  1135			return blk_trace_startstop(sdp->device->request_queue, 0);
  1136		case BLKTRACETEARDOWN:
  1137			return blk_trace_remove(sdp->device->request_queue);
  1138		case SCSI_IOCTL_GET_IDLUN:
  1139		case SCSI_IOCTL_GET_BUS_NUMBER:
  1140		case SCSI_IOCTL_PROBE_HOST:
  1141		case SG_GET_TRANSFORM:
  1142		case SG_SCSI_RESET:
  1143			if (atomic_read(&sdp->detaching))
  1144				return -ENODEV;
  1145			break;
  1146		default:
  1147			if (read_only)
  1148				return -EPERM;	/* don't know so take safe approach */
  1149			break;
  1150		}
  1151	
  1152		result = scsi_ioctl_block_when_processing_errors(sdp->device,
  1153				cmd_in, filp->f_flags & O_NDELAY);
  1154		if (result)
  1155			return result;
  1156	
  1157		return -ENOIOCTLCMD;
  1158	}
  1159	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 61589 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: clear UAC before sending SG_IO
  2020-09-10 10:15 [PATCH] scsi: clear UAC before sending SG_IO Randall Huang
  2020-09-10 14:36 ` kernel test robot
@ 2020-09-10 16:36 ` kernel test robot
  2020-09-10 17:43 ` Douglas Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2020-09-10 16:36 UTC (permalink / raw)
  To: Randall Huang, dgilbert, jejb, martin.petersen, linux-scsi, linux-kernel
  Cc: kbuild-all, clang-built-linux, huangrandall

[-- Attachment #1: Type: text/plain, Size: 10948 bytes --]

Hi Randall,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next v5.9-rc4 next-20200910]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Randall-Huang/scsi-clear-UAC-before-sending-SG_IO/20200910-181617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-r022-20200909 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 0a5dc7effb191eff740e0e7ae7bd8e1f6bdb3ad9)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/scsi/sg.c:938:10: error: use of undeclared identifier 'SCSI_UFS_REQUEST_SENSE'
                   _cmd = SCSI_UFS_REQUEST_SENSE;
                          ^
>> drivers/scsi/sg.c:939:26: error: no member named 'wlun_clr_uac' in 'struct Scsi_Host'
                   if (sdp->device->host->wlun_clr_uac) {
                       ~~~~~~~~~~~~~~~~~  ^
   drivers/scsi/sg.c:941:23: error: no member named 'wlun_clr_uac' in 'struct Scsi_Host'
                           sdp->device->host->wlun_clr_uac = false;
                           ~~~~~~~~~~~~~~~~~  ^
   3 errors generated.

# https://github.com/0day-ci/linux/commit/ff032a89412d0cf4592575b5e8f5385b223d2261
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Randall-Huang/scsi-clear-UAC-before-sending-SG_IO/20200910-181617
git checkout ff032a89412d0cf4592575b5e8f5385b223d2261
vim +/SCSI_UFS_REQUEST_SENSE +938 drivers/scsi/sg.c

   916	
   917	static long
   918	sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
   919			unsigned int cmd_in, void __user *p)
   920	{
   921		int __user *ip = p;
   922		int result, val, read_only;
   923		Sg_request *srp;
   924		unsigned long iflags;
   925		int _cmd;
   926	
   927		SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
   928					   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
   929		read_only = (O_RDWR != (filp->f_flags & O_ACCMODE));
   930	
   931		switch (cmd_in) {
   932		case SG_IO:
   933			if (atomic_read(&sdp->detaching))
   934				return -ENODEV;
   935			if (!scsi_block_when_processing_errors(sdp->device))
   936				return -ENXIO;
   937	
 > 938			_cmd = SCSI_UFS_REQUEST_SENSE;
 > 939			if (sdp->device->host->wlun_clr_uac) {
   940				sdp->device->host->hostt->ioctl(sdp->device, _cmd, NULL);
   941				sdp->device->host->wlun_clr_uac = false;
   942			}
   943	
   944			result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
   945					 1, read_only, 1, &srp);
   946			if (result < 0)
   947				return result;
   948			result = wait_event_interruptible(sfp->read_wait,
   949				(srp_done(sfp, srp) || atomic_read(&sdp->detaching)));
   950			if (atomic_read(&sdp->detaching))
   951				return -ENODEV;
   952			write_lock_irq(&sfp->rq_list_lock);
   953			if (srp->done) {
   954				srp->done = 2;
   955				write_unlock_irq(&sfp->rq_list_lock);
   956				result = sg_new_read(sfp, p, SZ_SG_IO_HDR, srp);
   957				return (result < 0) ? result : 0;
   958			}
   959			srp->orphan = 1;
   960			write_unlock_irq(&sfp->rq_list_lock);
   961			return result;	/* -ERESTARTSYS because signal hit process */
   962		case SG_SET_TIMEOUT:
   963			result = get_user(val, ip);
   964			if (result)
   965				return result;
   966			if (val < 0)
   967				return -EIO;
   968			if (val >= mult_frac((s64)INT_MAX, USER_HZ, HZ))
   969				val = min_t(s64, mult_frac((s64)INT_MAX, USER_HZ, HZ),
   970					    INT_MAX);
   971			sfp->timeout_user = val;
   972			sfp->timeout = mult_frac(val, HZ, USER_HZ);
   973	
   974			return 0;
   975		case SG_GET_TIMEOUT:	/* N.B. User receives timeout as return value */
   976					/* strange ..., for backward compatibility */
   977			return sfp->timeout_user;
   978		case SG_SET_FORCE_LOW_DMA:
   979			/*
   980			 * N.B. This ioctl never worked properly, but failed to
   981			 * return an error value. So returning '0' to keep compability
   982			 * with legacy applications.
   983			 */
   984			return 0;
   985		case SG_GET_LOW_DMA:
   986			return put_user((int) sdp->device->host->unchecked_isa_dma, ip);
   987		case SG_GET_SCSI_ID:
   988			{
   989				sg_scsi_id_t v;
   990	
   991				if (atomic_read(&sdp->detaching))
   992					return -ENODEV;
   993				memset(&v, 0, sizeof(v));
   994				v.host_no = sdp->device->host->host_no;
   995				v.channel = sdp->device->channel;
   996				v.scsi_id = sdp->device->id;
   997				v.lun = sdp->device->lun;
   998				v.scsi_type = sdp->device->type;
   999				v.h_cmd_per_lun = sdp->device->host->cmd_per_lun;
  1000				v.d_queue_depth = sdp->device->queue_depth;
  1001				if (copy_to_user(p, &v, sizeof(sg_scsi_id_t)))
  1002					return -EFAULT;
  1003				return 0;
  1004			}
  1005		case SG_SET_FORCE_PACK_ID:
  1006			result = get_user(val, ip);
  1007			if (result)
  1008				return result;
  1009			sfp->force_packid = val ? 1 : 0;
  1010			return 0;
  1011		case SG_GET_PACK_ID:
  1012			read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1013			list_for_each_entry(srp, &sfp->rq_list, entry) {
  1014				if ((1 == srp->done) && (!srp->sg_io_owned)) {
  1015					read_unlock_irqrestore(&sfp->rq_list_lock,
  1016							       iflags);
  1017					return put_user(srp->header.pack_id, ip);
  1018				}
  1019			}
  1020			read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1021			return put_user(-1, ip);
  1022		case SG_GET_NUM_WAITING:
  1023			read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1024			val = 0;
  1025			list_for_each_entry(srp, &sfp->rq_list, entry) {
  1026				if ((1 == srp->done) && (!srp->sg_io_owned))
  1027					++val;
  1028			}
  1029			read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1030			return put_user(val, ip);
  1031		case SG_GET_SG_TABLESIZE:
  1032			return put_user(sdp->sg_tablesize, ip);
  1033		case SG_SET_RESERVED_SIZE:
  1034			result = get_user(val, ip);
  1035			if (result)
  1036				return result;
  1037	                if (val < 0)
  1038	                        return -EINVAL;
  1039			val = min_t(int, val,
  1040				    max_sectors_bytes(sdp->device->request_queue));
  1041			mutex_lock(&sfp->f_mutex);
  1042			if (val != sfp->reserve.bufflen) {
  1043				if (sfp->mmap_called ||
  1044				    sfp->res_in_use) {
  1045					mutex_unlock(&sfp->f_mutex);
  1046					return -EBUSY;
  1047				}
  1048	
  1049				sg_remove_scat(sfp, &sfp->reserve);
  1050				sg_build_reserve(sfp, val);
  1051			}
  1052			mutex_unlock(&sfp->f_mutex);
  1053			return 0;
  1054		case SG_GET_RESERVED_SIZE:
  1055			val = min_t(int, sfp->reserve.bufflen,
  1056				    max_sectors_bytes(sdp->device->request_queue));
  1057			return put_user(val, ip);
  1058		case SG_SET_COMMAND_Q:
  1059			result = get_user(val, ip);
  1060			if (result)
  1061				return result;
  1062			sfp->cmd_q = val ? 1 : 0;
  1063			return 0;
  1064		case SG_GET_COMMAND_Q:
  1065			return put_user((int) sfp->cmd_q, ip);
  1066		case SG_SET_KEEP_ORPHAN:
  1067			result = get_user(val, ip);
  1068			if (result)
  1069				return result;
  1070			sfp->keep_orphan = val;
  1071			return 0;
  1072		case SG_GET_KEEP_ORPHAN:
  1073			return put_user((int) sfp->keep_orphan, ip);
  1074		case SG_NEXT_CMD_LEN:
  1075			result = get_user(val, ip);
  1076			if (result)
  1077				return result;
  1078			if (val > SG_MAX_CDB_SIZE)
  1079				return -ENOMEM;
  1080			sfp->next_cmd_len = (val > 0) ? val : 0;
  1081			return 0;
  1082		case SG_GET_VERSION_NUM:
  1083			return put_user(sg_version_num, ip);
  1084		case SG_GET_ACCESS_COUNT:
  1085			/* faked - we don't have a real access count anymore */
  1086			val = (sdp->device ? 1 : 0);
  1087			return put_user(val, ip);
  1088		case SG_GET_REQUEST_TABLE:
  1089			{
  1090				sg_req_info_t *rinfo;
  1091	
  1092				rinfo = kcalloc(SG_MAX_QUEUE, SZ_SG_REQ_INFO,
  1093						GFP_KERNEL);
  1094				if (!rinfo)
  1095					return -ENOMEM;
  1096				read_lock_irqsave(&sfp->rq_list_lock, iflags);
  1097				sg_fill_request_table(sfp, rinfo);
  1098				read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
  1099		#ifdef CONFIG_COMPAT
  1100				if (in_compat_syscall())
  1101					result = put_compat_request_table(p, rinfo);
  1102				else
  1103		#endif
  1104					result = copy_to_user(p, rinfo,
  1105							      SZ_SG_REQ_INFO * SG_MAX_QUEUE);
  1106				result = result ? -EFAULT : 0;
  1107				kfree(rinfo);
  1108				return result;
  1109			}
  1110		case SG_EMULATED_HOST:
  1111			if (atomic_read(&sdp->detaching))
  1112				return -ENODEV;
  1113			return put_user(sdp->device->host->hostt->emulated, ip);
  1114		case SCSI_IOCTL_SEND_COMMAND:
  1115			if (atomic_read(&sdp->detaching))
  1116				return -ENODEV;
  1117			return sg_scsi_ioctl(sdp->device->request_queue, NULL, filp->f_mode, p);
  1118		case SG_SET_DEBUG:
  1119			result = get_user(val, ip);
  1120			if (result)
  1121				return result;
  1122			sdp->sgdebug = (char) val;
  1123			return 0;
  1124		case BLKSECTGET:
  1125			return put_user(max_sectors_bytes(sdp->device->request_queue),
  1126					ip);
  1127		case BLKTRACESETUP:
  1128			return blk_trace_setup(sdp->device->request_queue,
  1129					       sdp->disk->disk_name,
  1130					       MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
  1131					       NULL, p);
  1132		case BLKTRACESTART:
  1133			return blk_trace_startstop(sdp->device->request_queue, 1);
  1134		case BLKTRACESTOP:
  1135			return blk_trace_startstop(sdp->device->request_queue, 0);
  1136		case BLKTRACETEARDOWN:
  1137			return blk_trace_remove(sdp->device->request_queue);
  1138		case SCSI_IOCTL_GET_IDLUN:
  1139		case SCSI_IOCTL_GET_BUS_NUMBER:
  1140		case SCSI_IOCTL_PROBE_HOST:
  1141		case SG_GET_TRANSFORM:
  1142		case SG_SCSI_RESET:
  1143			if (atomic_read(&sdp->detaching))
  1144				return -ENODEV;
  1145			break;
  1146		default:
  1147			if (read_only)
  1148				return -EPERM;	/* don't know so take safe approach */
  1149			break;
  1150		}
  1151	
  1152		result = scsi_ioctl_block_when_processing_errors(sdp->device,
  1153				cmd_in, filp->f_flags & O_NDELAY);
  1154		if (result)
  1155			return result;
  1156	
  1157		return -ENOIOCTLCMD;
  1158	}
  1159	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 35513 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: clear UAC before sending SG_IO
  2020-09-10 10:15 [PATCH] scsi: clear UAC before sending SG_IO Randall Huang
  2020-09-10 14:36 ` kernel test robot
  2020-09-10 16:36 ` kernel test robot
@ 2020-09-10 17:43 ` Douglas Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Douglas Gilbert @ 2020-09-10 17:43 UTC (permalink / raw)
  To: Randall Huang, jejb, martin.petersen, linux-scsi, linux-kernel

On 2020-09-10 6:15 a.m., Randall Huang wrote:
> Make sure UAC is clear before sending SG_IO.
> 
> Signed-off-by: Randall Huang <huangrandall@google.com>

This patch just looks wrong. Imagine if every LLD front loaded some LLD
specific code before each invocation of ioctl(SG_IO). Is UAC Unit Attention
Condition? If so the mid-level notes them as they fly past.

Haven't looked at the rest of the patchset but I suspect the "wlun_clr_uac"
work needs a rethink. If that is the REPORT LUNS Well known LUN then perhaps
it could be handled in the mid-level scanning code. Otherwise it should
be handled in the LLD/UFS.

Also users of ioctl(SG_IO) should be capable of handling UAs, even if they
are irrelevant, and repeat the invocation. Finally ioctl(sg_dev, SG_IO) is
not the only way to send a pass-through command, there are also
   - write(sg_dev, ...)
   - ioctl(bsg_dev, SG_IO, ...)
   - ioctl(most_blk_devs, SG_IO, ...)
   - ioctl(st_dev, SG_IO, ...)

Hopefully I have convinced you by now not to take this route.

Doug Gilbert

> ---
>   drivers/scsi/sg.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 20472aaaf630..ad11bca47ae8 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -922,6 +922,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
>   	int result, val, read_only;
>   	Sg_request *srp;
>   	unsigned long iflags;
> +	int _cmd;
>   
>   	SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
>   				   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
> @@ -933,6 +934,13 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
>   			return -ENODEV;
>   		if (!scsi_block_when_processing_errors(sdp->device))
>   			return -ENXIO;
> +
> +		_cmd = SCSI_UFS_REQUEST_SENSE;
> +		if (sdp->device->host->wlun_clr_uac) {
> +			sdp->device->host->hostt->ioctl(sdp->device, _cmd, NULL);
> +			sdp->device->host->wlun_clr_uac = false;
> +		}
> +
>   		result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
>   				 1, read_only, 1, &srp);
>   		if (result < 0)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-10 21:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10 10:15 [PATCH] scsi: clear UAC before sending SG_IO Randall Huang
2020-09-10 14:36 ` kernel test robot
2020-09-10 16:36 ` kernel test robot
2020-09-10 17:43 ` Douglas Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).