From patchwork Tue Aug 2 09:49:58 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: 594847 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp4196953maz; Tue, 2 Aug 2022 02:55:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfGVk6vTa21qR6UyCZiTfV4PS73dTSU1bCrzfX4C8BWfTG3hFDVStT12RJ5aFvSWiJV4l8 X-Received: by 2002:ac8:5c13:0:b0:320:f3e2:ccb6 with SMTP id i19-20020ac85c13000000b00320f3e2ccb6mr14642880qti.246.1659434133919; Tue, 02 Aug 2022 02:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659434133; cv=none; d=google.com; s=arc-20160816; b=Xrfacthznu/C3P/ftLWYD6UgpERkvE+PH2mgptAcU7HPVOMLvdXHQhly+Ih0SNhdnE EhMImJ+E6UNZTUAqcLhnUwdcW+n35qU10TvPEstD3i7MXc1tH985epuDy4HHeQArVd5j 735+IMBPn8L0cvi6EtqfQubOecOERiNqeQxG66m6A3ZqNtt7QZ0kQkONEUaFxleKxkL4 9V5Io4dMhYcQBTA4xfwX9DcziRwJI5a1OJdXMAENvKcTCdYXGg2CF/jBKIT8NxhFSjIp R9VWq+gchimCtlmtaRThguZSexcUr8SrTB4oif4MT1ZLe/UyqPjA17rSGdrw8SBLFk/L S5bQ== 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=x448FCGsB6jl4t/PEZTiuqAxlBX+i+OighRCNvx3IrY=; b=NisDS/TsISR3kPlQbqeXN/8JICa7eXXT+Grew2x3JHqpFeHuCV1SXvxnWwDvxZy83n zniSQWNDbjkwfJCGIlRvpJ4xaWdUAZiky9GTXeaLklZAOijRRBBrzcV7HD21D5GtfU2M KqM2TtabfZlpx9td3kPGbKkeo60Jg22zWNbQOll5KY1jCSXl7wWJvFgXRD3LZb+xjxh/ yHQeuc6Yqs6d0tubl/HgvsD0bZsfSVznPoXg1DKuewA8TxQAND588FmV72AYdh+h4A4u p754QopbfiF3EEIop713i1sItYTN+ncsaSgq2enlp1p47YOed+5CkL7nEEOg0ElvcfaJ ozHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a2o70i6o; 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 ay15-20020a05620a178f00b006b67d1bc131si8683357qkb.691.2022.08.02.02.55.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Aug 2022 02:55:33 -0700 (PDT) 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=a2o70i6o; 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]:57590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIocf-00040M-D0 for patch@linaro.org; Tue, 02 Aug 2022 05:55:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIoXl-0001L3-1m for qemu-devel@nongnu.org; Tue, 02 Aug 2022 05:50:29 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:37554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIoXj-0002Mu-7q for qemu-devel@nongnu.org; Tue, 02 Aug 2022 05:50:28 -0400 Received: by mail-wr1-x432.google.com with SMTP id z17so12467710wrq.4 for ; Tue, 02 Aug 2022 02:50:26 -0700 (PDT) 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; bh=x448FCGsB6jl4t/PEZTiuqAxlBX+i+OighRCNvx3IrY=; b=a2o70i6ozgrkoN+0syJ6dPIbzVBJa9qJmDlahBv+BChgsvfUIast9YimY1+nJjhzEc Rp4qxINM/eb26p2DShObyo0xHy8Z6Xjbf16z+cMYY0Jwzn+Jx3tgAXZR3wBxQ46mwmlu dkJW5rcJmxcRC218sQeh0E8GOlL/p740hcxz4qFWgUB22oCwxARhtBpcXRM17NZ+7bOA gcRP2QgKO4lbjWf9Vt5ohl/Nhbg2bg8VrU5/KiGdeK/9WX+EnRaUlVNZzx0ym1FM9FPB 9MIdIqitVw3Hnxjih5SB5O0z4Io9GkYyAmpHXRLoJlLmioTXu4XmGwfRPohyVHqSZYWt E7pA== 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; bh=x448FCGsB6jl4t/PEZTiuqAxlBX+i+OighRCNvx3IrY=; b=oNBjFJufNuIVCjqUwPV9bVVSGlVGxgUJI0OtgJyNEpJ/njb7pRCsTksqqJuA/S272u A2wQ4t6jlBdbEL/4yqS9M7bOhRoZdh1bE1r3J+3lGzPxSDkNXq+Fr31OCVgjL9iFZhmT u7oGNDWR0Hf0xJYj5Idf+bxh0p94MZnLnTXHxa8wqldMhXDeNDuhXMJbl2WMcUUlvQs2 TzpEJgELG8ecAHzJYfLIsuvGr4td+fC79Ni+Kd3yXvFQarqDfaj0R16lXSTOJlEGDFhH CZbu1GpA+VjUD6be+ngpoTuFAyfBdLKaBWvLa9IfAlfIPt+WY5e06OXcqRek8sx1yfom /RFw== X-Gm-Message-State: ACgBeo3cF1lcWnr7Zl0VrSnCXsj5aJCPddJUWok7BcZ6AyUU4sHVnMq/ B3kGaT6ThBjx1aHR6+kQ/Nnnqw== X-Received: by 2002:a5d:6c63:0:b0:220:5e4d:c6e9 with SMTP id r3-20020a5d6c63000000b002205e4dc6e9mr7856582wrz.250.1659433826495; Tue, 02 Aug 2022 02:50:26 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id x12-20020a05600c21cc00b0039747cf8354sm17660436wmj.39.2022.08.02.02.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 02:50:18 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7FAFB1FFC2; Tue, 2 Aug 2022 10:50:11 +0100 (BST) 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, =?utf-8?q?Alex_Benn=C3=A9e?= , "Dr. David Alan Gilbert" , virtio-fs@redhat.com (open list:virtiofs) Subject: [PATCH v4 10/22] hw/virtio: move vm_running check to virtio_device_started Date: Tue, 2 Aug 2022 10:49:58 +0100 Message-Id: <20220802095010.3330793-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220802095010.3330793-1-alex.bennee@linaro.org> References: <20220802095010.3330793-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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, T_SCC_BODY_TEXT_LINE=-0.01 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" All the boilerplate virtio code does the same thing (or should at least) of checking to see if the VM is running before attempting to start VirtIO. Push the logic up to the common function to avoid getting a copy and paste wrong. Signed-off-by: Alex Bennée --- include/hw/virtio/virtio.h | 5 +++++ hw/virtio/vhost-user-fs.c | 6 +----- hw/virtio/vhost-user-i2c.c | 6 +----- hw/virtio/vhost-user-rng.c | 6 +----- hw/virtio/vhost-user-vsock.c | 6 +----- hw/virtio/vhost-vsock.c | 6 +----- 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9bb2485415..74e7ad5a92 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -100,6 +100,7 @@ struct VirtIODevice VirtQueue *vq; MemoryListener listener; uint16_t device_id; + /* @vm_running: current VM running state via virtio_vmstate_change() */ bool vm_running; bool broken; /* device in invalid state, needs reset */ bool use_disabled_flag; /* allow use of 'disable' flag when needed */ @@ -376,6 +377,10 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) return vdev->started; } + if (!vdev->vm_running) { + return false; + } + return status & VIRTIO_CONFIG_S_DRIVER_OK; } diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index e513e4fdda..d2bebba785 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -122,11 +122,7 @@ static void vuf_stop(VirtIODevice *vdev) static void vuf_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserFS *fs = VHOST_USER_FS(vdev); - bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; - - if (!vdev->vm_running) { - should_start = false; - } + bool should_start = virtio_device_started(vdev, status); if (fs->vhost_dev.started == should_start) { return; diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 6020eee093..b930cf6d5e 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -93,11 +93,7 @@ static void vu_i2c_stop(VirtIODevice *vdev) static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserI2C *i2c = VHOST_USER_I2C(vdev); - bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; - - if (!vdev->vm_running) { - should_start = false; - } + bool should_start = virtio_device_started(vdev, status); if (i2c->vhost_dev.started == should_start) { return; diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index 3a7bf8e32d..a9c1c4bc79 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -90,11 +90,7 @@ static void vu_rng_stop(VirtIODevice *vdev) static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserRNG *rng = VHOST_USER_RNG(vdev); - bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; - - if (!vdev->vm_running) { - should_start = false; - } + bool should_start = virtio_device_started(vdev, status); if (rng->vhost_dev.started == should_start) { return; diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c index 0f8ff99f85..22c1616ebd 100644 --- a/hw/virtio/vhost-user-vsock.c +++ b/hw/virtio/vhost-user-vsock.c @@ -55,11 +55,7 @@ const VhostDevConfigOps vsock_ops = { static void vuv_set_status(VirtIODevice *vdev, uint8_t status) { VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev); - bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; - - if (!vdev->vm_running) { - should_start = false; - } + bool should_start = virtio_device_started(vdev, status); if (vvc->vhost_dev.started == should_start) { return; diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 0338de892f..8031c164a5 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -70,13 +70,9 @@ static int vhost_vsock_set_running(VirtIODevice *vdev, int start) static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status) { VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev); - bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; + bool should_start = virtio_device_started(vdev, status); int ret; - if (!vdev->vm_running) { - should_start = false; - } - if (vvc->vhost_dev.started == should_start) { return; }