Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp875132ybe; Fri, 13 Sep 2019 07:39:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqjZ6ogBmSsaQeosSrgTUSLv94p3XD7RGHhpD/f4DPiny29fQfNtIjkUjLxZlw96aQXnKP X-Received: by 2002:aa7:db05:: with SMTP id t5mr48884698eds.242.1568385539914; Fri, 13 Sep 2019 07:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568385539; cv=none; d=google.com; s=arc-20160816; b=oS8FAZuMGnsKwwMEi6ciA6mrVYrh/yrxmHfnJyjMn08W43XmKK2/sU5vzbFDzWsome njYSOExvGS8cJ8AH2/fWmxNykia9WlWLp7REw1A/GSqzB+JZHJi7Pcllplj3Rru9ZWxN Jyod3niEXLjiAESzqJ/s1vjcie+S+NmBH65ps0nIZKrY2UjfDbzWNQfED6dNDrpOwmtE sMnU3PJHcUX5N5fp3L0SBDQu3XRj0anIASpqrzHY4m2yN6ZIHgyaCbtBcq+/2d4FojRn vI6D7+FCkeELI8SzVCDdaY9Xz5qZbyZ3HSo0PiISSvcYZ02fmtoZzFYSYbI3X7rcap0O VZlw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qRpaQ0GswSM3LcYXqFrgSE8KR7wwUc4zFnYkp+Izteg=; b=LD3Rwk+IYR1IAiyw5mDNjWiialR55COYiKfKY8nlO7Fwt35wKsSlErRiHqJ1MSBZJo SYYTcwvaM8zc4iPiINShHH1sCR/AsrqUEhJcsTWsQvC7vuIX4HmEkRqKAzb69nCzVrNS RzNh+YNbE+aO0/Nk9qnzy7rbppqYFqNnGqbUY7kQLTJcautX8+Xu0jEaKbZnf/Cb8aBM xYkg9Jz58vRYZzwT0FJ/KIo1Y4BLfW8cvvFm6l33jBrdTDH6D0ySlJ0blI8ndpnv8pY0 2znu7+Snwyw6Q20DdcH9tFivMIMPeghb4gBCVuZ2QbgFffYHr7y51etLarccpWzSWhYe b+kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ySOAeNot; 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 h19si129708ejd.142.2019.09.13.07.38.36; Fri, 13 Sep 2019 07:38:59 -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=@kernel.org header.s=default header.b=ySOAeNot; 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 S2388998AbfIMNLh (ORCPT + 99 others); Fri, 13 Sep 2019 09:11:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:36736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388968AbfIMNLf (ORCPT ); Fri, 13 Sep 2019 09:11:35 -0400 Received: from localhost (unknown [104.132.45.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 84080208C0; Fri, 13 Sep 2019 13:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380295; bh=r7cLoDktyovYgaOgT8Ie3in9jqttJSNsJN4fs8+l2ws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ySOAeNotMNEEIaPlb4d9FgFZUgTirujstnHP8nAzwBfEJC7CTIRO4kVBDufTCxkP+ BGZ/ta7VpI/XaXqXVY0BaqJycjUrCGc8XobIqF+04SrYzvF0zAgNZuv3ZvgNNxhgiD Ysz6UmllV1zoKWjV0ggWQc4N7barVSdNjkIqW184= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 4.19 019/190] x86/ftrace: Fix warning and considate ftrace_jmp_replace() and ftrace_call_replace() Date: Fri, 13 Sep 2019 14:04:34 +0100 Message-Id: <20190913130601.090972965@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 745cfeaac09ce359130a5451d90cb0bd4094c290 ] Arnd reported the following compiler warning: arch/x86/kernel/ftrace.c:669:23: error: 'ftrace_jmp_replace' defined but not used [-Werror=unused-function] The ftrace_jmp_replace() function now only has a single user and should be simply moved by that user. But looking at the code, it shows that ftrace_jmp_replace() is similar to ftrace_call_replace() except that instead of using the opcode of 0xe8 it uses 0xe9. It makes more sense to consolidate that function into one implementation that both ftrace_jmp_replace() and ftrace_call_replace() use by passing in the op code separate. The structure in ftrace_code_union is also modified to replace the "e8" field with the more appropriate name "op". Cc: stable@vger.kernel.org Reported-by: Arnd Bergmann Acked-by: Arnd Bergmann Link: http://lkml.kernel.org/r/20190304200748.1418790-1-arnd@arndb.de Fixes: d2a68c4effd8 ("x86/ftrace: Do not call function graph from dynamic trampolines") Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- arch/x86/kernel/ftrace.c | 42 ++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 50d309662d78c..5790671857e55 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -53,7 +53,7 @@ int ftrace_arch_code_modify_post_process(void) union ftrace_code_union { char code[MCOUNT_INSN_SIZE]; struct { - unsigned char e8; + unsigned char op; int offset; } __attribute__((packed)); }; @@ -63,20 +63,23 @@ static int ftrace_calc_offset(long ip, long addr) return (int)(addr - ip); } -static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) +static unsigned char * +ftrace_text_replace(unsigned char op, unsigned long ip, unsigned long addr) { static union ftrace_code_union calc; - calc.e8 = 0xe8; + calc.op = op; calc.offset = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr); - /* - * No locking needed, this must be called via kstop_machine - * which in essence is like running on a uniprocessor machine. - */ return calc.code; } +static unsigned char * +ftrace_call_replace(unsigned long ip, unsigned long addr) +{ + return ftrace_text_replace(0xe8, ip, addr); +} + static inline int within(unsigned long addr, unsigned long start, unsigned long end) { @@ -686,22 +689,6 @@ int __init ftrace_dyn_arch_init(void) return 0; } -#if defined(CONFIG_X86_64) || defined(CONFIG_FUNCTION_GRAPH_TRACER) -static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr) -{ - static union ftrace_code_union calc; - - /* Jmp not a call (ignore the .e8) */ - calc.e8 = 0xe9; - calc.offset = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr); - - /* - * ftrace external locks synchronize the access to the static variable. - */ - return calc.code; -} -#endif - /* Currently only x86_64 supports dynamic trampolines */ #ifdef CONFIG_X86_64 @@ -923,8 +910,8 @@ static void *addr_from_call(void *ptr) return NULL; /* Make sure this is a call */ - if (WARN_ON_ONCE(calc.e8 != 0xe8)) { - pr_warn("Expected e8, got %x\n", calc.e8); + if (WARN_ON_ONCE(calc.op != 0xe8)) { + pr_warn("Expected e8, got %x\n", calc.op); return NULL; } @@ -995,6 +982,11 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops) #ifdef CONFIG_DYNAMIC_FTRACE extern void ftrace_graph_call(void); +static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr) +{ + return ftrace_text_replace(0xe9, ip, addr); +} + static int ftrace_mod_jmp(unsigned long ip, void *func) { unsigned char *new; -- 2.20.1