Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3636886ybl; Sun, 12 Jan 2020 23:20:16 -0800 (PST) X-Google-Smtp-Source: APXvYqywfG9ki/70ebZTS/u3dvQj3T7vnCs6lsFIWHgKyNuX3HoYwFTprM2S7ZfHPWMcRZHRaByV X-Received: by 2002:a9d:d0b:: with SMTP id 11mr12597873oti.287.1578900016109; Sun, 12 Jan 2020 23:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578900016; cv=none; d=google.com; s=arc-20160816; b=u8ktwqCgRP29kaU0sllUxKVO4y27+whHITEYGbjZnb1sEtvw8QD140qaSDx8Ydilvg 24wZ+LaQtdPvQwNTYpeHtU8lXnxRLAvI7/ErL5N1/yFo3p4NFJ4hkbxnf8PuBR8M+Sb3 tWnRWksf8fVBi5nGug2wWbK8aErX6uY58pf/Eqx7LrSkEVocPQ1NJ3+3wRNTA0QqZgH2 Co94ReO8cC7icMv9yFoK5mmGEOaskR9Jl1x0wwHv4IOEWziG0kz01oHXAdelyeZDvJwA o9e3rnLSJ3zTZJX+h9zGsvx0jDLOvJt2Orpz78V45MLrJ0PEhBs8h2rpmN7O6tvd553w Ee5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=CeQOPomeRjm+vp6HqwnfllvvAVBWVyQuwuH0Ny7M9vQ=; b=CUgQwtTWugHjNRPsFNIFOdM3D5mZwdVBYq2MCRAjLRBd8Csaivqava+dGePAOpPNq9 px6/IcwjoiSPIydwHHeuaFqex+x8FrHqb+PgUe44mmMiaCGNw87o2E6XQnxkcTX9LIJx +WVsnqAaZMLxa3+CJnCDm28hPOGqu2ZgDkALQKzAy8u/LGEMmFa8xya4E335DXUlQrlV I2oOhsDtKCFNGymqhdFFFqUPeNwsP/VIFTH9hGM1PtrUlgQeZMm4tmeQKmkRmFUf4Xsi OKYCwT6mEutWNqomj594EcQVktnJTSDOOpJhFW0DGcK6++v1yZA2DQ4jSOoOuTqGCJvu M3mg== 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 w26si6463600otp.239.2020.01.12.23.20.04; Sun, 12 Jan 2020 23:20:16 -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 S1728791AbgAMHTC (ORCPT + 99 others); Mon, 13 Jan 2020 02:19:02 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9163 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728646AbgAMHTC (ORCPT ); Mon, 13 Jan 2020 02:19:02 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2CCCE9D5164FAC6FDB32; Mon, 13 Jan 2020 15:18:59 +0800 (CST) Received: from huawei.com (10.175.104.193) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Mon, 13 Jan 2020 15:18:52 +0800 From: Cheng Jian To: , CC: , , , , , , Subject: [PATCH] x86/ftrace: usr ftrace_write to simplify code Date: Mon, 13 Jan 2020 07:33:47 +0000 Message-ID: <20200113073347.22748-1-cj.chengjian@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.193] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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]; -- 2.17.1