From nobody Fri Nov 14 19:39:05 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=1761648444; cv=none; d=zohomail.com; s=zohoarc; b=ShZ3zWZaSRxNhIZbhrA+bbi4HDXDFlb9miaHil3uGzc/eHwi65zSow6RnLHPFdSx9iwuoMoInNHe4CnvLY7txR7xX1flvy3sKBrbUOzQeV+PirMTCZZQ+y6XfbGi/TEd/OEPS0nz6xyQ7Z34YANZ4v3anU8BDq9dYa8f5BXKnWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761648444; 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=1X3Cvx0xDYSk/Rw52AD+6QSRYyGsoteW5TuQUBul1Hc=; b=fV3dyK+uYp7Pbfbg85Rnjm/9HdmO6ZuvwHazntP7QFjZ23BZ2Ln2zxsJyPJ80OF21KzZsKugPzM4Ya3RqG7mZ3nmAJ2i3Sv9XtM4Z+T71O7xmYHYagZDxB7HRUFzplXw4+WBoJ1kgnK55sgL5nNmLLGg5YBh0YUdwU/9oX6xjWo= 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 1761648444610220.48695655960967; Tue, 28 Oct 2025 03:47:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDhEO-0008T2-09; Tue, 28 Oct 2025 06:47:12 -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 1vDhDe-0007rr-2U for qemu-devel@nongnu.org; Tue, 28 Oct 2025 06:46:29 -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 1vDhDS-0005lF-CC for qemu-devel@nongnu.org; Tue, 28 Oct 2025 06:46:25 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 87F7741513; Tue, 28 Oct 2025 10:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 490E3C4CEE7; Tue, 28 Oct 2025 10:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761648372; bh=DMy/sGWIKYOYAjfxscxSO7zrh4vdvWXqXux+y2OofO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LGmEIE6qmOBBUaiw68FMIieV16L+rar82q/drLlhQLM1onQOrYezk8+4Ate2yOR4s MTikW5B73j5StNYZFvRZN/pHUwNiJMpuwT3F4u3vtqQQL9hIGycH3BKiSHavS75BZJ r0ohZLYqZqhK89HWnDvGRPvYLsefoHeWNONhzdVP7EIrrI9v1Xg+bLrFMS7QeJM2ox iwe4JrM6HznAWZ8pbWx0anIU/Ov95THrPZ5bU4jjKZiomAK9Yb5IFiyz3bPsGIFYZU QffCnlCt3AEUVSOQQgK80W2BLrXpHLi2bA+vOyMd+rFfusW+JUfvBlXkkC4O33Ds2o AjR00ZN7JjcCQ== From: "Naveen N Rao (AMD)" To: qemu-devel Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Eric Blake , Markus Armbruster , Marcelo Tosatti , Zhao Liu , Nikunj A Dadhania , Tom Lendacky , Michael Roth , Roy Hopkins , Srikanth Aithal Subject: [PATCH v3 1/9] target/i386: SEV: Generalize handling of SVM_SEV_FEAT_SNP_ACTIVE Date: Tue, 28 Oct 2025 16:13:26 +0530 Message-ID: <2bd23921fa66a3857892bf082dbf80508f93b076.1761648149.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: 1761648447091154100 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. Reviewed-by: Tom Lendacky Signed-off-by: Naveen N Rao (AMD) --- 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