The VCPU threads now set their own affinity, so kvm_create_vcpu_thread() only wraps pthread_create(). Remove it, and have kvm_cmd_run_work() call pthread_create() itself, as it did before commit 4c90ccf4c593 ("Correctly apply --vcpu-affinity to the VCPU threads"). pthread_create() doesn't set errno, so a failure is reported with die() again, instead of die_perror(). Suggested-by: Alexandru Elisei Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Mika Tammi --- New in v2. With both patches, lkvm builds for the same targets as with patch 1 alone, and boots guests the same way: on x86_64 and arm64 with and without --vcpu-affinity, with glibc and musl, and on the QEMU rv32 and rv64 KVM hosts with --vcpu-affinity 0. builtin-run.c | 4 ++-- include/kvm/util.h | 4 ---- util/util.c | 12 ------------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/builtin-run.c b/builtin-run.c index ac779a4..264bf8f 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -876,8 +876,8 @@ static int kvm_cmd_run_work(struct kvm *kvm) int i; for (i = 0; i < kvm->nrcpus; i++) { - if (kvm_create_vcpu_thread(kvm, &kvm->cpus[i]->thread, kvm_cpu_thread, kvm->cpus[i])) - die_perror("unable to create KVM VCPU thread"); + if (pthread_create(&kvm->cpus[i]->thread, NULL, kvm_cpu_thread, kvm->cpus[i]) != 0) + die("unable to create KVM VCPU thread"); } /* Only VCPU #0 is going to exit by itself when shutting down */ diff --git a/include/kvm/util.h b/include/kvm/util.h index dc09720..b767b77 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -151,9 +150,6 @@ void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size); void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size); void *mmap_guest_memfd(struct kvm *kvm, u64 size); -int kvm_create_vcpu_thread(struct kvm *kvm, pthread_t *thread, - void *(*start_routine)(void *), void *arg); - unsigned long host_page_size(void); #ifndef PAGE_SIZE diff --git a/util/util.c b/util/util.c index 59855d6..9baef5d 100644 --- a/util/util.c +++ b/util/util.c @@ -207,18 +207,6 @@ void *mmap_guest_memfd(struct kvm *kvm, u64 size) return addr; } -int kvm_create_vcpu_thread(struct kvm *kvm, pthread_t *thread, - void *(*start_routine)(void *), void *arg) -{ - int ret; - - ret = pthread_create(thread, NULL, start_routine, arg); - if (ret) - errno = ret; - - return -ret; -} - unsigned long host_page_size(void) { static long page_size; -- 2.54.0 (Apple Git-157)