Skip to content

Commit ab8edab

Browse files
author
Nicholas Bellinger
committed
vhost-scsi: Take configfs group dependency during VHOST_SCSI_SET_ENDPOINT
This patch addresses a bug where individual vhost-scsi configfs endpoint groups can be removed from below while active exports to QEMU userspace still exist, resulting in an OOPs. It adds a configfs_depend_item() in vhost_scsi_set_endpoint() to obtain an explicit dependency on se_tpg->tpg_group in order to prevent individual vhost-scsi WWPN endpoints from being released via normal configfs methods while an QEMU ioctl reference still exists. Also, add matching configfs_undepend_item() in vhost_scsi_clear_endpoint() to release the dependency, once QEMU's reference to the individual group at /sys/kernel/config/target/vhost/$WWPN/$TPGT is released. (Fix up vhost_scsi_clear_endpoint() error path - DanC) Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Cc: <stable@vger.kernel.org> # 3.6+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 885e7b0 commit ab8edab

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎drivers/vhost/scsi.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ static int
13121312
vhost_scsi_set_endpoint(struct vhost_scsi *vs,
13131313
struct vhost_scsi_target *t)
13141314
{
1315+
struct se_portal_group *se_tpg;
13151316
struct tcm_vhost_tport *tv_tport;
13161317
struct tcm_vhost_tpg *tpg;
13171318
struct tcm_vhost_tpg **vs_tpg;
@@ -1359,6 +1360,21 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
13591360
ret = -EEXIST;
13601361
goto out;
13611362
}
1363+
/*
1364+
* In order to ensure individual vhost-scsi configfs
1365+
* groups cannot be removed while in use by vhost ioctl,
1366+
* go ahead and take an explicit se_tpg->tpg_group.cg_item
1367+
* dependency now.
1368+
*/
1369+
se_tpg = &tpg->se_tpg;
1370+
ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
1371+
&se_tpg->tpg_group.cg_item);
1372+
if (ret) {
1373+
pr_warn("configfs_depend_item() failed: %d\n", ret);
1374+
kfree(vs_tpg);
1375+
mutex_unlock(&tpg->tv_tpg_mutex);
1376+
goto out;
1377+
}
13621378
tpg->tv_tpg_vhost_count++;
13631379
tpg->vhost_scsi = vs;
13641380
vs_tpg[tpg->tport_tpgt] = tpg;
@@ -1401,6 +1417,7 @@ static int
14011417
vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
14021418
struct vhost_scsi_target *t)
14031419
{
1420+
struct se_portal_group *se_tpg;
14041421
struct tcm_vhost_tport *tv_tport;
14051422
struct tcm_vhost_tpg *tpg;
14061423
struct vhost_virtqueue *vq;
@@ -1449,6 +1466,13 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
14491466
vs->vs_tpg[target] = NULL;
14501467
match = true;
14511468
mutex_unlock(&tpg->tv_tpg_mutex);
1469+
/*
1470+
* Release se_tpg->tpg_group.cg_item configfs dependency now
1471+
* to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur.
1472+
*/
1473+
se_tpg = &tpg->se_tpg;
1474+
configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
1475+
&se_tpg->tpg_group.cg_item);
14521476
}
14531477
if (match) {
14541478
for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {

0 commit comments

Comments
 (0)