From patchwork Sun Jan 31 10:28:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8173231 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A2BA79F96D for ; Sun, 31 Jan 2016 10:29:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C7418202FE for ; Sun, 31 Jan 2016 10:29:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E94E5202F0 for ; Sun, 31 Jan 2016 10:29:30 +0000 (UTC) Received: from localhost ([::1]:41098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpG6-0007P3-6L for patchwork-qemu-devel@patchwork.kernel.org; Sun, 31 Jan 2016 05:29:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFr-0007LZ-S5 for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPpFq-0007lg-Kf for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:15 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36183) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFq-0007lU-Ai for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:14 -0500 Received: by mail-wm0-x242.google.com with SMTP id 128so4652139wmz.3 for ; Sun, 31 Jan 2016 02:29:14 -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=a6gkMilB8uZSbIdJKOBgDGA/+03b2bsTn337C1QYpu0=; b=hjSttZXaPPt451ZPai+RmQhjV/XvWIrb/xYFeNhxo4Ddomy6uLhrop+ztu+TdDCCTJ G84+sQLrkaeXgnplY8+YMFKm1/vOX7L9kcRJ1s6QV4XypHzxgL1nw65lEoL5Nwxu+FOH 1MWIyFVbHO9EydRTmNvOlm54RT/Gq6TNHrMds8eIkgo1po103KBVkxtGrU8oVcEUFHRk nulhy/RloVu210uFYzNQeij7y5LqAvXCbMVUfWPep73BX2IbNdia3vdhWQN21hKQAIEb u/UWvejsG5yk/xRAnG8YCT75+XSUVW1EmUVjEzZqZu102hqj2zspc5REIDAaXQBrSA3Z G0ig== 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=a6gkMilB8uZSbIdJKOBgDGA/+03b2bsTn337C1QYpu0=; b=RirjR0HYTcmo6EPJfbdSMr4z/jR4EbQe2BZ0S/1uQLShhwFfrmMNL9/HZt/FfaEEmZ atZz2UR4SaBmmR3Ag80BfegPaRoWYehtkbnrd7AYc4loylaEeIdjUkVMul5VsnlksEiH YqWnaaM/SxQCvMlKTO9RN6jDSJ9+xTE0YH/6zsjHNnNzHqKCOF9+Yc6dHmPeInrbYO3p 1tuX0hZOSEYcPXcrTXLvyv01NEw9xjzr1xEZ0aROpBcgFX0zujSeT8VCxqsJZchfmsXf PizUNbgQVu2Cd5JjmhmjVrTcgugzXqBgMzEhydcdxtbOiAPKneZVxRCyyX2SfIIZkH0q MOpw== X-Gm-Message-State: AG10YOTTHhV6O+a8oakZCRGz9/FZw3e0k2XuIDzqQA0Kg/L3aT49XecCTYRPhDmgwJkbjA== X-Received: by 10.28.68.214 with SMTP id r205mr6431457wma.23.1454236153812; Sun, 31 Jan 2016 02:29:13 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 02:29:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 31 Jan 2016 11:28:59 +0100 Message-Id: <1454236146-23293-4-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 03/10] virtio: introduce qemu_get/put_virtqueue_element 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move allocation to virtio functions also when loading/saving a VirtQueueElement. This will also let the load/save functions keep backwards compatibility when the VirtQueueElement layout is changed. Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- hw/block/virtio-blk.c | 10 +++------- hw/char/virtio-serial-bus.c | 10 +++------- hw/scsi/virtio-scsi.c | 7 ++----- hw/virtio/virtio.c | 13 +++++++++++++ include/hw/virtio/virtio.h | 2 ++ 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index a874cb7..75b2bfc 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -807,8 +807,7 @@ static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f) while (req) { qemu_put_sbyte(f, 1); - qemu_put_buffer(f, (unsigned char *)&req->elem, - sizeof(VirtQueueElement)); + qemu_put_virtqueue_element(f, &req->elem); req = req->next; } qemu_put_sbyte(f, 0); @@ -831,14 +830,11 @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f, VirtIOBlock *s = VIRTIO_BLK(vdev); while (qemu_get_sbyte(f)) { - VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1); + VirtIOBlockReq *req; + req = qemu_get_virtqueue_element(f, sizeof(VirtIOBlockReq)); virtio_blk_init_request(s, req); - qemu_get_buffer(f, (unsigned char *)&req->elem, - sizeof(VirtQueueElement)); req->next = s->rq; s->rq = req; - - virtqueue_map(&req->elem); } return 0; diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index f0c1c45..12ce64a 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -645,9 +645,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f) if (elem_popped) { qemu_put_be32s(f, &port->iov_idx); qemu_put_be64s(f, &port->iov_offset); - - qemu_put_buffer(f, (unsigned char *)port->elem, - sizeof(VirtQueueElement)); + qemu_put_virtqueue_element(f, port->elem); } } } @@ -722,10 +720,8 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, qemu_get_be32s(f, &port->iov_idx); qemu_get_be64s(f, &port->iov_offset); - port->elem = g_new(VirtQueueElement, 1); - qemu_get_buffer(f, (unsigned char *)port->elem, - sizeof(VirtQueueElement)); - virtqueue_map(port->elem); + port->elem = + qemu_get_virtqueue_element(f, sizeof(VirtQueueElement)); /* * Port was throttled on source machine. Let's diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index ca20a1d..789cf38 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -188,7 +188,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq) assert(n < vs->conf.num_queues); qemu_put_be32s(f, &n); - qemu_put_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem)); + qemu_put_virtqueue_element(f, &req->elem); } static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq) @@ -201,12 +201,9 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq) qemu_get_be32s(f, &n); assert(n < vs->conf.num_queues); - req = g_malloc(sizeof(VirtIOSCSIReq) + vs->cdb_size); - qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem)); + req = qemu_get_virtqueue_element(f, sizeof(VirtIOSCSIReq) + vs->cdb_size); virtio_scsi_init_req(s, vs->cmd_vqs[n], req); - virtqueue_map(&req->elem); - if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) { error_report("invalid SCSI request migration data"); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9b2c0bf..388e91c 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -576,6 +576,19 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) return elem; } +void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz) +{ + VirtQueueElement *elem = g_malloc(sz); + qemu_get_buffer(f, (uint8_t *)elem, sizeof(VirtQueueElement)); + virtqueue_map(elem); + return elem; +} + +void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem) +{ + qemu_put_buffer(f, (uint8_t *)elem, sizeof(VirtQueueElement)); +} + /* virtio device */ static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector) { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 21fda17..44da9a8 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -153,6 +153,8 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, void virtqueue_map(VirtQueueElement *elem); void *virtqueue_pop(VirtQueue *vq, size_t sz); +void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz); +void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem); int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes, unsigned int out_bytes); void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,