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 1446480064 for ; Thu, 26 Nov 2026 06:12:56 +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 6AQ6BjsT005893; Thu, 26 Nov 2026 09:11:45 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6BjsT005893 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="yD3XhyL5" 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 6AQ67nN7005331 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 09:07:50 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ67nN7005331 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c505eecba6cso527350966b.1 for ; Wed, 25 Nov 2026 22:07:49 -0800 (PST) X-Gm-Message-State: APuU4Z81iONWZVKnPM9lAPSsIn4KYE0gjwOqa8W03qYAwYj40ywys+30 CnixqJr8Fu6TbWw1hutqSVeKM79SmsWFfIq1IU7qLBdf7qE9pzmjMKDf3o2wFS2DWZPqXlJW24l bJQzMkUvGSXOwNLgl2ex8ZRF8D/LA0JTEWOlMwgOeTg3nx79TOvUJlg== X-Gm-Gg: AZFdTZf8pBFpb8wpXK//NKgvjCB44wTnDgKrMHF5sPcfS4BbS4Fy3dm/q6r1E3lgC6K /D++kqKZEzagvGyAUeFPZ6W3WQoViYbjizB/wU7ioPr2Ra7ZoktQUg4XyGZbZgaibIlrwzzZcV7 zphguOaW9jOcBfZpxYBokbpgPxaeCMwe1VFVgKKknHtnVHSDRvOQ+dYIIvLar6BcSt8kRyxrJSg 4fVMqsRxvALHeXI9dkvLkWNlJwedw4RgMj37sYa5i1cXWTkTW7yYvRcVfIfgDTD4dmFnYRjXBpF ey71sLeuJwDNgCmsA1XSUA180o/TgTMf3HUuZrM/OqvO52J+932BAwHZSgMxQL9RSgvNWBwC3sz Y4fQ8IMseeTuviE88B5s9tal8 X-Received: by 2002:a17:907:d30c:b0:c51:b939:c993 with SMTP id a640c23a62f3a-c51b939cdb0mr271401366b.27.1795673269316; Wed, 25 Nov 2026 22:07:49 -0800 (PST) X-Received: by 2002:a17:907:d30c:b0:c51:b939:c993 with SMTP id a640c23a62f3a-c51b939cdb0mr271400066b.27.1795673268885; Wed, 25 Nov 2026 22:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795673268; cv=none; d=google.com; s=arc-20260327; b=pKQrGtlm1jtLzwTPHbvJEb+1qlZiepiSOuuciAPkddnI8LFv+cEKT39AmFwBUHmQpB PsR4YIB1XDqhLd+9gPqnY5yE1GnPu8MOUzZqsXzvc1bICKKC0J9x5g0pavH1Fiv5k2d8 QCFW0G9h44uiXMjfuMVZWcjfH/BqPnIcg7082MPCsOJtClqVGeapeIbHzYPipJwhPaYl 7RN6ipMEDbSauDWjBpCrNpBsimLhdNYUoSbWMTvmubjVQvNouizz2GZHk3IbYyj4PKWN 9omY7XB71MNc6liqpBkeZ4OtVLQaYRML9os8Kh26uZlvidtS7R3E2LMWxIB+SLcrfZSe ljRg== 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=Qb6EvvVgLTICgd66davQQ+4AXevWvWkW0ZeyM3MduMA=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=KzzO06n6OVSk1m4NR0t1Br9IapRPz5qFSztUqKVcDCfHF8rI/EH9t/XGhxkRV0w8rW paQP2Wco8tXdynjB1Her+cWKxrhpkrang/S0YExBVqIcYltDGCITmPpKbZsSMW2ULkno 3OgDV4dDQH+V5t4rFfz9GYSlrPLp5x2/HjsaBmS2qw0KGKsTDzckuUWd44lGtjiiqk0x u8dYV7fvg/uIFVbXEQ/W8FTcJQkBcpbD0H4sjviHyOva/S+UzCdnex9aUZJQdkO1U5s3 cg4q7nw3po8kgW6BGKNJN2LVaN1V6etWDs+/1V3/HyETo62Llt3UFRR1dxlZaQzcwDqJ +5Rg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=yD3XhyL5; 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-c513ad01adcsi1334593466b.20.2026.11.25.22.07.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 22:07:48 -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=yD3XhyL5; 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=Qb6EvvVgLTICgd66davQQ+4AXevWvWkW0ZeyM3MduMA=; b=yD3XhyL5QoVL 3xQTIBBvMvhH1fpJ7Jshy8oya5g3qi8i0Y6OUHZyn18HACKJe6T7giNhAQ06EGcQxGE13+qk0aXNT NoK7Ow8jnEEz4nVK+EN2HuZLnsApI2RETY6Hjr3lRgDibTHlLiWKgDTIDX/n31ZilxZEBQ+TyUdXP 3/G0ceu8kYZAzmxQfM7wk5WUqNzbeCL3oRY0iwoXk5cUXGLyvolZQKhiCTRAk9O7B7DxsyrEHHXOn A5Z1cjhwNo1WgmoUU24bKnFV48Hrfu81qSU+bD+Wj4TbOfl0eib6IboqGB/YjlygNDntLCK1Cqoct Xo/jy6dgY+xj+xKNEpUz6A==; 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 1xWSct-00E8nT-0y; Thu, 26 Nov 2026 07:06:45 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 26 Nov 2026 07:07:25 +0200 Message-ID: <20261126060620.2126341-28-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 26/28] ms/objtool/klp: Ignore replacement offset of empty x86 alternatives 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 An x86 alternative with an empty replacement, e.g. the second entry of ALTERNATIVE_2("orig", "repl", ft1, "", ft2) has a replacementlen of zero. Its replacement offset still gets a relocation, but the label it points at is the end of the previous replacement, which is also the beginning of the *next* alternative's replacement. The value is meaningless; get_alt_entry() already ignores it for that reason. klp diff doesn't ignore it. When such an alternative belongs to a changed function, cloning its relocations drags in the unrelated neighboring replacement, along with everything that replacement references. On an x86 clang/lto build an empty alternative in meminfo_proc_show() pulled in the replacement of an alternative in proc_kcore_init(), silently emitting a klp relocation against init text which has long since been freed by the time the patch is applied. Add arch_alt_ignore_new_reloc() and skip such relocations when cloning. This has to be arch specific: on arm64 a zero-length replacement instead identifies an alternative callback, whose replacement offset points at the callback function and must be preserved. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files") Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/7a885b70974795c3417f3358869e62aafd4ef783.1786138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf (cherry picked from commit 636f230ce21e2730072c58280f1fa0bed4a00eed) https://virtuozzo.atlassian.net/browse/VSTOR-156924 Feature: klp-build support Signed-off-by: Eva Kurchatova --- tools/objtool/arch/x86/special.c | 27 +++++++++++++++++++++++++ tools/objtool/include/objtool/special.h | 7 +++++++ tools/objtool/klp-diff.c | 6 +++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c index 09300761f108..161650ac703d 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -1,10 +1,37 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include #include +/* + * An alternative with an empty replacement, e.g. the second entry of + * + * ALTERNATIVE_2("orig", "repl", ft1, "", ft2) + * + * still gets a relocation for its replacement offset. But the label it points + * at is the end of the previous entry's replacement, which is also the + * beginning of the *next* entry's replacement. The value is meaningless: it's + * only ever used with a length of zero. + */ +bool arch_alt_ignore_new_reloc(struct section *sec, unsigned long offset) +{ + unsigned long entry_off; + + if (strcmp(sec->name, ".altinstructions")) + return false; + + entry_off = offset - (offset % ALT_ENTRY_SIZE); + + if (offset - entry_off != ALT_NEW_OFFSET) + return false; + + return !*(unsigned char *)(sec->data->d_buf + entry_off + + ALT_NEW_LEN_OFFSET); +} + void arch_handle_alternative(struct special_alt *alt) { static struct special_alt *group, *prev; diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/include/objtool/special.h index 72d09c0adf1a..39ce3fe557ba 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -32,6 +32,13 @@ int special_get_alts(struct elf *elf, struct list_head *alts); void arch_handle_alternative(struct special_alt *alt); +/* + * Should the reloc at @offset -- the "new" (replacement) field of a special + * section group entry -- be ignored? The meaning of a zero-length replacement + * is arch specific, so the arch decides. + */ +bool arch_alt_ignore_new_reloc(struct section *sec, unsigned long offset); + bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, struct reloc *reloc); diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 694790b8639c..7eac2ef0f73d 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -1250,6 +1250,10 @@ static int clone_sym_relocs(struct elfs *e, struct symbol *patched_sym) !strcmp(patched_reloc->sym->sec->name, ".altinstr_aux")) continue; + if (arch_alt_ignore_new_reloc(patched_sym->sec, + reloc_offset(patched_reloc))) + continue; + ret = convert_reloc_sym(e->patched, patched_reloc); if (ret < 0) { ERROR_FUNC(patched_rsec->base, reloc_offset(patched_reloc), -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel