From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066909; cv=none; d=zohomail.com; s=zohoarc; b=jQkIjU7tTfnK1pjdeGpIPGgT/+NWpD9Uc52+fvOoqtN8XwKUr5zoLWWLlJ2zUtL/nF13/LMpAblBmn+udGuU5G+4oZT1gmPEVokJCI/7Whtmc6JLrkc2FWLefeWNqlxgFeuTB4DCd/ALTTYMnlTWH8fY77N9HU5yvqhdioZvT5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066909; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dnp48zFz4N856ZPIHl/UMCcSs+S99equ6ItzvQY97UU=; b=ma7rimuJBGmMDTm7M/ycjQs+D2dH0njgbfz4Wgb59qgJ09UwDRlukh/wylKbyqUbxk5W6gJBXFWKCNgSO2L15p9KQZjroTeFPksxxHifWUZQs+dN0RMMVjniBZ2znNJ+oz64VAP/PnD8Veh38Szv1IUbaMRCzE7R9/HbVWTMBO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066909428796.9640826109819; Thu, 15 Oct 2026 05:21:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHKSJ-0002nH-B6; Thu, 15 Oct 2026 08:21:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHKSH-0002m4-E0 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:05 -0400 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 1xHKSF-0005Ht-M9 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:05 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-LhhRM2m1NkSEHwE7GCuNSg-1; Thu, 15 Oct 2026 12:21:01 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 583B3180074C; Thu, 15 Oct 2026 12:21:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 23650180029C; Thu, 15 Oct 2026 12:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066862; 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=dnp48zFz4N856ZPIHl/UMCcSs+S99equ6ItzvQY97UU=; b=Plh0WZVvWDn5swC/Jli2GBl1JvWwPJ1w5fIDzV8zuFDTdLB9cYDT5WojBjzL9tRxoZkAbb KPjeXzdiCExQ3ftaMktyyjrEnxT8AMeZlv3lDIuJE7EsTltpLgs2T2PMHhd+E6AxBYpmUV XZWzGt40VlVPki6vbn7G+MHRh+D2v8Y= X-MC-Unique: LhhRM2m1NkSEHwE7GCuNSg-1 X-Mimecast-MFC-AGG-ID: LhhRM2m1NkSEHwE7GCuNSg_1792066860 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 1/8] target/i386/kvm: Fix UBSAN shift error in MTRR mask computation Date: Thu, 15 Oct 2026 14:20:48 +0200 Message-ID: <20261015122055.888209-2-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066912903158500 On AMD EPYC processors, raw CPUID leaf 0x80000008 reports 52 physical address bits. When a machine type such as microvm forces host_phys_bits=3Dtrue, the CPU ends up with phys_bits=3D52, causing MAKE_64BIT_MASK(52, 0) to shift by 64 - which is undefined behavior. Fix by only computing the mask when phys_bits < 52. Fixes: fcc35e7ccaed ("target-i386: Fill high bits of mtrr mask") Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20260722120437.697986-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater --- target/i386/kvm/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a72b6e6b74cc7e16bb721d9a32332a0ed8473fc1..da922f72d71e00bd10ce087ccc9= 828c9692501d0 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5064,8 +5064,7 @@ static int kvm_get_msrs(X86CPU *cpu) * we're migrating to. */ =20 - if (cpu->fill_mtrr_mask) { - assert(cpu->phys_bits <=3D 52); + if (cpu->fill_mtrr_mask && cpu->phys_bits < 52) { mtrr_top_bits =3D MAKE_64BIT_MASK(cpu->phys_bits, 52 - cpu->phys_b= its); } else { mtrr_top_bits =3D 0; --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066896; cv=none; d=zohomail.com; s=zohoarc; b=JTaOiFb//qRYe7vPH2s6IcCR1rUf1tLmLAsN4fSf8AynsyppQCZOLWR3AUMDq5PfKNmeU6GWLaEaD2vBQ36/Iy20UOv83E68qvXO99ThX8/QPNAYsMjlNBcKEDi7XSKRvg7Vg8A3uag55IWiBJ5ZqaCn55TO/d5Pxy3Kpel+nXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066896; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Dl8SPp1wrcv62WgVI4ixi/APG8m8Atl7fa5msJSXI0Q=; b=g/EiR045ZRCpJOvcUyRmoQfz1sEYCncIT0q6+n+mto5uhI+wR7ZpHu6HrxEtmWHD9E4YAXMxrhQzYC2deiQDm33903yqqzkeHGZ9ugnw7lU+IOeTrr5dGWEvGoxl7jwSWUcZYyVLik8um5NW4arfMv2HZ1Ng7x9G/ZhRWAU6EyU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066896167112.89896069004749; Thu, 15 Oct 2026 05:21:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHKSJ-0002nI-Rf; Thu, 15 Oct 2026 08:21:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHKSI-0002mr-FP for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:06 -0400 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 1xHKSG-0005Hx-J2 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:06 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-SlgmKAQ_NZ6UktMbaM78ug-1; Thu, 15 Oct 2026 12:21:02 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B8EF91955BDF for ; Thu, 15 Oct 2026 12:21:01 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C5B6D18004D2; Thu, 15 Oct 2026 12:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066863; 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=Dl8SPp1wrcv62WgVI4ixi/APG8m8Atl7fa5msJSXI0Q=; b=IxYbcG9kEpoFIIOigW7fx0u3O3rcVDVHCiNS1yZJqbgz7ILftkpDae+QAh7J9SS4zRksf4 cUH/QJ47wUOgH90h6q1zZXWa3a5pGmmFfoxfr90mN6AS+2eY9HmCgGMFTOBKMtTcAiHYhc IhRxJi0oYXoBg0IAA3XVt7tlaeu9AZ0= X-MC-Unique: SlgmKAQ_NZ6UktMbaM78ug-1 X-Mimecast-MFC-AGG-ID: SlgmKAQ_NZ6UktMbaM78ug_1792066861 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 2/8] scripts/checkpatch: validate Fixes: tag format and commit ancestry Date: Thu, 15 Oct 2026 14:20:49 +0200 Message-ID: <20261015122055.888209-3-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066898515158500 Adapt the kernel's checkpatch Fixes: tag validation for QEMU. Add a git_commit_info() helper to resolve commit hashes and validate the Fixes: tag in commit messages. The canonical form is: Fixes: <12+ chars of sha1> ("") The check validates capitalization, spacing, hash length, lowercase hex, and quoted title. When the format is wrong and the commit can be resolved, suggest the corrected Fixes: line. When running inside a git repository, also verify that the referenced commit is an ancestor of master. Lines matching "Fixes: CVE-*" are skipped. The check can be disabled with --no-fixes-tag. Link: https://lore.kernel.org/qemu-devel/20260806171333.328864-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- scripts/checkpatch.pl | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9838a64178510f216ff22e9259de22320b9da731..5df266acb1729e0174969c50d4e= aaafb1e7b1ce4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -21,6 +21,7 @@ use Getopt::Long qw(:config no_auto_abbrev); my $quiet =3D 0; my $tree =3D 1; my $chk_signoff =3D 1; +my $chk_fixes_tag =3D 1; my $chk_patch =3D undef; my $chk_branch =3D undef; my $tst_only; @@ -54,6 +55,7 @@ Options: -q, --quiet quiet --no-tree run without a qemu tree --no-signoff do not check for 'Signed-off-by' line + --no-fixes-tag do not check for 'Fixes:' tag --patch treat FILE as patchfile --branch treat args as GIT revision list --emacs emacs compile window format @@ -94,6 +96,7 @@ GetOptions( 'q|quiet+' =3D> \$quiet, 'tree!' =3D> \$tree, 'signoff!' =3D> \$chk_signoff, + 'fixes-tag!' =3D> \$chk_fixes_tag, 'patch!' =3D> \$chk_patch, 'branch!' =3D> \$chk_branch, 'emacs!' =3D> \$emacs, @@ -441,6 +444,10 @@ sub build_types { build_types(); =20 $chk_signoff =3D 0 if ($file); +$chk_fixes_tag =3D 0 if ($file); + +my $gitroot =3D $ENV{'GIT_DIR'}; +$gitroot =3D ".git" if !defined($gitroot); =20 my @rawlines =3D (); my @lines =3D (); @@ -561,6 +568,24 @@ sub which { return ""; } =20 +sub git_commit_info { + my ($commit, $id, $desc) =3D @_; + + return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); + + my $output =3D `git log --no-color --format=3D'%H %s' -1 $commit 2>/dev/n= ull`; + if ($? !=3D 0) { + $id =3D undef; + } else { + chomp $output; + $output =3D~ s/^\s*//gm; + $id =3D substr($output, 0, 12); + $desc =3D substr($output, 41); + } + + return ($id, $desc); +} + sub expand_tabs { my ($str) =3D @_; =20 @@ -1855,6 +1880,47 @@ sub process { } } =20 +# Check Fixes: tag format and commit validity + if ($chk_fixes_tag && + $line =3D~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})\s*(.*)?/i= ) { + my $tag =3D $1; + my $orig_commit =3D $2; + my $title =3D $3; + + if ($line !~ /^\s*Fixes:\s+CVE/i) { + my $tag_case =3D not ($tag eq "Fixes:"); + my $tag_space =3D not ($line =3D~ /^fixes:? [0-9a-f]{5,40}/i); + my $id_length =3D not ($orig_commit =3D~ /^[0-9a-f]{12,40}$/); + my $id_case =3D not ($orig_commit !~ /[A-F]/); + + my $id =3D "0123456789ab"; + my $description =3D "commit title"; + my $has_quotes =3D 0; + + if (defined $title && $title =3D~ /^\("(.*?)"\)$/) { + $description =3D $1 if ($1); + $has_quotes =3D 1; + } elsif (defined $title && $title =3D~ /^\(?(.*?)\)?$/) { + $description =3D $1 if ($1); + } + + my ($cid, $ctitle) =3D git_commit_info($orig_commit, $id, $description= ); + + if (defined($cid) && ($ctitle ne $description || $tag_case || $tag_spa= ce || $id_length || $id_case || !$has_quotes)) { + my $fixed =3D "Fixes: $cid (\"$ctitle\")"; + WARN("Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"= <title line>\")'" . + " - ie: '$fixed'\n" . $herecurr); + } + if (which("git") ne "" && -e "$gitroot") { + my $hash =3D defined($cid) ? $cid : $orig_commit; + `git merge-base --is-ancestor $hash master 2>/dev/null`; + if ($? !=3D 0) { + WARN("Fixes: commit $hash is not an ancestor of master\n" . $herecur= r); + } + } + } + } + # Check SPDX-License-Identifier references a permitted license if (($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) && $rawline !~ /^-/) { --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066906; cv=none; d=zohomail.com; s=zohoarc; b=mOYX6HzuZKDlsrgCZAqiKAm24P8edtFAw0uZpOIUSK5stdxN3dx7YwACD6jlldpl9eyXAumk6pmsDtE0UwyGqw/Ms5t6PspphM8TZrcaQ5tZzzHZWiPKBMEJ/whocukD+vjGIaLIDG3uWeKxq4Dk7F6acqFNoCwkw1Kb00Lve9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066906; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fREmhUQtKJU3j1+MSYYCp5cEcdJ/20AGuBPbHsf21zQ=; b=ARIDrZnAV07upzRtEjh/wS5Sts7bjvG4q//9kpbKDTBB6A1KOu4wOzYYMnWdDxEhdN2Yyd5SHO28H2OmtmeTVlwSdIhhl5AMzxPRf3fBlXvIxGj7ttQvqh3B9azril8NcWJSU/33OkhjtmjNB+BUOIHBHTTOptBgD7HihCd9eOY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066906893887.9161510579274; Thu, 15 Oct 2026 05:21:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKSO-0002p3-EW; Thu, 15 Oct 2026 08:21:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSM-0002oH-TD for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSK-0005IT-OV for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:10 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-avZnk_1bP4enoISQFdpmsg-1; Thu, 15 Oct 2026 12:21:05 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A9DE180062D; Thu, 15 Oct 2026 12:21:04 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5E78A180057F; Thu, 15 Oct 2026 12:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066867; 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=fREmhUQtKJU3j1+MSYYCp5cEcdJ/20AGuBPbHsf21zQ=; b=VYPJM3PXqWZsSV3QI+BatTUZSUcIQ2Sb3+wImwg3XppD729bR0u5bKk2BUIPUrGPnUlEWN s2mO3lhPRMVXxbuko821u3Hg6wXKfqg+XsHr6M7S804mMrOWUVZLytiSagV5Qrx2+h5+Xb FHJ+WknGLALQCq+Y7E8xaN6oP2p2+DA= X-MC-Unique: avZnk_1bP4enoISQFdpmsg-1 X-Mimecast-MFC-AGG-ID: avZnk_1bP4enoISQFdpmsg_1792066864 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Hugo Komatsu <hugo.komatsu@nutanix.com>, John Levon <john.levon@nutanix.com>, Mark Cave-Ayland <mark.caveayland@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> Subject: [PULL 3/8] vfio-user: reject failover during init Date: Thu, 15 Oct 2026 14:20:50 +0200 Message-ID: <20261015122055.888209-4-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066908616158500 From: Hugo Komatsu <hugo.komatsu@nutanix.com> Virtio-net failover is a networking feature that relies on a primary and standby device pair. This is not currently supported for vfio-user. Refuse initialization if this property is set. Signed-off-by: Hugo Komatsu <hugo.komatsu@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com> Link: https://lore.kernel.org/qemu-devel/20260813110731.80-1-hugo.komatsu@n= utanix.com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- hw/vfio-user/pci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c index e7573d4a9f088c1afc8ed2709932842247abf6ac..983e1d4ad470bfa887a3a60e88e= 2f255f0ed085a 100644 --- a/hw/vfio-user/pci.c +++ b/hw/vfio-user/pci.c @@ -266,6 +266,11 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Err= or **errp) return; } =20 + if (pdev->failover_pair_id) { + error_setg(errp, "vfio-user: failover is not supported"); + return; + } + sock_name =3D udev->socket->u.q_unix.path; =20 vbasedev->name =3D g_strdup_printf("vfio-user:%s", sock_name); --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066933; cv=none; d=zohomail.com; s=zohoarc; b=M80r/1EggV6q+wRzY3Gh7NBK5n++z6CBiXRhhMXuQSmDJmeYh/Ch+dJ42Y8meLbzJvAkRCzJPDBeneM+m0Uw1f80LHKPIyfrjUKLR9/4u+rZq8rE625vKdxwvL7GVLYXL0IU0cG23+epgbHOmaI0CLtfzcjwU7XpPhPcsmPDc74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066933; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zjetcz5cxb4TTuuZEteF5VZxBDAYnVbJTCoPEJlR3hQ=; b=D30Mt0mOuIMfuEG0Qo2ndOxLeb+ATibAfsx9kR/+C/rJ0v4YOqx7Ix31S/NSozWVA585rXuuYmGDlf5U6HWK5E6v4xNBR7v9ls9zxKPhQgIi9RJi9KU0c+x6N/rPBKeJgAb9Z7BN6i2atiVLtBEcsVg9e2U3G6czsS/HvM6MjJQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066933553475.6555106101059; Thu, 15 Oct 2026 05:22:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKST-0002tr-PT; Thu, 15 Oct 2026 08:21:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSR-0002qH-9t for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSN-0005Ir-8S for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:14 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-9gWTLlQONTm2S6CIwE3j6w-1; Thu, 15 Oct 2026 12:21:07 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 287C11955BC5; Thu, 15 Oct 2026 12:21:06 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B65C718004D2; Thu, 15 Oct 2026 12:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066870; 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=zjetcz5cxb4TTuuZEteF5VZxBDAYnVbJTCoPEJlR3hQ=; b=KFe8+Oza2stj/HywH+1XIv5foeP8Im8QTNjRGFwu7g/VomWtpXoXsUjP/QgzLILnKUjBOn XEqg0uRRpjF938Vt18yJCdepIJtjMHgCOVafbmoPaTcWD6Sx6hsR5e10iVg8uOLAh/cE23 SqVOXKdNt77EeXLQb0G8jqArv0i91lk= X-MC-Unique: 9gWTLlQONTm2S6CIwE3j6w-1 X-Mimecast-MFC-AGG-ID: 9gWTLlQONTm2S6CIwE3j6w_1792066866 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Mikhail Malyshev <mike.malyshev@gmail.com>, Tomita Moeko <tomitamoeko@gmail.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> Subject: [PULL 4/8] vfio/igd: sanitize DBUF_CTL POWER_STATE for iGPU passthrough Date: Thu, 15 Oct 2026 14:20:51 +0200 Message-ID: <20261015122055.888209-5-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066935094158500 From: Mikhail Malyshev <mike.malyshev@gmail.com> On some hosts the firmware POST modeset leaves the display data buffer (DBUF) powered, so the passed-through iGPU's DBUF_CTL registers read back POWER_STATE=3D1 while POWER_REQUEST=3D0 -- an inconsistent leftover th= at never occurs under GVT-g, which emulates the register so POWER_STATE follows POWER_REQUEST. This was observed with a Windows guest (Intel KMD) on QEMU 9.1; a Linux/i915 guest was not tested. On the first-boot modeset the guest driver samples POWER_STATE to decide which DBUF slices are already enabled, sees the stale "powered" bit, and therefore never issues POWER_REQUEST. DBUF then powers down, the plane FIFO underruns, and scanout is corrupted (vertical stripes) until a full modeset (e.g. a display sleep/wake) re-requests power. The programming is a single inconsistent read-modify-write. Traced with x-no-mmap=3Don so every BAR0 access is visible: read 0x45008 =3D 0x4040c000 STATE=3D1, REQUEST=3D0 (stale leftover) write 0x45008 =3D 0x4043c000 RMW: tracker bits only; REQUEST still 0 read 0x45008 =3D 0x0043c000 STATE=3D0: DBUF powered down -> underrun The driver sees STATE=3D1, assumes the slice is already powered, and leaves REQUEST clear. Only after a display sleep/wake does it set REQUEST, which is why sleep/wake repairs the display: write 0x45008 =3D 0x8043c000 REQUEST=3D1 read 0x45008 =3D 0xc043c000 STATE follows -> powered, scanout clean The same pattern occurs on the other slice registers (0x44fe8, 0x44300, 0x44304). Present a consistent view like GVT-g: trap the DBUF_CTL slice registers (S1..S4, only as many as the generation exposes) in BAR0 and clear POWER_STATE on read whenever POWER_REQUEST is not set. Writes pass straight through to the device. Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com> Reviewed-by: Tomita Moeko <tomitamoeko@gmail.com> Link: https://lore.kernel.org/qemu-devel/20260724102959.1043264-1-mike.maly= shev@gmail.com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- hw/vfio/igd.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 413a49aae9163c6500bc50f29e5454f698addaa4..5e6160763cefb9d9739dd0a6462= 137c49109e81a 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -455,6 +455,96 @@ static bool vfio_pci_igd_override_gms(int gen, uint32_= t gms, uint32_t *gmch) #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 =20 +/* + * IGD BAR0 DBUF_CTL sanitize quirk. + * + * On hosts where the firmware POST modeset left the display engine powere= d, + * DBUF_CTL reads back POWER_STATE=3D1 while POWER_REQUEST=3D0 -- an incon= sistent + * leftover that never occurs under GVT-g (which emulates the register so + * STATE follows REQUEST). A passed-through guest driver samples POWER_ST= ATE + * to decide which DBUF slices are already enabled, sees this stale "power= ed" + * bit, and therefore never issues POWER_REQUEST. DBUF then powers down, = the + * plane FIFO underruns, and scanout is corrupted until a full modeset (e.= g. + * a display sleep/wake) re-requests power. + * + * Present a consistent view like GVT-g: intercept DBUF_CTL reads and clear + * POWER_STATE whenever POWER_REQUEST is not set. Writes pass straight + * through to the device. + */ +#define IGD_DBUF_POWER_REQUEST (1u << 31) +#define IGD_DBUF_POWER_STATE (1u << 30) + +/* + * DBUF_CTL slice registers within BAR0, in slice order (i915 numbers these + * S1..S4). How many slices exist is generation-dependent, so only the fi= rst + * igd_dbuf_ctl_nslices(gen) entries are real DBUF_CTL registers on a given + * part; the rest are unrelated registers and must not be trapped. + */ +static const uint32_t igd_dbuf_ctl_offsets[] =3D { + 0x45008, /* S1 */ 0x44FE8, /* S2 */ 0x44300, /* S3 */ 0x44304, /* S4 */ +}; + +/* + * DBUF slice count by generation, matching i915 dbuf.slice_mask: + * gen9/10 =3D 1 (S1), gen11 =3D 2 (S1-S2), gen12+ =3D 4 (S1-S4). + * + * Within gen12 the slice count is actually per-platform, not per-gen: ADL= -P / + * RPL-P / DG2 expose 4 slices, but TGL / RKL / ADL-S have only 2. We ret= urn 4 + * for all gen12+ (igd_gen() can't distinguish them), so on a <4-slice gen= 12 + * part S3/S4 (0x44300/0x44304) are over-trapped. This is harmless in pra= ctice: + * the read handler only mutates a value when POWER_REQUEST=3D0 && POWER_S= TATE=3D1, + * which whatever register lives at those offsets is very unlikely to pres= ent. + * A fully-correct count would have to key off the PCI device ID. + */ +static int igd_dbuf_ctl_nslices(int gen) +{ + if (gen <=3D 10) { + return 1; + } + if (gen =3D=3D 11) { + return 2; + } + return 4; +} + +typedef struct IGDDbufCtlQuirk { + VFIOPCIDevice *vdev; + uint32_t bar_offset; /* offset within BAR0 MMIO */ + uint8_t bar; +} IGDDbufCtlQuirk; + +static uint64_t igd_dbuf_ctl_read(void *opaque, hwaddr addr, unsigned size) +{ + IGDDbufCtlQuirk *q =3D opaque; + VFIOPCIDevice *vdev =3D q->vdev; + uint64_t val =3D vfio_region_read(&vdev->bars[q->bar].region, + addr + q->bar_offset, size); + + if (size =3D=3D 4 && !(val & IGD_DBUF_POWER_REQUEST) && + (val & IGD_DBUF_POWER_STATE)) { + val &=3D ~(uint64_t)IGD_DBUF_POWER_STATE; + error_report_once("IGD quirk: DBUF_CTL@0x%x cleared stale " + "POWER_STATE (POWER_REQUEST=3D0)", q->bar_offset= ); + } + return val; +} + +static void igd_dbuf_ctl_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + IGDDbufCtlQuirk *q =3D opaque; + VFIOPCIDevice *vdev =3D q->vdev; + + vfio_region_write(&vdev->bars[q->bar].region, + addr + q->bar_offset, data, size); +} + +static const MemoryRegionOps igd_dbuf_ctl_ops =3D { + .read =3D igd_dbuf_ctl_read, + .write =3D igd_dbuf_ctl_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) { VFIOQuirk *ggc_quirk, *bdsm_quirk; @@ -507,6 +597,35 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, in= t nr) 1); =20 QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); + + /* + * DBUF_CTL sanitize quirk (gen9+): trap the DBUF_CTL slice registers = so + * POWER_STATE is reported consistently with POWER_REQUEST (see + * igd_dbuf_ctl_read()). Only trap slices that actually exist on this + * generation -- the remaining offsets are unrelated registers. + */ + if (gen >=3D 9) { + int i, nslices =3D igd_dbuf_ctl_nslices(gen); + VFIOQuirk *dbuf_quirk =3D vfio_quirk_alloc(nslices); + IGDDbufCtlQuirk *dq; + + dq =3D g_new0(IGDDbufCtlQuirk, nslices); + dbuf_quirk->data =3D dq; + + for (i =3D 0; i < nslices; i++) { + dq[i].vdev =3D vdev; + dq[i].bar =3D nr; + dq[i].bar_offset =3D igd_dbuf_ctl_offsets[i]; + memory_region_init_io(&dbuf_quirk->mem[i], OBJECT(vdev), + &igd_dbuf_ctl_ops, &dq[i], + "vfio-igd-dbuf-ctl-quirk", 4); + memory_region_add_subregion_overlap(vdev->bars[nr].region.mem, + igd_dbuf_ctl_offsets[i], + &dbuf_quirk->mem[i], 1); + } + + QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, dbuf_quirk, next); + } } =20 static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066920; cv=none; d=zohomail.com; s=zohoarc; b=Cye7RASOXEm+6Oq2NxDJwNcd9GKGL1NgjZgpY3pH6+iTyZmjBoHnpYx/69VqLpuvzcT6qxTcc/Pa7O3L+VpNGj8C/2rfFboY/QoD4w6Oq0H5cXiBnp7c6ybylXfWBw8pmUmoisGC3/Wi8Yblm2KnX2FzTppH15z/cdn4OCFtHiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066920; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vhu6POVbLjiJYuxmQ4vtpr/w3/Vjw8wZhr0borEHm1g=; b=c1BRJygO1UmThDt+I3ISkQo+gMu1A9dofn9r49wexfbBKmZKMl0/6NO7bHw/cGSM7nNJSDymHtnSc20NJp2OrAr0mHTxBmbifpRer9WlyXwA0y0U3oGubGPAgYQOy3jGDlT3hdO1W0We4lLcn8HD50/bfXW/MQc7kzKU2TGGMls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066920234421.2963948515535; Thu, 15 Oct 2026 05:22:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKSS-0002rL-KF; Thu, 15 Oct 2026 08:21:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSP-0002pV-FG for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSN-0005Ik-4R for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:12 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-98-ZzktSK-SPJmHyLgN6j8KMg-1; Thu, 15 Oct 2026 12:21:09 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 064221955BD0; Thu, 15 Oct 2026 12:21:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 94EA6180057F; Thu, 15 Oct 2026 12:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066870; 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=vhu6POVbLjiJYuxmQ4vtpr/w3/Vjw8wZhr0borEHm1g=; b=ZxtOWbauq8Xm13C+fDh2U2hRqDeNY42h+2Ahojgt3x0DYKQmrVy16qOk89StWFdMKkIqbd 3TrDuMoN2ZOFA2ZM3lKioSrNgAuSB7EYWGIOLIDdpH5ahaokmE9NFLqI3E9JTgSygD0qda S+XWC9H1NOVzbpwOnMrE8kNxVS+xlIc= X-MC-Unique: ZzktSK-SPJmHyLgN6j8KMg-1 X-Mimecast-MFC-AGG-ID: ZzktSK-SPJmHyLgN6j8KMg_1792066868 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Tushar Dave <tdave@nvidia.com>, Shameer Kolothum <skolothumtho@nvidia.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> Subject: [PULL 5/8] hw/vfio: thread vf-token through iommufd bind Date: Thu, 15 Oct 2026 14:20:52 +0200 Message-ID: <20261015122055.888209-6-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066920893158500 From: Tushar Dave <tdave@nvidia.com> A VF fails to bind through the iommufd/cdev backend when its PF is bound to vfio-pci and requires a matching VF token. QEMU currently initializes struct vfio_device_bind_iommufd without the token flag or token UUID. Pass the existing vf-token device property to the IOMMUFD bind ioctl for PCI devices. Signed-off-by: Tushar Dave <tdave@nvidia.com> Reviewed-by: Shameer Kolothum <skolothumtho@nvidia.com> Reviewed-by: C=C3=A9dric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260908160731.1658621-1-tdave@nvi= dia.com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- hw/vfio/iommufd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 242644aa0010cd5af817a5d451308d730bc0daa4..de482128bf1bda6f2f7cdc35afa= 4621da6c29b4f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -155,6 +155,7 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vba= sedev) =20 static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **er= rp) { + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); IOMMUFDBackend *iommufd =3D vbasedev->iommufd; struct vfio_device_bind_iommufd bind =3D { .argsz =3D sizeof(bind), @@ -180,6 +181,15 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *= vbasedev, Error **errp) =20 /* Bind device to iommufd */ bind.iommufd =3D iommufd->fd; + + /* + * Pass the VF token when binding a PCI device. + */ + if (vdev && !qemu_uuid_is_null(&vdev->vf_token)) { + bind.flags |=3D VFIO_DEVICE_BIND_FLAG_TOKEN; + bind.token_uuid_ptr =3D (uintptr_t)&vdev->vf_token; + } + if (ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) { error_setg_errno(errp, errno, "error bind device fd=3D%d to iommuf= d=3D%d", vbasedev->fd, bind.iommufd); --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066917; cv=none; d=zohomail.com; s=zohoarc; b=QPhzs9Fe/a3U2fwcrK9JrALy5xU1xXpDGTNSS3cS9aFVgIBn5WsBu/w04z35kCMoIKnvXLcioYo+dAkypmMT8h0mL2q3L5ZDun7iftn5gxSDv7TPUJiBHLoPUvSxmzAB1iVKd5PaIOahoO7DPVT5NpV1s4p9OfdlwvPOqIkUEMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066917; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Mv2xuRM7yQNOA3AOJqXsmilOmSaKGP93T3T04IWMT9Q=; b=OLNMjKXGApCMotRaPDe8yOI4bHo3E2BUd3G9hhACM+bnYiZeL7VH4sUQ9E+Dlviu0qa6VyMK0BwM2AVSXpdASfP4vDz/NUMW4lUXA0ZvJ96Mwh29Y+RRxe+9RW6JWKp/rUUt1c21exOqAFb3zrVFFcD/Zxwt4LcrmHpth3oAxkA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066917574643.7077973756305; Thu, 15 Oct 2026 05:21:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKSY-000304-8B; Thu, 15 Oct 2026 08:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSV-0002xP-Em for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:19 -0400 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 <clg@redhat.com>) id 1xHKST-0005Ja-1b for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:18 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-28l3Ss-xN-qfXpzgmkmjNA-1; Thu, 15 Oct 2026 12:21:11 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 673AF1955F70; Thu, 15 Oct 2026 12:21:10 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7697818004D2; Thu, 15 Oct 2026 12:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066874; 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=Mv2xuRM7yQNOA3AOJqXsmilOmSaKGP93T3T04IWMT9Q=; b=Q+Bq9UD8I1SUZMD3qSTFX9atoglpSojz5sy47+/ZTVZHSRmcaXhiog+vucpxZq+AwDUuA7 MjlfteAjQy0CPl7d9WOGIT/Rxbzz5P+sVvLoKgywQRGpdB3IiTzIGyUJeKcL51W3tiX3Nd OwdJN+P83W1Ba9UrJ1G1+jAVOUgicIo= X-MC-Unique: 28l3Ss-xN-qfXpzgmkmjNA-1 X-Mimecast-MFC-AGG-ID: 28l3Ss-xN-qfXpzgmkmjNA_1792066870 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Yuan Wang <yuan1.wang@intel.com>, Tomita Moeko <tomitamoeko@gmail.com>, Bosheng Xue <bosheng.xue@intel.com>, Junjie Cao <junjie.cao@intel.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> Subject: [PULL 6/8] vfio/igd: Make MTL/ARL guests fall back to BAR-based framebuffer access Date: Thu, 15 Oct 2026 14:20:53 +0200 Message-ID: <20261015122055.888209-7-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066918770158500 From: Yuan Wang <yuan1.wang@intel.com> Meteor Lake and Arrow Lake GOP can read BAR0 MMIO offset 0x138914 to detect whether direct framebuffer access via DSM is available. In a VFIO passthrough VM, the guest cannot access the host DSM memory region via such a pointer. If the guest GOP enables that path, it may hand off a DSM-based framebuffer address that the guest cannot actually use. Intercept reads from the detection register and return 0 so the guest does not enable the DSM-based path and instead keeps using the standard BAR-based framebuffer address. Suggested-by: Tomita Moeko <tomitamoeko@gmail.com> Reviewed-by: Tomita Moeko <tomitamoeko@gmail.com> Reviewed-by: Bosheng Xue <bosheng.xue@intel.com> Reviewed-by: Junjie Cao <junjie.cao@intel.com> Reviewed-by: C=C3=A9dric Le Goater <clg@redhat.com> Signed-off-by: Yuan Wang <yuan1.wang@intel.com> Link: https://lore.kernel.org/qemu-devel/20260923052511.2842596-1-yuan1.wan= g@intel.com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- hw/vfio/igd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 5e6160763cefb9d9739dd0a6462137c49109e81a..4c7d6545924ca49cbe0285f77b4= 22517b1c59159 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -96,6 +96,8 @@ static int igd_gen(VFIOPCIDevice *vdev) case 0x4C00: /* Rocket Lake */ case 0x4600: /* Alder Lake */ case 0xA700: /* Raptor Lake */ + case 0x7D00: /* Meteor Lake / Arrow Lake */ + case 0xB600: /* Arrow Lake */ return 12; } =20 @@ -452,8 +454,30 @@ static bool vfio_pci_igd_override_gms(int gen, uint32_= t gms, uint32_t *gmch) return ret; } =20 -#define IGD_GGC_MMIO_OFFSET 0x108040 -#define IGD_BDSM_MMIO_OFFSET 0x1080C0 +#define IGD_GGC_MMIO_OFFSET 0x108040 +#define IGD_BDSM_MMIO_OFFSET 0x1080C0 +#define IGD_MTL_PCODE_STOLEN_ACCESS 0x138914 + +#define IGD_IS_MTL_OR_ARL(vdev) \ + ((((vdev)->device_id & 0xff00) =3D=3D 0x7d00) || \ + (((vdev)->device_id & 0xff00) =3D=3D 0xb600)) + +static uint64_t vfio_igd_pcode_stolen_access_read(void *opaque, hwaddr add= r, + unsigned size) +{ + return 0; +} + +static void vfio_igd_pcode_stolen_access_write(void *opaque, hwaddr addr, + uint64_t data, unsigned siz= e) +{ +} + +static const MemoryRegionOps vfio_igd_pcode_stolen_access_quirk =3D { + .read =3D vfio_igd_pcode_stolen_access_read, + .write =3D vfio_igd_pcode_stolen_access_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; =20 /* * IGD BAR0 DBUF_CTL sanitize quirk. @@ -547,7 +571,7 @@ static const MemoryRegionOps igd_dbuf_ctl_ops =3D { =20 void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) { - VFIOQuirk *ggc_quirk, *bdsm_quirk; + VFIOQuirk *ggc_quirk, *bdsm_quirk, *pcode_stolen_access_quirk; VFIOConfigMirrorQuirk *ggc_mirror, *bdsm_mirror; int gen; =20 @@ -562,6 +586,25 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 + /* + * MTL/ARL guests must keep using the BAR-based framebuffer address. + * Return 0 for PCODE stolen memory access detection (0x138914) so GOP + * stays on the standard access path in the VM. + */ + if (IGD_IS_MTL_OR_ARL(vdev)) { + pcode_stolen_access_quirk =3D vfio_quirk_alloc(1); + memory_region_init_io(pcode_stolen_access_quirk->mem, OBJECT(vdev), + &vfio_igd_pcode_stolen_access_quirk, vdev, + "vfio-igd-pcode-stolen-access-quirk", 4); + memory_region_add_subregion_overlap(vdev->bars[nr].region.mem, + IGD_MTL_PCODE_STOLEN_ACCESS, + pcode_stolen_access_quirk->mem, + 1); + + QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, + pcode_stolen_access_quirk, next); + } + if (vdev->igd_gms) { ggc_quirk =3D vfio_quirk_alloc(1); ggc_mirror =3D ggc_quirk->data =3D g_malloc0(sizeof(*ggc_mirror)); --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066920; cv=none; d=zohomail.com; s=zohoarc; b=Src9m7fT73ftA18X6ZVMBqNKyACCyAYVUN+frKTgU3ERgYqMZwObfza6CaOoPY0lRe//XShYS/HzxS8WXIUlfPkOckXfJ9mT1mdEGilYilmyc8wMjAlxS3x4GTkSanBJNi4vZyDQSBQ3QGxzcf7kefbndWkefmTwXAGhn/14sjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066920; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ullyBOj+y1vs0B10Sd7EyoQboW4UT4qycjBWYkvViCY=; b=aTnwKcnffRM8ibd2titSfhNXogiSk4SQ346pVkzjQcM8nqzXn5egnwK9JOwpBVruZaJnBs2u8R3/MeEyGiDcL2+fPOkhIbxU24kx0rObP3ZXqXOf2M7Eec+lVKtDKFpJZSa0NQt/HyGCE1QwM3ZZjhUhbXl9Kvwb4KYOG0sqXTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066920601297.4944382784321; Thu, 15 Oct 2026 05:22:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKSa-00031W-1r; Thu, 15 Oct 2026 08:21:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSV-0002xO-E6 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:19 -0400 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 <clg@redhat.com>) id 1xHKST-0005Jb-0M for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:18 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325--t5hOsYAPHqeJsIuV6ETGQ-1; Thu, 15 Oct 2026 12:21:13 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4566D1800628; Thu, 15 Oct 2026 12:21:12 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D4A5318002B6; Thu, 15 Oct 2026 12:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066874; 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=ullyBOj+y1vs0B10Sd7EyoQboW4UT4qycjBWYkvViCY=; b=MGiQs9j4Nhewuelx+/7DiZQ4HxIxkgJ5p9AWoJMv85q5sNfITpuRMVsK+eoK4WZ2UKbJgI 9VLWXqCKnDQryABKnGIvJx99WwpBhv8EY1eZZcUFsO+9n/3yuj0gofVnVrPJPtcnYlRpaR sJETcuxytJ3tpqbDXIfjoLBGgxyFn8s= X-MC-Unique: -t5hOsYAPHqeJsIuV6ETGQ-1 X-Mimecast-MFC-AGG-ID: -t5hOsYAPHqeJsIuV6ETGQ_1792066872 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Yuan Wang <yuan1.wang@intel.com>, Bosheng Xue <bosheng.xue@intel.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> Subject: [PULL 7/8] vfio/igd: Update igd-assign.txt for Intel MTL and newer platforms Date: Thu, 15 Oct 2026 14:20:54 +0200 Message-ID: <20261015122055.888209-8-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_PASS=-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: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066922962158500 From: Yuan Wang <yuan1.wang@intel.com> Update the igd-assign.txt documentation to reflect the addition of the 0006 patch in the ECI repository. This patch is required to enable support for Meteor Lake (MTL) and subsequent Intel platforms. Starting from MTL, the hardware-accessible BDSM (Base of Data Stolen Memory) register in the PCI configuration space has been removed. Instead, IGD devices now access stolen memory via MMIO BAR2 (LMEMBAR). Consequently, guest firmware no longer needs to program the legacy BDSM register. Reviewed-by: Bosheng Xue <bosheng.xue@intel.com> Signed-off-by: Yuan Wang <yuan1.wang@intel.com> Link: https://lore.kernel.org/qemu-devel/20260928084226.3537126-1-yuan1.wan= g@intel.com Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- docs/igd-assign.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/igd-assign.txt b/docs/igd-assign.txt index e54040335ba72dc971babb4d776e46d94f342f70..b9abfdbac3503f7e0e187a15fd0= 787d2bfef77f1 100644 --- a/docs/igd-assign.txt +++ b/docs/igd-assign.txt @@ -263,6 +263,6 @@ Footnotes [2] # echo "vfio-pci" > /sys/bus/pci/devices/0000:00:02.0/driver_override [3] https://web.archive.org/web/20240827012422/https://bugzilla.tianocore.= org/show_bug.cgi?id=3D935 Tianocore bugzilla was down since Jan 2025 :( -[4] https://eci.intel.com/docs/3.3/components/kvm-hypervisor.html, Patch 0= 001-0004 +[4] https://eci.intel.com/docs/3.3/components/kvm-hypervisor.html, Patch 0= 001-0004, 0006 [5] https://github.com/tomitamoeko/VfioIgdPkg [6] https://winraid.level1techs.com/t/tool-guide-news-uefi-bios-updater-ub= u/30357 --=20 2.56.0 From nobody Mon Nov 23 04:44:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792066923; cv=none; d=zohomail.com; s=zohoarc; b=VkdkQFtv5IvYJtyCYm62aoPmT/2m9Sb/7sLQONAKfhLzplfBN0CrTQp5zsupESuKnr9cVIcBJd4HosRzptljYeB801nMw3n4hsOPsIH0xhKzNWlfix1hq466s6TMWs0C3IDvrmHu4jFVoTi1wDdoSsYja6BFUWz4LBd4c+b/QgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792066923; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zZKOYC/lQ7Latj9cIvjvvB3GgFXd31lG/RDxcK2Y5XQ=; b=Ef1SUPo0TglwI438nDixoevhywv+iitxQffeJVilrnk+ImBRELZfcRm9q4OcFcUKWbcvgAG1rMeXz1Qu21vlTN5oGi3ViXemN/aC89yGiUw4sZFhmkv8ypTBNy+ZxPjdyK6CM5RZF8vJG2iqBVRzkJrxbLTACyJf9pO7iZN5FQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from=<clg@redhat.com> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792066923140874.9863569226852; Thu, 15 Oct 2026 05:22:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1xHKSh-00033V-1R; Thu, 15 Oct 2026 08:21:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <clg@redhat.com>) id 1xHKSZ-00031X-Ew for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:23 -0400 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 <clg@redhat.com>) id 1xHKSV-0005KY-Eu for qemu-devel@nongnu.org; Thu, 15 Oct 2026 08:21:22 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-GeBEtQP3N2iVb-GdUnJ4SQ-1; Thu, 15 Oct 2026 12:21:15 +0000 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65AE7195606E; Thu, 15 Oct 2026 12:21:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.48.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D613518004D2; Thu, 15 Oct 2026 12:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792066878; 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=zZKOYC/lQ7Latj9cIvjvvB3GgFXd31lG/RDxcK2Y5XQ=; b=iWLnELBhSjlDnbvP/rDWjpmT+nBXAeALZnq1I38VL4OTl/b9MPZ5xN4QQD04hI7g1393B7 dBLkQOmoF176kJsH49hJC4B9POWYrNIxGejMNRRuMM9I9/6c0uyuL+AEIwNAWak7gzsNtU k5MY2Y+gI1YlYS8iAg0d5HDMOfVj4vg= X-MC-Unique: GeBEtQP3N2iVb-GdUnJ4SQ-1 X-Mimecast-MFC-AGG-ID: GeBEtQP3N2iVb-GdUnJ4SQ_1792066874 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com> To: qemu-devel@nongnu.org Cc: Pankaj Kumar <pshit@nvidia.com>, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com>, Avihai Horon <avihaih@nvidia.com> Subject: [PULL 8/8] vfio/migration: Don't reset a device on a declined stop transition Date: Thu, 15 Oct 2026 14:20:55 +0200 Message-ID: <20261015122055.888209-9-clg@redhat.com> In-Reply-To: <20261015122055.888209-1-clg@redhat.com> References: <20261015122055.888209-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, 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_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792066924914158500 From: Pankaj Kumar <pshit@nvidia.com> QEMU resets a VFIO device whenever a migration state transition it requests fails. This is done by vfio_migration_set_state_or_reset(), which passes VFIO_DEVICE_STATE_ERROR as the recover state, forcing an immediate VFIO_DEVICE_RESET. However, a device may legitimately decline a state transition, e.g. a vGPU that refuses to stop while a profiling/debug session is active in the guest. Such a device is still healthy and running the guest, so resetting it destr= oys a perfectly good VM. Instead of resetting on a declined stop, recover the device to its current state. The current device state is always a valid, already-reached state, so recovering to it is effectively a no-op transition that cannot itself fail = and trigger a reset. Introduce a helper, vfio_migration_set_state_or_recover(), that selects the recover state based on the transition direction, and route the vmstate chan= ge and save-completion paths through it: - vfio_vmstate_change() and vfio_vmstate_change_prepare() recover to the current device state for the stop direction. The resume direction keeps ERROR as the recover state, since a device that cannot resume is genuine= ly broken. - vfio_save_complete_precopy() recovers to the current device state rather than STOP. If it runs after an earlier stop was declined (the device sti= ll in a running state), the stop-copy attempt is then rolled back instead of resetting the device. The existing vfio_migration_set_state_or_reset() is retained for the paths that must still reset on failure (save cleanup and the migration-failed notifier). This lets vendor drivers decline a stop as a matter of policy without losing the guest, and lets such drivers drop their own workarounds that swallowed = the spurious reset. Signed-off-by: Pankaj Kumar <pshit@nvidia.com> Reviewed-by: C=C3=A9dric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/qemu-devel/20261013044520.2439021-1-pshit@nvi= dia.com Reviewed-by: Avihai Horon <avihaih@nvidia.com> Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- hw/vfio/migration.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 73c49d8c24f21803de7c8615da63abecfd76b882..69d50cebdd5f1636a1f8b03967b= 6b01e7979e532 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -246,6 +246,25 @@ vfio_migration_set_state_or_reset(VFIODevice *vbasedev, VFIO_DEVICE_STATE_ERROR, errp); } =20 +/* + * On a stop-direction transition failure, recover the device to its curre= nt + * state instead of resetting it: the current state is valid and already + * reached, so recovering to it is effectively a no-op that cannot itself = fail. + * On a resume-direction (running) failure, the device is genuinely broken= , so + * reset it by using ERROR as the recover state. + */ +static int +vfio_migration_set_state_or_recover(VFIODevice *vbasedev, + enum vfio_device_mig_state new_state, + bool running, Error **errp) +{ + VFIOMigration *migration =3D vbasedev->migration; + enum vfio_device_mig_state recover_state =3D + running ? VFIO_DEVICE_STATE_ERROR : migration->device_state; + + return vfio_migration_set_state(vbasedev, new_state, recover_state, er= rp); +} + static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev, uint64_t data_size) { @@ -771,9 +790,16 @@ static int vfio_save_complete_precopy(QEMUFile *f, voi= d *opaque) =20 trace_vfio_save_complete_precopy_start(vbasedev->name); =20 - /* We reach here with device state STOP or STOP_COPY only */ - ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, - VFIO_DEVICE_STATE_STOP, &local_err); + /* + * We normally reach here with the device in STOP or STOP_COPY. Howeve= r, if + * an earlier stop transition was declined by the device, it may still= be in + * a running state. Recover to the current device state rather than ST= OP, so + * a device that declines the stop-copy transition is rolled back to i= ts + * current state instead of being reset out from under the guest. + */ + ret =3D vfio_migration_set_state_or_recover(vbasedev, + VFIO_DEVICE_STATE_STOP_COPY, + false, &local_err); if (ret) { error_report_err(local_err); return ret; @@ -1009,7 +1035,8 @@ static void vfio_vmstate_change_prepare(void *opaque,= bool running, vfio_final_precopy_reinit_check(vbasedev); } =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); + ret =3D vfio_migration_set_state_or_recover(vbasedev, new_state, runni= ng, + &local_err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() @@ -1040,7 +1067,8 @@ static void vfio_vmstate_change(void *opaque, bool ru= nning, RunState state) VFIO_DEVICE_STATE_STOP; } =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); + ret =3D vfio_migration_set_state_or_recover(vbasedev, new_state, runni= ng, + &local_err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() --=20 2.56.0