From patchwork Mon Sep 7 18:14:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 33109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id B1FC0B70BA for ; Tue, 8 Sep 2009 04:17:02 +1000 (EST) Received: from localhost ([127.0.0.1]:45536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mkilu-0007h1-J5 for incoming@patchwork.ozlabs.org; Mon, 07 Sep 2009 14:16:58 -0400 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 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n87IGJA7003622; Mon, 7 Sep 2009 14:16:19 -0400 Received: from redhat.com (vpn-6-95.tlv.redhat.com [10.35.6.95]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n87IGAr2013365 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 7 Sep 2009 14:16:16 -0400 Date: Mon, 7 Sep 2009 21:14:37 +0300 From: "Michael S. Tsirkin" To: anthony@codemonkey.ws, qemu-devel@nongnu.org, john.cooper@redhat.com Message-ID: <20090907181436.GA8538@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: rusty@rustcorp.com.au, jens.axboe@oracle.com Subject: [Qemu-devel] [PATCH] qemu: make virtio-blk PCI compliant by default X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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");