Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4521178ybb; Tue, 7 Apr 2020 09:03:54 -0700 (PDT) X-Google-Smtp-Source: APiQypLo9UlahRG8R6W3y7Kk+cfAaOl6ksx7h8nJNYtR6jBQg4IRIXsgzsgsVOit2osBQjM25bIM X-Received: by 2002:a4a:cb02:: with SMTP id r2mr2515812ooq.28.1586275433899; Tue, 07 Apr 2020 09:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586275433; cv=none; d=google.com; s=arc-20160816; b=BmiZqQYw5lAMcgvXRF/krHMXtpHr3+4HCgdHplvqU47f/cEFAKYYUlCa7IZ7kPVcgI XfKSzTaF/wKUO+3guRJ3SnPU2HkJ3k9z26kw4QipwBtRahhstLnHfbWUv/agjutEz/d5 DVdcT5VxDhksypRAGfRUcOxKnA4EcYlhS0XF9YiDGY4RhQBb8lxB1gKVy73o5Hklaz7a OVuzJ74Cr3FKY3Kd+2ElwvfdEjdGo9F5wDLuY6ekkuYEs/Dgs7XJOLeClnEruTHHWbcs vEkYa4nxmGgPxvBOtHjHC6MQyR4zvKnakQhTJpGtXO2LE8TFGt9UKlacMIPMTrZXdmd3 Wlug== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=PRxgvsRqSWn/AK3yEIP2ZSYGJq1vPL0pg7dDWpn0Y/A=; b=YeLRuV3c8ScRg1klnbaIIWiHJB5V1H5TWPOXqe8vHUT2Ws1o1PWZu90DanXaGFdEmV ogUUitUvw9wKH4pfX4pO7giYxA0pUbxtCWaadTE/YpDbczE2Zz3AQnD1AoGDmJbXOvO2 X+P0lizGTq5vmjC34sYjWnqLXjqWS3VuaYMxN4W7B+WCjDSrtPGHevy223gMXZ5g9CqT ybbStBOxPAdFcKPAH8nIsFdlkiY6uZ3EdBg5xxcAo/lOCsGgk2qeUjTf0MpJyiw+AxEo 3T0VZW/NqevK+WLfznW7mMYCSStIk/F9zrEa9++OJYKpBFfdwuCKuYjb7ir+ceWXKpyq VQ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gw12nJpw; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 109si1461210otv.36.2020.04.07.09.03.19; Tue, 07 Apr 2020 09:03:53 -0700 (PDT) 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=@kernel.org header.s=default header.b=Gw12nJpw; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727706AbgDGQCX (ORCPT + 99 others); Tue, 7 Apr 2020 12:02:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbgDGQCX (ORCPT ); Tue, 7 Apr 2020 12:02:23 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7CBB2075E; Tue, 7 Apr 2020 16:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586275342; bh=3VjqdLa0s70r8aebZrWtJwDbgUgBPZ4Fn9cPzsn7F8c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Gw12nJpwBaICSNfCelcRlTky9psIctNfr5AJaqWmlY49ejsFHlL99qIPglWjGUE6g lt8XQXYKRg8vkMPGLFA45y42nwSgDMDSWpCJnWHPa0OORNCkXAgpnZMm3xhLDod8Xu 5vmKwu/nNjeR6eTeVFO7ruZlDGkVoOk0ro2Istk8= Date: Wed, 8 Apr 2020 01:02:18 +0900 From: Masami Hiramatsu To: Zong Li Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 3/9] riscv: patch code by fixmap mapping Message-Id: <20200408010218.c601beb496712a1251e2c9a0@kernel.org> In-Reply-To: <0b6ad2759b47731a83008b46dbbed7c92e68cae2.1586265122.git.zong.li@sifive.com> References: <0b6ad2759b47731a83008b46dbbed7c92e68cae2.1586265122.git.zong.li@sifive.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 7 Apr 2020 22:46:48 +0800 Zong Li wrote: > On strict kernel memory permission, the ftrace have to change the > permission of text for dynamic patching the intructions. Use > riscv_patch_text_nosync() to patch code instead of probe_kernel_write. > > Signed-off-by: Zong Li > Suggested-by: Masami Hiramatsu Looks good to me. Reviewed-by: Masami Hiramatsu Thanks! > --- > arch/riscv/kernel/ftrace.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c > index c40fdcdeb950..08396614d6f4 100644 > --- a/arch/riscv/kernel/ftrace.c > +++ b/arch/riscv/kernel/ftrace.c > @@ -7,9 +7,23 @@ > > #include > #include > +#include > #include > +#include > > #ifdef CONFIG_DYNAMIC_FTRACE > +int ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex) > +{ > + mutex_lock(&text_mutex); > + return 0; > +} > + > +int ftrace_arch_code_modify_post_process(void) __releases(&text_mutex) > +{ > + mutex_unlock(&text_mutex); > + return 0; > +} > + > static int ftrace_check_current_call(unsigned long hook_pos, > unsigned int *expected) > { > @@ -46,20 +60,14 @@ static int __ftrace_modify_call(unsigned long hook_pos, unsigned long target, > { > unsigned int call[2]; > unsigned int nops[2] = {NOP4, NOP4}; > - int ret = 0; > > make_call(hook_pos, target, call); > > - /* replace the auipc-jalr pair at once */ > - ret = probe_kernel_write((void *)hook_pos, enable ? call : nops, > - MCOUNT_INSN_SIZE); > - /* return must be -EPERM on write error */ > - if (ret) > + /* Replace the auipc-jalr pair at once. Return -EPERM on write error. */ > + if (patch_text_nosync > + ((void *)hook_pos, enable ? call : nops, MCOUNT_INSN_SIZE)) > return -EPERM; > > - smp_mb(); > - flush_icache_range((void *)hook_pos, (void *)hook_pos + MCOUNT_INSN_SIZE); > - > return 0; > } > > -- > 2.26.0 > -- Masami Hiramatsu