Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvmtool 0/7] Fix --vcpu-affinity
@ 2026-09-17 15:49 Alexandru Elisei
  2026-09-17 15:49 ` [PATCH kvmtool 1/7] arm64: Pass the number of elements as the first argument to calloc() Alexandru Elisei
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Alexandru Elisei @ 2026-09-17 15:49 UTC (permalink / raw)
  To: will, julien.thierry.kdev, kvm, maz, oupton, fuad.tabba,
	joey.gouly, seiden, suzuki.poulose, yuzenghui, linux-arm-kernel,
	kvmarm

This is my attempt at fixing --vcpu-affinity, which I introduced. Patches #1-#4
are straightforward fixes, and they don't modify the current (broken) behaviour
in any way. Patch #5 fixes is most of the fix: with it, the VCPU threads run on
the physical CPUs passed to --vcpu-affinity, and most of the kvmtool threads,
except the virtio threads, use the main thread affinity.

The virtio threads are special because they are spawned from the VCPU threads,
and they inherit the VCPU thread affinity. Note that there might be other cases
where this happens.

Patches #6-#7 attempt to fix the remaining issue: #6 switch the entire codebase
to kvm_create_thread() instead of pthread_create(). In #7, kvm_create_thread()
will use the main thread affinity when creating new threads. These two patches
are RFC because they cause a lot of churn and I would like some feedback if it's
worth it.

Why is it useful to run the VCPUs on different physical CPUs than the other
threads? I can think of two situations:

1. Testing heterogenous hardware configurations, where the VM creation and setup
happens on a set of physical CPUs, and the VCPUs are run on a different set. I
used these patches for the KVM SPE series.

2. I/O testing. Maybe?

Tested on an Orion board and a x86 machine. On the x86 machine, there's was this
one thread called 'kvm-nx-lpage-re' which had affinity of the VCPUs, but I
couldn't figure out where it was created. I grep'ed for each part of the name in
the source node, no luck. I used strace, and couldn't see a clone call that
returned the corresponding pid. Any clues would be appreciated.

Alexandru Elisei (7):
  arm64: Pass the number of elements as the first argument to calloc()
  arm64: Consistently treat vcpu_affinity_cpuset as dynamically
    allocated
  arm64: Free the temporary cpumask in vcpu_affinity_parser()
  arm64/pmu: Consider kvmtool's affinity when searching for a PMU
  Correctly apply --vcpu-affinity to the VCPU threads
  Introduce kvm_create_thread()
  Don't apply --vcpu-affinity to threads spawned from VCPUs

 arm64/include/kvm/kvm-arch.h        |  2 --
 arm64/include/kvm/kvm-config-arch.h |  5 ----
 arm64/kvm-cpu.c                     |  9 ------
 arm64/kvm.c                         | 31 --------------------
 arm64/pmu.c                         | 31 +++++++++++---------
 builtin-run.c                       | 41 +++++++++++++++++++++++++--
 disk/aio.c                          |  3 +-
 disk/blk.c                          | 12 ++++++--
 disk/core.c                         | 29 ++++++++++---------
 disk/qcow.c                         | 44 ++++++++++++++++++++---------
 disk/raw.c                          | 21 +++++++++++---
 epoll.c                             |  2 +-
 include/kvm/disk-image.h            | 28 ++++++++++++------
 include/kvm/kvm-config.h            |  1 +
 include/kvm/kvm.h                   |  2 ++
 include/kvm/qcow.h                  |  3 +-
 include/kvm/uip.h                   |  2 ++
 include/kvm/util.h                  |  6 ++++
 kvm.c                               | 18 ++++++++++++
 net/uip/tcp.c                       |  7 ++---
 net/uip/udp.c                       |  5 ++--
 term.c                              |  4 +--
 ui/gtk3.c                           |  2 +-
 ui/sdl.c                            |  2 +-
 ui/vnc.c                            |  2 +-
 util/threadpool.c                   |  9 +++---
 util/util.c                         | 42 +++++++++++++++++++++++++++
 virtio/blk.c                        |  2 +-
 virtio/net.c                        | 26 +++++++++++------
 29 files changed, 258 insertions(+), 133 deletions(-)


base-commit: f67bc0bdae9433a9cfd05e65ea2c1bb6102566d9
-- 
2.55.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-09-21  8:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 15:49 [PATCH kvmtool 0/7] Fix --vcpu-affinity Alexandru Elisei
2026-09-17 15:49 ` [PATCH kvmtool 1/7] arm64: Pass the number of elements as the first argument to calloc() Alexandru Elisei
2026-09-17 15:49 ` [PATCH kvmtool 2/7] arm64: Consistently treat vcpu_affinity_cpuset as dynamically allocated Alexandru Elisei
2026-09-17 15:49 ` [PATCH kvmtool 3/7] arm64: Free the temporary cpumask in vcpu_affinity_parser() Alexandru Elisei
2026-09-17 15:49 ` [PATCH kvmtool 4/7] arm64/pmu: Consider kvmtool's affinity when searching for a PMU Alexandru Elisei
2026-09-17 15:49 ` [PATCH kvmtool 5/7] Correctly apply --vcpu-affinity to the VCPU threads Alexandru Elisei
2026-09-17 15:49 ` [RFC PATCH kvmtool 6/7] Introduce kvm_create_thread() Alexandru Elisei
2026-09-17 15:49 ` [RFC PATCH kvmtool 7/7] Don't apply --vcpu-affinity to threads spawned from VCPUs Alexandru Elisei
2026-09-18 12:22 ` [PATCH kvmtool 0/7] Fix --vcpu-affinity Marc Zyngier
2026-09-21  8:59   ` Alexandru Elisei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox