* [LTP] [PATCH] tst_virt: Add fallback KVM detection via virtio block devices
@ 2026-05-02 8:14 Darren Chang via ltp
2026-05-06 15:07 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 2+ messages in thread
From: Darren Chang via ltp @ 2026-05-02 8:14 UTC (permalink / raw)
To: ltp
Currently, is_kvm() relies on reading /proc/cpuinfo to find the
"QEMU Virtual CPU" string.
This patch introduces a fallback mechanism to detect KVM environments
by checking for the existence of standard virtio block devices when the
CPU info check fails. Specifically, it probes for:
- /sys/block/vda (Reliable sysfs kernel interface)
- /dev/vda (Standard Linux device node)
- /dev/block/vda (Android's ueventd device node)
Including "/dev/block/vda" ensures that the detection works seamlessly
within Android emulator environments (such as Cuttlefish),
which use ueventd and place block devices under /dev/block/ instead of
the standard Linux /dev/.
Signed-off-by: Darren Chang <chihsheng@google.com>
---
lib/tst_virt.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 109d7a853..ac0aef665 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -44,6 +44,19 @@ static int is_kvm(void)
}
SAFE_FCLOSE(NULL, cpuinfo);
+
+ /* * Fallback check for KVM:
+ * Android's ueventd creates block devices in /dev/block/
+ * instead of the standard Linux /dev/, so we check both.
+ */
+ if (!found) {
+ if (access("/dev/vda", F_OK) == 0 ||
+ access("/sys/block/vda", F_OK) == 0 ||
+ access("/dev/block/vda", F_OK) == 0) {
+ found = 1;
+ }
+ }
+
return found;
}
--
2.54.0.545.g6539524ca2-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] tst_virt: Add fallback KVM detection via virtio block devices
2026-05-02 8:14 [LTP] [PATCH] tst_virt: Add fallback KVM detection via virtio block devices Darren Chang via ltp
@ 2026-05-06 15:07 ` linuxtestproject.agent
0 siblings, 0 replies; 2+ messages in thread
From: linuxtestproject.agent @ 2026-05-06 15:07 UTC (permalink / raw)
To: Darren Chang; +Cc: ltp
Hi Darren,
On 2026-05-02, Darren Chang wrote:
> tst_virt: Add fallback KVM detection via virtio block devices
> + /* * Fallback check for KVM:
> + * Android's ueventd creates block devices in /dev/block/
> + * instead of the standard Linux /dev/, so we check both.
> + */
Malformed comment block. The `/*` opener must be on its own line with no
text. Use:
/*
* Fallback check for KVM:
* ...
*/
> + if (!found) {
> + if (access("/dev/vda", F_OK) == 0 ||
> + access("/sys/block/vda", F_OK) == 0 ||
> + access("/dev/block/vda", F_OK) == 0) {
> + found = 1;
> + }
> + }
Virtio block devices are not KVM-exclusive. Hyper-V and VMware guests with
virtio drivers also expose /dev/vda, so this will produce false positives.
Either narrow the detection (e.g. check /sys/class/dmi/id/product_name for
QEMU/KVM) or explicitly document this as a best-effort heuristic.
---
Note:
Our agent completed the review of the patch. The full review can be
found at: (not available)
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-06 15:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-02 8:14 [LTP] [PATCH] tst_virt: Add fallback KVM detection via virtio block devices Darren Chang via ltp
2026-05-06 15:07 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox