1
From 4030db0d2c5a79de2a1b5c31514503e4ff2a3cd1 Mon Sep 17 00:00:00 2001
2
From: Gleb Natapov <gleb@redhat.com>
3
Date: Mon, 17 May 2010 16:27:27 +0300
4
Subject: [PATCH 19/54] fix two issues with virtio-blk
6
1. Check if blk_size is valid in virtio_blk config.
7
2. Disable interrupt otherwise interrupt may stuck
10
Signed-off-by: Gleb Natapov <gleb@redhat.com>
14
- Treat sector size not equal to 512 bytes as error.
16
src/virtio-blk.c | 17 ++++++++++++++---
17
src/virtio-blk.h | 2 ++
18
src/virtio-ring.h | 2 ++
19
3 files changed, 18 insertions(+), 3 deletions(-)
21
diff --git a/src/virtio-blk.c b/src/virtio-blk.c
22
index 7cc2edb..e6167e9 100644
23
--- a/src/virtio-blk.c
24
+++ b/src/virtio-blk.c
25
@@ -127,23 +127,34 @@ virtio_blk_setup(void)
26
VIRTIO_CONFIG_S_DRIVER );
28
if (vp_find_vq(ioaddr, 0, vdrive_g->vq) < 0 ) {
29
+ dprintf(1, "fail to find vq for virtio-blk %x:%x\n",
30
+ pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf));
35
- dprintf(1, "fail to find vq for virtio-blk %x:%x\n",
36
- pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf));
40
struct virtio_blk_config cfg;
41
vp_get(ioaddr, 0, &cfg, sizeof(cfg));
43
- vdrive_g->drive.blksize = cfg.blk_size;
44
+ u32 f = vp_get_features(ioaddr);
45
+ vdrive_g->drive.blksize = (f & (1 << VIRTIO_BLK_F_BLK_SIZE)) ?
46
+ cfg.blk_size : DISK_SECTOR_SIZE;
48
vdrive_g->drive.sectors = cfg.capacity;
49
dprintf(3, "virtio-blk %x:%x blksize=%d sectors=%u\n",
50
pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf),
51
vdrive_g->drive.blksize, (u32)vdrive_g->drive.sectors);
53
+ if (vdrive_g->drive.blksize != DISK_SECTOR_SIZE) {
54
+ dprintf(1, "virtio-blk %x:%x block size %d is unsupported\n",
55
+ pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf),
56
+ vdrive_g->drive.blksize);
60
vdrive_g->drive.pchs.cylinders = cfg.cylinders;
61
vdrive_g->drive.pchs.heads = cfg.heads;
62
vdrive_g->drive.pchs.spt = cfg.sectors;
63
diff --git a/src/virtio-blk.h b/src/virtio-blk.h
64
index 8095d5b..7243704 100644
65
--- a/src/virtio-blk.h
66
+++ b/src/virtio-blk.h
67
@@ -16,6 +16,8 @@ struct virtio_blk_config
69
} __attribute__((packed));
71
+#define VIRTIO_BLK_F_BLK_SIZE 6
73
/* These two define direction. */
74
#define VIRTIO_BLK_T_IN 0
75
#define VIRTIO_BLK_T_OUT 1
76
diff --git a/src/virtio-ring.h b/src/virtio-ring.h
77
index 3fb86fe..014defc 100644
78
--- a/src/virtio-ring.h
79
+++ b/src/virtio-ring.h
80
@@ -105,6 +105,8 @@ static inline void vring_init(struct vring *vr,
81
vr->desc = phys_to_virt(pa);
83
vr->avail = (struct vring_avail *)&vr->desc[num];
84
+ /* disable interrupts */
85
+ vr->avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
87
/* physical address of used must be page aligned */