From e09658afc44014f61f4f8bad06186503d9ab8356 Mon Sep 17 00:00:00 2001 From: ihciah Date: Tue, 6 Aug 2024 16:37:49 +0000 Subject: [PATCH] virtio: skip redundant memory check Remove redundant memory check in descriptor chain creation. Signed-off-by: ihciah --- src/vmm/src/devices/virtio/queue.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vmm/src/devices/virtio/queue.rs b/src/vmm/src/devices/virtio/queue.rs index 92f438486da..0fd6882d201 100644 --- a/src/vmm/src/devices/virtio/queue.rs +++ b/src/vmm/src/devices/virtio/queue.rs @@ -96,6 +96,9 @@ pub struct DescriptorChain<'a, M: GuestMemory = GuestMemoryMmap> { } impl<'a, M: GuestMemory> DescriptorChain<'a, M> { + /// Creates a new `DescriptorChain` from the given memory and descriptor table. + /// + /// Note that the desc_table and queue_size are assumed to be validated by the caller. fn checked_new( mem: &'a M, desc_table: GuestAddress, @@ -106,8 +109,9 @@ impl<'a, M: GuestMemory> DescriptorChain<'a, M> { return None; } - let desc_head = mem.checked_offset(desc_table, (index as usize) * 16)?; - mem.checked_offset(desc_head, 16)?; + // There's no need for checking as we already validated the descriptor table and index + // bounds. + let desc_head = desc_table.unchecked_add(u64::from(index) * 16); // These reads can't fail unless Guest memory is hopelessly broken. let desc = match mem.read_obj::(desc_head) {