From patchwork Mon Dec 5 09:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631047 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2424188pvb; Mon, 5 Dec 2022 02:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ck3t3Tz9ocKw27q74vZIGr+C5zodHUABL6vWStw1UO6iQtaUs9MSugLbni7rRoihNmyqN X-Received: by 2002:a37:b1c5:0:b0:6fb:11d1:dab2 with SMTP id a188-20020a37b1c5000000b006fb11d1dab2mr73559568qkf.75.1670234407920; Mon, 05 Dec 2022 02:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234407; cv=none; d=google.com; s=arc-20160816; b=w0SKSPSTL1oU0k1/cf9asUzsGzjOBiDB652MQuKPaWfWx6dIHhz5k4rlliJwWwU7io +2IG3cgghiUadXdP6LOzVlf+LXXultx1UwUEkAm399Pv8V1s+n4pXraxhZwXhy9GJVc1 n5xUKAiLMb2b+AsQVgxu0rKY3c3KTEc5Vo6cinWqGgTzOF0uUJMDtPNbKzP0Rth3K14R LRiMTzpGQ7d4aEnPJ0QX21kZHMFRtiq11riHnISmoDjYLS+rsUPDBNQ9+ta/jtydE0Ig 5W9F71iZwAlWKNto6PgmFVvjzq5FQAhKURXSydxWPj/nYmCCGNa5xciiqTx+jeCva9lj 0enA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=No1rFWDOGgcpCRxA+eKIpRsQyOQa34f3lMNtg8s8nvw=; b=vBcKaO0NaQgkb8A8c8Bu+sVs+TBbfZBU98PB0wh3R7SJYk0zvQjgAY1Fq65F2dZAVb TFXlJiA6OroKR582OThSWcpmZkderD/G2A6s5VCXEJYbr9b79WZ2dwehmAQKWkwgkFug q4gMUOJs6ajIsMjVU5WKVtznxqB/XmhjO9DdP43XqcBJ5gxDaioGONixQ+ffUjCJLWE7 72eHeuKCNZ9xi/7XE7sVbU4JJdlND5Vx6s0rvRgCCJ7+sDBUNVgJxbeFt5qwlJnJKEmz 4MVhEFHA72Q1tRAC6BbUtxeGY02a6xktf5MRnCvK/qEKvCax5WSMOIbXNIMvXss4BrQF UE/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KNalBSSE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fy10-20020a05622a5a0a00b0039cdd7adeddsi7394490qtb.616.2022.12.05.02.00.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:00:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KNalBSSE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Bg-0002IJ-BW; Mon, 05 Dec 2022 04:55:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BX-000228-7L for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BV-0006xs-MU for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=No1rFWDOGgcpCRxA+eKIpRsQyOQa34f3lMNtg8s8nvw=; b=KNalBSSEcivUUWmLJwjieYOoUjAVRSoK8iMh4IuW1zO+iHle/hZZDnWlKppuNxSjOQllxW KkrL4E7Jvui14J7IXCTWnGgIXKM2IbNaZnIDou8Muhbf3dHWp6kr9wniPNJuQMDC5iRT+W aOB33nZB+rdi6+ZdswJAqJe/KXTCgQw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-LvnWEbokMBiiSiQFcldH3Q-1; Mon, 05 Dec 2022 04:54:46 -0500 X-MC-Unique: LvnWEbokMBiiSiQFcldH3Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64306101A56C; Mon, 5 Dec 2022 09:54:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CCD52166B29; Mon, 5 Dec 2022 09:54:38 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz Subject: [PATCH v2 16/51] include/hw: VM state takes precedence in virtio_device_should_start Date: Mon, 5 Dec 2022 10:51:53 +0100 Message-Id: <20221205095228.1314-17-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée The VM status should always preempt the device status for these checks. This ensures the device is in the correct state when we suspend the VM prior to migrations. This restores the checks to the order they where in before the refactoring moved things around. While we are at it lets improve our documentation of the various fields involved and document the two functions. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_started) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Bennée Tested-by: Christian Borntraeger Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-6-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index a973811cbf..acfd4df125 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -116,6 +116,13 @@ struct VirtIODevice bool broken; /* device in invalid state, needs reset */ bool use_disabled_flag; /* allow use of 'disable' flag when needed */ bool disabled; /* device in temporarily disabled state */ + /** + * @use_started: true if the @started flag should be used to check the + * current state of the VirtIO device. Otherwise status bits + * should be checked for a current status of the device. + * @use_started is only set via QMP and defaults to true for all + * modern machines (since 4.1). + */ bool use_started; bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ @@ -391,6 +398,16 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev) return false; } +/** + * virtio_device_started() - check if device started + * @vdev - the VirtIO device + * @status - the devices status bits + * + * Check if the device is started. For most modern machines this is + * tracked via the @vdev->started field (to support migration), + * otherwise we check for the final negotiated status bit that + * indicates everything is ready. + */ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) { if (vdev->use_started) { @@ -411,15 +428,11 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) */ static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t status) { - if (vdev->use_started) { - return vdev->started; - } - if (!vdev->vm_running) { return false; } - return status & VIRTIO_CONFIG_S_DRIVER_OK; + return virtio_device_started(vdev, status); } static inline void virtio_set_started(VirtIODevice *vdev, bool started)