{"id":2233271,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2233271/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260506021143.13797-1-xieyuanbin1@huawei.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.1/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/"},"msgid":"<20260506021143.13797-1-xieyuanbin1@huawei.com>","date":"2026-05-06T02:11:43","name":"[V2] powerpc/text-patching: simplify the implementation of ppc_kallsyms_lookup_name()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d4c92f77adeb129a6ba8e45e50eae7ae6bbc0a5b","submitter":{"id":92591,"url":"http://patchwork.ozlabs.org/api/1.1/people/92591/?format=json","name":"Xie Yuanbin","email":"xieyuanbin1@huawei.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260506021143.13797-1-xieyuanbin1@huawei.com/mbox/","series":[{"id":502916,"url":"http://patchwork.ozlabs.org/api/1.1/series/502916/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=502916","date":"2026-05-06T02:11:43","name":"[V2] powerpc/text-patching: simplify the implementation of ppc_kallsyms_lookup_name()","version":2,"mbox":"http://patchwork.ozlabs.org/series/502916/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233271/comments/","check":"success","checks":"http://patchwork.ozlabs.org/api/patches/2233271/checks/","tags":{},"headers":{"Return-Path":"\n <linuxppc-dev+bounces-20495-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256\n header.s=dkim header.b=yNTbuRmo;\n\tdkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com\n header.a=rsa-sha256 header.s=dkim header.b=yNTbuRmo;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-20495-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=45.249.212.187","lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=huawei.com","lists.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256\n header.s=dkim header.b=yNTbuRmo;\n\tdkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com\n header.a=rsa-sha256 header.s=dkim header.b=yNTbuRmo;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com\n (client-ip=45.249.212.187; helo=szxga01-in.huawei.com;\n envelope-from=xieyuanbin1@huawei.com; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9Jmr3ny3z1yJx\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 12:12:28 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4g9Jmq5MQvz2yZ6;\n\tWed, 06 May 2026 12:12:27 +1000 (AEST)","from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4g9Jmj5zYLz2xFl\n\tfor <linuxppc-dev@lists.ozlabs.org>; Wed, 06 May 2026 12:12:21 +1000 (AEST)","from canpmsgout06.his.huawei.com (unknown [172.19.92.157])\n\tby szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4g9JmK4Q6Xz1BFST\n\tfor <linuxppc-dev@lists.ozlabs.org>; Wed,  6 May 2026 10:12:01 +0800 (CST)","from mail.maildlp.com (unknown [172.19.163.0])\n\tby canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4g9Jbn3WcSzRhRT;\n\tWed,  6 May 2026 10:04:37 +0800 (CST)","from kwepemj100009.china.huawei.com (unknown [7.202.194.3])\n\tby mail.maildlp.com (Postfix) with ESMTPS id CC7FD40561;\n\tWed,  6 May 2026 10:12:09 +0800 (CST)","from DESKTOP-A37P9LK.huawei.com (10.67.109.17) by\n kwepemj100009.china.huawei.com (7.202.194.3) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.2.1544.36; Wed, 6 May 2026 10:12:09 +0800"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1778033547;\n\tcv=none;\n b=AYfx/BTds77R0l87GY0hy41oIKBFzBbVE7eqFrdTeteGyJL3qzSCEzkKpuNktcyt0AjLvkZ7+7zhrsWXYMrl3iY985ykX+xU7RJc0m5rwbFBk2p5WPiphx2L+L52jqVddyFtKgEJ3YJCzimznF7gnLX9lzl+9J+G65mrmH/sdSKejiOVNeFCRTQygH4f8bSCzKoIKryJ2OUyoOSLAaSLjsLAFVtBFB4LNtCGBEx/bdjStI8ueQHwW3EnSN+drbXA2VtBcwhG1qjALc9OLxv3W8PCFnticV6sZtSZ+GRMGE066GrrvFCNkEQHTZUX6TAL9cH2H29zEeaAblF32/PuoQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1778033547; c=relaxed/relaxed;\n\tbh=HMqHW+wl1jJEGGmKKzAemuQMuR+F3aEoMElUydaAiH0=;\n\th=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type;\n b=NHBD53+4jEp9Uj2b+CM+Jj76U0oWGANN2UeycjhrRp3sOfMICUYLqJIKvotyWca9hu26CaZkBqu6vkOsVc+GNDO5IDjf+OHkvLxRjPgVa0JqRzFmgpWXiOfPkRe7H7TZiHJlTOvtFETFJRGuQDon8cu++Z9wtqqPJY6ItvTpysCqlPMcNRePtFXGYuT52XhShWw28QcGu4rGLIkTS0HXamtscvRnn/Vi8O4B8Z+kzrGDZtWhtsz6VqmklTWmtIfbv5/CQUet0XJPG02nQygfpni1J700R9k4wgr4s6I9TWf4gnnHFOptUhkcw+GxuqtOMkmeL8peJwxGnbwfvrVKdg==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=huawei.com;\n dkim=pass (1024-bit key;\n unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256\n header.s=dkim header.b=yNTbuRmo;\n dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com\n header.a=rsa-sha256 header.s=dkim header.b=yNTbuRmo; dkim-atps=neutral;\n spf=pass (client-ip=45.249.212.187; helo=szxga01-in.huawei.com;\n envelope-from=xieyuanbin1@huawei.com;\n receiver=lists.ozlabs.org) smtp.mailfrom=huawei.com","dkim-signature":["v=1; a=rsa-sha256; d=huawei.com; s=dkim;\n\tc=relaxed/relaxed; q=dns/txt;\n\th=From;\n\tbh=HMqHW+wl1jJEGGmKKzAemuQMuR+F3aEoMElUydaAiH0=;\n\tb=yNTbuRmolm/SEoq+MkaSp/cYhtRgK4nsCKZwtO3fqA6+9ZhleNRt68Jnv2/RrJISaYn6gSd+u\n\taCx6xYY7OF2l0Uw8iMfP40fycKvDbh7HTo3w3AmhHFNraYyNk8UjMKjfYVfDjZn7E4qgOx7xeYc\n\tcbrTTJrKbUV2daiXo8CM/wE=","v=1; a=rsa-sha256; d=huawei.com; s=dkim;\n\tc=relaxed/relaxed; q=dns/txt;\n\th=From;\n\tbh=HMqHW+wl1jJEGGmKKzAemuQMuR+F3aEoMElUydaAiH0=;\n\tb=yNTbuRmolm/SEoq+MkaSp/cYhtRgK4nsCKZwtO3fqA6+9ZhleNRt68Jnv2/RrJISaYn6gSd+u\n\taCx6xYY7OF2l0Uw8iMfP40fycKvDbh7HTo3w3AmhHFNraYyNk8UjMKjfYVfDjZn7E4qgOx7xeYc\n\tcbrTTJrKbUV2daiXo8CM/wE="],"From":"Xie Yuanbin <xieyuanbin1@huawei.com>","To":"<chleroy@kernel.org>, <maddy@linux.ibm.com>, <mpe@ellerman.id.au>,\n\t<npiggin@gmail.com>, <andriy.shevchenko@intel.com>, <kees@kernel.org>","CC":"<linuxppc-dev@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,\n\t<lilinjie8@huawei.com>, <liaohua4@huawei.com>, <xieyuanbin1@huawei.com>","Subject":"[PATCH V2] powerpc/text-patching: simplify the implementation of\n ppc_kallsyms_lookup_name()","Date":"Wed, 6 May 2026 10:11:43 +0800","Message-ID":"<20260506021143.13797-1-xieyuanbin1@huawei.com>","X-Mailer":"git-send-email 2.53.0","X-Mailing-List":"linuxppc-dev@lists.ozlabs.org","List-Id":"<linuxppc-dev.lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev+help@lists.ozlabs.org>","List-Owner":"<mailto:linuxppc-dev+owner@lists.ozlabs.org>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Archive":"<https://lore.kernel.org/linuxppc-dev/>,\n  <https://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Subscribe":"<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain","X-Originating-IP":"[10.67.109.17]","X-ClientProxiedBy":"kwepems500001.china.huawei.com (7.221.188.70) To\n kwepemj100009.china.huawei.com (7.202.194.3)","X-Spam-Status":"No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,\n\tDKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,\n\tRCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled\n\tversion=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"},"content":"ppc_kallsyms_lookup_name() is called only twice in the kernel code, and\nthe parameters are all constant strings. strnlen(name, KSYM_NAME_LEN) is\ncalled inside ppc_kallsyms_lookup_name(), when the compiler detects that\nKSYM_NAME_LEN is larger then the constant strings,\nthe following error will be triggered:\n```log\n  CC      arch/powerpc/kernel/optprobes.o\nIn file included from ./arch/powerpc/include/asm/kprobes.h:24,\n                 from ./include/linux/kprobes.h:31,\n                 from arch/powerpc/kernel/optprobes.c:8:\nIn function 'ppc_kallsyms_lookup_name',\n    inlined from 'arch_prepare_optimized_kprobe' at arch/powerpc/kernel/optprobes.c:209:21:\n./arch/powerpc/include/asm/text-patching.h:232:13: error: 'strnlen' specified bound 512 exceeds source size 19 [-Werror=stringop-overread]\n  232 |         if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)\n      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\nIn function 'ppc_kallsyms_lookup_name',\n    inlined from 'arch_prepare_optimized_kprobe' at arch/powerpc/kernel/optprobes.c:210:22:\n./arch/powerpc/include/asm/text-patching.h:232:13: error: 'strnlen' specified bound 512 exceeds source size 13 [-Werror=stringop-overread]\n  232 |         if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)\n      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\ncc1: all warnings being treated as errors\n```\n\nThe error can be reproduced in the following ways:\nUse lastest linux-next source, change ppc_kallsyms_lookup_name() to\n__always_inline, use default ppc64_defconfig, set CONFIG_EXPERT=y,\nCONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=n, CONFIG_CC_OPTIMIZE_FOR_SIZE=y,\nand use gcc-14 or a later version for compilation.\n\nSince ppc_kallsyms_lookup_name() is called only twice in the kernel,\nand the parameters are all constant strins, simplify the implementation\nof ppc_kallsyms_lookup_name() and avoid calling strnlen().\n\nCc: Andy Shevchenko <andriy.shevchenko@intel.com>\nCc: Kees Cook <kees@kernel.org>\nSuggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>\nSigned-off-by: Xie Yuanbin <xieyuanbin1@huawei.com>\n---\nv1->v2: https://lore.kernel.org/20260205100517.292858-2-xieyuanbin1@huawei.com\n  - Not use strlen()\n\n arch/powerpc/include/asm/text-patching.h | 50 ++++++++----------------\n 1 file changed, 17 insertions(+), 33 deletions(-)","diff":"diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h\nindex e7f14720f630..2d3f698cb4f1 100644\n--- a/arch/powerpc/include/asm/text-patching.h\n+++ b/arch/powerpc/include/asm/text-patching.h\n@@ -221,39 +221,23 @@ static inline unsigned long ppc_global_function_entry(void *func)\n  * - For ABIv1, we lookup the dot variant.\n  * - For ABIv2, we return the local entry point.\n  */\n-static inline unsigned long ppc_kallsyms_lookup_name(const char *name)\n-{\n-\tunsigned long addr;\n-#ifdef CONFIG_PPC64_ELF_ABI_V1\n-\t/* check for dot variant */\n-\tchar dot_name[1 + KSYM_NAME_LEN];\n-\tbool dot_appended = false;\n-\n-\tif (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)\n-\t\treturn 0;\n-\n-\tif (name[0] != '.') {\n-\t\tdot_name[0] = '.';\n-\t\tdot_name[1] = '\\0';\n-\t\tstrlcat(dot_name, name, sizeof(dot_name));\n-\t\tdot_appended = true;\n-\t} else {\n-\t\tdot_name[0] = '\\0';\n-\t\tstrlcat(dot_name, name, sizeof(dot_name));\n-\t}\n-\taddr = kallsyms_lookup_name(dot_name);\n-\tif (!addr && dot_appended)\n-\t\t/* Let's try the original non-dot symbol lookup\t*/\n-\t\taddr = kallsyms_lookup_name(name);\n-#elif defined(CONFIG_PPC64_ELF_ABI_V2)\n-\taddr = kallsyms_lookup_name(name);\n-\tif (addr)\n-\t\taddr = ppc_function_entry((void *)addr);\n-#else\n-\taddr = kallsyms_lookup_name(name);\n-#endif\n-\treturn addr;\n-}\n+static inline unsigned long __ppc_kallsyms_lookup_name(const char *name)\n+{\n+\tunsigned long addr = kallsyms_lookup_name(name);\n+\n+\tif (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1) && !addr)\n+\t\taddr = kallsyms_lookup_name(name + 1);\n+\tif (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr)\n+\t\taddr = ppc_function_entry((void *)addr);\n+\n+\treturn addr;\n+}\n+\n+#ifdef CONFIG_PPC64_ELF_ABI_V1\n+#define ppc_kallsyms_lookup_name(x)\t__ppc_kallsyms_lookup_name(\".\" x)\n+#else\n+#define ppc_kallsyms_lookup_name(x)\t__ppc_kallsyms_lookup_name(x)\n+#endif\n \n /*\n  * Some instruction encodings commonly used in dynamic ftracing\n","prefixes":["V2"]}