Skip to content

Commit 8b97dc4

Browse files
committed
Support ARM CCA feature
Enable to build confidential guests using ARM CCA (Confidential Computing Architecture). This work relies on v7 series for Linux and v5 series for KVM. This has been tested only on the corresponding FVP model simulator. For testing, you require specific kvm-ioctls and kvm-bindings crates. Signed-off-by: Matias Ezequiel Vara Larsen <[email protected]>
1 parent 8affa13 commit 8b97dc4

File tree

16 files changed

+388
-40
lines changed

16 files changed

+388
-40
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ifeq ($(SEV),1)
2727
INIT_SRC += $(SNP_INIT_SRC)
2828
BUILD_INIT = 0
2929
endif
30+
ifeq ($(CCA), 1)
31+
FEATURE_FLAGS := --features cca
32+
endif
3033
ifeq ($(GPU),1)
3134
FEATURE_FLAGS += --features gpu
3235
endif

src/arch/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ authors = ["The Chromium OS Authors"]
55
edition = "2021"
66

77
[features]
8+
default = ["cca"]
9+
cca = []
810
tee = []
911
amd-sev = [ "tee" ]
1012
efi = []
@@ -18,8 +20,8 @@ smbios = { path = "../smbios" }
1820
utils = { path = "../utils" }
1921

2022
[target.'cfg(target_os = "linux")'.dependencies]
21-
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
22-
kvm-ioctls = ">=0.17"
23+
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" }
24+
kvm-ioctls = { version = ">=0.17", git = "https://github.com/virtee/kvm-ioctls", branch = "cca" }
2325

2426
[target.'cfg(target_arch = "aarch64")'.dependencies]
2527
vm-fdt = ">= 0.2.0"

