2786 Commits

Author SHA1 Message Date
Gleb Chesnokov
1171841931 Bump the version number to 3.8.0
These changes have been generated by running the following command:

$ scripts/update-version 3 8 0
2024-01-15 13:59:19 +03:00
Gleb Chesnokov
cee270448c scst/ChangeLog: Summarize the changes for the upcoming 3.8 release 2024-01-15 13:59:19 +03:00
Brian Meagher
df039cb3e9 scst.h, scst, device handlers: Fix scst_replace_port_info
scst_pass_through_cmd_done can run in interrupt context, and call
scst_replace_port_info, which in turn was calling scst_lookup_tg_id.
Since scst_lookup_tg_id does a mutex_lock, we should not call it from
interrupt context.

Add scst_cmd_inquired_dev_ident and use in various locations.
2024-01-12 10:50:15 +03:00
Gleb Chesnokov
b5693922e0 scst_lib: Use gfp_mask instead of GFP_KERNEL for percpu_ref_init()
Fix smatch-reported warning message:

drivers/scst/scst_lib.c:4198 scst_alloc_device() warn: use 'gfp_mask'
here instead of GFP_KERNEL?
2024-01-10 19:34:49 +03:00
Gleb Chesnokov
50e1babd39 scst/include/backport.h: Fix backport for new stable kernels
This patch fixes the build against kernel versions 5.4.263, 5.10.203,
5.15.136.
2024-01-10 19:34:49 +03:00
Gleb Chesnokov
7a48f02640 scst/include/backport.h: Port to the latest UEK 7 kernel
This patch fixes the build against UEK kernel 5.15.0-201.135.6.el9uek.
2024-01-10 19:34:49 +03:00
Gleb Chesnokov
be9d368361 scst_targ: Fix shift out of bounds
This patch should fix the following UBSAN warning:

UBSAN: shift-out-of-bounds in scst/src/scst_targ.c:3912:6
shift exponent -1 is negative

Call Trace:
 <TASK>
 show_stack+0x52/0x5c
 dump_stack_lvl+0x4a/0x63
 dump_stack+0x10/0x16
 ubsan_epilogue+0x9/0x36
 __ubsan_handle_shift_out_of_bounds.cold+0x61/0xef
 scst_process_active_cmd.cold+0xf/0x2d [scst]
 scst_process_redirect_cmd+0xd4/0x2e0 [scst]
 scst_tgt_cmd_done+0x48/0x70 [scst]
 scst_local_targ_xmit_response+0x64/0x220 [scst_local]
 scst_process_active_cmd+0x891/0x2140 [scst]
 scst_process_redirect_cmd+0xd4/0x2e0 [scst]
 scst_cmd_done_local+0x80/0x110 [scst]
 dev_user_process_reply+0x597/0x1160 [scst_user]
 dev_user_ioctl+0x145/0xb23 [scst_user]
 __x64_sys_ioctl+0x95/0xd0
 do_syscall_64+0x5c/0xc0
 entry_SYSCALL_64_after_hwframe+0x62/0xcc

Reported-by: Rob Turk <robtu@rtist.nl>
2023-12-28 11:58:22 +03:00
Gleb Chesnokov
5716ffa737 scst_lib: Fix mem access after free
Fixes: https://github.com/SCST-project/scst/issues/204
2023-12-28 11:02:09 +03:00
Gleb Chesnokov
d3da391be8 scst/include/backport.h: Unbreak the RHEL 8.9 build 2023-12-27 21:13:12 +03:00
Gleb Chesnokov
2d243a71e7 scst: Unbreak the RHEL 9.4 build
Fixes: https://github.com/SCST-project/scst/issues/201
2023-12-27 18:27:42 +03:00
Gleb Chesnokov
fd88df1e25 scst_mem: Port to Linux kernel v6.7
Support for the following mm layer changes in the Linux kernel v6.7:

