Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4522790ybv; Mon, 17 Feb 2020 00:33:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzUegBT9Wizwg4rJL4Ea5s99e+E+vU8dDDdwYc8idLt70Exe5eUbLWVHh0e3settmdUpERM X-Received: by 2002:a05:6808:643:: with SMTP id z3mr9308901oih.19.1581928391763; Mon, 17 Feb 2020 00:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581928391; cv=none; d=google.com; s=arc-20160816; b=FmaXwzwRveXyUUc/1KxBC6MPQpjNXms5+tGBltBDAidslLhL0u6ns3w3xQtlx0SnEJ WnB1M4ta0j3oujjTchfkXk4NDqWh6jYptPfwpV5RQatqcxqoLquIhzasm5RozGhEdjsi B4Ivx7aBNkH7QCdtTxufa7wKjiMLb5/CzFV/+sgghm1XXM2vm8mKMlFyeEKWu4PmXyyP jc0aRKnZ9Ii+rLHziDP61fZBOvWXfjsw05do0wpLmfwVzs2zokucIQ+tKyHCTsZz5yBN U09gqXpmk8LNeh+Tm36p26+kSytA/YfcrV8UxBb3PcGSg9O02c/SUTX6yCuN88VLXzco hAcg== 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=jQSZYEZ2vhkMED23W6rsFbYhYDKZOEiTycR94nUJ+Ew=; b=q3Mm4GJzpPRMA2ovvKSQRfGXUBnvdseAgLDxwyxtuJLwPRm6JZcwGW3sk9wV/oNXxT lp+Q2Az9I9AVQ0VXHhvc5h/TJVhT16NkE7+NaphNdJcgjtWkAQ25g3Clflyn9sCJ9w36 zAiel1uKjQzlOCvsBFsFAK5emm/kvRqHkSHx7xQU4Mg25xTKZ8eljBAkZIzD3VUZeeOE d5nOW5TMKgta2JyGmqSlFsHsNp7KqdRz5G8LVq6IWi+cJPG8iEr4AICJQtej5Cy6nknQ IttNhDdm5Oq0uBJXL+h0ndbnlN4Yu0+iv0jWxp74WWCPR/tTx4FkUvp5ikWF85nJU3+p qOng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QRcu7K1y; 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 p3si6567553oih.186.2020.02.17.00.32.59; Mon, 17 Feb 2020 00:33:11 -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=@sifive.com header.s=google header.b=QRcu7K1y; 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 S1728420AbgBQIcp (ORCPT + 99 others); Mon, 17 Feb 2020 03:32:45 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:33057 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728398AbgBQIcm (ORCPT ); Mon, 17 Feb 2020 03:32:42 -0500 Received: by mail-pj1-f65.google.com with SMTP id m7so2065786pjs.0 for ; Mon, 17 Feb 2020 00:32:42 -0800 (PST) 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=jQSZYEZ2vhkMED23W6rsFbYhYDKZOEiTycR94nUJ+Ew=; b=QRcu7K1ynFQwM/E1GpcioKUsU0jYPrs/IocnAODOpl69n8tyPN0p1m5oqePM3+dU+p YXh3OKQ7P927emmDXw95LEbZN6PRdCzzoqyHvyiPtpqu7FXPwU3ttIujRunfr43PaaQs lbqIDXrg94IkC/U1l9jxl47ENqXcpB0O3k2lIIrFDllsVk+fwEuN1vlRo1353ejNfxCE OM50ksoOxNJY6zn+w3oA34LR7DyD79xytbkFjqCUdM8xmUsF/C2UI2CHjvWtbzXNexsT 0s8Sqpf83fllFTHw8kW4U/idvnIZP+wqX8nMQAn4J+gqkdoogp9ExNVPU5Uq1WmWjIVR WthQ== 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=jQSZYEZ2vhkMED23W6rsFbYhYDKZOEiTycR94nUJ+Ew=; b=YhritjcWBM+9jS6cLMsFJbDu8AOpyQOEMApKCOK1uxHRhf70Kjm/2B3FYfZlPlW7OL xQFoktibHZSLJLMyzlWtRaun3S45NknTtR5bkCwbQJ2c2fcONdgkfdB61i67tJlt6Z0Z rgeka5hworRzNhIfQU1LlRpAg46exyhPWZ7MxEFOTxRuz10lgxoxeLA+ZkWtRWDVYTEY +l0uXenWTQZbMSR1Kxr+nUKMgb3qL0IxY/qdc/BvfCRHC24pBnrxa8i68WFVub0Nsm2U Ooaq+W40ByzkgZNad91iQ0ZZYpQtfYqAq9PDnKFu+Rh16NhJGJetiiXWU3UaXAk887h/ m5zA== X-Gm-Message-State: APjAAAUIi18WPdT+cB07+v2ukS1r4BbFIdOYiZfzU5O0BGKMEASmq2Yb bqoc7VV/8rykXsQmPHE8Qb0N9A== X-Received: by 2002:a17:902:8b85:: with SMTP id ay5mr13963098plb.253.1581928362335; Mon, 17 Feb 2020 00:32:42 -0800 (PST) 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 z10sm16989319pgz.88.2020.02.17.00.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 00:32:41 -0800 (PST) From: Zong Li To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH 8/8] riscv: add two hook functions of ftrace Date: Mon, 17 Feb 2020 16:32:23 +0800 Message-Id: <20200217083223.2011-9-zong.li@sifive.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217083223.2011-1-zong.li@sifive.com> References: <20200217083223.2011-1-zong.li@sifive.com> 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 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; +} + +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; +} + static int ftrace_check_current_call(unsigned long hook_pos, unsigned int *expected) { -- 2.25.0