qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Daniel P . Berrange" <berrange@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Sergio Lopez <slp@redhat.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, Dov Murik <dovmurik@linux.ibm.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Eric Blake <eblake@redhat.com>
Subject: Re: [PATCH v4 16/23] target/i386/sev: Remove stubs by using code elision
Date: Thu, 7 Oct 2021 18:22:34 +0100	[thread overview]
Message-ID: <YV8s2r+lNyP/sX7u@work-vm> (raw)
In-Reply-To: <6080fa16-66aa-570e-93c8-09be2ced9431@redhat.com>

* Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
> On 10/7/21 19:07, Dr. David Alan Gilbert wrote:
> > * Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
> >> 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>
> > 
> > What makes it allowed to *rely* on the compiler eliding calls?
> 
> I am not aware of a particular requirement on the compiler for code
> elision, however we already use this syntax:
> 
> $ git grep -A4 'ifdef CONFIG_' include/sysemu/
> ...
> include/sysemu/tcg.h:11:#ifdef CONFIG_TCG
> include/sysemu/tcg.h-12-extern bool tcg_allowed;
> include/sysemu/tcg.h-13-#define tcg_enabled() (tcg_allowed)
> include/sysemu/tcg.h-14-#else
> include/sysemu/tcg.h-15-#define tcg_enabled() 0

So that I'm fine with, the bit I'm more worried about is the bit where
inside the if () we call functions (like sev_get_cbit_position )  which
we know the compiler will elide; I'm sure any sane compiler will,
but.....

Looking at your example, in cpu.c there's still places that ifdef around
areas with tcg_enabled.

Dave

> ...
> 
> Cc'ing Richard/Eric/Daniel who have more experience with compiler
> features in case they can enlighten me here.
> 
> >> ---
> >>  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
> >>  
> >> +#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;
> >>  
> >> -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 = 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/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 <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/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: 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'))
> >> -- 
> >> 2.31.1
> >>
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2021-10-07 17:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 16:16 [PATCH v4 00/23] target/i386/sev: Housekeeping SEV + measured Linux SEV guest Philippe Mathieu-Daudé
2021-10-07 16:16 ` [PATCH v4 01/23] qapi/misc-target: Wrap long 'SEV Attestation Report' long lines Philippe Mathieu-Daudé
2021-10-07 16:16 ` [PATCH v4 02/23] qapi/misc-target: Group SEV QAPI definitions Philippe Mathieu-Daudé
2021-10-07 16:16 ` [PATCH v4 03/23] target/i386/kvm: Introduce i386_softmmu_kvm Meson source set Philippe Mathieu-Daudé
2021-10-07 16:16 ` [PATCH v4 04/23] target/i386/kvm: Restrict SEV stubs to x86 architecture Philippe Mathieu-Daudé
2021-10-07 16:16 ` [PATCH v4 05/23] target/i386/sev: Prefix QMP errors with 'SEV' Philippe Mathieu-Daudé
2021-10-07 16:23   ` Dr. David Alan Gilbert
2021-10-07 16:16 ` [PATCH v4 06/23] target/i386/monitor: Return QMP error when SEV is not enabled for guest Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 07/23] target/i386/cpu: Add missing 'qapi/error.h' header Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 08/23] target/i386/sev_i386.h: Remove unused headers Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 09/23] target/i386/sev: Remove sev_get_me_mask() Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 10/23] target/i386/sev: Mark unreachable code with g_assert_not_reached() Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 11/23] target/i386/sev: sev_get_attestation_report use g_autofree Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 12/23] target/i386/sev: Use g_autofree in sev_launch_get_measure() Philippe Mathieu-Daudé
2021-10-07 16:28   ` Dov Murik
2021-10-12  6:15     ` Dov Murik
2021-10-07 16:17 ` [PATCH v4 13/23] target/i386/sev: Restrict SEV to system emulation Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 14/23] target/i386/sev: Rename sev_i386.h -> sev.h Philippe Mathieu-Daudé
2021-10-07 16:32   ` Dr. David Alan Gilbert
2021-10-07 16:17 ` [PATCH v4 15/23] target/i386/sev: Declare system-specific functions in 'sev.h' Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 16/23] target/i386/sev: Remove stubs by using code elision Philippe Mathieu-Daudé
2021-10-07 17:07   ` Dr. David Alan Gilbert
2021-10-07 17:18     ` Philippe Mathieu-Daudé
2021-10-07 17:22       ` Dr. David Alan Gilbert [this message]
2021-10-08 11:46         ` Paolo Bonzini
2021-10-07 17:27       ` Daniel P. Berrangé
2021-10-07 19:51   ` Eric Blake
2021-10-07 16:17 ` [PATCH v4 17/23] target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 18/23] target/i386/sev: Move qmp_sev_inject_launch_secret() " Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 19/23] target/i386/sev: Move qmp_query_sev_capabilities() " Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 20/23] target/i386/sev: Move qmp_query_sev_launch_measure() " Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 21/23] target/i386/sev: Move qmp_query_sev() & hmp_info_sev() " Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 22/23] monitor: Reduce hmp_info_sev() declaration Philippe Mathieu-Daudé
2021-10-07 16:17 ` [PATCH v4 23/23] MAINTAINERS: Cover SEV-related files with X86/KVM section Philippe Mathieu-Daudé
2021-10-07 16:22   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YV8s2r+lNyP/sX7u@work-vm \
    --to=dgilbert@redhat.com \
    --cc=berrange@redhat.com \
    --cc=brijesh.singh@amd.com \
    --cc=dovmurik@linux.ibm.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=slp@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).