From nobody Sat Nov 15 00:46:06 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=1758191564; cv=none; d=zohomail.com; s=zohoarc; b=JsR1zkvM+AlfLjWQjQiSzzwATJUXTeSL8fVX5s2DPz0SN9QZl8gCe+He299sWi+cIkmPjgNgOnfxVpyuGpvaxvccf2FXP6WY8glvRcrgqgyvBncIEvHkvop1s7supHlTo6+plH2ljupIzxPKGxWsBgNxLRSsaieJ7xWk4dnr1GE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191564; 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=CvXEZgfj5KunM8yTj1UXUwGRceRUUB6iVbA4b9kIedM=; b=VObIH1EtXa/71V5wswkobQLuiVylMUxUaRdzvKuddc13eQPj0us3Lfv6r+EuEAnvip9+IsXsZAulkF++j1ZZR/4MCGm2TPs/u2cdd9zPXptmBt6KzgZgQWzwntWZ+8jtXjPU5ofVJVTjfB71hCPnZYHTg4xQ0bhMzca4jZFL7+w= 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 1758191563987631.4969417913296; Thu, 18 Sep 2025 03:32:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuq-0007Cf-2L; Thu, 18 Sep 2025 06:31:04 -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 1uzBun-0007CF-8P for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:31:03 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324: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 1uzBuk-0001Ow-MN for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:31:00 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 7662360209; Thu, 18 Sep 2025 10:30:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FDF1C4CEF7; Thu, 18 Sep 2025 10:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191455; bh=voC3RuuXy69NPBRMGb0xMv9euf2H4XXFvE+T4oED/WE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gG+PfqBGv1j+jb6yRHWZoN+/mWb3whrz8kOQhHomYHkQRjhNdA6XdplcZtrmgzz7H I3+gKLwLGAFhedLUHgwtEYsv6t4ucrUFWkBUnNUelWJPGdzB6+dKhndAEvxj27zSx/ Q4kZumUi1TibWJFKApMlYxMVzojd4RDk0ZIpEQoiVfJZOJH2dePB+lNHkAztLvVqx8 wKuUwQzP+wp2PTFXIpAZS6uygfRzJzz5BwyA++/LGQUiBi20jpKqs1kXEbNOwEvKwv Ln6d0rT2jJquixFKCDdN9yB7OzA09n3ZdzwcRCONouJCI3IkiXK5pyNMLyGa9s6wD+ iRCho0JkFUmKg== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 1/8] target/i386: SEV: Generalize handling of SVM_SEV_FEAT_SNP_ACTIVE Date: Thu, 18 Sep 2025 15:56:59 +0530 Message-ID: X-Mailer: git-send-email 2.51.0 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:3c04:e001:324:0:1991:8:25; envelope-from=naveen@kernel.org; helo=tor.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: 1758191566319116601 Content-Type: text/plain; charset="utf-8" Align with IGVM files providing sev features with SVM_SEV_FEAT_SNP_ACTIVE set by setting the same when creating a sev-snp-guest object. Since KVM sets this feature itself, SVM_SEV_FEAT_SNP_ACTIVE is unset before KVM_SEV_INIT2 ioctl is invoked. Move that out of IGVM-specific section to common code. While at it, convert the existing SVM_SEV_FEAT_SNP_ACTIVE definition to use the BIT() macro for consistency with upcoming feature flags. Signed-off-by: Naveen N Rao (AMD) Reviewed-by: Tom Lendacky --- target/i386/sev.h | 2 +- target/i386/sev.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 9db1a802f6bb..102546b112d6 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -44,7 +44,7 @@ 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) =20 typedef struct SevKernelLoaderContext { char *setup_data; diff --git a/target/i386/sev.c b/target/i386/sev.c index 1057b8ab2c60..2fb1268ed788 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -319,6 +319,15 @@ sev_set_guest_state(SevCommonState *sev_common, SevSta= te new_state) sev_common->state =3D new_state; } =20 +static void sev_set_feature(SevCommonState *sev_common, uint64_t feature, = bool set) +{ + if (set) { + 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) @@ -1897,15 +1906,15 @@ static int sev_common_kvm_init(ConfidentialGuestSup= port *cgs, Error **errp) -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 + /* + * 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; } @@ -3127,6 +3136,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_set_feature(SEV_COMMON(sev_snp_guest), SVM_SEV_FEAT_SNP_ACTIVE, tr= ue); } =20 /* guest info specific to sev-snp */ --=20 2.51.0 From nobody Sat Nov 15 00:46:06 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=1758191501; cv=none; d=zohomail.com; s=zohoarc; b=jScUjOP3sitYghOyYHG7OYbhg5EObhDgKhzXZPOdR5Zf2KUwrP3lEncXPtDvOI22gz87tuny9QG0hqZC2O4ri9F7844QYdwlcHh313vM82ct1bO55x8+iKzwaopkvb7GOaKvY1a396LSh2x9vY3C+KkB1qNLTpLXRaU24KshqSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191501; 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=pMPxpTBx0SYS4s09GeA8/r67tJPaXCpfI/LqV78K4Z0=; b=Uc9/PhUWbrM/WR6EHrNO6TzkEeTgw3nsNQeEJN1/HW4aSmXYqXPoaJQALxwzQaN6IG48WZxzxD+Lgl57FJq4S73CcPAuqUgqAVugGPSH2C9Z30UCCBTvvcOjONamZqTv8AiftQTs3kFG56FtWh3zCqmylyT52qPqJiKc9FoA1JA= 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 1758191501558872.8192176151629; Thu, 18 Sep 2025 03:31:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuX-00071G-O4; Thu, 18 Sep 2025 06:30:45 -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 1uzBuK-0006wa-JA for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:40 -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 1uzBuI-0001L7-GH for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:32 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 6FE3941880; Thu, 18 Sep 2025 10:30:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96A21C4CEEB; Thu, 18 Sep 2025 10:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191419; bh=dP5IVGjmx5XftVX1vvgwnPL2aJr8KldT3GTZjykn2Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxETtJFNX+jmX13mn+mvbN73JIqE8L+LWqtqxPRi+hcnfiNCAIgtQIQi03hpsMleg JekZvLZLPomHv0Wfk7jSHFbkFjZkUoiyMnDqRFf5kfH67tErPgpE1RUAfOWXU8yy+0 rrspUlJbzZKUGMdzy5B9SZ+qNL9fVATB8H2/fmQZku/ZOuU5fVF++g+GzLvw4QK4l+ 94Tbgvqx1ULaLWhhONyFzKIWP/wrg9BFhZZqrxmltbYaQPExgo4TW96JuNqKbTlqqR A1oGzWW0QUyumi8qOTrz2IiN6niHLWC4j9vHnCsNNwjx0PC9u3ctd9t6pKFvJyxLy9 uCl512O8rmmQg== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 2/8] target/i386: SEV: Ensure SEV features are only set through qemu cli or IGVM Date: Thu, 18 Sep 2025 15:57:00 +0530 Message-ID: X-Mailer: git-send-email 2.51.0 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: 1758191503635116600 Content-Type: text/plain; charset="utf-8" In preparation for qemu being able to set SEV features through the cli, add a check to ensure that SEV features are not also set if using IGVM files. Signed-off-by: Naveen N Rao (AMD) Reviewed-by: Tom Lendacky --- target/i386/sev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 2fb1268ed788..c4011a6f2ef7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1901,6 +1901,11 @@ static int sev_common_kvm_init(ConfidentialGuestSupp= ort *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) { --=20 2.51.0 From nobody Sat Nov 15 00:46:06 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=1758191514; cv=none; d=zohomail.com; s=zohoarc; b=JD7emlkVDZN0DUhBSkqKLzbIQ52e6LHAg9solvsE640/3cJ/PscK33CyMThhi/oETi+MPEOnkJSAaa3TBzRjsu8MUXZyOWPwogCphkMYvZBo3jsXy4MoGeam8yp0Q1WwhN99/O4rciSg88zP58cxe7nL3YqVXbHEbZyTQX/upwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191514; 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=UXa+Yls2AvEftm7quEPS39r5SyBrOhkB+4e6MYePw5Y=; b=VsBf2jWXwBDlLXIwJDn8wo2MlHZnq6EDccNB/92sodUBiK4J+md0Gtbe4wRmcL35MysZvLOnJDXlHpEuDOxOLjwzGTfnyv5lLXI1MvPQCRDRlxtPuzT8vMSXxAfGpxry4JBFT101/IZssq0h/g0Zf94WXjTi0fW8VOMc4NkMCfM= 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 1758191514815918.0257252614763; Thu, 18 Sep 2025 03:31:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuW-0006zP-LC; Thu, 18 Sep 2025 06:30:44 -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 1uzBuH-0006vs-Pu for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:40 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzBuE-0001LS-Do for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:29 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 495FE60207; Thu, 18 Sep 2025 10:30:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35F2FC4CEF7; Thu, 18 Sep 2025 10:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191423; bh=iInPTCFj8UCEpOkf584ztFBgNmedO/q1q8XQk2av7F0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=imMxmRMOFucVmbbnIljCOoD604kUGRxR+4MK5CZy9169s2vPHOhaFxj6UcmLNuhk0 kj2BDLbHIUMoEkXMWPTRXj3D0kSpSWoKI0bj7e1cltPjUSdK2HLNAElEOka/iTzbEL bTM+fpCgOZZ1TtghcV8L/VQOKYTxm6aP4QOvzVti3Go4Ow8lDJl9E+lVw1Axq26pdE N7IFCNQVgdCpz9p2nB39W4qasnNKYDAgyvn6hgxjtOH5mFj70Z2vPlPwKxFEc8HRTd pRr3vFzWo8f9Nrb64QB25A8NccjnjoSDmQlurtZ6qcqe15VFlzdU1RFqiDKQCN4Hbe 5SWgV/6JVI+rg== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 3/8] target/i386: SEV: Consolidate SEV feature validation to common init path Date: Thu, 18 Sep 2025 15:57:01 +0530 Message-ID: X-Mailer: git-send-email 2.51.0 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.105.4.254; envelope-from=naveen@kernel.org; helo=tor.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: 1758191515856116600 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. Signed-off-by: Naveen N Rao (AMD) Reviewed-by: Tom Lendacky --- target/i386/sev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index c4011a6f2ef7..7c4cd1146b9a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -595,9 +595,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))) { @@ -1913,6 +1910,10 @@ static int sev_common_kvm_init(ConfidentialGuestSupp= ort *cgs, Error **errp) } } =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 @@ -2532,9 +2533,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; --=20 2.51.0 From nobody Sat Nov 15 00:46:06 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=1758191479; cv=none; d=zohomail.com; s=zohoarc; b=hsyYJA+fLZTkSEvqUH+ieyjX9Jmq6SXRYaVgYJ2xpiwL7IqP084l/3Q198ed8VEIOsmkv+MNmsFdwItX1nscR8Ta0ZqQ5xffE/1EEF7TmKG9DftBUPvBwzaAikGj5Jpgw7IaIjlF0+MHEMHqPVj2RlR3fsUUVuT3Q+EZ+O4UPBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191479; 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=2AYlcrwEEvAORaRd2NI8UJsnzZtyUCN4WuWJfFPyFck=; b=GXgT+kD8lcevX+dx55i+WvcP5bzKAt12GktwmYq+l1sUVqdJYvArFmj3OL9/IiOfSiHR1n8NuCyOvtrEjIEU2u7tNe5zRrk5H6oJJeaXPQShVkqljZ3UBztwBT1GcfBCdQYHDlUnpoSUQJMUvk2dplDA/Gg9X6mWH6MrE9F8Sfg= 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 1758191479281427.8167155153776; Thu, 18 Sep 2025 03:31:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuV-0006yY-98; Thu, 18 Sep 2025 06:30:44 -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 1uzBuK-0006wZ-EB for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:40 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324: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 1uzBuH-0001Ld-LC for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:32 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id E79D36020E; Thu, 18 Sep 2025 10:30:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAD8CC4CEE7; Thu, 18 Sep 2025 10:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191426; bh=dV4uVX4HWUQHDw0uWQev5aF1tKrV/zVT0JFkQA9+V58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kiZhMNQQqX+qwE8TUVeKT871F21iL8xvZOvQcJ/3kr9GoUC89cMk4p9n8xg38mESq fCFmTJpc0ygxKSN/MyoYzdACI2T92v3qyf/u0X37kw20U7PxXv/I4F+SXGKtMFxmny VAQwVQPiwvEjlQx0JGeqcCHw27DdSK06S5vIphII//HHDp9pvJLLuwo77XmRbTQNy8 Iwmr2xBwZWsuYhElA7eGb4Rfo31nRnOiw/pnYkD3vJAxvqlxLBn1LZmBhecbUxWNEJ mMDeW94Hgwhm2UvY8RcTz6nc3SWOzvo3moOtgS1AFGEv7kR3BYxPkmpmGind/yXLxf idBzH7Qoo89iQ== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 4/8] target/i386: SEV: Validate that SEV-ES is enabled when VMSA features are used Date: Thu, 18 Sep 2025 15:57:02 +0530 Message-ID: X-Mailer: git-send-email 2.51.0 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:3c04:e001:324:0:1991:8:25; envelope-from=naveen@kernel.org; helo=tor.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: 1758191481557116600 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 Reviewed-by: Tom Lendacky Signed-off-by: Naveen N Rao (AMD) --- target/i386/sev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 7c4cd1146b9a..f6e4333922ea 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -518,6 +518,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.51.0 From nobody Sat Nov 15 00:46:06 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=1758191500; cv=none; d=zohomail.com; s=zohoarc; b=kVEeaxlMnZWBqtBZ9OD/tO0YFfdYFfh8HYxhmgjhP51/J+7YpwmlyT/nYR9bwjm4m63BR5AZHcWXoeS0E+8Rp8wDzPilxnFX7dozICukRA7zFJvNBaYoij4UAo019X9A9Obg9jIJctGjVGzI3dVOIrY2gJoGHc5DoRgV8RKgsyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191500; 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=Ob+0EmYK4hqYkodO+fQgUa86DPx+laRo3rxjjJnXS2E=; b=cpkecwErj0aHjBSHNjDSL7cafc0U3vSF6IyAgWB3epwaOM7mHR3Qx5Ya7BkuZTyCYNwfXA+oXlWFVXD5SFjGFrzAvMxqqccU1bRWsj5uD99SGK1I79eQnXxZnpVZ67w/6tnhVI6UPRj+nr+45XcqjteSzH4xfFVUpCVUBXV3CXA= 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 1758191500222921.0813620285548; Thu, 18 Sep 2025 03:31:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuY-00072A-8H; Thu, 18 Sep 2025 06:30:46 -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 1uzBuR-0006wj-Eb for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:40 -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 1uzBuP-0001Mw-54 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:39 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 7FF1A4178A; Thu, 18 Sep 2025 10:30:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A88BCC4CEE7; Thu, 18 Sep 2025 10:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191435; bh=MU3DcjI3mx45k0C4QGbtmZgCH9YaOww7yDlbWGEhMGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCZ62KR3WDR6hI5mo0R7s1IdARWfvtHeVK63VoctH2ZgPec4zNlSYxX5vR5JR230j EgVEjliK+nYiowRf0TBoMHXGlUBqBCSFFX6SJpRz4/QvtW5ztUwfnNZzI8HHO5iYuw efhF6Ms7Yfi0CUtYdZwjjj0sApXPXdcqPXiju85W4MWAiL9k5urLAPV8lYezJeTchV LsFFReQgtGvcwDoNEbNO3pcG7CZ2LlYMnpZ5WpKaX2mlpParqNpXh4omxa+4Dq7l+c 06rT3zq8KrQnnaqheDhZtu8sQgohdltaIqyf01iykRcMJwnsyJNSfOhVKmstPr7C9u miC08yRoDI1Ng== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 5/8] target/i386: SEV: Add support for enabling debug-swap SEV feature Date: Thu, 18 Sep 2025 15:57:03 +0530 Message-ID: X-Mailer: git-send-email 2.51.0 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: 1758191501865116600 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. 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) Reviewed-by: Tom Lendacky --- target/i386/sev.h | 1 + target/i386/sev.c | 20 ++++++++++++++++++++ qapi/qom.json | 6 +++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index 102546b112d6..8e09b2ce1976 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -45,6 +45,7 @@ bool sev_snp_enabled(void); #define SEV_SNP_POLICY_DBG 0x80000 =20 #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 f6e4333922ea..4f1b0bf6ccc8 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -319,6 +319,11 @@ 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 set) { if (set) { @@ -2741,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) { @@ -2758,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..df962d4a5215 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.51.0 From nobody Sat Nov 15 00:46:06 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=1758191528; cv=none; d=zohomail.com; s=zohoarc; b=ErJpJBo3lZnNnhRc65lmchxqwW8WHsvsIydL9cxku16MWfrZsq05IqEJ2s3OxvlaJtomiu6TJl33PyH3kZVzMtyT5RHtzkLsSDRW6gmNxlrVeJQS2ERpkRPrZKZt80xmB4HtSuKgsmcy5/W/+PdjBuYvC8GtuxZiJGm2DfoXqjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191528; 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=OAYsQOXVniz1HDd2CIgGKpW9KjjHL0RbnnqLghJuFPU=; b=Aucc4P8VonWE3kqNrOCbGKuZ6tBF7FCGT8fSBlcRqIV9d0FJ82nRsFiefIvPKDFq0qFtZUh0BJvRVc9W3XEbe+UtQd+RZSproXn78WJXMgTdjZ0lyPZ1G1D+7fXZlXDr7TYQnEajD/ZtDM3QE2Mu+bkiVfN1PwFZUxTMuQ4pEy4= 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 1758191528777938.6258637212032; Thu, 18 Sep 2025 03:32:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBuf-00078U-J9; Thu, 18 Sep 2025 06:30:53 -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 1uzBud-00076p-OI for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:51 -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 1uzBuS-0001NV-P4 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:51 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 2148B408F6; Thu, 18 Sep 2025 10:30:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4369DC4CEEB; Thu, 18 Sep 2025 10:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191439; bh=B7JHk9fWDpqUfKVj1TLxQafQWshyOG1fenZVw/oaq9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uE1t75Hff9IOa0GmD64eZ6wkalnBLB3pvn0CI39jiQqtP6LbUTmUptk6ZJdYUBYfh yNxgQmhVpYsTQodWbf5HdwRNVglTECoF9Ri54omvfqVdAoaQaKB4yCoSnJJOxyOt00 EdvlIy/72j5jN/iE9RAZFqovAGLdwn9WYC9XWmafjUeSfoYElHYYq0hDvjonAGwv1Z jLz/TLox3a4ZuuNWAwvWRkLGB9N4bWBB04nnmQkhKQ9hm+suyoRdzg+lee8WaT3lKo H/xosADVCD9LtVUNKIkLUIlAx47YQnLM14r+w0ZJaKr3oKQhWzN6anpdfDbgDO2m5y zbT/469fNqyaw== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 6/8] target/i386: SEV: Enable use of KVM_SEV_INIT2 for SEV-ES guests Date: Thu, 18 Sep 2025 15:57:04 +0530 Message-ID: <4d14083f34e3196a1ef179a958e30e800b5263fe.1758189463.git.naveen@kernel.org> X-Mailer: git-send-email 2.51.0 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: 1758191529879116600 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) Reviewed-by: Tom Lendacky --- 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 4f1b0bf6ccc8..6b11359f06dd 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.51.0 From nobody Sat Nov 15 00:46:06 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=1758191510; cv=none; d=zohomail.com; s=zohoarc; b=Vv31jRULWT/0jnpkRZ/OnQgeco2fYI40OaQFXdmghPGRuN9boHJd+ULgcZzX87jjCIjBt2EnFyBkPB5ddXQSABAwz7D52HhTMgy+I/9aEsbDC2vgJtK6WQpdrvbuVUdFYH3J5qeObU2lnlokscEN1tmYQ5p8eDJJZMhl7QEjOMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191510; 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=SIqRKpGOZjPxmdKdKN67QtJRVMylqHIjbGEPHXGOhWg=; b=exIVavvxStfywb6SqSYpgMdcZeEW76xjAhnG7B0bcoGWCPWIIOFjQpA5WwYc8GsSD1eviUeGg0ZD9DYOlOXJ3LyGRiCrHINIjAM5n+qducoN7BI7nuFOZo+gjFxVhnCnPh5Kz+2qB5bXPGf4FE+OjVYn8JOX0rdlNITmVwiZXw4= 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 1758191510748985.646277593738; Thu, 18 Sep 2025 03:31:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBua-00074O-Om; Thu, 18 Sep 2025 06:30:48 -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 1uzBuX-00071V-Sa for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:45 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzBuV-0001Nx-Ng for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:45 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id D099C60214; Thu, 18 Sep 2025 10:30:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBCC2C4CEFE; Thu, 18 Sep 2025 10:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191442; bh=WQk9MBDv7nge73LxcacIBKkMtT+aMc7tLLXhrGU/S2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WRivwrlFpEdBE9zknDmPdHKbYcPZ0PDWvVe9w4+L62Fx9C1AnE9cuyOppiXwteHKc 3zq46P/m1t0vXAUMUqRH0BsokBHBTvWqEJ92tbV4s1xrYu2zesOwqa1pAUm5KFmR7R 3lw+yG5n7bb09WXGGcJOTFHGyLfBXiwnsAgG/g5Z7Ol2pyxmHNfVwisELciCxMOt51 HQySSWhCw31+MFqMgydqFOvd51CGiyx6/5OWX1iYkjV+Rfat6flCLF3OfZm3wlioDt 6/fkG8/FnqQm22VOoCs0TL6piRKvNl0oRFSP50khi2Nb6eUremK+GjuFkgrnMvDHQq B3Hd3W2YClWaw== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 7/8] target/i386: SEV: Add support for enabling Secure TSC SEV feature Date: Thu, 18 Sep 2025 15:57:05 +0530 Message-ID: <9ef2a9ef63f4737efe7a926703222b6bf51b7bad.1758189463.git.naveen@kernel.org> X-Mailer: git-send-email 2.51.0 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.105.4.254; envelope-from=naveen@kernel.org; helo=tor.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: 1758191511904116600 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. By default, KVM uses the host TSC frequency for Secure TSC. 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) Reviewed-by: Tom Lendacky --- target/i386/sev.h | 1 + target/i386/sev.c | 13 +++++++++++++ qapi/qom.json | 6 +++++- 3 files changed, 19 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 6b11359f06dd..679bedb63c3a 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 df962d4a5215..52c23e85e349 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1100,6 +1100,9 @@ # 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 +1114,8 @@ '*id-auth': 'str', '*author-key-enabled': 'bool', '*host-data': 'str', - '*vcek-disabled': 'bool' } } + '*vcek-disabled': 'bool', + '*secure-tsc': 'bool' } } =20 ## # @TdxGuestProperties: --=20 2.51.0 From nobody Sat Nov 15 00:46:06 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=1758191513; cv=none; d=zohomail.com; s=zohoarc; b=mTCjZwLZ/y//8glrh78SFQmps729fTl6JNLCSQwZSXI2YmHdfMh5mxaxWls1dwmdLWjm5/RctnIQkEnD7km4B2yA9xmQtPdlAtyvgVTLGj/jFtjeFZ3NXETbdbk+HBF7xITbk5j8YXTjqgmJkYWerfddqvmwQR3uFpJyEvui6Ys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758191513; 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=V441rrLf3CcJ2KUupcV8NPoqCoYxouqmCaY6s6fIL7Q=; b=KM1f/6Kp/kLNPu3rfNiJrl26SzVlilc354mGtBVIaM6nE30dq6RUBZLP9cwuIAdeGffKaq0Mwtd21iELs0ZSertsEhbUq+NZYwcRC19N6J9zcw9rrBA6hRjlm10Lgp0PzkY2vs4/sMm3B9E1oVjufKsdhbr2OObQ2+KiciJbhds= 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 1758191513275878.6918570303279; Thu, 18 Sep 2025 03:31:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzBue-000770-7l; Thu, 18 Sep 2025 06:30:52 -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 1uzBuc-000766-50 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30: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 1uzBuZ-0001OJ-TW for qemu-devel@nongnu.org; Thu, 18 Sep 2025 06:30:49 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 3B9A94178A; Thu, 18 Sep 2025 10:30:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D072C4CEEB; Thu, 18 Sep 2025 10:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758191446; bh=iuqycozjbpUF2qdpbTkjQOSZMXX5AoQ7UjWfDC2opOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VyVBFbVmmbTjyWjoWdPpAQA0t4ZSvJ5gQhvi56Ul8W7dQiaYySzOwEKrtMPfONGSq mltpdguC3ZhAA3xizkgvlozYtHaacUniNHbfEtpCJH38e6qyhGxEpuK0XMivubi17I uDnsM1f5txvoc+VgQ9z17XHgmQSax804NLg/ZzXGo7FHmz06QJQLF7O0n6RFAescXe qnTNNJ0g3G/xOMkpv7aLef4CDc/SdhBInv6NDo1+3iBtgvmzewNzEgGeU4b6huI8M3 wVkZ+fkMIokWl1oAVDF6xh3McDMZUA73fZmtp89oUPstt2ib3TnL9EcI75ABMIyU2Q fvTUCRurSXk4g== From: "Naveen N Rao (AMD)" To: Paolo Bonzini , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel , , Tom Lendacky , Nikunj A Dadhania , "Daniel P. Berrange" , Eduardo Habkost , Zhao Liu , Michael Roth , Roy Hopkins Subject: [PATCH 8/8] target/i386: SEV: Add support for setting TSC frequency for Secure TSC Date: Thu, 18 Sep 2025 15:57:06 +0530 Message-ID: <6a9b3e02d1a1eb903bd3e7c9596dfe00029de01e.1758189463.git.naveen@kernel.org> X-Mailer: git-send-email 2.51.0 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: 1758191515986116600 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 679bedb63c3a..ef54265f4e46 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 52c23e85e349..c01ae70dd43d 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1103,6 +1103,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', @@ -1115,7 +1118,8 @@ '*author-key-enabled': 'bool', '*host-data': 'str', '*vcek-disabled': 'bool', - '*secure-tsc': 'bool' } } + '*secure-tsc': 'bool', + '*tsc-frequency': 'uint32' } } =20 ## # @TdxGuestProperties: --=20 2.51.0