[PATCH 0/2] vhost: set dirty log bits without pinning pages on x86
From: zhaoguohan
Date: Thu Nov 12 2026 - 04:09:29 EST
From: Khan Zhao <zhaoguohan@xxxxxxxxxx>
We use vhost-net with live migration in our product. While dirty
logging is enabled, every used ring update and every logged write goes
through set_bit_to_user(), which pins the log page, maps it, sets a
single bit and unpins it again. The TODO above that function has noted
for a long time that a direct user access would be better.
Patch 1 does that on x86: it tries a byte-sized cmpxchg on the user
address with page faults disabled, and falls back to the existing
pin/kmap path if the access faults or keeps losing to concurrent
updates of the same byte. Other architectures are unchanged, since
unsafe_try_cmpxchg_user() is only implemented on x86.
Patch 2 adds a userspace test in tools/virtio that drives used-ring
logging through vhost_test and checks the bitmap, including fault,
COW, shared-file and concurrent cases, plus a small benchmark mode.
On an x86_64 KVM guest (i7-12800HX host), the benchmark with logging
enabled went from 243.60 to 171.11 ns per descriptor, averaged over
five alternating runs. This is the per-descriptor cost in the vhost
worker; I have not measured the effect on total migration time.
Tool usage: the test, its documentation and the benchmark in patch 2
were largely generated with OpenAI Codex (gpt-6.1-sol) from a request
to exercise vhost used-ring dirty logging, and Codex helped run the
build and VM tests. The changelogs were edited with help from an AI
assistant. I have reviewed all of the code and take responsibility
for it.
Testing: x86_64 with SMAP under QEMU/KVM, running the test from
patch 2 against both the unmodified and patched vhost modules. i386
and arm64 are build-tested only; non-x86 has not been runtime tested.
Khan Zhao (2):
vhost: set dirty log bits without pinning pages on x86
tools/virtio: add a vhost dirty log test
drivers/vhost/vhost.c | 50 +++-
tools/virtio/.gitignore | 1 +
tools/virtio/Makefile | 7 +-
tools/virtio/vhost_log_test.c | 393 ++++++++++++++++++++++++++++++++
tools/virtio/vhost_log_test.rst | 53 +++++
5 files changed, 497 insertions(+), 7 deletions(-)
create mode 100644 tools/virtio/vhost_log_test.c
create mode 100644 tools/virtio/vhost_log_test.rst
base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
--
2.43.0