Skip to content

Commit 26bc14d

Browse files
committed
test(uffd_utils): add protocol definitions for secret freedom
This is needed because if guest_memfd is used to back guest memory, vCPU fault notifications are delivered via the UFFD UDS socket. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent 00ac2f3 commit 26bc14d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/firecracker/examples/uffd/uffd_utils.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,68 @@ pub struct GuestRegionUffdMapping {
3434
pub offset: u64,
3535
/// The configured page size for this memory region.
3636
pub page_size: usize,
37+
#[deprecated]
38+
pub page_size_kib: usize,
39+
}
40+
41+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
42+
pub struct FaultRequest {
43+
/// vCPU that encountered the fault (not meaningful to Fission)
44+
pub vcpu: u32,
45+
/// Offset in guest_memfd where the fault occured
46+
pub offset: u64,
47+
/// Flags (not meaningful to Fission)
48+
pub flags: u64,
49+
/// Async PF token (not meaningful to Fission)
50+
pub token: Option<u32>,
51+
}
52+
53+
impl FaultRequest {
54+
pub fn into_reply(self, len: u64) -> FaultReply {
55+
FaultReply {
56+
vcpu: Some(self.vcpu),
57+
offset: self.offset,
58+
len,
59+
flags: self.flags,
60+
token: self.token,
61+
zero: false,
62+
}
63+
}
64+
}
65+
66+
/// FaultReply
67+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
68+
pub struct FaultReply {
69+
/// vCPU that encountered the fault, from `FaultRequest` (if present, otherwise 0)
70+
pub vcpu: Option<u32>,
71+
/// Offset in guest_memfd where population started
72+
pub offset: u64,
73+
/// Length of populated area
74+
pub len: u64,
75+
/// Flags, must be copied from `FaultRequest`, otherwise 0
76+
pub flags: u64,
77+
/// Async PF token, must be copied from `FaultRequest`, otherwise None
78+
pub token: Option<u32>,
79+
/// Whether the populated pages are zero pages
80+
pub zero: bool,
81+
}
82+
83+
/// UffdMsgFromFirecracker
84+
#[derive(Serialize, Deserialize, Debug)]
85+
#[serde(untagged)]
86+
pub enum UffdMsgFromFirecracker {
87+
/// Mappings
88+
Mappings(Vec<GuestRegionUffdMapping>),
89+
/// FaultReq
90+
FaultReq(FaultRequest),
91+
}
92+
93+
/// UffdMsgToFirecracker
94+
#[derive(Serialize, Deserialize, Debug)]
95+
#[serde(untagged)]
96+
pub enum UffdMsgToFirecracker {
97+
/// FaultRep
98+
FaultRep(FaultReply),
3799
}
38100

39101
impl GuestRegionUffdMapping {

0 commit comments

Comments
 (0)