From nobody Sun Apr 12 07:24:44 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=1770877790; cv=none; d=zohomail.com; s=zohoarc; b=YKYQG2+fitoF+z1gQ40jV8wQn2Ez6lZEW6NrhtsSZlikQwcX6cez4kKnjQc7fxyw/5RlzenProOr4x9d0d8wkbSx1KmWDw8e/Rf4EEN61lzxBiEoWcHnITAhpncXeFHI5892KTceagoL0hP9so6+RWIO8NPhBNcepoqkuPa5AAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770877790; h=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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Lc7U1GbS1JHxjc6G1Vv9nRCpYH775c/aB7pSkgG/wFs=; b=mHlb76AJifQ4VYiZmy5TcslkfciZxV765pLgaTwdDGitq9SHTpb+8ywn5Lhv1SBBzgyQZV2RVyISN4C8n6AT0WjDz3gAKg4G/DN26XQ3OTJ45PoUeHM0DkuY3egahLNP2Rz8pSeZHeV9kLG/+bRhRzbo0wkUbAvqXgrjUmmRrS0= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770877790463583.5985232857577; Wed, 11 Feb 2026 22:29:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqQAr-0000yq-CW; Thu, 12 Feb 2026 01:27:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqQAW-0000Ri-PO for qemu-devel@nongnu.org; Thu, 12 Feb 2026 01:27:23 -0500 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 ) id 1vqQAT-0005M9-Pw for qemu-devel@nongnu.org; Thu, 12 Feb 2026 01:27:15 -0500 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-rzUMDyRrMGOsw0DY62gVgA-1; Thu, 12 Feb 2026 01:27:11 -0500 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3545dbb7ee6so2365795a91.3 for ; Wed, 11 Feb 2026 22:27:11 -0800 (PST) Received: from rhel9-box.lan ([122.164.27.113]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-3567e7d95d8sm4894122a91.2.2026.02.11.22.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 22:27:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770877633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lc7U1GbS1JHxjc6G1Vv9nRCpYH775c/aB7pSkgG/wFs=; b=Gsl7rIn9f/mGs/sB6kSZmpZo6b/EMvb1K/nunuUXPu99NZmsLBJEaCfiCgZRrTHD1TxdBE axNpfY0/8Byzo+CN7kUZmxN2MNCH134k+ssPJOPtisHzcaNQ/8FAyu3O2+YbdtCibJZ0ek y8bA0BzcQvMyihPEDN0tntVqy/LbuVQ= X-MC-Unique: rzUMDyRrMGOsw0DY62gVgA-1 X-Mimecast-MFC-AGG-ID: rzUMDyRrMGOsw0DY62gVgA_1770877631 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770877631; x=1771482431; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lc7U1GbS1JHxjc6G1Vv9nRCpYH775c/aB7pSkgG/wFs=; b=KUuCa0Cg8xI6dXjPJNqzRJ+wDHfQdl+/sq/xImyvydXkD7dOwfDVRmGoULzK4LIk7e Rd2GQ7V+KP8IjOWE1PQfdmha+xXKbb1OXlF7Egn05XxkOpxRh5gAau1tIcoVoz3kTw2+ qFVReuu9bDmaYVXW9wMZeiVkqFgA3nzk6Yq+CQO4iE42VdTzA7s8lQH9rqXtKq97Lppd VIwRYgmn2qJ2icdlfethGMNCmYNN1WJSJD1cvsQG1eHOCrZhw/yFpTzFHQEsyMtUR4sm QHTVYRXPhJlS25be3bQxSbRYl6WRyfTJRTgzmRD5JkBIgViwFZRaxE6Vk+qtKdDrM+H/ 2FEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770877631; x=1771482431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Lc7U1GbS1JHxjc6G1Vv9nRCpYH775c/aB7pSkgG/wFs=; b=fdj4KYXIP1TKSQ8xOBIyBod9KRh5VxrIlovSTfYasQVTXBOglnRIFWyIie/SH9Vwui +qPOe3seKLxLcKGxYmyT0k4eYAzJiMWivFjQebDNakYS37ReIy49dhTjgR08KyLKwmfm hFNKGIDWVSI0cBsFAhksocFjFkv6txT5xu6APIZt/mpj+1xmh5Ijm/G3BHCQW7KxskUV jhoFBAUhI3gWt/vEBuOEw9SbGjELZGejrNrpRbedJATUU1t1IYmUL/GILeuTuSuO35Ko JYfVnyaCOm0RYcKQTqeFdMOxO2iJe2dMld392DKbPO7oIJV2X9vxeQavo/uR6Hb4RPP4 4Viw== X-Forwarded-Encrypted: i=1; AJvYcCVnugi2Fk468IihsGCCRnXJreLaAlozyUb1+kbQgcNK/9IvmtlOQfOOblQ3aKPtOckTQlNdvOg7MPr1@nongnu.org X-Gm-Message-State: AOJu0YzIPgZrWY/3u/bNu6qXe4WZPrQA4EPJHWDfcQHZxeHS21KqCs+Z RsEGwnPQmYyZ+PV761PpSdkXEMZbgjGaHjF9OKvnjX+RNEvO/xwYpyuVh0DKs033eMAyYgfqlkA l/vFdrYS4OI88HzW9QqpiyKEUbbUp1eD/WZgrb/QN9B0/Qm35mPQoCmf5 X-Gm-Gg: AZuq6aI9XRMFQ8ukKdi7Vy25BkqcQ+ZfqqKSrzK30y/uk28qWRLAJPROD9AjljqlW69 6u3iQhC9+3UIeo1iqiuULAY9jwF8+TFd7rL/XPB3lWEhX6DcPI8LGz2lWSW3mkUglKtIl+j+r4b /8g2Kz1B5WuUaJEhog1FRYES4X5UgFZAWyxXD4sMXb6Gz1yBjt4HB48HxmrOn+2yQsli9k3QRAx GLk+8R3gLlHu/CQCqNTPYAq5d5m52OQcVhoarLK/Sf/Q4beP/qPIqzyj4k1GWdlPskgjSZ8v8/d HAsW/BgiPjOpGDFkp3A7mPcNcE+iWmv1aNOMMozKmJVeS7ay59ydYU1VhqmxDUA2waCJ9IaZ3T1 1HWp76j3PHZsW2FOpCUJklY/sZbG3atVHtd7a/ZZJaaiqYtN0PSFbKiM= X-Received: by 2002:a17:90a:d2ce:b0:341:2150:4856 with SMTP id 98e67ed59e1d1-35693d5e966mr1153069a91.17.1770877630752; Wed, 11 Feb 2026 22:27:10 -0800 (PST) X-Received: by 2002:a17:90a:d2ce:b0:341:2150:4856 with SMTP id 98e67ed59e1d1-35693d5e966mr1153054a91.17.1770877630409; Wed, 11 Feb 2026 22:27:10 -0800 (PST) From: Ani Sinha To: David Woodhouse , Paul Durrant , Paolo Bonzini , Marcelo Tosatti Cc: kraxel@redhat.com, Ani Sinha , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v4 26/31] kvm/xen-emu: re-initialize capabilities during confidential guest reset Date: Thu, 12 Feb 2026 11:55:10 +0530 Message-ID: <20260212062522.99565-27-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260212062522.99565-1-anisinha@redhat.com> References: <20260212062522.99565-1-anisinha@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.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, 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_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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 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: 1770877793336154100 Content-Type: text/plain; charset="utf-8" On confidential guests KVM virtual machine file descriptor changes as a part of the guest reset process. Xen capabilities needs to be re-initialize= d in KVM against the new file descriptor. Signed-off-by: Ani Sinha --- target/i386/kvm/xen-emu.c | 50 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 52de019834..69527145eb 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -44,9 +44,12 @@ =20 #include "xen-compat.h" =20 +NotifierWithReturn xen_vmfd_change_notifier; +static bool hyperv_enabled; static void xen_vcpu_singleshot_timer_event(void *opaque); static void xen_vcpu_periodic_timer_event(void *opaque); static int vcpuop_stop_singleshot_timer(CPUState *cs); +static int do_initialize_xen_caps(KVMState *s, uint32_t hypercall_msr); =20 #ifdef TARGET_X86_64 #define hypercall_compat32(longmode) (!(longmode)) @@ -54,6 +57,30 @@ static int vcpuop_stop_singleshot_timer(CPUState *cs); #define hypercall_compat32(longmode) (false) #endif =20 +static int xen_handle_vmfd_change(NotifierWithReturn *n, + void *data, Error** errp) +{ + int ret; + + /* we are not interested in pre vmfd change notification */ + if (((VmfdChangeNotifier *)data)->pre) { + return 0; + } + + ret =3D do_initialize_xen_caps(kvm_state, XEN_HYPERCALL_MSR); + if (ret < 0) { + return ret; + } + + if (hyperv_enabled) { + ret =3D do_initialize_xen_caps(kvm_state, XEN_HYPERCALL_MSR_HYPERV= ); + if (ret < 0) { + return ret; + } + } + return 0; +} + static bool kvm_gva_to_gpa(CPUState *cs, uint64_t gva, uint64_t *gpa, size_t *len, bool is_write) { @@ -111,15 +138,16 @@ static inline int kvm_copy_to_gva(CPUState *cs, uint6= 4_t gva, void *buf, return kvm_gva_rw(cs, gva, buf, sz, true); } =20 -int kvm_xen_init(KVMState *s, uint32_t hypercall_msr) +static int do_initialize_xen_caps(KVMState *s, uint32_t hypercall_msr) { + int xen_caps, ret; const int required_caps =3D KVM_XEN_HVM_CONFIG_HYPERCALL_MSR | KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL | KVM_XEN_HVM_CONFIG_SHARED_INF= O; + struct kvm_xen_hvm_config cfg =3D { .msr =3D hypercall_msr, .flags =3D KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL, }; - int xen_caps, ret; =20 xen_caps =3D kvm_check_extension(s, KVM_CAP_XEN_HVM); if (required_caps & ~xen_caps) { @@ -143,6 +171,21 @@ int kvm_xen_init(KVMState *s, uint32_t hypercall_msr) strerror(-ret)); return ret; } + return xen_caps; +} + +int kvm_xen_init(KVMState *s, uint32_t hypercall_msr) +{ + int xen_caps; + + xen_caps =3D do_initialize_xen_caps(s, hypercall_msr); + if (xen_caps < 0) { + return xen_caps; + } + + if (!hyperv_enabled && (hypercall_msr =3D=3D XEN_HYPERCALL_MSR_HYPERV)= ) { + hyperv_enabled =3D true; + } =20 /* If called a second time, don't repeat the rest of the setup. */ if (s->xen_caps) { @@ -185,6 +228,9 @@ int kvm_xen_init(KVMState *s, uint32_t hypercall_msr) xen_primary_console_reset(); xen_xenstore_reset(); =20 + xen_vmfd_change_notifier.notify =3D xen_handle_vmfd_change; + kvm_vmfd_add_change_notifier(&xen_vmfd_change_notifier); + return 0; } =20 --=20 2.42.0