Skip to content

Commit 70575e7

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael Tsirkin: "Some last minute fixes. The virtio-blk one is the most important one since it was actually seen in the field, but the rest of them are small and clearly safe, everything here has been in next for a while" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vdpa/mlx5: Fix MQ to support non power of two num queues vduse: prevent uninitialized memory accesses virtio-blk: Fix WARN_ON_ONCE in virtio_queue_rq() virtio_test: fixup for vq reset virtio-crypto: fix memory-leak vdpa/ifcvf: fix the calculation of queuepair
2 parents 7bc6e90 + a43ae80 commit 70575e7

File tree

7 files changed

+36
-17
lines changed

7 files changed

+36
-17
lines changed

drivers/block/virtio_blk.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
322322
if (unlikely(status))
323323
return status;
324324

325-
blk_mq_start_request(req);
326-
327325
vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
328326
if (unlikely(vbr->sg_table.nents < 0)) {
329327
virtblk_cleanup_cmd(req);
330328
return BLK_STS_RESOURCE;
331329
}
332330

331+
blk_mq_start_request(req);
332+
333333
return BLK_STS_OK;
334334
}
335335

@@ -391,8 +391,7 @@ static bool virtblk_prep_rq_batch(struct request *req)
391391
}
392392

393393
static bool virtblk_add_req_batch(struct virtio_blk_vq *vq,
394-
struct request **rqlist,
395-
struct request **requeue_list)
394+
struct request **rqlist)
396395
{
397396
unsigned long flags;
398397
int err;
@@ -408,7 +407,7 @@ static bool virtblk_add_req_batch(struct virtio_blk_vq *vq,
408407
if (err) {
409408
virtblk_unmap_data(req, vbr);
410409
virtblk_cleanup_cmd(req);
411-
rq_list_add(requeue_list, req);
410+
blk_mq_requeue_request(req, true);
412411
}
413412
}
414413

@@ -436,7 +435,7 @@ static void virtio_queue_rqs(struct request **rqlist)
436435

437436
if (!next || req->mq_hctx != next->mq_hctx) {
438437
req->rq_next = NULL;
439-
kick = virtblk_add_req_batch(vq, rqlist, &requeue_list);
438+
kick = virtblk_add_req_batch(vq, rqlist);
440439
if (kick)
441440
virtqueue_notify(vq->vq);
442441

drivers/crypto/virtio/virtio_crypto_akcipher_algs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static void virtio_crypto_akcipher_finalize_req(
5656
struct virtio_crypto_akcipher_request *vc_akcipher_req,
5757
struct akcipher_request *req, int err)
5858
{
59+
kfree(vc_akcipher_req->src_buf);
60+
kfree(vc_akcipher_req->dst_buf);
61+
vc_akcipher_req->src_buf = NULL;
62+
vc_akcipher_req->dst_buf = NULL;
5963
virtcrypto_clear_request(&vc_akcipher_req->base);
6064

6165
crypto_finalize_akcipher_request(vc_akcipher_req->base.dataq->engine, req, err);

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
323323
u32 q_pair_id;
324324

325325
ifcvf_lm = (struct ifcvf_lm_cfg __iomem *)hw->lm_cfg;
326-
q_pair_id = qid / hw->nr_vring;
326+
q_pair_id = qid / 2;
327327
avail_idx_addr = &ifcvf_lm->vring_lm_cfg[q_pair_id].idx_addr[qid % 2];
328328
last_avail_idx = vp_ioread16(avail_idx_addr);
329329

@@ -337,7 +337,7 @@ int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num)
337337
u32 q_pair_id;
338338

339339
ifcvf_lm = (struct ifcvf_lm_cfg __iomem *)hw->lm_cfg;
340-
q_pair_id = qid / hw->nr_vring;
340+
q_pair_id = qid / 2;
341341
avail_idx_addr = &ifcvf_lm->vring_lm_cfg[q_pair_id].idx_addr[qid % 2];
342342
hw->vring[qid].last_avail_idx = num;
343343
vp_iowrite16(num, avail_idx_addr);

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,14 +1320,16 @@ static void teardown_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *
13201320

13211321
static int create_rqt(struct mlx5_vdpa_net *ndev)
13221322
{
1323+
int rqt_table_size = roundup_pow_of_two(ndev->rqt_size);
1324+
int act_sz = roundup_pow_of_two(ndev->cur_num_vqs / 2);
13231325
__be32 *list;
13241326
void *rqtc;
13251327
int inlen;
13261328
void *in;
13271329
int i, j;
13281330
int err;
13291331

1330-
inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + ndev->rqt_size * MLX5_ST_SZ_BYTES(rq_num);
1332+
inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + rqt_table_size * MLX5_ST_SZ_BYTES(rq_num);
13311333
in = kzalloc(inlen, GFP_KERNEL);
13321334
if (!in)
13331335
return -ENOMEM;
@@ -1336,12 +1338,12 @@ static int create_rqt(struct mlx5_vdpa_net *ndev)
13361338
rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
13371339

13381340
MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q);
1339-
MLX5_SET(rqtc, rqtc, rqt_max_size, ndev->rqt_size);
1341+
MLX5_SET(rqtc, rqtc, rqt_max_size, rqt_table_size);
13401342
list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]);
1341-
for (i = 0, j = 0; i < ndev->rqt_size; i++, j += 2)
1343+
for (i = 0, j = 0; i < act_sz; i++, j += 2)
13421344
list[i] = cpu_to_be32(ndev->vqs[j % ndev->cur_num_vqs].virtq_id);
13431345

