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 AD2242095D2BF for ; Wed, 23 Aug 2017 13:08:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D7268763A; Wed, 23 Aug 2017 20:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5D7268763A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 883B168B09; Wed, 23 Aug 2017 20:10:56 +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-10-git-send-email-brijesh.singh@amd.com> From: Laszlo Ersek Message-ID: <74f00640-a142-c674-680d-b848999dfa06@redhat.com> Date: Wed, 23 Aug 2017 22:10:55 +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-10-git-send-email-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 23 Aug 2017 20:10:58 +0000 (UTC) Subject: Re: [PATCH v3 09/23] OvmfPkg/VirtioLib: add function to map VRING 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 20:08:24 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit There's one trivial omission in this patch, wrt. the previous review comments: On 08/23/17 14:22, Brijesh Singh wrote: > Add functions to map the ring buffer with BusMasterCommonBuffer so that (1) s/functions/a function/ I'll fix it up before I push the initial subsequence. Reviewed-by: Laszlo Ersek Thanks! Laszlo > ring can be accessed by both guest and hypervisor. > > 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/Include/Library/VirtioLib.h | 26 +++++++++++ > OvmfPkg/Library/VirtioLib/VirtioLib.c | 45 ++++++++++++++++++++ > 2 files changed, 71 insertions(+) > > diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h > index 40c51a2b3305..3d9314b3acaf 100644 > --- a/OvmfPkg/Include/Library/VirtioLib.h > +++ b/OvmfPkg/Include/Library/VirtioLib.h > @@ -62,6 +62,32 @@ VirtioRingInit ( > > /** > > + Map the ring buffer so that it can be accessed equally by both guest > + and hypervisor. > + > + @param[in] VirtIo The virtio device instance. > + > + @param[in] Ring The virtio ring to map. > + > + @param[out] RingBaseShift A resulting translation offset, to be > + passed to VirtIo->SetQueueAddress(). > + > + @param[out] Mapping A resulting token to pass to > + VirtIo->UnmapSharedBuffer(). > + > + @return Status code from VirtIo->MapSharedBuffer() > +**/ > +EFI_STATUS > +EFIAPI > +VirtioRingMap ( > + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, > + IN VRING *Ring, > + OUT UINT64 *RingBaseShift, > + OUT VOID **Mapping > + ); > + > +/** > + > Tear down the internal resources of a configured virtio ring. > > The caller is responsible to stop the host from using this ring before > diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c > index 8bc5b9aea4fc..535635ac0ba8 100644 > --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c > +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c > @@ -505,3 +505,48 @@ Failed: > VirtIo->UnmapSharedBuffer (VirtIo, MapInfo); > return EFI_OUT_OF_RESOURCES; > } > + > +/** > + > + Map the ring buffer so that it can be accessed equally by both guest > + and hypervisor. > + > + @param[in] VirtIo The virtio device instance. > + > + @param[in] Ring The virtio ring to map. > + > + @param[out] RingBaseShift A resulting translation offset, to be > + passed to VirtIo->SetQueueAddress(). > + > + @param[out] Mapping A resulting token to pass to > + VirtIo->UnmapSharedBuffer(). > + > + @return Status code from VirtIo->MapSharedBuffer() > +**/ > +EFI_STATUS > +EFIAPI > +VirtioRingMap ( > + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, > + IN VRING *Ring, > + OUT UINT64 *RingBaseShift, > + OUT VOID **Mapping > + ) > +{ > + EFI_STATUS Status; > + EFI_PHYSICAL_ADDRESS DeviceAddress; > + > + Status = VirtioMapAllBytesInSharedBuffer ( > + VirtIo, > + VirtioOperationBusMasterCommonBuffer, > + Ring->Base, > + EFI_PAGES_TO_SIZE (Ring->NumPages), > + &DeviceAddress, > + Mapping > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + *RingBaseShift = DeviceAddress - (UINT64)(UINTN)Ring->Base; > + return EFI_SUCCESS; > +} >