fix: windows GPU vm should set hypervisor=off (#18690)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-11-15 08:56:33 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 004ec64170
commit cd35933ffd
3 changed files with 20 additions and 3 deletions
+1
View File
@@ -41,6 +41,7 @@ type KVMGuestInstance interface {
IsNestedVirt() bool
IsKvmSupport() bool
HideKVM() bool
HideHypervisor() bool
}
func NewArch(arch string) Arch {
+4
View File
@@ -129,6 +129,7 @@ func (*X86) enableHypervFeatures(features map[string]bool) {
func (x86 *X86) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*desc.SGuestCpu, error) {
var hideKVM = s.HideKVM()
var hideHypervisor = s.HideHypervisor()
var hostCPUPassthrough = options.HostOptions.HostCpuPassthrough
var isCPUIntel = sysutils.IsProcessorIntel()
var isCPUAMD = sysutils.IsProcessorAmd()
@@ -174,6 +175,9 @@ func (x86 *X86) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*de
if hideKVM {
features["kvm"] = false
}
if hideHypervisor {
features["hypervisor"] = false
}
} else {
accel = "tcg"
cpuType = "qemu64"
+15 -3
View File
@@ -131,17 +131,29 @@ func (s *SKVMGuestInstance) GetKernelVersion() string {
return s.manager.host.GetKernelVersion()
}
func (s *SKVMGuestInstance) HideKVM() bool {
if s.hasGPU() {
func (s *SKVMGuestInstance) HideHypervisor() bool {
if s.IsRunning() && s.IsMonitorAlive() {
cmdline, _ := fileutils2.FileGetContents(path.Join("/proc", strconv.Itoa(s.GetPid()), "cmdline"))
if strings.Contains(cmdline, "hypervisor=off") {
return true
}
}
if s.hasGPU() && s.GetOsName() == OS_NAME_WINDOWS {
return true
}
return false
}
func (s *SKVMGuestInstance) HideKVM() bool {
if s.IsRunning() && s.IsMonitorAlive() {
cmdline, _ := fileutils2.FileGetContents(path.Join("/proc", strconv.Itoa(s.GetPid()), "cmdline"))
if strings.Contains(cmdline, "kvm=off") {
return true
}
}
if s.hasGPU() && s.GetOsName() != OS_NAME_WINDOWS {
return true
}
return false
}