Skip to content

Commit 8715c21

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 v8 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 e9598b6 commit 8715c21

File tree

16 files changed

+274
-13
lines changed

16 files changed

+274
-13
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["The Chromium OS Authors"]
55
edition = "2021"
66

77
[features]
8+
cca = [ "tee" ]
89
tee = []
910
amd-sev = [ "tee" ]
1011
efi = []

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/devices/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66

77
[features]
88
tee = []
9+
cca = [ "tee" ]
910
amd-sev = ["blk", "tee"]
1011
net = []
1112
blk = []

src/devices/src/fdt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,12 @@ fn create_psci_node(fdt: &mut FdtWriter) -> Result<()> {
286286
// Two methods available: hvc and smc.
287287
// As per documentation, PSCI calls between a guest and hypervisor may use the HVC conduit instead of SMC.
288288
// So, since we are using kvm, we need to use hvc.
289-
#[cfg(target_os = "linux")]
289+
#[cfg(all(target_os = "linux", not(feature = "cca")))]
290290
fdt.property_string("method", "hvc")?;
291291
#[cfg(target_os = "macos")]
292292
fdt.property_string("method", "smc")?;
293+
#[cfg(feature = "cca")]
294+
fdt.property_string("method", "smc")?;
293295
fdt.end_node(node)?;
294296

295297
Ok(())

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
use utils::eventfd::{EventFd, EFD_NONBLOCK};
1010
#[cfg(target_os = "macos")]
1111
use utils::worker_message::WorkerMessage;
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::{
@@ -72,7 +75,13 @@ impl Fs {
7275
.push(EventFd::new(utils::eventfd::EFD_NONBLOCK).map_err(FsError::EventFd)?);
7376
}
7477

75-
let avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_RING_F_EVENT_IDX);
78+
let avail_features = if cfg!(feature = "cca") {
79+
(1u64 << VIRTIO_F_VERSION_1)
80+
| (1u64 << VIRTIO_RING_F_EVENT_IDX)
81+
| (1 << VIRTIO_F_ACCESS_PLATFORM as u64)
82+
} else {
83+
(1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_RING_F_EVENT_IDX)
84+
};
7685

7786
let tag = fs_id.into_bytes();
7887
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::IrqChip;
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)]

src/libkrun/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build = "build.rs"
77

88
[features]
99
tee = []
10+
cca = [ "tee" ]
1011
amd-sev = [ "blk", "tee" ]
1112
net = []
1213
blk = []
@@ -16,6 +17,7 @@ snd = []
1617
virgl_resource_map2 = []
1718

1819
[dependencies]
20+
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
1921
crossbeam-channel = "0.5"
2022
env_logger = "0.9.0"
2123
libc = ">=0.2.39"

0 commit comments

Comments
 (0)