{"id":816362,"url":"http://patchwork.ozlabs.org/api/patches/816362/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20170920162910.32053-5-sergey.senozhatsky@gmail.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<20170920162910.32053-5-sergey.senozhatsky@gmail.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20170920162910.32053-5-sergey.senozhatsky@gmail.com/","date":"2017-09-20T16:29:06","name":"[RFC,v2,4/7] powerpc64: Add .opd based function descriptor dereference","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"447872c72eb7d6e79c2bf966f61bc6ee0b560ecd","submitter":{"id":3905,"url":"http://patchwork.ozlabs.org/api/people/3905/?format=json","name":"Sergey Senozhatsky","email":"sergey.senozhatsky@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20170920162910.32053-5-sergey.senozhatsky@gmail.com/mbox/","series":[{"id":4171,"url":"http://patchwork.ozlabs.org/api/series/4171/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=4171","date":"2017-09-20T16:29:02","name":"printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers","version":2,"mbox":"http://patchwork.ozlabs.org/series/4171/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816362/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816362/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xy57b605dz9t2Q\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 02:39:55 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xy57b2WdHzDqY3\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 02:39:55 +1000 (AEST)","from mail-pg0-x242.google.com (mail-pg0-x242.google.com\n\t[IPv6:2607:f8b0:400e:c05::242])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xy4vx3Pv0zDqXp\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tThu, 21 Sep 2017 02:29:49 +1000 (AEST)","by mail-pg0-x242.google.com with SMTP id d8so1911938pgt.3\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 20 Sep 2017 09:29:49 -0700 (PDT)","from localhost.localdomain ([121.137.63.184])\n\tby smtp.gmail.com with ESMTPSA id\n\tc185sm8890567pfb.57.2017.09.20.09.29.42\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tWed, 20 Sep 2017 09:29:47 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qT+NjFfZ\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qT+NjFfZ\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gmail.com\n\t(client-ip=2607:f8b0:400e:c05::242; helo=mail-pg0-x242.google.com;\n\tenvelope-from=sergey.senozhatsky@gmail.com; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qT+NjFfZ\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=CnpHgZ2+ZTbCeZd1Ck+ekMy+VDRmM6IJjtCT7xMUDx0=;\n\tb=qT+NjFfZCLQ+T28UFYOveLZbPebjdNHNDpSawkskKAh78+fZUB7mF6vKhqke6hUtE+\n\tt8KLdhyP2uSNMiOzmf5qo3TXOMY4x0ZNGV9iovw5+ElQ46EMoKEXzZxzII+LQ87Lma6O\n\t16wqhqrmam07MQtdAL9DzybtPJ0SnRRjc3IMsSwU0EHIUj/TagxQyzWCqq0HaupEmE4F\n\tk89vTKN1T1LwBwqS/LfRJqOpGiJSXiYR2vH7wpAIChBWhOoARyqx0B/m2K5oTY2b6h8k\n\tG788Kbsx+l/2NdSdgNd7/TZXzZM/1M+coMb2fBzvLdrnVVNGvmBixyPddhC+IDcnUplX\n\tSgEw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=CnpHgZ2+ZTbCeZd1Ck+ekMy+VDRmM6IJjtCT7xMUDx0=;\n\tb=l+YZhT8CjAV1FfKkWHulo9e/zRi89IZTJ8Ei7b4yGwrqgTGc6cyueR6uLSuC+feyQa\n\tBiEUY2us1Z0wdBs/SV/UvYYGVjxSPfPlWO4x3NpN5U2/FqU0VD0QMlHK9a2dWGTGnjRz\n\tIiihsSI3hexIDQLKcn565KqovhYRtFLseq8YYYkiRGF0yPnSHNS8hBS7z8rstxH5Zoxy\n\txPxc4XkV9VO+xBmu07DCzEXc/eAP3t/e3Q86qB3rpm8Z45S1H765Yvt9zsFLT+C+XOrc\n\t1Ofyoi9YbZac8dM75GK4loBEsr7H7bcdxLubbTr1rjua9OGzf7ncwFxug1l6Q2ALC9ob\n\t4cUw==","X-Gm-Message-State":"AHPjjUhHZ2jmqW0semJaZm86z/xrZKc7a7xDPBNM5iW47Hozz5PyVpeh\n\tUKMhQMLk3MVBrvX7r8M2GNY=","X-Google-Smtp-Source":"AOwi7QCrWWE7JWto/ELgrvGD7Q73g/KaZRTUdedeG7gRRvMzwtVaqTFnXpCqR3nF+W0msrQuVMrdsg==","X-Received":"by 10.84.194.1 with SMTP id g1mr2651908pld.74.1505924987817;\n\tWed, 20 Sep 2017 09:29:47 -0700 (PDT)","From":"Sergey Senozhatsky <sergey.senozhatsky@gmail.com>","To":"Tony Luck <tony.luck@intel.com>, Fenghua Yu <fenghua.yu@intel.com>,\n\tBenjamin Herrenschmidt <benh@kernel.crashing.org>,\n\tPaul Mackerras <paulus@samba.org>,\n\tMichael Ellerman <mpe@ellerman.id.au>, \n\tJames Bottomley <jejb@parisc-linux.org>, Helge Deller <deller@gmx.de>","Subject":"[RFC][PATCH v2 4/7] powerpc64: Add .opd based function descriptor\n\tdereference","Date":"Thu, 21 Sep 2017 01:29:06 +0900","Message-Id":"<20170920162910.32053-5-sergey.senozhatsky@gmail.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170920162910.32053-1-sergey.senozhatsky@gmail.com>","References":"<20170920162910.32053-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\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"Petr Mladek <pmladek@suse.com>, linux-ia64@vger.kernel.org,\n\tlinux-parisc@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,\n\tSteven Rostedt <rostedt@goodmis.org>, linux-kernel@vger.kernel.org,\n\tSergey Senozhatsky <sergey.senozhatsky@gmail.com>,\n\tJessica Yu <jeyu@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, \n\tlinuxppc-dev@lists.ozlabs.org","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"},"content":"We are moving towards separate kernel and module function descriptor\ndereference callbacks. This patch enables it for powerpc64.\n\nFor pointers that belong to the kernel\n-  Added __start_opd and __end_opd pointers, to track the kernel\n   .opd section address range;\n\n-  Added dereference_kernel_function_descriptor(). Now we\n   will dereference only function pointers that are within\n   [__start_opd, __end_opd];\n\nFor pointers that belong to a module\n-  Added dereference_module_function_descriptor() to handle module\n   function descriptor dereference. Now we will dereference only\n   pointers that are within [module->opd.start, module->opd.end].\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\n---\n arch/powerpc/include/asm/module.h   |  3 +++\n arch/powerpc/include/asm/sections.h | 11 +++++++++++\n arch/powerpc/kernel/module_64.c     | 16 ++++++++++++++++\n arch/powerpc/kernel/vmlinux.lds.S   |  2 ++\n 4 files changed, 32 insertions(+)","diff":"diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/module.h\nindex 6c0132c7212f..7e28442827f1 100644\n--- a/arch/powerpc/include/asm/module.h\n+++ b/arch/powerpc/include/asm/module.h\n@@ -45,6 +45,9 @@ struct mod_arch_specific {\n \tunsigned long tramp;\n #endif\n \n+\t/* For module function descriptor dereference */\n+\tunsigned long start_opd;\n+\tunsigned long end_opd;\n #else /* powerpc64 */\n \t/* Indices of PLT sections within module. */\n \tunsigned int core_plt_section;\ndiff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h\nindex 67379b8945e8..6b4ee0d1645f 100644\n--- a/arch/powerpc/include/asm/sections.h\n+++ b/arch/powerpc/include/asm/sections.h\n@@ -75,6 +75,17 @@ static inline unsigned long dereference_function_descriptor(unsigned long ptr)\n \t\tptr = (unsigned long)p;\n \treturn ptr;\n }\n+\n+#undef dereference_kernel_function_descriptor\n+static inline unsigned long\n+dereference_kernel_function_descriptor(unsigned long addr)\n+{\n+\tif (addr < (unsigned long)__start_opd ||\n+\t\t\taddr >= (unsigned long)__end_opd)\n+\t\treturn addr;\n+\n+\treturn dereference_function_descriptor(addr);\n+}\n #endif /* PPC64_ELF_ABI_v1 */\n \n #endif\ndiff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c\nindex 0b0f89685b67..94caec045a90 100644\n--- a/arch/powerpc/kernel/module_64.c\n+++ b/arch/powerpc/kernel/module_64.c\n@@ -344,6 +344,11 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,\n \t\telse if (strcmp(secstrings+sechdrs[i].sh_name,\"__versions\")==0)\n \t\t\tdedotify_versions((void *)hdr + sechdrs[i].sh_offset,\n \t\t\t\t\t  sechdrs[i].sh_size);\n+\t\telse if (!strcmp(secstrings + sechdrs[i].sh_name, \".opd\")) {\n+\t\t\tme->arch.start_opd = sechdrs[i].sh_addr;\n+\t\t\tme->arch.end_opd = sechdrs[i].sh_addr +\n+\t\t\t\t\t   sechdrs[i].sh_size;\n+\t\t}\n \n \t\t/* We don't handle .init for the moment: rename to _init */\n \t\twhile ((p = strstr(secstrings + sechdrs[i].sh_name, \".init\")))\n@@ -712,6 +717,17 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,\n \treturn 0;\n }\n \n+#ifdef PPC64_ELF_ABI_v1\n+unsigned long dereference_module_function_descriptor(struct module *mod,\n+\t\t\t\t\t\t     unsigned long addr)\n+{\n+\tif (addr < mod->arch.start_opd || addr >= mod->arch.end_opd)\n+\t\treturn addr;\n+\n+\treturn dereference_function_descriptor(addr);\n+}\n+#endif /* PPC64_ELF_ABI_v1 */\n+\n #ifdef CONFIG_DYNAMIC_FTRACE\n \n #ifdef CC_USING_MPROFILE_KERNEL\ndiff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S\nindex 882628fa6987..70e10251e083 100644\n--- a/arch/powerpc/kernel/vmlinux.lds.S\n+++ b/arch/powerpc/kernel/vmlinux.lds.S\n@@ -277,7 +277,9 @@ SECTIONS\n \t}\n \n \t.opd : AT(ADDR(.opd) - LOAD_OFFSET) {\n+\t\t__start_opd = .;\n \t\t*(.opd)\n+\t\t__end_opd = .;\n \t}\n \n \t. = ALIGN(256);\n","prefixes":["RFC","v2","4/7"]}