From patchwork Wed Mar 19 15:13:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 3851071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D3E9ABF540 for ; Wed, 19 Mar 2014 15:14:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECE0120176 for ; Wed, 19 Mar 2014 15:14:05 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C19F020131 for ; Wed, 19 Mar 2014 15:14:04 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQIBr-0003bw-8E; Wed, 19 Mar 2014 15:13:59 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQIBo-0006TW-L9; Wed, 19 Mar 2014 15:13:56 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQIBk-0006Sv-7D for linux-arm-kernel@lists.infradead.org; Wed, 19 Mar 2014 15:13:53 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2JFDLO4014592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Mar 2014 11:13:21 -0400 Received: from [10.3.113.16] ([10.3.113.16]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2JFDKAx000376; Wed, 19 Mar 2014 11:13:20 -0400 Message-ID: <1395241998.2967.52.camel@deneb.redhat.com> Subject: Re: [PATCH v2 11/15] arm64: add EFI stub From: Mark Salter To: Catalin Marinas Date: Wed, 19 Mar 2014 11:13:18 -0400 In-Reply-To: <20140319105706.GE2214@arm.com> References: <1394750828-16351-1-git-send-email-leif.lindholm@linaro.org> <1394750828-16351-12-git-send-email-leif.lindholm@linaro.org> <20140318120919.GG13200@arm.com> <1395153629.2967.10.camel@deneb.redhat.com> <20140318182826.GC20497@arm.com> <1395178831.2967.29.camel@deneb.redhat.com> <20140319105706.GE2214@arm.com> Organization: Red Hat, Inc Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140319_111352_391870_2E18F75F X-CRM114-Status: GOOD ( 26.97 ) X-Spam-Score: -6.9 (------) Cc: "linux-efi@vger.kernel.org" , Ard Biesheuvel , "linux-kernel@vger.kernel.org" , Leif Lindholm , "roy.franz@linaro.org" , "matt.fleming@intel.com" , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, 2014-03-19 at 10:57 +0000, Catalin Marinas wrote: > On Tue, Mar 18, 2014 at 09:40:31PM +0000, Mark Salter wrote: > > On Tue, 2014-03-18 at 18:28 +0000, Catalin Marinas wrote: > > > If UEFI doesn't handle the caches, the only thing left to EFI_STUB is to > > > flush by MVA. We don't need to flush the whole DRAM (and I would even > > > recommend it) but at least the relevant kernel code/data touched with > > > the MMU disabled. > > > > So, it goes like this: > > > > 1) UEFI calls stub with MMU/Caches on. Stub/kernel can be anywhere. > > 2) Stub runs and relocates kernel to the desired runtime location > > but continues to execute from wherever UEFI loaded it until just > > after ExitBootServices(). > > 3) After ExitBootServices, efi_entry() returns relocated entry point > > for kernel to efi_stub_entry() in efi-entry.S where the Dcache and > > MMU are turned off, the __flush_dcache_all is called, then the > > code jumps to the kernel proper entry point. > > > > It isn't clear to me if UEFI does cache flushing at ExitBootServices > > time, but even so, at least stack use will get cached between then and > > the kernel entry point. The stub could conceivably get its hands on the > > EFI memmap and invalidate dcache using address ranges from UEFI memory > > descriptors so maybe that is the way we should do it. > > I think the stub just needs to flush the relocated kernel image, ensure > it is sync with the memory. Additional flushing can be done by the > kernel for bits it writes (like page tables, code patching etc). We can > enter the kernel with the SCTLR.I bit set, so it can allocate in an > unified cache already and D-cache maintenance would be needed anyway. How about this? diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 83bfb72..ed480b2 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -52,11 +52,19 @@ ENTRY(efi_stub_entry) * efi_entry() will have relocated the kernel image if necessary * and we return here with device tree address in x0 and the kernel * entry point stored at *image_addr. Save those values in registers - * which are preserved by __flush_dcache_all. + * which are callee preserved. */ - ldr x1, [sp, #16] mov x20, x0 - mov x21, x1 + ldr x0, [sp, #16] + mov x21, x0 + + adrp x1, _text + add x1, x1, #:lo12:_text + adrp x2, _edata + add x2, x2, #:lo12:_edata + sub x1, x2, x1 + + bl __flush_dcache_area /* Turn off Dcache and MMU */ mrs x0, CurrentEL @@ -76,8 +84,6 @@ ENTRY(efi_stub_entry) msr sctlr_el1, x0 isb 2: - bl __flush_dcache_all - /* Jump to real entry point */ mov x0, x20 mov x1, xzr