Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vmm: raise the (v)CPU limit on kvm/x86_64 - #7299

Merged
likebreath merged 2 commits into
cloud-hypervisor:mainfrom
posk-io:x2apic-config
Sep 8, 2025
Merged

likebreath merged 2 commits into
cloud-hypervisor:mainfrom
posk-io:x2apic-config

Conversation

@posk-io

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

Copy link
Copy Markdown
Member

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

posk-io commented Aug 26, 2025

Copy link
Copy Markdown
Member Author

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).

@phip1611 phip1611 left a comment

Copy link
Copy Markdown
Member

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.

Comment thread vmm/src/config.rs Outdated
Comment thread vmm/src/config.rs Outdated
Comment thread vmm/src/cpu.rs Outdated
Comment thread vmm/src/cpu.rs Outdated
Comment thread vmm/src/cpu.rs Outdated
Comment thread vmm/src/vm.rs Outdated
Comment thread vmm/src/vm.rs Outdated
Comment thread vmm/src/vm.rs Outdated
@phip1611

phip1611 commented Aug 27, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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

@tpressure

tpressure commented Aug 27, 2025

Copy link
Copy Markdown
Member

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

posk-io commented Aug 27, 2025

Copy link
Copy Markdown
Member Author

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

posk-io commented Aug 27, 2025

Copy link
Copy Markdown
Member Author

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

posk-io commented Aug 28, 2025

Copy link
Copy Markdown
Member Author

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

up2wing commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

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

@likebreath likebreath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Two minor comments.

Comment thread vmm/src/lib.rs Outdated
Comment thread vmm/src/vm.rs Outdated
@likebreath

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

posk-io commented Sep 5, 2025

Copy link
Copy Markdown
Member Author

@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

phip1611 commented Sep 5, 2025

Copy link
Copy Markdown
Member

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

posk-io commented Sep 5, 2025

Copy link
Copy Markdown
Member Author

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
Talador12 added a commit to Talador12/cloud-hypervisor that referenced this pull request Apr 16, 2026
Add test_large_vcpu_count() that validates the 255+ vCPU support added
in cloud-hypervisor#7299. The test:
1. Boots a VM with 256 vCPUs (max=288)
2. Hotplugs to 288 (above 255 boundary)
3. Hotunplugs to 240 (below 255 boundary)
4. Hotplugs back to 260 (crossing 255 again)

Each step verifies the correct CPU count via the guest. x86_64 only
since 255+ vCPU support is x86_64-specific. Requires a host with at
least 288 logical CPUs (bare metal runner).

Closes cloud-hypervisor#7341

Signed-off-by: Keith Adler <[email protected]>
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