QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Masato Imai <mii@sfc.wide.ad.jp>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"open list:Overall KVM CPUs" <kvm@vger.kernel.org>
Subject: Re: [PATCH v3 1/1] accel/kvm: Fix segmentation fault
Date: Tue, 7 May 2024 09:33:02 +0200	[thread overview]
Message-ID: <ef6df20a-04c9-46bd-95b4-b5bc553364ab@linaro.org> (raw)
In-Reply-To: <20240507025010.1968881-2-mii@sfc.wide.ad.jp>

Hi Masato,

On 7/5/24 04:50, Masato Imai wrote:
> When the KVM acceleration parameter is not set, executing calc_dirty_rate
> with the -r or -b option results in a segmentation fault due to accessing
> a null kvm_state pointer in the kvm_dirty_ring_enabled function. This
> commit adds a null check for kvm_status to prevent segmentation faults.
> 
> Signed-off-by: Masato Imai <mii@sfc.wide.ad.jp>
> ---
>   accel/kvm/kvm-all.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index c0be9f5eed..544293be8a 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2329,7 +2329,7 @@ bool kvm_vcpu_id_is_valid(int vcpu_id)
>   
>   bool kvm_dirty_ring_enabled(void)
>   {
> -    return kvm_state->kvm_dirty_ring_size ? true : false;
> +    return kvm_state && kvm_state->kvm_dirty_ring_size;

I missed the previous iterations of this patch. I disagree
with this approach, we shouldn't call kvm_dirty_ring_enabled()
if kvm_state is NULL, this is a bad API usage. So I'd rather
assert(kvm_state) here and force the callers to check for
kvm_enabled() before calling.

>   }
>   
>   static void query_stats_cb(StatsResultList **result, StatsTarget target,



      parent reply	other threads:[~2024-05-07  7:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  2:50 [PATCH v3 0/1] accel/kvm: Fix segmentation fault Masato Imai
2024-05-07  2:50 ` [PATCH v3 1/1] " Masato Imai
2024-05-07  3:35   ` Zhijian Li (Fujitsu) via
2024-05-07  7:33   ` Philippe Mathieu-Daudé [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=ef6df20a-04c9-46bd-95b4-b5bc553364ab@linaro.org \
    --to=philmd@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=mii@sfc.wide.ad.jp \
    --cc=pbonzini@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 read-only IMAP folder(s) and NNTP newsgroup(s).