Skip to content

Commit 1eb8df1

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio,vhost,vdpa updates from Michael Tsirkin: - Doorbell remapping for ifcvf, mlx5 - virtio_vdpa support for mlx5 - Validate device input in several drivers (for SEV and friends) - ZONE_MOVABLE aware handling in virtio-mem - Misc fixes, cleanups * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (48 commits) virtio-mem: prioritize unplug from ZONE_MOVABLE in Big Block Mode virtio-mem: simplify high-level unplug handling in Big Block Mode virtio-mem: prioritize unplug from ZONE_MOVABLE in Sub Block Mode virtio-mem: simplify high-level unplug handling in Sub Block Mode virtio-mem: simplify high-level plug handling in Sub Block Mode virtio-mem: use page_zonenum() in virtio_mem_fake_offline() virtio-mem: don't read big block size in Sub Block Mode virtio/vdpa: clear the virtqueue state during probe vp_vdpa: allow set vq state to initial state after reset virtio-pci library: introduce vp_modern_get_driver_features() vdpa: support packed virtqueue for set/get_vq_state() virtio-ring: store DMA metadata in desc_extra for split virtqueue virtio: use err label in __vring_new_virtqueue() virtio_ring: introduce virtqueue_desc_add_split() virtio_ring: secure handling of mapping errors virtio-ring: factor out desc_extra allocation virtio_ring: rename vring_desc_extra_packed virtio-ring: maintain next in extra state for packed virtqueue vdpa/mlx5: Clear vq ready indication upon device reset vdpa/mlx5: Add support for doorbell bypassing ...
2 parents d8dc121 + db7b337 commit 1eb8df1

27 files changed

Lines changed: 708 additions & 349 deletions

drivers/block/virtio_blk.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#define VQ_NAME_LEN 16
2222
#define MAX_DISCARD_SEGMENTS 256u
2323

24+
/* The maximum number of sg elements that fit into a virtqueue */
25+
#define VIRTIO_BLK_MAX_SG_ELEMS 32768
26+
2427
static int major;
2528
static DEFINE_IDA(vd_index_ida);
2629

@@ -447,13 +450,6 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize)
447450
/* Host must always specify the capacity. */
448451
virtio_cread(vdev, struct virtio_blk_config, capacity, &capacity);
449452

450-
/* If capacity is too big, truncate with warning. */
451-
if ((sector_t)capacity != capacity) {
452-
dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
453-
(unsigned long long)capacity);
454-
capacity = (sector_t)-1;
455-
}
456-
457453
nblocks = DIV_ROUND_UP_ULL(capacity, queue_logical_block_size(q) >> 9);
458454

459455
string_get_size(nblocks, queue_logical_block_size(q),
@@ -728,7 +724,10 @@ static int virtblk_probe(struct virtio_device *vdev)
728724
if (err || !sg_elems)
729725
sg_elems = 1;
730726

731-
/* We need an extra sg elements at head and tail. */
727+
/* Prevent integer overflows and honor max vq size */
728+
sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2);
729+
730+
/* We need extra sg elements at head and tail. */
732731
sg_elems += 2;
733732
vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL);
734733
if (!vblk) {
@@ -936,6 +935,8 @@ static int virtblk_freeze(struct virtio_device *vdev)
936935
blk_mq_quiesce_queue(vblk->disk->queue);
937936

938937
vdev->config->del_vqs(vdev);
938+
kfree(vblk->vqs);
939+
939940
return 0;
940941
}
941942

drivers/char/virtio_console.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static struct port_buffer *get_inbuf(struct port *port)
475475

476476
buf = virtqueue_get_buf(port->in_vq, &len);
477477
if (buf) {
478-
buf->len = len;
478+
buf->len = min_t(size_t, len, buf->size);
479479
buf->offset = 0;
480480
port->stats.bytes_received += len;
481481
}
@@ -1709,7 +1709,7 @@ static void control_work_handler(struct work_struct *work)
17091709
while ((buf = virtqueue_get_buf(vq, &len))) {
17101710
spin_unlock(&portdev->c_ivq_lock);
17111711

1712-
buf->len = len;
1712+
buf->len = min_t(size_t, len, buf->size);
17131713
buf->offset = 0;
17141714

17151715
handle_control_message(vq->vdev, portdev, buf);

drivers/net/virtio_net.c

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,12 +1516,16 @@ static void virtnet_poll_cleantx(struct receive_queue *rq)
15161516
return;
15171517

15181518
if (__netif_tx_trylock(txq)) {
1519-
free_old_xmit_skbs(sq, true);
1519+
do {
1520+
virtqueue_disable_cb(sq->vq);
1521+
free_old_xmit_skbs(sq, true);
1522+
} while (unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
1523+
1524+
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
1525+
netif_tx_wake_queue(txq);
1526+
15201527
__netif_tx_unlock(txq);
15211528
}
1522-
1523-
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
1524-
netif_tx_wake_queue(txq);
15251529
}
15261530

15271531
static int virtnet_poll(struct napi_struct *napi, int budget)
@@ -1592,6 +1596,8 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
15921596
struct virtnet_info *vi = sq->vq->vdev->priv;
15931597
unsigned int index = vq2txq(sq->vq);
15941598
struct netdev_queue *txq;
1599+
int opaque;
1600+
bool done;
15951601

15961602
if (unlikely(is_xdp_raw_buffer_queue(vi, index))) {
15971603
/* We don't need to enable cb for XDP */
@@ -1601,14 +1607,32 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget)
16011607

16021608
txq = netdev_get_tx_queue(vi->dev, index);
16031609
__netif_tx_lock(txq, raw_smp_processor_id());
1610+
virtqueue_disable_cb(sq->vq);
16041611
free_old_xmit_skbs(sq, true);
1605-
__netif_tx_unlock(txq);
1606-
1607-
virtqueue_napi_complete(napi, sq->vq, 0);
16081612

16091613
if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS)
16101614
netif_tx_wake_queue(txq);
16111615

