From 3d1c216706c91157b73c4eb6d5be0ae6a450b803 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 21 Oct 2021 00:03:08 +0800 Subject: [PATCH] make interrupt events a try_send type, so they don't cause deadlock this will help mitigate interrupt storms, e.g. if someone tries a ping flood attack. --- services/llio/src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 968a01907..e785d561b 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -1035,10 +1035,28 @@ fn send_event(cb_conns: &[Option; 32], which: usize) { for entry in cb_conns.iter() { if let Some(scb) = entry { // note that the "which" argument is only used for GPIO events, to indicate which pin had the event - xous::send_message(scb.server_to_cb_cid, + match xous::try_send_message(scb.server_to_cb_cid, xous::Message::new_scalar(EventCallback::Event.to_usize().unwrap(), scb.cb_to_client_cid as usize, scb.cb_to_client_id as usize, which, 0) - ).unwrap(); + ) { + Ok(_) => {}, + Err(e) => { + match e { + xous::Error::ServerQueueFull => { + // this triggers if an interrupt storm happens. This could be perfectly natural and/or + // "expected", and the "best" behavior is probably to drop the events, but leave a warning. + // Examples of this would be a ping flood overwhelming the network stack. + log::warn!("Attempted to send event, but destination queue is full. Event was dropped: {:?}", scb); + } + xous::Error::ServerNotFound => { + log::warn!("Event callback subscriber has died. Event was dropped: {:?}", scb); + } + _ => { + log::error!("Callback error {:?}: {:?}", e, scb); + } + } + } + } }; } }