From patchwork Fri May 24 18:36:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 1105086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 459ZqZ10wQz9s9y for ; Sat, 25 May 2019 04:37:45 +1000 (AEST) Received: from localhost ([127.0.0.1]:58636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF4Z-0001G8-VX for incoming@patchwork.ozlabs.org; Fri, 24 May 2019 14:37:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF3v-0001Em-3l for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUF3s-0008Tk-RH for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUF3r-0008QE-BL for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D5E33082B44; Fri, 24 May 2019 18:36:51 +0000 (UTC) Received: from localhost (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B2415B2F7; Fri, 24 May 2019 18:36:46 +0000 (UTC) From: Stefan Hajnoczi To: Date: Fri, 24 May 2019 19:36:36 +0100 Message-Id: <20190524183638.20745-2-stefanha@redhat.com> In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com> References: <20190524183638.20745-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 24 May 2019 18:36:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v3 1/3] virtio: add vdc->vmchange_state() callback 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: Fam Zheng , Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The core virtio code invokes ->set_status() followed by ->ioeventfd_start() when the guest resumes execution. Both of these functions are also called in other cases unrelated to vm change state. This patch introduces ->vmstate_change() so that devices can act on guest pause/resume. The existing qemu_add_vm_change_state_handler() API isn't usable by virtio devices since the ordering between vm change state handlers is undefined. The new ->vmstate_change() callback is always invoked after ->set_status() and ->ioeventfd_start() when resuming a guest. A later patch makes use of this new callback. Signed-off-by: Stefan Hajnoczi --- include/hw/virtio/virtio.h | 7 +++++++ hw/virtio/virtio.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 27c0efc3d0..5742efa1d7 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -158,6 +158,13 @@ typedef struct VirtioDeviceClass { void (*save)(VirtIODevice *vdev, QEMUFile *f); int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id); const VMStateDescription *vmsd; + + /* Called when the device should start/stop running because the guest was + * resumed/paused. Note that this takes VIRTIO_CONFIG_S_DRIVER_OK into + * account so running is true iff the guest is resumed and the guest driver + * has already indicated it is ready. + */ + void (*vmstate_change)(VirtIODevice *vdev, bool running); } VirtioDeviceClass; void virtio_instance_init_common(Object *proxy_obj, void *data, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 4805727b53..cdf869456b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2291,6 +2291,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); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); bool backend_run = running && vdev->started; vdev->vm_running = running; @@ -2298,10 +2299,18 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state) virtio_set_status(vdev, vdev->status); } + if (!backend_run && vdc->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (k->vmstate_change) { k->vmstate_change(qbus->parent, backend_run); } + if (backend_run && vdc->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (!backend_run) { virtio_set_status(vdev, vdev->status); }