From 4e733a287c1e49ed185fd93117c582d0f019fb85 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 12:06:56 +0900 Subject: [PATCH] arm64/kallsyms: use kallsym for gic_data_v3 as well It turns out we can figure it out at runtime with a little trick, and the function that I could not figure how to tell which to use is actually set in a proper global "__smp_cross_call" pointer so we can use that instead. Change-Id: I40bed957005fbe60fbdcebd7d1d979b2c56c9b00 --- config.h.in | 7 - configure | 132 ------------------ configure.ac | 97 ------------- linux/driver/smp/arch/arm64/config-arm64.h.in | 67 --------- linux/driver/smp/arch/arm64/smp-arch-driver.c | 43 +++++- .../driver/smp/arch/x86_64/config-x86_64.h.in | 48 ------- 6 files changed, 37 insertions(+), 357 deletions(-) delete mode 100644 linux/driver/smp/arch/arm64/config-arm64.h.in delete mode 100644 linux/driver/smp/arch/x86_64/config-x86_64.h.in diff --git a/config.h.in b/config.h.in index 1b9e978f..0214bff9 100644 --- a/config.h.in +++ b/config.h.in @@ -45,13 +45,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H -/* Define to address of kernel symbol gic_data_gicv3, or 0 if exported */ -#undef IHK_KSYM_gic_data_gicv3 - -/* Define to address of kernel symbol gic_raise_softirq_gicv3, or 0 if - exported */ -#undef IHK_KSYM_gic_raise_softirq_gicv3 - /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT diff --git a/configure b/configure index 7840091f..f79c050e 100755 --- a/configure +++ b/configure @@ -3115,134 +3115,6 @@ esac KDIR="$WITH_KERNELSRC" TARGET="$WITH_TARGET" -IHK_LINUX_SYMTAB="" -case "X$WITH_SYSTEM_MAP" in - Xyes | Xno | X) - IHK_LINUX_SYMTAB="" - ;; - *) - IHK_LINUX_SYMTAB="$WITH_SYSTEM_MAP" - ;; -esac - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for System.map" >&5 -$as_echo_n "checking for System.map... " >&6; } -if test -r "$IHK_LINUX_SYMTAB"; then - IHK_LINUX_SYMTAB="$IHK_LINUX_SYMTAB" -elif test -r "/boot/System.map-`uname -r`"; then - IHK_LINUX_SYMTAB="/boot/System.map-`uname -r`" -elif test -r "$KDIR/System.map"; then - IHK_LINUX_SYMTAB="$KDIR/System.map" -fi - -if test "$IHK_LINUX_SYMTAB" == ""; then - as_fn_error $? "could not find" "$LINENO" 5 -fi - -if test -z "`eval cat $IHK_LINUX_SYMTAB`"; then - as_fn_error $? "could not read System.map file, no read permission?" "$LINENO" 5 -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $IHK_LINUX_SYMTAB" >&5 -$as_echo "$IHK_LINUX_SYMTAB" >&6; } - -IHK_LINUX_SYMTAB_CMD="cat $IHK_LINUX_SYMTAB" - -# IHK_FIND_KSYM(SYMBOL) -# ------------------------------------------------------ -# Search System.map for address of the given symbol and -# do one of three things in config.h: -# If not found, leave IHK_KSYM_foo undefined -# If found to be exported, "#define IHK_KSYM_foo 0" -# If found not to be exported, "#define IHK_KSYM_foo 0x" - -# POSTK_DEBUG_ARCH_DEP_10, Enhance IHK_FIND_KSYM macro feature. - -# -# AC_DEFUN([IHK_FIND_KSYM],[ -# AC_MSG_CHECKING([[System.map for symbol $1]]) -# ihk_addr=`eval $IHK_LINUX_SYMTAB_CMD | grep " $1\$" | cut -d\ -f1` -# if test -z $ihk_addr; then -# AC_MSG_RESULT([not found]) -# else -# ihk_result=$ihk_addr -# ihk_addr="0x$ihk_addr" -# m4_ifval([$2],[],[ -# if `eval $IHK_LINUX_SYMTAB_CMD | grep " __ksymtab_$1\$" >/dev/null`; then -# ihk_result="exported" -# ihk_addr="0" -# fi -# ]) -# AC_MSG_RESULT([$ihk_result]) -# AC_DEFINE_UNQUOTED(IHK_KSYM_[]$1,$ihk_addr, -# [Define to address of kernel symbol $1, or 0 if exported]) -# fi -# ]) - -if test "$TARGET" = "smp-arm64"; then - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking System.map for symbol gic_data" >&5 -$as_echo_n "checking System.map for symbol gic_data... " >&6; } - symbol_src=irq-gic-v3.c - ihk_addr=`eval $IHK_LINUX_SYMTAB_CMD | grep " gic_data\$" | cut -d\ -f1` - ihk_addr_array=($ihk_addr) - if test ${#ihk_addr_array[*]} -gt 1 ; then - for addr in $ihk_addr ; do - filename=`addr2line -e $KDIR/vmlinux ${addr} | cut -d ':' -f1 | rev | cut -d '/' -f1 | rev` - if test $filename = $symbol_src ; then - ihk_addr=$addr - break - fi - done - fi - if test -z $ihk_addr; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -$as_echo "not found" >&6; } - else - ihk_result=$ihk_addr - ihk_addr="0x$ihk_addr" - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ihk_result" >&5 -$as_echo "$ihk_result" >&6; } - -cat >>confdefs.h <<_ACEOF -#define IHK_KSYM_gic_data_gicv3 $ihk_addr -_ACEOF - - fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking System.map for symbol gic_raise_softirq" >&5 -$as_echo_n "checking System.map for symbol gic_raise_softirq... " >&6; } - symbol_src=irq-gic-v3.c - ihk_addr=`eval $IHK_LINUX_SYMTAB_CMD | grep " gic_raise_softirq\$" | cut -d\ -f1` - ihk_addr_array=($ihk_addr) - if test ${#ihk_addr_array[*]} -gt 1 ; then - for addr in $ihk_addr ; do - filename=`addr2line -e $KDIR/vmlinux ${addr} | cut -d ':' -f1 | rev | cut -d '/' -f1 | rev` - if test $filename = $symbol_src ; then - ihk_addr=$addr - break - fi - done - fi - if test -z $ihk_addr; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -$as_echo "not found" >&6; } - else - ihk_result=$ihk_addr - ihk_addr="0x$ihk_addr" - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ihk_result" >&5 -$as_echo "$ihk_result" >&6; } - -cat >>confdefs.h <<_ACEOF -#define IHK_KSYM_gic_raise_softirq_gicv3 $ihk_addr -_ACEOF - - fi - -fi - if test "x$ENABLE_MEMDUMP" != "xno" ; then enableval=yes # POSTK_DEBUG_ARCH_DEP_32, AC_CHECK_LIB for libiberty @@ -3882,9 +3754,6 @@ case "$TARGET" in smp*) ac_config_headers="$ac_config_headers config.h" - arch=`echo "$ARCH"` - ac_config_headers="$ac_config_headers linux/driver/smp/arch/$arch/config-$arch.h" - ;; esac @@ -4591,7 +4460,6 @@ for ac_config_target in $ac_config_targets do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - "linux/driver/smp/arch/$arch/config-$arch.h") CONFIG_HEADERS="$CONFIG_HEADERS linux/driver/smp/arch/$arch/config-$arch.h" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "linux/core/Makefile") CONFIG_FILES="$CONFIG_FILES linux/core/Makefile" ;; "linux/core/Makefile.module") CONFIG_FILES="$CONFIG_FILES linux/core/Makefile.module" ;; diff --git a/configure.ac b/configure.ac index 9a79ef7d..bb328b98 100644 --- a/configure.ac +++ b/configure.ac @@ -230,101 +230,6 @@ esac KDIR="$WITH_KERNELSRC" TARGET="$WITH_TARGET" -IHK_LINUX_SYMTAB="" -case "X$WITH_SYSTEM_MAP" in - Xyes | Xno | X) - IHK_LINUX_SYMTAB="" - ;; - *) - IHK_LINUX_SYMTAB="$WITH_SYSTEM_MAP" - ;; -esac - -AC_MSG_CHECKING([[for System.map]]) -if test -r "$IHK_LINUX_SYMTAB"; then - IHK_LINUX_SYMTAB="$IHK_LINUX_SYMTAB" -elif test -r "/boot/System.map-`uname -r`"; then - IHK_LINUX_SYMTAB="/boot/System.map-`uname -r`" -elif test -r "$KDIR/System.map"; then - IHK_LINUX_SYMTAB="$KDIR/System.map" -fi - -if test "$IHK_LINUX_SYMTAB" == ""; then - AC_MSG_ERROR([could not find]) -fi - -if test -z "`eval cat $IHK_LINUX_SYMTAB`"; then - AC_MSG_ERROR([could not read System.map file, no read permission?]) -fi -AC_MSG_RESULT([$IHK_LINUX_SYMTAB]) - -IHK_LINUX_SYMTAB_CMD="cat $IHK_LINUX_SYMTAB" - -# IHK_FIND_KSYM(SYMBOL) -# ------------------------------------------------------ -# Search System.map for address of the given symbol and -# do one of three things in config.h: -# If not found, leave IHK_KSYM_foo undefined -# If found to be exported, "#define IHK_KSYM_foo 0" -# If found not to be exported, "#define IHK_KSYM_foo 0x" - -# POSTK_DEBUG_ARCH_DEP_10, Enhance IHK_FIND_KSYM macro feature. -AC_DEFUN([IHK_FIND_KSYM],[ - AC_MSG_CHECKING([[System.map for symbol $1]]) - symbol_src=$2 - ihk_addr=`eval $IHK_LINUX_SYMTAB_CMD | grep " $1\$" | cut -d\ -f1` - ihk_addr_array=($ihk_addr) - if test ${#ihk_addr_array[*]} -gt 1 ; then - for addr in $ihk_addr ; do - filename=`addr2line -e $KDIR/vmlinux ${addr} | cut -d ':' -f1 | rev | cut -d '/' -f1 | rev` - if test $filename = $symbol_src ; then - ihk_addr=$addr - break - fi - done - fi - if test -z $ihk_addr; then - AC_MSG_RESULT([not found]) - else - ihk_result=$ihk_addr - ihk_addr="0x$ihk_addr" - m4_ifval([$2],[],[ - if `eval $IHK_LINUX_SYMTAB_CMD | grep " __ksymtab_$1\$" >/dev/null`; then - ihk_result="exported" - ihk_addr="0" - fi - ]) - AC_MSG_RESULT([$ihk_result]) - AC_DEFINE_UNQUOTED(IHK_KSYM_[]$1$3,$ihk_addr, - [Define to address of kernel symbol $1$3, or 0 if exported]) - fi -]) -# -# AC_DEFUN([IHK_FIND_KSYM],[ -# AC_MSG_CHECKING([[System.map for symbol $1]]) -# ihk_addr=`eval $IHK_LINUX_SYMTAB_CMD | grep " $1\$" | cut -d\ -f1` -# if test -z $ihk_addr; then -# AC_MSG_RESULT([not found]) -# else -# ihk_result=$ihk_addr -# ihk_addr="0x$ihk_addr" -# m4_ifval([$2],[],[ -# if `eval $IHK_LINUX_SYMTAB_CMD | grep " __ksymtab_$1\$" >/dev/null`; then -# ihk_result="exported" -# ihk_addr="0" -# fi -# ]) -# AC_MSG_RESULT([$ihk_result]) -# AC_DEFINE_UNQUOTED(IHK_KSYM_[]$1,$ihk_addr, -# [Define to address of kernel symbol $1, or 0 if exported]) -# fi -# ]) - -if test "$TARGET" = "smp-arm64"; then - IHK_FIND_KSYM([gic_data], [irq-gic-v3.c], [_gicv3]) - IHK_FIND_KSYM([gic_raise_softirq], [irq-gic-v3.c], [_gicv3]) -fi - if test "x$ENABLE_MEMDUMP" != "xno" ; then enableval=yes # POSTK_DEBUG_ARCH_DEP_32, AC_CHECK_LIB for libiberty @@ -401,8 +306,6 @@ AC_SUBST(uncomment_if_ENABLE_MEMDUMP) case "$TARGET" in smp*) AC_CONFIG_HEADERS([config.h]) - arch=`echo "$ARCH"` - AC_CONFIG_HEADERS([linux/driver/smp/arch/$arch/config-$arch.h]) ;; esac diff --git a/linux/driver/smp/arch/arm64/config-arm64.h.in b/linux/driver/smp/arch/arm64/config-arm64.h.in deleted file mode 100644 index c9e0ecad..00000000 --- a/linux/driver/smp/arch/arm64/config-arm64.h.in +++ /dev/null @@ -1,67 +0,0 @@ -/* config.h.in COPYRIGHT FUJITSU LIMITED 2015 */ -/* linux/driver/smp/arch/arm64/config-arm64.h.in. Generated from configure.ac by autoheader. */ -#ifndef HEADER_SMP_CONFIG_ARM64_H -#define HEADER_SMP_CONFIG_ARM64_H - -/* Define to address of kernel symbol irq-gic.c:gic_data, or 0 if exported */ -#undef IHK_KSYM_gic_data_gicv2 - -/* Define to address of kernel symbol irq-gic-v3.c:gic_data, or 0 if exported */ -#undef IHK_KSYM_gic_data_gicv3 - -/* Define to address of kernel symbol irq-gic.c:gic_raise_softirq, or 0 if exported */ -#undef IHK_KSYM_gic_raise_softirq_gicv2 - -/* Define to address of kernel symbol irq-gic-v3.c:gic_raise_softirq, or 0 if exported */ -#undef IHK_KSYM_gic_raise_softirq_gicv3 - -/* Define to address of kernel symbol __irq_domain_alloc_irqs, or 0 if exported */ -#undef IHK_KSYM___irq_domain_alloc_irqs - -/* Define to address of kernel symbol irq_domain_free_irqs, or 0 if exported */ -#undef IHK_KSYM_irq_domain_free_irqs - -/* Define to address of kernel symbol psci_ops, or 0 if exported */ -#undef IHK_KSYM_psci_ops - -/* Define to address of kernel symbol __cpu_logical_map, or 0 if exported */ -#undef IHK_KSYM___cpu_logical_map - -/* Define to address of kernel symbol dummy_irq_chip, or 0 if exported */ -#undef IHK_KSYM_dummy_irq_chip - -/* Define to address of kernel symbol get_uv_system_type, or 0 if exported */ -#undef IHK_KSYM_get_uv_system_type - -/* Define to address of kernel symbol init_deasserted, or 0 if exported */ -#undef IHK_KSYM_init_deasserted - -/* Define to address of kernel symbol irq_to_desc, or 0 if exported */ -#undef IHK_KSYM_irq_to_desc - -/* Define to address of kernel symbol invoke_psci_fn, or 0 if exported */ -#undef IHK_KSYM_invoke_psci_fn - -/* Define to address of kernel symbol __invoke_psci_fn_hvc, or 0 if exported */ -#undef IHK_KSYM___invoke_psci_fn_hvc - -/* Define to address of kernel symbol __invoke_psci_fn_smc, or 0 if exported */ -#undef IHK_KSYM___invoke_psci_fn_smc - -/* Define to address of kernel symbol cpu_pmu */ -#undef IHK_KSYM_cpu_pmu -#undef IHK_KSYM___oprofile_cpu_pmu - -/* Define to address of kernel symbol __irq_set_affinity */ -#undef IHK_KSYM___irq_set_affinity - -/* Define to address of kernel symbol arch_timer_use_virtual, or 0 if exported */ -#undef IHK_KSYM_arch_timer_use_virtual - -/* Define to address of kernel symbol arch_timer_uses_ppi, or 0 if exported */ -#undef IHK_KSYM_arch_timer_uses_ppi - -/* Define to address of kernel symbol arch_timer_rate */ -#undef IHK_KSYM_arch_timer_rate - -#endif /* HEADER_SMP_CONFIG_ARM64_H */ diff --git a/linux/driver/smp/arch/arm64/smp-arch-driver.c b/linux/driver/smp/arch/arm64/smp-arch-driver.c index f2728aae..ba5c5d06 100644 --- a/linux/driver/smp/arch/arm64/smp-arch-driver.c +++ b/linux/driver/smp/arch/arm64/smp-arch-driver.c @@ -31,7 +31,6 @@ #include #include #include -#include "config-arm64.h" #include "smp-driver.h" #include "smp-arch-driver.h" #include "smp-defines-driver.h" @@ -67,8 +66,6 @@ static unsigned long ihk_smp_gic_cpu_size = 0; static unsigned int ihk_gic_percpu_offset = 0; static phys_addr_t ihk_smp_gic_rdist_pa[NR_CPUS]; -static void (*ihk___smp_cross_call)(const struct cpumask *, unsigned int); - /* * If you edit IPI_XXX, you must edit following together. * mckernel/arch/arm64/kernel/include/irq.h::INTRID_xxx @@ -190,7 +187,8 @@ static unsigned long ihk_smp_psci_method = PSCI_METHOD_INVALID; /* psci_method v * IHK-SMP unexported kernel symbols */ static struct gic_chip_data_v3 *ihk_gic_data_v3; -static void (*ihk___smp_cross_call_gicv3)(const struct cpumask *, unsigned int); +static void (*ihk___smp_cross_call)(const struct cpumask *, unsigned int); + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) static int (*ihk___irq_domain_alloc_irqs)(struct irq_domain *domain, @@ -229,8 +227,43 @@ enum ppi_nr *ihk_arch_timer_uses_ppi; u32 *ihk_arch_timer_rate; +/* There are two symbols with the same name, but thanksfully only one is + * actually used, and the other will contain 0s by definition. + * We can use that to figure which symbol to use + */ +int lookup_gic_data_v3(void *data, const char *name, struct module *mod, + unsigned long address) +{ + unsigned long *gic_data; + int i; + + if (strcmp(name, "gic_data") == 0) { + gic_data = (void *)address; + /* check the first (arbitrary) 8 words for data */ + for (i = 0; i < 8; i++) { + if (gic_data[i]) { + ihk_gic_data_v3 = (void *) address; + return 1; + } + } + } + + return 0; +} + int ihk_smp_arch_symbols_init(void) { + if (WARN_ON(!kallsyms_on_each_symbol(lookup_gic_data_v3, NULL))) + return -EFAULT; + + void **ihk___smp_cross_call_p = + (void *) kallsyms_lookup_name("__smp_cross_call"); + if (WARN_ON(!ihk___smp_cross_call_p)) + return -EFAULT; + ihk___smp_cross_call = *ihk___smp_cross_call_p; + if (WARN_ON(!ihk___smp_cross_call)) + return -EFAULT; + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) ihk___irq_domain_alloc_irqs = (void *) kallsyms_lookup_name("__irq_domain_alloc_irqs"); @@ -652,8 +685,6 @@ static int ihk_smp_collect_gic_info(void) result = ihk_smp_dt_get_gic_base(); } - ihk___smp_cross_call = ihk___smp_cross_call_gicv3; - ihk_gic_max_vector = ihk_gic_data_v3->irq_nr; return result; diff --git a/linux/driver/smp/arch/x86_64/config-x86_64.h.in b/linux/driver/smp/arch/x86_64/config-x86_64.h.in deleted file mode 100644 index bbbcc93a..00000000 --- a/linux/driver/smp/arch/x86_64/config-x86_64.h.in +++ /dev/null @@ -1,48 +0,0 @@ -/* config-x86.h.in COPYRIGHT FUJITSU LIMITED 2015 */ -/* linux/driver/smp-x86/config.h.in. Generated from configure.ac by autoheader. */ -#ifndef HEADER_SMP_CONFIG_X86_H -#define HEADER_SMP_CONFIG_X86_H - -/* Define to address of kernel symbol __default_send_IPI_dest_field, or 0 if - exported */ -#undef IHK_KSYM___default_send_IPI_dest_field - -/* Define to address of kernel symbol alloc_desc, or 0 if exported */ -#undef IHK_KSYM_alloc_desc - -/* to address of kernel symbol dummy_irq_chip, or 0 if exported */ -#undef IHK_KSYM_dummy_irq_chip - -/* Define to address of kernel symbol get_uv_system_type, or 0 if exported */ -#undef IHK_KSYM_get_uv_system_type - -/* Define to address of kernel symbol init_deasserted, or 0 if exported */ -#undef IHK_KSYM_init_deasserted - -/* Define to address of kernel symbol irq_desc_tree, or 0 if exported */ -#undef IHK_KSYM_irq_desc_tree - -/* Define to address of kernel symbol irq_to_desc, or 0 if exported */ -#undef IHK_KSYM_irq_to_desc - -/* Define to address of kernel symbol irq_to_desc_alloc_node, or 0 if exported - */ -#undef IHK_KSYM_irq_to_desc_alloc_node - -/* Define to address of kernel symbol lapic_get_maxlvt, or 0 if exported */ -#undef IHK_KSYM_lapic_get_maxlvt - -/* Define to address of kernel symbol per_cpu__vector_irq, or 0 if exported */ -#undef IHK_KSYM_per_cpu__vector_irq - -/* Define to address of kernel symbol real_mode_header, or 0 if exported */ -#undef IHK_KSYM_real_mode_header - -/* Define to address of kernel symbol vector_irq, or 0 if exported */ -#undef IHK_KSYM_vector_irq - -/* Define to address of kernel symbol wakeup_secondary_cpu_via_init, or 0 if - * exported */ -#undef IHK_KSYM_wakeup_secondary_cpu_via_init - -#endif /* HEADER_SMP_CONFIG_X86_H */