From patchwork Thu Apr 9 11:28:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46942 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D4B1A21416 for ; Thu, 9 Apr 2015 11:29:37 +0000 (UTC) Received: by lbcne10 with SMTP id ne10sf26060010lbc.1 for ; Thu, 09 Apr 2015 04:29:36 -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=AHE+neLHq+bp+sCTcgjMhXTtUtJucGn6mfR7RejDma4=; b=lz6Q7RvTLKpElagkakrMtXDPY85DWu2EBhZ3iy1p3PsILrD4+hL/hobNx+r/jzkmXk jOM6Q1x8mB3WCa9KA867gvgTilNHgpDSTF5HFE60oO2fUeqy+8OF3MY9eG3QUY3suJgS olcwvm6s0RTKtGX7F3TklQ5WhfFjvnjifDpc1I+24s9XyMlqFVXDC8NZar3VCfF68Nr4 7s36M6ZAIU2e3CjTP70cBNAVIHl7eG63NyraL9dW6TJ1Xdh7xMEIEDVHR+eBcGN0J2hK X6MJh8anhtHt7HwUgXLd5Q/qN3aeVbzZvU4XTX1R0vAwJZYd1AziX5SFwCYVXCZn2ZOP ETQw== X-Gm-Message-State: ALoCoQlC2Lq5JH9QeIGcxrViOoItnA6nqN61DI0LMsF1X4QFcb68+SXdk5qD6T5V+eZKWpkMPsUF X-Received: by 10.180.101.39 with SMTP id fd7mr512196wib.0.1428578976802; Thu, 09 Apr 2015 04:29:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.68 with SMTP id la4ls281602lab.25.gmail; Thu, 09 Apr 2015 04:29:36 -0700 (PDT) X-Received: by 10.152.37.40 with SMTP id v8mr4252371laj.123.1428578976635; Thu, 09 Apr 2015 04:29:36 -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 ak2si1386473lbc.129.2015.04.09.04.29.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 04:29:36 -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 lbbqq2 with SMTP id qq2so79923773lbb.3 for ; Thu, 09 Apr 2015 04:29:36 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr20817472lbc.32.1428578976531; Thu, 09 Apr 2015 04:29:36 -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 l1csp411804lbt; Thu, 9 Apr 2015 04:29:35 -0700 (PDT) X-Received: by 10.107.8.199 with SMTP id h68mr1601445ioi.48.1428578969957; Thu, 09 Apr 2015 04:29:29 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id qs1si2224783igb.28.2015.04.09.04.29.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Apr 2015 04:29:29 -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-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YgAe9-0002NK-JN; Thu, 09 Apr 2015 11:29:21 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YgAe8-0002N8-2n for edk2-devel@lists.sourceforge.net; Thu, 09 Apr 2015 11:29:20 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f175.google.com; Received: from mail-wi0-f175.google.com ([209.85.212.175]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YgAe6-0007Tw-UN for edk2-devel@lists.sourceforge.net; Thu, 09 Apr 2015 11:29:20 +0000 Received: by wizk4 with SMTP id k4so88488759wiz.1 for ; Thu, 09 Apr 2015 04:29:13 -0700 (PDT) X-Received: by 10.194.208.229 with SMTP id mh5mr27646451wjc.108.1428578952926; Thu, 09 Apr 2015 04:29:12 -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.11 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Apr 2015 04:29:12 -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:52 +0200 Message-Id: <1428578932-24079-6-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: 1YgAe6-0007Tw-UN Subject: [edk2] [PATCH v4 5/5] ArmVirtualizationPkg: Xen: shuffle init order to deal with incoherency 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 In order to prevent memory corruption issues caused by the fact that, under virtualization, the guest is incoherent with the hypervisor's view of memory until it enables its caches and MMU, this patch reshuffles the init sequence so that the Xen shared memory regions are not touched before the caches and MMU are enabled. In addition, the loaded image itself is invalidated by virtual address, to ensure that any runtime changes (such as the applied relocations) will not suddenly become invisible once we turn the caches on. Contributed-under: TianoCore Contribution Agreement 1.0 Reviewed-By: Olivier Martin Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 1 + ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf index 86cf870b79ac..16023382a679 100755 --- a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf +++ b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf @@ -55,6 +55,7 @@ PrePiHobListPointerLib PlatformPeiLib MemoryInitPeiLib + CacheMaintenanceLib [Ppis] gArmMpCoreInfoPpiGuid diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c index 0772805890f2..f9ad37427217 100755 --- a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c +++ b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -102,12 +103,6 @@ PrePiMain ( // Initialize the architecture specific bits ArchInitialize (); - // Initialize the Serial Port - SerialPortInitialize (); - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r", - (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__); - SerialPortWrite ((UINT8 *) Buffer, CharCount); - // Declare the PI/UEFI memory region HobList = HobConstructor ( (VOID*)UefiMemoryBase, @@ -117,10 +112,23 @@ PrePiMain ( ); PrePeiSetHobList (HobList); + // + // Ensure that the loaded image is invalidated in the caches, so that any + // modifications we made with the caches and MMU off (such as the applied + // relocations) don't become invisible once we turn them on. + // + InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize)); + // Initialize MMU and Memory HOBs (Resource Descriptor HOBs) Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); ASSERT_EFI_ERROR (Status); + // Initialize the Serial Port + SerialPortInitialize (); + CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r", + (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + // Create the Stacks HOB (reserve the memory for all stacks) StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize); BuildStackHob (StacksBase, StacksSize);