Commit Graph

8984 Commits

Author SHA1 Message Date
Gleb Chesnokov
55ef00a79a qla2x00t: Avoid flush_scheduled_work() usage
See also commit c014d35e7d ("qla2x00t-32gbit: Avoid
flush_scheduled_work() usage").
2023-10-10 14:51:33 +03:00
Gleb Chesnokov
48e04668d6 qla2x00t: Drop redundant pci_enable_pcie_error_reporting()
See also commits:

- 7d1afe8a ("qla2x00t-32gbit: Drop redundant
  pci_enable_pcie_error_reporting()").

- 596800ce ("qla2x00t-32gbit: Backport to older kernel versions").
2023-10-10 14:51:33 +03:00
Gleb Chesnokov
60c26136bf scst/include/backport.h: Unbreak the RHEL 9.3 build
Fixes: https://github.com/SCST-project/scst/issues/167
2023-10-09 09:46:21 +03:00
Gleb Chesnokov
c71c284f93 nightly build: Update kernel versions
Another kernel versions update following the 6.5 release.
2023-09-21 10:27:58 +03:00
Brian Meagher
3c8f66e2b8 Add support for iSCSI TargetAlias
This includes both support during iSCSI LOGIN and iSNS.
2023-08-22 10:02:40 +03:00
Gleb Chesnokov
c00af8aab9 scst_lib: Improve scst_put_acg()
This patch refactors scst_put_acg() to directly call kref_put() with a
release callback that handles removal of scst_acg from the workqueue.
This replaces the previous approach of queuing a work item for each
kref_put() call, improving efficiency by reducing the number of queued
work items.
2023-07-21 10:38:52 +03:00
Gleb Chesnokov
4b840aeee3 scst: Do not use WQ_MEM_RECLAIM flag for workqueues
According to kernel documentation, this flag should be set if the
workqueue will be involved in the kernel's memory reclamation flow.
Since it is not, there is no need for the driver's WQ to have this
flag set so remove it.
2023-07-21 10:38:52 +03:00
Gleb Chesnokov
1f0ce86f3c scst: Fix removal of deprecated create_workqueue()
create_workqueue() was replaced with alloc_workqueue() with max_active set
to 0. However, the original create_workqueue() implicitly set max_active
to 1.

This change has led to unexpected bugs because previously, work items
could only be executed one by one. With the change, they can now be
executed simultaneously.

This patch fixes the issue by restoring max_active to 1.

Fixes: f4686e9102 ("scst: Remove deprecated create_workqueue()")
Fixes: https://github.com/SCST-project/scst/issues/179
2023-07-21 10:38:52 +03:00
Gleb Chesnokov
87235dfe3a scst: Use vmalloc_array() and vcalloc()
Use vmalloc_array() and vcalloc() to protect against multiplication
overflows.

The changes were done using the following Coccinelle
semantic patch:

// <smpl>
@initialize:ocaml@
@@

let rename alloc =
  match alloc with
    "vmalloc" -> "vmalloc_array"
  | "vzalloc" -> "vcalloc"
  | _ -> failwith "unknown"

@@
    size_t e1,e2;
    constant C1, C2;
    expression E1, E2, COUNT, x1, x2, x3;
    typedef u8;
    typedef __u8;
    type t = {u8,__u8,char,unsigned char};
    identifier alloc = {vmalloc,vzalloc};
    fresh identifier realloc = script:ocaml(alloc) { rename alloc };
@@

(
      alloc(x1*x2*x3)
|
      alloc(C1 * C2)
|
      alloc((sizeof(t)) * (COUNT), ...)
|
-     alloc((e1) * (e2))
+     realloc(e1, e2)
|
-     alloc((e1) * (COUNT))
+     realloc(COUNT, e1)
|
-     alloc((E1) * (E2))
+     realloc(E1, E2)
)
// </smpl>
2023-07-21 10:38:34 +03:00
Gleb Chesnokov
ceff753e13 qla2x00t-32gbit: Fix error code in qla2x00_start_sp()
This should be negative -EAGAIN instead of positive.  The callers treat
non-zero error codes the same so it doesn't really impact runtime beyond
some trivial differences to debug output.

Fixes: 80676d054e5a ("scsi: qla2xxx: Fix session cleanup hang")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/49866d28-4cfe-47b0-842b-78f110e61aab@moroto.mountain
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit e579b007eff3f upstream ]
2023-07-21 10:38:34 +03:00
Gleb Chesnokov
1d37f637e6 qla2x00t-32gbit: Silence a static checker warning
Smatch and Clang both complain that LOGIN_TEMPLATE_SIZE is more than
sizeof(ha->plogi_els_payld.fl_csp).

Smatch warning:
    drivers/scsi/qla2xxx/qla_iocb.c:3075 qla24xx_els_dcmd2_iocb()
    warn: '&ha->plogi_els_payld.fl_csp' sometimes too small '16' size = 112

Clang warning:
    include/linux/fortify-string.h:592:4: error: call to
    '__read_overflow2_field' declared with 'warning' attribute: detected
    read beyond size of field (2nd parameter); maybe use struct_group()?
    [-Werror,-Wattribute-warning]
                        __read_overflow2_field(q_size_field, size);

When I was reading this code I assumed the "- 4" meant that we were
skipping the last 4 bytes but actually it turned out that we are
skipping the first four bytes.

I have re-written it remove the magic numbers, be more clear and
silence the static checker warnings.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/4aa0485e-766f-4b02-8d5d-c6781ea8f511@moroto.mountain
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 134f66959cd0b upstream ]
2023-07-21 10:38:34 +03:00
Gleb Chesnokov
7076a91a3b qla2x00t-32gbit: Remove unused nvme_ls_waitq wait queue
System crash when qla2x00_start_sp(sp) returns error code EGAIN and wake_up
gets called for uninitialized wait queue sp->nvme_ls_waitq.

    qla2xxx [0000:37:00.1]-2121:5: Returning existing qpair of ffff8ae2c0513400 for idx=0
    qla2xxx [0000:37:00.1]-700e:5: qla2x00_start_sp failed = 11
    BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
    PGD 0 P4D 0
    Oops: 0000 [#1] SMP NOPTI
    Hardware name: HPE ProLiant DL360 Gen10/ProLiant DL360 Gen10, BIOS U32 09/03/2021
    Workqueue: nvme-wq nvme_fc_connect_ctrl_work [nvme_fc]
    RIP: 0010:__wake_up_common+0x4c/0x190
    RSP: 0018:ffff95f3e0cb7cd0 EFLAGS: 00010086
    RAX: 0000000000000000 RBX: ffff8b08d3b26328 RCX: 0000000000000000
    RDX: 0000000000000001 RSI: 0000000000000003 RDI: ffff8b08d3b26320
    RBP: 0000000000000001 R08: 0000000000000000 R09: ffffffffffffffe8
    R10: 0000000000000000 R11: ffff95f3e0cb7a60 R12: ffff95f3e0cb7d20
    R13: 0000000000000003 R14: 0000000000000000 R15: 0000000000000000
    FS:  0000000000000000(0000) GS:ffff8b2fdf6c0000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000000000000 CR3: 0000002f1e410002 CR4: 00000000007706e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    PKRU: 55555554
    Call Trace:
     __wake_up_common_lock+0x7c/0xc0
     qla_nvme_ls_req+0x355/0x4c0 [qla2xxx]
     ? __nvme_fc_send_ls_req+0x260/0x380 [nvme_fc]
     ? nvme_fc_send_ls_req.constprop.42+0x1a/0x45 [nvme_fc]
     ? nvme_fc_connect_ctrl_work.cold.63+0x1e3/0xa7d [nvme_fc]

Remove unused nvme_ls_waitq wait queue. nvme_ls_waitq logic was removed
previously in the commits tagged Fixed: below.

Fixes: 219d27d7147e ("scsi: qla2xxx: Fix race conditions in the code for aborting SCSI commands")
Fixes: 5621b0dd7453 ("scsi: qla2xxx: Simpify unregistration of FC-NVMe local/remote ports")
Cc: stable@vger.kernel.org
Signed-off-by: Manish Rangankar <mrangankar@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230615074633.12721-1-njavali@marvell.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 20fce500b232 upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
29d26d69db qla2x00t-32gbit: Update version to 10.02.08.400-k
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-9-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 991e7ac609ee upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
bb9b171dc4 qla2x00t-32gbit: Correct the index of array
Klocwork reported array 'port_dstate_str' of size 10 may use index value(s)
10..15.

Add a fix to correct the index of array.

Cc: stable@vger.kernel.org
Signed-off-by: Bikash Hazarika <bhazarika@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-8-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit b1b9d3825df4 upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
1f107c7ee5 qla2x00t-32gbit: Pointer may be dereferenced
Klocwork tool reported pointer 'rport' returned from call to function
fc_bsg_to_rport() may be NULL and will be dereferenced.

Add a fix to validate rport before dereferencing.

Cc: stable@vger.kernel.org
Signed-off-by: Shreyas Deodhar <sdeodhar@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-7-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 00eca15319d9 upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
beabef8afc qla2x00t-32gbit: Fix buffer overrun
Klocwork warning: Buffer Overflow - Array Index Out of Bounds

Driver uses fc_els_flogi to calculate size of buffer.  The actual buffer is
nested inside of fc_els_flogi which is smaller.

Replace structure name to allow proper size calculation.

Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-6-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit b68710a8094f upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
a1edff6677 qla2x00t-32gbit: Check valid rport returned by fc_bsg_to_rport()
Klocwork reported warning of rport maybe NULL and will be dereferenced.
rport returned by call to fc_bsg_to_rport() could be NULL and dereferenced.

Check valid rport returned by fc_bsg_to_rport().

Cc: stable@vger.kernel.org
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-5-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit af73f23a2720 upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
bb18381819 qla2x00t-32gbit: Avoid fcport pointer dereference
Klocwork reported warning of NULL pointer may be dereferenced.  The routine
exits when sa_ctl is NULL and fcport is allocated after the exit call thus
causing NULL fcport pointer to dereference at the time of exit.

To avoid fcport pointer dereference, exit the routine when sa_ctl is NULL.

Cc: stable@vger.kernel.org
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-4-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 6b504d06976f upstream ]
2023-07-19 11:45:31 +03:00
Gleb Chesnokov
0367c334c3 qla2x00t-32gbit: Fix potential NULL pointer dereference
Klocwork tool reported 'cur_dsd' may be dereferenced.  Add fix to validate
pointer before dereferencing the pointer.

