All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: anthony@codemonkey.ws, qemu-devel@nongnu.org, john.cooper@redhat.com
Cc: rusty@rustcorp.com.au, jens.axboe@oracle.com
Subject: [Qemu-devel] [PATCH] qemu: make virtio-blk PCI compliant by default
Date: Mon, 7 Sep 2009 21:14:37 +0300	[thread overview]
Message-ID: <20090907181436.GA8538@redhat.com> (raw)

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 <mst@redhat.com>
Reported-by: Vadim Rozenfeld <vrozenfe@redhat.com>
Tested-by: Vadim Rozenfeld <vrozenfe@redhat.com>

---

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

             reply	other threads:[~2009-09-07 18:16 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-07 18:14 Michael S. Tsirkin [this message]
2009-09-08  7:40 ` [Qemu-devel] Re: [PATCH] qemu: make virtio-blk PCI compliant by default john cooper
2009-09-08  7:58   ` Michael S. Tsirkin
2009-09-21 11:09     ` Rusty Russell
2009-09-21 15:47       ` john cooper
2009-09-22  9:30         ` Avi Kivity
2009-09-22 14:21           ` john cooper
2009-09-22 14:27             ` Avi Kivity
2009-09-22 14:41               ` Michael S. Tsirkin
2009-09-22 14:45                 ` Avi Kivity
2009-09-22 15:09               ` john cooper
2009-09-23  1:59                 ` Anthony Liguori
2009-09-23  4:56                   ` john cooper
2009-09-29  6:09                     ` [Qemu-devel] [PATCH 0/2] fix virtio_blk serial pci config breakage john cooper
2009-09-29  6:58                       ` [Qemu-devel] " Michael S. Tsirkin
2009-09-29  7:22                         ` Avi Kivity
2009-09-29  8:54                           ` Michael S. Tsirkin
2009-09-29  9:16                             ` Avi Kivity
2009-09-29 13:55                             ` Anthony Liguori
2009-09-29 14:06                               ` Michael S. Tsirkin
2009-09-29 14:14                                 ` Anthony Liguori
2009-09-29 16:24                                   ` Avi Kivity
2009-09-29 16:30                                   ` Michael S. Tsirkin
2009-09-29 17:26                                     ` Anthony Liguori
2009-09-29 17:31                                       ` Michael S. Tsirkin
2009-09-29 17:28                               ` Rusty Russell
2009-09-29 17:31                                 ` Anthony Liguori
2009-09-30  1:12                                   ` Rusty Russell
2009-09-30  1:22                                     ` Jamie Lokier
2009-10-05 15:44                                     ` john cooper
2009-09-29 18:44                               ` john cooper
2009-09-29 20:55                                 ` Anthony Liguori
2009-09-30  1:19                                   ` Rusty Russell
2009-09-30  2:17                                     ` Anthony Liguori
2009-09-30 12:00                                       ` Rusty Russell
2009-09-30 18:04                                         ` Jamie Lokier
2009-10-05 15:41                                           ` john cooper
2009-09-30 11:47                                   ` Paul Brook
2009-10-05 15:40                                     ` john cooper
2009-09-29 13:51                       ` Anthony Liguori
2009-09-29 16:22                         ` Avi Kivity
2009-09-29 17:24                           ` Anthony Liguori
2009-09-29  6:09                     ` [Qemu-devel] [PATCH 1/2] " john cooper
2009-09-29  9:01                       ` [Qemu-devel] " Michael S. Tsirkin
2009-10-05 15:47                       ` [Qemu-devel] [PATCH] fix virtio_blk serial pci config breakage, v2 john cooper
2009-10-05 19:54                         ` [Qemu-devel] " Michael S. Tsirkin
2009-10-07  5:49                           ` john cooper
2009-10-07 13:48                             ` Anthony Liguori
2009-10-07 13:52                               ` Michael S. Tsirkin
2009-10-07 13:55                                 ` Anthony Liguori
2009-10-07 15:38                                   ` john cooper
2009-10-05 20:15                         ` Michael S. Tsirkin
2009-10-06 14:23                         ` Anthony Liguori
2009-09-29  6:10                     ` [Qemu-devel] [PATCH 2/2] fix virtio_blk serial pci config breakage john cooper
2009-09-29  6:57                       ` [Qemu-devel] " Michael S. Tsirkin
2009-09-29 17:14                       ` Rusty Russell
2009-09-14 11:39   ` [Qemu-devel] Re: [PATCH] qemu: make virtio-blk PCI compliant by default Michael S. Tsirkin
2009-09-15  7:29     ` john cooper
2009-09-22  5:06     ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090907181436.GA8538@redhat.com \
    --to=mst@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=jens.axboe@oracle.com \
    --cc=john.cooper@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.