From patchwork Thu Nov 9 23:48:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 10052141 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 E7651601EA for ; Thu, 9 Nov 2017 23:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D89512B1FD for ; Thu, 9 Nov 2017 23:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB0F22B1F6; Thu, 9 Nov 2017 23:51:40 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 ADF692B1F9 for ; Thu, 9 Nov 2017 23:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755380AbdKIXuq (ORCPT ); Thu, 9 Nov 2017 18:50:46 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:55484 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755383AbdKIXul (ORCPT ); Thu, 9 Nov 2017 18:50:41 -0500 Received: by mail-pg0-f67.google.com with SMTP id 207so3205605pgc.12; Thu, 09 Nov 2017 15:50:41 -0800 (PST) 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=+/1dx3IeNeIDHtj+Ai5Hr5JIinukDMvP/AsT4drYWSU=; b=Qz02/UqTZjrQZuMAhPecrwT2ySlkXcZutcjs9rDNVp90AYgNXe4zmht+eDbidxX55s a9KgU/Zq28BgF8B4iZodWZcpXHg1tR7Ds7hcJmK0L+d1PJGikHauF0iqJaSf0wNUkCHL +DGceiSXEruoZuOc2bnIMD5517eVwt8840l+ABZriai4bOHfoPNX6HsIpB1TykKgyizO Qb9fCPclCevSVOyLywdWBP8XOntYjZcuTvbX42ZH0cv0OQ0NAcghGZ2kEFOwB/AzhzzA +FK6TcpPQuwrUd9xkCtby9z53CnpXqc1OZo3vY4pjUor94WxYbZ3c0dCJV0mPp0/myy3 jtrA== 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=+/1dx3IeNeIDHtj+Ai5Hr5JIinukDMvP/AsT4drYWSU=; b=R/HA2Un/4h8Hz40zz9JpqFnK/Gpj+N4UhuLSHtDyY5rJa/GBcVWR8KUoT5hbnnIinL UUjAB6xwUqtnAyWUqKgbZ9BxBpUw7o/rbt1qssNb1bk7x7XAdhWn0EiUbLJjlDgL60e9 V7rvgQgoliyWywx7RPn9An6V37b0GWgdLPyDZSuj5A5lYJUK5kyBynGWgUr7fKcUd4u+ 7JGxhkF5JVHHDkyIfNrk3tGlf6H6sFtO9C8zwfSXzPqQriBgIoE92WVzO1PfbvU5vzzI SyImujQ8FIEcYXmjsE2AivbyKAs8jqNs3/pcddxVLXkFEOL9Tuj9nKmXaiFY3BC3pfnb /aJA== X-Gm-Message-State: AJaThX4s49Nh2MPoJ/NUgWteMkvDMx+IDlAw8THizeLsYNunT/1F/6eS AfJsaD6tjKiM13nCgEbWebM= X-Google-Smtp-Source: ABhQp+RksV95Q5byTkrd/iXACOmhI33iJHVU6jSGJzXPpWqKT7V9I6WS9rwL2CFeAfXvDuWtZ+oItw== X-Received: by 10.101.97.20 with SMTP id z20mr2056794pgu.267.1510271440564; Thu, 09 Nov 2017 15:50:40 -0800 (PST) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id t25sm13160477pfh.67.2017.11.09.15.50.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 15:50:40 -0800 (PST) From: Sergey Senozhatsky To: Tony Luck , Fenghua Yu , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , James Bottomley Cc: Andrew Morton , Jessica Yu , Petr Mladek , Steven Rostedt , linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv4 3/6] powerpc64: Add .opd based function descriptor dereference Date: Fri, 10 Nov 2017 08:48:27 +0900 Message-Id: <20171109234830.5067-4-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171109234830.5067-1-sergey.senozhatsky@gmail.com> References: <20171109234830.5067-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 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 Tested-by: Santosh Sivaraj # for powerpc --- arch/powerpc/include/asm/module.h | 3 +++ arch/powerpc/include/asm/sections.h | 12 ++++++++++++ arch/powerpc/kernel/module_64.c | 14 ++++++++++++++ arch/powerpc/kernel/vmlinux.lds.S | 2 ++ 4 files changed, 31 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 82bec63bbd4f..e335a8f846af 100644 --- a/arch/powerpc/include/asm/sections.h +++ b/arch/powerpc/include/asm/sections.h @@ -66,6 +66,9 @@ static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end) } #ifdef PPC64_ELF_ABI_v1 + +#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1 + #undef dereference_function_descriptor static inline void *dereference_function_descriptor(void *ptr) { @@ -76,6 +79,15 @@ static inline void *dereference_function_descriptor(void *ptr) ptr = p; return ptr; } + +#undef dereference_kernel_function_descriptor +static inline void *dereference_kernel_function_descriptor(void *ptr) +{ + if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd) + 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 759104b99f9f..218971ac7e04 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -93,6 +93,15 @@ static unsigned int local_entry_offset(const Elf64_Sym *sym) { return 0; } + +void *dereference_module_function_descriptor(struct module *mod, void *ptr) +{ + if (ptr < (void *)mod->arch.start_opd || + ptr >= (void *)mod->arch.end_opd) + return ptr; + + return dereference_function_descriptor(ptr); +} #endif #define STUB_MAGIC 0x73747562 /* stub */ @@ -344,6 +353,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")) { + me->arch.start_opd = sechdrs[i].sh_addr; + me->arch.end_opd = sechdrs[i].sh_addr + + sechdrs[i].sh_size; + } /* We don't handle .init for the moment: rename to _init */ while ((p = strstr(secstrings + sechdrs[i].sh_name, ".init"))) diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 0494e1566ee2..5dac5ab22fa2 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -278,7 +278,9 @@ SECTIONS } .opd : AT(ADDR(.opd) - LOAD_OFFSET) { + __start_opd = .; *(.opd) + __end_opd = .; } . = ALIGN(256);