- c42d50aefd17 ("mm: shrinker: add infrastructure for dynamically
  allocating shrinker")
2023-12-27 18:02:30 +03:00
Gleb Chesnokov
12fd0ea93e scst/include/backport.h: Backport some debugfs functions
Support the previous commit against kernel versions before v5.0.

See also commit ff9fb72bc077 ("debugfs: return error values,
not NULL") # v5.0.
2023-10-10 15:10:02 +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
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
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
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
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
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
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
Gleb Chesnokov
d8894cbd11 scst.h: Refactor wait_event_locked() to enhance usability and clarity
1. Set the default process state to TASK_UNINTERRUPTIBLE during sleep.
   This change is made because our current code does not check whether a
   process was interrupted by a signal.

2. Prefix all SCST wait_event-related macros with 'scst_'. This helps to
   distinguish SCST-specific macros from those provided by the Linux
   kernel itself.

3. Add the capability to return an error code when a process in a
   non-TASK_UNINTERRUPTIBLE state is interrupted by a signal.

4. Divide the wait_event_locked function based on each lock type,
   resulting in the following new functions: scst_wait_event_lock(),
   scst_wait_event_lock_bh(), and scst_wait_event_lock_irq().
2023-06-20 09:53:50 +03:00
Gleb Chesnokov
334d29c96a scst.h: Unify names in prepare_to_wait_exclusive_head()
Use the standardized version of the name for wait_queue_head and
wait_queue_entry variables.

This patch doesn't change any functionality.
2023-06-20 09:53:50 +03:00
Gleb Chesnokov
7881162b9b scst: Unbreak the non-DLM build
Fix the following compiler error:

    ERROR: modpost: "scst_dlm_cluster_name" [...] undefined!

The error occurs because the declaration of scst_dlm_cluster_name is
located in the scst_dlm.c file, but it's used in the scst_sysfs.c file.
As a result, when building without DLM, this variable lacks a declaration.

To resolve this, the declaration is moved to the scst_main.c file, and the
variable scst_dlm_cluster_name is renamed to scst_cluster_name.

Fixes: 00f31004ab ("scst_sysfs: Add support for cluster_name")
2023-06-16 13:35:51 +03:00
Gleb Chesnokov
a6e0967054 scst/src/Makefile: Fix depmod warnings during installation process
This patch fixes the following warnings:

  /lib/.../scst_cdrom.ko needs unknown symbol scst_obtain_device_parameters
  /lib/.../scst_cdrom.ko needs unknown symbol scst_unregister_dev_driver
  ...

These warnings were caused by an incorrect module installation order:
the SCST module was being installed after the device handler modules
on which they depend. This patch rectifies the issue by altering the
order in which the modules are installed.

Additionally, this patch fixes the missing signatures for the device
handler modules.
2023-06-14 16:49:36 +03:00
Gleb Chesnokov
6c2771baef Makefile: Specify the installation directory for SCST modules explicitly
This patch fixes the installation process for Linux kernels where the
default value of INSTALL_MOD_DIR differs from `extra`.

For instance, it unbreaks `make rpm` against Fedora's kernels, where
INSTALL_MOD_DIR is set to `updates`.
2023-06-14 16:49:36 +03:00
Gleb Chesnokov
85e8086a7e Makefile: Implement several improvements to SCST Makefiles
1. Correct a typo, changing `make release` to `make 2release`.
2. Add information about package-related targets to the help section.
3. Remove `dev_handler` directory during the uninstall process.
4. Eliminate the non-existent `tgt` target from the PHONY targets.
5. Introduce SCST_MOD_DIR and SCST_DH_MOD_DIR as helper variables.
2023-06-14 16:49:36 +03:00
Gleb Chesnokov
3b0ab93c93 scst/include/backport.h: Unbreak the RHEL 9.3 build
Fixes: https://github.com/SCST-project/scst/issues/167
2023-06-13 17:49:50 +03:00
Gleb Chesnokov
68461f5876 scst: Remove support for RHEL5/6
The SCST has dropped support for RHEL5/6 since v3.6.
2023-05-10 13:24:47 +03:00
Brian Meagher
92db6a9fc5 scst_pres,scst_dlm: Fix broken UNIT ATTENTION for remote PR registrants
Previously, when scst_pr_send_ua_reg attempted to deliver a UNIT ATTENTION
to a registrant that was on another node in a dlm-based HA cluster, the
unit attention was dropped.

Rectify by adding a pr_reg_queue_rem_ua function to struct scst_cl_ops and
calling it from scst_pr_send_ua_reg.

Each registrant will maintain an incoming 'queue' of unit attentions by
adding next_rem_ua_idx to the registrant data maintained in the DLM.  This
will tell the other nodes which PR_REG_UA_LOCK lock to create in the
lockspace in order to 'send' a unit attention to the registrant.

Further, each node will also maintain two lists (pending and sent) for the
outgoing unit attentions from this node to a registrant.  When the
recipient has read all the sent unit attentions (and cleared
next_rem_ua_idx), then the sent list may be cleared.
2023-05-10 10:31:51 +03:00
Gleb Chesnokov
faac0a1964 scst: Port to Linux kernel v6.4
Support for the following driver core changes in the Linux kernel v6.4:
- 1aaba11da9aa ("driver core: class: remove module * from class_create()")
- 2243acd50ac4 ("driver core: class: remove struct class_interface * from callbacks")
2023-04-28 15:22:58 +03:00
Gleb Chesnokov
cf94272cea scst: Remove scst_module.c file
I haven't been able to find any sign of this file being used since the
initial commit, so remove this dead code.
2023-04-28 15:22:58 +03:00
Brian Meagher
c326e96886 scst_lib,scst_sysfs: Add aen_disabled setting
Add a setting to scst_tgt that can prevent scst_gen_aen_or_ua from
generating an AEN, even if the underlying transport is capable of
transmitting them.  It will instead generate a UA.
2023-04-17 20:31:58 +03:00
Gleb Chesnokov
33b8323a81 scst_lib: Avoid holding scst_mutex during sess_tgt_dev_list access
In the previous commit, we introduced the use of RCU protection when
accessing sess_tgt_dev_list in scst_get_max_lun_commands().

As a result, we can now drop the use of scst_mutex when accessing the
list.
2023-04-17 17:16:42 +03:00
Gleb Chesnokov
c9198bb027 scst: Use RCU read lock when accessing sess_tgt_dev_list
We must always protect sess_tgt_dev_list during access and
modification.

There are two mechanisms for that:

- tgt_dev_list_mutex for list modifications.
- RCU for read-only list accesses.

Currently, the codebase doesn't consistently apply protection when
accessing the list. Fix this by adding RCU protection.

See also commit 3e64094b0c ("scst_sysfs: Do not suspend I/O for LUN
management").
2023-04-17 17:16:42 +03:00
Gleb Chesnokov
87681c0d9a scst: Unbreak the RHEL 9.2 build
See also PR https://github.com/SCST-project/scst/pull/145.
2023-04-06 13:02:25 +03:00
Gleb Chesnokov
6f9a595f24 scst/include/backport.h: Fix the RHEL 9.0 build
Commit 9be09fd68b ("scst/include/backport.h: Fix building on
RHEL 8.8") fixed the build for RHEL 8.8, but at the same time, it
broke the build for RHEL 9.0.
2023-04-06 13:02:25 +03:00
Gleb Chesnokov
22b03d1c6e INSTALL.md: Fix a checkpatch complaint about whitespace
This patch fixes the following checkpatch warnings:

    ERROR:TRAILING_WHITESPACE: trailing whitespace.
2023-04-04 11:47:44 +03:00
Gleb Chesnokov
70dfb06c40 scst: Fix a checkpatch complaint about whitespace
This patch fixes the following checkpatch warnings:

    WARNING:SPACE_BEFORE_TAB: please, no space before tabs.
2023-04-04 11:47:44 +03:00