From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MkilR-0007es-Ar for qemu-devel@nongnu.org; Mon, 07 Sep 2009 14:16:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MkilM-0007ZY-G4 for qemu-devel@nongnu.org; Mon, 07 Sep 2009 14:16:28 -0400 Received: from [199.232.76.173] (port=60644 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MkilM-0007ZV-CG for qemu-devel@nongnu.org; Mon, 07 Sep 2009 14:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48299) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MkilL-0001Qa-W5 for qemu-devel@nongnu.org; Mon, 07 Sep 2009 14:16:24 -0400 Date: Mon, 7 Sep 2009 21:14:37 +0300 From: "Michael S. Tsirkin" Message-ID: <20090907181436.GA8538@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] qemu: make virtio-blk PCI compliant by default List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws, qemu-devel@nongnu.org, john.cooper@redhat.com Cc: rusty@rustcorp.com.au, jens.axboe@oracle.com commit bf011293faaa7f87e4de83185931e7411b794128 made virtio-blk-pci not PCI-compliant, since it makes region 0 (which is an i/o region) size > 256, and, since PCI 2.1, i/o regions are limited to 256 bytes size. When the ATA serial number feature is off, which is the default, make the device spec compliant again, by making region 0 smaller. Signed-off-by: Michael S. Tsirkin Reported-by: Vadim Rozenfeld Tested-by: Vadim Rozenfeld --- Note: the companion feature in guest kernel was added by 1d589bb16b825b3a7b4edd34d997f1f1f953033d in linux 2.6.31-rc1. diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index a33eafb..3652c0a 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -27,6 +27,7 @@ typedef struct VirtIOBlock void *rq; char serial_str[BLOCK_SERIAL_STRLEN + 1]; QEMUBH *bh; + size_t config_size; } VirtIOBlock; static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) @@ -362,7 +363,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) virtio_identify_template(&blkcfg); memcpy(&blkcfg.identify[VIRTIO_BLK_ID_SN], s->serial_str, VIRTIO_BLK_ID_SN_BYTES); - memcpy(config, &blkcfg, sizeof(blkcfg)); + memcpy(config, &blkcfg, s->config_size); } static uint32_t virtio_blk_get_features(VirtIODevice *vdev) @@ -419,18 +420,21 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo) VirtIOBlock *s; int cylinders, heads, secs; static int virtio_blk_id; - char *ps; + char *ps = (char *)drive_get_serial(dinfo->bdrv); + size_t size = strlen(ps) ? sizeof(struct virtio_blk_config) : + offsetof(struct virtio_blk_config, _blk_size); s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK, - sizeof(struct virtio_blk_config), + size, sizeof(VirtIOBlock)); + s->config_size = size; s->vdev.get_config = virtio_blk_update_config; s->vdev.get_features = virtio_blk_get_features; s->vdev.reset = virtio_blk_reset; s->bs = dinfo->bdrv; s->rq = NULL; - if (strlen(ps = (char *)drive_get_serial(s->bs))) + if (strlen(ps)) strncpy(s->serial_str, ps, sizeof(s->serial_str)); else snprintf(s->serial_str, sizeof(s->serial_str), "0"); -- 1.6.2.5