Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2758419pxj; Mon, 31 May 2021 10:01:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB0v1ohI29JtYqpAwk+RT+lAo68WazpayFcTHuWKAuhk2hfOkwzwU7SCiu+kt/VmvWjZRV X-Received: by 2002:a92:b506:: with SMTP id f6mr5865999ile.148.1622480491831; Mon, 31 May 2021 10:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622480491; cv=none; d=google.com; s=arc-20160816; b=kOOnuTcGVQTYFEyJ5cwHTKn+DcN6wmZqQbwG5dcxtBMqHmKev+qhE6V6/UTXVxJ2MZ OcNatffUtW+nH5odC40EklLk2S+uP+rp5eyJETYyAnLQL7naG59hQDsdT4Y3WUIpvfay 6HheUmUDY4/dKmTCwgSfYByMieG8S6GPPfieJDjkGOO/5furG3kU9cHiNkT0IO0MdF5T gLuhTs0uAGjklu5RMRaOXyfmDtsYfMFcr8qdn1vTzeI6wYU12iUuXmCPSJ36VIXWwgga OSBpqtGElXlclvi89p9CdqJw7fzaGSyRs6ZykocCKDrH9YEWWuP+x8tuc/P0aOlXeZ28 qLSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=7hvVGkNh6QOMeYEHdebj/egmT1oa4Ow/lM8hm/2y+MU=; b=dRDz4eLAKXKM0LPgI1femIrdn+Ea0ZUEvpCxXCfJXMDWey57PfkdnhEkukfpecG8QE DXTJJQuLObou8SO/QACfCkaTFSkpnbFJzbT51cOnkKqEsSqXynrSh32jKo/iQ+PbFuzF W3h6FOkQ3EA6YOgz5tYzv2qiBWL692O7C2ozKZQicU4yWyvzZLMv7JqqkY71r4CJjfS3 Z7uYldzi28vB9/2FTo7b2Aan91dAwWQ+4QCB81sckN4zbP8XyNsakns+AW0EhyfRk++1 3+jxRSZoJsFD7LRYE2Lz8gxeEL4OqGadBEY8hz5+A2b3s9GhD9SrAs5BR3unx+T4dDMC crSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si15272612jat.73.2021.05.31.10.01.18; Mon, 31 May 2021 10:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234951AbhEaRAW (ORCPT + 99 others); Mon, 31 May 2021 13:00:22 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:63429 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231177AbhEaPTL (ORCPT ); Mon, 31 May 2021 11:19:11 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id DED5240009; Mon, 31 May 2021 15:17:25 +0000 (UTC) Subject: Re: [PATCH] riscv: xip: support runtime trap patching To: Vitaly Wool , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Nicolas Pitre References: <20210531085342.17494-1-vitaly.wool@konsulko.com> From: Alex Ghiti Message-ID: <62961217-1733-eaa3-b072-cbb252620c9a@ghiti.fr> Date: Mon, 31 May 2021 17:17:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210531085342.17494-1-vitaly.wool@konsulko.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vitaly, Le 31/05/2021 ? 10:53, Vitaly Wool a ?crit?: > RISCV_ERRATA_ALTERNATIVE patches text at runtime which is currently > not possible when the kernel is executed from the flash in XIP mode. > Since runtime patching concerns only traps at the moment, let's just > have all the traps reside in RAM anyway if RISCV_ERRATA_ALTERNATIVE > is set. Thus, these functions will be patch-able even when the .text > section is in flash. > This sounds like a good fix for sifive platforms to work with XIP kernel in 5.13: did you test that it actually works on HW? > Signed-off-by: Vitaly Wool > --- > arch/riscv/kernel/traps.c | 13 +++++++++---- > arch/riscv/kernel/vmlinux-xip.lds.S | 15 ++++++++++++++- > 2 files changed, 23 insertions(+), 5 deletions(-) > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index 0721b9798595..7bc88d8aab97 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -86,8 +86,13 @@ static void do_trap_error(struct pt_regs *regs, int signo, int code, > } > } > > +#if defined (CONFIG_XIP_KERNEL) && defined (CONFIG_RISCV_ERRATA_ALTERNATIVE) > +#define __trap_section __section(".xip.traps") > +#else > +#define __trap_section > +#endif Maybe we could do something more generic. At the moment, only traps are subject to alternatives but that will likely expand: what about rather defining a section called __alternative_section? > #define DO_ERROR_INFO(name, signo, code, str) \ > -asmlinkage __visible void name(struct pt_regs *regs) \ > +asmlinkage __visible __trap_section void name(struct pt_regs *regs) \ > { \ > do_trap_error(regs, signo, code, regs->epc, "Oops - " str); \ > } > @@ -111,7 +116,7 @@ DO_ERROR_INFO(do_trap_store_misaligned, > int handle_misaligned_load(struct pt_regs *regs); > int handle_misaligned_store(struct pt_regs *regs); > > -asmlinkage void do_trap_load_misaligned(struct pt_regs *regs) > +asmlinkage void __trap_section do_trap_load_misaligned(struct pt_regs *regs) > { > if (!handle_misaligned_load(regs)) > return; > @@ -119,7 +124,7 @@ asmlinkage void do_trap_load_misaligned(struct pt_regs *regs) > "Oops - load address misaligned"); > } > > -asmlinkage void do_trap_store_misaligned(struct pt_regs *regs) > +asmlinkage void __trap_section do_trap_store_misaligned(struct pt_regs *regs) > { > if (!handle_misaligned_store(regs)) > return; > @@ -146,7 +151,7 @@ static inline unsigned long get_break_insn_length(unsigned long pc) > return GET_INSN_LENGTH(insn); > } > > -asmlinkage __visible void do_trap_break(struct pt_regs *regs) > +asmlinkage __visible __trap_section void do_trap_break(struct pt_regs *regs) > { > #ifdef CONFIG_KPROBES > if (kprobe_single_step_handler(regs)) > diff --git a/arch/riscv/kernel/vmlinux-xip.lds.S b/arch/riscv/kernel/vmlinux-xip.lds.S > index 4b29b9917f99..a3ff09c4c3f9 100644 > --- a/arch/riscv/kernel/vmlinux-xip.lds.S > +++ b/arch/riscv/kernel/vmlinux-xip.lds.S > @@ -99,9 +99,22 @@ SECTIONS > } > PERCPU_SECTION(L1_CACHE_BYTES) > > - . = ALIGN(PAGE_SIZE); > + . = ALIGN(8); > + .alternative : { > + __alt_start = .; > + *(.alternative) > + __alt_end = .; > + } > __init_end = .; > > + . = ALIGN(16); Why 16 here? > + .xip.traps : { > + __xip_traps_start = .; > + *(.xip.traps) > + __xip_traps_end = .; > + } > + > + . = ALIGN(PAGE_SIZE); > .sdata : { > __global_pointer$ = . + 0x800; > *(.sdata*) > Thanks, Alex