1616+
opaque = virtqueue_enable_cb_prepare(sq->vq);
1617+
1618+
done = napi_complete_done(napi, 0);
1619+
1620+
if (!done)
1621+
virtqueue_disable_cb(sq->vq);
1622+
1623+
__netif_tx_unlock(txq);
1624+
1625+
if (done) {
1626+
if (unlikely(virtqueue_poll(sq->vq, opaque))) {
1627+
if (napi_schedule_prep(napi)) {
1628+
__netif_tx_lock(txq, raw_smp_processor_id());
1629+
virtqueue_disable_cb(sq->vq);
1630+
__netif_tx_unlock(txq);
1631+
__napi_schedule(napi);
1632+
}
1633+
}
1634+
}
1635+
16121636
return 0;
16131637
}
16141638

@@ -1670,10 +1694,14 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
16701694
bool use_napi = sq->napi.weight;
16711695

16721696
/* Free up any pending old buffers before queueing new ones. */
1673-
free_old_xmit_skbs(sq, false);
1697+
do {
1698+
if (use_napi)
1699+
virtqueue_disable_cb(sq->vq);
1700+
1701+
free_old_xmit_skbs(sq, false);
16741702

1675-
if (use_napi && kick)
1676-
virtqueue_enable_cb_delayed(sq->vq);
1703+
} while (use_napi && kick &&
1704+
unlikely(!virtqueue_enable_cb_delayed(sq->vq)));
16771705

16781706
/* timestamp packet in software */
16791707
skb_tx_timestamp(skb);
@@ -3310,8 +3338,11 @@ static __maybe_unused int virtnet_restore(struct virtio_device *vdev)
33103338
virtnet_set_queues(vi, vi->curr_queue_pairs);
33113339

33123340
err = virtnet_cpu_notif_add(vi);
3313-
if (err)
3341+
if (err) {
3342+
virtnet_freeze_down(vdev);
3343+
remove_vq_common(vi);
33143344
return err;
3345+
}
33153346

33163347
return 0;
33173348
}

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
133133
&hw->notify_off_multiplier);
134134
hw->notify_bar = cap.bar;
135135
hw->notify_base = get_cap_addr(hw, &cap);
136+
hw->notify_base_pa = pci_resource_start(pdev, cap.bar) +
137+
le32_to_cpu(cap.offset);
136138
IFCVF_DBG(pdev, "hw->notify_base = %p\n",
137139
hw->notify_base);
138140
break;
@@ -161,6 +163,8 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
161163
notify_off = ifc_ioread16(&hw->common_cfg->queue_notify_off);
162164
hw->vring[i].notify_addr = hw->notify_base +
163165
notify_off * hw->notify_off_multiplier;
166+
hw->vring[i].notify_pa = hw->notify_base_pa +
167+
notify_off * hw->notify_off_multiplier;
164168
}
165169

166170
hw->lm_cfg = hw->base[IFCVF_LM_BAR];

drivers/vdpa/ifcvf/ifcvf_base.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,9 @@
1919
#include <uapi/linux/virtio_config.h>
2020
#include <uapi/linux/virtio_pci.h>
2121

22-
#define N3000_VENDOR_ID 0x1AF4
2322
#define N3000_DEVICE_ID 0x1041
24-
#define N3000_SUBSYS_VENDOR_ID 0x8086
2523
#define N3000_SUBSYS_DEVICE_ID 0x001A
2624

