From 8276dc53d32254753df4d35dcc6e2eafcb5ffe7a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 16:43:13 +0000 Subject: [PATCH 1/9] scstadmin: Make scstadmin again compatible with older Perl interpreters Fix the following Perl v5.10.1 warnings: Ambiguous use of -ENOENT resolved as -&ENOENT() at /usr/local/share/perl5/SCST/SCST.pm line ... According to https://stackoverflow.com/questions/23215511/ambiguous-use-of-constant-resolved-as-constant that message indicates a bug in the Perl interpreter. Reported-by: Gilbert Standen git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8928 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index 453a82e69..ca5c6537c 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -539,7 +539,7 @@ sub setScstAttribute { return TRUE if (!defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_ROOT_DIR(), $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { @@ -1053,7 +1053,7 @@ sub addDriverDynamicAttribute { } $cmd .= "add_attribute $attribute $value"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1096,7 +1096,7 @@ sub removeDriverDynamicAttribute { } $cmd .= "del_attribute $attribute $value"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1203,7 +1203,7 @@ sub addVirtualTarget { } $cmd .= "add_target $target $o_string"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1338,7 +1338,7 @@ sub addTargetDynamicAttribute { } $cmd .= "add_target_attribute $target $attribute $value"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1387,7 +1387,7 @@ sub removeTargetDynamicAttribute { } $cmd .= "del_target_attribute $target $attribute $value"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1464,7 +1464,7 @@ sub removeVirtualTarget { } $cmd .= "del_target $target"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1597,7 +1597,7 @@ sub addGroup { } $cmd .= "create $group"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1644,7 +1644,7 @@ sub removeGroup { } $cmd .= "del $group"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1686,7 +1686,7 @@ sub addDeviceGroup { } $cmd .= "create $group"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1718,7 +1718,7 @@ sub removeDeviceGroup { } $cmd .= "del $group"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1756,7 +1756,7 @@ sub addDeviceGroupDevice { } $cmd .= "add $device"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1812,7 +1812,7 @@ sub addTargetGroup { } $cmd .= "add $tgroup"; - my $bytes = -ENONENT; + my $bytes = - ENONENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1854,7 +1854,7 @@ sub addTargetGroupTarget { } $cmd .= "add $tgt"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1895,7 +1895,7 @@ sub removeDeviceGroupDevice { } $cmd .= "del $device"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1939,7 +1939,7 @@ sub removeTargetGroup { } $cmd .= "del $tgroup"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -1981,7 +1981,7 @@ sub removeTargetGroupTarget { } $cmd .= "del $tgt"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2032,7 +2032,7 @@ sub addInitiator { } $cmd .= "add $initiator"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2089,7 +2089,7 @@ sub removeInitiator { } $cmd .= "del $initiator"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2141,7 +2141,7 @@ sub moveInitiator { } $cmd .= "move $initiator $to"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2199,7 +2199,7 @@ sub clearInitiators { } $cmd .= "clear"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2274,7 +2274,7 @@ sub addLun { $cmd .= "add $device $lun $o_string"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2352,7 +2352,7 @@ sub removeLun { } $cmd .= "del $lun"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2464,7 +2464,7 @@ sub replaceLun { } $cmd .= "replace $device $lun $o_string"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2513,7 +2513,7 @@ sub clearLuns { } $cmd .= "clear"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2847,7 +2847,7 @@ sub setDriverAttribute { my $path = make_path(SCST_TARGETS_DIR(), $driver, $attribute); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -2995,7 +2995,7 @@ sub setTargetAttribute { $cmd = $value; } - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -3129,7 +3129,7 @@ sub setGroupAttribute { } $cmd .= $value; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -3289,7 +3289,7 @@ sub setLunAttribute { SCST_LUNS, $lun, $attribute); } - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -3432,7 +3432,7 @@ sub setInitiatorAttribute { my $path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, $group, SCST_LUNS, $initiator, $attribute); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -3719,7 +3719,7 @@ sub setAluaAttribute { return TRUE if (!defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { @@ -3744,7 +3744,7 @@ sub setDeviceGroupAttribute { return TRUE if (!defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { @@ -3775,7 +3775,7 @@ sub setTargetGroupAttribute { return TRUE if (!defined($group) || !defined($tgroup) || !defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup, $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { @@ -3812,7 +3812,7 @@ sub setTargetGroupTargetAttribute { !defined($tgt) || !defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup, $tgt, $attribute); my $io = new IO::File $path, O_WRONLY; @@ -3892,7 +3892,7 @@ sub setHandlerAttribute { return TRUE if (!defined($attribute) || !defined($value)); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $path = make_path(SCST_HANDLERS_DIR(), $handler, $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { @@ -4192,7 +4192,7 @@ sub openDevice { } $cmd .= "add_device $device $o_string"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -4240,7 +4240,7 @@ sub closeDevice { } $cmd .= "del_device $device"; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -4283,7 +4283,7 @@ sub setDeviceAttribute { } $cmd .= $value; - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { if ($self->{'debug'}) { @@ -4809,7 +4809,7 @@ sub closeSession { my $path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_SESSIONS, $session, 'force_close'); - my $bytes = -ENOENT; + my $bytes = - ENOENT; my $io = new IO::File $path, O_WRONLY; if ($io) { my $cmd = "1"; @@ -4922,12 +4922,12 @@ sub _syswrite { my $bytes = syswrite($io, $cmd, $length); $bytes = -$! if (!defined($bytes)); - if (defined($res_file) && $bytes == -EAGAIN) { + if (defined($res_file) && $bytes == - EAGAIN) { my $res_io = new IO::File $res_file, O_RDONLY; if (!$res_io) { cluck("FATAL: Failed opening $res_file: $!"); - return -ENOENT; + return - ENOENT; } my $res_val; From 54ccb1add2f9798c36c9bf138f9b3358273ca768 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 19:54:19 +0000 Subject: [PATCH 2/9] scst: Fix a debug statement in __scst_adjust_sg() Instead of printing the same 'sg' pointer in each iteration, print the sgi pointer. Fixes: commit 2755c024215f ("scst: Introduce for_each_sg() in scst_adjust_sg()") # v3.0.0 (r4910). git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8929 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 7c4e858bd..687b8864c 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -3305,13 +3305,8 @@ static bool __scst_adjust_sg(struct scst_cmd *cmd, struct scatterlist *sg, l = 0; for_each_sg(sg, sgi, *sg_cnt, i) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) - TRACE_DBG("i %d, sg_cnt %d, sg %p, page_link %lx, len %d", i, - *sg_cnt, sg, sgi->page_link, sgi->length); -#else - TRACE_DBG("i %d, sg_cnt %d, sg %p, page_link %lx", i, - *sg_cnt, sg, 0UL); -#endif + TRACE_DBG("sg[%d/%d]: addr %p, offset %d, len %d", i, *sg_cnt, + sgi, sgi->offset, sgi->length); l += sgi->length; if (l >= adjust_len) { int left = adjust_len - (l - sgi->length); From b30634f6e0f4ed8f96b16dd1414d7c685f9a1f2e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 19:57:13 +0000 Subject: [PATCH 3/9] scst: Improve scst_adjust_sg() documentation git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8930 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 61 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 687b8864c..4cb0e4c79 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -3294,6 +3294,18 @@ next: return; } +/** + * __scst_adjust_sg - reduce the length of a scatterlist + * @cmd: [in] SCST command that owns the scatterlist. + * @sg: [in/out] Scatterlist of which to reduce the length. + * @sg_cnt: [in/out] Number of elements of the scatterlist. + * @adjust_len: [in] New length of the scatterlist in bytes. + * @orig_sg: [out] Information needed to restore the original scatterlist. + * + * Return: + * True if @adjust_len was less than or equal to the length of @sg; false + * otherwise. + */ static bool __scst_adjust_sg(struct scst_cmd *cmd, struct scatterlist *sg, int *sg_cnt, int adjust_len, struct scst_orig_sg_data *orig_sg) { @@ -3334,9 +3346,11 @@ static bool __scst_adjust_sg(struct scst_cmd *cmd, struct scatterlist *sg, return res; } -/* - * Makes cmd's SG shorter on adjust_len bytes. Reg_sg is true for cmd->sg - * and false for cmd->write_sg. +/** + * scst_adjust_sg - reduce the length of the scatterlist of a command + * @cmd: [in/out] SCST command that owns the scatterlist. + * @reg_sg: [in] True selects cmd->sg; false selects cmd->write_sg. + * @adjust_len: [in] New length of the scatterlist in bytes. */ static void scst_adjust_sg(struct scst_cmd *cmd, bool reg_sg, int adjust_len) @@ -3380,6 +3394,21 @@ static void scst_adjust_sg(struct scst_cmd *cmd, bool reg_sg, return; } +/** + * __scst_adjust_sg_get_tail - reduce a scatterlist to its tail + * @cmd: [in] SCST command that owns the scatterlist. + * @sg: [in/out] Scatterlist of which to reduce the length. + * @sg_cnt: [in/out] Number of elements of the scatterlist. + * @res_sg: [out] Pointer to first scatterlist element of the tail. + * @res_sg_cnt: [out] Number of scatterlist elements in the tail. + * @adjust_len: [in] New length of the scatterlist in bytes. + * @orig_sg: [out] Information needed to restore the original scatterlist. + * @must_left: [in] How many bytes must remain in @res_sg to consider the + * operation successful. + * + * Return: + * 0 upon sucess; a negative value upon error. + */ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, struct scatterlist *sg, int *sg_cnt, struct scatterlist **res_sg, int *res_sg_cnt, @@ -3461,18 +3490,24 @@ out: return res; } -/* - * Returns in res_sg the tail of cmd's adjusted on adjust_len, i.e. tail - * of it. In res_sg_cnt sg_cnt of res_sg returned. Cmd only used to store - * cmd->sg restore information. +/** + * scst_adjust_sg_get_tail - reduce a scatterlist of a command to its tail + * @cmd: [in] SCST command that owns the scatterlist. Information + * about how to restore the scatterlist will be stored + * in @cmd. + * @res_sg: [out] Pointer to first scatterlist element of the tail. + * @res_sg_cnt: [out] Number of scatterlist elements in the tail. + * @res_dif_sg: [out] Pointer to first scatterlist element of the DIF tail. + * @res_dif_sg_cnt: [out] Number of scatterlist elements in the DIF tail. + * @adjust_len: [in] New length of the scatterlist in bytes. + * @must_left: [in] How many bytes must remain in @res_sg to consider the + * operation successful. * - * Parameter must_left defines how many bytes must left in res_sg to consider - * operation successful. + * Return: + * 0 upon success; a negative value upon error. * - * Returns 0 on success or error code otherwise. - * - * NOTE! Before scst_restore_sg_buff() called cmd->sg is corrupted and - * can NOT be used! + * NOTE! Until scst_restore_sg_buff() is called, @cmd->sg is corrupted and + * must NOT be used! */ static int scst_adjust_sg_get_tail(struct scst_cmd *cmd, struct scatterlist **res_sg, int *res_sg_cnt, From edff6da84e94a1776a00e52119b009fd256b91b8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 20:01:47 +0000 Subject: [PATCH 4/9] scst: Introduce a new local variable in __scst_adjust_sg_get_tail() This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8931 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4cb0e4c79..dd6281875 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -3414,6 +3414,7 @@ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, struct scatterlist **res_sg, int *res_sg_cnt, int adjust_len, struct scst_orig_sg_data *orig_sg, int must_left) { + struct scatterlist *sgi; int res = -ENOENT, i, j, l; TRACE_ENTRY(); @@ -3422,45 +3423,41 @@ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, l = 0; for (i = 0, j = 0; i < *sg_cnt; i++, j++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) - TRACE_DBG("i %d, j %d, sg %p, page_link %lx, len %d", i, j, - sg, sg[j].page_link, sg->length); -#else - TRACE_DBG("i %d, j %d, sg %p", i, j, sg); -#endif - if (unlikely(sg_is_chain(&sg[j]))) { - sg = sg_chain_ptr(&sg[j]); + sgi = &sg[j]; + TRACE_DBG("i %d, j %d, sg %p, len %d", i, j, sgi, sgi->length); + if (unlikely(sg_is_chain(sgi))) { + sgi = sg = sg_chain_ptr(sgi); j = 0; } - l += sg[j].length; + l += sgi->length; if (l >= adjust_len) { - int offs = adjust_len - (l - sg[j].length); + int offs = adjust_len - (l - sgi->length); TRACE_DBG_FLAG(TRACE_SG_OP|TRACE_MEMORY|TRACE_DEBUG, - "cmd %p (tag %llu), sg %p, adjust_len %d, i %d, " - "j %d, sg[j].length %d, offs %d", + "cmd %p (tag %llu), sg %p, adjust_len %d, i %d, j %d, sg->length %d, offs %d", cmd, (unsigned long long)cmd->tag, - sg, adjust_len, i, j, sg[j].length, offs); + sg, adjust_len, i, j, sgi->length, offs); - if (offs == sg[j].length) { + if (offs == sgi->length) { + sgi = sg_next(sgi); j++; offs = 0; } orig_sg->p_orig_sg_cnt = sg_cnt; orig_sg->orig_sg_cnt = *sg_cnt; - orig_sg->orig_sg_entry = &sg[j]; - orig_sg->orig_entry_offs = sg[j].offset; - orig_sg->orig_entry_len = sg[j].length; + orig_sg->orig_sg_entry = sgi; + orig_sg->orig_entry_offs = sgi->offset; + orig_sg->orig_entry_len = sgi->length; - sg[j].offset += offs; - sg[j].length -= offs; - *res_sg = &sg[j]; + sgi->offset += offs; + sgi->length -= offs; + *res_sg = sgi; *res_sg_cnt = *sg_cnt - j; - TRACE_DBG("j %d, sg %p, off %d, len %d, cnt %d " - "(offs %d)", j, &sg[j], sg[j].offset, - sg[j].length, *res_sg_cnt, offs); + TRACE_DBG("j %d, sg %p, off %d, len %d, cnt %d (offs %d)", + j, sgi, sgi->offset, sgi->length, *res_sg_cnt, + offs); res = 0; break; From 1cd44e93ad915a0ec839746bc7b73ddc3e19afeb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 20:58:06 +0000 Subject: [PATCH 5/9] scst: Fix __scst_adjust_sg_get_tail() Set *res_sg_cnt correctly in case the scatterlist is chained. Support chained scatterlists in the loop that calculates the number of bytes left. Fix restoring the original SG list in case an error happens: scst_check_restore_sg_buff() only restores the original sg list if cmd->sg_buff_modified has been set. However, __scst_adjust_sg_get_tail() does not set that variable. This patch fixes the following kernel complaints triggered by COMPARE AND WRITE (see also https://github.com/bvanassche/scst/issues/22): scst_adjust_sg_get_tail() failed: -22 WARNING: CPU: 2 PID: 1179 at /home/bart/software/scst.git/scst/src/scst_lib.c:6860 scst_cwr_read_cmd_finished+0x954/0xb10 [scst] CPU: 2 PID: 1179 Comm: disk011_0 Tainted: G O 5.7.0-rc4-dbg+ #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4-rebuilt.opensuse.org 04/01/2014 RIP: 0010:scst_cwr_read_cmd_finished+0x954/0xb10 [scst] Call Trace: scst_finish_internal_cmd+0x1f8/0x3c0 [scst] scst_process_active_cmd+0x594/0x17f0 [scst] scst_cmd_thread+0x470/0xc30 [scst] kthread+0x211/0x240 ret_from_fork+0x24/0x30 WARNING: CPU: 2 PID: 1179 at /home/bart/software/scst.git/scst/src/../include/scst.h:5030 blockio_exec_rw+0xbb2/0xe00 [scst_vdisk] CPU: 2 PID: 1179 Comm: disk011_0 Tainted: G W O 5.7.0-rc4-dbg+ #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4-rebuilt.opensuse.org 04/01/2014 RIP: 0010:blockio_exec_rw+0xbb2/0xe00 [scst_vdisk] Call Trace: blockio_exec_write+0x9c/0x160 [scst_vdisk] vdev_do_job+0xe8/0x290 [scst_vdisk] blockio_exec+0x153/0x4b0 [scst_vdisk] scst_do_real_exec+0xf4/0x680 [scst] scst_exec_check_blocking+0x24e/0x7b0 [scst] scst_exec_check_sn+0x252/0x7d0 [scst] scst_process_active_cmd+0x9a0/0x17f0 [scst] scst_cmd_thread+0x37e/0xc30 [scst] kthread+0x211/0x240 ret_from_fork+0x24/0x30 BUG: KASAN: slab-out-of-bounds in __scst_adjust_sg_get_tail+0x2da/0x550 [scst] Read of size 4 at addr ffff8881dd9b93cc by task disk011_0/1179 CPU: 3 PID: 1179 Comm: disk011_0 Tainted: G W O 5.7.0-rc4-dbg+ #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4-rebuilt.opensuse.org 04/01/2014 Call Trace: dump_stack+0xa5/0xe6 print_address_description.constprop.0+0x46/0x60 __kasan_report.cold+0x94/0xbb kasan_report+0x45/0x60 __asan_load4+0x6f/0x90 __scst_adjust_sg_get_tail+0x2da/0x550 [scst] scst_cwr_read_cmd_finished+0x574/0xb10 [scst] scst_finish_internal_cmd+0x1f8/0x3c0 [scst] scst_process_active_cmd+0x594/0x17f0 [scst] scst_cmd_thread+0x470/0xc30 [scst] kthread+0x211/0x240 ret_from_fork+0x24/0x30 Allocated by task 1549: save_stack+0x23/0x50 __kasan_kmalloc.constprop.0+0xcf/0xe0 kasan_slab_alloc+0x12/0x20 kmem_cache_alloc+0x101/0x370 mempool_alloc_slab+0x1b/0x20 mempool_alloc+0xf3/0x2b0 sg_pool_alloc+0x58/0xb0 __sg_alloc_table+0x14e/0x1c0 sg_alloc_table_chained+0x4f/0xf0 scsi_init_io+0x144/0x6d0 [scsi_mod] scsi_queue_rq+0xabc/0xe00 [scsi_mod] blk_mq_dispatch_rq_list+0x6ad/0xd10 __blk_mq_sched_dispatch_requests+0x1e9/0x2c0 blk_mq_sched_dispatch_requests+0x8e/0xc0 __blk_mq_run_hw_queue+0x128/0x1e0 __blk_mq_delay_run_hw_queue+0x2dd/0x310 blk_mq_run_hw_queue+0x145/0x1e0 blk_mq_sched_insert_request+0x236/0x360 blk_execute_rq_nowait+0x8e/0xa0 blk_execute_rq+0xe1/0x160 sg_io+0x43b/0x7a0 scsi_cmd_ioctl+0x27a/0x3e0 scsi_cmd_blk_ioctl+0x83/0x95 sd_ioctl_common+0xb6/0x150 [sd_mod] sd_ioctl+0x20/0x80 [sd_mod] blkdev_ioctl+0x1c3/0x3c0 block_ioctl+0x87/0xa0 ksys_ioctl+0x8e/0xd0 __x64_sys_ioctl+0x47/0x50 do_syscall_64+0x6f/0x310 entry_SYSCALL_64_after_hwframe+0x49/0xb3 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8932 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index dd6281875..4caac75da 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -3415,32 +3415,27 @@ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, int adjust_len, struct scst_orig_sg_data *orig_sg, int must_left) { struct scatterlist *sgi; - int res = -ENOENT, i, j, l; + int res = -ENOENT, i, l; TRACE_ENTRY(); TRACE_DBG("cmd %p, sg_cnt %d, sg %p", cmd, *sg_cnt, sg); l = 0; - for (i = 0, j = 0; i < *sg_cnt; i++, j++) { - sgi = &sg[j]; - TRACE_DBG("i %d, j %d, sg %p, len %d", i, j, sgi, sgi->length); - if (unlikely(sg_is_chain(sgi))) { - sgi = sg = sg_chain_ptr(sgi); - j = 0; - } + for_each_sg(sg, sgi, *sg_cnt, i) { + TRACE_DBG("i %d, sg %p, len %d", i, sgi, sgi->length); l += sgi->length; if (l >= adjust_len) { int offs = adjust_len - (l - sgi->length); TRACE_DBG_FLAG(TRACE_SG_OP|TRACE_MEMORY|TRACE_DEBUG, - "cmd %p (tag %llu), sg %p, adjust_len %d, i %d, j %d, sg->length %d, offs %d", + "cmd %p (tag %llu), sg %p, adjust_len %d, i %d, sg->length %d, offs %d", cmd, (unsigned long long)cmd->tag, - sg, adjust_len, i, j, sgi->length, offs); + sg, adjust_len, i, sgi->length, offs); if (offs == sgi->length) { sgi = sg_next(sgi); - j++; + i++; offs = 0; } @@ -3453,10 +3448,10 @@ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, sgi->offset += offs; sgi->length -= offs; *res_sg = sgi; - *res_sg_cnt = *sg_cnt - j; + *res_sg_cnt = *sg_cnt - i; - TRACE_DBG("j %d, sg %p, off %d, len %d, cnt %d (offs %d)", - j, sgi, sgi->offset, sgi->length, *res_sg_cnt, + TRACE_DBG("i %d, sg %p, off %d, len %d, cnt %d (offs %d)", + i, sgi, sgi->offset, sgi->length, *res_sg_cnt, offs); res = 0; @@ -3469,15 +3464,17 @@ static int __scst_adjust_sg_get_tail(struct scst_cmd *cmd, #ifdef CONFIG_SCST_EXTRACHECKS l = 0; - sg = *res_sg; - for (i = 0; i < *res_sg_cnt; i++) - l += sg[i].length; + for_each_sg(*res_sg, sgi, *res_sg_cnt, i) + l += sgi->length; if (l != must_left) { PRINT_ERROR("Incorrect length %d of adjusted sg (cmd %p, " "expected %d)", l, cmd, must_left); res = -EINVAL; - scst_check_restore_sg_buff(cmd); + (*res_sg)->offset = orig_sg->orig_entry_offs; + (*res_sg)->length = orig_sg->orig_entry_len; + *res_sg = NULL; + *res_sg_cnt = 0; goto out; } #endif From 5529400fd508babd1787064e6bd954cb71b75299 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 20:58:38 +0000 Subject: [PATCH 6/9] .gitignore: Add built-in.a git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8933 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fc39ba618..b2b65ad73 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ .depend_f .directory .tmp_versions +built-in.a debian/*.debhelper.log debian/*.substvars debian/.debhelper/ From 21edb121be9a38458d0f8abcccc3cfa9f76e83f3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 21:02:43 +0000 Subject: [PATCH 7/9] ib_srpt: Fix handling of iWARP logins The path_rec pointer is set for IB and RoCE logins but not for iWARP logins. Hence check the path_rec pointer before dereferencing it. See also upstream commit cbca2442a096 ("RDMA/srpt: Fix handling of iWARP logins") # v5.5. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8934 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 989ed72f4..165c1a432 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -3007,6 +3007,11 @@ static int srpt_rdma_cm_req_recv(struct rdma_cm_id *cm_id, struct srpt_device *sdev; struct srp_login_req req; const struct srp_login_req_rdma *req_rdma; + /* + * See also commit c2f8fc4ec440 ("IB/SA: Rename ib_sa_path_rec to + * sa_path_rec") # v4.12. + */ + typeof(cm_id->route.path_rec) path_rec = cm_id->route.path_rec; char src_addr[40]; sdev = ib_get_client_data(cm_id->device, &srpt_client); @@ -3031,7 +3036,7 @@ static int srpt_rdma_cm_req_recv(struct rdma_cm_id *cm_id, inet_ntop(&cm_id->route.addr.src_addr, src_addr, sizeof(src_addr)); return srpt_cm_req_recv(sdev, NULL, cm_id, cm_id->port_num, - cm_id->route.path_rec->pkey, &req, src_addr); + path_rec ? path_rec->pkey : 0, &req, src_addr); } static void srpt_cm_rej_recv(struct srpt_rdma_ch *ch, From fa4383ce03197c21db912260dbc1f7b655f76197 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 21:04:03 +0000 Subject: [PATCH 8/9] scst: Document __scst_create_prepare_internal_cmd() git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8935 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4caac75da..b24d3e69d 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5766,7 +5766,18 @@ out: return acn; } - +/** + * __scst_create_prepare_internal_cmd() - Create an internal SCSI command + * @cdb: SCSI CDB. + * @cdb_len: Length in bytes of @cdb. + * @queue_type: One of the SCST_CMD_QUEUE_* constants. + * @tgt_dev: LUN to submit the command to. + * @gfp_mask: GFP mask to use during execution of this command. + * @fantom: If false, add the command to tgt_dev->sess->sess_cmd_list. + * If true, do not add the command to that command list. + * + * Return: pointer to the newly allocated command or NULL. + */ struct scst_cmd *__scst_create_prepare_internal_cmd(const uint8_t *cdb, unsigned int cdb_len, enum scst_cmd_queue_type queue_type, struct scst_tgt_dev *tgt_dev, gfp_t gfp_mask, bool fantom) From e3f76c80a557213664094a51d6f6a15b78ac8b20 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 May 2020 21:06:37 +0000 Subject: [PATCH 9/9] qla2x00t-32gbit: Only use 'pragma GCC diagnostic' if supported by gcc git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8936 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t-32gbit/include/trace/events/qla.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qla2x00t-32gbit/include/trace/events/qla.h b/qla2x00t-32gbit/include/trace/events/qla.h index 737a667ab..e3b470023 100644 --- a/qla2x00t-32gbit/include/trace/events/qla.h +++ b/qla2x00t-32gbit/include/trace/events/qla.h @@ -9,8 +9,10 @@ #define QLA_MSG_MAX 256 +#if __GNUC__ * 256 + __GNUC_MINOR__ >= 4 * 256 + 6 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif DECLARE_EVENT_CLASS(qla_log_event, TP_PROTO(const char *buf, @@ -35,7 +37,9 @@ DEFINE_EVENT(qla_log_event, ql_dbg_log, TP_ARGS(buf, vaf) ); +#if __GNUC__ * 256 + __GNUC_MINOR__ >= 4 * 256 + 6 #pragma GCC diagnostic pop +#endif #endif /* _TRACE_QLA_H */