From patchwork Wed Apr 8 07:11:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46869 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1611A218CB for ; Wed, 8 Apr 2015 07:11:54 +0000 (UTC) Received: by lamp14 with SMTP id p14sf17652240lam.3 for ; Wed, 08 Apr 2015 00:11:51 -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=ftHpc42EOZkJVzXOoTYtgFo7tgNbtJEqinmeJBlx7Ik=; b=ifZjQXdXdT3aqmfBLfV7mWK7I1KbHVorjH/Sy7bkHgpDPYfhC7ZMkKn+e1823rb61U EppUPtjBjYLhg7Nq4SFOXFSQHVE8W7eZ4XHlWUHAEHEjI+cbwkurnZSidS+2rbpWbScE nRna9HQYInV3XV+qnsHyf5OmHfkGaGhnsbasWenDVM6IaHdxNsthFhyxxsL3UziUJih6 aqKNt45NDC7H+GsrjKm+7dYJCg4WZAtPVFaP6d1RnUM0UlZOo47fLzghxNVlOqPc5QHZ RIKzYhFbfZLTlDHmS2TuRN5tG/5OmL7TWN8OzBNv4+NlUYGydzzpFohAyE8K07nWW1a5 p3jA== X-Gm-Message-State: ALoCoQnLMB6WrVpM3pJ/2SxdJhSr5uO8fs6vyfD1nlXKZCQ6RMxE/fwb2KH19FQ9a/n7NC3O6Jps X-Received: by 10.112.28.111 with SMTP id a15mr868945lbh.21.1428477111847; Wed, 08 Apr 2015 00:11:51 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.204 with SMTP id ba12ls147293lab.41.gmail; Wed, 08 Apr 2015 00:11:51 -0700 (PDT) X-Received: by 10.152.179.172 with SMTP id dh12mr1203413lac.22.1428477111703; Wed, 08 Apr 2015 00:11:51 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id t17si8016990laz.27.2015.04.08.00.11.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 00:11:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lagv1 with SMTP id v1so59224119lag.3 for ; Wed, 08 Apr 2015 00:11:51 -0700 (PDT) X-Received: by 10.152.8.78 with SMTP id p14mr19392300laa.19.1428477111600; Wed, 08 Apr 2015 00:11:51 -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 l1csp878159lbt; Wed, 8 Apr 2015 00:11:50 -0700 (PDT) X-Received: by 10.50.66.37 with SMTP id c5mr9712476igt.26.1428477110010; Wed, 08 Apr 2015 00:11:50 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id w8si8792378igl.17.2015.04.08.00.11.49 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 Apr 2015 00:11:49 -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-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Yfk9C-0003XK-Da; Wed, 08 Apr 2015 07:11:38 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Yfk9B-0003XA-Fv for edk2-devel@lists.sourceforge.net; Wed, 08 Apr 2015 07:11:37 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f171.google.com; Received: from mail-wi0-f171.google.com ([209.85.212.171]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Yfk99-0005MC-Cg for edk2-devel@lists.sourceforge.net; Wed, 08 Apr 2015 07:11:37 +0000 Received: by widjs5 with SMTP id js5so26216164wid.1 for ; Wed, 08 Apr 2015 00:11:29 -0700 (PDT) X-Received: by 10.180.74.170 with SMTP id u10mr11580898wiv.46.1428477089409; Wed, 08 Apr 2015 00:11:29 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.65]) by mx.google.com with ESMTPSA id wo10sm14210001wjb.35.2015.04.08.00.11.26 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Apr 2015 00:11:28 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Wed, 8 Apr 2015 09:11:00 +0200 Message-Id: <1428477061-1768-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1428477061-1768-1-git-send-email-ard.biesheuvel@linaro.org> References: <1428477061-1768-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: 1Yfk99-0005MC-Cg Subject: [edk2] [PATCH v3 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.215.49 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 Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc | 4 ++-- ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc | 4 ++-- ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c | 10 ++++++++++ ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc index cad7353442f7..0b9a46f0197f 100644 --- a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +++ b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc @@ -103,8 +103,8 @@ gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000 gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000 - # Size of the region used by UEFI in permanent memory (Reserved 64MB) - gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000 + # Size of the region used by UEFI in permanent memory (Reserved 16MB) + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x01000000 # # ARM Pcds diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc index d01b3e9c8494..71869845a857 100644 --- a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc +++ b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc @@ -89,8 +89,8 @@ gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000 - # Size of the region used by UEFI in permanent memory (Reserved 64MB) - gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000 + # Size of the region used by UEFI in permanent memory (Reserved 16MB) + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x01000000 # # ARM Virtual Architectural Timer 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