Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu: Expose SGX EPC resource #1129

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ The following features are available for matching:
| | | **`RDTL3CA_NUM_CLOSID`** | int | The number or available CLOSID (Class of service ID) for Intel L3 Cache Allocation Technology
| **`cpu.security`** | attribute | | | Features related to security and trusted execution environments
| | | **`sgx.enabled`** | bool | `true` if Intel SGX (Software Guard Extensions) has been enabled, otherwise does not exist
| | | **`sgx.epc`** | int | The total amount Intel SGX Encrypted Page Cache memory in bytes. It's only present if `sgx.enabled` is `true`.
| | | **`se.enabled`** | bool | `true` if IBM Secure Execution for Linux is available and has been enabled, otherwise does not exist
| | | **`tdx.enabled`** | bool | `true` if Intel TDX (Trusted Domain Extensions) is available on the host and has been enabled, otherwise does not exist
| | | **`tdx.total_keys`** | int | The total amount of keys an Intel TDX (Trusted Domain Extensions) host can provide. It's only present if `tdx.enabled` is `true`.
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ option of nfd-worker.
| **`cpu-pstate.scaling_governor`** | string | The value of the Intel pstate scaling_governor when in use, either 'powersave' or 'performance'.
| **`cpu-cstate.enabled`** | bool | Set to 'true' if cstates are set in the intel_idle driver, otherwise set to 'false'. Unset if intel_idle cpuidle driver is not active.
| **`cpu-rdt.<rdt-flag>`** | true | **DEPRECATED** [Intel RDT][intel-rdt] capability is supported. See [RDT flags](customization-guide.md#intel-rdt-flags) for details.
| **`cpu-security.sgx.enabled`** | true | Set to 'true' if Intel SGX is enabled in BIOS (based a non-zero sum value of SGX EPC section sizes).
| **`cpu-security.sgx.enabled`** | true | Set to 'true' if Intel SGX is enabled in BIOS (based on a non-zero sum value of SGX EPC section sizes).
| **`cpu-security.se.enabled`** | true | Set to 'true' if IBM Secure Execution for Linux (IBM Z & LinuxONE) is available and enabled (requires `/sys/firmware/uv/prot_virt_host` facility)
| **`cpu-security.tdx.enabled`** | true | Set to 'true' if Intel TDX is available on the host and has been enabled (requires `/sys/module/kvm_intel/parameters/tdx`).
| **`cpu-security.sev.enabled`** | true | Set to 'true' if ADM SEV is available on the host and has been enabled (requires `/sys/module/kvm_intel/parameters/sev`).
Expand Down
2 changes: 1 addition & 1 deletion source/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
// Security
// skipLabel lists features that will not have labels created but are only made available for
// NodeFeatureRules (e.g. to be published via extended resources instead)
skipLabel := sets.NewString("tdx.total_keys")
skipLabel := sets.NewString("tdx.total_keys", "sgx.epc")
for k, v := range features.Attributes[SecurityFeature].Elements {
if !skipLabel.Has(k) {
labels["security."+k] = v
Expand Down
21 changes: 9 additions & 12 deletions source/cpu/security_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ import (
func discoverSecurity() map[string]string {
elems := make(map[string]string)

if sgxEnabled() {
// Set to 'true' based a non-zero sum value of SGX EPC section sizes. The
// kernel checks for IA32_FEATURE_CONTROL.SGX_ENABLE MSR bit but we can't
// do that as a normal user. Typically the BIOS, when enabling SGX,
// allocates "Processor Reserved Memory" for SGX EPC so we rely on > 0
// size here to set "SGX = enabled".
if epcSize := sgxEnabled(); epcSize > 0 {
elems["sgx.enabled"] = "true"
elems["sgx.epc"] = strconv.FormatUint(uint64(epcSize), 10)
}

if tdxEnabled() {
Expand All @@ -62,24 +68,15 @@ func discoverSecurity() map[string]string {
return elems
}

func sgxEnabled() bool {
func sgxEnabled() uint64 {
var epcSize uint64
if cpuid.CPU.SGX.Available {
for _, s := range cpuid.CPU.SGX.EPCSections {
epcSize += s.EPCSize
}
}

// Set to 'true' based a non-zero sum value of SGX EPC section sizes. The
// kernel checks for IA32_FEATURE_CONTROL.SGX_ENABLE MSR bit but we can't
// do that as a normal user. Typically the BIOS, when enabling SGX,
// allocates "Processor Reserved Memory" for SGX EPC so we rely on > 0
// size here to set "SGX = enabled".
if epcSize > 0 {
return true
}

return false
return epcSize
}

func tdxEnabled() bool {
Expand Down