From patchwork Thu Apr 9 11:28:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46940 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 57CFC21416 for ; Thu, 9 Apr 2015 11:29:32 +0000 (UTC) Received: by wghm4 with SMTP id m4sf25864849wgh.2 for ; Thu, 09 Apr 2015 04:29:31 -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:in-reply-to :references: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=cvR5Zj7dLHmcVUllhHonwnu8jLvn4kvSaJQGSOuWNPk=; b=ZLELg0nvuhWoZ8sU6y1HtRIb4xsd/dm8c/xtR26ic+VauWJock2acdEoBYHS5d5C75 2cU5vgmUCKiFxGBhbJubY28MmPV4qHjtzVfu5EOJ2ljv/OWGKONIBV7Mjj+AbxmuQzmV JJ92zs/HnRLxmgKpPlRXkHM1dlkA3cUavt8zzBfKStEQ+hHx9fmQ9siubJPxjCV1NF7P XtKC2Zb554RUAQbB4y8/S32UpMNhYh1NK9RjDzVRTnihEp7urD1YbfMC84eY4SdtekpH FcLU9e0vxF+YTREQ78jDHVJrnVWwu9ebBro7rD/1KKhBuBHn6Rb8WHgyyBP0WmbFX38K 06Uw== X-Gm-Message-State: ALoCoQkEjv298PUtbAsQODBoDcAiVQcnktSCJKrlo6JAAdyVWhwcV7ZVJO0Or5Ce1QMURjakQPUc X-Received: by 10.152.23.7 with SMTP id i7mr299531laf.1.1428578971672; Thu, 09 Apr 2015 04:29:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.110 with SMTP id bf14ls278385lab.48.gmail; Thu, 09 Apr 2015 04:29:31 -0700 (PDT) X-Received: by 10.152.21.99 with SMTP id u3mr4197101lae.105.1428578971440; Thu, 09 Apr 2015 04:29:31 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id jj4si9028388lbb.174.2015.04.09.04.29.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 04:29:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbuc2 with SMTP id uc2so85166315lbb.2 for ; Thu, 09 Apr 2015 04:29:31 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr12947492lbc.86.1428578970651; Thu, 09 Apr 2015 04:29:30 -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.67.65 with SMTP id l1csp411759lbt; Thu, 9 Apr 2015 04:29:29 -0700 (PDT) X-Received: by 10.107.40.2 with SMTP id o2mr46741755ioo.68.1428578966881; Thu, 09 Apr 2015 04:29:26 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id a1si12366475ioj.29.2015.04.09.04.29.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Apr 2015 04:29:26 -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-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YgAe6-0007iN-Ra; Thu, 09 Apr 2015 11:29:18 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YgAe6-0007iH-7N for edk2-devel@lists.sourceforge.net; Thu, 09 Apr 2015 11:29:18 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.48 as permitted sender) client-ip=74.125.82.48; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f48.google.com; Received: from mail-wg0-f48.google.com ([74.125.82.48]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YgAe5-0007Ts-2x for edk2-devel@lists.sourceforge.net; Thu, 09 Apr 2015 11:29:18 +0000 Received: by wgin8 with SMTP id n8so116826503wgi.0 for ; Thu, 09 Apr 2015 04:29:11 -0700 (PDT) X-Received: by 10.194.62.132 with SMTP id y4mr27243913wjr.91.1428578951027; Thu, 09 Apr 2015 04:29:11 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.113]) by mx.google.com with ESMTPSA id l10sm19692348wje.15.2015.04.09.04.29.09 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Apr 2015 04:29:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Thu, 9 Apr 2015 13:28:51 +0200 Message-Id: <1428578932-24079-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1428578932-24079-1-git-send-email-ard.biesheuvel@linaro.org> References: <1428578932-24079-1-git-send-email-ard.biesheuvel@linaro.org> 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: 1YgAe5-0007Ts-2x Subject: [edk2] [PATCH v4 4/5] ArmVirtualizationPkg: invalidate PEI memory region by VA 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: ard.biesheuvel@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.182 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 This updates ArmVirtualizationMemoryInitPeiLib so that the PEI memory region, i.e., the region that is used both before and after the MMU and caches are enabled, is invalidated by virtual address before enabling the MMU. This prevents issues where data we modified with the caches and MMU off may be shadowed by clean cachelines in system caches or in lower level caches on other CPUs, resulting in the this data to become invisible once we turn the MMU and caches on. Also reduce the size of the region to 16 MB (from 64 MB), to reduce the potential performance hit from invalidating the entire region by virtual address. Contributed-under: TianoCore Contribution Agreement 1.0 Reviewed-By: Olivier Martin Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c | 10 ++++++++++ ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf | 1 + 2 files changed, 11 insertions(+) diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c index 5f6cd059c47f..8ce63b4596e2 100644 --- a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c @@ -20,6 +20,7 @@ #include #include #include +#include VOID BuildMemoryTypeInformationHob ( @@ -79,6 +80,15 @@ MemoryPeim ( PcdGet64 (PcdSystemMemorySize) ); + // + // When running under virtualization, the PI/UEFI memory region may be + // clean but not invalidated in system caches or in lower level caches + // on other CPUs. So invalidate the region by virtual address, to ensure + // that the contents we put there with the caches and MMU off will still + // be visible after turning them on. + // + InvalidateDataCacheRange ((VOID*)(UINTN)UefiMemoryBase, UefiMemorySize); + // Build Memory Allocation Hob InitMmu (); diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf index fcdae06de7c2..b8a19c993d91 100644 --- a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf @@ -35,6 +35,7 @@ HobLib ArmLib ArmPlatformLib + CacheMaintenanceLib [Guids] gEfiMemoryTypeInformationGuid