From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
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>,
Ackerley Tng <ackerleytng@google.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [PATCH v3 RESEND 04/10] KVM: PPC: selftests: powerpc enable kvm_create_max_vcpus test
Date: Fri, 12 Jun 2026 20:44:17 +0530 [thread overview]
Message-ID: <fr2reqpi.ritesh.list@gmail.com> (raw)
In-Reply-To: <aiwd_8Jj34IH-pFH@google.com>
Sean Christopherson <seanjc@google.com> writes:
> On Fri, Jun 12, 2026, Ritesh Harjani wrote:
>> Sean Christopherson <seanjc@google.com> writes:
>>
>> > On Wed, Jun 10, 2026, Ritesh Harjani (IBM) wrote:
>> >> From: Nicholas Piggin <npiggin@gmail.com>
>> >>
>> >> powerpc's maximum permitted vCPU ID depends on the VM's SMT mode, and
>> >> the maximum reported by KVM_CAP_MAX_VCPU_ID exceeds a simple non-SMT
>> >> VM's limit.
>> >>
>> >> The powerpc KVM selftest port uses non-SMT VMs, so add a workaround
>> >> to the kvm_create_max_vcpus test case to limit vCPU IDs to
>> >> KVM_CAP_MAX_VCPUS on powerpc.
>> >
>> > How is this not a KVM bug? Literally the reason this test exists is to validate
>> > KVM's advertised KVM_CAP_MAX_VCPU_ID and KVM_CAP_MAX_VCPUS.
>>
>> It's not a KVM bug, it's expected on PowerPC. On PowerPC, vCPU ID encodes SMT topology, e.g. on P9,
>> vcpu id = core * stride + thread,
>> .. where the stride is same as kvm->arch.emul_smt_mode (VM's emulated SMT mode)
>>
>> So the vcpu ID space can be sparse, however KVM_CAP_MAX_VCPU_ID is the
>> absolute ceil value (MAX_SMT_THREADS * KVM_MAX_VCORES) i.e. the value
>> with the maximum stride / SMT value.
>>
>> Since default selftest VM uses stride 1, so it rejects IDS >= max_vcpus.
>>
>> e.g.
>> static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
>> ...
>> if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) {
>> pr_devel("KVM: VCPU ID too high\n");
>> core = KVM_MAX_VCORES; /* rejected case */
>> } else {
>>
>> So, it's expected on PowerPC. vcpus with higher IDs can be created but
>> for that we need to set KVM_CAP_PPC_SMT and use strided (sparse) IDs.
>> But since the test as of now is not doing that - that's the reason why
>> the patch only allows to test max vcpu IDs upto max vcpus.
>>
>> But I guess you must be hating the #ifdef __powerpc__ there. I agree I
>> don't like it either.. maybe we can do it this way?
>
> I don't love the #ifdef, but it's more that I didn't want to effectively skip a
> test because KVM was reporting bad information. But after peeking at KVM_CAP_PPC_SMT,
> I 100% agree we don't want to deal with that here.
>
>> -#ifdef __powerpc64__
>> /*
>> - * powerpc has a particular format for the vcpu ID that depends on
>> - * the guest SMT mode, and the max ID cap is too large for non-SMT
>> - * modes, where the maximum ID is the same as the maximum vCPUs.
>> + * Some architectures (e.g. powerpc) encode topology into the vCPU ID,
>> + * so a default VM can't necessarily use the full advertised ID range.
>> + * Let the arch limit the highest ID this test will create.
>> */
>> - kvm_max_vcpu_id = kvm_max_vcpus;
>> -#endif
>> + kvm_max_vcpu_id = kvm_arch_vcpu_id_limit(kvm_max_vcpus, kvm_max_vcpu_id);
>>
>>
>> And then in kvm_util.c -
>> +
>> +__weak int kvm_arch_vcpu_id_limit(int nr_vcpus, int vcpu_id_max)
>> +{
>> + return vcpu_id_max;
>> +}
>
> What if we do this? We're going to be bleeding PPC details into the test no
> matter what, adding an arch hooks just seems like extra cruft and an unnecessary
> layer of indirection.
>
> /*
> * Skip the vCPU ID test when running on PowerPC with SMT support, in
> * which case system topology is encoded into the vCPU ID, and so a VM
> * can't use the full advertised vCPU ID range without crafting a valid
> * platform specific topology.
> */
> if (kvm_max_vcpu_id > kvm_max_vcpus && !kvm_check_cap(KVM_CAP_PPC_SMT))
> test_vcpu_creation(
> kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus);
Thanks! That should do and I think that's the most cleaner version.
I will change patch-4 with your suggested changes then.
-ritesh
next prev parent reply other threads:[~2026-06-12 15:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 12:47 [PATCH v3 RESEND 00/10] KVM: selftests: add powerpc support Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 01/10] KVM: selftests: Move pgd_created check into virt_pgd_alloc Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 02/10] KVM: selftests: Add aligned guest physical page allocator Ritesh Harjani (IBM)
2026-06-10 16:18 ` Sean Christopherson
2026-06-11 16:30 ` Ritesh Harjani
2026-06-11 17:54 ` Sean Christopherson
2026-06-12 14:36 ` Ritesh Harjani
2026-06-10 12:47 ` [PATCH v3 RESEND 03/10] KVM: PPC: selftests: add support for powerpc Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 04/10] KVM: PPC: selftests: powerpc enable kvm_create_max_vcpus test Ritesh Harjani (IBM)
2026-06-10 17:59 ` Sean Christopherson
2026-06-12 12:49 ` Ritesh Harjani
2026-06-12 14:55 ` Sean Christopherson
2026-06-12 15:14 ` Ritesh Harjani [this message]
2026-06-10 12:47 ` [PATCH v3 RESEND 05/10] KVM: selftests: Print the vcpu_id when KVM_CREATE_VCPU ioctl fails Ritesh Harjani (IBM)
2026-06-10 12:59 ` Sean Christopherson
2026-06-10 12:47 ` [PATCH v3 RESEND 06/10] KVM: PPC: selftests: Use u64 instead of uint64_t Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 07/10] KVM: PPC: selftests: Use s64 instead of int64_t Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 08/10] KVM: PPC: selftests: Use u32 instead of uint32_t Ritesh Harjani (IBM)
2026-06-10 12:47 ` [PATCH v3 RESEND 09/10] KVM: PPC: selftests: Use u8 instead of uint8_t Ritesh Harjani (IBM)
2026-06-10 12:54 ` sashiko-bot
2026-06-10 12:47 ` [PATCH v3 RESEND 10/10] KVM: PPC: selftests: Replace u64 gpa, u64 gva|vaddr with gpa_t and gva_t Ritesh Harjani (IBM)
2026-06-10 12:51 ` [PATCH v3 RESEND 00/10] KVM: selftests: add powerpc support Sean Christopherson
2026-06-10 12:53 ` Ritesh Harjani
2026-06-10 16:19 ` Sean Christopherson
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=fr2reqpi.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=ackerleytng@google.com \
--cc=anushree.mathur@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=harshpb@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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