Skip to content

Commit 6b9e2ce

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "virtio: virtio 1.0 support, misc patches This adds a lot of infrastructure for virtio 1.0 support. Notable missing pieces: virtio pci, virtio balloon (needs spec extension), vhost scsi. Plus, there are some minor fixes in a couple of places. Note: some net drivers are affected by these patches. David said he's fine with merging these patches through my tree. Rusty's on vacation, he acked using my tree for these, too" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (70 commits) virtio_ccw: finalize_features error handling virtio_ccw: future-proof finalize_features virtio_pci: rename virtio_pci -> virtio_pci_common virtio_pci: update file descriptions and copyright virtio_pci: split out legacy device support virtio_pci: setup config vector indirectly virtio_pci: setup vqs indirectly virtio_pci: delete vqs indirectly virtio_pci: use priv for vq notification virtio_pci: free up vq->priv virtio_pci: fix coding style for structs virtio_pci: add isr field virtio: drop legacy_only driver flag virtio_balloon: drop legacy_only driver flag virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 virtio: allow finalize_features to fail virtio_ccw: legacy: don't negotiate rev 1/features virtio: add API to detect legacy devices virtio_console: fix sparse warnings vhost: remove unnecessary forward declarations in vhost.h ...
2 parents 14ba9a2 + f01a2a8 commit 6b9e2ce

40 files changed

+2048
-1428
lines changed

drivers/block/virtio_blk.c

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int __virtblk_add_req(struct virtqueue *vq,
8080
{
8181
struct scatterlist hdr, status, cmd, sense, inhdr, *sgs[6];
8282
unsigned int num_out = 0, num_in = 0;
83-
int type = vbr->out_hdr.type & ~VIRTIO_BLK_T_OUT;
83+
__virtio32 type = vbr->out_hdr.type & ~cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_OUT);
8484

8585
sg_init_one(&hdr, &vbr->out_hdr, sizeof(vbr->out_hdr));
8686
sgs[num_out++] = &hdr;
@@ -91,19 +91,19 @@ static int __virtblk_add_req(struct virtqueue *vq,
9191
* block, and before the normal inhdr we put the sense data and the
9292
* inhdr with additional status information.
9393
*/
94-
if (type == VIRTIO_BLK_T_SCSI_CMD) {
94+
if (type == cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_SCSI_CMD)) {
9595
sg_init_one(&cmd, vbr->req->cmd, vbr->req->cmd_len);
9696
sgs[num_out++] = &cmd;
9797
}
9898

9999
if (have_data) {
100-
if (vbr->out_hdr.type & VIRTIO_BLK_T_OUT)
100+
if (vbr->out_hdr.type & cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_OUT))
101101
sgs[num_out++] = data_sg;
102102
else
103103
sgs[num_out + num_in++] = data_sg;
104104
}
105105

106-
if (type == VIRTIO_BLK_T_SCSI_CMD) {
106+
if (type == cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_SCSI_CMD)) {
107107
sg_init_one(&sense, vbr->req->sense, SCSI_SENSE_BUFFERSIZE);
108108
sgs[num_out + num_in++] = &sense;
109109
sg_init_one(&inhdr, &vbr->in_hdr, sizeof(vbr->in_hdr));
@@ -119,12 +119,13 @@ static int __virtblk_add_req(struct virtqueue *vq,
119119
static inline void virtblk_request_done(struct request *req)
120120
{
121121
struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
122+
struct virtio_blk *vblk = req->q->queuedata;
122123
int error = virtblk_result(vbr);
123124

124125
if (req->cmd_type == REQ_TYPE_BLOCK_PC) {
125-
req->resid_len = vbr->in_hdr.residual;
126-
req->sense_len = vbr->in_hdr.sense_len;
127-
req->errors = vbr->in_hdr.errors;
126+
req->resid_len = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.residual);
127+
req->sense_len = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.sense_len);
128+
req->errors = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.errors);
128129
} else if (req->cmd_type == REQ_TYPE_SPECIAL) {
129130
req->errors = (error != 0);
130131
}
@@ -173,25 +174,25 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req,
173174

174175
vbr->req = req;
175176
if (req->cmd_flags & REQ_FLUSH) {
176-
vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
177+
vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_FLUSH);
177178
vbr->out_hdr.sector = 0;
178-
vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
179+
vbr->out_hdr.ioprio = cpu_to_virtio32(vblk->vdev, req_get_ioprio(vbr->req));
179180
} else {
180181
switch (req->cmd_type) {
181182
case REQ_TYPE_FS:
182183
vbr->out_hdr.type = 0;
183-
vbr->out_hdr.sector = blk_rq_pos(vbr->req);
184-
vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
184+
vbr->out_hdr.sector = cpu_to_virtio64(vblk->vdev, blk_rq_pos(vbr->req));
185+
vbr->out_hdr.ioprio = cpu_to_virtio32(vblk->vdev, req_get_ioprio(vbr->req));
185186
break;
186187
case REQ_TYPE_BLOCK_PC:
187-
vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
188+
vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_SCSI_CMD);
188189
vbr->out_hdr.sector = 0;
189-
vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
190+
vbr->out_hdr.ioprio = cpu_to_virtio32(vblk->vdev, req_get_ioprio(vbr->req));
190191
break;
191192
case REQ_TYPE_SPECIAL:
192-
vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;
193+
vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_GET_ID);
193194
vbr->out_hdr.sector = 0;
194-
vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
195+
vbr->out_hdr.ioprio = cpu_to_virtio32(vblk->vdev, req_get_ioprio(vbr->req));
195196
break;
196197
default:
197198
/* We don't put anything else in the queue. */
@@ -204,9 +205,9 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req,
204205
num = blk_rq_map_sg(hctx->queue, vbr->req, vbr->sg);
205206
if (num) {
206207
if (rq_data_dir(vbr->req) == WRITE)
207-
vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
208+
vbr->out_hdr.type |= cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_OUT);
208209
else
209-
vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
210+
vbr->out_hdr.type |= cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_IN);
210211
}
211212

212213
spin_lock_irqsave(&vblk->vqs[qid].lock, flags);
@@ -331,7 +332,8 @@ static ssize_t virtblk_serial_show(struct device *dev,
331332

332333
return err;
333334
}
334-
DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
335+
336+
static DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
335337

336338
static void virtblk_config_changed_work(struct work_struct *work)
337339
{
@@ -476,7 +478,8 @@ static int virtblk_get_cache_mode(struct virtio_device *vdev)
476478
struct virtio_blk_config, wce,
477479
&writeback);
478480
if (err)
479-
writeback = virtio_has_feature(vdev, VIRTIO_BLK_F_WCE);
481+
writeback = virtio_has_feature(vdev, VIRTIO_BLK_F_WCE) ||
482+
virtio_has_feature(vdev, VIRTIO_F_VERSION_1);
480483

481484
return writeback;
482485
}
@@ -821,25 +824,34 @@ static const struct virtio_device_id id_table[] = {
821824
{ 0 },
822825
};
823826

824-
static unsigned int features[] = {
827+
static unsigned int features_legacy[] = {
825828
VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY,
826829
VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, VIRTIO_BLK_F_SCSI,
827830
VIRTIO_BLK_F_WCE, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE,
828831
VIRTIO_BLK_F_MQ,
832+
}
833+
;
834+
static unsigned int features[] = {
835+
VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY,
836+
VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
837+
VIRTIO_BLK_F_TOPOLOGY,
838+
VIRTIO_BLK_F_MQ,
829839
};
830840

831841
static struct virtio_driver virtio_blk = {
832-
.feature_table = features,
833-
.feature_table_size = ARRAY_SIZE(features),
834-
.driver.name = KBUILD_MODNAME,
835-
.driver.owner = THIS_MODULE,
836-
.id_table = id_table,
837-
.probe = virtblk_probe,
838-
.remove = virtblk_remove,
839-
.config_changed = virtblk_config_changed,
842+
.feature_table = features,
843+
.feature_table_size = ARRAY_SIZE(features),
844+
.feature_table_legacy = features_legacy,
845+
.feature_table_size_legacy = ARRAY_SIZE(features_legacy),
846+
.driver.name = KBUILD_MODNAME,
847+
.driver.owner = THIS_MODULE,
848+
.id_table = id_table,
849+
.probe = virtblk_probe,
850+
.remove = virtblk_remove,
851+
.config_changed = virtblk_config_changed,
840852
#ifdef CONFIG_PM_SLEEP
841-
.freeze = virtblk_freeze,
842-
.restore = virtblk_restore,
853+
.freeze = virtblk_freeze,
854+
.restore = virtblk_restore,
843855
#endif
844856
};
845857

@@ -871,8 +883,8 @@ static int __init init(void)
871883

872884
static void __exit fini(void)
873885
{
874-
unregister_blkdev(major, "virtblk");
875886
unregister_virtio_driver(&virtio_blk);
887+
unregister_blkdev(major, "virtblk");
876888
destroy_workqueue(virtblk_wq);
877889
}
878890
module_init(init);

drivers/char/virtio_console.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static inline bool use_multiport(struct ports_device *portdev)
355355
*/
356356
if (!portdev->vdev)
357357
return 0;
358-
return portdev->vdev->features[0] & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
358+
return __virtio_test_bit(portdev->vdev, VIRTIO_CONSOLE_F_MULTIPORT);
359359
}
360360

