migration/dirtyrate: Fix segmentation fault
authorMasato Imai <mii@sfc.wide.ad.jp>
Mon, 17 Jun 2024 14:46:04 +0000 (22:46 +0800)
committerHyman Huang <yong.huang@smartx.com>
Mon, 17 Jun 2024 15:29:21 +0000 (23:29 +0800)
Since the kvm_dirty_ring_enabled function accesses a null kvm_state
pointer when the KVM acceleration parameter is not specified, running
calc_dirty_rate with the -r or -b option causes a segmentation fault.

Signed-off-by: Masato Imai <mii@sfc.wide.ad.jp>
Message-ID: <20240507025010.1968881-1-mii@sfc.wide.ad.jp>
[Assert kvm_state when kvm_dirty_ring_enabled was called to fix it. - Hyman]
Signed-off-by: Hyman Huang <yong.huang@smartx.com>
accel/kvm/kvm-all.c

index 009b49de4473efbcc665ded765c0f1ae6107414f..854cb86b2234510011d301d2ad0707dbdb44bbf3 100644 (file)
@@ -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,