The vring buffer is communication block between guest and hypervisor,
allocate the vring buffer using AllocateSharedPages() so that it can be
Map() with BusMasterCommonBufer for bi-directional access.

Cc: Ard Biesheuvel <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Tom Lendacky <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <[email protected]>
---
 OvmfPkg/Library/VirtioLib/VirtioLib.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c 
b/OvmfPkg/Library/VirtioLib/VirtioLib.c
index 09a3f9b7f2e5..9ba64204326f 100644
--- a/OvmfPkg/Library/VirtioLib/VirtioLib.c
+++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c
@@ -61,6 +61,7 @@ VirtioRingInit (
   OUT VRING                  *Ring
   )
 {
+  EFI_STATUS     Status;
   UINTN          RingSize;
   volatile UINT8 *RingPagesPtr;
 
@@ -79,9 +80,12 @@ 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) {
+  Status = VirtioAllocateSharedPages (VirtIo, Ring->NumPages, &Ring->Base);
+  if (EFI_ERROR (Status)) {
     return EFI_OUT_OF_RESOURCES;
   }
   SetMem (Ring->Base, RingSize, 0x00);
@@ -143,7 +147,7 @@ VirtioRingUninit (
   IN OUT VRING                  *Ring
   )
 {
-  FreePages (Ring->Base, Ring->NumPages);
+  VirtioFreeSharedPages (VirtIo, Ring->NumPages, Ring->Base);
   SetMem (Ring, sizeof *Ring, 0x00);
 }
 
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to