From patchwork Sat Sep 16 03:53:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 814459 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xvJWF0BYsz9t16 for ; Sat, 16 Sep 2017 14:02:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GWUxHrCD"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xvJWD68TnzDqYQ for ; Sat, 16 Sep 2017 14:02:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GWUxHrCD"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::244; helo=mail-pf0-x244.google.com; envelope-from=sergey.senozhatsky@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GWUxHrCD"; dkim-atps=neutral Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xvJRD2p7bzDrnj for ; Sat, 16 Sep 2017 13:58:48 +1000 (AEST) Received: by mail-pf0-x244.google.com with SMTP id g65so2071095pfe.1 for ; Fri, 15 Sep 2017 20:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m4NVOdEEbgW+yLsF7VlHqvGOWnvuNQRtnSx21e1b6Bk=; b=GWUxHrCDC9NQnugVSPE13EEAzjg3FO7MWI5lHZ8uYb4UJA08gWv91oqYlETEOoxcDb IxTIwIJygr5NNjw29iyt1sAPwjAgvR4HBDOWpn3M7x1AlILrt49Q5jhauEq8gSfNXSIy VXeDW5mt+/ITH21oFYBA2j8lqil9Byv+c7pyhO9FjeLlu82+Kx8IYcqjT4X8yf2IMVr7 BECWFVC0lSzfaQKkHyNGtaw3CAZXpMst4uRe4ObrtWBIGg9w2ueCoK5AbxLiRYMxhvXV ow/RSmQFDJlGlnJhSDjZgZbhfgWrC4mBiy2RW2Sh0crw91zOJlwKbNG7+ox0PSlO0iV+ La+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m4NVOdEEbgW+yLsF7VlHqvGOWnvuNQRtnSx21e1b6Bk=; b=tfDbRkkhu6eLYWvY+kXBrB+X/t76Cnz/efaKbksu6U1AvjGCwvW524V9y+JBDPaZST x8T76hw9+fDLCGk+zQEo/3mXAO9AOChKyOJ2aZ6DfiADm3QY5slXIgJz3Kx7h3oUSw2A xtZwmKzoWEF0crve57IefSIDmSFPuGq7iaTuDondKbw39lyAdZX0DidTJCchbZWPzEQ9 yf5OcAkb3/7iN0ObjohzBst2FT9KOxlfzajIdNSx/dDXF+vyVTki9mmnkjlLMJoSlA30 NgHsNxcrGNGSZlTxcmBInZoJRr7AO8YfxbdAHXujnQ2NDItpN7xpvnibrJPrPPbp9iWf EcGg== X-Gm-Message-State: AHPjjUioW509ntDmH56kLV68fAqHuvbIuGbDffRm3JjBPfjAsFZQQzjn UiBq9CothUBDaA== X-Google-Smtp-Source: ADKCNb6mwPuyg3VsLqB8A+HCfUVPghXXhZz4raiSj1edh5EUJMxQaWQmff7m8wqvMfgSiRh91pjbmQ== X-Received: by 10.84.238.141 with SMTP id v13mr30891509plk.349.1505534326300; Fri, 15 Sep 2017 20:58:46 -0700 (PDT) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id 76sm4448230pfp.158.2017.09.15.20.58.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 20:58:45 -0700 (PDT) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 1/5] sections: split dereference_function_descriptor() Date: Sat, 16 Sep 2017 12:53:43 +0900 Message-Id: <20170916035347.19705-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> References: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Alexei Starovoitov , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" There are two format specifiers to print out a pointer in symbolic format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two mean exactly the same thing, but some architectures (ia64, ppc64, parisc64) use an indirect pointer for C function pointers, where the function pointer points to a function descriptor (which in turn contains the actual pointer to the code). The '%pF/%pf, when used appropriately, automatically does the appropriate function descriptor dereference on such architectures. The "when used appropriately" part is tricky. Basically this is a subtle ABI detail, specific to some platforms, that made it to the API level and people can be unaware of it and miss the whole "we need to dereference the function" business out. [1] proves that point (note that it fixes only '%pF' and '%pS', there might be '%pf' and '%ps' cases as well). It appears that we can handle everything within the affected arches and make '%pS/%ps' smart enough to retire '%pF/%pf'. Function descriptors live in .opd elf section and all affected arches (ia64, ppc64, parisc64) handle it properly for kernel and modules. So we, technically, can decide if the dereference is needed by simply looking at the pointer: if it belongs to .opd section then we need to dereference it. The kernel and modules have their own .opd sections, obviously, that's why we need to split dereference_function_descriptor() and use separate kernel and module dereference arch callbacks. This patch does the first step, it a) adds dereference_kernel_function_descriptor() function. b) adds a weak alias to dereference_module_function_descriptor() function. So, for the time being, we will have: 1) dereference_function_descriptor() A generic function, that simply dereferences the pointer. There is bunch of places that call it: kgdbts, init/main.c, extable, etc. 2) dereference_kernel_function_descriptor() A function to call on kernel symbols that does kernel .opd section address range test. 3) dereference_module_function_descriptor() A function to call on modules' symbols that does modules' .opd section address range test. [1] https://marc.info/?l=linux-kernel&m=150472969730573 Signed-off-by: Sergey Senozhatsky --- include/asm-generic/sections.h | 4 ++-- include/linux/moduleloader.h | 4 ++++ kernel/module.c | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index e5da44eddd2f..21d2165e531a 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -49,10 +49,10 @@ extern char __ctors_start[], __ctors_end[]; extern __visible const void __nosave_begin, __nosave_end; -/* function descriptor handling (if any). Override - * in asm/sections.h */ +/* Function descriptor handling (if any). Override in asm/sections.h */ #ifndef dereference_function_descriptor #define dereference_function_descriptor(p) (p) +#define dereference_kernel_function_descriptor(p) (p) #endif /* random extra sections (if any). Override diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 4d0cb9bba93e..172904e9cded 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -85,6 +85,10 @@ void module_arch_cleanup(struct module *mod); /* Any cleanup before freeing mod->module_init */ void module_arch_freeing_init(struct module *mod); +/* Dereference module function descriptor */ +unsigned long dereference_module_function_descriptor(struct module *mod, + unsigned long addr); + #ifdef CONFIG_KASAN #include #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) diff --git a/kernel/module.c b/kernel/module.c index de66ec825992..87cdb46863cd 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2121,6 +2121,12 @@ void __weak module_arch_freeing_init(struct module *mod) { } +unsigned long __weak dereference_module_function_descriptor(struct module *mod, + unsigned long addr) +{ + return addr; +} + /* Free a module, remove from lists, etc. */ static void free_module(struct module *mod) { From patchwork Sat Sep 16 03:53:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 814460 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xvJYH6ck7z9t16 for ; Sat, 16 Sep 2017 14:04:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ihzKPt2J"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xvJYH5CLhzDrct for ; Sat, 16 Sep 2017 14:04:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ihzKPt2J"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c05::243; helo=mail-pg0-x243.google.com; envelope-from=sergey.senozhatsky@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ihzKPt2J"; dkim-atps=neutral Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xvJRL5WH9zDrnw for ; Sat, 16 Sep 2017 13:58:54 +1000 (AEST) Received: by mail-pg0-x243.google.com with SMTP id d8so2241256pgt.3 for ; Fri, 15 Sep 2017 20:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OfRmoCKaZTxH76f85Hvnq8h3YMNL73s6OtfMeyJchEA=; b=ihzKPt2JNphNcRhzF55U+ViPAtPrQmrI4I8wS+uNzN58qPLY5oP3FWev2QdTmCt1h8 s7JnP2zWINouAfPuaeoP1QXqNPESvMKATqc0+QIYSeDQ9VxzQzPng1sETMy6vwziSOFm tE9W6TFPC9Bww4gwudoAVpBeuYnSrjaKtBXvhLTNIw1GdqofUeYrcomKjQXkoggrHI08 iJ6h4pAsD7NVc2XbPEbJX9qVT9rZZHPY6Tp7255fOc0VB+xW1Ici3AXwihBPaahFpjb2 uqi6sGgghRXeWHQddHwcAsgzwZSBRDf4Gohtsh5gB4cqx34se+4ItzqwU73DrnW6wJnT DHXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OfRmoCKaZTxH76f85Hvnq8h3YMNL73s6OtfMeyJchEA=; b=WCFmAGiZ2agoZTLaGc6kMvE8AhSA35G0dYOCj3BoPQYnjRF8CwlQ/OtkPt2S/7f4MT /mryn08+LlC+EK5o+c1zbYiLKkdRIy2r0IupXJSTXTYlVNFvvR+G92d6FYkYJuSyjO9D 4fWzSjiOoYw621XC8Oe8Ntvvx5aX2EoLd4kIQ+l+rPeGEl4KwMikcxxY4r5pkFk7Xyl3 alu/2QGilTiqqnrH2GO3CGf6VDfuib+PLh9EMU1B0SpBb6QOj3KBPwXgV94Z3twjsaf0 Go82uH3iCdTqgk2EDkmoYAcgUHr+4edT5i14G51DEsJOmZWbNPi/EigUF0VM97+xKajp vtlg== X-Gm-Message-State: AHPjjUhmeoDuMwKjDnbsXbVWDU/ocpUwlsSsHNqqjazIyQf2dxn1Ue/3 +CmXJjOlTVd3SA== X-Google-Smtp-Source: ADKCNb5+5Kec3ncfrrAw+emYdbKrMNgzOmgON9Y0elrR2xm82eoL2rFLeoBQGYifIqWj24otNRYx4g== X-Received: by 10.84.225.2 with SMTP id t2mr30313733plj.425.1505534332715; Fri, 15 Sep 2017 20:58:52 -0700 (PDT) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id 76sm4448230pfp.158.2017.09.15.20.58.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 20:58:52 -0700 (PDT) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 2/5] ia64: Add .opd based function descriptor dereference Date: Sat, 16 Sep 2017 12:53:44 +0900 Message-Id: <20170916035347.19705-3-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> References: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Alexei Starovoitov , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" We are moving towards separate kernel and module function descriptor dereference callbacks. This patch enables it for IA64. For pointers that belong to the kernel - Added __start_opd and __end_opd pointers, to track the kernel .opd section address range; - Added dereference_kernel_function_descriptor(). Now we will dereference only function pointers that are within [__start_opd, __end_opd]; For pointers that belong to a module - Added dereference_module_function_descriptor() to handle module function descriptor dereference. Now we will dereference only pointers that are within [module->opd.start, module->opd.end]. Signed-off-by: Sergey Senozhatsky --- arch/ia64/include/asm/sections.h | 14 +++++++++++++- arch/ia64/kernel/module.c | 13 +++++++++++++ arch/ia64/kernel/vmlinux.lds.S | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/ia64/include/asm/sections.h b/arch/ia64/include/asm/sections.h index 2ab2003698ef..bff3f3535609 100644 --- a/arch/ia64/include/asm/sections.h +++ b/arch/ia64/include/asm/sections.h @@ -25,8 +25,11 @@ extern char __start_gate_fsyscall_patchlist[], __end_gate_fsyscall_patchlist[]; extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_bubble_down_patchlist[]; extern char __start_unwind[], __end_unwind[]; extern char __start_ivt_text[], __end_ivt_text[]; +extern char __start_opd[], __end_opd[]; #undef dereference_function_descriptor +#undef dereference_kernel_function_descriptor + static inline void *dereference_function_descriptor(void *ptr) { struct fdesc *desc = ptr; @@ -37,6 +40,15 @@ static inline void *dereference_function_descriptor(void *ptr) return ptr; } +static inline void *dereference_kernel_function_descriptor(void *ptr) +{ + /* + * Check if the ptr is a function descriptor and thus needs to + * be dereferenced. + */ + if (ptr < (void *)__start_opd || (void *)__end_opd < ptr) + return ptr; + return dereference_function_descriptor(ptr); +} #endif /* _ASM_IA64_SECTIONS_H */ - diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c index d1d945c6bd05..d42f1e19d75d 100644 --- a/arch/ia64/kernel/module.c +++ b/arch/ia64/kernel/module.c @@ -35,6 +35,7 @@ #include #include +#include #define ARCH_MODULE_DEBUG 0 @@ -917,3 +918,15 @@ module_arch_cleanup (struct module *mod) if (mod->arch.core_unw_table) unw_remove_unwind_table(mod->arch.core_unw_table); } + +unsigned long dereference_module_function_descriptor(struct module *mod, + unsigned long addr) +{ + Elf64_Shdr *opd = mod->arch.opd; + + if (addr < opd->sh_addr || + (opd->sh_addr + opd->sh_size) < addr) + return addr; + + return dereference_function_descriptor(addr); +} diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S index 798026dde52e..f872ba5ff82a 100644 --- a/arch/ia64/kernel/vmlinux.lds.S +++ b/arch/ia64/kernel/vmlinux.lds.S @@ -107,7 +107,9 @@ SECTIONS { RODATA .opd : AT(ADDR(.opd) - LOAD_OFFSET) { + __start_opd = .; *(.opd) + __end_opd = .; } /* From patchwork Sat Sep 16 03:53:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 814461 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xvJbT3CG8z9t16 for ; Sat, 16 Sep 2017 14:05:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n79MRlF2"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xvJbT23srzDrnj for ; Sat, 16 Sep 2017 14:05:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n79MRlF2"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::244; helo=mail-pf0-x244.google.com; envelope-from=sergey.senozhatsky@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n79MRlF2"; dkim-atps=neutral Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xvJRS1NklzDrnY for ; Sat, 16 Sep 2017 13:59:00 +1000 (AEST) Received: by mail-pf0-x244.google.com with SMTP id i23so2069426pfi.2 for ; Fri, 15 Sep 2017 20:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KYXU6Z1rehKcw0LU74adwCML4qq4/Y5wszCe6R2duPs=; b=n79MRlF2JtUgaE8k+s4aCoQUdpFfI/c1g79hYpWqgt00QG0zr4WLO80sOByJPmbwYN Krxcde6niBj9JtrNy5v9Gx8sqNMcQ3eNPDtUxb6yj97f7koH/jllcVEvQD7Df+YgOE30 3H+rz1U2jw5Eo5GI7lP8Tjt6AaOEkTktvtb/MohkEaBRGqwoVGbbs17DRqruD9iDa61f bKP7fD4wQD5t0gaoTQqyTFQsUMqRhIetaqsDfEmWHkW3yV0GdENhfQBXxKvDr9ni4i+7 OyY2N6lNQc5b1+r4KXZ1YTUMHhpFwWOhtg+fecuIR/K1DDTOUK+iWYcO9dwjpG0fS7IQ 5uGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KYXU6Z1rehKcw0LU74adwCML4qq4/Y5wszCe6R2duPs=; b=Y9l4SlbCtc5PTEmR6+Cf5LD3Urbqwa1FO0u2v99rknJPyHrylio17Ge7ecNjpKxYzL I1+W47/ujieMxfcO74W9Im6+oBQNsidQgSB/LKeq7LTboVsriXv+mJG2XSKtkP7pTN49 ue0MFBhWhLHB3uJCD61cImNArP0OnPUU+KHKUMSYZnK9KPnJonoKJZoQewumQgOt8Rqh VqNy/gS8XB62v9cIREoi9RQEYV6/dXkTzncTftN7EiigPLaikDXT4M/VIAWSL64g9FZQ CTBiyF38P0qgSouQghVQkyyhy9x+eYss9vKpP0yxhufLGNIE8jbrpyqCcI8XgWBj0jXl G6BA== X-Gm-Message-State: AHPjjUibniwA85QCNdLhLHSvaTaCrUxvzNk4D5Eh3cYjLaZok/it9bCl XSfXUjdJm5IPng== X-Google-Smtp-Source: AOwi7QB6S+1oUsVca4OFvW6fapm9NwjRHGXpnapfYqOTzsmAZ/kDoXq7rQV8BPu1IEwaieiW352AsQ== X-Received: by 10.159.194.201 with SMTP id u9mr9387881plz.142.1505534338124; Fri, 15 Sep 2017 20:58:58 -0700 (PDT) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id 76sm4448230pfp.158.2017.09.15.20.58.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 20:58:57 -0700 (PDT) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 3/5] powerpc64: Add .opd based function descriptor dereference Date: Sat, 16 Sep 2017 12:53:45 +0900 Message-Id: <20170916035347.19705-4-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> References: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Alexei Starovoitov , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" We are moving towards separate kernel and module function descriptor dereference callbacks. This patch enables it for powerpc64. For pointers that belong to the kernel - Added __start_opd and __end_opd pointers, to track the kernel .opd section address range; - Added dereference_kernel_function_descriptor(). Now we will dereference only function pointers that are within [__start_opd, __end_opd]; For pointers that belong to a module - Added dereference_module_function_descriptor() to handle module function descriptor dereference. Now we will dereference only pointers that are within [module->opd.start, module->opd.end]. Signed-off-by: Sergey Senozhatsky --- arch/powerpc/include/asm/module.h | 3 +++ arch/powerpc/include/asm/sections.h | 13 +++++++++++++ arch/powerpc/kernel/module_64.c | 16 ++++++++++++++++ arch/powerpc/kernel/vmlinux.lds.S | 2 ++ 4 files changed, 34 insertions(+) diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/module.h index 6c0132c7212f..7e28442827f1 100644 --- a/arch/powerpc/include/asm/module.h +++ b/arch/powerpc/include/asm/module.h @@ -45,6 +45,9 @@ struct mod_arch_specific { unsigned long tramp; #endif + /* For module function descriptor dereference */ + unsigned long start_opd; + unsigned long end_opd; #else /* powerpc64 */ /* Indices of PLT sections within module. */ unsigned int core_plt_section; diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h index 7902d6358854..7cc4db86952b 100644 --- a/arch/powerpc/include/asm/sections.h +++ b/arch/powerpc/include/asm/sections.h @@ -16,6 +16,9 @@ extern char __end_interrupts[]; extern char __prom_init_toc_start[]; extern char __prom_init_toc_end[]; +extern char __start_opd[]; +extern char __end_opd[]; + static inline int in_kernel_text(unsigned long addr) { if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end) @@ -66,6 +69,8 @@ static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end) #ifdef PPC64_ELF_ABI_v1 #undef dereference_function_descriptor +#undef dereference_kernel_function_descriptor + static inline void *dereference_function_descriptor(void *ptr) { struct ppc64_opd_entry *desc = ptr; @@ -75,6 +80,14 @@ static inline void *dereference_function_descriptor(void *ptr) ptr = p; return ptr; } + +static inline void *dereference_kernel_function_descriptor(void *ptr) +{ + if (ptr < (void *)__start_opd || (void *)__end_opd < ptr) + return ptr; + + return dereference_function_descriptor(ptr); +} #endif /* PPC64_ELF_ABI_v1 */ #endif diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 0b0f89685b67..52aa5d668364 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -344,6 +344,11 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr, else if (strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0) dedotify_versions((void *)hdr + sechdrs[i].sh_offset, sechdrs[i].sh_size); + else if (strcmp(secstrings + sechdrs[i].sh_name, ".opd")==0) { + me->arch.start_opd = sechdrs[i].sh_offset; + me->arch.end_opd = me->arch.start_opd + + sechdrs[i].sh_size; + } /* We don't handle .init for the moment: rename to _init */ while ((p = strstr(secstrings + sechdrs[i].sh_name, ".init"))) @@ -712,6 +717,17 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, return 0; } +#ifdef PPC64_ELF_ABI_v1 +unsigned long dereference_module_function_descriptor(struct module *mod, + unsigned long addr) +{ + if (addr < mod->arch.start_opd || mod->arch.end_opd < addr) + return addr; + + return dereference_function_descriptor(addr); +} +#endif /* PPC64_ELF_ABI_v1 */ + #ifdef CONFIG_DYNAMIC_FTRACE #ifdef CC_USING_MPROFILE_KERNEL diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 882628fa6987..70e10251e083 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -277,7 +277,9 @@ SECTIONS } .opd : AT(ADDR(.opd) - LOAD_OFFSET) { + __start_opd = .; *(.opd) + __end_opd = .; } . = ALIGN(256); From patchwork Sat Sep 16 03:53:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 814462 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xvJdk5Z03z9t16 for ; Sat, 16 Sep 2017 14:07:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B9yS/sQa"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xvJdk4MrtzDrnw for ; Sat, 16 Sep 2017 14:07:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B9yS/sQa"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c05::244; helo=mail-pg0-x244.google.com; envelope-from=sergey.senozhatsky@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B9yS/sQa"; dkim-atps=neutral Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xvJRY4c6JzDrnl for ; Sat, 16 Sep 2017 13:59:05 +1000 (AEST) Received: by mail-pg0-x244.google.com with SMTP id m30so2240752pgn.5 for ; Fri, 15 Sep 2017 20:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pbzYOzxbOw6DTwzifZOrQKTCkzmMvM1AuZ6bZBhn/8I=; b=B9yS/sQadvK96q1aIc5hTaldbqGJxKmWOZVclkuWvDhvllUkDv+5wFFmCKpgn1cLAA H7x9e98ZIsQ419oDJTJOLNfBYbEsPb/JH/HTuykLHWC5G0jZPQlpDkXFK5An/HMo5XUZ OD6OOc3LTqA1qF0EgGHjQGttdLlEccIX56KeA/MP80uN8d2RWuiP9IE5wuatW+QzCCK4 sOMICC26mnYTXqWayqsA4IACV674ytavudrLB4ND1rmxXKlm3k1Sknzz82CEDunNamzv DCQ/HJiGSRSkWJ2JkQ7qTpyjJGeALAgDZfwJTjxTyDkvtYspdsruMEx98/CovfT/c3xd 2Y/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pbzYOzxbOw6DTwzifZOrQKTCkzmMvM1AuZ6bZBhn/8I=; b=C8tOJskilY8rLhJ6427w8oGV7HAxW/XKh9Ef2mUQYL5kwyKnB4FRJzX5rWBzOtovrN clrMpmW937eyuZrVeWXH5m9e7LPnMKRsCgdlmh9Hk9XUn31+GXH5ZjwBOy6xOtYdJW6g YPqhkGug7vF9uXwtpP+YcgRL5Nu4c1X6udLPwFe/DzYrt6ucNlEy0faqr6GRpmgz7cGk +3w6Fp7mmg3BrfwQ1QDLhykDRklvQRkWC0dxqEhlGuAtlO4zAmE5nuHr9OrJDoAyC8MN qOedGiRrX/n4seK1QPzThwuM1oRiVtx/EOUAACSOrBcpKx6xaepTvTreXUTvrTzpLTIL 60bw== X-Gm-Message-State: AHPjjUjlLcVxWyvI9v/FnBrGniNbVu8CxHGme0ybU6tk32Zl2UkTHMJH dNry5p1hLa6eUw== X-Google-Smtp-Source: ADKCNb72JBLpCpXAZRIhvidNNJivAjezU/LFSmdoHpDu8p3KLbsGSzVCVXfc4iL0d9r2cUj11lkcHA== X-Received: by 10.99.126.84 with SMTP id o20mr26925543pgn.293.1505534343684; Fri, 15 Sep 2017 20:59:03 -0700 (PDT) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id 76sm4448230pfp.158.2017.09.15.20.58.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 20:59:03 -0700 (PDT) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 4/5] parisc64: Add .opd based function descriptor dereference Date: Sat, 16 Sep 2017 12:53:46 +0900 Message-Id: <20170916035347.19705-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> References: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Alexei Starovoitov , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" We are moving towards separate kernel and module function descriptor dereference callbacks. This patch enables it for parisc64. For pointers that belong to the kernel - Added __start_opd and __end_opd pointers, to track the kernel .opd section address range; - Added dereference_kernel_function_descriptor(). Now we will dereference only function pointers that are within [__start_opd, __end_opd]; For pointers that belong to a module - Added dereference_module_function_descriptor() to handle module function descriptor dereference. Now we will dereference only pointers that are within [module->opd.start, module->opd.end]. Signed-off-by: Sergey Senozhatsky --- arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++ arch/parisc/include/asm/sections.h | 3 +++ arch/parisc/kernel/module.c | 14 ++++++++++++++ arch/parisc/kernel/process.c | 10 ++++++++++ arch/parisc/kernel/vmlinux.lds.S | 2 ++ 5 files changed, 31 insertions(+) diff --git a/arch/parisc/boot/compressed/vmlinux.lds.S b/arch/parisc/boot/compressed/vmlinux.lds.S index a4ce3314e78e..4ebd4e65524c 100644 --- a/arch/parisc/boot/compressed/vmlinux.lds.S +++ b/arch/parisc/boot/compressed/vmlinux.lds.S @@ -29,7 +29,9 @@ SECTIONS . = ALIGN(16); /* Linkage tables */ .opd : { + __start_opd = .; *(.opd) + __end_opd = .; } PROVIDE (__gp = .); .plt : { *(.plt) diff --git a/arch/parisc/include/asm/sections.h b/arch/parisc/include/asm/sections.h index 9d13c3507ad6..e3cde650b2f9 100644 --- a/arch/parisc/include/asm/sections.h +++ b/arch/parisc/include/asm/sections.h @@ -6,7 +6,10 @@ #ifdef CONFIG_64BIT #undef dereference_function_descriptor +#undef dereference_kernel_function_descriptor + void *dereference_function_descriptor(void *); +void *dereference_kernel_function_descriptor(void *); #endif #endif diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index f1a76935a314..bc2eae8634fd 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -954,3 +954,17 @@ void module_arch_cleanup(struct module *mod) { deregister_unwind_table(mod); } + +#ifdef CONFIG_64BIT +unsigned long dereference_module_function_descriptor(struct module *mod, + unsigned long addr) +{ + void *opd_sz = mod->arch.fdesc_offset + + mod->arch.fdesc_max * sizeof(Elf64_Fdesc); + + if (addr < mod->arch.fdesc_offset || opd_sz < addr) + return addr; + + return dereference_function_descriptor(addr); +} +#endif diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c index 30f92391a93e..f30776bdaa79 100644 --- a/arch/parisc/kernel/process.c +++ b/arch/parisc/kernel/process.c @@ -267,6 +267,8 @@ get_wchan(struct task_struct *p) } #ifdef CONFIG_64BIT +extern char __start_opd[], __end_opd[]; + void *dereference_function_descriptor(void *ptr) { Elf64_Fdesc *desc = ptr; @@ -276,6 +278,14 @@ void *dereference_function_descriptor(void *ptr) ptr = p; return ptr; } + +void *dereference_kernel_function_descriptor(void *ptr) +{ + if (ptr < (void *)__start_opd || (void *)__end_opd < ptr) + return ptr; + + return dereference_function_descriptor(ptr); +} #endif static inline unsigned long brk_rnd(void) diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S index ffe2cbf52d1a..ab030895dd1e 100644 --- a/arch/parisc/kernel/vmlinux.lds.S +++ b/arch/parisc/kernel/vmlinux.lds.S @@ -99,7 +99,9 @@ SECTIONS . = ALIGN(16); /* Linkage tables */ .opd : { + __start_opd = .; *(.opd) + __end_opd = .; } PROVIDE (__gp = .); .plt : { *(.plt) From patchwork Sat Sep 16 03:53:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 814463 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xvJgl3Hqfz9t16 for ; Sat, 16 Sep 2017 14:09:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oiBW2WKd"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xvJgl22HmzDrp3 for ; Sat, 16 Sep 2017 14:09:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oiBW2WKd"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::242; helo=mail-pf0-x242.google.com; envelope-from=sergey.senozhatsky@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oiBW2WKd"; dkim-atps=neutral Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xvJRg34q5zDrhx for ; Sat, 16 Sep 2017 13:59:11 +1000 (AEST) Received: by mail-pf0-x242.google.com with SMTP id g65so2071349pfe.1 for ; Fri, 15 Sep 2017 20:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jqMjDFZPlndvRBevPf6/l+Sbczz31K9fx87lxL4edT4=; b=oiBW2WKdxlwW9vsvbFYtD7e8dUTs1YXu3AFEShaY4CzfbJ/yOB9nIQlqztpnapR1BE qQjUprLVJnlEFlhwJ6ut07uJCp7cxRVUDQx6VirY4/Qz63Lk8u35eE8lbHZZe05Dv+pZ MR9IyqhhAez2WVnPxWl3ZqrIWWtfc1yCQfb9HH0jMa5xb1a5nAKYC4z704CdUmjwXmp/ fWFROfT/meCHa4RD3on2hGDW799q07nbiX9SBxFLLyKkC6gNJm7ArJM+woSlix1P/bvB d5kvMogyTS2DoFYY308UWMStKo81zKDWeLEr+q5t2uoRlZX9tBm5EQ0Kitdd2JqajMUO h4WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jqMjDFZPlndvRBevPf6/l+Sbczz31K9fx87lxL4edT4=; b=lsGJ7ws+4Lu/fV+okjfN9Q7I4hlZDUPn+bZtz7mEz5sSnoaEPVB3z4cy2KAq8dGAIc K6M366skaVc4q6kkgjngt5x6a+gFL5CIDTNbEsVzNu/bdQXi+Yhc3K7XXCfLmr48BzDn WlLRNkIB86m5j4PnQQ27LZw/nlONprXXmZpe48OJuFGv8x4PPH0KmnhUhdkhNie4zipl yJyWazXtkhCqeycNdcOGgpCzHVMcUYp1gV/QGbxTFrrJ1lv0NK3TqvUFImA0FPSSWazV uxfh1igjvt1nU+E3GRELCeBSp/2XnpItlxdBoFDjaqCy8DnBNH3EMv7ymz0VCIbLVJ4g /aVA== X-Gm-Message-State: AHPjjUhWEnSWRLXHu8ICxjcW9bm3raeFiC9d1+J0x9AutkeAfnnaozj/ qXxIbKLiT+UpdQ== X-Google-Smtp-Source: ADKCNb4X5vFccnXsuJlsc4soNewupyWR/oxNEKfrTixQS056WWEFvtXUduzjurNjJIeQc+SqxXbJrA== X-Received: by 10.84.174.67 with SMTP id q61mr29826581plb.242.1505534349202; Fri, 15 Sep 2017 20:59:09 -0700 (PDT) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id 76sm4448230pfp.158.2017.09.15.20.59.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 20:59:08 -0700 (PDT) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 5/5] symbol lookup: use new kernel and module dereference functions Date: Sat, 16 Sep 2017 12:53:47 +0900 Message-Id: <20170916035347.19705-6-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> References: <20170916035347.19705-1-sergey.senozhatsky@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, Alexei Starovoitov , Steven Rostedt , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Call appropriate function descriptor dereference ARCH callbacks: - dereference_kernel_function_descriptor() if the pointer is a kernel symbol; - dereference_module_function_descriptor() if the pointer is a module symbol. This patch also removes dereference_function_descriptor() from '%pF/%pf' vsprintf handler, because it has the same behavior with '%pS/%ps' now. Signed-off-by: Sergey Senozhatsky --- Documentation/printk-formats.txt | 15 +++++---------- kernel/kallsyms.c | 1 + kernel/module.c | 1 + lib/vsprintf.c | 5 +---- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index 361789df51ec..b2afafc84638 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt @@ -50,26 +50,23 @@ Symbols/Function Pointers :: + %pS versatile_init+0x0/0x110 + %ps versatile_init %pF versatile_init+0x0/0x110 %pf versatile_init - %pS versatile_init+0x0/0x110 %pSR versatile_init+0x9/0x110 (with __builtin_extract_return_addr() translation) - %ps versatile_init %pB prev_fn_of_versatile_init+0x88/0x88 -The ``F`` and ``f`` specifiers are for printing function pointers, -for example, f->func, &gettimeofday. They have the same result as -``S`` and ``s`` specifiers. But they do an extra conversion on -ia64, ppc64 and parisc64 architectures where the function pointers -are actually function descriptors. - The ``S`` and ``s`` specifiers can be used for printing symbols from direct addresses, for example, __builtin_return_address(0), (void *)regs->ip. They result in the symbol name with (``S``) or without (``s``) offsets. If KALLSYMS are disabled then the symbol address is printed instead. +Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``) +and thus deprecated. + The ``B`` specifier results in the symbol name with offsets and should be used when printing stack backtraces. The specifier takes into consideration the effect of compiler optimisations which may occur @@ -77,8 +74,6 @@ when tail-call``s are used and marked with the noreturn GCC attribute. Examples:: - printk("Going to call: %pF\n", gettimeofday); - printk("Going to call: %pF\n", p->func); printk("%s: called from %pS\n", __func__, (void *)_RET_IP_); printk("%s: called from %pS\n", __func__, (void *)__builtin_return_address(0)); diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 127e7cfafa55..e2fc09ea9509 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -322,6 +322,7 @@ const char *kallsyms_lookup(unsigned long addr, if (is_ksym_addr(addr)) { unsigned long pos; + addr = dereference_kernel_function_descriptor(addr); pos = get_symbol_pos(addr, symbolsize, offset); /* Grab name */ kallsyms_expand_symbol(get_symbol_offset(pos), diff --git a/kernel/module.c b/kernel/module.c index 87cdb46863cd..4f591f2bbf5a 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3948,6 +3948,7 @@ const char *module_address_lookup(unsigned long addr, preempt_disable(); mod = __module_address(addr); if (mod) { + addr = dereference_module_function_descriptor(mod, addr); if (modname) *modname = mod->name; ret = get_ksymbol(mod, addr, size, offset); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 86c3385b9eb3..bf04b4f5d8e7 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -40,7 +40,6 @@ #include "../mm/internal.h" /* For the trace_print_flags arrays */ #include /* for PAGE_SIZE */ -#include /* for dereference_function_descriptor() */ #include /* cpu_to_le16 */ #include @@ -1721,10 +1720,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, } switch (*fmt) { - case 'F': + case 'F': /* %pF and %pf are kept for compatibility reasons only */ case 'f': - ptr = dereference_function_descriptor(ptr); - /* Fallthrough */ case 'S': case 's': case 'B':