@@ -15,6 +15,7 @@ limitations under the License.
1515*/
1616
1717use std:: cmp:: max;
18+ use std:: time:: Duration ;
1819
1920use tracing:: { instrument, Span } ;
2021
@@ -55,6 +56,13 @@ pub struct SandboxConfiguration {
5556 /// field should be represented as an `Option`, that type is not
5657 /// FFI-safe, so it cannot be.
5758 heap_size_override : u64 ,
59+ /// Delay between interrupt retries. This duration specifies how long to wait
60+ /// between attempts to send signals to the thread running the sandbox's VCPU.
61+ /// Multiple retries may be necessary because signals only interrupt the VCPU
62+ /// thread when the vcpu thread is in kernel space. There's a narrow window during which a
63+ /// signal can be delivered to the thread, but the thread may not yet
64+ /// have entered kernel space.
65+ interrupt_retry_delay : Duration ,
5866}
5967
6068impl SandboxConfiguration {
@@ -66,6 +74,8 @@ impl SandboxConfiguration {
6674 pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
6775 /// The minimum size of output data
6876 pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
77+ /// The default interrupt retry delay
78+ pub const DEFAULT_INTERRUPT_RETRY_DELAY : Duration = Duration :: from_micros ( 500 ) ;
6979
7080 #[ allow( clippy:: too_many_arguments) ]
7181 /// Create a new configuration for a sandbox with the given sizes.
@@ -75,13 +85,15 @@ impl SandboxConfiguration {
7585 output_data_size : usize ,
7686 stack_size_override : Option < u64 > ,
7787 heap_size_override : Option < u64 > ,
88+ interrupt_retry_delay : Duration ,
7889 #[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
7990 ) -> Self {
8091 Self {
8192 input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
8293 output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
8394 stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
8495 heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
96+ interrupt_retry_delay,
8597
8698 #[ cfg( gdb) ]
8799 guest_debug_info,
@@ -114,6 +126,16 @@ impl SandboxConfiguration {
114126 self . heap_size_override = heap_size;
115127 }
116128
129+ /// Sets the interrupt retry delay
130+ pub fn set_interrupt_retry_delay ( & mut self , delay : Duration ) {
131+ self . interrupt_retry_delay = delay;
132+ }
133+
134+ /// Get the delay between retries for interrupts
135+ pub fn get_interrupt_retry_delay ( & self ) -> Duration {
136+ self . interrupt_retry_delay
137+ }
138+
117139 /// Sets the configuration for the guest debug
118140 #[ cfg( gdb) ]
119141 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -172,6 +194,7 @@ impl Default for SandboxConfiguration {
172194 Self :: DEFAULT_OUTPUT_SIZE ,
173195 None ,
174196 None ,
197+ Self :: DEFAULT_INTERRUPT_RETRY_DELAY ,
175198 #[ cfg( gdb) ]
176199 None ,
177200 )
@@ -194,6 +217,7 @@ mod tests {
194217 OUTPUT_DATA_SIZE_OVERRIDE ,
195218 Some ( STACK_SIZE_OVERRIDE ) ,
196219 Some ( HEAP_SIZE_OVERRIDE ) ,
220+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
197221 #[ cfg( gdb) ]
198222 None ,
199223 ) ;
@@ -219,6 +243,7 @@ mod tests {
219243 SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
220244 None ,
221245 None ,
246+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
222247 #[ cfg( gdb) ]
223248 None ,
224249 ) ;
0 commit comments