Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5240330ybf; Wed, 4 Mar 2020 20:28:35 -0800 (PST) X-Google-Smtp-Source: ADFU+vu2sUL0UbRezrLi2YMLRzoxUh7vlAMaoMwuEmtdpKJN9dCwSTGB/EFvXMiqLk+67SZK+E5k X-Received: by 2002:a05:6830:1406:: with SMTP id v6mr5231584otp.232.1583382514925; Wed, 04 Mar 2020 20:28:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583382514; cv=none; d=google.com; s=arc-20160816; b=ZV79fqhEzwGQheW4NTSJ9uFCYFjz66PJDl5TLMOtJQ/iuu8+zUFXgosw9OCT8EUgc7 xkfeva/QIluaRvmfWePa2bJvB5agq+JYdxw85LD7xGio2ZEOUkcWFiWGSj6T3GDtL2Pe UvKBZNdXSTuafGY0sz+/HtfRubBvfF7CmWzxS4+yKRnbdmKd588HwGX/59JA1EVsho9G uCWepE/5ahQXyiUJVX4iWHxmmJ/aawY9t4CBzt5XUyGedZiFY+aO7j6cn/INeW2/DY+5 70KpWtLzHo7oJZIiqUYW2+n94J9vVqmUwzrZNfdKbGOnCYYHUtfo+W7QzIxZRtt751tc pP/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sS9dvBtV87gMWUGiIiRGt8RJH5mq+llNqMeBOdVmClE=; b=J0pc70FBCsNQ5jXEt39flf3dxmILVIsETFszKI/ry6BiYCrXk+I0aP8RpglLRA1o/h iDE2RvDoCwGYiNB/0Hb9iU76vx0BUMstvc4+cwkcjkml7nPQGW75jjNDeIupq/kY0WUp 26FCV3kFyAo6aaFAViusIVO8XnJuvTgeM7ncsb+ItiZEz7Fe5aehb+Fq9aEALv88/Gue 65ffVmlgk4oiJOb6vRn4kYZ9EBGqk/kmAjUl1Kl139gpXQTXTFTG7vSRSjgqQ27PRUt2 8W4E3e1CDi/abScJDnx+lsgZH01OD0gEvrCPBrhujfQOfyrCKEjUXTY/sxBUDpMNXLNj qwgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z9snj2lv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g18si2532026otj.248.2020.03.04.20.28.23; Wed, 04 Mar 2020 20:28:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z9snj2lv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725919AbgCEE1R (ORCPT + 99 others); Wed, 4 Mar 2020 23:27:17 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:34621 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgCEE1Q (ORCPT ); Wed, 4 Mar 2020 23:27:16 -0500 Received: by mail-lf1-f68.google.com with SMTP id w27so3429785lfc.1 for ; Wed, 04 Mar 2020 20:27:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sS9dvBtV87gMWUGiIiRGt8RJH5mq+llNqMeBOdVmClE=; b=Z9snj2lvrSLPdsNRBeZOWFaNcyEqk6Dwqvz7hhIVeSaaaJCnXCFQaGOKcUx7z48tXu SXmKi+SvTc23cCXr4QQtXz1pXBjtoWoTqLJYNZq8zvUDJ9XjbSq8/TVJDQ1QzOUbD9CY oFqY4TO8J3rw5ylDKUW8yOktXBimepvIs3uLSniPjraAFxfp9JZZTL68kFSdrbxODRJa o9MSbvOXYwncfHefEmYQyrqOD4HlKx2+IgTEnnkV8+8etB4xEzdQYC2z4EMTcki9aQdA wv1WpvFnYwlULtXQkq+LSv1i1Hn+LOtYJw2mOlfnJC1UWJoFvVrbf7b5irUxIopu5M92 iC4A== 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=sS9dvBtV87gMWUGiIiRGt8RJH5mq+llNqMeBOdVmClE=; b=o/J3iAFQKlaPlj/jmIKhErLRseU0zhmTA9nShOPD4uhKVBmAfMUrNZxD3TrHPjNr7f 9rqyTIVV/7YyMgN9ndDAfK5fzxlJK9fZA6E/pP6G2i76ZKEULyP1tf31i3JDJh8kzjkw BGilpXcjxQPLJNgHKYh/QUczJ3Y4y2n2qcr2SVB/Wi0dPPjXmQkIYTuAZ6NkGHRTgbcU DrCLio4yvjS4Bx1t58y51tW7hcJaHHaSANXkDgOkcEhHFVfpMaf8sBVFdkHXuIyubjnE 10EN2D+poxhMBr9djB63hFumCv0oYDJeRmsRuxDM1mjrCCr9+oquh2DstJVLvfipSDlI Y3dg== X-Gm-Message-State: ANhLgQ2myRaWpXmxTvNzW9+8YdUnkjU93W1xooQhbZZYwMUsjQRtwMNg /dcJmGOLC1sEqQXjNzSFJJXE7wqJD8tEmOEjFy0= X-Received: by 2002:a05:6512:3188:: with SMTP id i8mr4256307lfe.26.1583382435049; Wed, 04 Mar 2020 20:27:15 -0800 (PST) MIME-Version: 1.0 References: <20200217083223.2011-9-zong.li@sifive.com> In-Reply-To: From: Zong Li Date: Thu, 5 Mar 2020 12:27:03 +0800 Message-ID: Subject: Re: [PATCH 8/8] riscv: add two hook functions of ftrace To: Palmer Dabbelt Cc: Zong Li , linux-riscv , Albert Ou , Linux Kernel Mailing List , Paul Walmsley Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Palmer Dabbelt =E6=96=BC 2020=E5=B9=B43=E6=9C=885=E6= =97=A5 =E9=80=B1=E5=9B=9B =E4=B8=8A=E5=8D=889:44=E5=AF=AB=E9=81=93=EF=BC=9A > > On Mon, 17 Feb 2020 00:32:23 PST (-0800), zong.li@sifive.com wrote: > > After the text section be mask as non-writable, the ftrace have to > > change the permission of text for dynamic patching the intructions. > > Add ftrace_arch_code_modify_prepare and > > ftrace_arch_code_modify_post_process to change permission. > > > > Signed-off-by: Zong Li > > --- > > arch/riscv/kernel/ftrace.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c > > index c40fdcdeb950..576df0807200 100644 > > --- a/arch/riscv/kernel/ftrace.c > > +++ b/arch/riscv/kernel/ftrace.c > > @@ -7,9 +7,27 @@ > > > > #include > > #include > > +#include > > +#include > > #include > > > > #ifdef CONFIG_DYNAMIC_FTRACE > > +int ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex) > > +{ > > + mutex_lock(&text_mutex); > > + set_kernel_text_rw(); > > + set_all_modules_text_rw(); > > + return 0; > > +} > > None of the other architectures are doing anything remotely like this in = these > functions, despite many supporting STRICT_KERNEL_RWX. Having a function = that > maps all text as RW seems super dangerous, as one stack attack means NX i= s > gone. > > Looks like FIX_TEXT_POKE0 is the magic that makes the other ports work. > Your concern is right. Let me change the way. > > + > > +int ftrace_arch_code_modify_post_process(void) __releases(&text_mutex) > > +{ > > + set_all_modules_text_ro(); > > + set_kernel_text_ro(); > > + mutex_unlock(&text_mutex); > > + return 0; > > +} > > Presumably this needs a icache flush as well? Probably better to do so w= hen > installing the instructions, though. > Yes, I think I lost it. Thanks. > > + > > static int ftrace_check_current_call(unsigned long hook_pos, > > unsigned int *expected) > > { >