Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scst_copy_mgr: Fix scst_cm_desig_list list corruption #100

Merged
merged 4 commits into from
Nov 18, 2022

Conversation

lnocturno
Copy link
Contributor

Fixes: #99

Introduce the helper function scst_cm_get_free_lun(), which purpose is
to return the next free copy manager LUN.

This patch doesn't change any functionality.
@lnocturno lnocturno force-pushed the 3.7/gleb/fix-cm_desig_list-corruption branch from 89b4a53 to 225a062 Compare November 15, 2022 14:41
This patch should fix the following bug:

list_del corruption. next->prev should be ffff955cb1ea2540, but was ffff955c54a32440
 ------------[ cut here ]------------
kernel BUG at lib/list_debug.c:54!
invalid opcode: 0000 [#1] SMP PTI
Workqueue: events vdev_inq_changed_fn [scst_vdisk]
RIP: 0010:__list_del_entry_valid.cold+0x1d/0x47
Call Trace:
 scst_cm_dev_unregister+0x66/0xd0 [scst]
 scst_cm_update_dev+0x41/0xc0 [scst]
 process_one_work+0x1ee/0x390
 worker_thread+0x53/0x3e0
 kthread+0x124/0x150
 ret_from_fork+0x1f/0x30

scst_cm_desig_list is a global list for all SCST devices. It must be
protected with scst_cm_mutex because it can be modified by
scst_cm_init_inq_finish() from another thread when scst_cm_update_dev()
is called.

Fixes: #99
Introduce the helper function scst_cm_dev_free_designators(), which
purpose is to free copy manager designators for scst dev.

This patch doesn't change any functionality.
@lnocturno lnocturno force-pushed the 3.7/gleb/fix-cm_desig_list-corruption branch 3 times, most recently from b46f53a to f67325c Compare November 16, 2022 08:17
The SCST device may receive several events almost simultaneously to
update its designators. Each such event calls scst_cm_update_dev(),
which frees all device designators in the global list and then submits
a inquiry that fills a new designators into the scst_cm_desig_list list.

This is racy because submiting the inquiry is asynchronous and can be
finished in another thread.

	scst_cm_update_dev() 1       scst_cm_update_dev() 2
	----------------------       ----------------------

[1] mutex_lock(&scst_mutex)
[2] scst_cm_send_init_inquiry(dev, lun, NULL)
[3] mutex_unlock(&scst_mutex)
				[4] mutex_lock(&scst_mutex)
				[5] scst_cm_dev_free_designators(dev)
[6] scst_cm_init_inq_finish()
				[7] scst_cm_send_init_inquiry(dev, lun, NULL)
				[8] mutex_unlock(&scst_mutex)

As a result we may get the scst_cm_desig_list list, which contains
SCST device designators from several inquiries.

Hence serialize scst_cm_desig_list list updates.
@lnocturno lnocturno force-pushed the 3.7/gleb/fix-cm_desig_list-corruption branch from f67325c to bba854d Compare November 16, 2022 09:24
@lnocturno lnocturno merged commit 4138016 into master Nov 18, 2022
@lnocturno lnocturno deleted the 3.7/gleb/fix-cm_desig_list-corruption branch November 18, 2022 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kpanic in scst_cm_dev_unregister
1 participant