From nobody Sat Nov 15 01:21:20 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