From patchwork Mon Mar 30 19:13:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46531 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 221CE214C7 for ; Mon, 30 Mar 2015 19:14:46 +0000 (UTC) Received: by wixm2 with SMTP id m2sf21656422wix.0 for ; Mon, 30 Mar 2015 12:14: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: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=aXeGxU2J85skEo55H2eoSAvDAcqJn731FjBFVhZzmuE=; b=Pm5aJ/NOSnxgodASYXAevh4wNPwtP12HzcLsCzKTDggwHZer0hggtWcTMRcv0oS1jR h5fAkQhZKItEtzZ+QRuixjacuy3jN6EItsSanjTJkikGTeF3NpCSc813j7N5PR2RTpuQ kzv9TThG5pC2QU1Hw6UUajgN/FqNj2CiBcUjxj2GeUdRaTECI9X6lWNSXteUjDK+6TVk AReQoxJgk8dvSZp0LI/BP6wkPNc6wdZEdGhtlZJof8GUiDymcpQcX7cMFB3KoxMtCWvY KA69U1S2MH1zf4ECDjoZP5UKtp6eqJmEvJfDE0lsQJaMfr2R0wofSnQGK6Aw9gkbIl+x uC2g== X-Gm-Message-State: ALoCoQmNDT+MYIiGop/IcnzQYkBx+QxoeTNoHlFyxvmtLN37OcgpRhkN/pErC58CVnDZSGBBqPSw X-Received: by 10.180.97.200 with SMTP id ec8mr4022340wib.5.1427742885123; Mon, 30 Mar 2015 12:14:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.70 with SMTP id v6ls614790laz.2.gmail; Mon, 30 Mar 2015 12:14:44 -0700 (PDT) X-Received: by 10.152.234.42 with SMTP id ub10mr7418916lac.55.1427742884860; Mon, 30 Mar 2015 12:14:44 -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 ti8si955405lbb.149.2015.03.30.12.14.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 12:14:44 -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 lbbug6 with SMTP id ug6so102196088lbb.3 for ; Mon, 30 Mar 2015 12:14:44 -0700 (PDT) X-Received: by 10.112.185.66 with SMTP id fa2mr27382270lbc.117.1427742884716; Mon, 30 Mar 2015 12:14:44 -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.57.201 with SMTP id k9csp1337485lbq; Mon, 30 Mar 2015 12:14:43 -0700 (PDT) X-Received: by 10.42.226.4 with SMTP id iu4mr7193421icb.51.1427742883085; Mon, 30 Mar 2015 12:14:43 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id x189si9760973iod.25.2015.03.30.12.14.42 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Mar 2015 12:14:43 -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 1Ycf8s-0003nd-0K; Mon, 30 Mar 2015 19:14:34 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ycf8q-0003nO-4h for edk2-devel@lists.sourceforge.net; Mon, 30 Mar 2015 19:14:32 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.54 as permitted sender) client-ip=74.125.82.54; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f54.google.com; Received: from mail-wg0-f54.google.com ([74.125.82.54]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Ycf8o-0003Wz-U1 for edk2-devel@lists.sourceforge.net; Mon, 30 Mar 2015 19:14:32 +0000 Received: by wgbgs4 with SMTP id gs4so95051911wgb.0 for ; Mon, 30 Mar 2015 12:14:25 -0700 (PDT) X-Received: by 10.180.83.136 with SMTP id q8mr8804391wiy.39.1427742864901; Mon, 30 Mar 2015 12:14:24 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.130]) by mx.google.com with ESMTPSA id vq9sm17022823wjc.6.2015.03.30.12.14.19 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Mar 2015 12:14:24 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, olivier.martin@arm.com, leif.lindholm@linaro.org, roy.franz@linaro.org, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, lersek@redhat.com, julien.grall@linaro.org Date: Mon, 30 Mar 2015 21:13:53 +0200 Message-Id: <1427742834-24566-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427742834-24566-1-git-send-email-ard.biesheuvel@linaro.org> References: <1427742834-24566-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 -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1Ycf8o-0003Wz-U1 Subject: [edk2] [PATCH v2 2/3] 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 Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc | 6 ++++-- ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationXen.dsc | 4 ++-- .../ArmVirtualizationMemoryInitPeiLib.c | 10 ++++++++++ .../ArmVirtualizationMemoryInitPeiLib.inf | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc index 07ae63ada7c0..0b9a46f0197f 100644 --- a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc +++ b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc @@ -39,6 +39,8 @@ ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf [LibraryClasses.common] + MemoryInitPeiLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf + # Virtio Support VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf @@ -101,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 b24d0969e021..31ef5c43f44e 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