Skip to content

Commit db2eeca

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 03b9684 commit db2eeca

File tree

16 files changed

+285
-13
lines changed

16 files changed

+285
-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 ($(VIRGL_RESOURCE_MAP2),1)
3134
FEATURE_FLAGS += --features virgl_resource_map2
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ arm64_sys_reg!(MPIDR_EL1, 3, 0, 0, 0, 5);
110110
/// * `boot_ip` - Starting instruction pointer.
111111
/// * `mem` - Reserved DRAM for current VM.
112112
pub fn setup_regs(vcpu: &VcpuFd, cpu_id: u8, boot_ip: u64, mem: &GuestMemoryMmap) -> Result<()> {
113+
// PSTATE cannot be accesed from the host in CCA
114+
#[cfg(not(feature = "cca"))]
115+
#[allow(deref_nullptr)]
113116
// Get the register index of the PSTATE (Processor State) register.
114117
vcpu.set_one_reg(arm64_core_reg!(pstate), &PSTATE_FAULT_BITS_64.to_le_bytes())
115118
.map_err(Error::SetCoreRegister)?;

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/aarch64.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/block/device.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use utils::eventfd::{EventFd, EFD_NONBLOCK};
2727
use virtio_bindings::{
2828
virtio_blk::*, virtio_config::VIRTIO_F_VERSION_1, virtio_ring::VIRTIO_RING_F_EVENT_IDX,
2929
};
30+
#[cfg(feature = "cca")]
31+
use virtio_bindings::virtio_config::VIRTIO_F_ACCESS_PLATFORM;
32+
3033
use vm_memory::{ByteValued, GuestMemoryMmap};
3134

3235
use super::worker::BlockWorker;
@@ -240,10 +243,19 @@ impl Block {
240243
let disk_properties =
241244
DiskProperties::new(Arc::clone(&disk_image), disk_image_id.clone(), cache_type)?;
242245

243-
let mut avail_features = (1u64 << VIRTIO_F_VERSION_1)
246+
247+
let mut avail_features = if cfg!(feature = "cca") {
248+
(1u64 << VIRTIO_F_VERSION_1)
244249
| (1u64 << VIRTIO_BLK_F_FLUSH)
245250
| (1u64 << VIRTIO_BLK_F_SEG_MAX)
246-
| (1u64 << VIRTIO_RING_F_EVENT_IDX);
251+
| (1u64 << VIRTIO_RING_F_EVENT_IDX)
252+
| (1 << VIRTIO_F_ACCESS_PLATFORM as u64)
253+
} else {
254+
(1u64 << VIRTIO_F_VERSION_1)
255+
| (1u64 << VIRTIO_BLK_F_FLUSH)
256+
| (1u64 << VIRTIO_BLK_F_SEG_MAX)
257+
| (1u64 << VIRTIO_RING_F_EVENT_IDX)
258+
};
247259

248260
if is_disk_read_only {
249261
avail_features |= 1u64 << VIRTIO_BLK_F_RO;

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use libc::TIOCGWINSZ;
1010
use nix::ioctl_read_bad;
1111
use utils::eventfd::EventFd;
1212
use vm_memory::{ByteValued, Bytes, GuestMemoryMmap};
13+
#[cfg(feature = "cca")]
14+
use virtio_bindings::virtio_config::VIRTIO_F_ACCESS_PLATFORM;
1315

1416
use super::super::{
1517
ActivateError, ActivateResult, ConsoleError, DeviceState, Queue as VirtQueue, VirtioDevice,
@@ -30,9 +32,18 @@ use crate::virtio::{PortDescription, VmmExitObserver};
3032
pub(crate) const CONTROL_RXQ_INDEX: usize = 2;
3133
pub(crate) const CONTROL_TXQ_INDEX: usize = 3;
3234

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

3748
#[repr(C)]
3849
#[derive(Default)]

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 = []
@@ -19,6 +20,7 @@ nitro = [ "dep:nitro", "dep:nitro-enclaves" ]
1920
[dependencies]
2021
crossbeam-channel = ">=0.5.15"
2122
env_logger = "0.11"
23+
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
2224
libc = ">=0.2.39"
2325
libloading = "0.8"
2426
log = "0.4.0"

0 commit comments

Comments
 (0)