All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Mika Tammi <mikatammi@gmail.com>
Cc: Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH kvmtool v2 2/2] Remove kvm_create_vcpu_thread()
Date: Tue, 1 Dec 2026 16:21:53 +0000	[thread overview]
Message-ID: <aw70IRQlbUHWRUFE@raptor> (raw)
In-Reply-To: <20261130220543.70217-2-mikatammi@gmail.com>

Hi Mika,

On Mon, Nov 30, 2026 at 11:05:43PM +0100, Mika Tammi wrote:
> 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 <alexandru.elisei@arm.com>
> Assisted-by: Claude:claude-fable-5-2
> Signed-off-by: Mika Tammi <mikatammi@gmail.com>

Looks correct to me:
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>

Also tested on an arm64 machine with CONFIG_NR_CPUS=16, checked that the VCPU
threads are scheduled on the --vcpu-affinity cpulist:
Tested-by: Alexandru Elisei <alexandru.elisei@arm.com>

> ---
> 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 <signal.h>
>  #include <errno.h>
>  #include <limits.h>
> -#include <pthread.h>
>  #include <sys/param.h>
>  #include <sys/types.h>
>  #include <linux/types.h>
> @@ -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)
> 

  reply	other threads:[~2026-12-01 16:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:05 [PATCH kvmtool v2 1/2] Set the VCPU affinity with sched_setaffinity() (for musl compatibility) Mika Tammi
2026-11-30 22:05 ` [PATCH kvmtool v2 2/2] Remove kvm_create_vcpu_thread() Mika Tammi
2026-12-01 16:21   ` Alexandru Elisei [this message]
2026-12-01 16:21 ` [PATCH kvmtool v2 1/2] Set the VCPU affinity with sched_setaffinity() (for musl compatibility) Alexandru Elisei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw70IRQlbUHWRUFE@raptor \
    --to=alexandru.elisei@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mikatammi@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.