From 52cbfa820ab26fef940ba5c627c3884df72971f3 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sun, 15 Aug 2010 17:17:43 +0300 Subject: [PATCH] kvm: Fail virtio blk ioports by default This patch changes virtio block device ioports to fail by default and adds few specific stubs to keep kernel booting still. Signed-off-by: Pekka Enberg --- tools/kvm/blk-virtio.c | 59 +++++++++++++++++++++++----------- tools/kvm/include/kvm/ioport.h | 20 ++++++++++++ 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/tools/kvm/blk-virtio.c b/tools/kvm/blk-virtio.c index 7670f0c572ac..e7eb44e45a57 100644 --- a/tools/kvm/blk-virtio.c +++ b/tools/kvm/blk-virtio.c @@ -6,22 +6,13 @@ #define VIRTIO_PCI_IOPORT_SIZE 24 -#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001 -#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002 - -static struct pci_device_header blk_virtio_device = { - .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET, - .device_id = PCI_DEVICE_ID_VIRTIO_BLK, - .header_type = PCI_HEADER_TYPE_NORMAL, - .revision_id = 0, - .class = 0x010000, - .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, - .subsys_id = PCI_SUBSYSTEM_ID_VIRTIO_BLK, - .bar[0] = IOPORT_VIRTIO | PCI_BASE_ADDRESS_SPACE_IO, +struct device { + uint32_t guest_features; + uint8_t status; }; +static struct device device; + static bool blk_virtio_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) { unsigned long offset; @@ -30,20 +21,28 @@ static bool blk_virtio_in(struct kvm *self, uint16_t port, void *data, int size, switch (offset) { case VIRTIO_PCI_HOST_FEATURES: + ioport__write32(data, 0x00); + break; case VIRTIO_PCI_GUEST_FEATURES: case VIRTIO_PCI_QUEUE_PFN: case VIRTIO_PCI_QUEUE_NUM: case VIRTIO_PCI_QUEUE_SEL: case VIRTIO_PCI_QUEUE_NOTIFY: + return false; case VIRTIO_PCI_STATUS: + ioport__write8(data, device.status); + break; case VIRTIO_PCI_ISR: case VIRTIO_MSI_CONFIG_VECTOR: - return true; + default: + return false; }; - return false; + return true; } +#include + static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) { unsigned long offset; @@ -52,16 +51,22 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size switch (offset) { case VIRTIO_PCI_GUEST_FEATURES: + device.guest_features = ioport__read32(data); + break; case VIRTIO_PCI_QUEUE_PFN: case VIRTIO_PCI_QUEUE_SEL: case VIRTIO_PCI_QUEUE_NOTIFY: + return false; case VIRTIO_PCI_STATUS: + device.status = ioport__read8(data); + break; case VIRTIO_MSI_CONFIG_VECTOR: case VIRTIO_MSI_QUEUE_VECTOR: - return true; + default: + return false; }; - return false; + return true; } static struct ioport_operations blk_virtio_io_ops = { @@ -69,9 +74,25 @@ static struct ioport_operations blk_virtio_io_ops = { .io_out = blk_virtio_out, }; +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001 +#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002 + +static struct pci_device_header blk_virtio_pci_device = { + .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET, + .device_id = PCI_DEVICE_ID_VIRTIO_BLK, + .header_type = PCI_HEADER_TYPE_NORMAL, + .revision_id = 0, + .class = 0x010000, + .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, + .subsys_id = PCI_SUBSYSTEM_ID_VIRTIO_BLK, + .bar[0] = IOPORT_VIRTIO | PCI_BASE_ADDRESS_SPACE_IO, +}; + void blk_virtio__init(void) { - pci__register(&blk_virtio_device, 1); + pci__register(&blk_virtio_pci_device, 1); ioport__register(IOPORT_VIRTIO, &blk_virtio_io_ops, VIRTIO_PCI_IOPORT_SIZE); } diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h index eaedc1e7be82..b4ae9abea61e 100644 --- a/tools/kvm/include/kvm/ioport.h +++ b/tools/kvm/include/kvm/ioport.h @@ -17,4 +17,24 @@ struct ioport_operations { void ioport__register(uint16_t port, struct ioport_operations *ops, int count); +static inline uint8_t ioport__read8(uint8_t *data) +{ + return *data; +} + +static inline uint32_t ioport__read32(uint32_t *data) +{ + return *data; +} + +static inline void ioport__write8(uint8_t *data, uint8_t value) +{ + *data = value; +} + +static inline void ioport__write32(uint32_t *data, uint32_t value) +{ + *data = value; +} + #endif /* KVM__IOPORT_H */ -- 2.39.5