From nobody Mon Nov 25 07:52:43 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717483737; cv=none; d=zohomail.com; s=zohoarc; b=Kbbqp1cfjKh11qx+poWqOL1V4Zme6Hq3yGWGl1UgXrPexu5V17S2IDJsEBdqnWI+zwR30ijqluymrKfjZIE7PCwnzs3qlNG7j2UZ1ayZx5H3DD7cZrXUl2cf7r/D6nhKDHBSCfZJBeUMyrU4Cyc+0dSlbtsalTEME4FFsPt7Cfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717483737; h=Content-Type: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=tsVpLdbmx/uPeSaF81fFP7gyNO79Fr2K1Tb3dOWWZos=; b=MnrdsEI+i+XnrcvU9yv0T30pDwLPXXAjVtsn1hWzafAPZ+T/Vdxv2k32/humXkaKO0ocg461Ujo7Ae8keWFGbk+qahTD86LMkZUexCuYRAxU6u9FB86VUWBL7SZJCsQwExf8DRSAvTKKnWOeKisw3hl+yMBuleF++pmoX+FmJvM= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717483737775577.7415079944655; Mon, 3 Jun 2024 23:48:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sENva-0004FE-3P; Tue, 04 Jun 2024 02:45:51 -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 1sENvB-00045j-GY for qemu-devel@nongnu.org; Tue, 04 Jun 2024 02:45:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sENvA-0007XL-0m for qemu-devel@nongnu.org; Tue, 04 Jun 2024 02:45:25 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-8KReu0TsMMqUrVI9AYnB8w-1; Tue, 04 Jun 2024 02:45:19 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a68b41fb17cso228170966b.0 for ; Mon, 03 Jun 2024 23:45:19 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68ed879eacsm351732466b.99.2024.06.03.23.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 23:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717483523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tsVpLdbmx/uPeSaF81fFP7gyNO79Fr2K1Tb3dOWWZos=; b=dN1GTR9nQutqHib0rsmxfMLu8LIPCigmZ4R4V6H7jIqO4Uhv8ZHDfj1DNQQpbLtaG1ig02 D7kcvysblljQ0hbn2vkU/3ckxsieyR3xZtcyFWR+kXX7BHQBae/apvygSWCWtHecmVFrTy CqGSRbKinTi2bCsUTKxtaCE3lX49/OI= X-MC-Unique: 8KReu0TsMMqUrVI9AYnB8w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717483517; x=1718088317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tsVpLdbmx/uPeSaF81fFP7gyNO79Fr2K1Tb3dOWWZos=; b=V5lyU/uUFw/XgZB9N6xnAlI3ODc9uY6lhR8e0/qRSKK6jyKQovvWoMDbyktYl27niV W2acO68bxSDiBO7Vu74QOyKG6iRv2Xg6C7id4S4KIpFO/+Mz8M2S+hdX5hoOe6QzigbO lcwYwxn+elturguypuUhpLYnnXxSpIOxDhBYvnQc6i2VsvOJmkuDCbROnxJy0//F94iC NT9WQBMT8XnAbdomsNqcjqha+9+996DeZs6eFfsNlT3oPsvNvhMvzhIjpQZjFXQW3Tak Kt92SLhCRv6SAw4Mm/YYz1nAp6RpvRdchz/tZbznVJjvHtJmAWJn6NpJlpkQLUuXP47z 0gMw== X-Gm-Message-State: AOJu0YwTJfiQ1HgAx/9Jrduzqt2YYZ4D/AqPRHYiIwQVrbVj63qIr9d9 ZkStBeVFIqbYhm71L1gz+Ewb0Olw504mcDc+Mj2f7bARkhEo13BigquyK64S/c2DgXTOhLBxk+/ cxXJejihk9cbL5N9iypgqNDbaU1ptPKrrl19GFBhbmWdmAGepcOYOhnDNM+8eec/umIzV/snTNX SmPs8upCcrUrpYJs5TeFLs8yAViPjsR7Jf/gS0 X-Received: by 2002:a17:906:16d2:b0:a68:b5ea:171c with SMTP id a640c23a62f3a-a69542a0f0bmr128002766b.16.1717483517574; Mon, 03 Jun 2024 23:45:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCkyL+1eb4HhYrUjYTM1c6MEz6bRO5hWqWuOjWTRHopjBThP9l2GzNsYdZE3xRqAfvLdGQ8w== X-Received: by 2002:a17:906:16d2:b0:a68:b5ea:171c with SMTP id a640c23a62f3a-a69542a0f0bmr128001066b.16.1717483517210; Mon, 03 Jun 2024 23:45:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Michael Roth , Pankaj Gupta Subject: [PULL 22/45] i386/sev: Add a sev_snp_enabled() helper Date: Tue, 4 Jun 2024 08:43:46 +0200 Message-ID: <20240604064409.957105-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604064409.957105-1-pbonzini@redhat.com> References: <20240604064409.957105-1-pbonzini@redhat.com> 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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 @redhat.com) X-ZM-MESSAGEID: 1717483738773100003 Content-Type: text/plain; charset="utf-8" From: Michael Roth Add a simple helper to check if the current guest type is SNP. Also have SNP-enabled imply that SEV-ES is enabled as well, and fix up any places where the sev_es_enabled() check is expecting a pure/non-SNP guest. Signed-off-by: Michael Roth Signed-off-by: Pankaj Gupta Message-ID: <20240530111643.1091816-9-pankaj.gupta@amd.com> Signed-off-by: Paolo Bonzini --- target/i386/sev.h | 2 ++ target/i386/sev.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.h b/target/i386/sev.h index bedc667eeba..94295ee74f7 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -45,9 +45,11 @@ typedef struct SevKernelLoaderContext { #ifdef CONFIG_SEV bool sev_enabled(void); bool sev_es_enabled(void); +bool sev_snp_enabled(void); #else #define sev_enabled() 0 #define sev_es_enabled() 0 +#define sev_snp_enabled() 0 #endif =20 uint32_t sev_get_cbit_position(void); diff --git a/target/i386/sev.c b/target/i386/sev.c index a81b3228d4c..4edfedc1393 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -325,12 +325,21 @@ sev_enabled(void) return !!object_dynamic_cast(OBJECT(cgs), TYPE_SEV_COMMON); } =20 +bool +sev_snp_enabled(void) +{ + ConfidentialGuestSupport *cgs =3D MACHINE(qdev_get_machine())->cgs; + + return !!object_dynamic_cast(OBJECT(cgs), TYPE_SEV_SNP_GUEST); +} + bool sev_es_enabled(void) { ConfidentialGuestSupport *cgs =3D MACHINE(qdev_get_machine())->cgs; =20 - return sev_enabled() && (SEV_GUEST(cgs)->policy & SEV_POLICY_ES); + return sev_snp_enabled() || + (sev_enabled() && SEV_GUEST(cgs)->policy & SEV_POLICY_ES); } =20 uint32_t @@ -946,7 +955,9 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, = Error **errp) "support", __func__); goto err; } + } =20 + if (sev_es_enabled() && !sev_snp_enabled()) { if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) { error_setg(errp, "%s: guest policy requires SEV-ES, but " "host SEV-ES support unavailable", --=20 2.45.1