diff mbox series

[v5,7/8] xen: add /buildinfo/config entry to hypervisor filesystem

Message ID 20200219081126.29534-8-jgross@suse.com (mailing list archive)
State Superseded
Headers show
Series Add hypervisor sysfs-like support | expand

Commit Message

Jürgen Groß Feb. 19, 2020, 8:11 a.m. UTC
Add the /buildinfo/config entry to the hypervisor filesystem. This
entry contains the .config file used to build the hypervisor.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3:
- store data in gzip format
- use binfile mechanism to create data file
- move code to kernel.c
---
 .gitignore                   |  2 ++
 docs/misc/hypfs-paths.pandoc |  4 ++++
 xen/common/Makefile          | 12 ++++++++++++
 xen/common/kernel.c          | 10 ++++++++++
 xen/include/xen/kernel.h     |  3 +++
 5 files changed, 31 insertions(+)

Comments

Jan Beulich Feb. 19, 2020, 3:57 p.m. UTC | #1
On 19.02.2020 09:11, Juergen Gross wrote:
> --- a/xen/common/Makefile
> +++ b/xen/common/Makefile
> @@ -1,6 +1,7 @@
>  obj-$(CONFIG_ARGO) += argo.o
>  obj-y += bitmap.o
>  obj-y += bsearch.o
> +obj-y += config_data.o

In particular with embedded uses in mind, I think this wants to
have a Kconfig control.

> @@ -414,6 +421,9 @@ static int __init buildinfo_init(void)
>      hypfs_add_leaf(&version, &major, true);
>      hypfs_add_leaf(&version, &minor, true);
>  
> +    config.e.size = xen_config_data_size;

This being the only use of xen_config_data_size, it suggests that
it could in principle live in .init.rodata. I realize this may
mean more customization to the binfile script than is warranted
by these 4 bytes of data, but I wanted to at least point out the
aspect.

> --- a/xen/include/xen/kernel.h
> +++ b/xen/include/xen/kernel.h
> @@ -100,5 +100,8 @@ extern enum system_state {
>  
>  bool_t is_active_kernel_text(unsigned long addr);
>  
> +extern char xen_config_data;
> +extern unsigned int xen_config_data_size;

const for both?

Jan
Jürgen Groß Feb. 20, 2020, 6:13 a.m. UTC | #2
On 19.02.20 16:57, Jan Beulich wrote:
> On 19.02.2020 09:11, Juergen Gross wrote:
>> --- a/xen/common/Makefile
>> +++ b/xen/common/Makefile
>> @@ -1,6 +1,7 @@
>>   obj-$(CONFIG_ARGO) += argo.o
>>   obj-y += bitmap.o
>>   obj-y += bsearch.o
>> +obj-y += config_data.o
> 
> In particular with embedded uses in mind, I think this wants to
> have a Kconfig control.

Okay.

> 
>> @@ -414,6 +421,9 @@ static int __init buildinfo_init(void)
>>       hypfs_add_leaf(&version, &major, true);
>>       hypfs_add_leaf(&version, &minor, true);
>>   
>> +    config.e.size = xen_config_data_size;
> 
> This being the only use of xen_config_data_size, it suggests that
> it could in principle live in .init.rodata. I realize this may
> mean more customization to the binfile script than is warranted
> by these 4 bytes of data, but I wanted to at least point out the
> aspect.

In case this pattern is coming up again we might want to enhance
the script, but right now I don't think this is needed.

> 
>> --- a/xen/include/xen/kernel.h
>> +++ b/xen/include/xen/kernel.h
>> @@ -100,5 +100,8 @@ extern enum system_state {
>>   
>>   bool_t is_active_kernel_text(unsigned long addr);
>>   
>> +extern char xen_config_data;
>> +extern unsigned int xen_config_data_size;
> 
> const for both?

Yes.


Juergen
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index fd5610718d..bc8e053ccb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -297,6 +297,8 @@  xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
 xen/arch/*/efi/efi.h
 xen/arch/*/efi/runtime.c
+xen/common/config_data.S
+xen/common/config.gz
 xen/include/headers*.chk
 xen/include/asm
 xen/include/asm-*/asm-offsets.h
diff --git a/docs/misc/hypfs-paths.pandoc b/docs/misc/hypfs-paths.pandoc
index e392feff27..1faebcccbc 100644
--- a/docs/misc/hypfs-paths.pandoc
+++ b/docs/misc/hypfs-paths.pandoc
@@ -133,6 +133,10 @@  Information about the compile domain.
 
 The compiler used to build Xen.
 
+#### /buildinfo/config = STRING
+
+The contents of the `xen/.config` file at the time of the hypervisor build.
+
 #### /buildinfo/version/
 
 A directory containing version information of the hypervisor.
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 3a2c1ae690..72fb790c57 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -1,6 +1,7 @@ 
 obj-$(CONFIG_ARGO) += argo.o
 obj-y += bitmap.o
 obj-y += bsearch.o
+obj-y += config_data.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
@@ -73,3 +74,14 @@  subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-$(CONFIG_NEEDS_LIBELF) += libelf
 subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
+
+config.gz: ../.config
+	gzip -c $< >$@
+
+config_data.o: config.gz
+
+config_data.S: $(XEN_ROOT)/xen/tools/binfile
+	$(XEN_ROOT)/xen/tools/binfile $@ config.gz xen_config_data
+
+clean::
+	rm config_data.S config.gz 2>/dev/null || true
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 6ee0e64404..3d496bb9e6 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -388,6 +388,13 @@  static HYPFS_STRING_INIT(compile_by, "compile_by");
 static HYPFS_STRING_INIT(compile_date, "compile_date");
 static HYPFS_STRING_INIT(compile_domain, "compile_domain");
 static HYPFS_STRING_INIT(extra, "extra");
+static struct hypfs_entry_leaf config = {
+    .e.type = XEN_HYPFS_TYPE_STRING,
+    .e.encoding = XEN_HYPFS_ENC_GZIP,
+    .e.name = "config",
+    .e.read = hypfs_read_leaf,
+    .content = &xen_config_data
+};
 
 static int __init buildinfo_init(void)
 {
@@ -414,6 +421,9 @@  static int __init buildinfo_init(void)
     hypfs_add_leaf(&version, &major, true);
     hypfs_add_leaf(&version, &minor, true);
 
+    config.e.size = xen_config_data_size;
+    hypfs_add_leaf(&buildinfo, &config, true);
+
     return 0;
 }
 __initcall(buildinfo_init);
diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h
index 548b64da9f..2f883031f9 100644
--- a/xen/include/xen/kernel.h
+++ b/xen/include/xen/kernel.h
@@ -100,5 +100,8 @@  extern enum system_state {
 
 bool_t is_active_kernel_text(unsigned long addr);
 
+extern char xen_config_data;
+extern unsigned int xen_config_data_size;
+
 #endif /* _LINUX_KERNEL_H */