From patchwork Wed Apr 8 07:11:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46870 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 D29F0218CB for ; Wed, 8 Apr 2015 07:11:55 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf3113794wgt.1 for ; Wed, 08 Apr 2015 00:11:55 -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=9LPg/Ne+jGfvd4PXwNdvlys3LHH+KxVrbIlwaLt+UEc=; b=PqFMPddFu7oCyvyCS9hpeD0iWg+IEz+Q0cACJ88XZj1OAGMsjPOlKzIvvAPV3CyCyb iI5566Czh5I4rR3mhWMkYPpjTx0dFjs8wYHqU8wHz2XexCkzscYecU8L6UOsWWGHbwmB oLxnz67TPxYj70w5UQLe6mxZK6Cz/78wUAqnxIe7Km2jg7Rwtt9Ow0mkFo3Ac/0AqjHJ stv57KI/2Gu6DNivmzTFePLwOMvg94+tRSi8Wmm14QVhgihK+u1tdbXVR6cX6pDnmTnR klrO1PMxkn/pdQAR27+9dc27JBHRbWQEe6vDHXvo3VLxXoPDik45zuz8iwYwZGE4CI9k stlQ== X-Gm-Message-State: ALoCoQle9Xk69JybYIF+whKxzPAiqrSukHV6fog3/gHFa0nS6LBqVqMhGrz861AzwUVH86i5g6uS X-Received: by 10.180.106.136 with SMTP id gu8mr1071533wib.6.1428477115163; Wed, 08 Apr 2015 00:11:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.70 with SMTP id le6ls140854lac.50.gmail; Wed, 08 Apr 2015 00:11:54 -0700 (PDT) X-Received: by 10.152.2.105 with SMTP id 9mr21462853lat.16.1428477114960; Wed, 08 Apr 2015 00:11:54 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id uf6si7987367lac.168.2015.04.08.00.11.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 00:11:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by laat2 with SMTP id t2so52124696laa.1 for ; Wed, 08 Apr 2015 00:11:54 -0700 (PDT) X-Received: by 10.152.28.5 with SMTP id x5mr21425230lag.112.1428477114845; Wed, 08 Apr 2015 00:11:54 -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 l1csp878187lbt; Wed, 8 Apr 2015 00:11:54 -0700 (PDT) X-Received: by 10.50.23.105 with SMTP id l9mr4537619igf.13.1428477113181; Wed, 08 Apr 2015 00:11:53 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id i5si8789135igt.36.2015.04.08.00.11.49 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 Apr 2015 00:11:53 -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 1Yfk9G-0005rH-CU; Wed, 08 Apr 2015 07:11:42 +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 1Yfk9F-0005rC-1q for edk2-devel@lists.sourceforge.net; Wed, 08 Apr 2015 07:11:41 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.180 as permitted sender) client-ip=209.85.212.180; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f180.google.com; Received: from mail-wi0-f180.google.com ([209.85.212.180]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Yfk9E-0005vc-3P for edk2-devel@lists.sourceforge.net; Wed, 08 Apr 2015 07:11:41 +0000 Received: by wiaa2 with SMTP id a2so46657352wia.0 for ; Wed, 08 Apr 2015 00:11:34 -0700 (PDT) X-Received: by 10.180.104.33 with SMTP id gb1mr11466083wib.33.1428477094152; Wed, 08 Apr 2015 00:11:34 -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.29 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Apr 2015 00:11:33 -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:01 +0200 Message-Id: <1428477061-1768-6-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: 1Yfk9E-0005vc-3P Subject: [edk2] [PATCH v3 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.215.51 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 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);