[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/40] target/i386/sev: Remove stubs by using code elision
From: |
Paolo Bonzini |
Subject: |
[PULL 21/40] target/i386/sev: Remove stubs by using code elision |
Date: |
Wed, 13 Oct 2021 11:07:09 +0200 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
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é <philmd@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20211007161716.453984-17-philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.c | 13 +++++++------
target/i386/meson.build | 2 +-
target/i386/sev-stub.c | 41 -----------------------------------------
target/i386/sev.h | 12 +++++++++++-
4 files changed, 19 insertions(+), 49 deletions(-)
delete mode 100644 target/i386/sev-stub.c
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 8289dc87bd..fc3ed80ef1 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 = 0;
break;
case 0x8000001F:
- *eax = sev_enabled() ? 0x2 : 0;
- *eax |= sev_es_enabled() ? 0x8 : 0;
- *ebx = sev_get_cbit_position();
- *ebx |= sev_get_reduced_phys_bits() << 6;
- *ecx = 0;
- *edx = 0;
+ *eax = *ebx = *ecx = *edx = 0;
+ if (sev_enabled()) {
+ *eax = 0x2;
+ *eax |= sev_es_enabled() ? 0x8 : 0;
+ *ebx = sev_get_cbit_position();
+ *ebx |= sev_get_reduced_phys_bits() << 6;
+ }
break;
default:
/* reserved values: zero */
diff --git a/target/i386/meson.build b/target/i386/meson.build
index a4f45c3ec1..ae38dc9563 100644
--- a/target/i386/meson.build
+++ b/target/i386/meson.build
@@ -6,7 +6,7 @@ i386_ss.add(files(
'xsave_helper.c',
'cpu-dump.c',
))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'), if_false:
files('sev-stub.c'))
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c'))
# x86 cpu type
i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))
diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c
deleted file mode 100644
index 7e8b6f9a25..0000000000
--- a/target/i386/sev-stub.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * QEMU SEV stub
- *
- * Copyright Advanced Micro Devices 2018
- *
- * Authors:
- * Brijesh Singh <brijesh.singh@amd.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * 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 **errp)
-{
- g_assert_not_reached();
-}
diff --git a/target/i386/sev.h b/target/i386/sev.h
index c96072bf78..b6289234b0 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
+#ifndef CONFIG_USER_ONLY
+#include CONFIG_DEVICES /* CONFIG_SEV */
+#endif
+
#include "exec/confidential-guest-support.h"
#include "qapi/qapi-types-misc-target.h"
@@ -35,8 +39,14 @@ typedef struct SevKernelLoaderContext {
size_t cmdline_size;
} SevKernelLoaderContext;
+#ifdef CONFIG_SEV
bool sev_enabled(void);
-extern bool sev_es_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);
--
2.31.1
- [PULL 07/40] qapi/misc-target: Group SEV QAPI definitions, (continued)
- [PULL 07/40] qapi/misc-target: Group SEV QAPI definitions, Paolo Bonzini, 2021/10/13
- [PULL 10/40] target/i386/sev: Prefix QMP errors with 'SEV', Paolo Bonzini, 2021/10/13
- [PULL 17/40] target/i386/sev: Use g_autofree in sev_launch_get_measure(), Paolo Bonzini, 2021/10/13
- [PULL 22/40] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 06/40] qapi/misc-target: Wrap long 'SEV Attestation Report' long lines, Paolo Bonzini, 2021/10/13
- [PULL 11/40] target/i386/monitor: Return QMP error when SEV is not enabled for guest, Paolo Bonzini, 2021/10/13
- [PULL 14/40] target/i386/sev: Remove sev_get_me_mask(), Paolo Bonzini, 2021/10/13
- [PULL 19/40] target/i386/sev: Rename sev_i386.h -> sev.h, Paolo Bonzini, 2021/10/13
- [PULL 25/40] target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 15/40] target/i386/sev: Mark unreachable code with g_assert_not_reached(), Paolo Bonzini, 2021/10/13
- [PULL 21/40] target/i386/sev: Remove stubs by using code elision,
Paolo Bonzini <=
- [PULL 26/40] target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 28/40] MAINTAINERS: Cover SEV-related files with X86/KVM section, Paolo Bonzini, 2021/10/13
- [PULL 29/40] qapi: Make some ObjectTypes depend on the build settings, Paolo Bonzini, 2021/10/13
- [PULL 30/40] tests: tcg: Fix PVH test with binutils 2.36+, Paolo Bonzini, 2021/10/13
- [PULL 12/40] target/i386/cpu: Add missing 'qapi/error.h' header, Paolo Bonzini, 2021/10/13
- [PULL 13/40] target/i386/sev_i386.h: Remove unused headers, Paolo Bonzini, 2021/10/13
- [PULL 18/40] target/i386/sev: Restrict SEV to system emulation, Paolo Bonzini, 2021/10/13
- [PULL 16/40] target/i386/sev: sev_get_attestation_report use g_autofree, Paolo Bonzini, 2021/10/13
- [PULL 24/40] target/i386/sev: Move qmp_query_sev_capabilities() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 27/40] monitor: Reduce hmp_info_sev() declaration, Paolo Bonzini, 2021/10/13