mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: kvmarm@lists.linux.dev
Cc: kvm@vger.kernel.org, maz@kernel.org, will@kernel.org,
	oupton@kernel.org, aneesh.kumar@kernel.org, steven.price@arm.com,
	linux-kernel@vger.kernel.org, alexandru.elisei@arm.com,
	tabba@google.com, Oliver Upton <oliver.upton@linux.dev>,
	Suzuki K Poulose <suzuki.poulose@arm.com>
Subject: [kvmtool PATCH v5 08/15] arm64: Add support for finding vCPU for given MPIDR
Date: Thu,  8 Jan 2026 17:57:46 +0000	[thread overview]
Message-ID: <20260108175753.1292097-9-suzuki.poulose@arm.com> (raw)
In-Reply-To: <20260108175753.1292097-1-suzuki.poulose@arm.com>

From: Oliver Upton <oliver.upton@linux.dev>

Some PSCI calls take an MPIDR affinity as an argument. Add a helper to
get the vCPU that matches an MPIDR so we can find the intended
recipient.

Reviewed-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 arm64/include/kvm/kvm-arch.h |  2 ++
 arm64/kvm.c                  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/arm64/include/kvm/kvm-arch.h b/arm64/include/kvm/kvm-arch.h
index 8f508ef8..a50e6a4f 100644
--- a/arm64/include/kvm/kvm-arch.h
+++ b/arm64/include/kvm/kvm-arch.h
@@ -114,4 +114,6 @@ struct kvm_arch {
 	cpu_set_t *vcpu_affinity_cpuset;
 };
 
+struct kvm_cpu *kvm__arch_mpidr_to_vcpu(struct kvm *kvm, u64 target_mpidr);
+
 #endif /* ARM_COMMON__KVM_ARCH_H */
diff --git a/arm64/kvm.c b/arm64/kvm.c
index 23b4dab1..41c47b13 100644
--- a/arm64/kvm.c
+++ b/arm64/kvm.c
@@ -5,6 +5,7 @@
 #include "kvm/virtio-console.h"
 #include "kvm/fdt.h"
 #include "kvm/gic.h"
+#include "kvm/kvm-cpu.h"
 
 #include <linux/byteorder.h>
 #include <linux/cpumask.h>
@@ -128,6 +129,22 @@ void kvm__arch_init(struct kvm *kvm)
 	kvm__arch_enable_mte(kvm);
 }
 
+
+struct kvm_cpu *kvm__arch_mpidr_to_vcpu(struct kvm *kvm, u64 target_mpidr)
+{
+	int i;
+
+	for (i = 0; i < kvm->nrcpus; i++) {
+		struct kvm_cpu *tmp = kvm->cpus[i];
+		u64 mpidr = kvm_cpu__get_vcpu_mpidr(tmp) & ARM_MPIDR_HWID_BITMASK;
+
+		if (mpidr == target_mpidr)
+			return tmp;
+	}
+
+	return NULL;
+}
+
 static u64 kvm__arch_get_payload_region_size(struct kvm *kvm)
 {
 	if (kvm->cfg.arch.aarch32_guest)
-- 
2.43.0


  parent reply	other threads:[~2026-01-08 17:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 17:57 [kvmtool PATCH v5 00/15] arm64: Handle PSCI calls in userspace Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 01/15] Allow pausing the VM from vcpu thread Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 02/15] update_headers: arm64: Track psci.h for PSCI definitions Suzuki K Poulose
2026-02-09 15:51   ` Will Deacon
2026-02-27 10:23     ` Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 03/15] update headers: Linux v6.18 Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 04/15] Import arm-smccc.h from " Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 05/15] arm64: Stash kvm_vcpu_init for later use Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 06/15] arm64: Use KVM_SET_MP_STATE ioctl to power off non-boot vCPUs Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 07/15] arm64: Expose ARM64_CORE_REG() for general use Suzuki K Poulose
2026-01-08 17:57 ` Suzuki K Poulose [this message]
2026-01-08 17:57 ` [kvmtool PATCH v5 09/15] arm64: Add skeleton implementation for PSCI Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 10/15] arm64: psci: Implement CPU_SUSPEND Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 11/15] arm64: psci: Implement CPU_ON Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 12/15] arm64: psci: Implement AFFINITY_INFO Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 13/15] arm64: psci: Implement MIGRATE_INFO_TYPE Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 14/15] arm64: psci: Implement SYSTEM_{OFF,RESET} Suzuki K Poulose
2026-01-08 17:57 ` [kvmtool PATCH v5 15/15] arm64: smccc: Start sending PSCI to userspace Suzuki K Poulose
2026-02-09 16:25 ` [kvmtool PATCH v5 00/15] arm64: Handle PSCI calls in userspace Will Deacon

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=20260108175753.1292097-9-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=oupton@kernel.org \
    --cc=steven.price@arm.com \
    --cc=tabba@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®