Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5548315ybi; Tue, 30 Jul 2019 23:09:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNfA9wpq7ygkVg+ct1pMdN4qihmqEgJd6dF6WzZ8QQLO9JiK2trzZCMvt7GPOjNN1d/AWT X-Received: by 2002:a17:902:76c7:: with SMTP id j7mr115282520plt.247.1564553347436; Tue, 30 Jul 2019 23:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564553347; cv=none; d=google.com; s=arc-20160816; b=TxQqmuppob3p9vVmerdvqA3LWrNJ4G1J5Nvi/XcoDRDlHuhBYQnnZVNN3JRla4kldW M2Zru02IswpTEwQMH6fDIK34fGFkNHX6EjYRWa+6MtxXgeJO7Mv33TjWw3m7WRl3VnFs JXJvbo/JDbNiYaJnPHloWhcz60OMEk5Ma2vcTO9CktNFWmq+W4dzbULFr9nnfPidQlhs WnAO0Rjfw3wXuN6z0Ck/a07C5XEGFcwLHnUvF8r+gAHdgXO23FyiUQjQfyIBo6qqaKBg za7zpTvLqVIXsC2NhXTUPkfLjsEHYG/HeAicGh2z4r4MFNWs25O2r/79e1bgNDi9zwpM 0miA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=m6crFz6hHWQ6uC1VqWw4SBmJlXxX1Oxyb3RZsSUOdZE=; b=QAOPi86uAP8xLmXG15kkWEySp3CYah0xdJOJMy/4wfA42FOyQQCkAZ3OaNJzOstF97 GXaOr4lXJNcA1yMQZJBNNytyxd6D1+gVO/PCms0ODztJTOKzNCC05qTARAmkGJJRxHo9 gYyAB3vBCr3ClAAPmnbY7xOJPt86yc+iR44Oxs7jBRjZNVsUE+2B9mjKrX05z+djsjnW D5YOgHDMjqPd/jBkhShnCrzD350YIZ+HHTOPtaanbNM6QW72bk6FXmwhVXkILmqXOZMh buO4m48c+SnQpU9ixr/rOfD0hR56zcoDLRl4ufOJFxWho2Zq3JV5C+S2OIrCpsY+EFrA 2rFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=AZ7rfQ2J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63si30295517pge.113.2019.07.30.23.08.51; Tue, 30 Jul 2019 23:09:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=AZ7rfQ2J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbfGaCvN (ORCPT + 99 others); Tue, 30 Jul 2019 22:51:13 -0400 Received: from conssluserg-06.nifty.com ([210.131.2.91]:19894 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbfGaCvM (ORCPT ); Tue, 30 Jul 2019 22:51:12 -0400 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (authenticated) by conssluserg-06.nifty.com with ESMTP id x6V2oueF031454; Wed, 31 Jul 2019 11:50:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com x6V2oueF031454 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1564541459; bh=m6crFz6hHWQ6uC1VqWw4SBmJlXxX1Oxyb3RZsSUOdZE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AZ7rfQ2J2rZvxOZBxH8+52vTeD/7Iqo/gz++mYxVnGkvlqn9gQhZ109Uorvhx4mIu yRv/86EOQz9IsE5mMYkKTmxun2J/0PtpjvHPc7Bk7i9z2z0ajIn1Gx3mJVjK3Aafi+ z6Yq82csrNJqwQIQqXx7pgk+P+8/MyjJn7yAdHqg3RQXNKxfzI7keh44An84YMlUYK LrMAB9cYEUcKkDYlcK0Y+21JSBEF5gtA82cVmq8zQCySnl3dOyYT2vBOhy7OqsT4ih OvqCTM3bSEcYAgK3F69V0gjR6mWA5RqXckiCX8/oyDsJ7J/7ozY/bfGmNB9vk2Vc/y EbO7Bvx1I0P5Q== X-Nifty-SrcIP: [209.85.217.44] Received: by mail-vs1-f44.google.com with SMTP id m8so45217853vsj.0; Tue, 30 Jul 2019 19:50:58 -0700 (PDT) X-Gm-Message-State: APjAAAXn+PNml88Yn5YTyUEdqN3IFhSvdFT8bynYHjJ0IgNrK8g2tyor 2+xKVZmWuy7P3O1OhOpOyBtXdJloD0yOczKtOW8= X-Received: by 2002:a67:8e0a:: with SMTP id q10mr52522588vsd.215.1564541455592; Tue, 30 Jul 2019 19:50:55 -0700 (PDT) MIME-Version: 1.0 References: <20190509143859.9050-1-joe.lawrence@redhat.com> <20190509143859.9050-4-joe.lawrence@redhat.com> In-Reply-To: <20190509143859.9050-4-joe.lawrence@redhat.com> From: Masahiro Yamada Date: Wed, 31 Jul 2019 11:50:19 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 03/10] livepatch: Add klp-convert tool To: Joe Lawrence Cc: Linux Kernel Mailing List , live-patching@vger.kernel.org, Linux Kbuild mailing list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 9, 2019 at 11:39 PM Joe Lawrence wrote: > > From: Josh Poimboeuf > > Livepatches may use symbols which are not contained in its own scope, > and, because of that, may end up compiled with relocations that will > only be resolved during module load. Yet, when the referenced symbols > are not exported, solving this relocation requires information on the > object that holds the symbol (either vmlinux or modules) and its > position inside the object, as an object may contain multiple symbols > with the same name. Providing such information must be done > accordingly to what is specified in > Documentation/livepatch/module-elf-format.txt. > > Currently, there is no trivial way to embed the required information > as requested in the final livepatch elf object. klp-convert solves > this problem in two different forms: (i) by relying on Symbols.list, > which is built during kernel compilation, to automatically infer the > relocation targeted symbol, and, when such inference is not possible > (ii) by using annotations in the elf object to convert the relocation > accordingly to the specification, enabling it to be handled by the > livepatch loader. > > Given the above, create scripts/livepatch to hold tools developed for > livepatches and add source files for klp-convert there. > > The core file of klp-convert is scripts/livepatch/klp-convert.c, which > implements the heuristics used to solve the relocations and the > conversion of unresolved symbols into the expected format, as defined > in [1]. > > klp-convert receives as arguments the Symbols.list file, an input > livepatch module to be converted and the output name for the converted > livepatch. When it starts running, klp-convert parses Symbols.list and > builds two internal lists of symbols, one containing the exported and > another containing the non-exported symbols. Then, by parsing the rela > sections in the elf object, klp-convert identifies which symbols must > be converted, which are those unresolved and that do not have a > corresponding exported symbol, and attempts to convert them > accordingly to the specification. > > By using Symbols.list, klp-convert identifies which symbols have names > that only appear in a single kernel object, thus being capable of > resolving these cases without the intervention of the developer. When > various homonymous symbols exist through kernel objects, it is not > possible to infer the right one, thus klp-convert falls back into > using developer annotations. If these were not provided, then the tool > will print a list with all acceptable targets for the symbol being > processed. > > Annotations in the context of klp-convert are accessible as struct > klp_module_reloc entries in sections named > .klp.module_relocs.. These entries are pairs of symbol > references and positions which are to be resolved against definitions > in . > > Define the structure klp_module_reloc in > include/linux/uapi/livepatch.h allowing developers to annotate the > livepatch source code with it. > > klp-convert relies on libelf and on a list implementation. Add files > scripts/livepatch/elf.c and scripts/livepatch/elf.h, which are a > libelf interfacing layer and scripts/livepatch/list.h, which is a > list implementation. > > Update Makefiles to correctly support the compilation of the new tool, > update MAINTAINERS file and add a .gitignore file. > > [1] - Documentation/livepatch/module-elf-format.txt > > Signed-off-by: Josh Poimboeuf > Signed-off-by: Konstantin Khlebnikov > Signed-off-by: Joao Moreira > Signed-off-by: Joe Lawrence > --- > MAINTAINERS | 1 + > include/uapi/linux/livepatch.h | 5 + > scripts/Makefile | 1 + > scripts/livepatch/.gitignore | 1 + > scripts/livepatch/Makefile | 7 + > scripts/livepatch/elf.c | 753 ++++++++++++++++++++++++++++++++ > scripts/livepatch/elf.h | 73 ++++ > scripts/livepatch/klp-convert.c | 713 ++++++++++++++++++++++++++++++ > scripts/livepatch/klp-convert.h | 39 ++ > scripts/livepatch/list.h | 391 +++++++++++++++++ > 10 files changed, 1984 insertions(+) > create mode 100644 scripts/livepatch/.gitignore > create mode 100644 scripts/livepatch/Makefile > create mode 100644 scripts/livepatch/elf.c > create mode 100644 scripts/livepatch/elf.h > create mode 100644 scripts/livepatch/klp-convert.c > create mode 100644 scripts/livepatch/klp-convert.h > create mode 100644 scripts/livepatch/list.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 52842fa37261..c1587e1cc385 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -9022,6 +9022,7 @@ F: arch/x86/kernel/livepatch.c > F: Documentation/livepatch/ > F: Documentation/ABI/testing/sysfs-kernel-livepatch > F: samples/livepatch/ > +F: scripts/livepatch/ > F: tools/testing/selftests/livepatch/ > L: live-patching@vger.kernel.org > T: git git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git > diff --git a/include/uapi/linux/livepatch.h b/include/uapi/linux/livepatch.h > index e19430918a07..1c364d42d38e 100644 > --- a/include/uapi/linux/livepatch.h > +++ b/include/uapi/linux/livepatch.h > @@ -12,4 +12,9 @@ > #define KLP_RELA_PREFIX ".klp.rela." > #define KLP_SYM_PREFIX ".klp.sym." > > +struct klp_module_reloc { > + void *sym; > + unsigned int sympos; > +} __attribute__((packed)); > + > #endif /* _UAPI_LIVEPATCH_H */ > diff --git a/scripts/Makefile b/scripts/Makefile > index 9d442ee050bd..bf9ce74b70b0 100644 > --- a/scripts/Makefile > +++ b/scripts/Makefile > @@ -39,6 +39,7 @@ build_unifdef: $(obj)/unifdef > subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins > subdir-$(CONFIG_MODVERSIONS) += genksyms > subdir-$(CONFIG_SECURITY_SELINUX) += selinux > +subdir-$(CONFIG_LIVEPATCH) += livepatch > > # Let clean descend into subdirs > subdir- += basic dtc gdb kconfig mod package > diff --git a/scripts/livepatch/.gitignore b/scripts/livepatch/.gitignore > new file mode 100644 > index 000000000000..dc22fe4b6a5b > --- /dev/null > +++ b/scripts/livepatch/.gitignore > @@ -0,0 +1 @@ > +klp-convert > diff --git a/scripts/livepatch/Makefile b/scripts/livepatch/Makefile > new file mode 100644 > index 000000000000..2842ecdba3fd > --- /dev/null > +++ b/scripts/livepatch/Makefile > @@ -0,0 +1,7 @@ > +hostprogs-y := klp-convert > +always := $(hostprogs-y) > + > +klp-convert-objs := klp-convert.o elf.o > + > +HOST_EXTRACFLAGS := -g -I$(INSTALL_HDR_PATH)/include -Wall This looks strange. Theoretically, you cannot include headers in $(INSTALL_HDR_PATH)/include from host programs. headers_install works for the target architecture, not host architecture. This may cause a strange result when you are cross-compiling the kernel. BTW, which header in $(INSTALL_HDR_PATH)/include do you need to include ? Also, -Wall is redundant because it is set by the top-level Makefile. -- Best Regards Masahiro Yamada