From patchwork Mon Mar 30 19:13:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46532 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ACB4F214C7 for ; Mon, 30 Mar 2015 19:14:51 +0000 (UTC) Received: by lbbug6 with SMTP id ug6sf22046492lbb.3 for ; Mon, 30 Mar 2015 12:14:50 -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=IOxJXWb7l6/q4jMxOfQsryfxC/VQDYlF/dyjzAYsJ68=; b=ESYq5EaW7fndQqkYTJPhYTYMd9KPU+NEooc5YkP/XanSbGjWyUF/8aK6EX8vJz1iuy JCqQocFntPUE7ncAoBTAjpFhzTn/AqqDkgt+sLxfl6dYf0NuehmCXyXmob3s5zvO1GlP N+Be4L7OwJJaY0edvEKbTLhm9cC2tZZzeT+Ddf1UrzmSNkxG9ou7091Bg7x3mrw54ccz 5ftu9oK9mE+5eg3uALWNZtQFyTynkCMy07p7BtXRHf4l8mse7YxurEozBt4tliziZFKl APBLdWPxKlrJxsUOdWsQ/gJJz0oU5SBcmyqPxLCMXyuaFIf0HnWQp5lg/bhO7QScPdz0 5w1g== X-Gm-Message-State: ALoCoQnNv/wuPuxYtXjPaxcIofmr5N6k+jr1Eyzo9jc0GxNKm9PgKlEKRNTVF/xPRn/7NIR2T0sh X-Received: by 10.180.126.37 with SMTP id mv5mr4016316wib.3.1427742890285; Mon, 30 Mar 2015 12:14:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.206 with SMTP id l14ls140978laa.16.gmail; Mon, 30 Mar 2015 12:14:50 -0700 (PDT) X-Received: by 10.152.10.231 with SMTP id l7mr1937045lab.35.1427742889999; Mon, 30 Mar 2015 12:14:49 -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 b8si7641931lae.45.2015.03.30.12.14.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 12:14:49 -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 labe2 with SMTP id e2so111560891lab.3 for ; Mon, 30 Mar 2015 12:14:49 -0700 (PDT) X-Received: by 10.112.162.232 with SMTP id yd8mr1303638lbb.41.1427742889892; Mon, 30 Mar 2015 12:14:49 -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 k9csp1337526lbq; Mon, 30 Mar 2015 12:14:48 -0700 (PDT) X-Received: by 10.43.181.199 with SMTP id pj7mr40059440icc.16.1427742888189; Mon, 30 Mar 2015 12:14:48 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id m3si9738973ige.4.2015.03.30.12.14.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Mar 2015 12:14:48 -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 1Ycf8v-0004Ks-0t; Mon, 30 Mar 2015 19:14:37 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ycf8t-0004Kl-Uc for edk2-devel@lists.sourceforge.net; Mon, 30 Mar 2015 19:14:35 +0000 Received-SPF: pass (sog-mx-4.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-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Ycf8s-0000Va-52 for edk2-devel@lists.sourceforge.net; Mon, 30 Mar 2015 19:14:35 +0000 Received: by wgra20 with SMTP id a20so185248182wgr.3 for ; Mon, 30 Mar 2015 12:14:28 -0700 (PDT) X-Received: by 10.180.80.101 with SMTP id q5mr25743042wix.83.1427742868141; Mon, 30 Mar 2015 12:14:28 -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.25 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Mar 2015 12:14:27 -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:54 +0200 Message-Id: <1427742834-24566-4-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: 1Ycf8s-0000Va-52 Subject: [edk2] [PATCH v2 3/3] 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 we make with the caches off (such as applying the ELF relocations) will not suddenly become invisible once we turn the caches on. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- .../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);