qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
	kvm@vger.kernel.org, Peter Xu <peterx@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value
Date: Fri, 21 Feb 2020 18:03:56 +0100	[thread overview]
Message-ID: <a6d29e18-722c-77d1-ca56-220b3b02ae00@redhat.com> (raw)
In-Reply-To: <20200221163336.2362-1-philmd@redhat.com>

On 21/02/20 17:33, Philippe Mathieu-Daudé wrote:
> kvm_vm_ioctl() can fail, check its return value, and log an error
> when it failed. This fixes Coverity CID 1412229:
> 
>   Unchecked return value (CHECKED_RETURN)
> 
>   check_return: Calling kvm_vm_ioctl without checking return value
> 
> Reported-by: Coverity (CID 1412229)
> Fixes: 235e8982ad3 ("support using KVM_MEM_READONLY flag for regions")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  accel/kvm/kvm-all.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index c111312dfd..6df3a4d030 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -308,13 +308,23 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo
>          /* Set the slot size to 0 before setting the slot to the desired
>           * value. This is needed based on KVM commit 75d61fbc. */
>          mem.memory_size = 0;
> -        kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
> +        ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
> +        if (ret < 0) {
> +            goto err;
> +        }
>      }
>      mem.memory_size = slot->memory_size;
>      ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
>      slot->old_flags = mem.flags;
> +err:
>      trace_kvm_set_user_memory(mem.slot, mem.flags, mem.guest_phys_addr,
>                                mem.memory_size, mem.userspace_addr, ret);
> +    if (ret < 0) {
> +        error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot=%d,"
> +                     " start=0x%" PRIx64 ", size=0x%" PRIx64 ": %s",
> +                     __func__, mem.slot, slot->start_addr,
> +                     (uint64_t)mem.memory_size, strerror(errno));
> +    }
>      return ret;
>  }
>  
> 

Queued, thanks.

Paolo



      parent reply	other threads:[~2020-02-21 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-21 16:33 [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value Philippe Mathieu-Daudé
2020-02-21 16:44 ` Peter Xu
2020-02-21 17:03 ` Paolo Bonzini [this message]

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=a6d29e18-722c-77d1-ca56-220b3b02ae00@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=dgilbert@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).