Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4640920ybl; Mon, 13 Jan 2020 17:39:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzYreHJ6qbld9sk+xWQH7M9KcTpshNl2JwEbbPwP06qynOshBA41tBk03UW+tB+a3n4i10J X-Received: by 2002:aca:dc8b:: with SMTP id t133mr15348741oig.98.1578965961393; Mon, 13 Jan 2020 17:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578965961; cv=none; d=google.com; s=arc-20160816; b=T5L3vwigUIaChqnyRLlPz0uDzwKuVruYqkAHTjthLtJtTP54oao4dEJktgWZxLkUpj mJN5vQcqXQG11y8zJde6Qvp5kEpMl3HpI00d/oBj9CdvketH3j782AgbfADOqlBrcisr Z+YCcO+8qvRP9kFKjRAwaO5sjhdfGHVaefCOE6nVDUI7dfhK1BOqZ4/joZs2cThkcBCE I7GJSlFd2buvxNVaMyJtujIK0dMxBoP8STK99OJugWb5SluOWAtCKCIUZ+gXEf3mUCtw 7gCxZMAU1n/RL8ieb/DO7BrZBM2PssNS1N7Lb34mPOLex8/miZeT6fOh8/G2+Rcbefly 0wXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=pIHWi1FfDFHbVweTvdMDdVKwGc6jDxF3YQ21FHDX0NM=; b=zgHJVg0zHSGCuujh6amAuuyufVl8R2EUL4B5oSDITre6tFkQ95zcwO2Dsm0XRKBWc3 jz5dX5P7n3I/0EVA3/fN6DCm+JGT6kqiUaJndn84I54KyGaGW1xYJ0cMw/uY2CT2d7+a rhQDJyBBamXZIeDU3pFEvsi+BwwzoJInKXq2XxV+WV9RkgP7aNX+rSC7XJLaIRW4wGni 9zoEcoryr0QRHiVGg9ef5HnAcRMjCw/CQEYHCSIlmz/rmpsTXn2y28AcNRelebX38Vjd dUpPL5n2lUWkHz4aW4Bgm818xIrnFHoHunCm9ACn5g3OvpX45lWgndHNAZ35ER/zW/xF wtHQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n14si8145563otk.179.2020.01.13.17.39.09; Mon, 13 Jan 2020 17:39:21 -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; 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 S1729538AbgANBhx (ORCPT + 99 others); Mon, 13 Jan 2020 20:37:53 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8714 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728946AbgANBhx (ORCPT ); Mon, 13 Jan 2020 20:37:53 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id BA7115B6EC2D4E62466E; Tue, 14 Jan 2020 09:37:51 +0800 (CST) Received: from [127.0.0.1] (10.133.217.236) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Tue, 14 Jan 2020 09:37:42 +0800 Subject: Re: [PATCH] x86/ftrace: usr ftrace_write to simplify code To: , CC: , , , , , References: <20200113073347.22748-1-cj.chengjian@huawei.com> From: "chengjian (D)" Message-ID: <8ab66ffb-614b-063d-7362-2f01906aec51@huawei.com> Date: Tue, 14 Jan 2020 09:37:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200113073347.22748-1-cj.chengjian@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.133.217.236] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I am sorry. usr => use in subject. I will resend this patch.  --Cheng Jian On 2020/1/13 15:33, Cheng Jian wrote: > ftrace_write() can be used directly in ftrace_modify_code_direct(), > that make the code more brief. > > Signed-off-by: Cheng Jian > --- > arch/x86/kernel/ftrace.c | 24 +++++++++++------------- > 1 file changed, 11 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > index 024c3053dbba..6b36ed2fd04d 100644 > --- a/arch/x86/kernel/ftrace.c > +++ b/arch/x86/kernel/ftrace.c > @@ -114,6 +114,16 @@ static const unsigned char *ftrace_nop_replace(void) > return ideal_nops[NOP_ATOMIC5]; > } > > +static int ftrace_write(unsigned long ip, const char *val, int size) > +{ > + ip = text_ip_addr(ip); > + > + if (probe_kernel_write((void *)ip, val, size)) > + return -EPERM; > + > + return 0; > +} > + > static int > ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code, > unsigned const char *new_code) > @@ -138,10 +148,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code, > if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) > return -EINVAL; > > - ip = text_ip_addr(ip); > - > /* replace the text with the new text */ > - if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE)) > + if (ftrace_write(ip, new_code, MCOUNT_INSN_SIZE)) > return -EPERM; > > sync_core(); > @@ -326,16 +334,6 @@ int ftrace_int3_handler(struct pt_regs *regs) > } > NOKPROBE_SYMBOL(ftrace_int3_handler); > > -static int ftrace_write(unsigned long ip, const char *val, int size) > -{ > - ip = text_ip_addr(ip); > - > - if (probe_kernel_write((void *)ip, val, size)) > - return -EPERM; > - > - return 0; > -} > - > static int add_break(unsigned long ip, const char *old) > { > unsigned char replaced[MCOUNT_INSN_SIZE];