From patchwork Tue Jun 4 07:34:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10974349 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 88EBB912 for ; Tue, 4 Jun 2019 07:39:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782422875E for ; Tue, 4 Jun 2019 07:39:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CA0528767; Tue, 4 Jun 2019 07:39:23 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 004CA2875E for ; Tue, 4 Jun 2019 07:39:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:47460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY42U-0004ME-51 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Jun 2019 03:39:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY3yo-0001F2-JU for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY3yn-0003fS-HQ for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:34 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42692) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hY3yn-0003bq-97 for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:33 -0400 Received: by mail-pf1-x444.google.com with SMTP id q10so1935602pff.9 for ; Tue, 04 Jun 2019 00:35:33 -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=kr819H7lf43YtonHy3KPFOGfzuzf63KXY2ivIp5O1R0=; b=MK92V1Hgrn/hsMFylc7hj2LnV3wXX11rAB9Eta32S35opPYOOdlpYR2jEURZKXyeVM czKPdr0MQhGoHIh5M9kITpTzmmkuS+c6YPJl7LQqeQGsJ/z2/3RWS0zjHkMPSwY+safp uRuFgQbZM6K2W+JjKiLmRtG23D9dW9ZvIffVwDTm7W0GHEX3wkHZsd/mh7J2moxp7Tqa w60QfT/E+r9vPKETb4cDK73gQxFcZ7JBAeDWnB/eHrCxzpV0ioz9t0EHFXv6B5fVG69m dmfgy/jbn+oYkYG8VgOs9VXKVb/m1mrMRzUEwk/DjMIyxpp0tPn2llsHe/rKUNuK3TOo giZg== 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=kr819H7lf43YtonHy3KPFOGfzuzf63KXY2ivIp5O1R0=; b=MJqHuU6FYl54UrWY34rMkr0V8t3w+W7Yg+ZlZrf79Kma8pNdgo4zM83/+qZQ1L2fx3 22lhotlGiwiBJjX055Ws7jFwEHO9NZEU1VrBq6JMhINYMFB94Qo9WHwCvdZxwO8segxD s9qb6mzlJ5QiTn/yMTLbCR/fACn5cZFju1rnFC0GDALJ7KFypM6cxR5eY5UK0vs9rPm+ J2mIiOWaii8JJaMJuz5h6h5c9r72r8L9MRF68AEDNtYNwt167sjUubJKeR2P/GlBDM8m ZEsUVoRHD3tMVmrvG5uqPBeUmFS9iKSpqowVl909oQIYl53utp64bmOCzSOYzbtW5Uhy O9rg== X-Gm-Message-State: APjAAAUFexMrIgnMKdaY0BBegI6ozvGswJqLIgJDkR3rfOd5WAhp+9uj TQjG9tUSlpYyP9pqObnP+Vk= X-Google-Smtp-Source: APXvYqwuMS0dJ7cxNZCohtYFJjt4GsyYFUIGCVZ3dLdjYoEZ1NImmL/yEHWLGzH7x/uduqxJIwdl7A== X-Received: by 2002:a63:e408:: with SMTP id a8mr34019828pgi.146.1559633732044; Tue, 04 Jun 2019 00:35:32 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id v4sm20017907pfe.180.2019.06.04.00.35.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 00:35:31 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org Date: Tue, 4 Jun 2019 15:34:55 +0800 Message-Id: <20190604073459.15651-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604073459.15651-1-xieyongji@baidu.com> References: <20190604073459.15651-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::444 Subject: [Qemu-devel] [PATCH v2 1/5] virtio: Set "start_on_kick" on virtio_set_features() 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: Xie Yongji , dgilbert@redhat.com, qemu-devel@nongnu.org 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 guest feature is not set correctly on virtio_reset() and virtio_init(). So we should not use it to set "start_on_kick" at that point. This patch set "start_on_kick" on virtio_set_features() instead. Fixes: badaf79cfdbd3 ("virtio: Introduce started flag to VirtioDevice") Signed-off-by: Xie Yongji Reviewed-by: Greg Kurz --- hw/virtio/virtio.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 07f4a64b48..6508b2faad 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1214,8 +1214,7 @@ 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->start_on_kick = false; vdev->started = false; vdev->broken = false; vdev->guest_features = 0; @@ -2069,14 +2068,22 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val) return -EINVAL; } ret = virtio_set_features_nocheck(vdev, val); - if (!ret && virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { - /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ - int i; - for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { - if (vdev->vq[i].vring.num != 0) { - virtio_init_region_cache(vdev, i); + if (!ret) { + if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { + /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ + int i; + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + if (vdev->vq[i].vring.num != 0) { + virtio_init_region_cache(vdev, i); + } } } + + if (!vdev->started && + virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && + !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { + vdev->start_on_kick = true; + } } return ret; } @@ -2228,6 +2235,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } } + if (!vdev->started && + virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && + !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { + vdev->start_on_kick = true; + } + rcu_read_lock(); for (i = 0; i < num; i++) { if (vdev->vq[i].vring.desc) { @@ -2330,8 +2343,7 @@ 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->start_on_kick = false; vdev->started = false; vdev->device_id = device_id; vdev->status = 0; From patchwork Tue Jun 4 07:34:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10974343 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 28DAC912 for ; Tue, 4 Jun 2019 07:37:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16FF928764 for ; Tue, 4 Jun 2019 07:37:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ADD528784; Tue, 4 Jun 2019 07:37:02 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 AEDCF28764 for ; Tue, 4 Jun 2019 07:37:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:47441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY40D-0002UJ-2W for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Jun 2019 03:37:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY3yr-0001GU-CB for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY3yq-0003on-Cl for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:37 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:41771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hY3yq-0003ml-7F for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:36 -0400 Received: by mail-pf1-x42d.google.com with SMTP id q17so12154489pfq.8 for ; Tue, 04 Jun 2019 00:35:36 -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=mls9WkvxiCV9h+B5dVJf3CgBUNhcd0qcQOsSbC06TbQ=; b=rK/QmNWmn4e0FGHrbWzG7rRrSw+ccnnilCZesqL47xV8hz6FBF9/7pM0SQG/fBpoJi 37BWWRz4I3M1/LgAFfDLKbkaXeg8aZDwGs0xJb6W/r5f24810+29n+a3x3/L4t61dR1O ChnJ+/eDuIy2kjuWfK8SIG2ekOwBfno4KQBvS7POBNC/cUR4bYyOXcBNDC0xSO/wW9nA K6NoXIr4U38hynsSdtR9Yio3tuR/VqzFUfsAYPNRsk+t4jJp/v4W/qxvro5G5iHGcx38 GHtYQrr2n+dT7kKE2tDKwa0bstxQLkc6VAnuCKduExSYgWZ6K+hoJ3MYu7phQ+HJicHV HfpA== 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=mls9WkvxiCV9h+B5dVJf3CgBUNhcd0qcQOsSbC06TbQ=; b=j5c21KEDXamtgUQhFur9Qi4ZUs50o9dQlg1g9Cg6YTRXq4u27uyAiOcBBRZQHcuWF4 UWgSkk7IyA9V6EsWK0SM4V4/DUf4m+jPK0vcZPgWEc4BNlMVs9a5FoyZV3KIKS3KVc2R F/Qdt/Clv8v51EjpOHJ5EYyGw4zMoG8WuZfG8nhljS4ELi+31RtYZoRaHNazkSrENyqd W8iEYLlcPRU7X3aVyIqoD2rxxphBD4vI5Gnes+yakmYqVzz1cbsFVEZ6YWPoflXD4L66 vJXpA+gYNTfgf0I2zn8m3Fx403eYGuDpvjO/kyQrLB69TiCgloto3WGiwDJWI14Sw9Dw tzEA== X-Gm-Message-State: APjAAAVRSa89x6WE+nepmQSthAR8ZUn2VetGFpQMB03mzky0Ks7zW/Ow feCd2461DD83gTO+OL9mW1I= X-Google-Smtp-Source: APXvYqw09hqw8C9PVYcNr2Qy5x3GQV9m9N6aSqHjalp+TSPeh5bmwnOttTDqsL2o37dWAKZovNgNTg== X-Received: by 2002:a63:2706:: with SMTP id n6mr34631171pgn.238.1559633735217; Tue, 04 Jun 2019 00:35:35 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id v4sm21873288pff.45.2019.06.04.00.35.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 00:35:34 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org Date: Tue, 4 Jun 2019 15:34:56 +0800 Message-Id: <20190604073459.15651-3-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604073459.15651-1-xieyongji@baidu.com> References: <20190604073459.15651-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::42d Subject: [Qemu-devel] [PATCH v2 2/5] virtio: Set "start_on_kick" for legacy devices 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: Xie Yongji , dgilbert@redhat.com, qemu-devel@nongnu.org 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 Besides virtio 1.0 transitional devices, we should also set "start_on_kick" flag for legacy devices (virtio 0.9). Signed-off-by: Xie Yongji --- hw/virtio/virtio.c | 2 -- include/hw/virtio/virtio.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6508b2faad..6ec45d8f0a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2080,7 +2080,6 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val) } if (!vdev->started && - virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { vdev->start_on_kick = true; } @@ -2236,7 +2235,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } if (!vdev->started && - virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { vdev->start_on_kick = true; } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 27c0efc3d0..303242b3c2 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -106,7 +106,7 @@ struct VirtIODevice bool vm_running; bool broken; /* device in invalid state, needs reset */ bool started; - bool start_on_kick; /* virtio 1.0 transitional devices support that */ + bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ VMChangeStateEntry *vmstate; char *bus_name; uint8_t device_endian; From patchwork Tue Jun 4 07:34:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10974351 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 3A32E14C0 for ; Tue, 4 Jun 2019 07:39:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A06B2875E for ; Tue, 4 Jun 2019 07:39:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E23028767; Tue, 4 Jun 2019 07:39:29 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 C99EA2875E for ; Tue, 4 Jun 2019 07:39:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:47462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY42a-0004Qo-5N for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Jun 2019 03:39:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY3yu-0001IS-9o for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY3yt-00045Y-ER for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:40 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:34498) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hY3yt-0003y4-8E for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:39 -0400 Received: by mail-pg1-x541.google.com with SMTP id h2so6598602pgg.1 for ; Tue, 04 Jun 2019 00:35:39 -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=XTNMBKN2X1BkfbMgr70LpEg84K+wAte084VIv3k+D1I=; b=eRY7kWAUZ8kn8Qqjp0Boz4O+CM1SK9RoFVjsxl4IlCWcIT0XPsDCg0rY6hBO1QZy/k OIqwzZQf6tJWZMbD5I+3ssuCzh9vNOmWcUTn4fd3rWHjoVO5WoB8eDzNmCv2ihGZenAS +InfQzqHdphxpS46Ng40pLDGH6sbLF/WSUZOUbPJZbtyYq9PqlaXrNBrYHV2h1CtgafL wVsKZv8IMPB1R/GXXEBYfUede9bWmbXDfA8q59vLUfN3v79jJQxWEpVQ3DBNUx5CGMmw cOSd3Ymj9SFCz08t6KNiO+na2J8UNr2HGQW//fpGKxv2d/bQwV7vqB+aI5SI1tMsmY/p j3xA== 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=XTNMBKN2X1BkfbMgr70LpEg84K+wAte084VIv3k+D1I=; b=H6rZqgWMLOVMEi6lZL3vyaLnwaxir8V5wys7s0eiICP8kLA1LsdhKp60NEU26X/5ia CLtCTMPAQCABPlegR4r7Ucav+KJlQ1fFhVPR6dhCyPg8SYua/FgD49AippAAhpOLVguf coVEjJ9/Oz8+594VhFnz4uef4oSUKZX0DXD/xLl7dUHmxBYydKVvqZPpWuup7aIbtAFn AGTqdwE5olZViHSEwTvrYtFDVDfvjWZv/SlH2snkZAK7pJy3TeHzf16tqEpRV2NUDBnB UswIaisO23eNbggRR6gDffveeepMqjgFYnZkJbQvRv3bHnXv8qyXdZ4hUFkaFo4Nj1nG 88mw== X-Gm-Message-State: APjAAAU0P9aZ30crxFd4WF3G9R78su1dk2P0/79bDXwxDAmH6W+8hdbA 89GrXTvruAvNWXJvjoZ7s40= X-Google-Smtp-Source: APXvYqybLj7SVGuaVCTwtM8siXHKLSXVO1OnORlyJUFJmtcl5/6c0LO2gFkEgMz1OAfPGgsY7ltXcA== X-Received: by 2002:a17:90a:62c6:: with SMTP id k6mr33981582pjs.7.1559633738223; Tue, 04 Jun 2019 00:35:38 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id b16sm17232845pfd.12.2019.06.04.00.35.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 00:35:37 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org Date: Tue, 4 Jun 2019 15:34:57 +0800 Message-Id: <20190604073459.15651-4-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604073459.15651-1-xieyongji@baidu.com> References: <20190604073459.15651-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::541 Subject: [Qemu-devel] [PATCH v2 3/5] virtio: Make sure we get correct state of device on handle_aio_output() 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: Xie Yongji , dgilbert@redhat.com, qemu-devel@nongnu.org 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 We should set the flags: "start_on_kick" and "started" after we call the kick functions (handle_aio_output() and handle_output()). Signed-off-by: Xie Yongji --- hw/virtio/virtio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6ec45d8f0a..3dc2f8c223 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1575,11 +1575,11 @@ void virtio_queue_notify(VirtIODevice *vdev, int n) event_notifier_set(&vq->host_notifier); } else if (vq->handle_output) { vq->handle_output(vdev, vq); - } - if (unlikely(vdev->start_on_kick)) { - vdev->started = true; - vdev->start_on_kick = false; + if (unlikely(vdev->start_on_kick)) { + vdev->started = true; + vdev->start_on_kick = false; + } } } From patchwork Tue Jun 4 07:34:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10974345 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 6A70314C0 for ; Tue, 4 Jun 2019 07:37:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58E111FF41 for ; Tue, 4 Jun 2019 07:37:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A6C128779; Tue, 4 Jun 2019 07:37:10 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 F218E1FF41 for ; Tue, 4 Jun 2019 07:37:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:47444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY40L-0002bT-55 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Jun 2019 03:37:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY3yx-0001Kp-Nm for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY3yw-0004UC-Ov for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:43 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:44655) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hY3yw-0004Mh-Iw for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:42 -0400 Received: by mail-pg1-x544.google.com with SMTP id n2so9825624pgp.11 for ; Tue, 04 Jun 2019 00:35:42 -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=0LFWE+6YBWNetnIjT0/2k7O7uyx6xdsCiXpzjLGF0E8=; b=fKZQwn8dh+OPZQuQscBOTSRkc+9+3XY6psxqRvrxoGcuSBJEKvVNSrBxf+qckjp8vS 4d60AIbV8oOgRD/lBPZ/kVrSlX10ip3Yenowg6DXILhKRz3xm/D/kprXQt78ckxR8fyu Gpb+H5e1A31zZ2DBd62/WCwqzwjQ/M5o6VLE4tuvVw76rzU0oR/3qNJsypGkPkS7eV2z tPDLhn5mC9nvuQTIGMotOLHkmgIQeOLi7kUl34Y5+UK9ezRpOpR95pl4qj6JAbcANaiE 0s/l4h77kE0/YRXmToBMPZb6BgIkCA6HjptG+jSfcWXWSfwsDLIcLtMNZO3pUAFM4NPR 4EJQ== 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=0LFWE+6YBWNetnIjT0/2k7O7uyx6xdsCiXpzjLGF0E8=; b=PHcrCR96BYtwuQr9HWl+3HC9gSFbnMDog6NNIblG194SZ+oKRZmTyyjupFXvRmNQ/d SaDeKSbEfN9W7EHrY6+38WtWXpYBVoiP95reX2hglr0yUcLR4QBxTvczl9qx0+8+Qm8H +cQDpqNOi2gr5qGs44eJbXVCo/dzJ1NVu5b5ouSbSU1UAzxD/i4a2rvNcWpxNptucAMn I/cN9VYzoR052dJ4QwKwdr1PoD/D8/hKigQ1+8323ZVfN+hx0eBrDqWN4VLtxO/pnGYS EzNnBx+mX/aEvk+ps5mYMXDDyOF0FcSyRyEi6406z8KxE0M0rn28acZXJJBrSG4VEt71 oz9w== X-Gm-Message-State: APjAAAVnZ06+wArZxR7TEVwhrRtQ79mZojqBNBQYlAHH6+jcRCZrxrx8 sECY/hQU1fuyO4fJWlw4YTMdurdT X-Google-Smtp-Source: APXvYqyth0u6KIGmJPcmLqnzefKa4kPF5OCC+7EHSY2dFyQUU+p23NQa+LC+1w6yYeOBDTMO1FUHTg== X-Received: by 2002:a17:90a:7f02:: with SMTP id k2mr35414091pjl.78.1559633741441; Tue, 04 Jun 2019 00:35:41 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id m8sm26428531pff.137.2019.06.04.00.35.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 00:35:41 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org Date: Tue, 4 Jun 2019 15:34:58 +0800 Message-Id: <20190604073459.15651-5-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604073459.15651-1-xieyongji@baidu.com> References: <20190604073459.15651-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::544 Subject: [Qemu-devel] [PATCH v2 4/5] virtio: Don't change "started" flag on virtio_vmstate_change() 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: Xie Yongji , dgilbert@redhat.com, qemu-devel@nongnu.org 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 We will call virtio_set_status() on virtio_vmstate_change(). The "started" flag should not be changed in this case. Otherwise, we may get an incorrect value when we set "started" flag but not set DRIVER_OK in source VM. Signed-off-by: Xie Yongji --- hw/virtio/virtio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3dc2f8c223..3960619bd4 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1162,9 +1162,13 @@ 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 ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) != + (val & VIRTIO_CONFIG_S_DRIVER_OK)) { + 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) { From patchwork Tue Jun 4 07:34:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10974347 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 322BB14C0 for ; Tue, 4 Jun 2019 07:37:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E5321FF41 for ; Tue, 4 Jun 2019 07:37:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1234828779; Tue, 4 Jun 2019 07:37:17 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 7B7371FF41 for ; Tue, 4 Jun 2019 07:37:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:47446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY40R-0002hQ-HJ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Jun 2019 03:37:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY3z1-0001Ns-ES for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY3z0-0004wQ-3V for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:47 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:45280) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hY3yz-0004tR-TY for qemu-devel@nongnu.org; Tue, 04 Jun 2019 03:35:46 -0400 Received: by mail-pg1-x541.google.com with SMTP id w34so9815477pga.12 for ; Tue, 04 Jun 2019 00:35:45 -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=BlmwWQSrvfnPLK3snMGwGG+KcVuIss3R/7Aben6MrQw=; b=VJ8WpLxq43rtFJQ9KMSJSFwSHLmfhxYJ4phcnhQLO6VuOcNa81TtNGRMs0fdFpCz4S yMfq4G9kHxo9Ec2eTESm5PTfnDoK6OUxen1oNS73U0n91eYHkJ0QXHj52gsZqrpzfahN /RmFv5nfN+i+cyKFfF1bJbAqD50f+QSF1inhSLMz5PjFFM4VrqQkhbxh3drXMEiGTQ2Q tXu4b6yN4NGx+yLNF3qfN7ATT/xtHSzHTp08k9D2e2PiXZBvteBuZXDk9NA0eByrlB03 Usi2BvVjXKSxhtbwixUXfgZhz8wOAQyVXYHUYT01uiMz1HVWDIaa01cdcmmd2+CeVYuw 7S+Q== 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=BlmwWQSrvfnPLK3snMGwGG+KcVuIss3R/7Aben6MrQw=; b=Fm+KzA9QW4PNGmNlfpofHLQyGEwLDm6ue3MgTY/vJENnfGCmIOQqveHGCvu3JWTdJX mvcq6808w3mxT1RxVlfV7jBunKn+o7Eudvrm/sbPCJNNtVwnxdETy/qyGg6hWOIUINSA uUOww/PQZ+8MsO2LvcfX7AjfiFsUsEnvIelgl+q1u1NK4vUdksRuHRbGKd1QrQDa96ol 8kmGd9dQmHLExZX90+H3cma8oyC157PcLabkIOOFu0b+0bcqlEXnyKSlajVA6hSqaikL 8/YxB4PPFG6LNw5plmzQgD7s5d5BIU1wH5tC0+qE7MNg/HnVbkTbNg+B7rNcvKz8EAr6 cm3Q== X-Gm-Message-State: APjAAAXcy6d1Hy0UIz3fhD9jYTTxVfi9ZszkNF1zUIVdFgQYAm3zGRUe CpoY+CjOxQpa4XCB7BQEpIQqgqm+ X-Google-Smtp-Source: APXvYqyx2Cn2oWru565C85iqVbPdB5kTgKZHSX0YYGuquvXmTkPAhf81/XoH66oZlUvYcmoIecANXA== X-Received: by 2002:a17:90a:6348:: with SMTP id v8mr35026298pjs.34.1559633744907; Tue, 04 Jun 2019 00:35:44 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id m20sm995215pjn.16.2019.06.04.00.35.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 00:35:44 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org Date: Tue, 4 Jun 2019 15:34:59 +0800 Message-Id: <20190604073459.15651-6-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604073459.15651-1-xieyongji@baidu.com> References: <20190604073459.15651-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::541 Subject: [Qemu-devel] [PATCH v2 5/5] virtio: add "use-started" property 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: Xie Yongji , dgilbert@redhat.com, qemu-devel@nongnu.org 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 In order to avoid migration issues, we introduce a "use-started" property to the base virtio device to indicate whether use "started" flag or not. This property will be true by default and set to false when machine type <= 4.0.1. Signed-off-by: Xie Yongji --- hw/block/vhost-user-blk.c | 4 ++-- hw/core/machine.c | 4 +++- hw/virtio/virtio.c | 21 ++++++++------------- include/hw/virtio/virtio.h | 21 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 9cb61336a6..85bc4017e7 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -191,7 +191,7 @@ static void vhost_user_blk_stop(VirtIODevice *vdev) static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserBlk *s = VHOST_USER_BLK(vdev); - bool should_start = vdev->started; + bool should_start = virtio_device_started(vdev, status); int ret; if (!vdev->vm_running) { @@ -317,7 +317,7 @@ static int vhost_user_blk_connect(DeviceState *dev) } /* restore vhost state */ - if (vdev->started) { + if (virtio_device_started(vdev, vdev->status)) { ret = vhost_user_blk_start(vdev); if (ret < 0) { error_report("vhost-user-blk: vhost start failed: %s", diff --git a/hw/core/machine.c b/hw/core/machine.c index f1a0f45f9c..133c113ebf 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -24,7 +24,9 @@ #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" -GlobalProperty hw_compat_4_0_1[] = {}; +GlobalProperty hw_compat_4_0_1[] = { + { "virtio-device", "use-started", "false" }, +}; const size_t hw_compat_4_0_1_len = G_N_ELEMENTS(hw_compat_4_0_1); GlobalProperty hw_compat_4_0[] = {}; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3960619bd4..9af2e339af 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1165,10 +1165,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val) if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) != (val & VIRTIO_CONFIG_S_DRIVER_OK)) { - vdev->started = val & VIRTIO_CONFIG_S_DRIVER_OK; - if (unlikely(vdev->start_on_kick && vdev->started)) { - vdev->start_on_kick = false; - } + virtio_set_started(vdev, val & VIRTIO_CONFIG_S_DRIVER_OK); } if (k->set_status) { @@ -1539,8 +1536,7 @@ static bool virtio_queue_notify_aio_vq(VirtQueue *vq) ret = vq->handle_aio_output(vdev, vq); if (unlikely(vdev->start_on_kick)) { - vdev->started = true; - vdev->start_on_kick = false; + virtio_set_started(vdev, true); } } @@ -1560,8 +1556,7 @@ static void virtio_queue_notify_vq(VirtQueue *vq) vq->handle_output(vdev, vq); if (unlikely(vdev->start_on_kick)) { - vdev->started = true; - vdev->start_on_kick = false; + virtio_set_started(vdev, true); } } } @@ -1581,8 +1576,7 @@ void virtio_queue_notify(VirtIODevice *vdev, int n) vq->handle_output(vdev, vq); if (unlikely(vdev->start_on_kick)) { - vdev->started = true; - vdev->start_on_kick = false; + virtio_set_started(vdev, true); } } } @@ -2083,7 +2077,7 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val) } } - if (!vdev->started && + if (!virtio_device_started(vdev, vdev->status) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { vdev->start_on_kick = true; } @@ -2238,7 +2232,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } } - if (!vdev->started && + if (!virtio_device_started(vdev, vdev->status) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { vdev->start_on_kick = true; } @@ -2306,7 +2300,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state) VirtIODevice *vdev = opaque; BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - bool backend_run = running && vdev->started; + bool backend_run = running && virtio_device_started(vdev, vdev->status); vdev->vm_running = running; if (backend_run) { @@ -2683,6 +2677,7 @@ static void virtio_device_instance_finalize(Object *obj) static Property virtio_properties[] = { DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice, host_features), + DEFINE_PROP_BOOL("use-started", VirtIODevice, use_started, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 303242b3c2..b189788cb2 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -105,6 +105,7 @@ struct VirtIODevice uint16_t device_id; bool vm_running; bool broken; /* device in invalid state, needs reset */ + bool use_started; bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ VMChangeStateEntry *vmstate; @@ -351,4 +352,24 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev) /* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; } + +static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) +{ + if (vdev->use_started) { + return vdev->started; + } + + return status & VIRTIO_CONFIG_S_DRIVER_OK; +} + +static inline void virtio_set_started(VirtIODevice *vdev, bool started) +{ + if (started) { + vdev->start_on_kick = false; + } + + if (vdev->use_started) { + vdev->started = started; + } +} #endif