1344-
MLX5_SET(rqtc, rqtc, rqt_actual_size, ndev->rqt_size);
1346+
MLX5_SET(rqtc, rqtc, rqt_actual_size, act_sz);
13451347
err = mlx5_vdpa_create_rqt(&ndev->mvdev, in, inlen, &ndev->res.rqtn);
13461348
kfree(in);
13471349
if (err)
@@ -1354,14 +1356,15 @@ static int create_rqt(struct mlx5_vdpa_net *ndev)
13541356

13551357
static int modify_rqt(struct mlx5_vdpa_net *ndev, int num)
13561358
{
1359+
int act_sz = roundup_pow_of_two(num / 2);
13571360
__be32 *list;
13581361
void *rqtc;
13591362
int inlen;
13601363
void *in;
13611364
int i, j;
13621365
int err;
13631366

1364-
inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + ndev->rqt_size * MLX5_ST_SZ_BYTES(rq_num);
1367+
inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + act_sz * MLX5_ST_SZ_BYTES(rq_num);
13651368
in = kzalloc(inlen, GFP_KERNEL);
13661369
if (!in)
13671370
return -ENOMEM;
@@ -1372,10 +1375,10 @@ static int modify_rqt(struct mlx5_vdpa_net *ndev, int num)
13721375
MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q);
13731376

13741377
list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]);
1375-
for (i = 0, j = 0; i < ndev->rqt_size; i++, j += 2)
1378+
for (i = 0, j = 0; i < act_sz; i++, j = j + 2)
13761379
list[i] = cpu_to_be32(ndev->vqs[j % num].virtq_id);
13771380

1378-
MLX5_SET(rqtc, rqtc, rqt_actual_size, ndev->rqt_size);
1381+
MLX5_SET(rqtc, rqtc, rqt_actual_size, act_sz);
13791382
err = mlx5_vdpa_modify_rqt(&ndev->mvdev, in, inlen, ndev->res.rqtn);
13801383
kfree(in);
13811384
if (err)

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,15 @@ static void vduse_vdpa_get_config(struct vdpa_device *vdpa, unsigned int offset,
673673
{
674674
struct vduse_dev *dev = vdpa_to_vduse(vdpa);
675675

676-
if (offset > dev->config_size ||
677-
len > dev->config_size - offset)
676+
/* Initialize the buffer in case of partial copy. */
677+
memset(buf, 0, len);
678+
679+
if (offset > dev->config_size)
678680
return;
679681

682+
if (len > dev->config_size - offset)
683+
len = dev->config_size - offset;
684+
680685
memcpy(buf, dev->config + offset, len);
681686
}
682687

tools/virtio/linux/virtio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct virtio_device {
1414
u64 features;
1515
struct list_head vqs;
1616
spinlock_t vqs_list_lock;
17+
const struct virtio_config_ops *config;
1718
};
1819

1920
struct virtqueue {
@@ -23,7 +24,9 @@ struct virtqueue {
2324
struct virtio_device *vdev;
2425
unsigned int index;
2526
unsigned int num_free;
27+
unsigned int num_max;
2628
void *priv;
29+
bool reset;
2730
};
2831

2932
/* Interfaces exported by virtio_ring. */

tools/virtio/linux/virtio_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#include <linux/virtio.h>
44
#include <uapi/linux/virtio_config.h>
55

6+
struct virtio_config_ops {
7+
int (*disable_vq_and_reset)(struct virtqueue *vq);
8+
int (*enable_vq_after_reset)(struct virtqueue *vq);
9+
};
10+
611
/*
712
* __virtio_test_bit - helper to test feature bits. For use by transports.
813
* Devices should normally use virtio_has_feature,

0 commit comments

Comments
 (0)