361361
static DEFINE_SPINLOCK(dma_bufs_lock);
@@ -566,9 +566,9 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
566566
if (!use_multiport(portdev))
567567
return 0;
568568

569-
cpkt.id = port_id;
570-
cpkt.event = event;
571-
cpkt.value = value;
569+
cpkt.id = cpu_to_virtio32(portdev->vdev, port_id);
570+
cpkt.event = cpu_to_virtio16(portdev->vdev, event);
571+
cpkt.value = cpu_to_virtio16(portdev->vdev, value);
572572

573573
vq = portdev->c_ovq;
574574

@@ -669,8 +669,8 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,
669669
* Give out the data that's requested from the buffer that we have
670670
* queued up.
671671
*/
672-
static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
673-
bool to_user)
672+
static ssize_t fill_readbuf(struct port *port, char __user *out_buf,
673+
size_t out_count, bool to_user)
674674
{
675675
struct port_buffer *buf;
676676
unsigned long flags;
@@ -688,7 +688,8 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
688688
if (ret)
689689
return -EFAULT;
690690
} else {
691-
memcpy(out_buf, buf->buf + buf->offset, out_count);
691+
memcpy((__force char *)out_buf, buf->buf + buf->offset,
692+
out_count);
692693
}
693694

694695
buf->offset += out_count;
@@ -1162,7 +1163,7 @@ static int get_chars(u32 vtermno, char *buf, int count)
11621163
/* If we don't have an input queue yet, we can't get input. */
11631164
BUG_ON(!port->in_vq);
11641165

1165-
return fill_readbuf(port, buf, count, false);
1166+
return fill_readbuf(port, (__force char __user *)buf, count, false);
11661167
}
11671168

11681169
static void resize_console(struct port *port)
@@ -1602,7 +1603,8 @@ static void unplug_port(struct port *port)
16021603
}
16031604

