From patchwork Thu Dec 1 17:55:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 86126 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp810251qgi; Thu, 1 Dec 2016 09:56:08 -0800 (PST) X-Received: by 10.84.210.46 with SMTP id z43mr87192087plh.175.1480614968700; Thu, 01 Dec 2016 09:56:08 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id z65si989231plh.175.2016.12.01.09.56.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2016 09:56:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5F5B881F1E; Thu, 1 Dec 2016 09:56:08 -0800 (PST) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org 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 80EC581F1C for ; Thu, 1 Dec 2016 09:56:07 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6A748E005; Thu, 1 Dec 2016 17:56:06 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-138.phx2.redhat.com [10.3.116.138]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB1Hu0Am017729; Thu, 1 Dec 2016 12:56:05 -0500 From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 1 Dec 2016 18:55:55 +0100 Message-Id: <20161201175556.2479-3-lersek@redhat.com> In-Reply-To: <20161201175556.2479-1-lersek@redhat.com> References: <20161201175556.2479-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 01 Dec 2016 17:56:07 +0000 (UTC) Subject: [edk2] [PATCH 2/3] MdeModulePkg: S3SaveStateDxe, SmmS3SaveState: save 64-bit LoopTimes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Tian , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c | 8 ++++---- MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) -- 2.9.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c index 32263c96c56b..efc0ef914064 100644 --- a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c +++ b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveState.c @@ -343,15 +343,15 @@ BootScriptWriteMemPoll ( UINT64 Address; VOID *Data; VOID *DataMask; - UINTN Delay; - UINTN LoopTimes; + UINT64 Delay; + UINT64 LoopTimes; UINT32 Remainder; Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH); Address = VA_ARG (Marker, UINT64); Data = VA_ARG (Marker, VOID *); DataMask = VA_ARG (Marker, VOID *); - Delay = (UINTN)VA_ARG (Marker, UINT64); + Delay = VA_ARG (Marker, UINT64); // // According to the spec, the interval between 2 polls is 100ns, // but the unit of Duration for S3BootScriptSaveMemPoll() is microsecond(1000ns). @@ -359,7 +359,7 @@ BootScriptWriteMemPoll ( // Duration will be minimum 1(microsecond) to be minimum deviation, // so LoopTimes = Delay / 10. // - LoopTimes = (UINTN) DivU64x32Remainder ( + LoopTimes = DivU64x32Remainder ( Delay, 10, &Remainder diff --git a/MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c b/MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c index 739f19eac437..0d1580dc35ab 100644 --- a/MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c +++ b/MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.c @@ -342,15 +342,15 @@ BootScriptWriteMemPoll ( UINT64 Address; VOID *Data; VOID *DataMask; - UINTN Delay; - UINTN LoopTimes; + UINT64 Delay; + UINT64 LoopTimes; UINT32 Remainder; Width = VA_ARG (Marker, S3_BOOT_SCRIPT_LIB_WIDTH); Address = VA_ARG (Marker, UINT64); Data = VA_ARG (Marker, VOID *); DataMask = VA_ARG (Marker, VOID *); - Delay = (UINTN)VA_ARG (Marker, UINT64); + Delay = VA_ARG (Marker, UINT64); // // According to the spec, the interval between 2 polls is 100ns, // but the unit of Duration for S3BootScriptSaveMemPoll() is microsecond(1000ns). @@ -358,7 +358,7 @@ BootScriptWriteMemPoll ( // Duration will be minimum 1(microsecond) to be minimum deviation, // so LoopTimes = Delay / 10. // - LoopTimes = (UINTN) DivU64x32Remainder ( + LoopTimes = DivU64x32Remainder ( Delay, 10, &Remainder