From nobody Wed Feb 11 03:44:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604264602; cv=none; d=zohomail.com; s=zohoarc; b=L4NpKEworBdEhwIML2sFLfCNHXGAoRgaDjahJDp4uA8mUjOR2NHQnuEsc0qAZQy+14W/k9stQaTaC6T549Ho5l52OFV5nOKd1CnnqSN3pR3cTFz8jLOGVGJ0AIuMIGPh9suxkMLsxcyLKtfn/bldOqYxC9170OY2N21tZdbPQ/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604264602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gwfVXRhQA82A5xD9GkELRckQ93zr4+8h6ghz6ZCncOU=; b=EPEt8gqBmDStN2gz8mQyrl9cKS6ddBq/ZmvQn7sC/NjnKwE6f0wxWaf3wO7tpi2vu5sz8fA1oD5pZ0G/0I4LKrabAsJzIHt7cOr8sko8D3ds8AtsA7WKt16uffJNtIF5X2IoLAOI60XsuCi1V1ZUlwRCJ7crNZIIpoJi1Q344Lw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604264602128387.71572914761737; Sun, 1 Nov 2020 13:03:22 -0800 (PST) Received: from localhost ([::1]:50802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZKVV-0007nx-0y for importer@patchew.org; Sun, 01 Nov 2020 16:03:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZKSL-0004Vl-0h for qemu-devel@nongnu.org; Sun, 01 Nov 2020 16:00:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZKSJ-0005As-1L for qemu-devel@nongnu.org; Sun, 01 Nov 2020 16:00:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-9VXFLG-cPaKapZcXOIWmgw-1; Sun, 01 Nov 2020 15:59:59 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6C1B80362F; Sun, 1 Nov 2020 20:59:58 +0000 (UTC) Received: from gimli.home (ovpn-112-213.phx2.redhat.com [10.3.112.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F31B5B4D4; Sun, 1 Nov 2020 20:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604264402; 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=gwfVXRhQA82A5xD9GkELRckQ93zr4+8h6ghz6ZCncOU=; b=H3adHfiG/lboP4xSYddYqxh+0LKQCvjX/Gh6na/8LNfeRHCY8WmjuoJejcqV9IEeN34DvM 78WMr6blzUEgb+Rj6rdjlbl0oZE+HqM5N/EEww4Yst5pt7rDR2LPVeWXBjMWv51hLvfPhU pj1uIBbCoeLJAuYcgLXx+MF9wI49V44= X-MC-Unique: 9VXFLG-cPaKapZcXOIWmgw-1 Subject: [PULL v3 06/32] vfio: Add migration state change notifier From: Alex Williamson To: qemu-devel@nongnu.org Date: Sun, 01 Nov 2020 13:59:55 -0700 Message-ID: <160426439508.24886.9216394604782328687.stgit@gimli.home> In-Reply-To: <160426371498.24886.12193840637250368669.stgit@gimli.home> References: <160426371498.24886.12193840637250368669.stgit@gimli.home> User-Agent: StGit/0.21-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=alex.williamson@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=alex.williamson@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/01 15:59:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.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_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kirti Wankhede , Cornelia Huck , Neo Jia , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Kirti Wankhede Added migration state change notifier to get notification on migration state change. These states are translated to VFIO device state and conveyed to vendor driver. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Cornelia Huck Signed-off-by: Alex Williamson --- hw/vfio/migration.c | 28 ++++++++++++++++++++++++++++ hw/vfio/trace-events | 1 + include/hw/vfio/vfio-common.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index e1ffae05e288..7ec85b6469c5 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -175,6 +175,30 @@ static void vfio_vmstate_change(void *opaque, int runn= ing, RunState state) (migration->device_state & mask) | value); } =20 +static void vfio_migration_state_notifier(Notifier *notifier, void *data) +{ + MigrationState *s =3D data; + VFIOMigration *migration =3D container_of(notifier, VFIOMigration, + migration_state); + VFIODevice *vbasedev =3D migration->vbasedev; + int ret; + + trace_vfio_migration_state_notifier(vbasedev->name, + MigrationStatus_str(s->state)); + + switch (s->state) { + case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_FAILED: + ret =3D vfio_migration_set_state(vbasedev, + ~(VFIO_DEVICE_STATE_SAVING | VFIO_DEVICE_STATE_RESUM= ING), + VFIO_DEVICE_STATE_RUNNING); + if (ret) { + error_report("%s: Failed to set state RUNNING", vbasedev->name= ); + } + } +} + static void vfio_migration_exit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; @@ -219,8 +243,11 @@ static int vfio_migration_init(VFIODevice *vbasedev, } =20 migration =3D vbasedev->migration; + migration->vbasedev =3D vbasedev; migration->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_= change, vbasedev); + migration->migration_state.notify =3D vfio_migration_state_notifier; + add_migration_state_change_notifier(&migration->migration_state); return 0; =20 err: @@ -270,6 +297,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev) if (vbasedev->migration) { VFIOMigration *migration =3D vbasedev->migration; =20 + remove_migration_state_change_notifier(&migration->migration_state= ); qemu_del_vm_change_state_handler(migration->vm_state); vfio_migration_exit(vbasedev); } diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 41de81f12f60..78d7d83b5ef8 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -150,3 +150,4 @@ vfio_display_edid_write_error(void) "" vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, uin= t32_t dev_state) " (%s) running %d reason %s device state %d" +vfio_migration_state_notifier(const char *name, const char *state) " (%s) = state %s" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9a571f1fb552..2bd593ba38bb 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -59,10 +59,12 @@ typedef struct VFIORegion { } VFIORegion; =20 typedef struct VFIOMigration { + struct VFIODevice *vbasedev; VMChangeStateEntry *vm_state; VFIORegion region; uint32_t device_state; int vm_running; + Notifier migration_state; } VFIOMigration; =20 typedef struct VFIOAddressSpace {