diff --git a/bootstrap/src/initnsmgr.rs b/bootstrap/src/initnsmgr.rs index 4e58092d9c..406cace436 100644 --- a/bootstrap/src/initnsmgr.rs +++ b/bootstrap/src/initnsmgr.rs @@ -173,13 +173,13 @@ impl<'sock> NamespaceScheme<'sock> { return Err(Error::new(ENODEV)); }; - let scheme_fd = syscall::openat_with_filter( + let reserved = syscall::reserve_fd(1)?; + let scheme_fd = syscall::openat_into( cap_fd.as_raw_fd(), + reserved, reference, flags, fcntl_flags as usize, - ctx.uid, - ctx.gid, )?; Ok(scheme_fd) @@ -353,7 +353,7 @@ impl<'sock> SchemeSync for NamespaceScheme<'sock> { return Err(Error::new(ENODEV)); }; - syscall::unlinkat_with_filter(cap_fd.as_raw_fd(), reference, flags, ctx.uid, ctx.gid)?; + syscall::unlinkat(cap_fd.as_raw_fd(), reference, flags)?; Ok(()) } diff --git a/drivers/usb/xhcid/src/xhci/mod.rs b/drivers/usb/xhcid/src/xhci/mod.rs index aaf0bb31d6..83e5106898 100644 --- a/drivers/usb/xhcid/src/xhci/mod.rs +++ b/drivers/usb/xhcid/src/xhci/mod.rs @@ -305,9 +305,10 @@ pub struct Xhci { device_enumerator: Mutex>>, device_enumerator_sender: Sender, device_enumerator_receiver: Receiver, + + dma_pool: Mutex>>, } -} // SAFETY: Xhci contains the following fields with their safety mechanisms: // - `port_states`, `handles`, `drivers`: CHashMap (per-key interior locking) // - `op`, `ports`, `cmd`, `run`, `primary_event_ring`: Mutex<...> @@ -501,6 +502,7 @@ impl Xhci { device_enumerator: Mutex::new(None), device_enumerator_sender, device_enumerator_receiver, + dma_pool: Mutex::new(Vec::new()), }; xhci.init(max_slots)?; @@ -1074,6 +1076,16 @@ impl Xhci { Self::alloc_dma_zeroed_unsized_raw(self.ac64_effective(), count) } + fn dma_pool_take(&self, size: usize) -> Option> { + let mut pool = self.dma_pool.lock().unwrap_or_else(|e| e.into_inner()); + pool.iter().position(|b| b.len() >= size).map(|i| pool.swap_remove(i)) + } + fn dma_pool_put(&self, buf: Dma<[u8]>) { + const MAX_POOL: usize = 32; + let mut pool = self.dma_pool.lock().unwrap_or_else(|e| e.into_inner()); + if pool.len() < MAX_POOL { pool.push(buf); } + } + pub async fn attach_device(&self, port_id: PortId) -> syscall::Result<()> { if self.port_states.contains_key(&port_id) { debug!("Already contains port {}", port_id); diff --git a/drivers/usb/xhcid/src/xhci/scheme.rs b/drivers/usb/xhcid/src/xhci/scheme.rs index e51ba78cb7..cb2bb64e30 100644 --- a/drivers/usb/xhcid/src/xhci/scheme.rs +++ b/drivers/usb/xhcid/src/xhci/scheme.rs @@ -2080,8 +2080,9 @@ impl Xhci { // TODO: Validate the size. // TODO: Sizes above 65536, *perhaps*. let data_buffer_opt = if req.transfers_data { - let data_buffer = unsafe { self.alloc_dma_zeroed_unsized(req.length as usize)? }; - assert_eq!(data_buffer.len(), req.length as usize); + let data_buffer = self.dma_pool_take(req.length as usize).unwrap_or_else(|| unsafe { + self.alloc_dma_zeroed_unsized(req.length as usize).expect("DMA alloc") + }); Some(data_buffer) } else { None