From 0019eecadde1b6e0a1fd51eeb0da86576e496dab Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:39:23 +0100 Subject: [PATCH] virtio-gpud: Don't process flush requests for background VT's This ensures that the foreground VT doesn't lockup if a background VT spams us with flush requests. In the future we may want to add a scheduler or collapse redundant flush requests. --- graphics/virtio-gpud/src/scheme.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/graphics/virtio-gpud/src/scheme.rs b/graphics/virtio-gpud/src/scheme.rs index a874d782cd..c7b3bed07a 100644 --- a/graphics/virtio-gpud/src/scheme.rs +++ b/graphics/virtio-gpud/src/scheme.rs @@ -370,6 +370,11 @@ impl<'a> SchemeMut for Scheme<'a> { fn fsync(&mut self, id: usize) -> syscall::Result { let handle = self.handles.get(&id).ok_or(SysError::new(EINVAL))?; + if handle.vt != *handle.display.active_vt.borrow() { + // This is a protection against background VT's spamming us with flush requests. We will + // flush the resource on the next scanout anyway + return Ok(0); + } futures::executor::block_on(handle.display.flush(handle.vt, None)).unwrap(); Ok(0) } @@ -395,6 +400,12 @@ impl<'a> SchemeMut for Scheme<'a> { ) -> syscall::Result { let handle = self.handles.get(&id).ok_or(SysError::new(EINVAL))?; + if handle.vt != *handle.display.active_vt.borrow() { + // This is a protection against background VT's spamming us with flush requests. We will + // flush the resource on the next scanout anyway + return Ok(buf.len()); + } + let damage = unsafe { core::slice::from_raw_parts( buf.as_ptr() as *const Damage,