From patchwork Thu Jun 4 15:55:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 49538 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A3C372154F for ; Thu, 4 Jun 2015 16:27:46 +0000 (UTC) Received: by lbbti3 with SMTP id ti3sf11840765lbb.1 for ; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=ClDvq18XG619F4gQS4twyv5FfizccCE7nZkQ6KiMtMs=; b=Yb1NCpsiiZRT7wAebHq2piwJhI8t4MF7P7+v8UlEToJoqAiOVGWvzCU9VhxCDzrSa+ FAdnUcdU6LwUs7AOMPyAfk4agWvBiRuPkglzMnkafCB2ZEq041DUZOwVKaqfrm5fzk3L w9cCfOVUU1LwNlJknLu7U5YfUNaxfS8qRKHAHvEtUk6bZDtX0BfDw3Tr4PbN8V0UHF/B jGqUa0oNI7AlQJd/qA1h4j8XxILf5ZFo0Cdwfv2CmCFOmudbcg3eU3J48kR5gEOW2GiZ cdJHu+lKPvejfObniB+8tfhKiuKVfBhst+TFLUYsdVfUzzKbyCY6Q2rhGyd6YwzWLPGw o1qw== X-Gm-Message-State: ALoCoQkca7oj7zmCWAQgNRW7JZSeT30KAsQfVZSegXKu4TT3iDUnNb92qffVtKvT2MuJkNp+56WE X-Received: by 10.112.203.168 with SMTP id kr8mr36345612lbc.10.1433435265670; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.239.130 with SMTP id vs2ls203947lac.97.gmail; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) X-Received: by 10.112.118.206 with SMTP id ko14mr38570543lbb.28.1433435265523; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id s10si2268529laj.84.2015.06.04.09.27.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2015 09:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbcue7 with SMTP id ue7so30669593lbc.0 for ; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr22792416lbb.56.1433435265371; Thu, 04 Jun 2015 09:27:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp733464lbb; Thu, 4 Jun 2015 09:27:44 -0700 (PDT) X-Received: by 10.50.67.111 with SMTP id m15mr6317785igt.29.1433435262414; Thu, 04 Jun 2015 09:27:42 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id bx19si16887759igb.63.2015.06.04.09.27.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 04 Jun 2015 09:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Z0XzR-0006NW-Sm; Thu, 04 Jun 2015 16:27:33 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Z0XzQ-0006NR-Jx for edk2-devel@lists.sourceforge.net; Thu, 04 Jun 2015 16:27:32 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.216.44 as permitted sender) client-ip=209.85.216.44; envelope-from=heyi.guo@linaro.org; helo=mail-vn0-f44.google.com; Received: from mail-vn0-f44.google.com ([209.85.216.44]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Z0XzP-0004x3-Sm for edk2-devel@lists.sourceforge.net; Thu, 04 Jun 2015 16:27:32 +0000 Received: by vnbf7 with SMTP id f7so5718782vnb.7 for ; Thu, 04 Jun 2015 09:27:26 -0700 (PDT) X-Received: by 10.52.26.199 with SMTP id n7mr57410796vdg.23.1433433359851; Thu, 04 Jun 2015 08:55:59 -0700 (PDT) Received: from localhost.localdomain ([167.160.116.86]) by mx.google.com with ESMTPSA id di5sm4948150vdc.6.2015.06.04.08.55.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jun 2015 08:55:58 -0700 (PDT) From: Heyi Guo To: feng.tian@intel.com Date: Thu, 4 Jun 2015 23:55:40 +0800 Message-Id: <1433433340-30006-1-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.1.4 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1Z0XzP-0004x3-Sm Cc: edk2-devel@lists.sourceforge.net, ilias.biris@linaro.org Subject: [edk2] [PATCH] MdeModulePkg: Fix bug of AllocatePages for large alignment X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: heyi.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 DescEnd will be clipped for alignment in CoreFindFreePagesI, and it may fall below DescStart, when alignment is more than 16KB (included) and both DescStart and original DescEnd fall into a single range of such alignment. This results in a huge size (Negative number in unsigned type) for this descriptor, fulfilling the allocation requirement but failing to run ConvertPages; at last it causes occasional failure of AllocatePages. A simple comparison is added to ensure we would never get a negative number. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo --- MdeModulePkg/Core/Dxe/Mem/Page.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index a92c865..f2efaf1 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1051,6 +1051,11 @@ CoreFindFreePagesI ( DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1; + // Skip if DescEnd is less than DescStart after alignment clipping + if (DescEnd < DescStart) { + continue; + } + // // Compute the number of bytes we can used from this // descriptor, and see it's enough to satisfy the request