From patchwork Tue Oct 15 15:24:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 21044 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C64E620D9F for ; Tue, 15 Oct 2013 15:24:30 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id a41sf18462854yho.5 for ; Tue, 15 Oct 2013 08:24:30 -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:date:from:to:cc:subject:message-id :mime-version:user-agent:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-disposition; bh=31fcdMGSc0ui/Fjd0C2ZmvOedhvfsnTiVg9O2xIq8ps=; b=T1vPaF9FpY5hPWhqcJo8GsxpdUs0r+o6JtqD2ysz3xdqxGYo3MBg3tNrx+kBjS99w8 nqUb9TkZ3AqxUQcFcO1fBX1il7myPKC9StTwV0gwQQnek0HdyYN5AuGymV8OIBRbof6W bU8tHYoSu77HEghXejP9j/t4fhbMOmePv0jeaStOnRYMleuji8j+eAMUhTwNqbjZrGUO vT+SrAtvU/LRo6Ln/cAvvLd0YYwpSi+BXEilSvhqwQ0gfvelOrOxAZ4toZv3wqZzk7o7 NMTNZ31sNseeMXMjjlnDCVvDZSDcBmmMry1OP+2K9z+exO2XuuNJDGgOi86sEgxIVE5b i7Ug== X-Received: by 10.58.134.110 with SMTP id pj14mr4339790veb.14.1381850670240; Tue, 15 Oct 2013 08:24:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.64.68 with SMTP id m4ls146506qes.5.gmail; Tue, 15 Oct 2013 08:24:30 -0700 (PDT) X-Received: by 10.58.55.227 with SMTP id v3mr10928054vep.16.1381850670149; Tue, 15 Oct 2013 08:24:30 -0700 (PDT) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id wp10si22935060vdb.123.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Oct 2013 08:24:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id i3so5313714vbh.12 for ; Tue, 15 Oct 2013 08:24:29 -0700 (PDT) X-Gm-Message-State: ALoCoQkNVtf9DQ1A97ZXr09wUHi34SVLFtkFGFKDT9s0Z2UkblY2ZVeEp1/TTRxeIoh3ZeBpfpIE X-Received: by 10.52.230.102 with SMTP id sx6mr33847864vdc.15.1381850669926; Tue, 15 Oct 2013 08:24:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp307729vcz; Tue, 15 Oct 2013 08:24:29 -0700 (PDT) X-Received: by 10.194.119.106 with SMTP id kt10mr1700443wjb.72.1381850668087; Tue, 15 Oct 2013 08:24:28 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id yw3si27227428wjc.158.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Oct 2013 08:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of Dave.Martin@arm.com designates 217.140.96.21 as permitted sender) client-ip=217.140.96.21; Received: from localhost.localdomain (e103592.cambridge.arm.com [10.1.203.142]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id r9FFOMoA023992; Tue, 15 Oct 2013 16:24:22 +0100 Date: Tue, 15 Oct 2013 16:24:22 +0100 From: Dave Martin To: Taras Kondratiuk Cc: "linux-arm-kernel@lists.infradead.org" , Patch Tracking , Steve McIntyre , Linaro Networking , Dave Martin , Will Deacon , Russell King , Linaro Kernel Subject: Re: [RFC PATCH] ARM: kexec: Assemble relocate code in ARM mode Message-ID: <20131015152422.GC2312@localhost.localdomain> MIME-Version: 1.0 User-Agent: Mutt/1.5.21 (2010-09-15) X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-Disposition: inline On Thu, Oct 10, 2013 at 11:36:08PM +0300, Taras Kondratiuk wrote: > On 10 October 2013 17:12, Dave Martin wrote: > > On Wed, Oct 09, 2013 at 11:57:03PM +0300, Taras Kondratiuk wrote: > >> In Thumb2 kernel (CONFIG_THUMB2_KERNEL) kexec's relocate code is assembled > >> in Thumb2 mode, but cpu_v7_reset() jumps to this code in ARM state, > >> because its address is page aligned and has 0 in LSB. > >> > >> Assemble this code in ARM mode to fix the issue. > > > > I think the actual issue here is that relocate_new_kernel is not properly > > annotated as a function symbol. > > > > Can you remove the explicit label declaration and try the following: > > > > #include > > > > ENTRY(relocate_new_kernel) > > > > /* body of relocate_new_kernel */ > > > > ENDPROC(relocate_new_kernel) > > > > > > Without this, the linker will treat it as a random pointer to data and > > never set the Thumb bit. > > > > This fails in precisely the same was as an ordinary function call > > would fail if the destination function doesn't have the needed > > annotation. > > > > > > There should be no need to switch to ARM if the kernel is just jumping > > to itself... > > I think it won't help, because here is no direct jump to this label. > This code gets copied to a new page and jump is done to the beginning > of that page. Ah, right. I think that the fncpy() function should work. This is for the precise purpsoe of copying a function body from one place to another, while reatining the Thumb bit. I have to disappear early to today, but I'll try and follow up. Currently, I have the following, but I've not been able to test it yet. If you'd like to give it a try, that would be much appreciated. Cheers ---Dave >From 94925667e650202e1baf74e1ff223671d316401d Mon Sep 17 00:00:00 2001 From: Dave Martin Date: Tue, 15 Oct 2013 11:48:46 +0100 Subject: [PATCH] ARM: kexec: Use the right ISA for relocate_new_kernel Copying a function with memcpy() and then trying to execute the result isn't portable to Thumb. This patch modifies the kexec soft restart code to copy its assembler trampoline relocate_new_kernel() using fncpy() instead, so that relocate_new_kernel can be in the same ISA as the rest of the kernel without problems. Signed-off-by: Dave Martin --- arch/arm/kernel/machine_kexec.c | 20 +++++++++----------- arch/arm/kernel/relocate_kernel.S | 7 ++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c index 57221e3..ce135b3 100644 --- a/arch/arm/kernel/machine_kexec.c +++ b/arch/arm/kernel/machine_kexec.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,7 @@ #include #include -extern const unsigned char relocate_new_kernel[]; +extern char relocate_new_kernel; extern const unsigned int relocate_new_kernel_size; extern unsigned long kexec_start_address; @@ -141,8 +142,9 @@ void (*kexec_reinit)(void); void machine_kexec(struct kimage *image) { unsigned long page_list; - unsigned long reboot_code_buffer_phys; void *reboot_code_buffer; + unsigned long v2p_offset; + void *entry_point; /* * This can only happen if machine_shutdown() failed to disable some @@ -154,10 +156,9 @@ void machine_kexec(struct kimage *image) page_list = image->head & PAGE_MASK; - /* we need both effective and real address here */ - reboot_code_buffer_phys = - page_to_pfn(image->control_code_page) << PAGE_SHIFT; reboot_code_buffer = page_address(image->control_code_page); + v2p_offset = (page_to_pfn(image->control_code_page) << PAGE_SHIFT) + - (unsigned long)reboot_code_buffer; /* Prepare parameters for reboot_code_buffer*/ kexec_start_address = image->start; @@ -168,16 +169,13 @@ void machine_kexec(struct kimage *image) /* copy our kernel relocation code to the control code page */ - memcpy(reboot_code_buffer, - relocate_new_kernel, relocate_new_kernel_size); + entry_point = fncpy(reboot_code_buffer, + &relocate_new_kernel, relocate_new_kernel_size); - - flush_icache_range((unsigned long) reboot_code_buffer, - (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE); printk(KERN_INFO "Bye!\n"); if (kexec_reinit) kexec_reinit(); - soft_restart(reboot_code_buffer_phys); + soft_restart((unsigned long)entry_point + v2p_offset); } diff --git a/arch/arm/kernel/relocate_kernel.S b/arch/arm/kernel/relocate_kernel.S index d0cdedf..1492930 100644 --- a/arch/arm/kernel/relocate_kernel.S +++ b/arch/arm/kernel/relocate_kernel.S @@ -2,11 +2,11 @@ * relocate_kernel.S - put the kernel image in place to boot */ +#include #include - .globl relocate_new_kernel -relocate_new_kernel: - + .align 3 +ENTRY(relocate_new_kernel) ldr r0,kexec_indirection_page ldr r1,kexec_start_address @@ -59,6 +59,7 @@ relocate_new_kernel: ldr r2,kexec_boot_atags ARM( mov pc, lr ) THUMB( bx lr ) +ENDPROC(relocate_new_kernel) .align