Cc: stable@vger.kernel.org
Signed-off-by: Bikash Hazarika <bhazarika@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-3-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 464ea494a40c upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
0b9f73b1d8 qla2x00t-32gbit: Array index may go out of bound
Klocwork reports array 'vha->host_str' of size 16 may use index value(s)
16..19.  Use snprintf() instead of sprintf().

Cc: stable@vger.kernel.org
Co-developed-by: Bikash Hazarika <bhazarika@marvell.com>
Signed-off-by: Bikash Hazarika <bhazarika@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230607113843.37185-2-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit d721b591b95c upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
6aff6bfacb qla2x00t-32gbit: Drop useless LIST_HEAD
'new_fcports' is unused, so drop it.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/49bb77624c9edc8d9bf8fe71d0c8a4cd7e582175.1685854354.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 022000d3f586 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
d74330aed2 qla2x00t-32gbit: Backport to older kernel versions
Unbreak the build for the previous commit against kernel versions
before v5.16.

See also commit 3080ea5553cc ("stddef: Introduce DECLARE_FLEX_ARRAY()
helper") # v5.16.
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
cba2284cd1 qla2x00t-32gbit: Replace one-element array with DECLARE_FLEX_ARRAY() helper
One-element arrays as fake flex arrays are deprecated and we are moving
towards adopting C99 flexible-array members, instead. So, replace
one-element array declaration in struct ct_sns_gpnft_rsp, which is
ultimately being used inside a union:

drivers/scsi/qla2xxx/qla_def.h:
3240 struct ct_sns_gpnft_pkt {
3241         union {
3242                 struct ct_sns_req req;
3243                 struct ct_sns_gpnft_rsp rsp;
3244         } p;
3245 };

Refactor the rest of the code, accordingly.

This issue was found with the help of Coccinelle.

Link: https://github.com/KSPP/linux/issues/245
Link: https://github.com/KSPP/linux/issues/193
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/ZH+/rZ1R1cBjIxjS@work
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 512a365368c7 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
d26ab07ae9 qla2x00t-32gbit: Fix end of loop test
This loop will exit successfully when "found" is false or in the failure
case it times out with "wait_iter" set to -1.  The test for timeouts is
impossible as is.

Fixes: b843adde8d49 ("scsi: qla2xxx: Fix mem access after free")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/cea5a62f-b873-4347-8f8e-c67527ced8d2@kili.mountain
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 339020091e24 upstrema ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
ffd578e720 qla2x00t-32gbit: Update version to 10.02.08.300-k
Update version to 10.02.08.300-k.

Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-8-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit eb91eb809c8d upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
e8a1a2f15a qla2x00t-32gbit: Wait for io return on terminate rport
System crash due to use after free.
Current code allows terminate_rport_io to exit before making
sure all IOs has returned. For FCP-2 device, IO's can hang
on in HW because driver has not tear down the session in FW at
first sign of cable pull. When dev_loss_tmo timer pops,
terminate_rport_io is called and upper layer is about to
free various resources. Terminate_rport_io trigger qla to do
the final cleanup, but the cleanup might not be fast enough where it
leave qla still holding on to the same resource.

Wait for IO's to return to upper layer before resources are freed.

Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-7-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit fc0cba0c7be8 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
284f4446e1 qla2x00t-32gbit: Fix mem access after free
System crash, where driver is accessing scsi layer's
memory (scsi_cmnd->device->host) to search for a well known internal
pointer (vha). The scsi_cmnd was released back to upper layer which
could be freed, but the driver is still accessing it.

7 [ffffa8e8d2c3f8d0] page_fault at ffffffff86c010fe
  [exception RIP: __qla2x00_eh_wait_for_pending_commands+240]
  RIP: ffffffffc0642350  RSP: ffffa8e8d2c3f988  RFLAGS: 00010286
  RAX: 0000000000000165  RBX: 0000000000000002  RCX: 00000000000036d8
  RDX: 0000000000000000  RSI: ffff9c5c56535188  RDI: 0000000000000286
  RBP: ffff9c5bf7aa4a58   R8: ffff9c589aecdb70   R9: 00000000000003d1
  R10: 0000000000000001  R11: 0000000000380000 R12: ffff9c5c5392bc78
  R13: ffff9c57044ff5c0 R14: ffff9c56b5a3aa00  R15: 00000000000006db
  ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
8 [ffffa8e8d2c3f9c8] qla2x00_eh_wait_for_pending_commands at ffffffffc0646dd5 [qla2xxx]
9 [ffffa8e8d2c3fa00] __qla2x00_async_tm_cmd at ffffffffc0658094 [qla2xxx]

Remove access of freed memory. Currently the driver was checking to see if
scsi_done was called by seeing if the sp->type has changed. Instead,
check to see if the command has left the  oustanding_cmds[] array as
sign of scsi_done was called.

Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-6-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit b843adde8d49 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
7db9f41bae qla2x00t-32gbit: Fix hang in task management
Task management command hangs where a side
band chip reset failed to nudge the TMF
from it's current send path.

Add additional error check to block TMF
from entering during chip reset and along
the TMF path to cause it to bail out, skip
over abort of marker.

Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-5-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 9ae615c5bfd3 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
7a1d0ddaf5 qla2x00t-32gbit: Backport to older kernel versions
Unbreak the build for the previous commit against kernel versions
before v5.1.
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
4b813bf125 qla2x00t-32gbit: Fix task management cmd fail due to unavailable resource
Task management command failed with status 2Ch which is
a result of too many task management commands sent
to the same target. Hence limit task management commands
to 8 per target.

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202304271952.NKNmoFzv-lkp@intel.com/
Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-4-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 6a87679626b5 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
3f90ea1321 qla2x00t-32gbit: Fix task management cmd failure
Task management cmd failed with status 30h which means
FW is not able to finish processing one task management
before another task management for the same lun.
Hence add wait for completion of marker to space it out.

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202304271802.uCZfwQC1-lkp@intel.com/
Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-3-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com <mailto:himanshu.madhani@oracle.com>>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit 9803fb5d2759 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
9ff415d407 qla2x00t-32gbit: Multi-que support for TMF
Add queue flush for task management command, before
placing it on the wire.
Do IO flush for all Request Q's.

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202304271702.GpIL391S-lkp@intel.com/
Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://lore.kernel.org/r/20230428075339.32551-2-njavali@marvell.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com <mailto:himanshu.madhani@oracle.com>>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[ commit d90171dd0da5 upstream ]
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
606430be29 scst/include/backport.h: Improve the RHEL 9.2 backport
This was detected by smatch.
2023-07-19 11:35:51 +03:00
Gleb Chesnokov
bc9ec6f9e7 scst: Replace all strlcpy() with strscpy()
strlcpy() reads the entire source buffer first. This read may exceed the
destination size limit. This is both inefficient and can lead to linear
read overflows if a source string is not NULL-terminated [1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
2023-07-19 10:54:35 +03:00
Gleb Chesnokov
16a17c259b iscsi-scst: Port to Linux kernel v6.5
Use sendmsg() conditionally with MSG_SPLICE_PAGES in write_data()
rather than calling sendpage().

Support for the following net layer changes in the Linux kernel v6.5:

- dc97391e6610 ("sock: Remove ->sendpage*() in favour of
  sendmsg(MSG_SPLICE_PAGES)")
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
324bf62e28 iscsi-scst: Refactor sendpage functionality in write_data()
This patch carries out a refactoring of the sendpage functionality in
the write_data() function:

1. Reorganize the logic used to select the sock_sendpage function.
2. Streamline the data sending loop by reducing conditional branches and
   eliminating labels.
3. Adjust the error handling for -EINTR and -EAGAIN to make the code
   cleaner and easier to follow.

This patch doesn't change any functionality.
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
c1f7510d80 iscsi-scst: Improve 'write iop loop' in write_data()
This patch introduces several improvements to the 'write iop loop' in
the write_data() function:

1. Move iop-related variables under the scope of the 'write iop loop'.
2. Eliminate the 'retry' label, use 'continue' instead for simplicity.
3. Remove the redundant 'rest' variable, use just 'res' instead.

This patch doesn't change any functionality.
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
b5294cbf38 iscsi-scst: Improve write_data()
This patch introduces several improvements to the write_data() function:

1. Remove the redundant 'sendpage' function pointer variable.
2. Update variables related to size to use the size_t type for better
   type correctness and safety.
3. Introduce a new variable, 'parent_req', to store the
   'write_cmnd->parent_req' pointer and reduce redundant accesses.
4. Fix several checkpatch warnings.

This patch doesn't change any functionality.
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
a62b094f4f scst_user: Port to Linux kernel v6.5
Support for the following mm layer changes in the Linux kernel v6.5:

- 54d020692b34 ("mm/gup: remove unused vmas parameter from
  get_user_pages()")
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
7a1ea234e7 scst_tape: Port to Linux kernel v6.5
Support for the following scsi core changes in the Linux kernel v6.5:

- a6cdc35fab0d ("scsi: core: Support retrieving sub-pages of mode
  pages")
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
76750f3352 scst: Port to Linux kernel v6.5
Support for the following block layer changes in the Linux kernel v6.5:

- 05bdb9965305 ("block: replace fmode_t with a block-specific type for
  block open flags")
- 0718afd47f70 ("block: introduce holder ops")
- 2736e8eeb0cc ("block: use the holder as indication for exclusive opens")
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
5c14b16fb7 scst_vdisk: Open block devices exclusively
Enable exclusive opening of block devices to prevent concurrent usage.

Additionally, remove the redundant 'holder' argument for
'blkdev_get_by_path()' where exclusive opening isn't utilized.
2023-07-10 10:34:57 +03:00
Gleb Chesnokov
86d5b218e4 scst_targ: Check prepare_to_wait_exclusive_head() return value
The prepare_to_wait_exclusive_head() function was modified in
commit d8894cbd11 ("scst.h: Refactor wait_event_locked() to enhance
usability and clarity"). It now returns an error if the current
interruptible thread has pending signals.

This patch introduces the scst_wait_for_cmd() helper function for the
scst_cmd_thread(). This new function handles the return value of the
prepare_to_wait_exclusive_head() appropriately.

This patch fixes the following Coverity complaint:

    CID 321410 (#1 of 1): Unchecked return value (CHECKED_RETURN)
    check_return: Calling prepare_to_wait_exclusive_head without
    checking return value.
2023-06-30 10:56:09 +03:00
Gleb Chesnokov
057224f669 scst_user: Simplify signal pending check
The scst_wait_event_interruptible_lock_irq() function now implicitly
checks for pending signals. Therefore, there is no need to check for
these signals explicitly. This patch replaces the explicit check with a
simple evaluation of the function's return value.

This patch doesn't change any functionality.
2023-06-30 10:56:09 +03:00
Gleb Chesnokov
6a925490fd scst: Confirm percpu refs has scheduled and switched to atomic
This patch replaces percpu_ref_kill() with percpu_ref_kill_and_confirm()
to guarantee safe usage of references in atomic mode immediately
afterwards.

This change ensures accurate checking of active commands following the
initial reference killing.

Reported-by: Lev Vainblat <lev@zadarastorage.com>
2023-06-28 19:31:45 +03:00
Gleb Chesnokov
bdf867ffd1 scst: Use scst_wait_event_...() with INTERRUPTIBLE sleep
This patch changes the processing threads to use INTERRUPTIBLE sleep
states in the scst_wait_event_...() functions. This aims to avoid
warnings from the hung task detection checker and to prevent
unnecessary load counting.

Fixes: d8894cbd11 ("scst.h: Refactor wait_event_locked() to enhance usability and clarity")
2023-06-27 17:11:13 +03:00
Gleb Chesnokov
1d6ab4aa72 nightly build: Update kernel versions
Another kernel versions update following the 6.4 release.
2023-06-27 10:31:33 +03:00
Gleb Chesnokov
be1574d80e scst_lib: Make __scst_ext_blocking_done() static
Since __scst_ext_blocking_done() is only called from inside scst_lib.c,
declare that function static.

This patch doesn't change any functionality.
2023-06-20 09:53:50 +03:00
Gleb Chesnokov
2c5c12c017 scst_lib: Enable scst_sync_ext_block_dev() to handle signals
This patch modifies scst_sync_ext_block_dev() to support INTERRUPTIBLE
waiting and handle signal-induced waiting cancellation. To achieve this,
the waitqueue head is moved from the stack and allocated with the blocker.
Additionally, reference counting and its management are added to the
blocker to handle memory freeing from multiple contexts.

Fixes: https://github.com/SCST-project/scst/issues/164
2023-06-20 09:53:50 +03:00
Gleb Chesnokov
b13b580d8b scst_lib: Split scst_ext_block_dev() for clarity and easier maintenance
This patch divides the scst_ext_block_dev() function into two separate
functions to improve code readability and simplify maintenance:

1. scst_sync_ext_block_dev() - This function is for synchronous blocking
   and serves as the equivalent of calling the old scst_ext_block_dev()
   function with the SCST_EXT_BLOCK_SYNC flag.

2. scst_ext_block_dev() - This function is for asynchronous blocking.

Additionally, the patch introduces the helper function
scst_dev_ext_block() to reduce code duplication between the
scst_sync_ext_block_dev() and scst_ext_block_dev() functions.

This patch doesn't change any functionality.
2023-06-20 09:53:50 +03:00