Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2642225ybh; Mon, 9 Mar 2020 09:58:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuCJbdaa/2wrw8Ak3NUqbzK1Pl/qbcqhEUd1v/L0JzF2oC4NGDI0WsV5crVpct3TGAmux08 X-Received: by 2002:a05:6808:4cd:: with SMTP id a13mr155849oie.137.1583773090061; Mon, 09 Mar 2020 09:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583773090; cv=none; d=google.com; s=arc-20160816; b=qijeaXzY9AIMMw9xYHgIGH28KSf11b/CV3oqFm8D9T2mxLD7YtkoagFlPxmoKlRnJN IyrK/2cBYv8+OLwN9OY/bcgzqNcQcqeFh+yX/SYwrV2cWQTS+d3YCeUD6+nP+N4zlId1 VjrRxlrK0tetqGRiFSiP7SDETW7WptVnrV91VR1N+D4U8O1IMtoYnN/Z1PYt7vJIm0rq zhZ1/ghbpBTUhXQcQQ73lSlM2IBIhGU/k2ceh4df0PXtTAfm3EwaPf0DdjtsYvMJPHPK PQ2T4ziy0zlnRLphfpn7xZSpvv6nVezSw42cle1tBA/EVgfhSjoV83N5jfqy+Bniw1M3 x4yQ== 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:date:subject:cc:to:from :dkim-signature; bh=seWJfto8ScXH/WTie1kGmp0AZpPcjTPuoxrfVsKEou8=; b=shLl77XMqixmgoSTe7ZYHJlET6Gkbyq68/+u7b070nEirWat3BUp4Qpu8B/IaFkCmF yPh4Br2/rpt6pHcDB5/X8cr8gVx0fLrBSXu1gT79xkimQ2yZ+Ixh7e4Sohci6lPYswz+ iFu7MwG8NUZqIA8shpuFDtAPbZbbC+ZDYyIov0VfFmsOj08iARINH6SbORV280f23dvI I/JcLvr+zTl0O2PW2bslO6o09FPUbcM3NTzUlq/OHK+a70PpHg9nnPXvfcGBtiI1Bab2 0cut06uw302lYjja6gBb5XQGgd/9lldZqpv3KD0wzAnBmPRICIf1XQhEPAY7yuKkIKAk np6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=ZYOiXfiY; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j80si4660368oib.144.2020.03.09.09.57.58; Mon, 09 Mar 2020 09:58:10 -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=@sifive.com header.s=google header.b=ZYOiXfiY; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727384AbgCIQ4N (ORCPT + 99 others); Mon, 9 Mar 2020 12:56:13 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:39577 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727360AbgCIQ4J (ORCPT ); Mon, 9 Mar 2020 12:56:09 -0400 Received: by mail-pj1-f66.google.com with SMTP id d8so108633pje.4 for ; Mon, 09 Mar 2020 09:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=seWJfto8ScXH/WTie1kGmp0AZpPcjTPuoxrfVsKEou8=; b=ZYOiXfiY0tuckfLvllImLc1PbkvyeyMedOVlEVYN8R2vuqmWY3Pk58X31O6HtH1cMQ F4wo1cSGiZlx5pD2FM2mTALZXAGQH8b7G9UU8YcW1TVdW8l9z+94mEs2fqOCJ8XnGhxX oGfN+MV06tnAAhEY1DcVv6yHEnbmLysfoigH9gIClmGeVe7y4ctJGqO4ScJCk8JPIEP3 3y92APRfOMk/ipYJEKKDf6HnMqwP1duhPyvlvgAYg2cl4CwZ0yLqOMoYxRm7EI33JsG/ Wq4+HmnQATpQgd0JT1TJVWY1eznEda9oruz+3TYhG8zlO01YOkECSxW8VWmkyPYZDujq evlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=seWJfto8ScXH/WTie1kGmp0AZpPcjTPuoxrfVsKEou8=; b=TtfE0KbpCpiLZo18Xo9noSLD+iTeu7VZZsWd/e6whw/NEZICZDYoyHwtlXHtOluBxR zibGs9f2TuBio8KniS0ld9TbpUlDBAsBW1pidzQzOKsL830/eGBifPvTDUs9i9sCTRTL z774AoD+ZGBcINFTRVtTVDAHscJR5JvXLWftEU5f9Wxo+k2UXMr9OiHsETjQgENtpGTm lNtOj35tGuJoJAGB+HTDhIry5OEYeFdPc1vlCspaVnVAf2FUR8FyLYiFdyD0TGaAS9jf l5apWTISCbdE6LaollvqDotRCmvT7qF6WkXzOev5Yvc6HyoDUmCshpA3GmRtYBb7I4xK IDhQ== X-Gm-Message-State: ANhLgQ1mm/OSz40u8ooY1XRPWoQjzQJZMjNPtHO1HLQg6GDZyfCCRBuJ Pkd1Wifjlh/HenGtoc9qpyu3Ag== X-Received: by 2002:a17:90a:202f:: with SMTP id n44mr255862pjc.150.1583772967759; Mon, 09 Mar 2020 09:56:07 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id cm2sm104013pjb.23.2020.03.09.09.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 09:56:07 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v3 9/9] riscv: patch code by fixmap mapping Date: Tue, 10 Mar 2020 00:55:44 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/riscv/kernel/ftrace.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index c40fdcdeb950..ce69b34ff55d 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -8,6 +8,7 @@ #include #include #include +#include #ifdef CONFIG_DYNAMIC_FTRACE static int ftrace_check_current_call(unsigned long hook_pos, @@ -46,20 +47,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 (riscv_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.25.1