From 444db7e42e5e1eba129e53e38eb2c690dc5f8efb Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Tue, 9 May 2023 14:45:09 +0800 Subject: [PATCH] fix(host): hide kvm only gpu guests (#16974) Signed-off-by: wanyaoqi --- pkg/hostman/guestman/arch/arch.go | 1 + pkg/hostman/guestman/arch/x86.go | 6 +----- pkg/hostman/guestman/qemu-kvmhelper.go | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/hostman/guestman/arch/arch.go b/pkg/hostman/guestman/arch/arch.go index 0c3473f2ef..d2d8cfc325 100644 --- a/pkg/hostman/guestman/arch/arch.go +++ b/pkg/hostman/guestman/arch/arch.go @@ -40,6 +40,7 @@ type KVMGuestInstance interface { CpuMax() (uint, error) IsNestedVirt() bool IsKvmSupport() bool + HideKVM() bool } func NewArch(arch string) Arch { diff --git a/pkg/hostman/guestman/arch/x86.go b/pkg/hostman/guestman/arch/x86.go index fb407f25f9..526fd09e4c 100644 --- a/pkg/hostman/guestman/arch/x86.go +++ b/pkg/hostman/guestman/arch/x86.go @@ -128,11 +128,7 @@ func (*X86) enableHypervFeatures(features map[string]bool) { } func (x86 *X86) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*desc.SGuestCpu, error) { - var hideKVM = true - if s.IsNestedVirt() { - hideKVM = false - } - + var hideKVM = s.HideKVM() var hostCPUPassthrough = options.HostOptions.HostCpuPassthrough var isCPUIntel = sysutils.IsProcessorIntel() var isCPUAMD = sysutils.IsProcessorAmd() diff --git a/pkg/hostman/guestman/qemu-kvmhelper.go b/pkg/hostman/guestman/qemu-kvmhelper.go index ee3eeaac2e..03cef976a0 100644 --- a/pkg/hostman/guestman/qemu-kvmhelper.go +++ b/pkg/hostman/guestman/qemu-kvmhelper.go @@ -130,6 +130,13 @@ func (s *SKVMGuestInstance) GetKernelVersion() string { return s.manager.host.GetKernelVersion() } +func (s *SKVMGuestInstance) HideKVM() bool { + if s.hasGPU() { + return true + } + return false +} + func (s *SKVMGuestInstance) CpuMax() (uint, error) { cpuMax, ok := s.manager.qemuMachineCpuMax[s.Desc.Machine] if !ok { @@ -786,6 +793,17 @@ func (s *SKVMGuestInstance) gpusHasVga() bool { return false } +func (s *SKVMGuestInstance) hasGPU() bool { + manager := s.manager.GetHost().GetIsolatedDeviceManager() + for i := 0; i < len(s.Desc.IsolatedDevices); i++ { + dev := manager.GetDeviceByAddr(s.Desc.IsolatedDevices[i].Addr) + if dev.GetDeviceType() == api.GPU_VGA_TYPE || dev.GetDeviceType() == api.GPU_HPC_TYPE { + return true + } + } + return false +} + func (s *SKVMGuestInstance) initCpuDesc(cpuMax uint) error { var err error s.fixGuestMachineType()