From: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Christophe Leroy <chleroy@kernel.org>,
Anushree Mathur <anushree.mathur@linux.ibm.com>,
Venkat Rao Bagalkote <venkat88@linux.ibm.com>,
Harsh Prateek Bora <harshpb@linux.ibm.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Subject: [RFC 3/3] KVM: PPC: Book3S HV nestedv2: cap max vcpus to PAPR limit
Date: Fri, 11 Sep 2026 10:26:47 +0530 [thread overview]
Message-ID: <e2c1ef05eaa19beb28a3db08fb697a80528cd43a.1789099725.git.ritesh.list@gmail.com> (raw)
In-Reply-To: <cover.1789099725.git.ritesh.list@gmail.com>
PAPR spec for H_GUEST_CREATE_VCPU says:
"Only 2048 VCPUs can be created, and the specified ID must be in the range of 0
to 2047"
However, KVM reports KVM_CAP_MAX_VCPUS as NR_CPUS and KVM_CAP_MAX_VCPU_ID as
8 * NR_CPUS. It also passes the userspace vCPU id through to the hcall unchanged.
On a nestedv2 host (KVM on PowerVM / pseries nested PAPR) built with
NR_CPUS > 2048, kvm selftest e.g. kvm_create_max_vcpus will create vCPU
2048 and fail with EINVAL when the hypervisor returns H_P3.
Following error gets reported (with a debug print added to selftest to
print failed vcpu_id number):
./kvm_create_max_vcpus
Random seed: 0x6ec3f539
KVM_CAP_MAX_VCPU_ID: 65536
KVM_CAP_MAX_VCPUS: 8192
Testing creating 8192 vCPUs, with IDs 0...8191.
[ 62.655458][ T302] KVM: Create Guest vcpu hcall failed, rc=-56
[ 62.655458][ T302] KVM: Create Guest vcpu hcall failed, rc=-56
Failed KVM_CREATE_VCPU for vcpu_id 2048 with errno 22
==== Test Assertion Failure ====
lib/kvm_util.c:1395: vcpu->fd >= 0
pid=302 tid=302 errno=22 - Invalid argument
1 0x00000000100061d3: __vm_vcpu_add at kvm_util.c:1395 (discriminator 6)
2 0x0000000010001a6b: test_vcpu_creation at kvm_create_max_vcpus.c:32 (discriminator 3)
3 0x000000001000160b: main at kvm_create_max_vcpus.c:59
4 0x000000001001b713: __libc_start_call_main at libc-start.o:?
5 0x000000001001bb47: __libc_start_main_impl at ??:?
KVM_CREATE_VCPU failed, rc: -1 errno: 22 (Invalid argument)
[ 65.316986][ T302] KVM: TLB LPID invalidation hcall failed, rc=-2
[ 65.316986][ T302] KVM: TLB LPID invalidation hcall failed, rc=-2
Cap both extensions at 2048 when kvmhv_is_nestedv2() is set, so
userspace never requests an id the L0 cannot create. PowerNV and
nestedv1 are unchanged. The issue is only seen with nestedv2.
While at it, this also fixes the limit for KVM_CAP_NR_VCPUS.
Fixes: 19d31c5f1157 ("KVM: PPC: Add support for nestedv2 guests")
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/include/asm/kvm_host.h | 1 +
arch/powerpc/kvm/powerpc.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 2d139c807577..d48232557259 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -37,6 +37,7 @@
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
#include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */
#define KVM_MAX_VCPU_IDS (MAX_SMT_THREADS * KVM_MAX_VCORES)
+#define KVM_MAX_VCPU_IDS_NESTEDv2 2048 /* PAPR H_GUEST_CREATE_VCPU vcpuId */
/*
* Limit the nested partition table to 4096 entries (because that's what
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 9194cf492d1c..cf620b6534de 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -663,12 +663,18 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
r = min(num_present_cpus(), KVM_MAX_VCPUS);
else
r = min(num_online_cpus(), KVM_MAX_VCPUS);
+ if (kvmhv_is_nestedv2())
+ r = min(r, KVM_MAX_VCPU_IDS_NESTEDv2);
break;
case KVM_CAP_MAX_VCPUS:
r = KVM_MAX_VCPUS;
+ if (kvmhv_is_nestedv2())
+ r = min(r, KVM_MAX_VCPU_IDS_NESTEDv2);
break;
case KVM_CAP_MAX_VCPU_ID:
r = KVM_MAX_VCPU_IDS;
+ if (kvmhv_is_nestedv2())
+ r = min(r, KVM_MAX_VCPU_IDS_NESTEDv2);
break;
#ifdef CONFIG_PPC_BOOK3S_64
case KVM_CAP_PPC_GET_SMMU_INFO:
--
2.39.5
prev parent reply other threads:[~2026-09-11 4:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 4:56 [RFC 0/3] KVM: PPC: BE guest-exit fixes and nestedv2 vCPU limit Ritesh Harjani (IBM)
2026-09-11 4:56 ` [RFC 1/3] KVM: PPC: Book3S HV: Read EX_DSISR as a 32-bit field on guest exit Ritesh Harjani (IBM)
2026-09-11 4:56 ` [RFC 2/3] KVM: PPC: Book3S: Don't call __ffs() on an empty pending_exceptions bitmap Ritesh Harjani (IBM)
2026-09-11 4:56 ` Ritesh Harjani (IBM) [this message]
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=e2c1ef05eaa19beb28a3db08fb697a80528cd43a.1789099725.git.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=anushree.mathur@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=harshpb@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=sshegde@linux.ibm.com \
--cc=venkat88@linux.ibm.com \
/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®