Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2241997rdf; Mon, 6 Nov 2023 08:27:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IF978KAWgMjTC332gkhArz7y3AY+GMGutsxbdy2Wi8Kw6EysG5FIBGrspvNbxsBEQ1XFq/+ X-Received: by 2002:a05:6a00:1886:b0:692:a727:1fdd with SMTP id x6-20020a056a00188600b00692a7271fddmr34950401pfh.4.1699288073856; Mon, 06 Nov 2023 08:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699288073; cv=none; d=google.com; s=arc-20160816; b=u5nj1fzxtac2msc8gyDAO7dXW5TDDJAFWWvh9zYXAQM9XOFjUHDk5xiiT28rZlCinQ M7732/f3RomAhblal21iXFZwAk/dUI+m1KVhMJPnrokhjqxTmi3p0Hfd7etzGiYGkbpN Y9z/5Z02FLrR3bOwqZIfF39AzbsJ1pwF08E+3Y7XGYhMkc8qTID81NTzoMul87I2g59Q RZleo+U9RWglB2Yp3rx++L4uPHxMDidNQQAOdT0QwiVoEy7kDdfQve9wo31F3KhmUBAw 3wyUM1wodDbJztoS2H6eer7icckNRW5CTmRrPZekWu6JozhAVGCFHYrY81vNcnW6sbCa c8pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=toIsN5YluhK1lr5tb8LU9OIiJH3LReIfnzzttfHELBo=; fh=vZ6WhgrPPTeFSs0fWRWCKnl4FbJkrfyiREmhm+x1VlA=; b=UNc+AEnGQqfVPDE9imcfWQxcCJb9NdtalKU6LqiBK3J6WrDeiW/IE6MhI2dHzlt9Gv tQEU8CqDKXAWxDZ5lFtyAqiXSOdpmWd+kBrz5YAAWcOWOUz5qECZNH9sdJd2tcebK7uu fGOvAYTJI+pip6HaIS5z47lCXcELNYVAWoTj620TPYhF6SABCkymElUmrlpSl7FAghup lGtnAdayF5ytHejPdbXKzjq1liermc/33jxddBCOhAP7x6DPG2sksjYgwifhh4ecmSif yRHaDxo/KbvHUbMpa70Y01MDiumYOlD7Sn3hOUitssPUyHH6R9VAE/qsqRMiQeQJI0ZH +ovw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="muMZ/PdM"; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id f7-20020a656287000000b00578af609d05si18644pgv.244.2023.11.06.08.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 08:27:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="muMZ/PdM"; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5EDDC80A90C2; Mon, 6 Nov 2023 08:27:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232906AbjKFQ1C (ORCPT + 99 others); Mon, 6 Nov 2023 11:27:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbjKFQ05 (ORCPT ); Mon, 6 Nov 2023 11:26:57 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D59F10DA; Mon, 6 Nov 2023 08:26:48 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 89D202006A; Mon, 6 Nov 2023 16:26:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1699288006; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=toIsN5YluhK1lr5tb8LU9OIiJH3LReIfnzzttfHELBo=; b=muMZ/PdMzdEGYdrBzSbc2tfO3CG+/H4jXg+MByNR1BMW3inVuBkxNhAP9CrjYTXhM6mhyX 82mYFyNwTL55Gmod2ZynXNvGYF7t4RyJVn22qK3jpYRVqSqej5xpALDanmby0LWA+kTOMs yOg7pFb0cr9Z9HqV5NwG3l0aYzhTk9Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1699288006; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=toIsN5YluhK1lr5tb8LU9OIiJH3LReIfnzzttfHELBo=; b=f/pEvAUiGss8lhQB+Y1NdLrRfy1Dq2lf2bHRITC0GOxjtBiDFcRFemCiAujmj4TtKz16cr Rah/sGF/A6DqLGBg== Received: from localhost.cz (lhruska.udp.ovpn2.prg.suse.de [10.100.204.118]) by relay2.suse.de (Postfix) with ESMTP id 2A5092C1C7; Mon, 6 Nov 2023 16:26:46 +0000 (UTC) From: Lukas Hruska To: Petr Mladek , Miroslav Benes , Josh Poimboeuf Cc: Joe Lawrence , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Marcos Paulo de Souza , Lukas Hruska Subject: [PATCH v1 5/5] documentation: Update on livepatch elf format Date: Mon, 6 Nov 2023 17:25:13 +0100 Message-ID: <20231106162513.17556-6-lhruska@suse.cz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231106162513.17556-1-lhruska@suse.cz> References: <20231106162513.17556-1-lhruska@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 08:27:47 -0800 (PST) Add a section to Documentation/livepatch/module-elf-format.rst describing how klp-convert works for fixing relocations. Signed-off-by: Lukas Hruska --- Documentation/livepatch/module-elf-format.rst | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Documentation/livepatch/module-elf-format.rst b/Documentation/livepatch/module-elf-format.rst index a03ed02ec57e..2aa9b11cd806 100644 --- a/Documentation/livepatch/module-elf-format.rst +++ b/Documentation/livepatch/module-elf-format.rst @@ -300,3 +300,70 @@ symbol table, and relocation section indices, ELF information is preserved for livepatch modules and is made accessible by the module loader through module->klp_info, which is a :c:type:`klp_modinfo` struct. When a livepatch module loads, this struct is filled in by the module loader. + +6. klp-convert tool +=================== +The livepatch relocation sections might be created using +scripts/livepatch/klp-convert. It is called automatically during +the build as part of a module post processing. + +The tool is not able to find the symbols and all the metadata +automatically. Instead, all needed information must already be +part of rela entry for the given symbol. Such a rela can +be created easily by using KLP_RELOC_SYMBOL() macro after +the symbol declaration. + +KLP_RELOC_SYMBOL causes that the relocation entries for +the given symbol will be created in the following format:: + + .klp.sym.rela.lp_object.sym_object.sym_name,sympos + ^ ^ ^ ^ ^ ^ ^ ^ ^ + |___________| |_______| |________| |______| | + [A] [B] [C] [D] [E] + +[A] + The symbol name is prefixed with the string ".klp.sym.rela." + +[B] + The name of the object (i.e. "vmlinux" or name of module) which + is livepatched. + +[C] + The name of the object (i.e. "vmlinux" or name of module) to + which the symbol belongs follows immediately after the prefix. + +[D] + The actual name of the symbol. + +[E] + The position of the symbol in the object (as according to kallsyms) + This is used to differentiate duplicate symbols within the same + object. The symbol position is expressed numerically (0, 1, 2...). + The symbol position of a unique symbol is 0. + +Example: +-------- +**Livepatch source code:** + +:: + + extern char *saved_command_line \ + KLP_RELOC_SYMBOL(vmlinux, vmlinux, saved_command_line, 0); + +**`readelf -r -W` output of compiled module:** + +:: + + Relocation section '.rela.text' at offset 0x32e60 contains 10 entries: + Offset Info Type Symbol's Value Symbol's Name + Addend + ... + 0000000000000068 0000003c00000002 R_X86_64_PC32 0000000000000000 .klp.sym.rela.vmlinux.vmlinux.saved_command_line,0 - 4 + ... + +**`readelf -r -W` output of transformed module by klp-convert:** + +:: + + Relocation section '.klp.rela.vmlinux.text' at offset 0x5cb60 contains 1 entry: + Offset Info Type Symbol's Value Symbol's Name + Addend + 0000000000000068 0000003c00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.saved_command_line,0 - 4 -- 2.42.0