From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 603DA21E47D65 for ; Wed, 23 Aug 2017 14:15:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B61A5356C9; Wed, 23 Aug 2017 21:18:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B61A5356C9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-43.phx2.redhat.com [10.3.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EA8766D39; Wed, 23 Aug 2017 21:18:03 +0000 (UTC) To: Brijesh Singh , edk2-devel@lists.01.org Cc: Jordan Justen , Tom Lendacky , Ard Biesheuvel References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> <1503490967-5559-11-git-send-email-brijesh.singh@amd.com> From: Laszlo Ersek Message-ID: <3ea40326-af2f-6ecf-bf8d-c8bfacfe4eb9@redhat.com> Date: Wed, 23 Aug 2017 23:18:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1503490967-5559-11-git-send-email-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 23 Aug 2017 21:18:05 +0000 (UTC) Subject: Re: [PATCH v3 10/23] OvmfPkg/VirtioLib: alloc VRING buffer with AllocateSharedPages() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Aug 2017 21:15:31 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/23/17 14:22, Brijesh Singh wrote: > 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 > --- > OvmfPkg/Library/VirtioLib/VirtioLib.inf | 1 - > OvmfPkg/Include/Library/VirtioLib.h | 5 ++--- > OvmfPkg/Library/VirtioLib/VirtioLib.c | 22 +++++++++++++------- > 3 files changed, 16 insertions(+), 12 deletions(-) > > diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.inf b/OvmfPkg/Library/VirtioLib/VirtioLib.inf > index fb5897a88ecf..e33856de38c4 100644 > --- a/OvmfPkg/Library/VirtioLib/VirtioLib.inf > +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.inf > @@ -32,5 +32,4 @@ [LibraryClasses] > BaseLib > BaseMemoryLib > DebugLib > - MemoryAllocationLib > UefiBootServicesTableLib > diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h > index 3d9314b3acaf..c3e56ea23b89 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. > + @retval Status codes propagated from > + VirtIo->AllocateSharedPages(). (1) The documentation has been updated (thanks for that), but I also requested "@return", not "@retval". Can be fixed up on push. > > @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 535635ac0ba8..e5366e385f5d 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. > + @retval Status codes propagated from > + VirtIo->AllocateSharedPages(). (2) Same as (1), should be @return. Reviewed-by: Laszlo Ersek Thanks! Laszlo > > @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); > } > >