From patchwork Sat Sep 30 02:53:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 9979055 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 E02276037F for ; Sat, 30 Sep 2017 02:54:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5B4229794 for ; Sat, 30 Sep 2017 02:54:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA580297C4; Sat, 30 Sep 2017 02:54:39 +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 1035B29794 for ; Sat, 30 Sep 2017 02:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752821AbdI3Cyi (ORCPT ); Fri, 29 Sep 2017 22:54:38 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:32845 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752649AbdI3Cyg (ORCPT ); Fri, 29 Sep 2017 22:54:36 -0400 Received: by mail-pf0-f194.google.com with SMTP id m28so712142pfi.0; Fri, 29 Sep 2017 19:54:35 -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=ruqaY+XaeGuzsVLe3cCY1dnlhxkPJYbioyL70BUnmHk=; b=VUk5+DUieFn7LXkImPJB+JGN3OD5FSRx+9aesamn2UaTx6iK/sh6BMit76JpV0UdF2 F2UyCD03ukUOQ1epbj3/poige9YEzHy7ojRxWfVu3RuU6BR1qzpnKAEmyiozBL8jBeZB 2Zpaz/KyR7Uv7eGMytneSSyy53+jxA36BIjpCKwK/gWinXgjHcYx/XNCy1YR1SOpsTVu 671pgJtxDK54PQvyfXjXDKhrUEnW7zayf0MtVX6AMXht+jgnGtw+IFA505EFmteo1EwR 4GzcOF0QwCea9r8M8+12ClvqidXIY5DaGLu7Yhmu9ES8BNw9IrErwdglTSeGR2m2mVAr xXuA== 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=ruqaY+XaeGuzsVLe3cCY1dnlhxkPJYbioyL70BUnmHk=; b=FDFhUvogn6yUdk0UHC2+Qpti69HqHBcmWRgEXikJUf5fEFQnyefRTeku37y9DNEAsc PQC8MhZfZLOc0YdRGMgV3ENt3GMWUYTvj9/rfYTuK1pR958aN3UIKlGK796yfR7f/CHl 0QiZHWXNFXKniRaady/YOyR9H5nzjv5FNKe8WwU0/6ZQWxy/4YqZ7cl9Z3XSToskgZpF lGOXMAXBwiqMHS9b0oJuwd9oIJjFnE9Nfu3KAMtWNnt4HET/zYGtT5V7Y0oig1s/sDc/ JgB/YRvpB+mXmz4GvFqgT70qI2gDMuR5CA3V+5vLzqD6VQaTxGQas2AwBzidX5zkTl7J E8Jg== X-Gm-Message-State: AHPjjUjFmf+5CU1ilYud/Cl0Kzn92XCltJq7BHdbiHhNoXGnRB3WXCNU n3jYXq8+P+1XlAWr5v+YEjA= X-Google-Smtp-Source: AOwi7QAKYhhyqerjzfMzG4oJmo5Qn2gsppG2ikuFZTDkBOEu0zcLl5T7QF2+hldJwAt1dQPraELeFQ== X-Received: by 10.98.155.87 with SMTP id r84mr9445613pfd.66.1506740075446; Fri, 29 Sep 2017 19:54:35 -0700 (PDT) Received: from localhost.localdomain ([175.223.27.84]) by smtp.gmail.com with ESMTPSA id b1sm8680714pgn.94.2017.09.29.19.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 19:54:34 -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 5/7] parisc64: Add .opd based function descriptor dereference Date: Sat, 30 Sep 2017 11:53:17 +0900 Message-Id: <20170930025319.987-6-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 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 Signed-off-by: Helge Deller Tested-by: Helge Deller # parisc64 Tested-by: Santosh Sivaraj # powerpc64 Acked-by: Michael Ellerman # powerpc64 Tested-by: Tony Luck # ia64 Reviewed-by: Petr Mladek --- arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++ arch/parisc/include/asm/sections.h | 2 ++ arch/parisc/kernel/module.c | 17 +++++++++++++++++ arch/parisc/kernel/process.c | 9 +++++++++ arch/parisc/kernel/vmlinux.lds.S | 2 ++ 5 files changed, 32 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 59fbe0067112..845ddc9a3421 100644 --- a/arch/parisc/include/asm/sections.h +++ b/arch/parisc/include/asm/sections.h @@ -7,6 +7,8 @@ #ifdef CONFIG_64BIT #undef dereference_function_descriptor unsigned long dereference_function_descriptor(unsigned long); +#undef dereference_kernel_function_descriptor +unsigned long dereference_kernel_function_descriptor(unsigned long); #endif #endif diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index f1a76935a314..28f89b3dcc11 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -66,6 +66,7 @@ #include #include +#include #if 0 #define DEBUGP printk @@ -954,3 +955,19 @@ 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) +{ + unsigned long start_opd = (Elf64_Addr)mod->core_layout.base + + mod->arch.fdesc_offset; + unsigned long end_opd = start_opd + + mod->arch.fdesc_count * sizeof(Elf64_Fdesc); + + if (addr < start_opd || addr >= end_opd) + return addr; + + return dereference_function_descriptor(addr); +} +#endif diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c index d350aa913acc..423bbfe90e2b 100644 --- a/arch/parisc/kernel/process.c +++ b/arch/parisc/kernel/process.c @@ -276,6 +276,15 @@ unsigned long dereference_function_descriptor(unsigned long ptr) ptr = (unsigned long)p; return ptr; } + +unsigned long dereference_kernel_function_descriptor(unsigned long addr) +{ + if (addr < (unsigned long)__start_opd || + addr >= (unsigned long)__end_opd) + return addr; + + return dereference_function_descriptor(addr); +} #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)