27-
#define C5000X_PL_VENDOR_ID 0x1AF4
28-
#define C5000X_PL_DEVICE_ID 0x1000
29-
#define C5000X_PL_SUBSYS_VENDOR_ID 0x8086
30-
#define C5000X_PL_SUBSYS_DEVICE_ID 0x0001
31-
32-
#define C5000X_PL_BLK_VENDOR_ID 0x1AF4
33-
#define C5000X_PL_BLK_DEVICE_ID 0x1001
34-
#define C5000X_PL_BLK_SUBSYS_VENDOR_ID 0x8086
35-
#define C5000X_PL_BLK_SUBSYS_DEVICE_ID 0x0002
36-
3725
#define IFCVF_NET_SUPPORTED_FEATURES \
3826
((1ULL << VIRTIO_NET_F_MAC) | \
3927
(1ULL << VIRTIO_F_ANY_LAYOUT) | \
@@ -73,6 +61,7 @@ struct vring_info {
7361
u16 last_avail_idx;
7462
bool ready;
7563
void __iomem *notify_addr;
64+
phys_addr_t notify_pa;
7665
u32 irq;
7766
struct vdpa_callback cb;
7867
char msix_name[256];
@@ -87,6 +76,7 @@ struct ifcvf_hw {
8776
u8 notify_bar;
8877
/* Notificaiton bar address */
8978
void __iomem *notify_base;
79+
phys_addr_t notify_base_pa;
9080
u32 notify_off_multiplier;
9181
u64 req_features;
9282
u64 hw_features;

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
264264
{
265265
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
266266

267-
state->avail_index = ifcvf_get_vq_state(vf, qid);
267+
state->split.avail_index = ifcvf_get_vq_state(vf, qid);
268268
return 0;
269269
}
270270

@@ -273,7 +273,7 @@ static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
273273
{
274274
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
275275

276-
return ifcvf_set_vq_state(vf, qid, state->avail_index);
276+
return ifcvf_set_vq_state(vf, qid, state->split.avail_index);
277277
}
278278

279279
static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,
@@ -413,6 +413,21 @@ static int ifcvf_vdpa_get_vq_irq(struct vdpa_device *vdpa_dev,
413413
return vf->vring[qid].irq;
414414
}
415415

416+
static struct vdpa_notification_area ifcvf_get_vq_notification(struct vdpa_device *vdpa_dev,
417+
u16 idx)
418+
{
419+
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
420+
struct vdpa_notification_area area;
421+
422+
area.addr = vf->vring[idx].notify_pa;
423+
if (!vf->notify_off_multiplier)
424+
area.size = PAGE_SIZE;
425+
else
426+
area.size = vf->notify_off_multiplier;
427+
428+
return area;
429+
}
430+
416431
/*
417432
* IFCVF currently does't have on-chip IOMMU, so not
418433
* implemented set_map()/dma_map()/dma_unmap()
@@ -440,6 +455,7 @@ static const struct vdpa_config_ops ifc_vdpa_ops = {
440455
.get_config = ifcvf_vdpa_get_config,
441456
.set_config = ifcvf_vdpa_set_config,
442457
.set_config_cb = ifcvf_vdpa_set_config_cb,
458+
.get_vq_notification = ifcvf_get_vq_notification,
443459
};
444460

445461
static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -536,18 +552,21 @@ static void ifcvf_remove(struct pci_dev *pdev)
536552
}
537553

538554
static struct pci_device_id ifcvf_pci_ids[] = {
539-
{ PCI_DEVICE_SUB(N3000_VENDOR_ID,
555+
/* N3000 network device */
556+
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_REDHAT_QUMRANET,
540557
N3000_DEVICE_ID,
541-
N3000_SUBSYS_VENDOR_ID,
558+
PCI_VENDOR_ID_INTEL,
542559
N3000_SUBSYS_DEVICE_ID) },
543-
{ PCI_DEVICE_SUB(C5000X_PL_VENDOR_ID,
544-
C5000X_PL_DEVICE_ID,
545-
C5000X_PL_SUBSYS_VENDOR_ID,
546-
C5000X_PL_SUBSYS_DEVICE_ID) },
547-
{ PCI_DEVICE_SUB(C5000X_PL_BLK_VENDOR_ID,
548-
C5000X_PL_BLK_DEVICE_ID,
549-
C5000X_PL_BLK_SUBSYS_VENDOR_ID,
550-
C5000X_PL_BLK_SUBSYS_DEVICE_ID) },
560+
/* C5000X-PL network device */
561+
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_REDHAT_QUMRANET,
562+
VIRTIO_TRANS_ID_NET,
563+
PCI_VENDOR_ID_INTEL,
564+
VIRTIO_ID_NET) },
565+
/* C5000X-PL block device */
566+
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_REDHAT_QUMRANET,
567+
VIRTIO_TRANS_ID_BLOCK,
568+
PCI_VENDOR_ID_INTEL,
569+
VIRTIO_ID_BLOCK) },
551570

552571
{ 0 },
553572
};

drivers/vdpa/mlx5/core/mlx5_vdpa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ struct mlx5_vdpa_mr {
3535

3636
/* serialize mkey creation and destruction */
3737
struct mutex mkey_mtx;
38+
bool user_mr;
3839
};
3940

4041
struct mlx5_vdpa_resources {
4142
u32 pdn;
4243
struct mlx5_uars_page *uar;
4344
void __iomem *kick_addr;
45+
u64 phys_kick_addr;
4446
u16 uid;
4547
u32 null_mkey;
4648
bool valid;

0 commit comments

Comments
 (0)