]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: S3SaveStateDxe, SmmS3SaveState: save 64-bit LoopTimes
authorLaszlo Ersek <lersek@redhat.com>
Wed, 30 Nov 2016 19:19:06 +0000 (20:19 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Tue, 3 Jan 2017 11:23:38 +0000 (12:23 +0100)
The BootScriptWriteMemPoll() helper function in both drivers does the
following:

- pop Delay from the variable argument list as UINT64, then truncate it to
  UINTN,

- divide Delay by 10, using DivU64x32Remainder(), then store the quotient
  in LoopTimes (also UINTN),

- pass LoopTimes to S3BootScriptSaveMemPoll() as last argument.

The truncation to UINTN is superfluous and wrong in this logic (not to
mention incompatible with the PI spec); it prevents callers from
specifying Delays longer than 0xFFFF_FFFF * 100ns (approximately 429
seconds == 7 minutes 9 seconds) on Ia32. In particular it prevents callers
from specifying an infinite timeout (for example, 0xFFFF_FFFF_FFFF_FFFF *
100ns, approximately 58494 years).

Change the type of Delay and LoopTimes to UINT64. Keep the same logic,
just remove the truncations. The resultant LoopTimes values can be safely
passed to S3BootScriptSaveMemPoll() thanks to the previous patch.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: "Yao, Jiewen" <jiewen.yao@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c
MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c

index 32263c96c56be3e7279f6cf5f084ef4b40ed5304..efc0ef91406463bc72a33cfde9e2788eec7bb519 100644 (file)
@@ -343,15 +343,15 @@ BootScriptWriteMemPoll (
   UINT64                     Address;                                    \r
   VOID                      *Data;                                    \r
   VOID                      *DataMask;                                  \r
-  UINTN                     Delay;                                   \r
-  UINT                    LoopTimes;\r
+  UINT64                    Delay;\r
+  UINT64                    LoopTimes;\r
   UINT32                    Remainder;\r
 \r
   Width    = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);                  \r
   Address  = VA_ARG (Marker, UINT64);                                    \r
   Data     = VA_ARG (Marker, VOID *);                                    \r
   DataMask = VA_ARG (Marker, VOID *);                                    \r
-  Delay    = (UINTN)VA_ARG (Marker, UINT64);                            \r
+  Delay    = VA_ARG (Marker, UINT64);\r
   //\r
   // According to the spec, the interval between 2 polls is 100ns,\r
   // but the unit of Duration for S3BootScriptSaveMemPoll() is microsecond(1000ns).\r
@@ -359,7 +359,7 @@ BootScriptWriteMemPoll (
   // Duration will be minimum 1(microsecond) to be minimum deviation,\r
   // so LoopTimes = Delay / 10.\r
   //\r
-  LoopTimes = (UINTN) DivU64x32Remainder (\r
+  LoopTimes = DivU64x32Remainder (\r
                 Delay,\r
                 10,\r
                 &Remainder\r
index 739f19eac437445c743544a228566795552f154f..0d1580dc35abbbd8f29dc33fa8eda2fd8443fda9 100644 (file)
@@ -342,15 +342,15 @@ BootScriptWriteMemPoll (
   UINT64                     Address;                                    \r
   VOID                      *Data;                                       \r
   VOID                      *DataMask;                                   \r
-  UINTN                      Delay;                                       \r
-  UINT                     LoopTimes;\r
+  UINT64                     Delay;\r
+  UINT64                     LoopTimes;\r
   UINT32                     Remainder;\r
 \r
   Width    = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH);                  \r
   Address  = VA_ARG (Marker, UINT64);                                    \r
   Data     = VA_ARG (Marker, VOID *);                                    \r
   DataMask = VA_ARG (Marker, VOID *);                                    \r
-  Delay    = (UINTN)VA_ARG (Marker, UINT64);                            \r
+  Delay    = VA_ARG (Marker, UINT64);\r
   //\r
   // According to the spec, the interval between 2 polls is 100ns,\r
   // but the unit of Duration for S3BootScriptSaveMemPoll() is microsecond(1000ns).\r
@@ -358,7 +358,7 @@ BootScriptWriteMemPoll (
   // Duration will be minimum 1(microsecond) to be minimum deviation,\r
   // so LoopTimes = Delay / 10.\r
   //\r
-  LoopTimes = (UINTN) DivU64x32Remainder (\r
+  LoopTimes = DivU64x32Remainder (\r
                 Delay,\r
                 10,\r
                 &Remainder\r