mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-06 03:56:34 +00:00
hypervisor: Simplify TDX protection detection
Let's rely on the kvm module 'tdx' parameter to do so. This aligns with both OSVs (Canonical, Red Hat, SUSE) and the TDX adoption (https://github.com/intel/tdx-linux) stacks. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
2ee03b5dc3
commit
cdb8531302
@ -8,39 +8,21 @@ package virtcontainers
|
||||
import "os"
|
||||
|
||||
const (
|
||||
tdxSeamSysFirmwareDir = "/sys/firmware/tdx_seam/"
|
||||
|
||||
tdxSysFirmwareDir = "/sys/firmware/tdx/"
|
||||
tdxKvmParameterPath = "/sys/module/kvm_intel/parameters/tdx"
|
||||
|
||||
sevKvmParameterPath = "/sys/module/kvm_amd/parameters/sev"
|
||||
|
||||
snpKvmParameterPath = "/sys/module/kvm_amd/parameters/sev_snp"
|
||||
)
|
||||
|
||||
// TDX is supported and properly loaded when the firmware directory (either tdx or tdx_seam) exists or `tdx` is part of the CPU flag
|
||||
func checkTdxGuestProtection(flags map[string]bool) bool {
|
||||
if d, err := os.Stat(tdxSysFirmwareDir); err == nil && d.IsDir() {
|
||||
return true
|
||||
}
|
||||
|
||||
if d, err := os.Stat(tdxSeamSysFirmwareDir); err == nil && d.IsDir() {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Implementation of this function is architecture specific
|
||||
func availableGuestProtection() (guestProtection, error) {
|
||||
flags, err := CPUFlags(procCPUInfo)
|
||||
if err != nil {
|
||||
return noneProtection, err
|
||||
// TDX is supported and enabled when the kvm module 'tdx' parameter is set to 'Y'
|
||||
if _, err := os.Stat(tdxKvmParameterPath); err == nil {
|
||||
if c, err := os.ReadFile(tdxKvmParameterPath); err == nil && len(c) > 0 && (c[0] == 'Y') {
|
||||
return tdxProtection, nil
|
||||
}
|
||||
}
|
||||
|
||||
if checkTdxGuestProtection(flags) {
|
||||
return tdxProtection, nil
|
||||
}
|
||||
|
||||
// SEV-SNP is supported and enabled when the kvm module `sev_snp` parameter is set to `Y`
|
||||
// SEV-SNP support infers SEV (-ES) support
|
||||
if _, err := os.Stat(snpKvmParameterPath); err == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user