Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp627640img; Fri, 22 Mar 2019 05:27:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzazqVRb9xSkzMfAOO+/PKFFcbuTeMbgvwPfCQP4xu+gmhZ7V7JJs4fhFQOPBfySFDHfGpV X-Received: by 2002:a62:3001:: with SMTP id w1mr8801868pfw.59.1553257655172; Fri, 22 Mar 2019 05:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257655; cv=none; d=google.com; s=arc-20160816; b=EZb8S6bHjwQrwHBPaGEqiMYj9qSEWNN7wzdmvlN5jPIWgE09SBqEKFJyD+fvBl4NIg Be+8gDRe0lP1CYELi3mhyjGY6GNL+EJTker8VRimGeeuA/4KxyeHU9mLiZ7Z3T2w/XLH RQJrq12ni2+kgnoNtpUlX5B8Tb28gAZQH495td+WGhajOq36NPjXHbIfSdag8pOU2Qbg eiTRqrdGyW9I3SNzy1RcipaYBaBwvWzU6hDEu3larCmgtaQ5Axc7DeqHwzCJ1NybNepu MXiCHuP0EccVAUAc9SUAmpevriqw9K8SyIrL2fs5jtdoM0SuBzKGE+DUbSidtJTjPirH 5yuw== 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=NyFrcn0He/8oWvzsr7SXWqKB2vMzCuM/xsdfnMkT3JM=; b=vAfyjMO9JzBFdJUNnep4wUSjMbrFfmEy6DUgNqqBtBckdcIlZ/T6Eg6RZY0sLF2fIJ vDSXt4e2FFe+lyZi8S3dF+OULrVJMcQCzrhqL5OvOCpI5tn7GuZAXknF0nJ0ooTdPbwo /F0nZeWidr1ctmVKgKTerjf8zTwflEAqLqfakMFhbVHyu4Y8dDBXBaSgD8Ocb3jPnQJF 7HN4+zMPa6P+/IwhAEolhVBpJl+ayPsMS+0S1PdFdMY6HMHIPfBY0K3/V7b8xyLnffc4 LgT57KVQ2x0vaOSzis6KncE1DVkCbUmWe8da5X5M/s/u/G4Oq1PQfZj+h2Tts4y8Muja myIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OUF+olZ1; 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 f3si6614075pfn.122.2019.03.22.05.27.20; Fri, 22 Mar 2019 05:27:35 -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=OUF+olZ1; 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 S2391042AbfCVMWm (ORCPT + 99 others); Fri, 22 Mar 2019 08:22:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:33796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390690AbfCVMWh (ORCPT ); Fri, 22 Mar 2019 08:22:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 CBFEB218A1; Fri, 22 Mar 2019 12:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257356; bh=SPGBBFlhDeXCvcNzV56+nEJeslCF3XtixKVPsQXxPqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OUF+olZ10MKRJi6mGM4SD/DIheRJ2ir4w+tuQQYYeonXC51aBv/C2j+E+17DocytA VZ8c9wutCL7V6+uGGnAsHVVh39wFlbL0L27K6rRsIByHp/gaKe2833Sd0SJsb1tDLC MGLlSyhy6LfxQb+bpgsr8WTEReX3lX6Co2FKwl8c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , "Steven Rostedt (VMware)" Subject: [PATCH 5.0 208/238] x86/ftrace: Fix warning and considate ftrace_jmp_replace() and ftrace_call_replace() Date: Fri, 22 Mar 2019 12:17:07 +0100 Message-Id: <20190322111310.514952475@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 745cfeaac09ce359130a5451d90cb0bd4094c290 upstream. 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: Greg Kroah-Hartman --- arch/x86/kernel/ftrace.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -49,7 +49,7 @@ int ftrace_arch_code_modify_post_process union ftrace_code_union { char code[MCOUNT_INSN_SIZE]; struct { - unsigned char e8; + unsigned char op; int offset; } __attribute__((packed)); }; @@ -59,20 +59,23 @@ static int ftrace_calc_offset(long ip, l 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) { @@ -664,22 +667,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 @@ -891,8 +878,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; } @@ -963,6 +950,11 @@ void arch_ftrace_trampoline_free(struct #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;