From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757592024; cv=none; d=zohomail.com; s=zohoarc; b=XmTgueJTk6ymQOSSa/T4lgRc/DPhRSKxB4uGyVrKv0L2mBr8aPpWBzSX/Iy57jsq1rRgdNB9u00nFD8+U+NfOuuleqez8L22sXCFPxT9Uw19Xr7S6GOFiPbU301x4OK8QBD555nq4ixapSyJytg2jVXwBmUBDY6M+HHov45vjjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757592024; 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=R7PBKryPEwmg9CDdCMnrGs1OsoN898y3QtKDLqGzrZs=; b=TOKW/FSINdrzoeGUFO44zY4E4pn4T9dhCAO7IuNsdGqXO422k0RZPVyGUwC+QruIVtly5OShzwdloKfHiakopLebSf1bL5kflM4trpT9QvPJmbF6ipUoI3SEWuUG3ble7hdosZ/xTIQN8XY8eKgFIUYDSdWUAupLnEJ0TxxnSiA= 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 1757592024363689.5148331406999; Thu, 11 Sep 2025 05:00:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfwL-0002OW-ST; Thu, 11 Sep 2025 07:58:14 -0400 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 1uwfwG-0002Ng-7s for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:09 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfwB-0006Om-Se for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:06 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 72D1344EE0; Thu, 11 Sep 2025 11:58:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8952CC4CEF1; Thu, 11 Sep 2025 11:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591881; bh=/D55pFyt3VJdmuGX0Hft3q3YJw6AKpeKJBy5hh1wrNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=si55fs3taRGv6SAX3cphNIIaluOEZV9VQnKLgYUNGSmXMaNchVlUd+JsPJ2xwRiH8 zwH6MXBgSOZRGaP4LPMkkQhyde1HwI8aHaKga9zE3IjfC5RZUkmv4onCzhiGPP02UX enhtrEf8Iaae5HK5+5vS+BnHyKz3Bx5Dx5X/jQUriX+6WYd4QVc35fi/N0evXgKXry GLmfdagiyDawSQmpxtB7XHDWFUfV/bJRlziv2YQ+BLgNQnfIfKsCLrwqqUhRe29yXw 4rVtjJdnrKQyz5EUu395/OcvyurmkfpmHGOA6mM/N96kLdsOSAqRXfi+UMLvMYmpL/ XPfcoggS7JszA== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins Subject: [RFC PATCH 1/7] target/i386: SEV: Consolidate SEV feature validation to common init path Date: Thu, 11 Sep 2025 17:24:20 +0530 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @kernel.org) X-ZM-MESSAGEID: 1757592027113116600 Content-Type: text/plain; charset="utf-8" Currently, check_sev_features() is called in multiple places when processing IGVM files: both when processing the initial VMSA SEV features from IGVM, as well as when validating the full contents of the VMSA. Move this to a single point in sev_common_kvm_init() to simplify the flow, as well as to re-use this function when VMSA SEV features are being set without using IGVM files. Since check_sev_features() relies on SVM_SEV_FEAT_SNP_ACTIVE being set in VMSA SEV features depending on the guest type, set this flag by default when creating SEV-SNP guests. When using IGVM files, this field is anyway over-written so that validation in check_sev_features() is still relevant. Finally, add a check to ensure SEV features aren't also set through qemu cli if using IGVM files. Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 1057b8ab2c60..243e9493ba8d 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -586,9 +586,6 @@ static int check_vmsa_supported(SevCommonState *sev_com= mon, hwaddr gpa, vmsa_check.x87_fcw =3D 0; vmsa_check.mxcsr =3D 0; =20 - if (check_sev_features(sev_common, vmsa_check.sev_features, errp) < 0)= { - return -1; - } vmsa_check.sev_features =3D 0; =20 if (!buffer_is_zero(&vmsa_check, sizeof(vmsa_check))) { @@ -1892,20 +1889,29 @@ static int sev_common_kvm_init(ConfidentialGuestSup= port *cgs, Error **errp) * as SEV_STATE_UNINIT. */ if (x86machine->igvm) { + if (sev_common->sev_features & ~SVM_SEV_FEAT_SNP_ACTIVE) { + error_setg(errp, "%s: SEV features can't be specified when= using IGVM files", + __func__); + return -1; + } if (IGVM_CFG_GET_CLASS(x86machine->igvm) ->process(x86machine->igvm, machine->cgs, true, errp) = =3D=3D -1) { return -1; } - /* - * KVM maintains a bitmask of allowed sev_features. This does = not - * include SVM_SEV_FEAT_SNP_ACTIVE which is set accordingly by= KVM - * itself. Therefore we need to clear this flag. - */ - args.vmsa_features =3D sev_common->sev_features & - ~SVM_SEV_FEAT_SNP_ACTIVE; } =20 + if (check_sev_features(sev_common, sev_common->sev_features, errp)= < 0) { + return -1; + } + + /* + * KVM maintains a bitmask of allowed sev_features. This does not + * include SVM_SEV_FEAT_SNP_ACTIVE which is set accordingly by KVM + * itself. Therefore we need to clear this flag. + */ + args.vmsa_features =3D sev_common->sev_features & ~SVM_SEV_FEAT_SN= P_ACTIVE; + ret =3D sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_er= ror); break; } @@ -2518,9 +2524,6 @@ static int cgs_set_guest_state(hwaddr gpa, uint8_t *p= tr, uint64_t len, __func__); return -1; } - if (check_sev_features(sev_common, sa->sev_features, errp) < 0= ) { - return -1; - } sev_common->sev_features =3D sa->sev_features; } return 0; @@ -3127,6 +3130,7 @@ sev_snp_guest_instance_init(Object *obj) =20 /* default init/start/finish params for kvm */ sev_snp_guest->kvm_start_conf.policy =3D DEFAULT_SEV_SNP_POLICY; + SEV_COMMON(sev_snp_guest)->sev_features |=3D SVM_SEV_FEAT_SNP_ACTIVE; } =20 /* guest info specific to sev-snp */ --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757592047; cv=none; d=zohomail.com; s=zohoarc; b=C2QceDrV2qzizPCXRTcPc33bZk28i3H8s5eJ6UnCnOjJfWTcGgYQe18W+mevjorUhY0sZRb+1wXQLQXFnBY0HBf8e8uIGD+on+OEEvzVfyO1rg4/rrPQwzEP5z1au2LTqQWHpuk1ZjhIlc9FexV6hZ3HdlBANJFDrw9TaP7AndE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757592047; 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=H7uid+k8ZQ1ZsluKhR/vitZ4B3+wMB4NfdE8fWqU68w=; b=hbZ7WPg+rvxpX15D7txVYddm/2lM8dqCvNIJvHRvHB/2aMt6bfHzQiTIJEg5lMMxVfnHaGCB/jYEfhHacoQdE1GSVxdOZDv3hjglM5zOBmOL3nGGcF/VEqvwvCIXAnfIvqrFivsMmDPIwwfmnled0NSQcQ9IFAsgclwrqd8tUjk= 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 1757592047239426.06956276033804; Thu, 11 Sep 2025 05:00:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfw7-0002Ju-Hp; Thu, 11 Sep 2025 07:57:59 -0400 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 1uwfw1-0002Iy-OJ for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:55 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfvn-0006J7-LG for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:52 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 7496041788; Thu, 11 Sep 2025 11:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62F98C4CEF0; Thu, 11 Sep 2025 11:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591854; bh=2z1LZETut4QsqrD4hbQwCdQhV7qbnpi4feefGZI8cIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFkxMQ6zgcqS07/oUhpub27PmF1d+40G661vUe32HGLf3BVSOuboCHp2u6MEjva4s /F/1qwZLufM7BhIz/JYFF3NzBNGt7ALXGFVqMYOL9y6BqgPRfQ+nFnvgU+04RMxYmC OC18c/gxzjY11nfbT6k2AiqQYrd9WRkl4SdLbt7xcccs5CMYoGq7A/ZgCaAscJcKqy MinjQYkQfNJBAfOe0BjURvJtlF6qYmvNMJYH0bPjRaDSU/DF/R5EDnRJtyfAKAEQvI DLodAyr3j8XzR/mgp1NAIJm7poxn4fW9czLXGeeRcy8gZMfQym5RHah8+/KBgXIkoY Nm3AFTcrM3tQQ== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins Subject: [RFC PATCH 2/7] target/i386: SEV: Validate that SEV-ES is enabled when VMSA features are used Date: Thu, 11 Sep 2025 17:24:21 +0530 Message-ID: <75d491d24e39a6d95049868c56e4f2088ed48d6e.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=172.234.252.31; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @kernel.org) X-ZM-MESSAGEID: 1757592049646116600 Content-Type: text/plain; charset="utf-8" SEV features in the VMSA are only meaningful for SEV-ES and SEV-SNP guests, as they control aspects of the encrypted guest state that are not relevant for basic SEV guests. Add a check in check_sev_features() to ensure that SEV-ES or SEV-SNP is enabled when any SEV features are specified. Reviewed-by: Nikunj A Dadhania Signed-off-by: Naveen N Rao (AMD) Reviewed-by: Tom Lendacky --- target/i386/sev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 243e9493ba8d..fa23b5c38e9b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -509,6 +509,12 @@ static int check_sev_features(SevCommonState *sev_comm= on, uint64_t sev_features, __func__); return -1; } + if (sev_features && !sev_es_enabled()) { + error_setg(errp, + "%s: SEV features require either SEV-ES or SEV-SNP to b= e enabled", + __func__); + return -1; + } if (sev_features & ~sev_common->supported_sev_features) { error_setg(errp, "%s: VMSA contains unsupported sev_features: %lX, " --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757592042; cv=none; d=zohomail.com; s=zohoarc; b=kHxZQwam18DOI9C6lhsPBANgno+efW+twzDGOVAzTosOzVmVKgggoJNmdQvTuCHFrWsbeQjxkP3rnvvlgqk4A1nLPOrXusXtGOA4p8rctThQm0iYH28qA01KYkVYsWa08EpxXrW8BR4qy2m8wq5hYfajrEwQh7TDvCF79if3Vcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757592042; 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=ktR9urkrCeKv9BB5g82lkidLMbLGh69/iQmx0i3UDJM=; b=PXFX1H8Or10HF8Xu1+lx1gtM/Zgc5eS40Z+xlySjb8gPhh/r3/913ioe9xLo9umREkeOsyaSwQUqSK/WgYAKdYq5xqRAq2fJ3M2mUU3Lf+lniGQ/5UfM35gHp7crwg4Ge53G4tgi0XXjeTSIU39Jle46qX9Cyv8iOqfpGEkL1VA= 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 1757592042361789.1893389761029; Thu, 11 Sep 2025 05:00:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfw4-0002Ij-3K; Thu, 11 Sep 2025 07:57:56 -0400 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 1uwfvy-0002IL-Os for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:50 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfvq-0006Jl-Vx for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:49 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id B2F5A40A3A; Thu, 11 Sep 2025 11:57:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 866E3C4CEF0; Thu, 11 Sep 2025 11:57:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591858; bh=I3D/RCo9dBe/+uHLQzw9ngK0cT2br+oK6Tf6IcL4Lms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NFpBqLtgJlxOnPhGzDOUqGCLkqjzdF6Ato/12zvO+VzqgyIrbSdMidqC7cmDLXviO lxq7c0wPB/zqeVTgZWwGdidDtDIlHZt37KzgBOSwt67Dh6y/EWD5NfYpowosOxU3vL B2rVGJ5iCG+G7jZ1WITzuqe5gnWcJ7d7e1eMcjMYXM1wi9aiy5bWPc0hf8/gbQfELm PO6FFRprnLiUFJ+W3LlkhxuhzDTIE8z7LLLyYSL1FjMFxdTXMcC1zayY1WR7e1FnLW uyppU8UfpVsZRu7SynRp5cnwmMr9NUmzJTXxBHDAP1fyNHDF0x1zjzxzrbBBuFUtZt stDkUWXgevvlQ== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins Subject: [RFC PATCH 3/7] target/i386: SEV: Add support for enabling debug-swap SEV feature Date: Thu, 11 Sep 2025 17:24:22 +0530 Message-ID: <0a77cf472bc36fee7c1be78fc7d6d514d22bca9a.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=172.234.252.31; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @kernel.org) X-ZM-MESSAGEID: 1757592045459116600 Content-Type: text/plain; charset="utf-8" Add support for enabling debug-swap VMSA SEV feature in SEV-ES and SEV-SNP guests through a new "debug-swap" boolean property on SEV guest objects. Though the boolean property is available for plain SEV guests, check_sev_features() will reject setting this for plain SEV guests. Add helpers for setting and querying the VMSA SEV features so that they can be re-used for subsequent VMSA SEV features, and convert the existing SVM_SEV_FEAT_SNP_ACTIVE definition to use the BIT() macro for consistency with the new feature flag. Sample command-line: -machine q35,confidential-guest-support=3Dsev0 \ -object sev-snp-guest,id=3Dsev0,cbitpos=3D51,reduced-phys-bits=3D1,debug-= swap=3Don Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.h | 3 ++- target/i386/sev.c | 29 +++++++++++++++++++++++++++++ qapi/qom.json | 6 +++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 9db1a802f6bb..8e09b2ce1976 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -44,7 +44,8 @@ bool sev_snp_enabled(void); #define SEV_SNP_POLICY_SMT 0x10000 #define SEV_SNP_POLICY_DBG 0x80000 =20 -#define SVM_SEV_FEAT_SNP_ACTIVE 1 +#define SVM_SEV_FEAT_SNP_ACTIVE BIT(0) +#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) =20 typedef struct SevKernelLoaderContext { char *setup_data; diff --git a/target/i386/sev.c b/target/i386/sev.c index fa23b5c38e9b..b3e4d0f2c1d5 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -319,6 +319,20 @@ sev_set_guest_state(SevCommonState *sev_common, SevSta= te new_state) sev_common->state =3D new_state; } =20 +static bool is_sev_feature_set(SevCommonState *sev_common, uint64_t featur= e) +{ + return !!(sev_common->sev_features & feature); +} + +static void sev_set_feature(SevCommonState *sev_common, uint64_t feature, = bool value) +{ + if (value) { + sev_common->sev_features |=3D feature; + } else { + sev_common->sev_features &=3D ~feature; + } +} + static void sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size, size_t max_size) @@ -2732,6 +2746,16 @@ static int cgs_set_guest_policy(ConfidentialGuestPol= icyType policy_type, return 0; } =20 +static bool sev_common_get_debug_swap(Object *obj, Error **errp) +{ + return is_sev_feature_set(SEV_COMMON(obj), SVM_SEV_FEAT_DEBUG_SWAP); +} + +static void sev_common_set_debug_swap(Object *obj, bool value, Error **err= p) +{ + sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_DEBUG_SWAP, value); +} + static void sev_common_class_init(ObjectClass *oc, const void *data) { @@ -2749,6 +2773,11 @@ sev_common_class_init(ObjectClass *oc, const void *d= ata) sev_common_set_kernel_hashes); object_class_property_set_description(oc, "kernel-hashes", "add kernel hashes to guest firmware for measured Linux boot"); + object_class_property_add_bool(oc, "debug-swap", + sev_common_get_debug_swap, + sev_common_set_debug_swap); + object_class_property_set_description(oc, "debug-swap", + "enable virtualization of debug registers"); } =20 static void diff --git a/qapi/qom.json b/qapi/qom.json index 830cb2ffe781..71cd8ad588b5 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1010,13 +1010,17 @@ # designated guest firmware page for measured boot with -kernel # (default: false) (since 6.2) # +# @debug-swap: enable virtualization of debug registers (default: false) +# (since 10.2) +# # Since: 9.1 ## { 'struct': 'SevCommonProperties', 'data': { '*sev-device': 'str', '*cbitpos': 'uint32', 'reduced-phys-bits': 'uint32', - '*kernel-hashes': 'bool' } } + '*kernel-hashes': 'bool', + '*debug-swap': 'bool' } } =20 ## # @SevGuestProperties: --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757591961; cv=none; d=zohomail.com; s=zohoarc; b=BqbU9WmAxmf012ovPaWVy0dqaPZn/8xDbeP4nu6eG4Urz7b7K2V1q98A8B2x0j5mnjRdNJ7/vP6gyuPjAHn5eNiGpZGerUQSyOvZrgJagR795a5FzJo9TzO8mzaXpnSDCzCfi3grQkk9mrYxi/vJM+zws+ZWTGLIZiCOM31oZSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757591961; 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=GXnrF6kjokj5+Ba8OQYs6OuNp2b8C+YnJJsOH9ln6Gc=; b=eJQP3Y1H6qY707BlHof7LLSkvJDZyxeTMW2E+mTaeXvSRtAo3YaVPd1lTqPqlQyv2oJkjodftK4Rkzs3r5IVg1ljS6/xyopLHTFG0TlOvapErTsbZvZs+g1O+One+J8H9QkIOF09n9j5wGribkP3w6oV93FhGZQSUeP6VjGHbGk= 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 1757591961264153.11636023470066; Thu, 11 Sep 2025 04:59:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfw9-0002Kv-PO; Thu, 11 Sep 2025 07:58:01 -0400 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 1uwfw0-0002Ii-Nv for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:55 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfvs-0006KT-FH for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:57:52 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id C0339417EF; Thu, 11 Sep 2025 11:57:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD8F4C4CEF0; Thu, 11 Sep 2025 11:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591862; bh=FqYI/fFenEh9NNXj5tqAx70QKfo6zQDqB92zhCRqVd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PTFhELJ9YB5jcNQyGYI1KUtcaO2BUbASn4g1PmS2sJsQn6OcojeuIw6jtKKdkSMN/ oJxFw93lEK+gCToqKgECCVzjgJIY/90OnzKEKLZdt9CbQwjDv3403JAg7KzL38c6kv zLpRLHHBHumzlLo2KBPpqjIljGzS+TmDrUjTeUVIbjoX8mt6lVWFJoFjTzox9M2R1E 1FTZB98irrvpGjZAMcnXWvt/yHbzbxZ9GijPAQ0JrTGaQKbo4w4vQcbkI1VfvLarUD 5fp7ZS1vLrcg8D0ggoOVUNfwLUBBruWvpaYJM1psnY1VxA8TJhwqv9vzC6/t7A1r2G lv4xxOxMxLs8g== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins Subject: [RFC PATCH 4/7] target/i386: SEV: Enable use of KVM_SEV_INIT2 for SEV-ES guests Date: Thu, 11 Sep 2025 17:24:23 +0530 Message-ID: <84893d59f11b16890612ef2436ad233526ebe3fd.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=172.234.252.31; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 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 @kernel.org) X-ZM-MESSAGEID: 1757591962119116600 Content-Type: text/plain; charset="utf-8" Now that users can enable VMSA SEV features, update sev_init2_required() to return true if any SEV features are requested. This enables qemu to use KVM_SEV_INIT2 for SEV-ES guests when necessary. Sample command-line: -machine q35,confidential-guest-support=3Dsev0 \ -object sev-guest,id=3Dsev0,policy=3D0x5,cbitpos=3D51,reduced-phys-bits= =3D1,debug-swap=3Don Reviewed-by: Nikunj A Dadhania Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b3e4d0f2c1d5..3063ad2d077a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1704,8 +1704,7 @@ sev_vm_state_change(void *opaque, bool running, RunSt= ate state) */ static bool sev_init2_required(SevGuestState *sev_guest) { - /* Currently no KVM_SEV_INIT2-specific options are exposed via QEMU */ - return false; + return !!SEV_COMMON(sev_guest)->sev_features; } =20 static int sev_kvm_type(X86ConfidentialGuest *cg) --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757591962; cv=none; d=zohomail.com; s=zohoarc; b=ZsrGG0GqsaHLIEBGoYVJmLzUQnQbqoNDpmWBJL3yGzFaZ1shDzVy2KxNIrpcIQRCNnEXJl730geq0KdEHeXjCHFomq846N4EQGR2Nm4ARzKudMUnXGaGMw8x1n/H7ijhnfJpTtrO3FWxd5yXnJGxOOvLn8Incv2jMKD8Tl4h3zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757591962; 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=TrFL29yHJlCsR43hCvr/Nj1USyRmGrmAfhbZDpM71Vg=; b=n0+8thV/orlH/Jvf8ajDfLG1bECHF7UPGCBwdeYA2Qm802P8AIR147pRXQqBx3SvM01witjKR8EO3dawEGvSbxwU1gCYCaQRr+k/qrdFxVkONabOJiXiRHqgFcrJkT0RgJs/dwjhJDYghzOMGWeH2wlkG2Kxf9iVcoBjJ8BiUw0= 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 1757591962436335.78253681445835; Thu, 11 Sep 2025 04:59:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfwB-0002LU-Af; Thu, 11 Sep 2025 07:58:03 -0400 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 1uwfw8-0002KT-Qh for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:00 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfw2-0006Lf-4N for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:00 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 5CB0543B90; Thu, 11 Sep 2025 11:57:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67916C4CEF0; Thu, 11 Sep 2025 11:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591867; bh=Q3CepnBB4cHosxsbgQq/BWCHIzMOIfZtr4L86ETM60c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K9Kq2SBbcrBBgMPPopSCW8mK4WtaloHNpIkxibYgl7dxtwYYuFRYv1dfw9+tVjvsp 2NRdtenfxAPDguvFryFEASdoDoxHjLIcyBujCNdO0fx+YSFRyg4xAC+1eANefmxElQ MnQyVnidCecqJQmtkbfRAs8N9GVzZgOucuwJCQNxuKMhVhK57HPER5trA/G/3UQm8w aNrzbYLroM4Mt3BefQqNmhxOjZExFlYOo27gztca9eq43YHWhJhPtS6734qRSfyuu7 iB/UCZZwN8YUkgOK87u3bSg/kK+SpA41zpwCOOdXhmxRJS3x3vSHZEv7xv6pRkFh/u JxeOHaL29eaKA== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins , Ketan Chaturvedi Subject: [RFC PATCH 5/7] target/i386: SEV: Add support for enabling Secure TSC SEV feature Date: Thu, 11 Sep 2025 17:24:24 +0530 Message-ID: <4c5ecb5835d8600e1b7b30fba2e36e1163b8da83.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: 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 @kernel.org) X-ZM-MESSAGEID: 1757591963871116600 Content-Type: text/plain; charset="utf-8" Add support for enabling Secure TSC VMSA SEV feature in SEV-SNP guests through a new "secure-tsc" boolean property on SEV-SNP guest objects. Sample command-line: -machine q35,confidential-guest-support=3Dsev0 \ -object sev-snp-guest,id=3Dsev0,cbitpos=3D51,reduced-phys-bits=3D1,secure= -tsc=3Don Co-developed-by: Ketan Chaturvedi Signed-off-by: Ketan Chaturvedi Co-developed-by: Nikunj A Dadhania Signed-off-by: Nikunj A Dadhania Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.h | 1 + target/i386/sev.c | 13 +++++++++++++ qapi/qom.json | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 8e09b2ce1976..87e73034ad15 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -46,6 +46,7 @@ bool sev_snp_enabled(void); =20 #define SVM_SEV_FEAT_SNP_ACTIVE BIT(0) #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) +#define SVM_SEV_FEAT_SECURE_TSC BIT(9) =20 typedef struct SevKernelLoaderContext { char *setup_data; diff --git a/target/i386/sev.c b/target/i386/sev.c index 3063ad2d077a..8f88df19a408 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -3117,6 +3117,16 @@ sev_snp_guest_set_host_data(Object *obj, const char = *value, Error **errp) memcpy(finish->host_data, blob, len); } =20 +static bool sev_snp_guest_get_secure_tsc(Object *obj, Error **errp) +{ + return is_sev_feature_set(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_TSC); +} + +static void sev_snp_guest_set_secure_tsc(Object *obj, bool value, Error **= errp) +{ + sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_TSC, value); +} + static void sev_snp_guest_class_init(ObjectClass *oc, const void *data) { @@ -3152,6 +3162,9 @@ sev_snp_guest_class_init(ObjectClass *oc, const void = *data) object_class_property_add_str(oc, "host-data", sev_snp_guest_get_host_data, sev_snp_guest_set_host_data); + object_class_property_add_bool(oc, "secure-tsc", + sev_snp_guest_get_secure_tsc, + sev_snp_guest_set_secure_tsc); } =20 static void diff --git a/qapi/qom.json b/qapi/qom.json index 71cd8ad588b5..b05a475ef499 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1100,6 +1100,8 @@ # firmware. Set this to true to disable the use of VCEK. # (default: false) (since: 9.1) # +# @secure-tsc: enable Secure TSC (default: false) (since 10.2) +# # Since: 9.1 ## { 'struct': 'SevSnpGuestProperties', @@ -1111,7 +1113,8 @@ '*id-auth': 'str', '*author-key-enabled': 'bool', '*host-data': 'str', - '*vcek-disabled': 'bool' } } + '*vcek-disabled': 'bool', + '*secure-tsc': 'bool' } } =20 ## # @TdxGuestProperties: --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757592004; cv=none; d=zohomail.com; s=zohoarc; b=Chu/fQXrMvVIwk+6ueAlwjUY+pZKaqh9NcAgdEJVc2tbXeJshRJUxCMRbQOds5Vd5XAy2ADAO6Ccc3FSnNqmUZ3YDN17cKW+tyN4Q8RPyH8oDl4lNvAHVoOC71EyOLI3PtNFQJs3l2NvD2Us71Hm3pCKnom41ToogwBzqg8VP8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757592004; 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=3s3V4/bAgP6KL6c2Bun3s0nIJ6YVbjGJtOSHpaP672M=; b=Ox8cRobFWVCyMygykEeCevEj9Ebc6DGYg26jW/L9KQmxsgI7Lzk3xeD7oCKdB/32i6v9LCsZBtk+Q6NZ+g0Gx+1W/Gyfd4nezAsWxuYtseLI1nS+9ss/5wGKlCFfl07DMAxS5ZSVDX85BzZGTlvB8nyuea2Ch/VQU5l9R5HDCHs= 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 175759200420631.73253659595946; Thu, 11 Sep 2025 05:00:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfwC-0002Lf-WC; Thu, 11 Sep 2025 07:58:05 -0400 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 1uwfw9-0002Kx-QP for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:01 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfw6-0006Ml-Gz for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:01 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id F273F44ED7; Thu, 11 Sep 2025 11:57:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F4AC4CEF0; Thu, 11 Sep 2025 11:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591871; bh=lqDFC3PoMqY9bhdEGeCOP+WTgMv8uQWnXYCTLdQ56bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bLBIDwTY0eNGv0Rr5xkjt5j4BPbo5qRqjI1sv8UwH5yx/2EHnVBEd17rk0LVJcVga jw5b/TVri/bbUHZDBtxIVH1r3NxK6rf0hI8zSKVU0/reB2wLuIdIZkYqZBh2Y8X+dc x/CAvloeKHvhF/mGC7Ajb1TRf0deMrxCbpIK4IzO5OKOcrUcdlEww30AWoSbWK6Ui3 OJvQsPJGQi6234x5baxPkeegfv3XMGUgHyggnMyhBBkL9VIN554o2Gw9S9xLjSsPRy YLWiEtz/1RI/D/6zLk8VkuavrVazlUIc9YF7wZLJ6uy6GKx9iXMdj+06r/eYv4YI3w aGNL1pvj4V+kQ== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins , Ketan Chaturvedi Subject: [RFC PATCH 6/7] target/i386: SEV: Add support for setting TSC frequency for Secure TSC Date: Thu, 11 Sep 2025 17:24:25 +0530 Message-ID: <23a293fca3e2ac22c7da052123e27c2794f40932.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @kernel.org) X-ZM-MESSAGEID: 1757592006682116600 Content-Type: text/plain; charset="utf-8" Add support for configuring the TSC frequency when Secure TSC is enabled in SEV-SNP guests through a new "tsc-frequency" property on SEV-SNP guest objects, similar to the vCPU-specific property used by regular guests and TDX. A new property is needed since SEV-SNP guests require the TSC frequency to be specified during early SNP_LAUNCH_START command before any vCPUs are created. The user-provided TSC frequency is set through KVM_SET_TSC_KHZ before issuing KVM_SEV_SNP_LAUNCH_START. Co-developed-by: Ketan Chaturvedi Signed-off-by: Ketan Chaturvedi Co-developed-by: Nikunj A Dadhania Signed-off-by: Nikunj A Dadhania Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ qapi/qom.json | 6 +++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 8f88df19a408..facf51c810d9 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -178,6 +178,7 @@ struct SevSnpGuestState { char *id_auth_base64; uint8_t *id_auth; char *host_data; + uint32_t tsc_khz; =20 struct kvm_sev_snp_launch_start kvm_start_conf; struct kvm_sev_snp_launch_finish kvm_finish_conf; @@ -536,6 +537,13 @@ static int check_sev_features(SevCommonState *sev_comm= on, uint64_t sev_features, __func__, sev_features, sev_common->supported_sev_featu= res); return -1; } + if (sev_snp_enabled() && SEV_SNP_GUEST(sev_common)->tsc_khz && + !(sev_features & SVM_SEV_FEAT_SECURE_TSC)) { + error_setg(errp, + "%s: TSC frequency can only be set if Secure TSC is ena= bled", + __func__); + return -1; + } return 0; } =20 @@ -1085,6 +1093,18 @@ sev_snp_launch_start(SevCommonState *sev_common) return 1; } =20 + if (is_sev_feature_set(sev_common, SVM_SEV_FEAT_SECURE_TSC)) { + rc =3D -EINVAL; + if (kvm_check_extension(kvm_state, KVM_CAP_VM_TSC_CONTROL)) { + rc =3D kvm_vm_ioctl(kvm_state, KVM_SET_TSC_KHZ, sev_snp_guest-= >tsc_khz); + } + if (rc < 0) { + error_report("%s: Unable to set Secure TSC frequency to %u kHz= ret=3D%d", + __func__, sev_snp_guest->tsc_khz, rc); + return 1; + } + } + rc =3D sev_ioctl(sev_common->sev_fd, KVM_SEV_SNP_LAUNCH_START, start, &fw_error); if (rc < 0) { @@ -3127,6 +3147,28 @@ static void sev_snp_guest_set_secure_tsc(Object *obj= , bool value, Error **errp) sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_TSC, value); } =20 +static void +sev_snp_guest_get_tsc_frequency(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t value =3D SEV_SNP_GUEST(obj)->tsc_khz * 1000; + + visit_type_uint32(v, name, &value, errp); +} + +static void +sev_snp_guest_set_tsc_frequency(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t value; + + if (!visit_type_uint32(v, name, &value, errp)) { + return; + } + + SEV_SNP_GUEST(obj)->tsc_khz =3D value / 1000; +} + static void sev_snp_guest_class_init(ObjectClass *oc, const void *data) { @@ -3165,6 +3207,9 @@ sev_snp_guest_class_init(ObjectClass *oc, const void = *data) object_class_property_add_bool(oc, "secure-tsc", sev_snp_guest_get_secure_tsc, sev_snp_guest_set_secure_tsc); + object_class_property_add(oc, "tsc-frequency", "uint32", + sev_snp_guest_get_tsc_frequency, + sev_snp_guest_set_tsc_frequency, NULL, NULL); } =20 static void diff --git a/qapi/qom.json b/qapi/qom.json index b05a475ef499..5b99148cb790 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1102,6 +1102,9 @@ # # @secure-tsc: enable Secure TSC (default: false) (since 10.2) # +# @tsc-frequency: set secure TSC frequency. Only valid if Secure TSC +# is enabled (default: zero) (since 10.2) +# # Since: 9.1 ## { 'struct': 'SevSnpGuestProperties', @@ -1114,7 +1117,8 @@ '*author-key-enabled': 'bool', '*host-data': 'str', '*vcek-disabled': 'bool', - '*secure-tsc': 'bool' } } + '*secure-tsc': 'bool', + '*tsc-frequency': 'uint32' } } =20 ## # @TdxGuestProperties: --=20 2.50.1 From nobody Sun Sep 28 17:03:47 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757592010; cv=none; d=zohomail.com; s=zohoarc; b=ZEHNOhybBRVkQ8jnrGh1MdFG6wuTv53ycFbhtn3Jv97m52STyoeNKUWx8a++AUsPDzxlZIOqXGQc+05TLU+JBAO1SoN6I1vomrrn2DPQbEa6ANITTy9QeD3xsAws7yXT5OqOdietewGc1DNpIIKscvQMev7PjULqkbX4MgRa+vQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757592010; 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=ohVBxMSKepEIIKNU7xEsSZ0SDRfMDZ1Ubi8Z68NG9DI=; b=cbSKKUKGGpAkHGhmmoBSskUEIZ3YNpGCN9lN0ydA7UjvNZn4xBJq+6hnY6dMQsBPZOji7cmsH2T4Zd8p/HhhD655eL9S8DBXJUjL56RX6zaJbCs7SqhmaEcBAyfEVnypmVt57DpWJWBKDWZEh++dNI3Vefgt3TawNonkFYeZ1k0= 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 1757592009962830.4564196667218; Thu, 11 Sep 2025 05:00:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwfwG-0002Nh-HZ; Thu, 11 Sep 2025 07:58:08 -0400 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 1uwfwE-0002Mh-UF for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:06 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwfwA-0006O2-CK for qemu-devel@nongnu.org; Thu, 11 Sep 2025 07:58:06 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 6D3FD41A00; Thu, 11 Sep 2025 11:57:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92B73C4CEF0; Thu, 11 Sep 2025 11:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757591877; bh=7HOJXed/grVIwqxVnBC0UOQowTK5L/FCl7Cie6uBUm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1ntO9aEo82Qc78/YNeyI6LSQHMMSt10UyA//C2B2KcD0FLcWLj18okAIoyxhZ4LM sxbA1oBVssrhDk6VCVyEh/Q75omSlQw04GBqJzB9ZyLsXdeh8u3yLFaGo0ixvV+tW+ k2uRaFFE0EIcOeGLjf3PT/NY8NyJBaZcFNfqeQjGBziSs217O57pipb+fZpjanrYFL MdJKEqA+FvP3sgqZKdnzSDuChWOP3DvsnY8ixHeRohuWXmc1J1M/S+8ccp9H3m738D rPNQ6KWdsAEcPSCcWKJRoxdDIPZxQWaICJ/aEFwvjPmy0qZHrB8CSfw1U3TWtTD6nk MDpIinpFepTIw== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Sean Christopherson Cc: qemu-devel , , "Daniel P. Berrange" , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Neeraj Upadhyay , Roy Hopkins Subject: [RFC PATCH 7/7] target/i386: SEV: Add support for enabling Secure AVIC SEV feature Date: Thu, 11 Sep 2025 17:24:26 +0530 Message-ID: <632eaad0ef28943520a1285c8efb3d8a756e4624.1757589490.git.naveen@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=naveen@kernel.org; helo=sea.source.kernel.org 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @kernel.org) X-ZM-MESSAGEID: 1757592012441116600 Content-Type: text/plain; charset="utf-8" Add support for enabling Secure AVIC VMSA SEV feature in SEV-SNP guests through a new "secure-avic" boolean property on SEV-SNP guest objects. Sample command-line: -machine q35,confidential-guest-support=3Dsev0 \ -object sev-snp-guest,id=3Dsev0,cbitpos=3D51,reduced-phys-bits=3D1,secure= -avic=3Don Reviewed-by: Nikunj A Dadhania Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.h | 1 + target/i386/sev.c | 13 +++++++++++++ qapi/qom.json | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 87e73034ad15..a374c144bccd 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -47,6 +47,7 @@ bool sev_snp_enabled(void); #define SVM_SEV_FEAT_SNP_ACTIVE BIT(0) #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) #define SVM_SEV_FEAT_SECURE_TSC BIT(9) +#define SVM_SEV_FEAT_SECURE_AVIC BIT(16) =20 typedef struct SevKernelLoaderContext { char *setup_data; diff --git a/target/i386/sev.c b/target/i386/sev.c index facf51c810d9..f9170e21ca57 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -3147,6 +3147,16 @@ static void sev_snp_guest_set_secure_tsc(Object *obj= , bool value, Error **errp) sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_TSC, value); } =20 +static bool sev_snp_guest_get_secure_avic(Object *obj, Error **errp) +{ + return is_sev_feature_set(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_AVIC); +} + +static void sev_snp_guest_set_secure_avic(Object *obj, bool value, Error *= *errp) +{ + sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_SECURE_AVIC, value); +} + static void sev_snp_guest_get_tsc_frequency(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -3210,6 +3220,9 @@ sev_snp_guest_class_init(ObjectClass *oc, const void = *data) object_class_property_add(oc, "tsc-frequency", "uint32", sev_snp_guest_get_tsc_frequency, sev_snp_guest_set_tsc_frequency, NULL, NULL); + object_class_property_add_bool(oc, "secure-avic", + sev_snp_guest_get_secure_avic, + sev_snp_guest_set_secure_avic); } =20 static void diff --git a/qapi/qom.json b/qapi/qom.json index 5b99148cb790..5dce560a2f54 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1105,6 +1105,8 @@ # @tsc-frequency: set secure TSC frequency. Only valid if Secure TSC # is enabled (default: zero) (since 10.2) # +# @secure-avic: enable Secure AVIC (default: false) (since 10.2) +# # Since: 9.1 ## { 'struct': 'SevSnpGuestProperties', @@ -1118,7 +1120,8 @@ '*host-data': 'str', '*vcek-disabled': 'bool', '*secure-tsc': 'bool', - '*tsc-frequency': 'uint32' } } + '*tsc-frequency': 'uint32', + '*secure-avic': 'bool' } } =20 ## # @TdxGuestProperties: --=20 2.50.1