From patchwork Sun Jan 31 10:28:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 576166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 36ECA140C05 for ; Sun, 31 Jan 2016 21:29:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=JkU8DTq+; dkim-atps=neutral Received: from localhost ([::1]:41101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpGO-0008PY-7q for incoming@patchwork.ozlabs.org; Sun, 31 Jan 2016 05:29:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFp-0007JM-SV for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPpFo-0007l3-UY for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:13 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFo-0007ky-Nw for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:12 -0500 Received: by mail-wm0-x242.google.com with SMTP id p63so4658399wmp.1 for ; Sun, 31 Jan 2016 02:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EckNAKy19+Dxdn2uqbqQcVKk9m6EHlA6d4Rp08udLvA=; b=JkU8DTq+EEUFvjuSizxHT0yvlROA3DHef2NAjBri4J5HFYbq2avewFc8q3JLWQrblM i8iBsMirjp59WCAf34HjNgcjz11HtHrqnez5tukscBHeSvad3AljBNoMjyCGjL8xX8SI 1no6/O6cnrc099xIC2IQJ7uGFb7uqvN4DT7Jp3sXmFzwvpKX/luuItU4v28B+HtywW61 7nPi58b/1f0ITkqBq8vkU8r7eu4H1gFF5TNCChn/dTa12ntaVKK3AUsBU9lg+wWiyr/3 rq/1Y7Ym8KvuBbATg1VTK58E5nezN9zumQuyEcNtr6vl5DJCqbJoss7yZxbPya+gATtJ H0tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EckNAKy19+Dxdn2uqbqQcVKk9m6EHlA6d4Rp08udLvA=; b=Nxdr+/Xlu/TFT79IekMKLv1qiVQDzw+aOo/2O37WR3IQl/82mg+UMvU/4/WBDcME0A DM5VI17nkaJwWs10s+gWu7Q/SpHjhjg/Y2G0oYs0Rw2xpbrMN7tU3WyFAN4cyP1xl9UZ UnAKiDtwWCltqhzylAn3yxuQ4GoK+TiarWpdpGvkS8sQKn/JVB5+IgfLpw+d5xCIsiWJ xFDvUer/4P4xpzcqqQUVKLODxB2cLNytwLoj/yipKxuW98/9E/1v0t9S+BiAws+MviH7 WhYFIlMmufNEcDD6AvY8WQwpzGOL5qih8d0HNoI9YzqZHCHvMAxXUXCN5BlU4Cg8eV/r QHHQ== X-Gm-Message-State: AG10YORPz6UWkrp7+zgQMcApxGwsngkjm0gs59RvwGRrCneZ/Hbe+uFCoArrSKOJorecWA== X-Received: by 10.28.140.142 with SMTP id o136mr5754196wmd.45.1454236152212; Sun, 31 Jan 2016 02:29:12 -0800 (PST) Received: from donizetti.fosdem.net ([2001:67c:1810:f051:7105:9465:633c:859]) by smtp.gmail.com with ESMTPSA id i79sm2349430wmf.24.2016.01.31.02.29.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 02:29:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 31 Jan 2016 11:28:57 +0100 Message-Id: <1454236146-23293-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454236146-23293-1-git-send-email-pbonzini@redhat.com> References: <1454236146-23293-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Cc: cornelia.huck@de.ibm.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 01/10] virtio: move VirtQueueElement at the beginning of the structs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The next patch will make virtqueue_pop/vring_pop allocate memory for the VirtQueueElement. In some cases (blk, scsi, gpu) the device wants to extend VirtQueueElement with device-specific fields and, until now, the place of the VirtQueueElement within the containing struct didn't matter. When allocating the entire block in virtqueue_pop/vring_pop, however, the containing struct must basically be a "subclass" of VirtQueueElement, with the VirtQueueElement as the first field. Make that the case for blk and scsi; gpu is already doing it. Signed-off-by: Paolo Bonzini Reviewed-by: Cornelia Huck --- hw/scsi/virtio-scsi.c | 3 +-- include/hw/virtio/virtio-blk.h | 2 +- include/hw/virtio/virtio-scsi.h | 13 ++++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 607593c..df8e379 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -44,8 +44,7 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq) { VirtIOSCSIReq *req; VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s; - const size_t zero_skip = offsetof(VirtIOSCSIReq, elem) - + sizeof(VirtQueueElement); + const size_t zero_skip = offsetof(VirtIOSCSIReq, vring); req = g_malloc(sizeof(*req) + vs->cdb_size); req->vq = vq; diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index ae11a63..403ab86 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -60,9 +60,9 @@ typedef struct VirtIOBlock { } VirtIOBlock; typedef struct VirtIOBlockReq { + VirtQueueElement elem; int64_t sector_num; VirtIOBlock *dev; - VirtQueueElement elem; struct virtio_blk_inhdr *in; struct virtio_blk_outhdr out; QEMUIOVector qiov; diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h index 088fe9f..63f5b51 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -102,18 +102,17 @@ typedef struct VirtIOSCSI { } VirtIOSCSI; typedef struct VirtIOSCSIReq { + /* Note: + * - fields up to resp_iov are initialized by virtio_scsi_init_req; + * - fields starting at vring are zeroed by virtio_scsi_init_req. + * */ + VirtQueueElement elem; + VirtIOSCSI *dev; VirtQueue *vq; QEMUSGList qsgl; QEMUIOVector resp_iov; - /* Note: - * - fields before elem are initialized by virtio_scsi_init_req; - * - elem is uninitialized at the time of allocation. - * - fields after elem are zeroed by virtio_scsi_init_req. - * */ - - VirtQueueElement elem; /* Set by dataplane code. */ VirtIOSCSIVring *vring;