Skip to contentSkip to conversation

xen: auto-generate symbols for xen hypercalls

PATCH Superseded Juergen Gross 2 participants 9 messages Dec 17, 2014 – Jan 19, 2015

Subsystems (4)
lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

v2 cover xen: auto-generate symbols for xen hypercalls

The Xen hypercalls are defined in include/xen/interface/xen.h. There are some places where for each hypercall a table element is created. Instead of manually add each hypercall element to these tables use an auto generated header built during the make process of the kernel.

Changes in V2:
- add "autogenerated" comment to generated header file as suggested by David Vrabel (patch 1)
- some minor adjustments to patch 4 as suggested by David Vrabel

Juergen Gross (4):
xen: build infrastructure for generating hypercall depending symbols
xen: synchronize include/xen/interface/xen.h with xen
xen: use generated hypervisor symbols in arch/x86/xen/trace.c
xen: use generated hypercall symbols in arch/x86/xen/xen-head.S

 arch/x86/syscalls/Makefile  |  9 +++++++
 arch/x86/xen/trace.c        | 50 +++--------------------------------
 arch/x86/xen/xen-head.S     | 63 +++++++--------------------------------------
 include/xen/interface/xen.h |  6 ++++-
 scripts/xen-hypercalls.sh   | 12 +++++++++
 5 files changed, 40 insertions(+), 100 deletions(-)
 create mode 100644 scripts/xen-hypercalls.sh
Signature · 1 line
2.1.2
author maintainer
#1 lore raw

PATCH v2 1/4 xen: build infrastructure for generating hypercall depending symbols

Today there are several places in the kernel which build tables containing one entry for each possible Xen hypercall. Create an infrastructure to be able to generate these tables at build time.

---
 arch/x86/syscalls/Makefile |  9 +++++++++
 scripts/xen-hypercalls.sh  | 12 ++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 scripts/xen-hypercalls.sh
arch/x86/syscalls/Makefile +9 -0
index 3323c27..a55abb9 100644
@@ -19,6 +19,9 @@ quiet_cmd_syshdr = SYSHDR  $@
 quiet_cmd_systbl = SYSTBL  $@
       cmd_systbl = $(CONFIG_SHELL) '$(systbl)' $< $@
 
+quiet_cmd_hypercalls = HYPERCALLS $@
+      cmd_hypercalls = $(CONFIG_SHELL) '$<' $@ $(filter-out $<,$^)
+
 syshdr_abi_unistd_32 := i386
 $(uapi)/unistd_32.h: $(syscall32) $(syshdr)
 	$(call if_changed,syshdr)
@@ -47,10 +50,16 @@ $(out)/syscalls_32.h: $(syscall32) $(systbl)
 $(out)/syscalls_64.h: $(syscall64) $(systbl)
 	$(call if_changed,systbl)
 
+$(out)/xen-hypercalls.h: $(srctree)/scripts/xen-hypercalls.sh
+	$(call if_changed,hypercalls)
+
+$(out)/xen-hypercalls.h: $(srctree)/include/xen/interface/xen*.h
+
 uapisyshdr-y			+= unistd_32.h unistd_64.h unistd_x32.h
 syshdr-y			+= syscalls_32.h
 syshdr-$(CONFIG_X86_64)		+= unistd_32_ia32.h unistd_64_x32.h
 syshdr-$(CONFIG_X86_64)		+= syscalls_64.h
+syshdr-$(CONFIG_XEN)		+= xen-hypercalls.h
 
 targets	+= $(uapisyshdr-y) $(syshdr-y)
 
scripts/xen-hypercalls.sh new file +12 -0
new file mode 100644
index 0000000..676d922
@@ -0,0 +1,12 @@
+#!/bin/sh
+out="$1"
+shift
+in="$@"
+
+for i in $in; do
+	eval $CPP $LINUXINCLUDE -dD -imacros "$i" -x c /dev/null
+done | \
+awk '$1 == "#define" && $2 ~ /__HYPERVISOR_[a-z][a-z_0-9]*/ { v[$3] = $2 }
+	END {   print "/* auto-generated by scripts/xen-hypercall.sh */"
+		for (i in v) if (!(v[i] in v))
+			print "HYPERCALL("substr(v[i], 14)")"}' | sort -u >$out
Signature · 1 line
2.1.2
Reviewed-by on v2 1/4
#2 lore raw

