From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 97EB680032 for ; Thu, 26 Nov 2026 06:13:12 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ6C1Fr005991; Thu, 26 Nov 2026 09:12:02 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6C1Fr005991 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="SkXHWYBu" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ681t6005377 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 09:08:01 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ681t6005377 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c50a8e37286so640825866b.3 for ; Wed, 25 Nov 2026 22:08:01 -0800 (PST) X-Gm-Message-State: APuU4Z8Jerv3vhw0VEVaeY6ApiQOiZRxLLqjaTMIo7R4TZXhrGWHzwOx GAFOSmuR4k2ed6Ss+kjaD+7I1fucSk60QuKi/sZKBrnDThNR1O4+qLh8M7zmSQO5DocfAJPFZgn 4OPOx4VYO9LotDsPIhUNwk8pL9cDU3CL/1wYYN9rZrgcTKWxIpgFueg== X-Gm-Gg: AZFdTZf8l+9033O7rCKEibbRCANtRwehWupTzsHhF/xftNPyLibY7aEhUKEoyDqKsfN y4xewcRd/SpeHIMfqaLF4cl3uey/xZO8Fi960j2ta2JMbXfNOmUDj/O1CoISyAWwo555jsp+t9Y IhGceFmWbz8m0NWMSdO7E+RkZTe/Fbo03G5SpcwClO2nRCIcoJ/iDG8WYmcXmMMI6543hIQ1GE/ 5UlxrxZIBSAb/8NBcYvuSgFT7gKQqJFtklxu1CtZQpQKpNYUDeSTx+G5qlQUukgNdkOxnEMCFEa 3tR3g12P6DFlsaTyMIkB4G57jHzo9vB6glX981mgTXrC6PqgZFRwg0++owXrcmRr8xLXm4s/Clk eYrxM0nS/ZD1qU6R8wp7aYBan X-Received: by 2002:a17:906:1408:b0:c51:fcf:a966 with SMTP id a640c23a62f3a-c513aaade52mr1200602966b.35.1795673280891; Wed, 25 Nov 2026 22:08:00 -0800 (PST) X-Received: by 2002:a17:906:1408:b0:c51:fcf:a966 with SMTP id a640c23a62f3a-c513aaade52mr1200601966b.35.1795673280385; Wed, 25 Nov 2026 22:08:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795673280; cv=none; d=google.com; s=arc-20260327; b=YlWYMRBgqITvUXZWaJvNEEslzocl5REQv2fOUmx+wOc98I8aM9N2LpoZQmuYklXRCq YqmrWJYQ2YUSu2FGT1hQgpsHRoMQg5om54NwMGiLzO3WSCyL9P1cY6HC74TDtHfbYx2w xULrtdp01FPLcUmZqiQDrrRUWhMiKn2P9s7dZk54Uben7eP99vnco8Dpd/aB7M+sp61x QKHgovAS0pf8iJcNUSPHdn7+MgwL+ry/MIrOSOunXwOCyucrxnX7Vaz1mM6y7gIn1TV4 Ottb7RQ8gOBoJBlT+bM8Ny3xMdjUE4zGIQqQCSVqo9vQpnhqs8hXPjbrfcKVWii46U4y O5Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ChKHGt9EYzvcKzzBO4VupulkhTPXT9KoDirTmrmeFJk=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=j46khJUAumwY1p2jWVaLlatfZotSh5XMTdeytMJeKGW3m1OD/sELIzRagyT+N/WLMb +LOXkxCvigc+Da8PQJVM2Ba/tVC/Mc5qbwjGW5L8aih7fVO5KB8qVoWgJLQUucLDgiII qTA2FJK9FDu/2tAASpjevoAQ9RQbYWF6dtZ4GTBVi9hpPW+GRAve8rpyauvXGtcOBv2i NH7Y3ytg6/Gfcsh8+87aA9N/ls6Amx9zrU1oi3NL/SZo61OezsFpVxpxsDjOsluB35z/ sm6EPUq90oYmAFzp8QpGpuGGlm6+HPfaFkJPgjDv66kwbttlIyfNtVkTyPhjCp4FhC94 kkKg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=SkXHWYBu; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513afe2a56si1296342666b.61.2026.11.25.22.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 22:08:00 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=SkXHWYBu; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=ChKHGt9EYzvcKzzBO4VupulkhTPXT9KoDirTmrmeFJk=; b=SkXHWYBuI5vi UnFjSbsPNxunutKY1VRdqPvWlR6zE6etSBlwCK8TCZy2UCiaII+yOY3llTOZYIMYS349Z6OrS3j4m hkWIyzrntO2uGZ4cZv1VByuGIxCf9eBOkoedQPeoebAtwYEEBOvMqo5DYDWEwqLUteeJddsDLjid1 zSFr6er8PNpSFFdcGCtxfXtwDJgfjtGxkLAtVTMUUsit/I1Ol4hUretfWqPNQST98T14LroMO7jSA quiu3/HtdWycZXLIf/adsO/T14rRmWHLomgGpUB4XxIL/KXyJqI17LYWmjAi9mxYys3UDsPwrEXbH f4AhI8RVESUhosonYdxM0Q==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWScq-00E8nT-3C; Thu, 26 Nov 2026 07:06:43 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 26 Nov 2026 07:07:17 +0200 Message-ID: <20261126060620.2126341-20-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> References: <20261126060620.2126341-2-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 18/28] ms/objtool/klp: Fix cross-module klp relocation section naming X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Josh Poimboeuf A klp relocation section is .klp.rela.., where objname is the object being patched. klp-build wrongly derives objname from where the referenced symbol lives, not where it's referenced. For a cross-module reference like patched can_isotp code calling can.ko's can_rx_unregister(), that gives .klp.rela.can..text rather than .klp.rela.can_isotp..text. Unless the patch happens to patch can.ko as well, the relocation never gets applied and the call goes off into the weeds. Name the intermediate section __klp_relocs. so post-link can read the patched object's name from there. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files") Reported-by: Joe Lawrence Link: https://lore.kernel.org/20260720145658.1103243-2-joe.lawrence@redhat.com Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/ee93a08f3e55e76ffa67d04e283917ddaa893f09.1786138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf (cherry picked from commit 07f14d6af9d7791fdc2b44a3dd0693e42c71d2b8) https://virtuozzo.atlassian.net/browse/VSTOR-128510 Feature: klp-build support Signed-off-by: Eva Kurchatova --- tools/objtool/include/objtool/klp.h | 10 ++++-- tools/objtool/klp-diff.c | 17 +++++++-- tools/objtool/klp-post-link.c | 53 +++++++++++++++++------------ 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h index ad830a7ce55b..d9cb594f4924 100644 --- a/tools/objtool/include/objtool/klp.h +++ b/tools/objtool/include/objtool/klp.h @@ -14,11 +14,15 @@ #define KLP_FUNCS_SEC "__klp_funcs" /* - * __klp_relocs is an intermediate section which are created by klp diff and - * converted into KLP symbols/relas by "objtool klp post-link". This is needed - * to work around the linker, which doesn't preserve SHN_LIVEPATCH or + * __klp_relocs. are intermediate sections which are created by klp + * diff and converted into KLP symbols/relas by "objtool klp post-link". This + * is needed to work around the linker, which doesn't preserve SHN_LIVEPATCH or * SHF_RELA_LIVEPATCH, nor does it support having two RELA sections for a * single PROGBITS section. + * + * "objname" is the name of the object being patched ("vmlinux" or a module + * name). post-link uses it to name the resulting + * .klp.rela.objname.section_name sections. */ #define KLP_RELOCS_SEC "__klp_relocs" #define KLP_STRINGS_SEC ".rodata.klp.str1.1" diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 5b14005f8eee..a2483b404b66 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1143,8 +1143,8 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, } /* - * Create the __klp_relocs entry. This will be converted to an actual - * KLP rela by "objtool klp post-link". + * Create the __klp_relocs. entry. This will be converted to + * an actual KLP rela by "objtool klp post-link". * * This intermediate step is necessary to prevent corruption by the * linker, which doesn't know how to properly handle two rela sections @@ -1152,7 +1152,18 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, */ if (!klp_relocs) { - klp_relocs = elf_create_section(e->out, KLP_RELOCS_SEC, 0, + const char *objname = find_modname(e); + char sec_name[SEC_NAME_LEN]; + + if (!objname) + return -1; + + /* section format: __klp_relocs.objname */ + if (snprintf_check(sec_name, SEC_NAME_LEN, + KLP_RELOCS_SEC ".%s", objname)) + return -1; + + klp_relocs = elf_create_section(e->out, sec_name, 0, 0, SHT_PROGBITS, 8, SHF_ALLOC); if (!klp_relocs) return -1; diff --git a/tools/objtool/klp-post-link.c b/tools/objtool/klp-post-link.c index c013e39957b1..350d20495897 100644 --- a/tools/objtool/klp-post-link.c +++ b/tools/objtool/klp-post-link.c @@ -19,19 +19,11 @@ #include #include -static int fix_klp_relocs(struct elf *elf) +static int fix_klp_reloc_sec(struct elf *elf, struct section *symtab, + struct section *klp_relocs) { - struct section *symtab, *klp_relocs; - - klp_relocs = find_section_by_name(elf, KLP_RELOCS_SEC); - if (!klp_relocs) - return 0; - - symtab = find_section_by_name(elf, ".symtab"); - if (!symtab) { - ERROR("missing .symtab"); - return -1; - } + /* section format: __klp_relocs.sec_objname */ + const char *sec_objname = klp_relocs->name + strlen(KLP_RELOCS_SEC "."); for (int i = 0; i < sec_size(klp_relocs) / sizeof(struct klp_reloc); i++) { struct klp_reloc *klp_reloc; @@ -39,7 +31,6 @@ static int fix_klp_relocs(struct elf *elf) struct section *sec, *tmp, *klp_rsec; unsigned long offset; struct reloc *reloc; - char sym_modname[64]; char rsec_name[SEC_NAME_LEN]; u64 addend; struct symbol *sym, *klp_sym; @@ -55,7 +46,7 @@ static int fix_klp_relocs(struct elf *elf) reloc = find_reloc_by_dest(elf, klp_relocs, klp_reloc_off + offsetof(struct klp_reloc, offset)); if (!reloc) { - ERROR("malformed " KLP_RELOCS_SEC " section"); + ERROR("malformed %s section", klp_relocs->name); return -1; } @@ -66,17 +57,13 @@ static int fix_klp_relocs(struct elf *elf) reloc = find_reloc_by_dest(elf, klp_relocs, klp_reloc_off + offsetof(struct klp_reloc, sym)); if (!reloc) { - ERROR("malformed " KLP_RELOCS_SEC " section"); + ERROR("malformed %s section", klp_relocs->name); return -1; } klp_sym = reloc->sym; addend = reloc_addend(reloc); - /* symbol format: .klp.sym.modname.sym_name,sympos */ - if (sscanf(klp_sym->name + strlen(KLP_SYM_PREFIX), "%55[^.]", sym_modname) != 1) - ERROR("can't find modname in klp symbol '%s'", klp_sym->name); - /* * Create the KLP rela: */ @@ -84,7 +71,7 @@ static int fix_klp_relocs(struct elf *elf) /* section format: .klp.rela.sec_objname.section_name */ if (snprintf_check(rsec_name, SEC_NAME_LEN, KLP_RELOC_SEC_PREFIX "%s.%s", - sym_modname, sec->name)) + sec_objname, sec->name)) return -1; klp_rsec = find_section_by_name(elf, rsec_name); @@ -134,10 +121,32 @@ static int fix_klp_relocs(struct elf *elf) return 0; } +static int fix_klp_relocs(struct elf *elf) +{ + struct section *symtab, *sec; + + symtab = find_section_by_name(elf, ".symtab"); + if (!symtab) { + ERROR("missing .symtab"); + return -1; + } + + for_each_sec(elf, sec) { + if (strncmp(sec->name, KLP_RELOCS_SEC ".", + strlen(KLP_RELOCS_SEC "."))) + continue; + + if (fix_klp_reloc_sec(elf, symtab, sec)) + return -1; + } + + return 0; +} + /* * This runs on the livepatch module after all other linking has been done. It - * converts the intermediate __klp_relocs section into proper KLP relocs to be - * processed by livepatch. This needs to run last to avoid linker wreckage. + * converts the intermediate __klp_relocs.* sections into proper KLP relocs to + * be processed by livepatch. This needs to run last to avoid linker wreckage. * Linkers don't tend to handle the "two rela sections for a single base * section" case very well, nor do they appreciate SHN_LIVEPATCH. */ -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel