From nobody Mon Feb 9 11:32:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633623516; cv=none; d=zohomail.com; s=zohoarc; b=Xj/Th/jAJIsemXKzjtjZPqQPAEPRHarCpnxBooEgezng2qqkD481m//pi58dYJIB4ff2y9yfeDVFS+NechBKRos/eG7r+0xlK1qC2Tf5kCbrlIN+kuVmuuJCDAexxKTdDu1awR9u2cnrQk9oonxDxiB8bxJA7P+9juBZNBdl96c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633623516; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=avS7dA1xbWdOVEvDf5GxDqun22mmkWzrjGDOVnO4aN8=; b=KenWrou97c7SI6Oa308iZpOdMtyyBHcnmEFm5x1kDXhLrFS9LNCfBvqxqrHv0XSivxiKCUAD/M8ZLDL9e1P5RU7lCC+TlEioXuKPmL94t0oKEynrBiudDL0KAPA4V7aZnvSLRLhyf2hw+0cEVw3HxP4p0q7Y/Vqot4/zQqDz6Mc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633623516800417.096555044748; Thu, 7 Oct 2021 09:18:36 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-Ha_wp889PWCW0ED4CdxgTA-1; Thu, 07 Oct 2021 12:18:32 -0400 Received: by mail-wr1-f69.google.com with SMTP id v15-20020adfa1cf000000b00160940b17a2so5117725wrv.19 for ; Thu, 07 Oct 2021 09:18:32 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id q3sm19131wmc.25.2021.10.07.09.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 09:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633623515; 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=avS7dA1xbWdOVEvDf5GxDqun22mmkWzrjGDOVnO4aN8=; b=JtU1wQCJsGDZ/EQZMUOggqLd6zddC3O51Hw20thp+pVRJue0/EFnj2HFelIhn49LhtQWgt PU5bj8Fg2GFl/RI84GhUckmmcuDO6S99YKefAdtqtw0IIGjhGaoA5rMx4qO4M+TF304Uzr X4LZO+5UmS0biKO82mr0asGTqGDAU34= X-MC-Unique: Ha_wp889PWCW0ED4CdxgTA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=avS7dA1xbWdOVEvDf5GxDqun22mmkWzrjGDOVnO4aN8=; b=3QtstrZikhQB/AZ8E5c5BvwfoNhFlE1LC3ZNug4P+IKwzRQOFtFqJh1QgU7qdFN62A +cNDth6KdZZI68EUAXGInPo0mme1q/eyPR6rA4lS2Mj6vea9nYNFcJ/C8zsri7agA3a1 jwYHPrzA5aqHCLloYavKJR55rAbVT6O4MGshUnZBR7549KOVsvvtU9veYbTmKMYSep3h oReSh9HzU8DIc2+i0QsUz9tC/Z/eXeqEOb97hUafT9LPv2k1OrptXc6S1YYuomKpBRdl uCkWr3J6two4MOXST9G13p3aVxSn+GzVuMSgoO11Nk6PA6eDws6ciRAWimEXmeDP+Bop N8VQ== X-Gm-Message-State: AOAM531H05ZW45rS5bn9oGBI8+jKWocyX2D3d4dSCqxuEeZ1011PoYXL W/aUk1zktc3I2RJfTLgEUbABRUPOgJKsPWdrbbwGIT5oNNWK41wkzOAJaNsAObcsEloOnFzHsWn uao1EjW0rGJOFpA== X-Received: by 2002:adf:a550:: with SMTP id j16mr6790540wrb.180.1633623511670; Thu, 07 Oct 2021 09:18:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiNFDP2mIfyzBdX6qysBlWdROekH+j9h8XYmdGma4KNZrh1RRhjU928Fdh1xrhu6HNRCOYpw== X-Received: by 2002:adf:a550:: with SMTP id j16mr6790510wrb.180.1633623511460; Thu, 07 Oct 2021 09:18:31 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , James Bottomley , Brijesh Singh , Sergio Lopez , Dov Murik , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 16/23] target/i386/sev: Remove stubs by using code elision Date: Thu, 7 Oct 2021 18:17:09 +0200 Message-Id: <20211007161716.453984-17-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007161716.453984-1-philmd@redhat.com> References: <20211007161716.453984-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633623518279100001 Only declare sev_enabled() and sev_es_enabled() when CONFIG_SEV is set, to allow the compiler to elide unused code. Remove unnecessary stubs. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake --- target/i386/sev.h | 14 ++++++++++++-- target/i386/cpu.c | 13 +++++++------ target/i386/sev-stub.c | 41 ----------------------------------------- target/i386/meson.build | 2 +- 4 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 target/i386/sev-stub.c diff --git a/target/i386/sev.h b/target/i386/sev.h index c96072bf78d..d9548e3e642 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -14,6 +14,10 @@ #ifndef QEMU_SEV_I386_H #define QEMU_SEV_I386_H =20 +#ifndef CONFIG_USER_ONLY +#include CONFIG_DEVICES /* CONFIG_SEV */ +#endif + #include "exec/confidential-guest-support.h" #include "qapi/qapi-types-misc-target.h" =20 @@ -35,8 +39,14 @@ typedef struct SevKernelLoaderContext { size_t cmdline_size; } SevKernelLoaderContext; =20 -bool sev_enabled(void); -extern bool sev_es_enabled(void); +#ifdef CONFIG_SEV + bool sev_enabled(void); +bool sev_es_enabled(void); +#else +#define sev_enabled() 0 +#define sev_es_enabled() 0 +#endif + extern SevInfo *sev_get_info(void); extern uint32_t sev_get_cbit_position(void); extern uint32_t sev_get_reduced_phys_bits(void); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8289dc87bd5..fc3ed80ef1e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5764,12 +5764,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D 0; break; case 0x8000001F: - *eax =3D sev_enabled() ? 0x2 : 0; - *eax |=3D sev_es_enabled() ? 0x8 : 0; - *ebx =3D sev_get_cbit_position(); - *ebx |=3D sev_get_reduced_phys_bits() << 6; - *ecx =3D 0; - *edx =3D 0; + *eax =3D *ebx =3D *ecx =3D *edx =3D 0; + if (sev_enabled()) { + *eax =3D 0x2; + *eax |=3D sev_es_enabled() ? 0x8 : 0; + *ebx =3D sev_get_cbit_position(); + *ebx |=3D sev_get_reduced_phys_bits() << 6; + } break; default: /* reserved values: zero */ diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c deleted file mode 100644 index 7e8b6f9a259..00000000000 --- a/target/i386/sev-stub.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * QEMU SEV stub - * - * Copyright Advanced Micro Devices 2018 - * - * Authors: - * Brijesh Singh - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - * - */ - -#include "qemu/osdep.h" -#include "qapi/error.h" -#include "sev.h" - -bool sev_enabled(void) -{ - return false; -} - -uint32_t sev_get_cbit_position(void) -{ - return 0; -} - -uint32_t sev_get_reduced_phys_bits(void) -{ - return 0; -} - -bool sev_es_enabled(void) -{ - return false; -} - -bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **err= p) -{ - g_assert_not_reached(); -} diff --git a/target/i386/meson.build b/target/i386/meson.build index a4f45c3ec1d..ae38dc95635 100644 --- a/target/i386/meson.build +++ b/target/i386/meson.build @@ -6,7 +6,7 @@ 'xsave_helper.c', 'cpu-dump.c', )) -i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false: fi= les('sev-stub.c')) +i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c')) =20 # x86 cpu type i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c')) --=20 2.31.1