Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4640823ybl; Mon, 13 Jan 2020 17:39:14 -0800 (PST) X-Google-Smtp-Source: APXvYqzsRVNvQoydWvCDCOQ48aYECojHkCcfCPslCKUhcauuP197ACDMDEGTz0tjXSVtzl9y6zlo X-Received: by 2002:aca:5303:: with SMTP id h3mr14224203oib.109.1578965954844; Mon, 13 Jan 2020 17:39:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578965954; cv=none; d=google.com; s=arc-20160816; b=zU36LXBtuNJvyn5A+mJEo2NA/n+4PSsrvNu8Im31R/RtWiRXOKixt9KoHlRzWDzu5z 4Cr+bcPSRfenrlV54r/b6FJikI/l+OUcD7pLagz5695Dy5LhUL8RY7TkHzvMCBSKtSEP YchaEv5SG02hTJDfLJWuic8DUf7+gJ6jQBMrNnR2e0Vn0BUUpI6jGnfG1rYYC+YgDm+Y +m4fWf5hIr6cDfOKA+5WMTkFgq9VFEovgNhVLNu/uP90e+4rvzx37ETbezCABHVSPn6u fAw4tdymauN0mNnGG53L8SsZBAkH73MQIArsKu/46LlR22GB+wrKlg/DFNnurDDHAdWd AJxg== 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=Mjz10ZoU9docHpyyFsX19/NA2aPrR9n5y5lwpRrgnVI=; b=WAcqRIT/ETq3yZB9fgprfjafGDkmaf/yCIkZaS1irhRV/jtOeDosGVcOh1DV/KkAW9 7trXAkmnlY0qgBWjbFNX0am28aqVicvDqBgMFk50rAsNTCZptvXyz+GZsvt7Q5jTiYD6 oIjzU+aM2NXio81D1uD0wYQz2uMmyTobawO901QqSbcS6IxjkXw9gOl4TWzTrVjdeEW7 5J+fH6BueWjesd/QoXxfKt78DSb2MlbKTueueBGhlBRIpUileh1STc9HmYKTEjbRclzQ PpYs2F066D10/1kqVspCgvKrvBTUrjdvAcicFT7PSgam6ESKmwX+IgCOuVd+icWlMEJh kwow== 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 i23si1749505otf.41.2020.01.13.17.39.02; Mon, 13 Jan 2020 17:39:14 -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 S1729531AbgANBhf (ORCPT + 99 others); Mon, 13 Jan 2020 20:37:35 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:60630 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729081AbgANBhe (ORCPT ); Mon, 13 Jan 2020 20:37:34 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 31963EB1957F3B2A33A1; Tue, 14 Jan 2020 09:37:33 +0800 (CST) Received: from huawei.com (10.175.104.193) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Tue, 14 Jan 2020 09:37:22 +0800 From: Cheng Jian To: , , , , , CC: , Subject: [PATCH] x86/ftrace: use ftrace_write to simplify code Date: Tue, 14 Jan 2020 01:52:17 +0000 Message-ID: <20200114015217.9246-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 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