16041605
/* Any private messages that the Host and Guest want to share */
1605-
static void handle_control_message(struct ports_device *portdev,
1606+
static void handle_control_message(struct virtio_device *vdev,
1607+
struct ports_device *portdev,
16061608
struct port_buffer *buf)
16071609
{
16081610
struct virtio_console_control *cpkt;
@@ -1612,29 +1614,32 @@ static void handle_control_message(struct ports_device *portdev,
16121614

16131615
cpkt = (struct virtio_console_control *)(buf->buf + buf->offset);
16141616

1615-
port = find_port_by_id(portdev, cpkt->id);
1616-
if (!port && cpkt->event != VIRTIO_CONSOLE_PORT_ADD) {
1617+
port = find_port_by_id(portdev, virtio32_to_cpu(vdev, cpkt->id));
1618+
if (!port &&
1619+
cpkt->event != cpu_to_virtio16(vdev, VIRTIO_CONSOLE_PORT_ADD)) {
16171620
/* No valid header at start of buffer. Drop it. */
16181621
dev_dbg(&portdev->vdev->dev,
16191622
"Invalid index %u in control packet\n", cpkt->id);
16201623
return;
16211624
}
16221625

1623-
switch (cpkt->event) {
1626+
switch (virtio16_to_cpu(vdev, cpkt->event)) {
16241627
case VIRTIO_CONSOLE_PORT_ADD:
16251628
if (port) {
16261629
dev_dbg(&portdev->vdev->dev,
16271630
"Port %u already added\n", port->id);
16281631
send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
16291632
break;
16301633
}
1631-
if (cpkt->id >= portdev->config.max_nr_ports) {
1634+
if (virtio32_to_cpu(vdev, cpkt->id) >=
1635+
portdev->config.max_nr_ports) {
16321636
dev_warn(&portdev->vdev->dev,
1633-
"Request for adding port with out-of-bound id %u, max. supported id: %u\n",
1637+
"Request for adding port with "
1638+
"out-of-bound id %u, max. supported id: %u\n",
16341639
cpkt->id, portdev->config.max_nr_ports - 1);
16351640
break;
16361641
}
1637-
add_port(portdev, cpkt->id);
1642+
add_port(portdev, virtio32_to_cpu(vdev, cpkt->id));
16381643
break;
16391644
case VIRTIO_CONSOLE_PORT_REMOVE:
16401645
unplug_port(port);
@@ -1670,7 +1675,7 @@ static void handle_control_message(struct ports_device *portdev,
16701675
break;
16711676
}
16721677
case VIRTIO_CONSOLE_PORT_OPEN:
1673-
port->host_connected = cpkt->value;
1678+
port->host_connected = virtio16_to_cpu(vdev, cpkt->value);
16741679
wake_up_interruptible(&port->waitqueue);
16751680
/*
16761681
* If the host port got closed and the host had any
@@ -1752,7 +1757,7 @@ static void control_work_handler(struct work_struct *work)
17521757
buf->len = len;
17531758
buf->offset = 0;
17541759

1755-
handle_control_message(portdev, buf);
1760+
handle_control_message(vq->vdev, portdev, buf);
17561761

17571762
spin_lock(&portdev->c_ivq_lock);
17581763
if (add_inbuf(portdev->c_ivq, buf) < 0) {

drivers/lguest/lguest_device.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static unsigned desc_size(const struct lguest_device_desc *desc)
9494
}
9595

9696
/* This gets the device's feature bits. */
97-
static u32 lg_get_features(struct virtio_device *vdev)
97+
static u64 lg_get_features(struct virtio_device *vdev)
9898
{
9999
unsigned int i;
100100
u32 features = 0;
@@ -126,7 +126,7 @@ static void status_notify(struct virtio_device *vdev)
126126
* sorted out, this routine is called so we can tell the Host which features we
127127
* understand and accept.
128128
*/
129-
static void lg_finalize_features(struct virtio_device *vdev)
129+
static int lg_finalize_features(struct virtio_device *vdev)
130130
{
131131
unsigned int i, bits;
132132
struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
@@ -136,20 +136,25 @@ static void lg_finalize_features(struct virtio_device *vdev)
136136
/* Give virtio_ring a chance to accept features. */
137137
vring_transport_features(vdev);
138138

139+
/* Make sure we don't have any features > 32 bits! */
140+
BUG_ON((u32)vdev->features != vdev->features);
141+
139142
/*
140-
* The vdev->feature array is a Linux bitmask: this isn't the same as a
141-
* the simple array of bits used by lguest devices for features. So we
142-
* do this slow, manual conversion which is completely general.
143+
* Since lguest is currently x86-only, we're little-endian. That
144+
* means we could just memcpy. But it's not time critical, and in
145+
* case someone copies this code, we do it the slow, obvious way.
143146
*/
144147
memset(out_features, 0, desc->feature_len);
145148
bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
146149
for (i = 0; i < bits; i++) {
147-
if (test_bit(i, vdev->features))
150+
if (__virtio_test_bit(vdev, i))
148151
out_features[i / 8] |= (1 << (i % 8));
149152
}
150153

151154
/* Tell Host we've finished with this device's feature negotiation */
152155
status_notify(vdev);
156+
157+
return 0;
153158
}
154159

155160
/* Once they've found a field, getting a copy of it is easy. */

drivers/misc/mic/card/mic_virtio.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,23 @@ static inline struct device *mic_dev(struct mic_vdev *mvdev)
6868
}
6969

7070
/* This gets the device's feature bits. */
71-
static u32 mic_get_features(struct virtio_device *vdev)
71+
static u64 mic_get_features(struct virtio_device *vdev)
7272
{
7373
unsigned int i, bits;
7474
u32 features = 0;
7575
struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
7676
u8 __iomem *in_features = mic_vq_features(desc);
7777
int feature_len = ioread8(&desc->feature_len);
7878

79-
bits = min_t(unsigned, feature_len,
80-
sizeof(vdev->features)) * 8;
79+
bits = min_t(unsigned, feature_len, sizeof(features)) * 8;
8180
for (i = 0; i < bits; i++)
8281
if (ioread8(&in_features[i / 8]) & (BIT(i % 8)))
8382
features |= BIT(i);
8483

8584
return features;
8685
}
8786

88-
static void mic_finalize_features(struct virtio_device *vdev)
87+
static int mic_finalize_features(struct virtio_device *vdev)
8988
{
9089
unsigned int i, bits;
9190
struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
@@ -97,14 +96,19 @@ static void mic_finalize_features(struct virtio_device *vdev)
9796
/* Give virtio_ring a chance to accept features. */
9897
vring_transport_features(vdev);
9998

99+
/* Make sure we don't have any features > 32 bits! */
100+
BUG_ON((u32)vdev->features != vdev->features);
101+
100102
memset_io(out_features, 0, feature_len);
101103
bits = min_t(unsigned, feature_len,
102104
sizeof(vdev->features)) * 8;
103105
for (i = 0; i < bits; i++) {
104-
if (test_bit(i, vdev->features))
106+
if (__virtio_test_bit(vdev, i))
105107
iowrite8(ioread8(&out_features[i / 8]) | (1 << (i % 8)),
106108
&out_features[i / 8]);
107109
}
110+
111+
return 0;
108112
}
109113

110114
/*

0 commit comments

Comments
 (0)