Skip to content

RFC add Valgrind hint in kvm_get_one_reg()

Daniel Henrique Barboza qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest1 patch 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1kvm-all.c: hint Valgrind that kvm_get_one_reg() inits memoryaccel/kvm/kvm-all.c+17 -04 replies

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchDavid Gibson
1/1R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/1] add Valgrind hint in kvm_get_one_reg()

Hi,

Valgrind is not happy with how we're using KVM functions that receives a parameter via reference and write them. This results in a lot of complaints about uninitialized values when using these functions because, as default, Valgrind doesn't know that the variable is being initialized in the function.

This is the overall pattern that Valgrind does not like:

---
uint64_t val;
(...)
kvm_get_one_reg(...., &val);

if (val) {...}
---

Valgrind complains that the 'if' clause is using an uninitialized variable.

A quick fix is to init 'val' and be done with it. The drawback is that every single caller of kvm_get_one_reg() must also be bothered with initializing these variables to avoid the warnings.

David suggested in [1] that, instead, we should add a Valgrind hint in the common KVM functions to fix this issue for everyone. This is what this patch accomplishes. kvm_get_one_reg() has 20+ callers so I believe this extra boilerplate is worth the benefits.

There are more common instances of KVM functions that Valgrind complains about. If we're good with the approach taken here we can think about adding this hint for more functions.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-03/msg07351.html

Daniel Henrique Barboza (1):
kvm-all.c: hint Valgrind that kvm_get_one_reg() inits memory

 accel/kvm/kvm-all.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Signature · 1 line
2.35.1