From bbd72d6453de159ecf94aa358f83676f1064d751 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 23 Aug 2024 22:26:00 +0530 Subject: [PATCH] vm-virtio: Gain access to virtqueue before accessing them In case of SEV-SNP guests on MSHV, any host component including VMM trying to access any guest memory region, needs to call gain_access API to acquire access to that particular memory region. This applies to all the virtqueue buffers as well which the VMM is using to use to perform DMA into the guest and in order to facilitate device emulation. While creating various virtqueues we are already using access platform hook to translate the addresses but currently we are missing the size arguments which would be required by the SevSnpAccessPlatformProxy to gain access to the memory of these queues. Signed-off-by: Jinank Jain --- .../src/transport/pci_common_config.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/virtio-devices/src/transport/pci_common_config.rs b/virtio-devices/src/transport/pci_common_config.rs index a741f580a..04e89d922 100644 --- a/virtio-devices/src/transport/pci_common_config.rs +++ b/virtio-devices/src/transport/pci_common_config.rs @@ -261,9 +261,21 @@ impl VirtioPciCommonConfig { // Translate address of descriptor table and vrings. if let Some(access_platform) = &self.access_platform { if ready { - let desc_table = access_platform.translate_gva(q.desc_table(), 0).unwrap(); - let avail_ring = access_platform.translate_gva(q.avail_ring(), 0).unwrap(); - let used_ring = access_platform.translate_gva(q.used_ring(), 0).unwrap(); + let desc_table = access_platform + .translate_gva( + q.desc_table(), + get_vring_size(VringType::Desc, q.size()), + ) + .unwrap(); + let avail_ring = access_platform + .translate_gva( + q.avail_ring(), + get_vring_size(VringType::Avail, q.size()), + ) + .unwrap(); + let used_ring = access_platform + .translate_gva(q.used_ring(), get_vring_size(VringType::Used, q.size())) + .unwrap(); q.set_desc_table_address( Some((desc_table & 0xffff_ffff) as u32), Some((desc_table >> 32) as u32),