From nobody Tue Feb 10 00:24:01 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=1768224676; cv=none; d=zohomail.com; s=zohoarc; b=nqUSndEVnjED0lWb5TzP+t7Qlp/aHmgqjoEcCOfwIzFMQ8YtYAcYwEndn0pIJQ7oSPvLax0D4VTFC8Ma1n6lxUMyD6eS+zHXosTvTn/Is4AwInQVPcLK/+XDdR9HvVGf0T3d8BCs/L8Pv3iL1wE2fc+BzZ47dFWo76+FcnHFRa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768224676; 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=/Xl2NZDHarHkXqS5yrKrfSXN4c45GQhJC2FoUsQnchs=; b=ed/ydS0WAZaIHY5Ayf8yOVACXYSgXTpRI+qpnKeHyvOnNPKSISKJPY45kN4sDL18q6AyXlotpBj/iOyPaLq/9HiTkuaZIzWcnPo0T0MRfrHz4Dy7IEG2bQFrrsF2pdRyD1eAHaFL4+dpw1rHomgo9aFceyv7wfpVeqQZ3JbD2p4= 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 17682246763081023.1534586893578; Mon, 12 Jan 2026 05:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfHuL-0003m5-6Y; Mon, 12 Jan 2026 08:24:33 -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 1vfHuC-0003Hm-DQ for qemu-devel@nongnu.org; Mon, 12 Jan 2026 08:24:26 -0500 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 1vfHuA-0003pZ-9n for qemu-devel@nongnu.org; Mon, 12 Jan 2026 08:24:23 -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-325-UcPZHL8rMjqjQ32rrMXqGQ-1; Mon, 12 Jan 2026 08:24:17 -0500 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-34c37b8dc4fso12168641a91.2 for ; Mon, 12 Jan 2026 05:24:16 -0800 (PST) Received: from rhel9-box.lan ([110.227.88.119]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-c4cc05cd87asm17544771a12.15.2026.01.12.05.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 05:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768224260; 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=/Xl2NZDHarHkXqS5yrKrfSXN4c45GQhJC2FoUsQnchs=; b=al0S5g+BAd6PtHUYUtUhnuEtq6hgRHZ4b0/p/tf58NzWxhGvVxuwTqzz9637iQ0bFjXlzi PyfzqwEbvgi4qehrl6z/JOC3N6JoDKlNp5Y0qghSlO2H44z3o+l20FpXZX2KyZs3sdXHih DGsATlgucwUtX+MrC9Xz7jOaFUQDwJk= X-MC-Unique: UcPZHL8rMjqjQ32rrMXqGQ-1 X-Mimecast-MFC-AGG-ID: UcPZHL8rMjqjQ32rrMXqGQ_1768224256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1768224256; x=1768829056; 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=/Xl2NZDHarHkXqS5yrKrfSXN4c45GQhJC2FoUsQnchs=; b=YS+h+uFUq6RWQSjFqCmH8ixDr1BVLg2779ncLrppIfG2miHOtWo+l1UoJQzmIUmhNt qWTmriJS+dKeGDeX52TruKU0pNhz2w/v9NVPZiaxTZyxgpYEEMF1NCK21e+zpiDHX7cX xBiL7kMn/rMFGy3vKZZJH4MBZHtyBaDzGigSdHKUg09OAZQiXVh4t9zamtBmMAb4/VgL 3HmyKWgCFv4yZNN5Z+gxbNo8OGLAvOfYY9DjhmUUVNQQq/NHVPBiSE3zLiWOTwN3F4MS BtICRGlTgtde3xDfbCE/9mSR83ZWquUBjDjifWvwmK5SeGE0rDmGjHtZDLJ9AYK73wLa DRPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768224256; x=1768829056; 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=/Xl2NZDHarHkXqS5yrKrfSXN4c45GQhJC2FoUsQnchs=; b=YVnE8CrfR3rGYNcYn63AFaurY5yC6YHBTsB1F12M2ThKswsnzIA44q+HBtY2M+7S0U YG4cXeP7zI07lzS9hy2kPGiKFLB7FlAsNcVYfQy3+sP6tvoPD66BaEzmjMoFo6OXdqd+ I89NDlR7/IhvwzRCAf/sPk7/NWXwIR5Wxz0xbXMAhEmHlktq7Nx4EXDz+M/RfQFi5bzx mP7T56mQHAm80/hCZkLFjjGuKu/SjF+UqKA6iyji2m/Y9vP5LDZW1ASGL1+q7jmyJ6Dz rfdOd+A3kNvvHMGexRIVRDn3j0qr33dfB9Anup7i2qINRrB4mvjBoCiTsIzKx71vWyb5 pLDQ== X-Forwarded-Encrypted: i=1; AJvYcCXTP4dyJm4h1tKBVWbxQ+XuqRXiq3mAy+3fvq8Ceb47/dMpra+3Hq/GaJnPpUtiqB5ySSB0MKQmQ/VH@nongnu.org X-Gm-Message-State: AOJu0YzUjRMRER81/ktpER9k9Vn29qtgcBqr3zsCZby0f+RTaSe5y4X/ P/u97S0C86Wh9k13F5QzVsQcZYFL/GU161Wq0Cji+fIk6irfkMjGQ0bJ8zKE7HowL5gabBb2xBt HxmVM4V11CI9JpSKPyh8PqvkenfppDII47tSckiSSGR5tSrqqYMADh+13 X-Gm-Gg: AY/fxX6M3uj5A4DNh8Wm4Q7Pepnxdx/Ab13XAVqPVUqpK3Hb+eTL5ABm73kO/sjf2ak +j7cXRlnDdEX9powNa3ZILsyF+zM+0WDpSN8Xd2ruMF1qTJzGBIyW+/uVjNHFDMS+ozh/7j2gqr dKLfCZxXajfM2fjdt+S3/uRJitkVdb4ZTNEjvWRAHIIpmpbq6P0n+HnD9Lb3zK+fvsxyqVTjY6v iwQWt7D2je170SUOUlbhMNEUIgZy0P/PuJRwEJUqFW9cbkdDLqv9AMjo8yoJAPjAcHz/b6kHnZV ffh5P2L0klAZMagmRMNdLQe+3tFgUcQhVaj5Mij6iUM25eIMD8FTvTOjhS17/ZNLfVA2IOfZJK4 i6fgXjoC6WRn8Zhn5qT2uvtcoD1CxZRrGrTrJLi9SVN8= X-Received: by 2002:a05:6a21:3389:b0:364:13e1:10f0 with SMTP id adf61e73a8af0-3898f990467mr15895550637.48.1768224255806; Mon, 12 Jan 2026 05:24:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkV+5Pj+vPwdorDJk/3GEPIk0RVkmzj9pSTKP97TxM+k+HNRr4FYBWDj0fQukT5a54s7G7qw== X-Received: by 2002:a05:6a21:3389:b0:364:13e1:10f0 with SMTP id adf61e73a8af0-3898f990467mr15895534637.48.1768224255391; Mon, 12 Jan 2026 05:24:15 -0800 (PST) From: Ani Sinha To: Paolo Bonzini , Marcelo Tosatti , Zhao Liu Cc: Ani Sinha , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 19/32] i386/sev: add support for confidential guest reset Date: Mon, 12 Jan 2026 18:52:32 +0530 Message-ID: <20260112132259.76855-20-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260112132259.76855-1-anisinha@redhat.com> References: <20260112132259.76855-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 (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.129.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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1768224677383158500 Content-Type: text/plain; charset="utf-8" When the KVM VM file descriptor changes as a part of the confidential guest reset mechanism, it necessary to create a new confidential guest context and re-encrypt the VM memeory. This happens for SEV-ES and SEV-SNP virtual mach= ines as a part of SEV_LAUNCH_FINISH, SEV_SNP_LAUNCH_FINISH operations. A new resettable interface for SEV module has been added. A new reset callb= ack for the reset 'exit' state has been implemented to perform the above operat= ions when the VM file descriptor has changed during VM reset. Tracepoints has been added also for tracing purpose. Signed-off-by: Ani Sinha --- target/i386/sev.c | 52 ++++++++++++++++++++++++++++++++++++++++ target/i386/trace-events | 1 + 2 files changed, 53 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index d7425dde96..d45356843c 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -30,8 +30,10 @@ #include "system/kvm.h" #include "kvm/kvm_i386.h" #include "sev.h" +#include "system/cpus.h" #include "system/system.h" #include "system/runstate.h" +#include "system/reset.h" #include "trace.h" #include "migration/blocker.h" #include "qom/object.h" @@ -85,6 +87,10 @@ typedef struct QEMU_PACKED PaddedSevHashTable { uint8_t padding[ROUND_UP(sizeof(SevHashTable), 16) - sizeof(SevHashTab= le)]; } PaddedSevHashTable; =20 +static void sev_handle_reset(Object *obj, ResetType type); + +SevKernelLoaderContext sev_load_ctx =3D {}; + QEMU_BUILD_BUG_ON(sizeof(PaddedSevHashTable) % 16 !=3D 0); =20 #define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" @@ -128,6 +134,7 @@ struct SevCommonState { uint8_t build_id; int sev_fd; SevState state; + ResettableState reset_state; =20 QTAILQ_HEAD(, SevLaunchVmsa) launch_vmsa; }; @@ -1984,6 +1991,38 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport= *cgs, Error **errp) return 0; } =20 +/* + * handle sev vm reset + */ +static void sev_handle_reset(Object *obj, ResetType type) +{ + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + SevCommonStateClass *klass =3D SEV_COMMON_GET_CLASS(sev_common); + + if (!sev_common) { + return; + } + + if (!runstate_is_running()) { + return; + } + + sev_add_kernel_loader_hashes(&sev_load_ctx, &error_fatal); + if (!sev_check_state(sev_common, SEV_STATE_RUNNING)) { + /* this calls sev_snp_launch_finish() etc */ + klass->launch_finish(sev_common); + } + + trace_sev_handle_reset(); + return; +} + +static ResettableState *sev_reset_state(Object *obj) +{ + SevCommonState *sev_common =3D SEV_COMMON(obj); + return &sev_common->reset_state; +} + int sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp) { @@ -2462,6 +2501,8 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderCont= ext *ctx, Error **errp) return false; } =20 + /* save the context here so that it can be re-used when vm is reset */ + memcpy(&sev_load_ctx, ctx, sizeof(*ctx)); return klass->build_kernel_loader_hashes(sev_common, area, ctx, errp); } =20 @@ -2722,8 +2763,16 @@ static void sev_common_class_init(ObjectClass *oc, const void *data) { ConfidentialGuestSupportClass *klass =3D CONFIDENTIAL_GUEST_SUPPORT_CL= ASS(oc); + ResettableClass *rc =3D RESETTABLE_CLASS(oc); =20 klass->kvm_init =3D sev_common_kvm_init; + /* + * the exit phase makes sure sev handles reset after all legacy resets + * have taken place (in the hold phase) and IGVM has also properly + * set up the boot state. + */ + rc->phases.exit =3D sev_handle_reset; + rc->get_state =3D sev_reset_state; =20 object_class_property_add_str(oc, "sev-device", sev_common_get_sev_device, @@ -2758,6 +2807,8 @@ sev_common_instance_init(Object *obj) cgs->get_mem_map_entry =3D cgs_get_mem_map_entry; cgs->set_guest_policy =3D cgs_set_guest_policy; =20 + qemu_register_resettable(OBJECT(sev_common)); + QTAILQ_INIT(&sev_common->launch_vmsa); =20 /* add migration blocker */ @@ -2779,6 +2830,7 @@ static const TypeInfo sev_common_info =3D { .abstract =3D true, .interfaces =3D (const InterfaceInfo[]) { { TYPE_USER_CREATABLE }, + { TYPE_RESETTABLE_INTERFACE }, { } } }; diff --git a/target/i386/trace-events b/target/i386/trace-events index 51301673f0..b320f655ee 100644 --- a/target/i386/trace-events +++ b/target/i386/trace-events @@ -14,3 +14,4 @@ kvm_sev_attestation_report(const char *mnonce, const char= *data) "mnonce %s data kvm_sev_snp_launch_start(uint64_t policy, char *gosvw) "policy 0x%" PRIx64= " gosvw %s" kvm_sev_snp_launch_update(uint64_t src, uint64_t gpa, uint64_t len, const = char *type) "src 0x%" PRIx64 " gpa 0x%" PRIx64 " len 0x%" PRIx64 " (%s page= )" kvm_sev_snp_launch_finish(char *id_block, char *id_auth, char *host_data) = "id_block %s id_auth %s host_data %s" +sev_handle_reset(void) "" --=20 2.42.0