History log of /device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
fcb636ea4244cb29d3f6a6d938dd9f7692ecfa7c 16-Oct-2015 Laszlo Ersek <lersek@redhat.com> OvmfPkg: VirtioBlkDxe: reset device at ExitBootServices()

(1) VirtioLib allocates the virtio ring in EfiBootServicesData memory.
(This is intentional.) Code that executes after ExitBootServices() is
permitted to reuse such memory.

(2) The hypervisor is allowed to look at, and act upon, a live virtio ring
at any time, even without explicit virtio kicks from the guest.

Should boot loader code or kernel code, running between ExitBootServices()
and the kernel's own virtio drivers resetting the device, overwrite the
pages that used to contain the virtio ring before ExitBootServices(), QEMU
could theoretically interpret that unrelated data as garbage ring
contents, and abort the guest.

Although we have seen no such reports, better be prudent and reset the
device in an ExitBootServices() event handler. Among other things, this
causes QEMU to forget about the device's virtio ring.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18624 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
c404616199df383226df1b70940008c01cfaec81 25-Sep-2014 Jordan Justen <jordan.l.justen@intel.com> OvmfPkg: Fix VS2005 build warnings

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16171 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
957914ee65e634eaa4743872ace6e9ac9ad446e4 18-Dec-2013 Laszlo Ersek <lersek@redhat.com> OvmfPkg: VirtioBlkInit(): log topology attributes

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15005 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
6476804e3cd2e1da23dee03024a21ab0e5c1f8ec 18-Dec-2013 Laszlo Ersek <lersek@redhat.com> OvmfPkg: VirtioBlkInit(): expose virtio-blk topology in BlockIo

UEFI spec virtio spec
======================================= =================================
LowestAlignedLba EFI_LBA (UINT64) alignment_offset u8
+-------------------------------------- +--------------------------------
| first LBA that is aligned to a | offset of first aligned
| physical block boundary (SCSI | logical block
| definition)

LogicalBlocksPerPhysicalBlock UINT32 physical_block_exp u8
+-------------------------------------- +--------------------------------
| number of logical blocks per | # of logical blocks per
| physical block [...] does not contain | physical block (log2)
| an exponential value

OptimalTransferLengthGranularity UINT32 opt_io_size le32
+-------------------------------------- +--------------------------------
| optimal transfer length granularity | optimal (suggested maximum) I/O
| as a number of logical blocks [...] A | size in blocks
| value of 0 means there is no reported
| optimal transfer length granularity

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15004 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
21479c3c80fa4742027537d91f57fbf469848208 18-Dec-2013 Laszlo Ersek <lersek@redhat.com> OvmfPkg/VirtioBlkDxe/VirtioBlk.c: rewrap overlong lines

Lines should be no longer than 79 characters.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15003 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
71914406e894c462dc9255c7a18f9cbe3651b8f8 12-Dec-2013 Laszlo Ersek <lersek@redhat.com> OvmfPkg: Virtio drivers: fix incorrect casts in init functions

The recent patch

OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL

was fixed up at commit time, in order to silence warnings issued by the
Visual Studio compiler. Differences between the posted and committed
patch:

> diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
> -index 17b9f71..96a0d9f 100644
> +index 17b9f71..f09b0d1 100644
> --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
> +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
> @@ -23,7 +23,6 @@
> @@ -994,7 +998,7 @@
> + // step 4c -- Report GPFN (guest-physical frame number) of queue.
> + //
> + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+ (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++ (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> + if (EFI_ERROR (Status)) {
> + goto ReleaseQueue;
> + }
> @@ -1495,7 +1499,7 @@
> goto Exit;
> }
> diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
> -index 6cee014..8dcf9da 100644
> +index 6cee014..4203fbd 100644
> --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
> +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
> @@ -57,14 +57,15 @@ VirtioNetInitRing (
> @@ -1539,7 +1543,7 @@
> - Status = VIRTIO_CFG_WRITE (Dev, Generic.VhdrQueueAddress,
> - (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
> + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+ (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
> ++ (UINT32)(UINTN) Ring->Base >> EFI_PAGE_SHIFT);
> if (EFI_ERROR (Status)) {
> - VirtioRingUninit (Ring);
> + goto ReleaseQueue;
> @@ -1721,7 +1725,7 @@
> Exit:
> gBS->RestoreTPL (OldTpl);
> diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
> -index b836fb3..bcec676 100644
> +index b836fb3..2223c9c 100644
> --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
> +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
> @@ -38,7 +38,6 @@
> @@ -1908,7 +1912,7 @@
> + // step 4c -- Report GPFN (guest-physical frame number) of queue.
> + //
> + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+ (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++ (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> if (EFI_ERROR (Status)) {
> goto ReleaseQueue;
> }

These casts are incorrect -- they throw away address bits >=32 before
shifting, which can break the drivers in guests with more than 4GB RAM.

The bug is clearly an artifact of the edk2 coding style, which requires
cast expressions to be written as

(type) expression

rather than the usual

(type)expression

The latter correctly reflects that casts have one of the strongest
bindings in C. The former actively obscures that fact. Cf.

(type) expr1 >> expr2

vs.

(type)expr1 >> expr2

Make sure we shift before we truncate.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14970 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
ece77e4047c36ddd177949e81d548bda244ea8a7 11-Dec-2013 Olivier Martin <olivier.martin@arm.com> OvmfPkg/Virtio: Removed VirtioReadDevice() / VirtIoWriteDevice() functions

These functions did not provide much more than the new protocol functions
VIRTIO_DEVICE_PROTOCOL.ReadDevice() / VIRTIO_DEVICE_PROTOCOL.WriteDevice().

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14968 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
56f65ed838e8d73e91d54a8ed984d777c936843c 11-Dec-2013 Olivier Martin <olivier.martin@arm.com> OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL

This change replaces the accesses to the PCI bus from the Block, Scsi and Net drivers by
the use of the new VIRTIO_DEVICE_PROTOCOL protocol that abstracts the transport layer.
It means these drivers can be used on PCI and MMIO transport layer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>

v5:
- VirtioFlush(): update comment block in VirtioLib.[hc]; error code is
propagated from VirtIo->SetQueueNotify().
- VirtioBlkInit(): jump to Failed label if SetPageSize() fails
- VirtioBlkInit(): fixup comment, and add error handling, near
SetQueueNum() call
- VirtioBlkDriverBindingStart(): remove redundant (always false) check for
a subsystem device ID different from VIRTIO_SUBSYSTEM_BLOCK_DEVICE;
VirtioBlkDriverBindingSupported() handles it already
- VirtioNetGetFeatures(): update stale comment block
- VirtioNetGetFeatures(): retrieve MAC address byte for byte (open-coded
loop)
- VirtioNetDriverBindingStart(): remove redundant (always false) check for
a subsystem device ID different from VIRTIO_SUBSYSTEM_NETWORK_CARD;
VirtioNetDriverBindingSupported() handles it already
- VirtioNetInitRing(): call SetQueueNum() and SetQueueAlign() for proper
MMIO operation
- VirtioNetInitialize(): fix destination error label for when
SetPageSize() fails
- VirtioScsi.c: fix comment block of VIRTIO_CFG_WRITE()/VIRTIO_CFG_READ()
- VirtioScsiInit(): fix destination error label for when SetPageSize()
fails
- VirtioScsiInit(): call SetQueueNum() and SetQueueAlign() for proper MMIO
operation

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14966 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
43e54972af046697fbc9c4416810724daa57559d 30-Sep-2013 Olivier Martin <olivier.martin@arm.com> OvmfPkg: Removed magic values for the Virtio Sub-System ID in the PCI device drivers

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14742 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
c8c2e4d61339592056931dff5c209b7d06fb466c 18-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: VirtioBlkDriverBindingStop: fix incorrect use of UEFI driver model

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13866 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
389b5518bfc986cf40e3c1b15851182f9330d10d 14-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg/VirtioBlkDxe: Fix VS2012 IA32 build

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13847 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
2f03f796a40769d7390d0a9e5da70424e795afdc 14-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: VirtioBlkDxe: fix div & mod of 64-bit dividends on IA32/gcc-4.4

OvmfPkg/VirtioBlkDxe/VirtioBlk.c:667: undefined reference to `__umoddi3'
OvmfPkg/VirtioBlkDxe/VirtioBlk.c:750: undefined reference to `__udivdi3'

These operations would come from libgcc in the IA32 build, but OVMF does not
link against libgcc.

Regression-tested the X64 build with Fedora 18 Alpha XFCE and Windows 8
Consumer Preview guests.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13846 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
9de0355b1ad7c8afaaf1dc0545438c9a6659d869 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: MSVC build fixes for VirtioLib and VirtioBlkDxe

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Mike Lee <leemiketw@gmail.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13845 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
e371e7e545b266ce4ae8ff76da6c98616214599f 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: librarize reusable bits from VirtioBlkDxe's SynchronousRequest()

new VirtioLib functions:
- VirtioPrepare(): prepare for appending descriptors
- VirtioFlush(): submit descriptor chain and await host answer

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13844 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
7fcacd6c92616fd993a5befd93bcc9cad2610c90 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: rename AppendDesc to VirtioAppendDesc

AppendDesc() should have a prefix implying its containing library,
VirtioLib. Update its sole client VirtioBlkDxe.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13843 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
263559b87232826552c9e42c1652d9f9488c9870 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: extract VirtioLib from VirtioBlkDxe

Introduce a new library called VirtioLib, for now only collecting the
following reusable functions with as little changes as possible:

- VirtioWrite()
- VirtioRead()
- VirtioRingInit()
- VirtioRingUninit()
- AppendDesc()

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13842 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
6b28fe9ee8957c98b4c70c83560734196f43f92f 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: Include/IndustryStandard: extract VirtioBlk.h from Virtio.h

Separate virtio-blk related macro and type definitions from generic virtio
related ones. Adapt the virtio-blk driver since it needs the latter too.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13841 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
a9624f945e37047196e825fcbe170772373fdae9 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: rename OFFSET_OF_VHDR() / SIZE_OF_VHDR() to *_OF_VBLK()

since they are in fact virtio-blk specific.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13840 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
55c3443a4f9a7bba34f1c60c6121c6b73dd05241 12-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: regroup virtio config fields into generic & specific structs

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13839 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
fd51d7599173164be618d26e9d3673c09f60dbb2 08-Oct-2012 jljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524> OvmfPkg: introduce virtio-blk driver

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13798 6f19259b-4bc3-4df7-8a09-765794883524
/device/linaro/bootloader/edk2/OvmfPkg/VirtioBlkDxe/VirtioBlk.c