Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2224345ybh; Mon, 9 Mar 2020 01:24:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtnm07Y3M/r8Rye8hkYhNGS595OMGO3LzU8KA0nbCUhgFfEzBZ0XaqDA0fSX8gmPCLxWxW+ X-Received: by 2002:a05:6808:289:: with SMTP id z9mr10161983oic.48.1583742274626; Mon, 09 Mar 2020 01:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583742274; cv=none; d=google.com; s=arc-20160816; b=KmqKgpobnAuDgg3jj5Rop1ZnaMMy214MTlqhw+RrrPgNrHUarHhEHGrHjl6vicn/82 DVkswUo4uKoJRW6GHaJheMXpYDm0YJmTqqArod6LoelBqUdHKvPxIOKRbEkZ09HshuUX b3PC+q8lgh2I/Kunjqa7e1q0dhi4maxETGJ6iypNj7InvIbPXyPHl5jpNg52xIQYtzmd C4qSYyHs0KnwzsRUzvrbubK8u9AwX6LOuDltzIWwVlZIL+zzNBtg6a5cr62iCZteNh1c jKQa09eIkIAcaGMywUD09Yh/WAlnMy/v35JoaKEA/k1rKf+n3ec07LIOsqyPtSqN5ddK kdkw== 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=hhewPgtSMIk0T9zm8jq/AuT32HQw/osOl1xLvIAe8EK8+YORX0AJXdhSjtwh1aoIEU dR5mkTp+2f3PEyjwAhyMn4sTzYMxJ81VxBp7cGsPfITR7BmaYhZ78s4HmC9Jmfii+BNQ m47X1EgUu5U8H4TxRWGTlPKZKObv/QTpHsSlq82uCWedYbRIRq1IQKBt0DvanIhShtiy 4g0OBiHAlT+1wWHwWgezRHUspBr6dN+PhSOijFXYfoT2jJ0yhO9hLcEqNk8rLQOP/u5+ x2pw72kbISIK6pcPdl8Qz5i6BCBjiXOPLuy9tH8tylgOyWrHo/pdOf91k6gxvhDTkvac 4ohw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=WjKcO9RU; 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 p15si5986331otq.215.2020.03.09.01.24.23; Mon, 09 Mar 2020 01:24:34 -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=WjKcO9RU; 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 S1726659AbgCIIXA (ORCPT + 99 others); Mon, 9 Mar 2020 04:23:00 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38988 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbgCIIW4 (ORCPT ); Mon, 9 Mar 2020 04:22:56 -0400 Received: by mail-pf1-f193.google.com with SMTP id w65so3946264pfb.6 for ; Mon, 09 Mar 2020 01:22:55 -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=WjKcO9RUXrq2Owu6OwvIVyRHIjDygk6NNmdiZyD6x7GnB6m6Q6mEoRTwhDkr+ff9x4 E224ttLqthCf/OCP8hsjeb4HH8gHCxdmkCv6MKP5U5L74ojmT7qf93HvaDX/f7uvoJu1 zsXE6KEWswMvBYMTnX/otBAO1Cp5Oja5iyRG9lPJT4F09Wl3CdG7/ZeiC+sypc98OTOD Fc5I9vaOpNvg5xbikor6HIVDEpTmop/FCoiGSZs/Wa3Jdc5vGlBoXB0KPZXFhcstXA+e Nwt3BYhSeD88SsRSeY+Y1BSbuLYSBi3WlADGsEszCpTBDc55DgVSzxIdHX55r/TfRo3e Bbig== 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=VFiU+4Nn4g9veh3HBwxdaIecgb/67CsCGJloB431nUuIzqMFr6kwhnnykUMKnbCzmn 9NqokzayZ+pYOtlZe+Q/mfv7a0+0yTcwtPgHpMAwXOI1YDy7vBZPlaz31Rrz11qzDz1K VWHnHIaB0aFleF0wgSFg/I9Gs6NtyJpfL1d6wbF+hKz4jaFHb69JKTc/lcgukj+sEMu9 zi2f/gscB36jcF0kNsJGjv6co98Ash5n2mYrFLMq2GLdUtvRgxwBMzy1h5Ycvbf0KRSu V10KbsGQkgcVhTN1AkNsAwu4iMCDL4iyxAD3sDF0mRJhbVd5gK3uH6DdRwG8cgiQI+W4 HKeg== X-Gm-Message-State: ANhLgQ1mQ+j0SL+eCgMWWakK4L2jr6ow1St4m9ZW1xsB+NrfJfYmoGa0 ZLA0YybE7kkdWEy9OGry41bzq6xwaAg= X-Received: by 2002:a63:f447:: with SMTP id p7mr15266733pgk.326.1583742175247; Mon, 09 Mar 2020 01:22:55 -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 v5sm18364779pfn.64.2020.03.09.01.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 01:22:54 -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 v2 9/9] riscv: patch code by fixmap mapping Date: Mon, 9 Mar 2020 16:22:29 +0800 Message-Id: <4e0f705ad808e9e0ec2db346c548dd2c5522e109.1583741997.git.zong.li@sifive.com> 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