Skip to content

Commit 6784538

Browse files
committed
Remove external AXI response support from invoke_dpe and certify_key_extended
The mailbox in 2.0 is large enough to support the full response, so external AXI response via DMA is unnecessary complexity.
1 parent 2d84048 commit 6784538

2 files changed

Lines changed: 11 additions & 128 deletions

File tree

runtime/src/certify_key_extended.rs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ use crate::{
1616
invoke_dpe::invoke_dpe_cmd, mutrefbytes, CaliptraDpeProfile, Drivers, PauserPrivileges,
1717
};
1818
use arrayvec::ArrayVec;
19-
use caliptra_api::mailbox::{
20-
populate_checksum, CertifyKeyExtendedMldsa87Req, SUBSYSTEM_MAILBOX_SIZE_LIMIT,
21-
};
19+
use caliptra_api::mailbox::{CertifyKeyExtendedMldsa87Req, SUBSYSTEM_MAILBOX_SIZE_LIMIT};
2220
use caliptra_common::mailbox_api::{
2321
CertifyKeyExtendedEcc384Req, CertifyKeyExtendedFlags, CertifyKeyExtendedResp, MailboxRespHeader,
2422
};
25-
use caliptra_drivers::AxiAddr;
2623
use caliptra_error::{CaliptraError, CaliptraResult};
2724
use dpe::commands::{CertifyKeyMldsa87Cmd, CertifyKeyP384Cmd, Command};
2825
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -54,83 +51,27 @@ impl CertifyKeyExtendedCmd {
5451
) -> CaliptraResult<usize> {
5552
let cmd = CertifyKeyExtendedMldsa87Req::ref_from_bytes(cmd_args)
5653
.map_err(|_| CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?;
57-
// External responses can only be done in subsystem mode
58-
if cmd.flags.external_axi_response() && !drivers.soc_ifc.subsystem_mode() {
59-
return Err(CaliptraError::RUNTIME_MAILBOX_INVALID_PARAMS);
60-
}
6154

6255
// Trim the response buffer to the correct size. If the response doesn't fit, it will fail
6356
// during DPE execution and not at the transport layer. This is especially important for DPE
6457
// handle rotation so the caller doesn't lose the handle.
6558
let mbox_resp = if drivers.soc_ifc.subsystem_mode() {
66-
let len = if cmd.flags.external_axi_response() {
67-
usize::min(mbox_resp.len(), cmd.axi_response.max_size as usize)
68-
} else {
69-
// The mailbox size is smaller when subsystem is enabled
70-
usize::min(mbox_resp.len(), SUBSYSTEM_MAILBOX_SIZE_LIMIT)
71-
};
59+
// The mailbox size is smaller when subsystem is enabled
60+
let len = usize::min(mbox_resp.len(), SUBSYSTEM_MAILBOX_SIZE_LIMIT);
7261
mbox_resp
7362
.get_mut(..len)
7463
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?
7564
} else {
7665
mbox_resp
7766
};
7867

79-
let len = Self::execute(
68+
Self::execute(
8069
drivers,
8170
CaliptraDpeProfile::Mldsa87,
8271
&cmd.flags,
8372
&cmd.certify_key_req,
8473
mbox_resp,
85-
)?;
86-
87-
// We are done if the response is going over the mailbox
88-
let respond_to_mailbox = !cmd.flags.external_axi_response();
89-
if respond_to_mailbox {
90-
return Ok(len);
91-
}
92-
93-
// Populate the checksum so the full response can be checked at the destination
94-
// Make sure there is at least enough space for the response header
95-
let len = usize::max(len, size_of::<MailboxRespHeader>());
96-
populate_checksum(
97-
mbox_resp
98-
.get_mut(..len)
99-
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?,
100-
);
101-
102-
// Get the number of words to send by rounding up to nearest word
103-
let num_words = len.next_multiple_of(4) / 4;
104-
let len = num_words * 4;
105-
if len > cmd.axi_response.max_size as usize {
106-
return Err(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY);
107-
}
108-
109-
// Get the buffer that will be sent over DMA. The DMA only supports sending words so we need
110-
// to convert the response buffer to a &[u32].
111-
let buffer = mbox_resp
112-
.get(..len)
113-
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?;
114-
let buffer: &[u32] =
115-
FromBytes::ref_from_bytes(buffer).map_err(|_| CaliptraError::ADDRESS_MISALIGNED)?;
116-
117-
// Send the response over DMA to the specified AXI address
118-
let axi_addr = AxiAddr {
119-
lo: cmd.axi_response.addr_lo,
120-
hi: cmd.axi_response.addr_hi,
121-
};
122-
for (i, word) in buffer.iter().enumerate() {
123-
drivers.dma.write_dword(
124-
AxiAddr {
125-
lo: axi_addr.lo + (i as u32 * 4),
126-
hi: axi_addr.hi,
127-
},
128-
*word,
129-
);
130-
}
131-
132-
// Response is sent over DMA instead of the mailbox, so return 0 length
133-
Ok(0)
74+
)
13475
}
13576

13677
#[inline(never)]

runtime/src/invoke_dpe.rs

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Abstract:
1212
1313
--*/
1414

15-
use crate::{ec_dpe_env, mldsa_dpe_env, AxiAddr, Drivers, PauserPrivileges};
15+
use crate::{ec_dpe_env, mldsa_dpe_env, Drivers, PauserPrivileges};
1616
use arrayvec::ArrayVec;
1717
use caliptra_api::mailbox::{
18-
populate_checksum, AxiResponseInfo, InvokeDpeMldsa87Flags, InvokeDpeMldsa87Req,
19-
MailboxReqHeader, MailboxRespHeader, SUBSYSTEM_MAILBOX_SIZE_LIMIT,
18+
AxiResponseInfo, InvokeDpeMldsa87Flags, InvokeDpeMldsa87Req, MailboxReqHeader,
19+
MailboxRespHeader, SUBSYSTEM_MAILBOX_SIZE_LIMIT,
2020
};
2121
use caliptra_cfi_derive_git::cfi_impl_fn;
2222
use caliptra_common::mailbox_api::{InvokeDpeReq, InvokeDpeResp};
@@ -95,78 +95,20 @@ impl InvokeDpeCmd {
9595
.get(..cmd.data_size as usize)
9696
.ok_or(CaliptraError::RUNTIME_MAILBOX_INVALID_PARAMS)?;
9797

98-
// External responses can only be done in subsystem mode
99-
if cmd.flags.external_axi_response() && !drivers.soc_ifc.subsystem_mode() {
100-
return Err(CaliptraError::RUNTIME_MAILBOX_INVALID_PARAMS);
101-
}
102-
10398
// Trim the response buffer to the correct size. If the response doesn't fit, it will fail
10499
// during DPE execution and not at the transport layer. This is especially important for DPE
105100
// handle rotation so the caller doesn't lose the handle.
106101
let mbox_resp = if drivers.soc_ifc.subsystem_mode() {
107-
let len = if cmd.flags.external_axi_response() {
108-
usize::min(mbox_resp.len(), cmd.axi_response.max_size as usize)
109-
} else {
110-
// The mailbox size is smaller when subsystem is enabled
111-
usize::min(mbox_resp.len(), SUBSYSTEM_MAILBOX_SIZE_LIMIT)
112-
};
102+
// The mailbox size is smaller when subsystem is enabled
103+
let len = usize::min(mbox_resp.len(), SUBSYSTEM_MAILBOX_SIZE_LIMIT);
113104
mbox_resp
114105
.get_mut(..len)
115106
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?
116107
} else {
117108
mbox_resp
118109
};
119110

120-
// Execute the DPE command and get the length of the response that was written
121-
let len = Self::execute(drivers, dpe_cmd_buf, mbox_resp, CaliptraDpeProfile::Mldsa87)?;
122-
123-
// We are done if the response is going over the mailbox
124-
let respond_to_mailbox = !cmd.flags.external_axi_response();
125-
if respond_to_mailbox {
126-
return Ok(len);
127-
}
128-
129-
// Populate the checksum so the full response can be checked at the destination
130-
// Make sure there is at least enough space for the response header
131-
let len = usize::max(len, size_of::<MailboxRespHeader>());
132-
populate_checksum(
133-
mbox_resp
134-
.get_mut(..len)
135-
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?,
136-
);
137-
138-
// Get the number of words to send by rounding up to nearest word
139-
let num_words = len.next_multiple_of(4) / 4;
140-
let len = num_words * 4;
141-
if len > cmd.axi_response.max_size as usize {
142-
return Err(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY);
143-
}
144-
145-
// Get the buffer that will be sent over DMA. The DMA only supports sending words so we need
146-
// to convert the response buffer to a &[u32].
147-
let buffer = mbox_resp
148-
.get(..len)
149-
.ok_or(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY)?;
150-
let buffer: &[u32] =
151-
FromBytes::ref_from_bytes(buffer).map_err(|_| CaliptraError::ADDRESS_MISALIGNED)?;
152-
153-
// Send the response over DMA to the specified AXI address
154-
let axi_addr = AxiAddr {
155-
lo: cmd.axi_response.addr_lo,
156-
hi: cmd.axi_response.addr_hi,
157-
};
158-
for (i, word) in buffer.iter().enumerate() {
159-
drivers.dma.write_dword(
160-
AxiAddr {
161-
lo: axi_addr.lo + (i as u32 * 4),
162-
hi: axi_addr.hi,
163-
},
164-
*word,
165-
);
166-
}
167-
168-
// Response is sent over DMA instead of the mailbox, so return 0 length
169-
Ok(0)
111+
Self::execute(drivers, dpe_cmd_buf, mbox_resp, CaliptraDpeProfile::Mldsa87)
170112
}
171113

172114
#[cfg_attr(not(feature = "no-cfi"), cfi_impl_fn)]

0 commit comments

Comments
 (0)