From patchwork Wed May 29 07:09:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10966219 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 597C015E6 for ; Wed, 29 May 2019 07:22:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44A0928767 for ; Wed, 29 May 2019 07:22:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 387C828795; Wed, 29 May 2019 07:22:12 +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 D62DF28767 for ; Wed, 29 May 2019 07:22:11 +0000 (UTC) Received: from localhost ([127.0.0.1]:48869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsuZ-0001E5-4U for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 May 2019 03:22:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsjl-0000ae-JK for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVsjj-0006R3-Ke for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:01 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:46977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVsjh-0006PA-KD for qemu-devel@nongnu.org; Wed, 29 May 2019 03:10:59 -0400 Received: by mail-pg1-x544.google.com with SMTP id v9so782472pgr.13 for ; Wed, 29 May 2019 00:10:56 -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=GjcX2eS1qWnd/pfqLo8M97WyTdrvK7+rz7aAhVuI32E=; b=fqa8ii6B3pDGwtNzmAtAtIZ+g03DBeYwNeakYkbtOh4SavsZuY8XV8yVgsaggskbTJ 2GF7SfAeUPJbl8xqUKBrlmwVSTfyqPuCouZi4QN2v3ZseDEzTk2drpHAGfOFi7t7z08X 7IJSdGAE43tOzDHRoXPoyvsiPQMIa7cP4Eviy4NZoVaCfjomfIOIz+E0ILiUEi4OV6RV nOqW4PuG2UxWWQzSjz+fS0OBxnkGDLvKZaKW031YmIfvcYbIrX1BXAa689BoJi07uuiZ lpQDbBVtcfZl3qXQUV0tWQiPyTVj3wPj6UFKSuHyOUOEMPQYMW9pcv1lcv32vL2n7gem CxFQ== 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=GjcX2eS1qWnd/pfqLo8M97WyTdrvK7+rz7aAhVuI32E=; b=OB34nfl/Y6Z3XXR7hDCkJq40S/X4bFpWEY6x/UO+RgJXqclLQQxi34QOJd+d5gSf9G 8aNYAGP6APMPEBRFjQ1w76nbkTvaz6gHI1YFC9jDPCBnkj8RYNAtmufqst80dx1cQ9d2 H1cA3vQM3VvHKowD8Z7qGVBRrI2DJuleut/Tm7HnLGv70Qt8WqOCTPgVP0TrR9ID8UWN /ysKiAOsBkOIo31CRtTWhDMEIWjmSqYH1DhRCILktQFfZMu/5XOZ5VHBFTGnDE6Eoenb 0kwShsLH4RPiCbTAK1enmL8+LnlX6PLM4AmYzNOuBHRLBqQvnpL7EhiIuFRlPm0us4Ew nXig== X-Gm-Message-State: APjAAAXjglZLD3vP9Yj5jHgdmjDM56t7qSd2p51Rr56v+R1sCBz53LvV /YNv7C92hxea8NkCMRGfOVc= X-Google-Smtp-Source: APXvYqzMQrN7WpQ4HgD5jGm7YyQEsSHQpyTnP7/o8i5oQ+8l8N902SqK6EDKwHcwgROqeZMlJ+vnfw== X-Received: by 2002:a17:90a:ac03:: with SMTP id o3mr10472629pjq.114.1559113855429; Wed, 29 May 2019 00:10:55 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id r4sm4619471pjd.28.2019.05.29.00.10.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 00:10:55 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org, dgilbert@redhat.com Date: Wed, 29 May 2019 15:09:51 +0800 Message-Id: <20190529070955.25565-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529070955.25565-1-xieyongji@baidu.com> References: <20190529070955.25565-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 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 , 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. Signed-off-by: Xie Yongji Reviewed-by: Greg Kurz --- hw/virtio/virtio.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 4805727b53..fc8fca81ad 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,21 @@ 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 (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; } @@ -2331,8 +2337,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 Wed May 29 07:09:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10966279 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 52699912 for ; Wed, 29 May 2019 07:38:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4174521FAC for ; Wed, 29 May 2019 07:38:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35AF6287C5; Wed, 29 May 2019 07:38: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 D65E121FAC for ; Wed, 29 May 2019 07:38:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:49135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVtA1-0006gM-5L for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 May 2019 03:38:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsjm-0000bX-LG for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVsjl-0006SC-PC for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:02 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:34094) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVsjl-0006Ql-KK for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:01 -0400 Received: by mail-pf1-x442.google.com with SMTP id n19so1028104pfa.1 for ; Wed, 29 May 2019 00:10:59 -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=KCQFP+ZFlVwkBiduDICRQjKoGn++Fs0jXbPk/B+kRlo=; b=pVXhUfN13yEkPRGYJVvtc3bqZOUVWl+Ggu18I5ldY/H0W8rkQ74YJfddMKVwNC6eQm sAfjiNP+kGUSp2EpQ0NEaeF2jFkFt0u+Ei9huGtoZrwcgxngVhWO6Tpx/5JGSGQphZZL qrteWcVdPGSxcsJ4u9LSeHmmsxOmsR3Gp05jVcrRvhMATlcGRMU5l0EbIkTZ2DL8urpE cYFsIz5ysJEAqg+U7NkujALgGSQYq31JLc5Tceh2rgJVEgRFOP5ZJ+y6LKr53o/wqJKA lSm/Nsj5aqhAPsPd4JeyvQrX+CNCJgde/grMJ0jRfcT04qGg7vupvo6HRxACUq89mTfh 3INw== 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=KCQFP+ZFlVwkBiduDICRQjKoGn++Fs0jXbPk/B+kRlo=; b=Pg843tk3XTET5I/gPk+2hUyZp6KEacUDUMmSN5+nkxk4QqBROVpwwY0h9ez/HtZho5 Kreu4QbfHtnRBrHfC9Wl3b21aH4hsDv+mUcdJ/EdF5KrY9JzKfLPSQ6vvkHL85KpiPzF nfXO/YkIU6XgusOPoQnavjxWvHxxFUqm6m4FVe4UkgtxI8s5YA+Z5KtJV6GgGexYtl97 Xr6QL3FhT+eGKn53AckJ2A7JrjCypkSuEO7jJ1HNkI087YN0KH3Sf1UMNoZgLHl4haF9 WdsoinNdGew7E5VKGQrDQW+xB07Pvkf4m7VZwR0YWW6h0y0s3fEswkZxhmFmp1yc4ecp VuVg== X-Gm-Message-State: APjAAAVTwcxLQ5XqnJOO2YoUiAyhKehZND6srRJYul5vQI1L+BKWHNA9 Vktg1/sWxdta1UFZxyavwIQ= X-Google-Smtp-Source: APXvYqyyhGSdqPEvv1BlR4DJGOhel4jLkeN9sbYM++/muzgCF4kRzJDLYhIt6usA/7IMGd86xDA2JA== X-Received: by 2002:a17:90a:cb0a:: with SMTP id z10mr10432703pjt.101.1559113858348; Wed, 29 May 2019 00:10:58 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id k6sm16970656pfi.86.2019.05.29.00.10.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 00:10:58 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org, dgilbert@redhat.com Date: Wed, 29 May 2019 15:09:52 +0800 Message-Id: <20190529070955.25565-3-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529070955.25565-1-xieyongji@baidu.com> References: <20190529070955.25565-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 2/5] virtio: Migrate the "start_on_kick" flag 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 , 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 migrate the "start_on_kick" flag so that we would not miss starting device on kicking at startup after migration. Signed-off-by: Xie Yongji --- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index fc8fca81ad..4d4ff67791 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque) return vdev->started; } +static bool virtio_start_on_kick_needed(void *opaque) +{ + VirtIODevice *vdev = opaque; + + return vdev->start_on_kick; +} + static const VMStateDescription vmstate_virtqueue = { .name = "virtqueue_state", .version_id = 1, @@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name = "virtio/start_on_kick", + .version_id = 1, + .minimum_version_id = 1, + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField[]) { + VMSTATE_BOOL(start_on_kick, VirtIODevice), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio = { .name = "virtio", .version_id = 1, @@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } }; From patchwork Wed May 29 07:09:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10966237 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 BF90976 for ; Wed, 29 May 2019 07:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A576228660 for ; Wed, 29 May 2019 07:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98E3A28646; Wed, 29 May 2019 07:25:30 +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 50F9328646 for ; Wed, 29 May 2019 07:25:30 +0000 (UTC) Received: from localhost ([127.0.0.1]:48943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsxl-0004F3-IF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 May 2019 03:25:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsjn-0000c8-A5 for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVsjm-0006SS-9J for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:03 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:33772) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVsjm-0006Rm-4Z for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:02 -0400 Received: by mail-pl1-x643.google.com with SMTP id g21so673082plq.0 for ; Wed, 29 May 2019 00:11:02 -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=U0Mx+YreHQRLB91RmN0bCzlScT5GPJ9gYEH0yygk22I=; b=Yh8u7qAa+gm1IgAdJvgF+dQVqowHj+EIH/1ZcE6ssV/lKulMZ0mWCuoGD1iX/3F1OQ w1uxWPtvrPIC1HRk6yidkJyJk+xK3NPVQGar2qqQ8GqYOPDnm+Xuvo/OO/ESmwObCwqB ksLvdUD5bx213A2uy0NSJ1R0EMB223Dultb2IKtks97LNPsOVp/aGFEZl/zb0rWcHqC+ ybIpuVpbxmODClIGSBVjXTX+nvdVEjg8Q//EVlPVwmnccdkBGCDbw+6yKPgcK9riuYG1 RdjM9J9axFDqEmM6sJXuz15FNU5ZSewlWvqrthABshy0x01lvlKOS/usC3ayveg2m5ni Ir3Q== 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=U0Mx+YreHQRLB91RmN0bCzlScT5GPJ9gYEH0yygk22I=; b=HKUNHvlHOWfg1C8N6eRcK/h5uSRISTRyCzHHJxZwNHtPpfMnsQ+7ZqZrXWhJI6b0o0 B0+HZhsK9SDsU2mcYHxcBy0YJnztujzjsMoeURtcPL4BBPeEZhDwkPEPe9bODkf4O7VZ Dqf3cmtP9HS0oB3F5qIK6YfErKr9DpT1laSE5YDSWZ9QQLn9EM7v5Yyq/dZ261AVVrOA oBkskwGuBvXvHLp2kwqVN8eUdu/I1NycNAGZZEzWTG5xrejsapa5tgovcu1OOI9pdftB khhUo3AddxVc+/B7iF2sEoncHudGqQJbTYwxOdJMLsHU3rlQTjZB1Zgdycw+qoknzxYm Nz3g== X-Gm-Message-State: APjAAAXI7nG/4d4MetR9zDwojSmAiQcBwSYkUAbyrC+Q23VqEW09CpdY WGtuIkADA5dKCnANLWABG9G6DQQW X-Google-Smtp-Source: APXvYqzKOGBL90ccywgTotQmecQj/JHDq3LGi8Lm9hVJuY0jvjyQhbz1wxtW1n5kCc41CQHHLcto2g== X-Received: by 2002:a17:902:2947:: with SMTP id g65mr118403751plb.115.1559113861345; Wed, 29 May 2019 00:11:01 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id n12sm15493682pgq.54.2019.05.29.00.11.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 00:11:00 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org, dgilbert@redhat.com Date: Wed, 29 May 2019 15:09:53 +0800 Message-Id: <20190529070955.25565-4-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529070955.25565-1-xieyongji@baidu.com> References: <20190529070955.25565-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::643 Subject: [Qemu-devel] [PATCH 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 , 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 4d4ff67791..8a81374492 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 Wed May 29 07:09:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10966289 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 DC77C912 for ; Wed, 29 May 2019 07:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDDC91FFFE for ; Wed, 29 May 2019 07:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1D3328775; Wed, 29 May 2019 07:40: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=-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 71C211FFFE for ; Wed, 29 May 2019 07:40:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:49191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVtCR-0000NT-HC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 May 2019 03:40:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsjq-0000ii-9y for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVsjp-0006UD-F6 for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:06 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVsjp-0006Tw-AE for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:05 -0400 Received: by mail-pg1-x541.google.com with SMTP id n2so784667pgp.11 for ; Wed, 29 May 2019 00:11:05 -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=03Gb86KPthOkR7l6zYdtWIDlcvr0+sRNjxvLK/QpGew=; b=hQWpyhYlwSHOhN/SueOAIqFdWmoyD/uiyvQeDhsrU9lwzfY0LR9HcTKxRdk91JOfPu ekvlEx5fk333DQ4OwlJepksehspXut72/mttjMKwOvMVKdtD5hmlAue7v6Rhw5mpat78 JDZxo9vFaFDOSqBQPeseIjQhpG3hcLSJreCa5mZcmLURywxX6m8O1B63PPA+WPNDZW1U yePDGdXd3svxLJR99sPo/qRsyz0aXbxvrVaHSuXA+j7LtJBPNV0glwx2M8M0UQJ/ctKD dzMSy0JVQE/v3w+afuowpVlDtfWTMydjnoWN2fbcSZZ0NS1cQW+X8edRz/GyByqcUWqd 007g== 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=03Gb86KPthOkR7l6zYdtWIDlcvr0+sRNjxvLK/QpGew=; b=CQCgg9QEtql3JppTt+9XYpJG6JG4oS+Tqsrkm/VDOX7fNrs6TBS/SVxrMJJ4qj135t nfMhHEsoPII/7zx15kFjr38ZsXeNDFSAacYHIJKHuBapsvY2wiU5WvOjv896vC/172OI q/3jjN54OeD/iWFbXK3wYMYqO+fc5kV9UzslVtR58dTwZXha/Xc+buvvGs7n3TZJ7Vm0 /6Vw1CGtyq/yEXZ3s3NqXQN44vkL6K3v5zYcIADV5DL4sKobP2IFVccusqVF85wS3/pV mbHS70pOlr6YN7KyXOv9CbXTIIxEbb1ZjHdMWZxojhHMtqkzyWBYAhcCLTfmyLC7Jo0Y f9iw== X-Gm-Message-State: APjAAAUFwJjzlLmdj8ee56m8q3zGlpGfisHfXVt4iX7uGiPTMQdbvuyU xuwH5QrMJczHw9wlCS2xK7M= X-Google-Smtp-Source: APXvYqx2m0DQRuE0UpGlMyawvNWbiJaTsYKzI5K/s3kFSlKdrsMqG1z59naEXToy/x5J0snGiNVM9Q== X-Received: by 2002:a63:2325:: with SMTP id j37mr135339747pgj.137.1559113864504; Wed, 29 May 2019 00:11:04 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id c127sm17387040pfb.107.2019.05.29.00.11.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 00:11:04 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org, dgilbert@redhat.com Date: Wed, 29 May 2019 15:09:54 +0800 Message-Id: <20190529070955.25565-5-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529070955.25565-1-xieyongji@baidu.com> References: <20190529070955.25565-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 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 , 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 8a81374492..9e17293d46 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 Wed May 29 07:09: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: 10966249 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 67EA31398 for ; Wed, 29 May 2019 07:28:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5092228767 for ; Wed, 29 May 2019 07:28:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43FEB28795; Wed, 29 May 2019 07:28:13 +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 B856B28767 for ; Wed, 29 May 2019 07:28:12 +0000 (UTC) Received: from localhost ([127.0.0.1]:48967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVt0O-0006vV-1o for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 May 2019 03:28:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsjt-0000lv-Rg for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVsjs-0006Vh-Mw for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:09 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVsjs-0006VU-HT for qemu-devel@nongnu.org; Wed, 29 May 2019 03:11:08 -0400 Received: by mail-pf1-x443.google.com with SMTP id a23so1020499pff.4 for ; Wed, 29 May 2019 00:11:08 -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=wRsGG+CGI58wbB7Mu7nQkCFNg2G6+zgNOiTS5HlNUlA=; b=oS4L5qKNQS+ZvLE5YFnPSgWq1B9nlIahoTrgCkNKl6aLEN+fsxF+wztid3inPjecMl jZ3DR2FKtD0nqnTFX4Kt7kgbBaawIkJ7sD3N2tYneHvotojaZBSf9H0dghyVDyDAbDbE +JKYlHWGqLAvMStwxRMSdG73kNr9F91H/hw9LIpS7EjvHcL0j5OPw7jRZFHR/v/iRqjz D8FBMbWGtKUXEjJqCxekpti3CxoplQOOomKga0tytLaAeqUkjs5e12sOEBoBU0/7vTaR CgNDaooWZlayngwSZRuDouvaFzEFZFVn9CzAFuPKGObKPV2b0Q76rSjG+b604BvoK1Gv DrWg== 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=wRsGG+CGI58wbB7Mu7nQkCFNg2G6+zgNOiTS5HlNUlA=; b=RTVxFr8UXGU+kAoHOYOkWEDhFjGJG60S7P2kFGWY3tpwPWrhM3cjUaB6dVacPfyr9H jztXIVf85/T+j5LEXg6lMe4X4gTUxjrFeWd/OeLd/zLJYEtiCQvQCotpULn38/J+FrtG ADUozO3w3vYELUK/334/nYT/V9MX8FxQPNmaaJ0DqFD/xySyWLQS8zcYOaWawuBTgfUq lZPSRzijeH3UGVRiZ2DxwNSr3DDQUEr0P5PhjW04JwJff3AIdNtrJzAJSWcJd04ZxtJV jQuuqOe6CzCRp2/8kXM2XAqRTrClBI5adF1Bbz8fMU3RwC4Vfs2rSfELhzvGQ8fZMMCt M0Bw== X-Gm-Message-State: APjAAAWlGT93Rk5+Q8F8/ezfcgzretKYtEX63jNmNZEK65X0xC44bbHO ubNs3o1jP7XDfTIRF+r/F5Q= X-Google-Smtp-Source: APXvYqxkMNjESQg57MaxRwMsrqBHV13dx6I98in6HvbqVaR4y7VLSFJYCnMk5lZ238uXg/sd7/Ebsg== X-Received: by 2002:a63:8449:: with SMTP id k70mr19826829pgd.208.1559113867619; Wed, 29 May 2019 00:11:07 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id 5sm16693672pfh.109.2019.05.29.00.11.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 00:11:07 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, groug@kaod.org, dgilbert@redhat.com Date: Wed, 29 May 2019 15:09:55 +0800 Message-Id: <20190529070955.25565-6-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529070955.25565-1-xieyongji@baidu.com> References: <20190529070955.25565-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::443 Subject: [Qemu-devel] [PATCH 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 , 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 "started" and "start_on_kick" flag could be used. This property will be true by default and set to false when machine type <= 4.0. Suggested-by: Greg Kurz Signed-off-by: Xie Yongji --- hw/block/vhost-user-blk.c | 8 ++++++-- hw/core/machine.c | 4 +++- hw/virtio/virtio.c | 7 ++++--- include/hw/virtio/virtio.h | 10 ++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 9cb61336a6..520c5d3d4b 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -191,9 +191,13 @@ 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 = status & VIRTIO_CONFIG_S_DRIVER_OK; int ret; + if (virtio_device_started(vdev)) { + should_start = true; + } + if (!vdev->vm_running) { should_start = false; } @@ -317,7 +321,7 @@ static int vhost_user_blk_connect(DeviceState *dev) } /* restore vhost state */ - if (vdev->started) { + if (virtio_device_started(vdev)) { 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 934c1bcceb..1730d28c1b 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[] = {}; +GlobalProperty hw_compat_4_0[] = { + { "virtio-device", "use-started", "false" }, +}; const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); GlobalProperty hw_compat_3_1[] = { diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9e17293d46..4c05a9efe3 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1803,14 +1803,14 @@ static bool virtio_started_needed(void *opaque) { VirtIODevice *vdev = opaque; - return vdev->started; + return vdev->started && vdev->use_started; } static bool virtio_start_on_kick_needed(void *opaque) { VirtIODevice *vdev = opaque; - return vdev->start_on_kick; + return vdev->start_on_kick && vdev->use_started; } static const VMStateDescription vmstate_virtqueue = { @@ -2320,7 +2320,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->vm_running = running; if (backend_run) { @@ -2698,6 +2698,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 27c0efc3d0..ba4dbd7480 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; /* virtio 1.0 transitional devices support that */ VMChangeStateEntry *vmstate; @@ -351,4 +352,13 @@ 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) +{ + if (vdev->use_started) { + return vdev->started; + } + + return vdev->status & VIRTIO_CONFIG_S_DRIVER_OK; +} #endif