Acidanthera UEFI Development Kit based on EDK II edk2-stable202311
Go to file
Laszlo Ersek 71914406e8 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
2013-12-12 17:28:05 +00:00
AppPkg Enable the build command override the .DSC file contents to enable debug output and specify which debug messages are displayed. An example: 2013-11-19 02:37:37 +00:00
ArmPkg ARM Packages: Removed 'inline' keyword 2013-12-10 16:39:54 +00:00
ArmPlatformPkg ARM Packages: Removed 'inline' keyword 2013-12-10 16:39:54 +00:00
BaseTools Sync BaseTool trunk (version r2610) into EDKII BaseTools. 2013-11-18 07:41:21 +00:00
BeagleBoardPkg ArmPlatformPkg: Fix and Implement ArmPlatformGetPrimaryCoreMpId 2013-12-06 16:11:34 +00:00
Conf Adding top-level Conf directory for next generation of EDK II build infrastructure tools. 2007-06-20 19:33:23 +00:00
CryptoPkg Fixed one typo in MathRShiftU64.S stub implementation; Add one digest algorithm registration to make sure the underlying algorithm is available for the default OpenSSL software PRNG implementation. 2013-11-19 02:57:19 +00:00
DuetPkg Fix Duet hang/reboot issue due to the NULL instance of CpuExceptionHandlerLib is used. 2013-11-26 05:41:34 +00:00
EdkCompatibilityPkg Follow UEFI spec to add the definition for EFI_SPECIFICATION_VERSION, and update other table version to refer to it. Remove the “/D TIANO_RELEASE_VERSION=0x00080006” option in Nt32Pkg DSC file, since it’s not used in source code. 2013-11-26 07:36:29 +00:00
EdkShellBinPkg EdkShellBinPkg: Added AArch64 EdkShellPkg binary and Updated Arm binary 2013-09-24 11:43:02 +00:00
EdkShellPkg Follow UEFI spec to add the definition for EFI_SPECIFICATION_VERSION, and update other table version to refer to it. Remove the “/D TIANO_RELEASE_VERSION=0x00080006” option in Nt32Pkg DSC file, since it’s not used in source code. 2013-11-26 07:36:29 +00:00
EmbeddedPkg EmbeddedPkg/EmbeddedPkg.dec: Defined default values for PcdPrePiCpuMemorySize & PcdPrePiCpuIoSize 2013-11-28 21:40:14 +00:00
EmulatorPkg EmulatorPkg: Use FaultTolerantWritePei driver. 2013-07-03 09:24:07 +00:00
FatBinPkg Fix a bug in Fat driver that it asserts when OpenEx/ReadEx/WriteEx is about to return failure. 2013-11-29 03:04:16 +00:00
IntelFrameworkModulePkg Add additional check mRuntimeSmbiosEntryPoint == NULL to avoid K9 error. 2013-12-11 08:53:19 +00:00
IntelFrameworkPkg Fill the ImageHandle and DriverBindingHandle field of Driver Binding Protocol before installing the Driver Binding Protocol instance. 2013-07-10 02:06:49 +00:00
MdeModulePkg 1. Add ISCSI iBFT CHAP types to IScsiBootFirmwareTable.h. 2013-12-10 09:14:39 +00:00
MdePkg 1. Add ISCSI iBFT CHAP types to IScsiBootFirmwareTable.h. 2013-12-10 09:14:39 +00:00
NetworkPkg 1. Add ISCSI iBFT CHAP types to IScsiBootFirmwareTable.h. 2013-12-10 09:14:39 +00:00
Nt32Pkg Follow UEFI spec to add the definition for EFI_SPECIFICATION_VERSION, and update other table version to refer to it. Remove the “/D TIANO_RELEASE_VERSION=0x00080006” option in Nt32Pkg DSC file, since it’s not used in source code. 2013-11-26 07:36:29 +00:00
Omap35xxPkg EmbeddedPkg: Introduced a separate SerialPortExtLib library 2013-03-12 00:40:11 +00:00
OptionRomPkg OptionRomPkg: Corrected path for the FtdiUsbSerialDxe.inf in OptionRomPkg.dsc 2013-11-01 17:01:23 +00:00
OvmfPkg OvmfPkg: Virtio drivers: fix incorrect casts in init functions 2013-12-12 17:28:05 +00:00
PcAtChipsetPkg Fix PciHostBridge driver to return success for EfiPciHostBridgeEndEnumeration to fix OVMF boot no display issue. 2013-07-22 07:35:51 +00:00
PerformancePkg Refine the select language logic. 2013-09-05 05:39:57 +00:00
SecurityPkg Correct INF file to make module pass ICC compiler. 2013-12-11 08:22:43 +00:00
ShellBinPkg ShellBinPkg: Update ARM and AArch64 Binaries with svn 14706 ShellPkg sources 2013-09-24 10:22:32 +00:00
ShellPkg ShellPkg: Refactor out the searching for pipe characters 2013-12-12 17:27:27 +00:00
SourceLevelDebugPkg Correct INF file to make module pass ICC compiler. 2013-12-11 08:22:43 +00:00
StdLib StdLib: Update Copyright Notices. 2013-12-10 22:16:57 +00:00
StdLibPrivateInternalFiles EADK (StdLib, AppPkg, StdLibPrivateInternalFiles): Update ReadMe.txt in all packages. 2013-10-24 23:14:10 +00:00
UefiCpuPkg Correct INF file to make module pass ICC compiler. 2013-12-11 08:22:43 +00:00
UnixPkg UnixPkg: Remove UnixPkg files (It is replaced by EmulatorPkg) 2013-07-29 21:09:55 +00:00
BuildNotes2.txt Update to new SVN URL in readme.txt 2013-06-08 05:26:39 +00:00
edksetup.bat Update edksetup.bat to check VS2012 2013-09-04 07:41:04 +00:00
edksetup.sh Correct copyright year 2011-02-16 12:21:31 +00:00