From patchwork Wed Nov 30 11:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 629469 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp792490pvb; Wed, 30 Nov 2022 03:25:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf70IgRTqWexGSvbV2/Hhytj7eejQiIVmxViDIPUaaRrx09U9vTy5+qYgdFrgWe9UNHyU+aW X-Received: by 2002:a37:c0a:0:b0:6fc:7802:9cc2 with SMTP id 10-20020a370c0a000000b006fc78029cc2mr12764928qkm.723.1669807516970; Wed, 30 Nov 2022 03:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669807516; cv=none; d=google.com; s=arc-20160816; b=OjPleVKHOFaU1k/oSh1+qPDoIm7wxwbHABgx7lTFrFFrqFHsykrwC1Vd36Yado37k8 8Tv0xdjhxuKXriBXGRppvi/mnSC0NH7ICVqHYZCJ6NpztsNhLv0LtBuD6zXMGX5bcDLV ekDLvF0FwjKcYUXJYOFi2rlX2Q4OPMtjFb8JcJO1vN56fV3Q3nmT99B9Odf5vCq5bpx0 +ISHeSO1/7cKQExWReuNr7vLs+2P2kw4RCJwx7mckuiBU69gJ3qRt5ZvYRJcfStvy3fu LopEGVlAUTJsO/Qz32+DhAD4GHXOgaPvfrgq59k+QeM8c5eqUsM+aRk0IMXLTGKb/Ee7 Dc6w== 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=d70kMeIFAreRNq1P8Q9A13pWa2SZk/EgMzBIG4xKn9g=; b=uAub1hnkwa/5Iq3j4pjATdR78mFGghs2EplLAwMk7cRJDLUOj58jW6zfk/4/G5amJ3 YptMUhultFWoX8iMVVJjnFcsCYLP+/nPhUjHO8qda9LSh/TWPHMfW1QZG7fYjnVuhzA+ AUbqBJk2UHrMweldBMNUfhXAAjfnMKM+P5dwFQgnHR+FMqBbkKimouNCUTe+xL6qI7o7 ORk8zIrHvlSQKy6xibD8NYeV3FcNL+bS1StBJSgphmzFLlIDqr+/Yfo6Q84RUOb46gsn 1bcinTtEfuL93pGi7XNor49MekdF/EMBTR4bS6gyQkIaOnjMWPcde7zjUnNduIzrGlcQ RMFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gR7WQbt8; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g13-20020a0562140acd00b004c6dacaf4c5si617867qvi.109.2022.11.30.03.25.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Nov 2022 03:25:16 -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=@linaro.org header.s=google header.b=gR7WQbt8; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0LCp-0004LN-MW; Wed, 30 Nov 2022 06:24:47 -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 1p0LCn-0004KR-Ow for qemu-devel@nongnu.org; Wed, 30 Nov 2022 06:24:45 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0LCl-0004f3-W0 for qemu-devel@nongnu.org; Wed, 30 Nov 2022 06:24:45 -0500 Received: by mail-wr1-x433.google.com with SMTP id bs21so26568663wrb.4 for ; Wed, 30 Nov 2022 03:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d70kMeIFAreRNq1P8Q9A13pWa2SZk/EgMzBIG4xKn9g=; b=gR7WQbt8TvLhqxViA1+f7PpR/2/B54W8gdmhQPwVgE59IHkZbCR1Go8fcyRtAnGsad Ot8d5XEZev1uPKEbST9LpG9tU/xpf98ieshFZuMwbtqK9H64JvSB2zFJBOi7uObhtoAA MDYDROfJVaaKpouFoY5+3D3M2tj1mnyN+RpOYb4JGAMHGPQRxUKINUAqsayVK4hvDNpO 8nTNys3ENYGyhutrWJ7iX6EWlQ6VVzAIpfUevSXPy/U5k13G9aPuN1NiZh8bFGv7TEle LH3Y24Fwjcc5uKEYow2VYJEHHaX11jf97sJoxnwDFXAhACsU2rx9rYX9+Ls1o+x53z52 8cEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d70kMeIFAreRNq1P8Q9A13pWa2SZk/EgMzBIG4xKn9g=; b=4Yympocwnugwl3ltm+lTV743BLB5mwmQMKCGceaJCrLTCio6LmjGAuDqEkwqZbAdXl pwjHuSfj6qCwJYRUybff1zzQVDMzCFvWiWOxxaiJPdhvofGDgxq5gcWyBJw9rG86ebCb H+AE4q2pYNZtaX7V7YtLyoVLcyw15ymrALSgkAawT86wv62jEbwIPTNVc+C9nosAy+iO Awe9CTbl1HV6L5imj1dzaWBmuhU9yBB+U7DZ6drrBchD2PrCxI+ngwiNeEwRBlgpT9EK pJQ6sp3gHInbtBLjyEo/hH86T8Hjb1rhaFX+0hvRyTsadEvMe8qt00R1zj/4kkXgYtks Op/Q== X-Gm-Message-State: ANoB5pkTFkP4/YV/esScpyktwMDiDipqv5tCg/DzvE9IUD9PGGUEWhSV qjbuV/fuzPXhDZmTaB0IgLAjGg== X-Received: by 2002:a05:6000:60c:b0:242:10ac:6ab2 with SMTP id bn12-20020a056000060c00b0024210ac6ab2mr11265079wrb.552.1669807482586; Wed, 30 Nov 2022 03:24:42 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id v128-20020a1cac86000000b003cfa80443a0sm1577944wme.35.2022.11.30.03.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 03:24:41 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 055511FFBD; Wed, 30 Nov 2022 11:24:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger Subject: [PATCH v4 5/5] include/hw: VM state takes precedence in virtio_device_should_start Date: Wed, 30 Nov 2022 11:24:39 +0000 Message-Id: <20221130112439.2527228-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221130112439.2527228-1-alex.bennee@linaro.org> References: <20221130112439.2527228-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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 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 --- v3 - rm extra line - fix fn name in comment for virtio_device_started() --- 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)