src/arch/src/aarch64/fdt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ fn create_psci_node(fdt: &mut FdtWriter) -> Result<()> {
285285
// Two methods available: hvc and smc.
286286
// As per documentation, PSCI calls between a guest and hypervisor may use the HVC conduit instead of SMC.
287287
// So, since we are using kvm, we need to use hvc.
288+
#[cfg(not(feature = "cca"))]
288289
fdt.property_string("method", "hvc")?;
290+
#[cfg(feature = "cca")]
291+
fdt.property_string("method", "smc")?;
289292
fdt.end_node(node)?;
290293

291294
Ok(())

src/arch/src/aarch64/linux/regs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ arm64_sys_reg!(MPIDR_EL1, 3, 0, 0, 0, 5);
125125
/// * `boot_ip` - Starting instruction pointer.
126126
/// * `mem` - Reserved DRAM for current VM.
127127
pub fn setup_regs(vcpu: &VcpuFd, cpu_id: u8, boot_ip: u64, mem: &GuestMemoryMmap) -> Result<()> {
128-
// Get the register index of the PSTATE (Processor State) register.
128+
// PSTATE cannot be accesed from the host in CCA
129+
#[cfg(not(feature = "cca"))]
129130
#[allow(deref_nullptr)]
131+
// Get the register index of the PSTATE (Processor State) register.
130132
vcpu.set_one_reg(arm64_core_reg!(pstate), &PSTATE_FAULT_BITS_64.to_le_bytes())
131133
.map_err(Error::SetCoreRegister)?;
132134

src/cpuid/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ edition = "2021"
88
vmm-sys-util = ">=0.11"
99

1010
[target.'cfg(target_os = "linux")'.dependencies]
11-
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
12-
kvm-ioctls = ">=0.17"
11+
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" }
12+
kvm-ioctls = { version = ">=0.17", git = "https://github.com/virtee/kvm-ioctls", branch = "cca" }

src/devices/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ authors = ["The Chromium OS Authors"]
55
edition = "2021"
66

77
[features]
8+
default = ["cca"]
89
tee = []
10+
cca = []
911
amd-sev = ["blk", "tee"]
1012
net = []
1113
blk = []

src/devices/src/virtio/console/device.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ use crate::virtio::{PortDescription, VmmExitObserver};
3030
pub(crate) const CONTROL_RXQ_INDEX: usize = 2;
3131
pub(crate) const CONTROL_TXQ_INDEX: usize = 3;
3232

33-
pub(crate) const AVAIL_FEATURES: u64 = 1 << uapi::VIRTIO_CONSOLE_F_SIZE as u64
34-
| 1 << uapi::VIRTIO_CONSOLE_F_MULTIPORT as u64
35-
| 1 << uapi::VIRTIO_F_VERSION_1 as u64;
33+
// CCA requires VIRTIO_F_ACCESS_PLATFORM to ensure DMA-APIs
34+
// are triggered for virtio in Linux
35+
pub(crate) const AVAIL_FEATURES: u64 = if cfg!(feature = "cca") {
36+
1 << uapi::VIRTIO_CONSOLE_F_SIZE as u64
37+
| 1 << uapi::VIRTIO_CONSOLE_F_MULTIPORT as u64
38+
| 1 << uapi::VIRTIO_F_VERSION_1 as u64
39+
| 1 << uapi::VIRTIO_F_ACCESS_PLATFORM as u64
40+
} else {
41+
1 << uapi::VIRTIO_CONSOLE_F_SIZE as u64
42+
| 1 << uapi::VIRTIO_CONSOLE_F_MULTIPORT as u64
43+
| 1 << uapi::VIRTIO_F_VERSION_1 as u64
44+
};
3645

3746
#[repr(C)]
3847
#[derive(Default)]

src/devices/src/virtio/console/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod defs {
2222
pub const VIRTIO_CONSOLE_F_MULTIPORT: u32 = 1;
2323
pub const VIRTIO_F_VERSION_1: u32 = 32;
2424
pub const VIRTIO_ID_CONSOLE: u32 = 3;
25+
pub const VIRTIO_F_ACCESS_PLATFORM: u32 = 33;
2526
}
2627

2728
#[allow(dead_code)]

src/devices/src/virtio/fs/device.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use std::thread::JoinHandle;
99
#[cfg(target_os = "macos")]
1010
use hvf::MemoryMapping;
1111
use utils::eventfd::{EventFd, EFD_NONBLOCK};
12-
use virtio_bindings::{virtio_config::VIRTIO_F_VERSION_1, virtio_ring::VIRTIO_RING_F_EVENT_IDX};
12+
use virtio_bindings::{
13+
virtio_config::VIRTIO_F_ACCESS_PLATFORM, virtio_config::VIRTIO_F_VERSION_1,
14+
virtio_ring::VIRTIO_RING_F_EVENT_IDX,
15+
};
1316
use vm_memory::{ByteValued, GuestMemoryMmap};
1417

1518
use super::super::{
@@ -70,7 +73,13 @@ impl Fs {
7073
.push(EventFd::new(utils::eventfd::EFD_NONBLOCK).map_err(FsError::EventFd)?);
7174
}
7275

73-
let avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_RING_F_EVENT_IDX);
76+
let avail_features = if cfg!(feature = "cca") {
77+
(1u64 << VIRTIO_F_VERSION_1)
78+
| (1u64 << VIRTIO_RING_F_EVENT_IDX)
79+
| (1 << VIRTIO_F_ACCESS_PLATFORM as u64)
80+
} else {
81+
(1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_RING_F_EVENT_IDX)
82+
};
7483

7584
let tag = fs_id.into_bytes();
7685
let mut config = VirtioFsConfig::default();

src/devices/src/virtio/rng/device.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ use super::super::{
1313
use super::{defs, defs::uapi};
1414
use crate::legacy::GicV3;
1515
use crate::Error as DeviceError;
16+
use virtio_bindings::virtio_config::VIRTIO_F_ACCESS_PLATFORM;
1617

1718
// Request queue.
1819
pub(crate) const REQ_INDEX: usize = 0;
1920

2021
// Supported features.
21-
pub(crate) const AVAIL_FEATURES: u64 = 1 << uapi::VIRTIO_F_VERSION_1 as u64;
22+
pub(crate) const AVAIL_FEATURES: u64 = if cfg!(feature = "cca") {
23+
1 << uapi::VIRTIO_F_VERSION_1 as u64 | 1 << VIRTIO_F_ACCESS_PLATFORM as u64
24+
} else {
25+
1 << uapi::VIRTIO_F_VERSION_1 as u64
26+
};
2227

2328
#[derive(Copy, Clone, Debug, Default)]
2429
#[repr(C, packed)]

0 commit comments

Comments
 (0)