From b0338c53297cfbabd727f36c4878379c86cf4ddc Mon Sep 17 00:00:00 2001 From: Brijesh Singh Date: Wed, 23 Aug 2017 06:57:18 -0400 Subject: [PATCH] OvmfPkg/VirtioLib: alloc VRING buffer with AllocateSharedPages() The VRING buffer is a communication area between guest and hypervisor. Allocate it using VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages() so that it can be mapped later with VirtioRingMap() for bi-directional access. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh [lersek@redhat.com: correct typo in VirtioRingInit() comment blocks] Reviewed-by: Laszlo Ersek Regression-tested-by: Laszlo Ersek --- OvmfPkg/Include/Library/VirtioLib.h | 5 ++--- OvmfPkg/Library/VirtioLib/VirtioLib.c | 22 ++++++++++++++-------- OvmfPkg/Library/VirtioLib/VirtioLib.inf | 1 - 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index 6a422deba2..547b4ee497 100644 --- a/OvmfPkg/Include/Library/VirtioLib.h +++ b/OvmfPkg/Include/Library/VirtioLib.h @@ -42,9 +42,8 @@ @param[out] Ring The virtio ring to set up. - @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous - pages for the requested QueueSize. Fields of - Ring have indeterminate value. + @return Status codes propagated from + VirtIo->AllocateSharedPages(). @retval EFI_SUCCESS Allocation and setup successful. Ring->Base (and nothing else) is responsible for diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c index 84acfe6183..40ea17dfaf 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -44,9 +43,8 @@ @param[out] Ring The virtio ring to set up. - @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous - pages for the requested QueueSize. Fields of - Ring have indeterminate value. + @return Status codes propagated from + VirtIo->AllocateSharedPages(). @retval EFI_SUCCESS Allocation and setup successful. Ring->Base (and nothing else) is responsible for @@ -61,6 +59,7 @@ VirtioRingInit ( OUT VRING *Ring ) { + EFI_STATUS Status; UINTN RingSize; volatile UINT8 *RingPagesPtr; @@ -79,10 +78,17 @@ VirtioRingInit ( sizeof *Ring->Used.AvailEvent, EFI_PAGE_SIZE); + // + // Allocate a shared ring buffer + // Ring->NumPages = EFI_SIZE_TO_PAGES (RingSize); - Ring->Base = AllocatePages (Ring->NumPages); - if (Ring->Base == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = VirtIo->AllocateSharedPages ( + VirtIo, + Ring->NumPages, + &Ring->Base + ); + if (EFI_ERROR (Status)) { + return Status; } SetMem (Ring->Base, RingSize, 0x00); RingPagesPtr = Ring->Base; @@ -143,7 +149,7 @@ VirtioRingUninit ( IN OUT VRING *Ring ) { - FreePages (Ring->Base, Ring->NumPages); + VirtIo->FreeSharedPages (VirtIo, Ring->NumPages, Ring->Base); SetMem (Ring, sizeof *Ring, 0x00); } diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.inf b/OvmfPkg/Library/VirtioLib/VirtioLib.inf index fb5897a88e..e33856de38 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.inf +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.inf @@ -32,5 +32,4 @@ BaseLib BaseMemoryLib DebugLib - MemoryAllocationLib UefiBootServicesTableLib