Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp972264pxj; Fri, 4 Jun 2021 02:57:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ5SjkOY+uUkiKBVy/wevbaucrBB2trwTTBevbf0YWksG8JchB8IKRg5mJTSvGpkUh3Hok X-Received: by 2002:a17:907:1de6:: with SMTP id og38mr1934118ejc.471.1622800649857; Fri, 04 Jun 2021 02:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622800649; cv=none; d=google.com; s=arc-20160816; b=Dotn7HumJgkNN6hGhkZGiXbOPBa0ni2PuCgiDOV7bBYD7o4ucJSGc56fR51pkaOs4s w5MBYxd50f6073sUDifxIE7NBFW1iiQMJ6tFlo2PheNw60QjOfcml2hbicLpVP4jQofE KuimgLqCu3jJI53EQKxioxHd/smked5svSGw7Ogu1COuDP67WZoXozjdEakBnec3Ic4h UrPzGbtKsw/G05qpBhC/FI1CHTXgILiDRUG2+zLHiEnMYdg/z5lrpxtOa74S3mExcZNE 6MQfmQHPb90uCQ+MZ/SvIscCqny58RMTDXnALkH08ZCcMdowWATcCFq1U7jujGspXFXb MfaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dHxjx5YL69TG257xYMSlRK9DeSKTQjJUGuYuF182ZkA=; b=ze3wRVi+SaLwDQl/P7cN+9L2Y/TpEvrPyaxyvEkPkjbA+5QDNrwqiVkdEDU5yR4sru 0iS2T+Jm48cH/UOivsvgh8wJcVUcICgaxSbjiIOM33HPh8Dax0ll7FMEvJ7IxavAr5fI l5LUwqjyzzO5uVj8megEaLZS+/I1yQ5CJT0HnVe+JubMNClgjqwrI4oyIObh1SCO1SoF 9F+R2blC0HbtvZuz9tx12AdN+hH0FYvg9vThtu82VbKHfB9dRxmh1OvexXBZrqL0sNtJ qXAxUf61vjjC+Pv7HHpoPxCqJaogHME/tRLmzSJcbJdGyEgAnr3ZsQbI9uMeoP2ahoFL WsHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=ZjNrkxUT; 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 m22si3283090ejn.250.2021.06.04.02.57.05; Fri, 04 Jun 2021 02:57:29 -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; dkim=pass header.i=@konsulko.com header.s=google header.b=ZjNrkxUT; 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 S230010AbhFDJzi (ORCPT + 99 others); Fri, 4 Jun 2021 05:55:38 -0400 Received: from mail-yb1-f171.google.com ([209.85.219.171]:42956 "EHLO mail-yb1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbhFDJzh (ORCPT ); Fri, 4 Jun 2021 05:55:37 -0400 Received: by mail-yb1-f171.google.com with SMTP id x6so12846263ybl.9 for ; Fri, 04 Jun 2021 02:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dHxjx5YL69TG257xYMSlRK9DeSKTQjJUGuYuF182ZkA=; b=ZjNrkxUTZGVEOoJt3tb3BRIbJS+FLoZFrMhc6MX/H92/nvb6aCc3J/4G1fgy3QycmF wI/D/zKJ5ReMigNMp1Yruu+AfWR9GYZFfjznAioLnLSJQieXrGVOO6VX0V7ya22FKgQi l4R+FvRvFa0eHm/hoSZ3YM1MqKW1pwFIOSlqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dHxjx5YL69TG257xYMSlRK9DeSKTQjJUGuYuF182ZkA=; b=tRSN+kjvBzt4fgYR7P+RcUEFGGDSOVFgoJtAaD+NcKDHQ8tztyN+hn2mj6s36qCohe 3MYr8OxFginuqUd02USeL+yzQOFzGJNfqhUdmcYVNotKpiF84mx6npjCzBGpd7A96Mf/ b1FbrCjyVLCsuwgnedngVduxGxc6vw3f3C4Ecq8GDHGRs6vtgLfF0emnRz3Cjif2RfHJ VbKdrkyk6XcsY1aun902Okvyppeq8zOI6aJijXkCu4CsB53RWfYh+mMJxf3KBdu/ONeX hUynxTunG8GNbcZA0sJsTbASIAODTxlrQUqMe2POrGNd/vc6ine4dFBD3ExjXq778Ob2 F8sw== X-Gm-Message-State: AOAM5325HK4Xfu1N2oDNZdM1j72fjgOxEfzQZN4fVCgJ0rk3MK77xVR+ /n0ohDHtWbcwLVuqyRMl3SM8C6MLNSfOszoB+4eIyQ== X-Received: by 2002:a05:6902:4b2:: with SMTP id r18mr3959329ybs.446.1622800371649; Fri, 04 Jun 2021 02:52:51 -0700 (PDT) MIME-Version: 1.0 References: <20210531085342.17494-1-vitaly.wool@konsulko.com> <62961217-1733-eaa3-b072-cbb252620c9a@ghiti.fr> <2fb64dce-779a-c6f2-53b7-088cd38813a4@ghiti.fr> In-Reply-To: <2fb64dce-779a-c6f2-53b7-088cd38813a4@ghiti.fr> From: Vitaly Wool Date: Fri, 4 Jun 2021 11:52:40 +0200 Message-ID: Subject: Re: [PATCH] riscv: xip: support runtime trap patching To: Alex Ghiti Cc: linux-riscv , LKML , Palmer Dabbelt , Nicolas Pitre Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alex, On Fri, Jun 4, 2021 at 11:35 AM Alex Ghiti wrote: > > Le 31/05/2021 =C3=A0 17:17, Alex Ghiti a =C3=A9crit : > > Hi Vitaly, > > > > Le 31/05/2021 =C3=A0 10:53, Vitaly Wool a =C3=A9crit : > >> 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 kerne= l > > 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? > > Any thoughts about that? Oh sorry, I have overlooked this. I do agree this is the way to go long term, I just wanted to do a reasonably good quick fix since the default SiFive configuration won't even build with CONFIG_XIP enabled. So I would probably just suggest to take the existing solution and then think over the details (e. g. should we just use one "alternative section" for both the functions and the table or have separate ones?) for the generic solution. Best regards, Vitaly > Thanks, > > Alex > > > > >> #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) > >> - . =3D ALIGN(PAGE_SIZE); > >> + . =3D ALIGN(8); > >> + .alternative : { > >> + __alt_start =3D .; > >> + *(.alternative) > >> + __alt_end =3D .; > >> + } > >> __init_end =3D .; > >> + . =3D ALIGN(16); > > > > Why 16 here? > > > >> + .xip.traps : { > >> + __xip_traps_start =3D .; > >> + *(.xip.traps) > >> + __xip_traps_end =3D .; > >> + } > >> + > >> + . =3D ALIGN(PAGE_SIZE); > >> .sdata : { > >> __global_pointer$ =3D . + 0x800; > >> *(.sdata*) > >> > > > > Thanks, > > > > Alex > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv