* [PATCH v3 0/1] accel/kvm: Fix segmentation fault
@ 2024-05-07 2:50 Masato Imai
2024-05-07 2:50 ` [PATCH v3 1/1] " Masato Imai
0 siblings, 1 reply; 5+ messages in thread
From: Masato Imai @ 2024-05-07 2:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Masato Imai
Changes from v2:
- avoid segfault in kvm/accel instead of migration/dirtyrate
v2: https://lore.kernel.org/qemu-devel/20240423091306.754432-1-mii@sfc.wide.ad.jp
Masato Imai (1):
accel/kvm: Fix segmentation fault
accel/kvm/kvm-all.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/1] accel/kvm: Fix segmentation fault
2024-05-07 2:50 [PATCH v3 0/1] accel/kvm: Fix segmentation fault Masato Imai
@ 2024-05-07 2:50 ` Masato Imai
2024-05-07 3:35 ` Zhijian Li (Fujitsu) via
2024-05-07 7:33 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 5+ messages in thread
From: Masato Imai @ 2024-05-07 2:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Masato Imai, Paolo Bonzini, open list:Overall KVM CPUs
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;
}
static void query_stats_cb(StatsResultList **result, StatsTarget target,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] accel/kvm: Fix segmentation fault
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é
1 sibling, 0 replies; 5+ messages in thread
From: Zhijian Li (Fujitsu) @ 2024-05-07 3:35 UTC (permalink / raw)
To: Masato Imai, qemu-devel; +Cc: Paolo Bonzini, open list:Overall KVM CPUs
on 5/7/2024 10:50 AM, 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>
LGTM,
Tested-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> 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;
> }
>
> static void query_stats_cb(StatsResultList **result, StatsTarget target,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] accel/kvm: Fix segmentation fault
@ 2024-05-07 3:35 ` Zhijian Li (Fujitsu) via
0 siblings, 0 replies; 5+ messages in thread
From: Zhijian Li (Fujitsu) via @ 2024-05-07 3:35 UTC (permalink / raw)
To: Masato Imai, qemu-devel; +Cc: Paolo Bonzini, open list:Overall KVM CPUs
on 5/7/2024 10:50 AM, 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>
LGTM,
Tested-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> 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;
> }
>
> static void query_stats_cb(StatsResultList **result, StatsTarget target,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] accel/kvm: Fix segmentation fault
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é
1 sibling, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-05-07 7:33 UTC (permalink / raw)
To: Masato Imai, qemu-devel; +Cc: Paolo Bonzini, open list:Overall KVM CPUs
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,
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-07 7:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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)
2024-05-07 3:35 ` Zhijian Li (Fujitsu) via
2024-05-07 7:33 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.