@@ -167,6 +167,7 @@ MODULE_PARM_DESC(max_io_vqs, "Set the max number of IO virtqueues a vhost scsi d
167
167
168
168
struct vhost_scsi_virtqueue {
169
169
struct vhost_virtqueue vq ;
170
+ struct vhost_scsi * vs ;
170
171
/*
171
172
* Reference counting for inflight reqs, used for flush operation. At
172
173
* each time, one reference tracks new commands submitted, while we
@@ -181,6 +182,9 @@ struct vhost_scsi_virtqueue {
181
182
struct vhost_scsi_cmd * scsi_cmds ;
182
183
struct sbitmap scsi_tags ;
183
184
int max_cmds ;
185
+
186
+ struct vhost_work completion_work ;
187
+ struct llist_head completion_list ;
184
188
};
185
189
186
190
struct vhost_scsi {
@@ -190,12 +194,8 @@ struct vhost_scsi {
190
194
191
195
struct vhost_dev dev ;
192
196
struct vhost_scsi_virtqueue * vqs ;
193
- unsigned long * compl_bitmap ;
194
197
struct vhost_scsi_inflight * * old_inflight ;
195
198
196
- struct vhost_work vs_completion_work ; /* cmd completion work item */
197
- struct llist_head vs_completion_list ; /* cmd completion queue */
198
-
199
199
struct vhost_work vs_event_work ; /* evt injection work item */
200
200
struct llist_head vs_event_list ; /* evt injection queue */
201
201
@@ -358,10 +358,11 @@ static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
358
358
} else {
359
359
struct vhost_scsi_cmd * cmd = container_of (se_cmd ,
360
360
struct vhost_scsi_cmd , tvc_se_cmd );
361
- struct vhost_scsi * vs = cmd -> tvc_vhost ;
361
+ struct vhost_scsi_virtqueue * svq = container_of (cmd -> tvc_vq ,
362
+ struct vhost_scsi_virtqueue , vq );
362
363
363
- llist_add (& cmd -> tvc_completion_list , & vs -> vs_completion_list );
364
- vhost_work_queue ( & vs -> dev , & vs -> vs_completion_work );
364
+ llist_add (& cmd -> tvc_completion_list , & svq -> completion_list );
365
+ vhost_vq_work_queue ( & svq -> vq , & svq -> completion_work );
365
366
}
366
367
}
367
368
@@ -509,17 +510,17 @@ static void vhost_scsi_evt_work(struct vhost_work *work)
509
510
*/
510
511
static void vhost_scsi_complete_cmd_work (struct vhost_work * work )
511
512
{
512
- struct vhost_scsi * vs = container_of (work , struct vhost_scsi ,
513
- vs_completion_work );
513
+ struct vhost_scsi_virtqueue * svq = container_of (work ,
514
+ struct vhost_scsi_virtqueue , completion_work );
514
515
struct virtio_scsi_cmd_resp v_rsp ;
515
516
struct vhost_scsi_cmd * cmd , * t ;
516
517
struct llist_node * llnode ;
517
518
struct se_cmd * se_cmd ;
518
519
struct iov_iter iov_iter ;
519
- int ret , vq ;
520
+ bool signal = false;
521
+ int ret ;
520
522
521
- bitmap_zero (vs -> compl_bitmap , vs -> dev .nvqs );
522
- llnode = llist_del_all (& vs -> vs_completion_list );
523
+ llnode = llist_del_all (& svq -> completion_list );
523
524
llist_for_each_entry_safe (cmd , t , llnode , tvc_completion_list ) {
524
525
se_cmd = & cmd -> tvc_se_cmd ;
525
526
@@ -539,21 +540,17 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
539
540
cmd -> tvc_in_iovs , sizeof (v_rsp ));
540
541
ret = copy_to_iter (& v_rsp , sizeof (v_rsp ), & iov_iter );
541
542
if (likely (ret == sizeof (v_rsp ))) {
542
- struct vhost_scsi_virtqueue * q ;
543
+ signal = true;
544
+
543
545
vhost_add_used (cmd -> tvc_vq , cmd -> tvc_vq_desc , 0 );
544
- q = container_of (cmd -> tvc_vq , struct vhost_scsi_virtqueue , vq );
545
- vq = q - vs -> vqs ;
546
- __set_bit (vq , vs -> compl_bitmap );
547
546
} else
548
547
pr_err ("Faulted on virtio_scsi_cmd_resp\n" );
549
548
550
549
vhost_scsi_release_cmd_res (se_cmd );
551
550
}
552
551
553
- vq = -1 ;
554
- while ((vq = find_next_bit (vs -> compl_bitmap , vs -> dev .nvqs , vq + 1 ))
555
- < vs -> dev .nvqs )
556
- vhost_signal (& vs -> dev , & vs -> vqs [vq ].vq );
552
+ if (signal )
553
+ vhost_signal (& svq -> vs -> dev , & svq -> vq );
557
554
}
558
555
559
556
static struct vhost_scsi_cmd *
@@ -1770,6 +1767,7 @@ static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features)
1770
1767
1771
1768
static int vhost_scsi_open (struct inode * inode , struct file * f )
1772
1769
{
1770
+ struct vhost_scsi_virtqueue * svq ;
1773
1771
struct vhost_scsi * vs ;
1774
1772
struct vhost_virtqueue * * vqs ;
1775
1773
int r = - ENOMEM , i , nvqs = vhost_scsi_max_io_vqs ;
@@ -1788,10 +1786,6 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
1788
1786
}
1789
1787
nvqs += VHOST_SCSI_VQ_IO ;
1790
1788
1791
- vs -> compl_bitmap = bitmap_alloc (nvqs , GFP_KERNEL );
1792
- if (!vs -> compl_bitmap )
1793
- goto err_compl_bitmap ;
1794
-
1795
1789
vs -> old_inflight = kmalloc_array (nvqs , sizeof (* vs -> old_inflight ),
1796
1790
GFP_KERNEL | __GFP_ZERO );
1797
1791
if (!vs -> old_inflight )
@@ -1806,7 +1800,6 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
1806
1800
if (!vqs )
1807
1801
goto err_local_vqs ;
1808
1802
1809
- vhost_work_init (& vs -> vs_completion_work , vhost_scsi_complete_cmd_work );
1810
1803
vhost_work_init (& vs -> vs_event_work , vhost_scsi_evt_work );
1811
1804
1812
1805
vs -> vs_events_nr = 0 ;
@@ -1817,8 +1810,14 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
1817
1810
vs -> vqs [VHOST_SCSI_VQ_CTL ].vq .handle_kick = vhost_scsi_ctl_handle_kick ;
1818
1811
vs -> vqs [VHOST_SCSI_VQ_EVT ].vq .handle_kick = vhost_scsi_evt_handle_kick ;
1819
1812
for (i = VHOST_SCSI_VQ_IO ; i < nvqs ; i ++ ) {
1820
- vqs [i ] = & vs -> vqs [i ].vq ;
1821
- vs -> vqs [i ].vq .handle_kick = vhost_scsi_handle_kick ;
1813
+ svq = & vs -> vqs [i ];
1814
+
1815
+ vqs [i ] = & svq -> vq ;
1816
+ svq -> vs = vs ;
1817
+ init_llist_head (& svq -> completion_list );
1818
+ vhost_work_init (& svq -> completion_work ,
1819
+ vhost_scsi_complete_cmd_work );
1820
+ svq -> vq .handle_kick = vhost_scsi_handle_kick ;
1822
1821
}
1823
1822
vhost_dev_init (& vs -> dev , vqs , nvqs , UIO_MAXIOV ,
1824
1823
VHOST_SCSI_WEIGHT , 0 , true, NULL );
@@ -1833,8 +1832,6 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
1833
1832
err_vqs :
1834
1833
kfree (vs -> old_inflight );
1835
1834
err_inflight :
1836
- bitmap_free (vs -> compl_bitmap );
1837
- err_compl_bitmap :
1838
1835
kvfree (vs );
1839
1836
err_vs :
1840
1837
return r ;
@@ -1854,7 +1851,6 @@ static int vhost_scsi_release(struct inode *inode, struct file *f)
1854
1851
kfree (vs -> dev .vqs );
1855
1852
kfree (vs -> vqs );
1856
1853
kfree (vs -> old_inflight );
1857
- bitmap_free (vs -> compl_bitmap );
1858
1854
kvfree (vs );
1859
1855
return 0 ;
1860
1856
}
0 commit comments