-
Notifications
You must be signed in to change notification settings - Fork 145
Panic: division by zero in physicalCores() on Intel VMs with uneven core count #161
Copy link
Copy link
Closed
Description
Environment: Proxmox VM with 5 cores allocated (uneven number) from an 8-core Xeon host.
The Problem: In virtualized environments, especially with uneven core allocation, the CPUID instruction can return inconsistent or zero values that don't match real hardware behavior.
panic: runtime error: integer divide by zero
goroutine 1 [running]:
github.com/klauspost/cpuid/v2.physicalCores()
github.com/klauspost/cpuid/v2@v2.2.10/cpuid.go:881 +0xef
github.com/klauspost/cpuid/v2.addInfo(0x11247c40, 0x42?)
github.com/klauspost/cpuid/v2@v2.2.10/detect_x86.go:33 +0x1e5
github.com/klauspost/cpuid/v2.Detect()
github.com/klauspost/cpuid/v2@v2.2.10/cpuid.go:376 +0x85
github.com/klauspost/cpuid/v2.init.0()
github.com/klauspost/cpuid/v2@v2.2.10/cpuid.go:355 +0x9f
What's happening:
- Proxmox/KVM is virtualizing the CPU topology
- With 5 cores allocated (unusual number), the hypervisor's CPUID emulation returns problematic values
- Either
threadsPerCore()returns 0, orlogicalCores()returns 0 physicalCores()does division without checking for zero
The specific bug location:
Looking at the code in physicalCores():
func physicalCores() int {
v, _ := vendorID()
switch v {
case Intel:
return logicalCores() / threadsPerCore() // ← PANIC HERE
case AMD, Hygon:
lc := logicalCores()
tpc := threadsPerCore()
if lc > 0 && tpc > 0 { // ← AMD has protection
return lc / tpc
}
// ... fallback logic
}
return 0
}Intel path has NO zero-check, while AMD does!
Related issues
resolves #16981
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels