Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp370175ybb; Wed, 8 Apr 2020 01:13:56 -0700 (PDT) X-Google-Smtp-Source: APiQypLjKhUeKLcVpOe0e396AeZTy13scTWhZ94g9FFCQkZZINP6kEZgpvUSHMQReqboRZgSy/bs X-Received: by 2002:a05:6808:7c4:: with SMTP id f4mr1513846oij.31.1586333635968; Wed, 08 Apr 2020 01:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586333635; cv=none; d=google.com; s=arc-20160816; b=h5N8xsrjmfsHMyu+ZB61978g+TuUgq/P7r5OT25mR9EDy9MWgeemNwkLl49kkgUXaU Mzr8JJV7gIYyFDzHtn/QAOl1ICXGSC8e/g+6Don76AV50J8dKjyjrWfw1C2kj7d3AQDk QoesrN5N/MclfyBkQQMZVXt1AtUTjJUiAQAbisEkI1qmYR0yMSLKaawECIBrJ3EzNbNi xDg6MzuvHXaz4aFEQKQV/eFAqW4yExl1suZg4kbdONNhWKYNTs9eNNC93FjexsQjM4xv cLCGJJv1RfjpDhoG+3wYHkK4J8JX+5zjQVC5B1XRnzP5VYfwB9MYCllXDDOkAP9R5Kx2 E75A== 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=XkJsQ5wK/x/TlqEbA+mDNHgNHjaEj7vOian5h3Az/dI=; b=tUjJ6kE63ffo6uJwbSkeHsRhGq8Ijn3fRufSsypSI3ICeSvNCIzSUft7Xrj4BB05oQ cr4Dl9U6BqMD1DYUJIEWNhrImCiEwD9jvihUxFXp/ltP1Ca3UChWbLFiT7LNJhGLIY/M AAoaw/dedwrElsG091w+dwdpQgo5HJr8KXAssBBRAlTfdICv6Zx0y5X5yEzNe9QxctrI xqjC+nOa0lrlT8aK07OSMYoqjxa4v9sEvGW9J1u/nSipa8AG1ApZiJs2tlUlHTo2BSwg B9x6OfWB8P3K0B/iXXUfA8Y8k4babZpnQe4O4pC4QioY/SF0f6ieHllMifyewdrXvSzs oDbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=GoQ2lksF; 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 j184si1629118oih.216.2020.04.08.01.13.42; Wed, 08 Apr 2020 01:13:55 -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=GoQ2lksF; 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 S1727254AbgDHH5Q (ORCPT + 99 others); Wed, 8 Apr 2020 03:57:16 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46941 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgDHH5P (ORCPT ); Wed, 8 Apr 2020 03:57:15 -0400 Received: by mail-pf1-f193.google.com with SMTP id q3so2038162pff.13 for ; Wed, 08 Apr 2020 00:57:15 -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=XkJsQ5wK/x/TlqEbA+mDNHgNHjaEj7vOian5h3Az/dI=; b=GoQ2lksF14YYCaOtMuoKYM7vT3Yx9eYSzDJeBCT1onK+swzFQVmrxQNz8A0Tx1UV7w N4ukqiuGUz7US9jG6G1pNTsCLz0BIPllR5BjjArtNUhj2U6cj8SyMJrr0nyeieYkUBWS lRuu0Ksmv3TE6giCaCh0dC879/19i4O751Yez/1Q6bLNmfw/Avdp1LOLgu3G/M+9XGP2 OD2j9gih+Y+EHJJMt6O6mMQ8IEtjo/iu/nAwwpROg7jmT5q2oS8i+Fyi2h759BYMgIic FXmTCxNbmRzSoqCsLEcV0QdM/JF3rA1UzVR/48veI1V1jXkwkN5Aj5Sh4zsr73xcomL4 u3yg== 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=XkJsQ5wK/x/TlqEbA+mDNHgNHjaEj7vOian5h3Az/dI=; b=gVfXTGlSc/OZ+TsYaZOTovB/9OGGKF836bZrkN7pIV3FCSgWcyqmYWVkBNCyja34AR COwllzU6EUxLhoH6YOmi2JxfsGUekkvM8g0H/E+fwpyCc5oP83r+xOoKmyrbR4V+fK40 FTP3AET6kuamTl+zEolyKuX2iD+2HQSQByb4ayJJalMS7aG7xgEf/33cwPCkdXITFU7p kw54Zzwbw+wcj3oweUtP3iO9Qlt/oXXXVHk4fXMSOyBdZMBz11JypDGXH/DO6Gq5VxWp mNBciGTaY0iRfuqczXxHASqVPgQCpe73OArutB1TVziS0B1ibuz4QOlxMvqJ4zysoCrR aZlQ== X-Gm-Message-State: AGi0Pub8qklx6lABobF7yD6A8BbCW4U56J9g+1JfFVT+QkaBEovgHmto jPLfBYilH2VEpm4E9HxqxGes4Q== X-Received: by 2002:a62:1e84:: with SMTP id e126mr6071812pfe.315.1586332634924; Wed, 08 Apr 2020 00:57:14 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d85sm485599pfd.157.2020.04.08.00.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 00:57:14 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v5 3/9] riscv: patch code by fixmap mapping Date: Wed, 8 Apr 2020 15:56:58 +0800 Message-Id: <27f31750f58cd0ad2805579b16b001aa88103688.1586332296.git.zong.li@sifive.com> X-Mailer: git-send-email 2.26.0 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 Suggested-by: Masami Hiramatsu Reviewed-by: Masami Hiramatsu --- 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