From patchwork Wed Mar 20 11:26:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10861411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D80581390 for ; Wed, 20 Mar 2019 11:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B436929B4E for ; Wed, 20 Mar 2019 11:28:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A886429B50; Wed, 20 Mar 2019 11:28:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2CC2129B4E for ; Wed, 20 Mar 2019 11:28:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:46401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6ZOh-00008L-Ea for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Mar 2019 07:28:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6ZNY-0007jS-IZ for qemu-devel@nongnu.org; Wed, 20 Mar 2019 07:27:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6ZNX-0003oV-Du for qemu-devel@nongnu.org; Wed, 20 Mar 2019 07:27:28 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:45753) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h6ZNX-0003o5-2V for qemu-devel@nongnu.org; Wed, 20 Mar 2019 07:27:27 -0400 Received: by mail-pf1-x442.google.com with SMTP id v21so1704881pfm.12 for ; Wed, 20 Mar 2019 04:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eX8ddzsNtHLK642MPr1RzE+GTBi36YMIFONSfsubNPA=; b=peZp1rXS3K9xst2IlpcPS6A1RlP7ntdhs2weSlDaoMePeGPWHzGBloE/xqieEefnik kzICGcud51apronhvzIrbWSYF0bBiDpJfOaMAlmnk7tSXI/6uuxVXToqFfet2ADjUzC9 1V4TxkJ8nqIelkh21aPygl9GVT8Mw4M9UNIiWmGujZNhGHEONzgXRsMO5T+6phxsiPii ANNDmKCxEyThjOum0ZoTuNX4kL1n1lo1BZXQ+XUPRpIGkGmMOuo/u+5aAaN48No14py1 gpmlJ6X54A+OZC7DwQKSJfjIcCr2yYdfbtJPkPVMFIIoB2uOQM4OpEFDWeXUDGFZ0nhK 51ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eX8ddzsNtHLK642MPr1RzE+GTBi36YMIFONSfsubNPA=; b=uT52vSe3EJjUaaBw/HdlRoj11QYXwxPMe+r2FKOJo/JtNo6kD7Agm9bkU4wLL6cDyb aXkLtMYTVeCRK5gOSsLyeRsVoGcKOX9gE0elBRTXbJDfZilupVaUY0SV8nt6QTrC6Gh1 lMMGG/m5OZHFR8BHHcYx1Rn6f71zHkujk+epxjRRugAxntBgPhZcJzngPbMsoc67+Nm9 gt6Pv/4c2AsGS73NhxHuHmekVnmMKZ9TkxPonZJzZkpZ+f39odsSTWQOYEYIl47zu2xg JHhvV8pLdyKpm+w6s/RvKL5jAvFpP3hwEKC5Q0JF7SLXMb4loUB4Gl/Pyvxb2DtvrlbZ 1fcA== X-Gm-Message-State: APjAAAWfKj4NJHVCLs/noMBO8X/MhEq5DXCbh/FBSosO3bkyKyNSwS1d CzlG2x96r3vASyK2XdmdoNo= X-Google-Smtp-Source: APXvYqzuR9W+7UhwQTimIfMB2UxS4ghGhIPTgxRn17JZhW3f4r7zLqQlqaAVYf4K3VGJUdldZsqgXA== X-Received: by 2002:a17:902:728b:: with SMTP id d11mr7537078pll.257.1553081246323; Wed, 20 Mar 2019 04:27:26 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id w123sm3265360pfw.72.2019.03.20.04.27.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 04:27:25 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, kwolf@redhat.com, mreitz@redhat.com, stefanha@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com, maxime.coquelin@redhat.com, yury-kotov@yandex-team.ru, wrfsh@yandex-team.ru, changpeng.liu@intel.com Date: Wed, 20 Mar 2019 19:26:40 +0800 Message-Id: <20190320112646.3712-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190320112646.3712-1-xieyongji@baidu.com> References: <20190320112646.3712-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v8 1/7] virtio: Introduce started flag to VirtioDevice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji The virtio 1.0 transitional devices support driver uses the device before setting the DRIVER_OK status bit. So we introduce a started flag to indicate whether driver has started the device or not. Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- hw/virtio/virtio.c | 52 ++++++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 2626a895cb..af7b59b4ae 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1162,10 +1162,16 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val) } } } + vdev->started = val & VIRTIO_CONFIG_S_DRIVER_OK; + if (unlikely(vdev->start_on_kick && vdev->started)) { + vdev->start_on_kick = false; + } + if (k->set_status) { k->set_status(vdev, val); } vdev->status = val; + return 0; } @@ -1208,6 +1214,9 @@ void virtio_reset(void *opaque) k->reset(vdev); } + vdev->start_on_kick = (virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && + !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)); + vdev->started = false; vdev->broken = false; vdev->guest_features = 0; vdev->queue_sel = 0; @@ -1518,14 +1527,21 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) static bool virtio_queue_notify_aio_vq(VirtQueue *vq) { + bool ret = false; + if (vq->vring.desc && vq->handle_aio_output) { VirtIODevice *vdev = vq->vdev; trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); - return vq->handle_aio_output(vdev, vq); + ret = vq->handle_aio_output(vdev, vq); + + if (unlikely(vdev->start_on_kick)) { + vdev->started = true; + vdev->start_on_kick = false; + } } - return false; + return ret; } static void virtio_queue_notify_vq(VirtQueue *vq) @@ -1539,6 +1555,11 @@ static void virtio_queue_notify_vq(VirtQueue *vq) trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); vq->handle_output(vdev, vq); + + if (unlikely(vdev->start_on_kick)) { + vdev->started = true; + vdev->start_on_kick = false; + } } } @@ -1556,6 +1577,11 @@ void virtio_queue_notify(VirtIODevice *vdev, int n) } else if (vq->handle_output) { vq->handle_output(vdev, vq); } + + if (unlikely(vdev->start_on_kick)) { + vdev->started = true; + vdev->start_on_kick = false; + } } uint16_t virtio_queue_vector(VirtIODevice *vdev, int n) @@ -1770,6 +1796,13 @@ static bool virtio_broken_needed(void *opaque) return vdev->broken; } +static bool virtio_started_needed(void *opaque) +{ + VirtIODevice *vdev = opaque; + + return vdev->started; +} + static const VMStateDescription vmstate_virtqueue = { .name = "virtqueue_state", .version_id = 1, @@ -1898,6 +1931,17 @@ static const VMStateDescription vmstate_virtio_broken = { } }; +static const VMStateDescription vmstate_virtio_started = { + .name = "virtio/started", + .version_id = 1, + .minimum_version_id = 1, + .needed = &virtio_started_needed, + .fields = (VMStateField[]) { + VMSTATE_BOOL(started, VirtIODevice), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio = { .name = "virtio", .version_id = 1, @@ -1913,6 +1957,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_ringsize, &vmstate_virtio_broken, &vmstate_virtio_extra_state, + &vmstate_virtio_started, NULL } }; @@ -2286,6 +2331,9 @@ void virtio_init(VirtIODevice *vdev, const char *name, g_malloc0(sizeof(*vdev->vector_queues) * nvectors); } + vdev->start_on_kick = (virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && + !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)); + vdev->started = false; vdev->device_id = device_id; vdev->status = 0; atomic_set(&vdev->isr, 0); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index ce9516236a..fea08bcc44 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -105,6 +105,8 @@ struct VirtIODevice uint16_t device_id; bool vm_running; bool broken; /* device in invalid state, needs reset */ + bool started; + bool start_on_kick; /* virtio 1.0 transitional devices support that */ VMChangeStateEntry *vmstate; char *bus_name; uint8_t device_endian;