qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Dov Murik <dovmurik@linux.ibm.com>
Cc: "Brijesh Singh" <brijesh.singh@amd.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Sergio Lopez" <slp@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"James Bottomley" <jejb@linux.ibm.com>,
	qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH 1/2] target/i386/sev: Use local variable for kvm_sev_launch_start
Date: Mon, 11 Oct 2021 18:55:20 +0100	[thread overview]
Message-ID: <YWR6iPrZQUiv3FWC@work-vm> (raw)
In-Reply-To: <20211011173026.2454294-2-dovmurik@linux.ibm.com>

* Dov Murik (dovmurik@linux.ibm.com) wrote:
> The struct kvm_sev_launch_start has a constant and small size, and
> therefore we can use a regular local variable for it instead of
> allocating and freeing heap memory for it.
> 
> Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  target/i386/sev.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 4c64c68244..0062566c71 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -647,31 +647,29 @@ sev_launch_start(SevGuestState *sev)
>      gsize sz;
>      int ret = 1;
>      int fw_error, rc;
> -    struct kvm_sev_launch_start *start;
> +    struct kvm_sev_launch_start start = {
> +        .handle = sev->handle, .policy = sev->policy
> +    };
>      guchar *session = NULL, *dh_cert = NULL;
>  
> -    start = g_new0(struct kvm_sev_launch_start, 1);
> -
> -    start->handle = sev->handle;
> -    start->policy = sev->policy;
>      if (sev->session_file) {
>          if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) {
>              goto out;
>          }
> -        start->session_uaddr = (unsigned long)session;
> -        start->session_len = sz;
> +        start.session_uaddr = (unsigned long)session;
> +        start.session_len = sz;
>      }
>  
>      if (sev->dh_cert_file) {
>          if (sev_read_file_base64(sev->dh_cert_file, &dh_cert, &sz) < 0) {
>              goto out;
>          }
> -        start->dh_uaddr = (unsigned long)dh_cert;
> -        start->dh_len = sz;
> +        start.dh_uaddr = (unsigned long)dh_cert;
> +        start.dh_len = sz;
>      }
>  
> -    trace_kvm_sev_launch_start(start->policy, session, dh_cert);
> -    rc = sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error);
> +    trace_kvm_sev_launch_start(start.policy, session, dh_cert);
> +    rc = sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_START, &start, &fw_error);
>      if (rc < 0) {
>          error_report("%s: LAUNCH_START ret=%d fw_error=%d '%s'",
>                  __func__, ret, fw_error, fw_error_to_str(fw_error));
> @@ -679,11 +677,10 @@ sev_launch_start(SevGuestState *sev)
>      }
>  
>      sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE);
> -    sev->handle = start->handle;
> +    sev->handle = start.handle;
>      ret = 0;
>  
>  out:
> -    g_free(start);
>      g_free(session);
>      g_free(dh_cert);
>      return ret;
> -- 
> 2.25.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2021-10-11 17:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 17:30 [PATCH 0/2] target/i386/sev: Replace malloc with local variables Dov Murik
2021-10-11 17:30 ` [PATCH 1/2] target/i386/sev: Use local variable for kvm_sev_launch_start Dov Murik
2021-10-11 17:55   ` Dr. David Alan Gilbert [this message]
2021-10-11 17:30 ` [PATCH 2/2] target/i386/sev: Use local variable for kvm_sev_launch_measure Dov Murik
2021-10-11 17:57   ` Dr. David Alan Gilbert
2021-10-12 11:02 ` [PATCH 0/2] target/i386/sev: Replace malloc with local variables Paolo Bonzini

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=YWR6iPrZQUiv3FWC@work-vm \
    --to=dgilbert@redhat.com \
    --cc=brijesh.singh@amd.com \
    --cc=dovmurik@linux.ibm.com \
    --cc=ehabkost@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.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).