From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85724C433DB for ; Mon, 1 Feb 2021 20:09:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3389964DDB for ; Mon, 1 Feb 2021 20:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232999AbhBAUJR (ORCPT ); Mon, 1 Feb 2021 15:09:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233119AbhBAUIW (ORCPT ); Mon, 1 Feb 2021 15:08:22 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A649C061573 for ; Mon, 1 Feb 2021 12:07:42 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id g10so2087142eds.2 for ; Mon, 01 Feb 2021 12:07:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xT/3mkH8sZ5OMfp1FrmkjDWgvg0SwuKeYxgJNZyLoDo=; b=cRDm4sqbq+CB028UtpL9i+6peUdZrtOaLzh6zqA7cNyFKJe/OmDQqS0Jtlx4Cm4NQd VqZi0wWcshldrmTo7yT2BYRHczjl8Nb8tjP06gcKRIyfpSntr97OLBU1Q6y3MQM2cFT4 zyrQBVbErTTFINDtfJXJsS3jfoAqcmB2tzEJs6z0QZ/Fq60b4nPRNVioQePXajIegxKb Uj31QNlhF7HFi1dNGhOPekCCOR7LJxWpcJpNyP90Wdol1ZyRwNXKtRWzWQOpa+K54d/l CW+29X0YJ9v/yyJPmT1S9mBTz2hFC4Rs6qI9W1SiMPFfSk9d7osvMi60cgkpMYbSLInF Htrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xT/3mkH8sZ5OMfp1FrmkjDWgvg0SwuKeYxgJNZyLoDo=; b=dLCe1uHPKDGAg1NwyEsAX4Mf1S/EMSMyK/pqjazaXrPLqspyM6AEso+yfzj+ZeQNHr R5BBcVR4CNnjcX0Ew3h1LWA5F9MLz1hiIo61MGAvZtTso/9ClZZsXzOhY+KgdsQ+av2P KdVo8QfsJYvKD9Ujl9yT7dlWE7/hchZB2+mo08w+OA26glXBn0zzgc+P4kzfBN2+RqoE SEWhq0zL9f3ixoQ3GQnCclLBMOQXlWGqvku7J1CWl3u4eGwsZrTYkpI4lqM8vS5D4m+5 PXROtjcpKGhhUnrbfn6km7fOnDyEaxpr8dAwRv0oCvbsjLmCVODTUdnmWL8sllqQLn/S ULSg== X-Gm-Message-State: AOAM533fJ9aJ42NF9hiFE/4lVXlW9GZe3xnLGTjJywQm4qBecoQcHuxt OifjdcTKLWak4BnS4XsrQco= X-Google-Smtp-Source: ABdhPJxObczU54wNLvoKrAVCnifyU+i0VODlb6DbXR9M+yfM/5RAfMXmS8PR+HB8TWLOiz0X1vXxbg== X-Received: by 2002:aa7:d4c8:: with SMTP id t8mr21496147edr.199.1612210061322; Mon, 01 Feb 2021 12:07:41 -0800 (PST) Received: from p4 (net-93-70-85-165.cust.vodafonedsl.it. [93.70.85.165]) by smtp.gmail.com with ESMTPSA id di28sm9128182edb.71.2021.02.01.12.07.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Feb 2021 12:07:40 -0800 (PST) Date: Mon, 1 Feb 2021 20:07:37 +0000 From: Giancarlo Ferrari To: Russell King - ARM Linux admin Cc: Mark Rutland , linux-kernel@vger.kernel.org, penberg@kernel.org, geert@linux-m68k.org, linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, rppt@kernel.org, giancarlo.ferrari@nokia.com Subject: Re: [PATCH] ARM: kexec: Fix panic after TLB are invalidated Message-ID: <20210201200734.GC15399@p4> References: <1612140296-12546-1-git-send-email-giancarlo.ferrari89@gmail.com> <20210201124720.GA66060@C02TD0UTHF1T.local> <20210201130344.GF1463@shell.armlinux.org.uk> <20210201135714.GB66060@C02TD0UTHF1T.local> <20210201160838.GH1463@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210201160838.GH1463@shell.armlinux.org.uk> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, Feb 01, 2021 at 04:08:38PM +0000, Russell King - ARM Linux admin wrote: > On Mon, Feb 01, 2021 at 01:57:14PM +0000, Mark Rutland wrote: > > We could simplify this slightly if we moved the kexec_& variables into a > > struct (using asm-offset KEXEC_VAR_* offsets and a KEXEC_VAR_SIZE region > > reserved in the asm), then here we could do something like: > > > > static struct kexec_vars *kexec_buffer_vars(void *buffer) > > { > > unsigned long code = ((unisigned long)relocate_new_kernel) & ~1; > > unsigned long vars - (unsigned long)relocate_vars; > > unsigned long offset = vars - code; > > > > return buffer + offset; > > } > > > > ... and in machine_kexec() do: > > > > struct kexec_vars *kv = kexec_buffer_vars(reboot_code_buffer); > > > > kv->start_address = image->start; > > kv->indirection_page = page_list; > > kv->mach_type = machine-arch_type; > > kv->boot_atags = arch.kernel_r2; > > > > ... if that looks any better to you? > > Something like this? > > diff --git a/arch/arm/include/asm/kexec-internal.h b/arch/arm/include/asm/kexec-internal.h > new file mode 100644 > index 000000000000..ecc2322db7aa > --- /dev/null > +++ b/arch/arm/include/asm/kexec-internal.h > @@ -0,0 +1,12 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ARM_KEXEC_INTERNAL_H > +#define _ARM_KEXEC_INTERNAL_H > + > +struct kexec_relocate_data { > + unsigned long kexec_start_address; > + unsigned long kexec_indirection_page; > + unsigned long kexec_mach_type; > + unsigned long kexec_r2; > +}; > + > +#endif > diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c > index a1570c8bab25..be8050b0c3df 100644 > --- a/arch/arm/kernel/asm-offsets.c > +++ b/arch/arm/kernel/asm-offsets.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -170,5 +171,9 @@ int main(void) > DEFINE(MPU_RGN_PRBAR, offsetof(struct mpu_rgn, prbar)); > DEFINE(MPU_RGN_PRLAR, offsetof(struct mpu_rgn, prlar)); > #endif > + DEFINE(KEXEC_START_ADDR, offsetof(struct kexec_relocate_data, kexec_start_address)); > + DEFINE(KEXEC_INDIR_PAGE, offsetof(struct kexec_relocate_data, kexec_indirection_page)); > + DEFINE(KEXEC_MACH_TYPE, offsetof(struct kexec_relocate_data, kexec_mach_type)); > + DEFINE(KEXEC_R2, offsetof(struct kexec_relocate_data, kexec_r2)); > return 0; > } > diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c > index 5d84ad333f05..2b09dad7935e 100644 > --- a/arch/arm/kernel/machine_kexec.c > +++ b/arch/arm/kernel/machine_kexec.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -22,11 +23,6 @@ > extern void relocate_new_kernel(void); > extern const unsigned int relocate_new_kernel_size; > > -extern unsigned long kexec_start_address; > -extern unsigned long kexec_indirection_page; > -extern unsigned long kexec_mach_type; > -extern unsigned long kexec_boot_atags; > - > static atomic_t waiting_for_crash_ipi; > > /* > @@ -159,6 +155,7 @@ void (*kexec_reinit)(void); > void machine_kexec(struct kimage *image) > { > unsigned long page_list, reboot_entry_phys; > + struct kexec_relocate_data *data; > void (*reboot_entry)(void); > void *reboot_code_buffer; > > @@ -174,18 +171,17 @@ void machine_kexec(struct kimage *image) > > reboot_code_buffer = page_address(image->control_code_page); > > - /* Prepare parameters for reboot_code_buffer*/ > - set_kernel_text_rw(); > - kexec_start_address = image->start; > - kexec_indirection_page = page_list; > - kexec_mach_type = machine_arch_type; > - kexec_boot_atags = image->arch.kernel_r2; > - > /* copy our kernel relocation code to the control code page */ > reboot_entry = fncpy(reboot_code_buffer, > &relocate_new_kernel, > relocate_new_kernel_size); > > + data = reboot_code_buffer + relocate_new_kernel_size; > + data->kexec_start_address = image->start; > + data->kexec_indirection_page = page_list; > + data->kexec_mach_type = machine_arch_type; > + data->kexec_r2 = image->arch.kernel_r2; > + > /* get the identity mapping physical address for the reboot code */ > reboot_entry_phys = virt_to_idmap(reboot_entry); > > diff --git a/arch/arm/kernel/relocate_kernel.S b/arch/arm/kernel/relocate_kernel.S > index 72a08786e16e..218d524360fc 100644 > --- a/arch/arm/kernel/relocate_kernel.S > +++ b/arch/arm/kernel/relocate_kernel.S > @@ -5,14 +5,16 @@ > > #include > #include > +#include > #include > > .align 3 /* not needed for this code, but keeps fncpy() happy */ > > ENTRY(relocate_new_kernel) > > - ldr r0,kexec_indirection_page > - ldr r1,kexec_start_address > + adr r7, relocate_new_kernel_end > + ldr r0, [r7, #KEXEC_INDIR_PAGE] > + ldr r1, [r7, #KEXEC_START_ADDR] > > /* > * If there is no indirection page (we are doing crashdumps) > @@ -57,34 +59,16 @@ ENTRY(relocate_new_kernel) > > 2: > /* Jump to relocated kernel */ > - mov lr,r1 > - mov r0,#0 > - ldr r1,kexec_mach_type > - ldr r2,kexec_boot_atags > - ARM( ret lr ) > - THUMB( bx lr ) > - > - .align > - > - .globl kexec_start_address > -kexec_start_address: > - .long 0x0 > - > - .globl kexec_indirection_page > -kexec_indirection_page: > - .long 0x0 > - > - .globl kexec_mach_type > -kexec_mach_type: > - .long 0x0 > - > - /* phy addr of the atags for the new kernel */ > - .globl kexec_boot_atags > -kexec_boot_atags: > - .long 0x0 > + mov lr, r1 > + mov r0, #0 > + ldr r1, [r7, #KEXEC_MACH_TYPE] > + ldr r2, [r7, #KEXEC_R2] > + ARM( ret lr ) > + THUMB( bx lr ) > > ENDPROC(relocate_new_kernel) > > + .align 3 Nice. Why we should align 3 ? For the fncpy I suppose. > relocate_new_kernel_end: > > .globl relocate_new_kernel_size > > -- > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! I don't know now how to proceed now, as you (Mark and you) do completely the patch. You see is my first kernel patch submission :) . Thanks, GF