Skip to content

Conversation

@posk-io
Copy link
Contributor

@posk-io posk-io commented Aug 26, 2025

Raise the max number of supported (v)CPUs on x86_64 kvm hosts to 8192.

Other platfroms (non-x64) keep their existing CPU limits pending further development and testing.

Signed-off-by: Barret Rhoden [email protected]
Signed-off-by: Neel Natu [email protected]
Signed-off-by: Ofir Weisse [email protected]
Signed-off-by: Peter Oskolkov [email protected]

@posk-io posk-io requested a review from a team as a code owner August 26, 2025 18:52
@posk-io
Copy link
Contributor Author

posk-io commented Aug 26, 2025

Note: I have a draft of several new itegration tests here: posk-io@0a250e1, but they fail when run from a VM (i.e. they fail making a nested VM with >= 254 vCPUs). I don't have a spare baremetal host to run the tests at the moment.

Another reason could be that the kernel in the VM image that is used to run the tests has a smaller CONFIG_NR_CPUS. Anyway, manual testing indicates the PR/patch series works on AMD and Intel hosts with up to 1024 vCPUs (the limit that the host KVM imposes in my tests).

Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for working on this! I left a few remarks.

@phip1611
Copy link
Member

phip1611 commented Aug 27, 2025

Follow-up of #7299 (comment): I just noticed that using > 512 vCPUs on my AMD Ryzen 7 7840U w/ Radeon 780M Graphics causes:

Error: Cloud Hypervisor exited with the following chain of errors:
  0: Error booting VM
  1: The VM could not boot
  2: Error from CPU manager
  3: Error creating vCPU
  4: Failed to create Vcpu
  5: Invalid argument (os error 22)

This surprises me. I expected that at least 4096 vCPUs should be supported. Aye, @tpressure?

@tpressure
Copy link
Member

General remark: we should not generate an MPTable if we have more than 255 vCPUs but solely rely on the MADT.

@tpressure
Copy link
Member

I'm also missing the part where you expose KVM_FEATURE_MSI_EXT_DEST_ID . Is this missing on purpose?

@tpressure
Copy link
Member

tpressure commented Aug 27, 2025

Follow-up of #7299 (comment): I just noticed that using > 512 vCPUs on my AMD Ryzen 7 7840U w/ Radeon 780M Graphics causes:

Error: Cloud Hypervisor exited with the following chain of errors:
  0: Error booting VM
  1: The VM could not boot
  2: Error from CPU manager
  3: Error creating vCPU
  4: Failed to create Vcpu
  5: Invalid argument (os error 22)

This surprises me. I expected that at least 4096 vCPUs should be supported. Aye, @tpressure?

On my (Intel) system, it works fine with 768 vCPUs. I will check with my AMD system tomorrow (evening). Did you make sure to increase your ulimit correctly? I'm using ulimit -n 10000.

@posk-io
Copy link
Contributor Author

posk-io commented Aug 27, 2025

I'm also missing the part where you expose KVM_FEATURE_MSI_EXT_DEST_ID . Is this missing on purpose?

This was done in a previous PR:

entry.eax |= 1 << KVM_FEATURE_MSI_EXT_DEST_ID;

@posk-io
Copy link
Contributor Author

posk-io commented Aug 27, 2025

General remark: we should not generate an MPTable if we have more than 255 vCPUs but solely rely on the MADT.

This was done in a previous PR:

if x2apic_id_max >= MAX_SUPPORTED_CPUS_LEGACY {

@posk-io
Copy link
Contributor Author

posk-io commented Aug 28, 2025

Update: I was able to boot VMs with 1024 vCPUs on both Intel and AMD hosts. For some reason max KVM host limit is 1024 on machines I have access to. Does anybody know if this is tunable?

I'll lower the max vCPU limit in the PR to 8192, as this seems to be the Linux kernel's max, and do the cosmetic fixes suggested tomorrow. Will also experiment with the integration test (although it may be flaky, as it is unclear how the kvm host nr_cpu limit is determined).

@posk-io posk-io force-pushed the x2apic-config branch 2 times, most recently from b80ff51 to 28ee5ce Compare August 28, 2025 18:12
@up2wing
Copy link
Contributor

up2wing commented Sep 1, 2025

Update: I was able to boot VMs with 1024 vCPUs on both Intel and AMD hosts. For some reason max KVM host limit is 1024 on machines I have access to. Does anybody know if this is tunable?

I'll lower the max vCPU limit in the PR to 8192, as this seems to be the Linux kernel's max, and do the cosmetic fixes suggested tomorrow. Will also experiment with the integration test (although it may be flaky, as it is unclear how the kvm host nr_cpu limit is determined).

kvm has a KVM_MAX_VCPUS macro which can be defined by CONFIG_KVM_MAX_NR_VCPUS, so the best method I suppose is not setting a max value in cloud hypervisor, instead, it's better to query the value from kvm.

For example, qemu did like this:
https://github.com/qemu/qemu/blob/master/accel/kvm/kvm-all.c#L2692

Copy link
Member

@likebreath likebreath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Two minor comments.

@likebreath
Copy link
Member

Update: I was able to boot VMs with 1024 vCPUs on both Intel and AMD hosts. For some reason max KVM host limit is 1024 on machines I have access to. Does anybody know if this is tunable?
I'll lower the max vCPU limit in the PR to 8192, as this seems to be the Linux kernel's max, and do the cosmetic fixes suggested tomorrow. Will also experiment with the integration test (although it may be flaky, as it is unclear how the kvm host nr_cpu limit is determined).

kvm has a KVM_MAX_VCPUS macro which can be defined by CONFIG_KVM_MAX_NR_VCPUS, so the best method I suppose is not setting a max value in cloud hypervisor, instead, it's better to query the value from kvm.

For example, qemu did like this: https://github.com/qemu/qemu/blob/master/accel/kvm/kvm-all.c#L2692

The current implementation already checks with KVM_MAX_VCPUS - see Error::MaximumVcpusExceeded. We kind of need a constant limit (say MAX_SUPPORTED_CPUS) to clarify the different limits on different architectures.

@likebreath
Copy link
Member

Will also experiment with the integration test (although it may be flaky, as it is unclear how the kvm host nr_cpu limit is determined).

That would be great to have. The challenge is that the most majority of our integration tests run on fairly small Azure VMs (8/16 vCPUs), and I'd assume that won't serve the purpose for launching a VM with 255+ vCPUs on top of it. We do have a couple baremetal x86_64 self-host runners, and we may can experiment with these machines. Not a blocker for landing this PR.

@likebreath
Copy link
Member

@posk-io I see we are very close to conclude on this series with landing this PR (just two small comments above). It would be good to include the increased vCPU limits in our next release (scheduled next Thursday). Thanks.

@posk-io
Copy link
Contributor Author

posk-io commented Sep 5, 2025

@posk-io I see we are very close to conclude on this series with landing this PR (just two small comments above). It would be good to include the increased vCPU limits in our next release (scheduled next Thursday). Thanks.

Ack. Give me a couple of hours (traveling - not in my usual habitat).

@phip1611
Copy link
Member

phip1611 commented Sep 5, 2025

Very nit but please strip the Intel from the PR name, as this works for Intel and AMD. This will help developers in the future to look through old PRs without getting confused

@posk-io posk-io changed the title vmm: raise the (v)CPU limit on kvm/Intel/x86_64 vmm: raise the (v)CPU limit on kvm/x86_64 Sep 5, 2025
@posk-io
Copy link
Contributor Author

posk-io commented Sep 5, 2025

Very nit but please strip the Intel from the PR name, as this works for Intel and AMD. This will help developers in the future to look through old PRs without getting confused

Done.

@posk-io posk-io force-pushed the x2apic-config branch 2 times, most recently from b0a0e0a to cd04317 Compare September 5, 2025 20:45
Raise the max number of supported (v)CPUs on kvm x86_64 hosts
to 8192 (the max allowed value of CONFIG_NR_CPUS in the Linux kernel).

Other platfroms keep their existing CPU limits pending further
development and testing.

The change has been tested on Intel and AMD hosts.

Signed-off-by: Barret Rhoden <[email protected]>
Signed-off-by: Neel Natu <[email protected]>
Signed-off-by: Ofir Weisse <[email protected]>
Signed-off-by: Peter Oskolkov <[email protected]>
@likebreath likebreath added this pull request to the merge queue Sep 8, 2025
@likebreath likebreath moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Sep 8, 2025
Merged via the queue into cloud-hypervisor:main with commit 05d222f Sep 8, 2025
40 checks passed
@posk-io posk-io deleted the x2apic-config branch September 9, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants