Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3464821imb; Tue, 5 Mar 2019 09:59:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyjEliomHfn1PwqbmzuMFtuz/styvmf7fnEBWaC8z2tFWHjzijt7RU6oySu37xSQQsk8AHK X-Received: by 2002:a17:902:8643:: with SMTP id y3mr2422838plt.195.1551808745546; Tue, 05 Mar 2019 09:59:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551808745; cv=none; d=google.com; s=arc-20160816; b=fU8GIbh6FqHbHUI+noCa75L4TgBqhMfNl1YrKC3zRwI/DFgd6aY/nAJkQrGZbCbiQL qLcyoTAlz+036GYMi7V6Tjfr2ikO1Q6qKURCJUjCZ/cHbm3lTNZWzwDYySDP+fspZ+UX xJKE7WIEWduOUKZBmNKziRM9e1/e5MFir1ycc+s1zXvdk6vRAPIWjchrUJyptxi/sfHl o+WN6CGNsj6C7EYRZq8w5D0pUMCW3pj0QvPE+/VLsK3vMHYQxDaPgc40Ju2Ud2ZlI3IY ngn/h6r3XBa0vtlASODeXBVFbRPdo2lzHqx7ffhSfZzGWIacHU/1rOoE63XFmB03ksbs 7gyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/Ge2DKc8DMthB5Ba52pSQpiB9j28X+ncf3wXtDuR5vw=; b=1FAYB4eSusYXSu+YERTd3jvDY4BhnLtlmZkm3ydaihqBO+ELak3097YkRn1/4Xsx7x STWfWePijnlfj7px+NuSWNyLYnqvLW+67nSCgjxI3z9wErTBap7reWK6IHN+rtIn51rm kENZXzOOozPpwPbxCao7iq4lyD9JmBeyWbskHu0ZneQFz2h30qR7TSORKtj/RJthUMyD tjgOKWb3wrBgn058zlYxGO3u7yQuZuFSbKYBmk8G9TBFYOm5f6dX1Msp88HwpINYQcR1 Zd7ddQvCxPcVfMuuu7zkKgSpoA146UqCsgjUZ9qHhBCxjMG1wC29UQIX0KKqtjT5Es7H DUXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=hcU2U2qb; 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 f30si8300072pgl.340.2019.03.05.09.58.49; Tue, 05 Mar 2019 09:59:05 -0800 (PST) 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=@joelfernandes.org header.s=google header.b=hcU2U2qb; 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 S1726539AbfCEQZ1 (ORCPT + 99 others); Tue, 5 Mar 2019 11:25:27 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:43718 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726502AbfCEQZ0 (ORCPT ); Tue, 5 Mar 2019 11:25:26 -0500 Received: by mail-qt1-f196.google.com with SMTP id y4so9538545qtc.10 for ; Tue, 05 Mar 2019 08:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/Ge2DKc8DMthB5Ba52pSQpiB9j28X+ncf3wXtDuR5vw=; b=hcU2U2qb1IwKk2btOW7rAxR816NBesZIYuL47lLgAbZVah0HzTaci3+4h7cMEfLGRy 1XqC4Gp7XQjfQBCCiSHFdVzeVpUbA3gnVttlGKLXRAXl4Ro3bljQqjwCR8ekPptkNQPW TZXRmtLhWPNdoHId0oAp4g6rIk/WERpiDOACc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/Ge2DKc8DMthB5Ba52pSQpiB9j28X+ncf3wXtDuR5vw=; b=OvvR8X0hFib+J4MBs+vO9dQ15S/IJfhL8pBRmokEjtOUX8McwtB9/vNd5SxIeoOUTr VTvNBTF//BhU7mVVc7UtmRUUI7MUrQwkHag1cUEphUp1gQYIi+6LSG2YTMMaiIE0XBTP +GjpdS51gz0hugOc+Y4zrkImOcvo0JfV44yZIQDSDz80k9sHuhtpezBkgoIMcT+fkRZA wywgD1kXNab7XtBLR/a7SqdffKnFw+5wqAjB++bCzejxDREWmBs5pJOF9Vf0DSxo8UkI xeOWDb7xdOWXomTtzyIi6jEwKpF/PJ6Qi3KlUoJYaPMCcSvmeYXIYTJMPEyoltV1xUau nB+g== X-Gm-Message-State: APjAAAVv/kctFdyb56lJvYPm0cGYLktTGPvON1PODW65MMzLOqnb9DXt UWGmTCz0uqOFZ2G6rwuZISmjug== X-Received: by 2002:ac8:1b96:: with SMTP id z22mr1988621qtj.329.1551803125182; Tue, 05 Mar 2019 08:25:25 -0800 (PST) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id u1sm6065184qki.36.2019.03.05.08.25.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Mar 2019 08:25:23 -0800 (PST) Date: Tue, 5 Mar 2019 11:25:23 -0500 From: Joel Fernandes To: Dietmar Eggemann Cc: linux-kernel@vger.kernel.org, Andrew Morton , ast@kernel.org, atishp04@gmail.com, dancol@google.com, Dan Williams , gregkh@linuxfoundation.org, Guenter Roeck , Jonathan Corbet , karim.yaghmour@opersys.com, Kees Cook , kernel-team@android.com, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-devel@vger.kernel.org, Manoj Rao , Masahiro Yamada , mhiramat@kernel.org, qais.yousef@arm.com, rdunlap@infradead.org, rostedt@goodmis.org, Shuah Khan , yhs@fb.com Subject: Re: [PATCH v4 1/2] Provide in-kernel headers for making it easy to extend the kernel Message-ID: <20190305162523.GA78911@google.com> References: <20190301160856.129678-1-joel@joelfernandes.org> <934dc2dc-18b6-bc7c-9845-dac0577f7b47@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <934dc2dc-18b6-bc7c-9845-dac0577f7b47@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 04, 2019 at 11:48:52PM +0100, Dietmar Eggemann wrote: > On 3/1/19 5:08 PM, Joel Fernandes (Google) wrote: > > Introduce in-kernel headers and other artifacts which are made available > > as an archive through proc (/proc/kheaders.tar.xz file). This archive makes > > it possible to build kernel modules, run eBPF programs, and other > > tracing programs that need to extend the kernel for tracing purposes > > without any dependency on the file system having headers and build > > artifacts. > > > > On Android and embedded systems, it is common to switch kernels but not > > have kernel headers available on the file system. Raw kernel headers > > also cannot be copied into the filesystem like they can be on other > > distros, due to licensing and other issues. There's no linux-headers > > package on Android. Further once a different kernel is booted, any > > headers stored on the file system will no longer be useful. By storing > > the headers as a compressed archive within the kernel, we can avoid these > > issues that have been a hindrance for a long time. > > > > The feature is also buildable as a module just in case the user desires > > it not being part of the kernel image. This makes it possible to load > > and unload the headers on demand. A tracing program, or a kernel module > > builder can load the module, do its operations, and then unload the > > module to save kernel memory. The total memory needed is 3.8MB. > > > > The code to read the headers is based on /proc/config.gz code and uses > > the same technique to embed the headers. > > > > To build a module, the below steps have been tested on an x86 machine: > > modprobe kheaders > > rm -rf $HOME/headers > > mkdir -p $HOME/headers > > tar -xvf /proc/kheaders.tar.xz -C $HOME/headers >/dev/null > > cd my-kernel-module > > make -C $HOME/headers M=$(pwd) modules > > rmmod kheaders > > > > Additional notes: > > (1) external modules must be built on the same arch as the host that > > built vmlinux. This can be done either in a qemu emulated chroot on the > > target, or natively. This is due to host arch dependency of kernel > > scripts. > > > > (2) > > A limitation of module building with this is, since Module.symvers is > > not available in the archive due to a cyclic dependency with building of > > the archive into the kernel or module binaries, the modules built using > > the archive will not contain symbol versioning (modversion). This is > > usually not an issue since the idea of this patch is to build a kernel > > module on the fly and load it into the same kernel. An appropriate > > warning is already printed by the kernel to alert the user of modules > > not having modversions when built using the archive. For building with > > modversions, the user can use traditional header packages. For our > > tracing usecases, we build modules on the fly with this so it is not a > > concern. > > > > (3) I have left IKHD_ST and IKHD_ED markers as is to facilitate > > future patches that would extract the headers from a kernel or module > > image. > > > > Signed-off-by: Joel Fernandes (Google) > > --- > > > > Changes since v3: > > - Blank tar was being generated because of a one line I > > forgot to push. It is updated now. > > - Added module.lds since arm64 needs it to build modules. > > Tested on x86 with eBPF scripts and exporting an alternative > BCC_KERNEL_SOURCE. > > Tested-by: Dietmar Eggemann Thank you! Will repost with the tags soon. - Joel