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 <jinankjain@microsoft.com>
This commit is contained in:
Jinank Jain 2024-08-23 22:26:00 +05:30 committed by Wei Liu
parent 8e5c7a37b9
commit bbd72d6453

View File

@ -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),