From patchwork Sat Sep 30 02:53:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 9979059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8431E6037F for ; Sat, 30 Sep 2017 02:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79AE429794 for ; Sat, 30 Sep 2017 02:54:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E413297C4; Sat, 30 Sep 2017 02:54:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5E2329794 for ; Sat, 30 Sep 2017 02:54:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbdI3Cyr (ORCPT ); Fri, 29 Sep 2017 22:54:47 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33531 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752822AbdI3Cyo (ORCPT ); Fri, 29 Sep 2017 22:54:44 -0400 Received: by mail-pg0-f68.google.com with SMTP id u136so890381pgc.0; Fri, 29 Sep 2017 19:54:44 -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=qob96aV46LLoRgzym0jIgBK2NUii0pMQJKTizP9ojOs=; b=T97nKbiZA50CLzr8iibKw19nEFAzlLgCk4xZgSuGYOvunfylQ7d3CluWVd84WYf+gW rj4ULbDqhBQK8qDGwx8JVco2U0AO+DW/so6uoA63rSrT1T9+zMJDZ/6dbyC8SXualRwN iprP6lfJlAgJKq2wMpxH6puwBifni0vNUrfsOiGvxa/Y65YiDwu+CwLNskp4jNiqqWXb teB0uqmLit7t1CKbhp29rYcO9zkXtRCtzt2McHyLL+Xfj9OHStEGwqZLmsEBz6/RtTxL H+aGErUgf+vnTNw1kjBfR+Ss9Dmx7DUGffg5fnM83l4ks06rFZsBQM7/MjWP1Aa59Ie2 rKuw== 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=qob96aV46LLoRgzym0jIgBK2NUii0pMQJKTizP9ojOs=; b=PLzUJ7Hw1O77cjnGFgfDNVJt0BWy3naCYJYu23wAIAYgiaIU9VQIJohNwwnGxK0xSZ P4tzG+iL9DiQiip3GcfUwJVVqMKNv5aMfD6zyjxjP4Idzlw8AwKDjvzwrRvq0osyBpo6 1BhhXYBGy/wJwksNBnpp5J9a4qde5ft2RNMK1oVhXgwbAbsL9gp3aSe6ord+BMpD8Lt0 ZmUkp0qMcRmnwQxavdlJdT0VxvFklYDvtx5TU9FSCa7BNa5hT7rica/ba2NqWa71P5T7 QHOxq5mj/E4lIx38aXAygt1t5hcrqW7lZoCrScKL26ay3B0TMC7sJ9D9LsyF9bAJ68oq DUsg== X-Gm-Message-State: AHPjjUgVJ3DzPWRvdt6k41lQwHYAnAbIMvuJhlL3SXikzucES4OF3Rgm mvpZ5f7MOZC9OdcKsujE+lk= X-Google-Smtp-Source: AOwi7QBlKBaBBq/oab7sWOB3P+OWJeY5C3vRGkXReU7iGG1PlCRAJv42gW0bfDxGGWNWjfRhfnKA5g== X-Received: by 10.101.74.133 with SMTP id b5mr7431716pgu.100.1506740083575; Fri, 29 Sep 2017 19:54:43 -0700 (PDT) Received: from localhost.localdomain ([175.223.27.84]) by smtp.gmail.com with ESMTPSA id b1sm8680714pgn.94.2017.09.29.19.54.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 19:54:43 -0700 (PDT) From: Sergey Senozhatsky To: Petr Mladek , Steven Rostedt Cc: Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , James Bottomley , Helge Deller , Andrew Morton , Jessica Yu , Alexei Starovoitov , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 6/7] symbol lookup: use new kernel and module dereference functions Date: Sat, 30 Sep 2017 11:53:18 +0900 Message-Id: <20170930025319.987-7-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20170930025319.987-1-sergey.senozhatsky@gmail.com> References: <20170930025319.987-1-sergey.senozhatsky@gmail.com> Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Helge Deller # parisc64 Tested-by: Santosh Sivaraj # powerpc64 Acked-by: Michael Ellerman # powerpc64 Tested-by: Tony Luck # ia64 --- Documentation/printk-formats.txt | 20 ++++++++++---------- kernel/kallsyms.c | 1 + kernel/module.c | 1 + lib/vsprintf.c | 5 +---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index 361789df51ec..3adbc4fdd482 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt @@ -50,26 +50,28 @@ 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. We have ``F`` and ``f`` because on ia64, ppc64 and +parisc64 function pointers are indirect and, in fact, are function +descriptors, which require additional dereferencing before we can lookup +the symbol. As of now, ``S`` and ``s`` perform dereferencing on those +platforms (when needed), so ``F`` and ``f`` exist for compatibility +reasons only. + 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 +79,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 b792e814150a..63361de377ad 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 bcd906a39010..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 = (void *)dereference_function_descriptor((unsigned long)ptr); - /* Fallthrough */ case 'S': case 's': case 'B':