From nobody Sun Sep 28 17:41:23 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