Re: [Xen-devel] [Patch V2 1/4] xen: build infrastructure for generating hypercall depending symbols

Quoted 3 lines · Juergen Gross

Today there are several places in the kernel which build tables containing one entry for each possible Xen hypercall. Create an infrastructure to be able to generate these tables at build time.

David

author maintainer
#3 lore raw

PATCH v2 2/4 xen: synchronize include/xen/interface/xen.h with xen

In reply to Juergen Gross

The header include/xen/interface/xen.h doesn't contain all definitions from Xen's version of that header. Update it accordingly.

---
 arch/x86/xen/trace.c        | 2 +-
 include/xen/interface/xen.h | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/xen/trace.c +1 -1
index 520022d..8296cdf 100644
@@ -29,7 +29,7 @@ static const char *xen_hypercall_names[] = {
 	N(vcpu_op),
 	N(set_segment_base),
 	N(mmuext_op),
-	N(acm_op),
+	N(xsm_op),
 	N(nmi_op),
 	N(sched_op),
 	N(callback_op),
include/xen/interface/xen.h +5 -1
index f68719f..a483789 100644
@@ -67,7 +67,7 @@
 #define __HYPERVISOR_vcpu_op              24
 #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
 #define __HYPERVISOR_mmuext_op            26
-#define __HYPERVISOR_acm_op               27
+#define __HYPERVISOR_xsm_op               27
 #define __HYPERVISOR_nmi_op               28
 #define __HYPERVISOR_sched_op             29
 #define __HYPERVISOR_callback_op          30
@@ -75,7 +75,11 @@
 #define __HYPERVISOR_event_channel_op     32
 #define __HYPERVISOR_physdev_op           33
 #define __HYPERVISOR_hvm_op               34
+#define __HYPERVISOR_sysctl               35
+#define __HYPERVISOR_domctl               36
+#define __HYPERVISOR_kexec_op             37
 #define __HYPERVISOR_tmem_op              38
+#define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
Signature · 1 line
2.1.2
author maintainer
#4 lore raw

PATCH v2 3/4 xen: use generated hypervisor symbols in arch/x86/xen/trace.c

In reply to Juergen Gross

Instead of manually list all hypervisor calls in arch/x86/xen/trace.c use the auto generated list.

---
 arch/x86/xen/trace.c | 50 ++++----------------------------------------------
 1 file changed, 4 insertions(+), 46 deletions(-)
arch/x86/xen/trace.c +4 -46
index 8296cdf..a702ec2 100644
@@ -1,54 +1,12 @@
 #include <linux/ftrace.h>
 #include <xen/interface/xen.h>
+#include <xen/interface/xen-mca.h>
 
-#define N(x)	[__HYPERVISOR_##x] = "("#x")"
+#define HYPERCALL(x)	[__HYPERVISOR_##x] = "("#x")",
 static const char *xen_hypercall_names[] = {
-	N(set_trap_table),
-	N(mmu_update),
-	N(set_gdt),
-	N(stack_switch),
-	N(set_callbacks),
-	N(fpu_taskswitch),
-	N(sched_op_compat),
-	N(dom0_op),
-	N(set_debugreg),
-	N(get_debugreg),
-	N(update_descriptor),
-	N(memory_op),
-	N(multicall),
-	N(update_va_mapping),
-	N(set_timer_op),
-	N(event_channel_op_compat),
-	N(xen_version),
-	N(console_io),
-	N(physdev_op_compat),
-	N(grant_table_op),
-	N(vm_assist),
-	N(update_va_mapping_otherdomain),
-	N(iret),
-	N(vcpu_op),
-	N(set_segment_base),
-	N(mmuext_op),
-	N(xsm_op),
-	N(nmi_op),
-	N(sched_op),
-	N(callback_op),
-	N(xenoprof_op),
-	N(event_channel_op),
-	N(physdev_op),
-	N(hvm_op),
-
-/* Architecture-specific hypercall definitions. */
-	N(arch_0),
-	N(arch_1),
-	N(arch_2),
-	N(arch_3),
-	N(arch_4),
-	N(arch_5),
-	N(arch_6),
-	N(arch_7),
+#include <asm/xen-hypercalls.h>
 };
-#undef N
+#undef HYPERCALL
 
 static const char *xen_hypercall_name(unsigned op)
 {
Signature · 1 line
2.1.2
author maintainer
#5 lore raw

PATCH v2 4/4 xen: use generated hypercall symbols in arch/x86/xen/xen-head.S

In reply to Juergen Gross

Instead of manually list each hypercall in arch/x86/xen/xen-head.S use the auto generated symbol list.

This also corrects the wrong address of xen_hypercall_mca which was located 32 bytes higher than it should.

Symbol addresses have been verified to match the correct ones via objdump output.

---
 arch/x86/xen/xen-head.S | 63 ++++++++-----------------------------------------
 1 file changed, 10 insertions(+), 53 deletions(-)
arch/x86/xen/xen-head.S +10 -53
index 674b2225..8afdfcc 100644
@@ -12,6 +12,8 @@
 
 #include <xen/interface/elfnote.h>
 #include <xen/interface/features.h>
+#include <xen/interface/xen.h>
+#include <xen/interface/xen-mca.h>
 #include <asm/xen/interface.h>
 
 #ifdef CONFIG_XEN_PVH
@@ -85,59 +87,14 @@ ENTRY(xen_pvh_early_cpu_init)
 .pushsection .text
 	.balign PAGE_SIZE
 ENTRY(hypercall_page)
-#define NEXT_HYPERCALL(x) \
-	ENTRY(xen_hypercall_##x) \
-	.skip 32
-
-NEXT_HYPERCALL(set_trap_table)
-NEXT_HYPERCALL(mmu_update)
-NEXT_HYPERCALL(set_gdt)
-NEXT_HYPERCALL(stack_switch)
-NEXT_HYPERCALL(set_callbacks)
-NEXT_HYPERCALL(fpu_taskswitch)
-NEXT_HYPERCALL(sched_op_compat)
-NEXT_HYPERCALL(platform_op)
-NEXT_HYPERCALL(set_debugreg)
-NEXT_HYPERCALL(get_debugreg)
-NEXT_HYPERCALL(update_descriptor)
-NEXT_HYPERCALL(ni)
-NEXT_HYPERCALL(memory_op)
-NEXT_HYPERCALL(multicall)
-NEXT_HYPERCALL(update_va_mapping)
-NEXT_HYPERCALL(set_timer_op)
-NEXT_HYPERCALL(event_channel_op_compat)
-NEXT_HYPERCALL(xen_version)
-NEXT_HYPERCALL(console_io)
-NEXT_HYPERCALL(physdev_op_compat)
-NEXT_HYPERCALL(grant_table_op)
-NEXT_HYPERCALL(vm_assist)
-NEXT_HYPERCALL(update_va_mapping_otherdomain)
-NEXT_HYPERCALL(iret)
-NEXT_HYPERCALL(vcpu_op)
-NEXT_HYPERCALL(set_segment_base)
-NEXT_HYPERCALL(mmuext_op)
-NEXT_HYPERCALL(xsm_op)
-NEXT_HYPERCALL(nmi_op)
-NEXT_HYPERCALL(sched_op)
-NEXT_HYPERCALL(callback_op)
-NEXT_HYPERCALL(xenoprof_op)
-NEXT_HYPERCALL(event_channel_op)
-NEXT_HYPERCALL(physdev_op)
-NEXT_HYPERCALL(hvm_op)
-NEXT_HYPERCALL(sysctl)
-NEXT_HYPERCALL(domctl)
-NEXT_HYPERCALL(kexec_op)
-NEXT_HYPERCALL(tmem_op) /* 38 */
-ENTRY(xen_hypercall_rsvr)
-	.skip 320
-NEXT_HYPERCALL(mca) /* 48 */
-NEXT_HYPERCALL(arch_1)
-NEXT_HYPERCALL(arch_2)
-NEXT_HYPERCALL(arch_3)
-NEXT_HYPERCALL(arch_4)
-NEXT_HYPERCALL(arch_5)
-NEXT_HYPERCALL(arch_6)
-	.balign PAGE_SIZE
+	.skip PAGE_SIZE
+
+#define HYPERCALL(n) \
+	.equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \
+	.type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32
+#include <asm/xen-hypercalls.h>
+#undef HYPERCALL
+
 .popsection
 
 	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz "linux")
Signature · 1 line
2.1.2
Reviewed-by on v2 4/4
#6 lore raw

Re: [Xen-devel] [Patch V2 4/4] xen: use generated hypercall symbols in arch/x86/xen/xen-head.S

Quoted 8 lines · Juergen Gross

Instead of manually list each hypercall in arch/x86/xen/xen-head.S use the auto generated symbol list.

This also corrects the wrong address of xen_hypercall_mca which was located 32 bytes higher than it should.

Symbol addresses have been verified to match the correct ones via objdump output.

David

author maintainer
#7 lore raw
In reply to Juergen Gross

Hi,

anything missing to take these patches?

Juergen

Quoted 24 lines · Juergen Gross

The Xen hypercalls are defined in include/xen/interface/xen.h. There are some places where for each hypercall a table element is created. Instead of manually add each hypercall element to these tables use an auto generated header built during the make process of the kernel.

Changes in V2:
- add "autogenerated" comment to generated header file as suggested by David Vrabel (patch 1)
- some minor adjustments to patch 4 as suggested by David Vrabel

Juergen Gross (4):
xen: build infrastructure for generating hypercall depending symbols
xen: synchronize include/xen/interface/xen.h with xen
xen: use generated hypervisor symbols in arch/x86/xen/trace.c
xen: use generated hypercall symbols in arch/x86/xen/xen-head.S

  arch/x86/syscalls/Makefile  |  9 +++++++
  arch/x86/xen/trace.c        | 50 +++--------------------------------
  arch/x86/xen/xen-head.S     | 63 +++++++--------------------------------------
  include/xen/interface/xen.h |  6 ++++-
  scripts/xen-hypercalls.sh   | 12 +++++++++
  5 files changed, 40 insertions(+), 100 deletions(-)

create mode 100644 scripts/xen-hypercalls.sh

#8 lore raw
Quoted 3 lines · Juergen Gross

Hi,

anything missing to take these patches?

Patch #1 needs an x86 maintainer ack.

David

Quoted 27 lines · Juergen Gross
Quoted 25 lines

The Xen hypercalls are defined in include/xen/interface/xen.h. There are some places where for each hypercall a table element is created. Instead of manually add each hypercall element to these tables use an auto generated header built during the make process of the kernel.

Changes in V2:
- add "autogenerated" comment to generated header file as suggested by David Vrabel (patch 1)
- some minor adjustments to patch 4 as suggested by David Vrabel

Juergen Gross (4):
xen: build infrastructure for generating hypercall depending symbols
xen: synchronize include/xen/interface/xen.h with xen
xen: use generated hypervisor symbols in arch/x86/xen/trace.c
xen: use generated hypercall symbols in arch/x86/xen/xen-head.S

  arch/x86/syscalls/Makefile  |  9 +++++++
  arch/x86/xen/trace.c        | 50 +++--------------------------------
  arch/x86/xen/xen-head.S     | 63
+++++++--------------------------------------
  include/xen/interface/xen.h |  6 ++++-
  scripts/xen-hypercalls.sh   | 12 +++++++++
  5 files changed, 40 insertions(+), 100 deletions(-)

create mode 100644 scripts/xen-hypercalls.sh