[OpenAFS] OpenAFS patch for sys_call_table-crippled RedHat kernels.

Derrick J Brashear shadow@dementia.org
Fri, 25 Oct 2002 10:33:24 -0400 (EDT)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--42002020-1582993119-1035556404=:7040
Content-Type: TEXT/PLAIN; CHARSET=us-ascii; FORMAT=flowed
Content-ID: <Pine.LNX.3.96L.1021025103212.7040i@scully.trafford.dementia.org>

Now it's in the archives on this list as well as openafs-devel, so
hopefully people will find it. 

---------- Forwarded message ----------
Date: Fri, 18 Oct 2002 19:08:50 -0400
From: Chaskiel M Grundman <cg2v@andrew.cmu.edu>
To: openafs-devel@openafs.org
Subject: [OpenAFS-devel] Updated redhat workaround patch

The attached patch should be able to deal with the current redhat kernels 
that export neither sys_call_table nor kallsyms_symbol_to_address (This 
one's configure script should even be able to tell when redhat breaks it 
again)

This patch completely replaces the earlier patch I wrote, which is in the 
redhat 8.0 openafs 1.2.7 SRPM.


P.S. to whoever redhat's informant on this list is: In the absolute worst 
case, I can nm vmlinux and/or read System.map and write the address into a 
/proc file to get at it. In the long run openafs can and probably will 
transition to a proc based interface for most of it's needs. But that's the 
long run and there are still some unresolved issues, so this isn't helping.
  

--42002020-1582993119-1035556404=:7040
Content-Type: TEXT/PLAIN; CHARSET=iso-8859-1; NAME="rh8-stable.diff"
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-ID: <Pine.LNX.3.96L.1021025103212.7040j@scully.trafford.dementia.org>
Content-Description: 

diff -ru openafs-1.2.7-orig/acconfig.h openafs-1.2.7/acconfig.h
--- openafs-1.2.7-orig/acconfig.h	2002-09-11 03:02:15.000000000 -0400
+++ openafs-1.2.7/acconfig.h	2002-10-18 18:37:09.000000000 -0400
@@ -36,6 +36,9 @@
 #undef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS
 #undef STRUCT_INODE_HAS_I_DEVICES
 #undef EXPORTED_TASKLIST_LOCK
+#undef EXPORTED_SYS_CALL_TABLE
+#undef EXPORTED_KALLSYMS_SYMBOL
+#undef EXPORTED_KALLSYMS_ADDRESS
 #undef COMPLETION_H_EXISTS
 #undef ssize_t
=20
diff -ru openafs-1.2.7-orig/acinclude.m4 openafs-1.2.7/acinclude.m4
--- openafs-1.2.7-orig/acinclude.m4	2002-09-25 23:48:52.000000000 -0400
+++ openafs-1.2.7/acinclude.m4	2002-10-18 18:42:00.000000000 -0400
@@ -130,6 +130,12 @@
 			OMIT_FRAME_POINTER=3D-fomit-frame-pointer
 		 fi
 		 AC_SUBST(OMIT_FRAME_POINTER)
+		 OPENAFS_GCC_SUPPORTS_MARCH
+		 AC_SUBST(P5PLUS_KOPTS)
+		 OPENAFS_GCC_NEEDS_NO_STRENGTH_REDUCE
+		 OPENAFS_GCC_NEEDS_NO_STRICT_ALIASING
+		 OPENAFS_GCC_SUPPORTS_NO_COMMON
+		 AC_SUBST(LINUX_GCC_KOPTS)
 	         ifdef([OPENAFS_CONFIGURE_LIBAFS],
 	           [LINUX_BUILD_VNODE_FROM_INODE(config,afs)],
 	           [LINUX_BUILD_VNODE_FROM_INODE(src/config,src/afs/LINUX)]
@@ -144,9 +150,42 @@
 		 LINUX_EXPORTS_TASKLIST_LOCK
 		 LINUX_NEED_RHCONFIG
 		 LINUX_WHICH_MODULES
+		 if test "$ac_cv_linux_config_modversions" =3D "xno"; then
+		   AC_MSG_WARN([Cannot determine sys_call_table status. assuming it's =
exported])
+		   ac_cv_linux_exports_sys_call_table=3Dyes
+		 else
+		   LINUX_EXPORTS_SYS_CALL_TABLE
+		   LINUX_EXPORTS_KALLSYMS_SYMBOL
+		   LINUX_EXPORTS_KALLSYMS_ADDRESS
+		   LINUX_EXPORTS_INIT_MM
+		   if test "x$ac_cv_linux_exports_sys_call_table" =3D "xno"; then
+                       linux_syscall_method=3Dnone
+                       if test "x$ac_cv_linux_exports_init_mm" =3D "xyes"; =
then
+                          linux_syscall_method=3Dscan
+                          if test "x$ac_cv_linux_exports_kallsyms_address" =
=3D "xyes"; then
+                             =
linux_syscall_method=3Dscan_with_kallsyms_address
+                          fi
+                       fi
+                       if test "x$ac_cv_linux_exports_kallsyms_symbol" =3D =
"xyes"; then
+                          linux_syscall_method=3Dkallsyms_symbol
+                       fi
+                       if test "x$linux_syscall_method" =3D "xnone"; then
+			AC_MSG_ERROR([no available sys_call_table access method])
+                       fi
+		   fi
+		 fi
 		 if test "x$ac_cv_linux_exports_tasklist_lock" =3D "xyes" ; then
 		  AC_DEFINE(EXPORTED_TASKLIST_LOCK)
 		 fi
+		 if test "x$ac_cv_linux_exports_sys_call_table" =3D "xyes"; then
+		  AC_DEFINE(EXPORTED_SYS_CALL_TABLE)
+		 fi
+		 if test "x$ac_cv_linux_exports_kallsyms_symbol" =3D "xyes"; then
+		  AC_DEFINE(EXPORTED_KALLSYMS_SYMBOL)
+		 fi
+		 if test "x$ac_cv_linux_exports_kallsyms_address" =3D "xyes"; then
+		  AC_DEFINE(EXPORTED_KALLSYMS_ADDRESS)
+		 fi
 		 if test "x$ac_cv_linux_completion_h_exists" =3D "xyes" ; then
 		  AC_DEFINE(COMPLETION_H_EXISTS)
 		 fi
diff -ru openafs-1.2.7-orig/src/afs/LINUX/osi_module.c =
openafs-1.2.7/src/afs/LINUX/osi_module.c
--- openafs-1.2.7-orig/src/afs/LINUX/osi_module.c	2002-05-02 =
11:38:45.000000000 -0400
+++ openafs-1.2.7/src/afs/LINUX/osi_module.c	2002-10-18 18:52:13.000000000 =
-0400
@@ -26,6 +26,10 @@
 #if LINUX_VERSION_CODE >=3D KERNEL_VERSION(2,4,0)
 #include <linux/init.h>
 #endif
+#ifndef EXPORTED_SYS_CALL_TABLE
+#include <linux/sched.h>
+#include <linux/syscall.h>
+#endif
=20
=20
=20
@@ -40,11 +44,19 @@
 asmlinkage int (*sys_killp)(int pid, int signal);
 asmlinkage long (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
=20
+#ifdef EXPORTED_SYS_CALL_TABLE
 #ifdef AFS_SPARC64_LINUX20_ENV
 extern unsigned int sys_call_table[];  /* changed to uint because SPARC64 =
has syscaltable of 32bit items */
 #else
 extern void * sys_call_table[]; /* safer for other linuces */
 #endif
+#else /* EXPORTED_SYS_CALL_TABLE */
+#ifdef AFS_SPARC64_LINUX20_ENV
+static unsigned int *sys_call_table;  /* changed to uint because SPARC64 =
has syscaltable of 32bit items */
+#else
+static void ** sys_call_table; /* safer for other linuces */
+#endif
+#endif
 extern struct file_system_type afs_file_system;
=20
 static long get_page_offset(void);
@@ -72,7 +84,11 @@
 #if defined(__NR_setgroups32)
 asmlinkage int (*sys32_setgroups32p)(int gidsetsize, __kernel_gid_t32 =
*grouplist);
 #endif
+#ifdef EXPORTED_SYS_CALL_TABLE
 extern unsigned int sys_call_table32[];
+#else
+static unsigned int *sys_call_table32;
+#endif
=20
 asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long =
parm3,
 			     long parm4, long parm5)
@@ -200,6 +216,24 @@
 #endif
 #endif
=20
+#ifndef EXPORTED_SYS_CALL_TABLE
+    unsigned long *ptr;
+    unsigned long offset;
+    unsigned long datalen;
+    int ret;
+    unsigned long token;
+    char      *mod_name;
+    unsigned long    mod_start;
+    unsigned long    mod_end;
+    char      *sec_name;
+    unsigned long    sec_start;
+    unsigned long    sec_end;
+    char      *sym_name;
+    unsigned long    sym_start;
+    unsigned long    sym_end;
+#endif
+
+
=20
=20
     /* obtain PAGE_OFFSET value */
@@ -213,6 +247,58 @@
     }
 #endif
=20
+#ifndef EXPORTED_SYS_CALL_TABLE
+    sys_call_table=3D0;
+
+#ifdef EXPORTED_KALLSYMS_SYMBOL
+    ret=3D1;
+    token=3D0;
+    while (ret) {
+       sym_start=3D0;
+       ret=3Dkallsyms_symbol_to_address("sys_call_table", &token, =
&mod_name,
+	               &mod_start, &mod_end, &sec_name, &sec_start, &sec_end,
+                       &sym_name, &sym_start, &sym_end);
+       if (ret && !strcmp(mod_name, "kernel"))
+               break;
+    }
+    if (ret && sym_start) {
+	    sys_call_table=3Dsym_start;
+    }
+#else
+#ifdef EXPORTED_KALLSYMS_ADDRESS
+    ret=3Dkallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name,
+                    &mod_start, &mod_end, &sec_name, &sec_start, &sec_end,
+                    &sym_name, &sym_start, &sym_end);
+    ptr=3D(unsigned long *)sec_start;
+    datalen=3D(sec_end-sec_start)/sizeof(unsigned long);
+#else
+    ptr=3D(unsigned long *)&init_mm;
+    datalen=3D16384;
+#endif
+    for (offset=3D0;offset <datalen;ptr++,offset++) {
+        if (ptr[0] =3D=3D (unsigned long)&sys_exit &&
+            ptr[__NR_open - __NR_exit] =3D=3D (unsigned long)&sys_open) {
+            sys_call_table=3Dptr - __NR_exit;
+            break;
+        }
+    }
+#ifdef EXPORTED_KALLSYMS_ADDRESS
+       ret=3Dkallsyms_address_to_symbol((unsigned long)sys_call_table, =
&mod_name,
+                       &mod_start, &mod_end, &sec_name, &sec_start, =
&sec_end,
+                       &sym_name, &sym_start, &sym_end);
+       if (ret && strcmp(sym_name, "sys_call_table"))
+               sys_call_table=3D0;
+#endif
+#endif
+    if (!sys_call_table) {
+         printf("Failed to find address of sys_call_table\n");
+         return -EIO;
+    }
+# ifdef AFS_SPARC64_LINUX20_ENV
+error cant support this yet.
+#endif
+#endif /* SYS_CALL_TABLE */
+
     /* Initialize pointers to kernel syscalls. */
 #if defined(AFS_IA64_LINUX20_ENV)
     kernel_gp =3D ((struct fptr *)printk)->gp;
Only in openafs-1.2.7/src/afs/LINUX: osi_vfs.h
diff -ru openafs-1.2.7-orig/src/cf/linux-test4.m4 =
openafs-1.2.7/src/cf/linux-test4.m4
--- openafs-1.2.7-orig/src/cf/linux-test4.m4	2002-09-11 03:02:51.000000000 =
-0400
+++ openafs-1.2.7/src/cf/linux-test4.m4	2002-10-18 18:44:47.000000000 -0400
@@ -14,6 +14,70 @@
 AC_MSG_RESULT($ac_cv_linux_exports_tasklist_lock)
 CPPFLAGS=3D"$save_CPPFLAGS"])
=20
+AC_DEFUN(LINUX_EXPORTS_SYS_CALL_TABLE, [
+AC_MSG_CHECKING(for exported sys_call_table)
+save_CPPFLAGS=3D"$CPPFLAGS"
+CPPFLAGS=3D"-I${LINUX_KERNEL_PATH}/include -D__KERNEL__ $CPPFLAGS"
+AC_CACHE_VAL(ac_cv_linux_exports_sys_call_table,
+[
+AC_TRY_COMPILE(
+[#include <linux/modversions.h>],
+[#ifndef __ver_sys_call_table
+#error sys_call_table not exported
+#endif],
+ac_cv_linux_exports_sys_call_table=3Dyes,
+ac_cv_linux_exports_sys_call_table=3Dno)])
+AC_MSG_RESULT($ac_cv_linux_exports_sys_call_table)
+CPPFLAGS=3D"$save_CPPFLAGS"])
+
+AC_DEFUN(LINUX_EXPORTS_INIT_MM, [
+AC_MSG_CHECKING(for exported init_mm)
+save_CPPFLAGS=3D"$CPPFLAGS"
+CPPFLAGS=3D"-I${LINUX_KERNEL_PATH}/include -D__KERNEL__ $CPPFLAGS"
+AC_CACHE_VAL(ac_cv_linux_exports_init_mm,
+[
+AC_TRY_COMPILE(
+[#include <linux/modversions.h>],
+[#ifndef __ver_init_mm
+#error init_mm not exported
+#endif],
+ac_cv_linux_exports_init_mm=3Dyes,
+ac_cv_linux_exports_init_mm=3Dno)])
+AC_MSG_RESULT($ac_cv_linux_exports_init_mm)
+CPPFLAGS=3D"$save_CPPFLAGS"])
+
+AC_DEFUN(LINUX_EXPORTS_KALLSYMS_SYMBOL, [
+AC_MSG_CHECKING(for exported kallsyms_symbol_to_address)
+save_CPPFLAGS=3D"$CPPFLAGS"
+CPPFLAGS=3D"-I${LINUX_KERNEL_PATH}/include -D__KERNEL__ $CPPFLAGS"
+AC_CACHE_VAL(ac_cv_linux_exports_kallsyms_symbol,
+[
+AC_TRY_COMPILE(
+[#include <linux/modversions.h>],
+[#ifndef __ver_kallsyms_symbol_to_address
+#error kallsyms_symbol_to_address not exported
+#endif],
+ac_cv_linux_exports_kallsyms_symbol=3Dyes,
+ac_cv_linux_exports_kallsyms_symbol=3Dno)])
+AC_MSG_RESULT($ac_cv_linux_exports_kallsyms_symbol)
+CPPFLAGS=3D"$save_CPPFLAGS"])
+
+AC_DEFUN(LINUX_EXPORTS_KALLSYMS_ADDRESS, [
+AC_MSG_CHECKING(for exported kallsyms_address_to_symbol)
+save_CPPFLAGS=3D"$CPPFLAGS"
+CPPFLAGS=3D"-I${LINUX_KERNEL_PATH}/include -D__KERNEL__ $CPPFLAGS"
+AC_CACHE_VAL(ac_cv_linux_exports_kallsyms_address,
+[
+AC_TRY_COMPILE(
+[#include <linux/modversions.h>],
+[#ifndef __ver_kallsyms_address_to_symbol
+#error kallsyms_address_to_symbol not exported
+#endif],
+ac_cv_linux_exports_kallsyms_address=3Dyes,
+ac_cv_linux_exports_kallsyms_address=3Dno)])
+AC_MSG_RESULT($ac_cv_linux_exports_kallsyms_address)
+CPPFLAGS=3D"$save_CPPFLAGS"])
+
 AC_DEFUN(LINUX_COMPLETION_H_EXISTS, [
 AC_MSG_CHECKING(for linux/completion.h existance)
 save_CPPFLAGS=3D"$CPPFLAGS"
Only in openafs-1.2.7/src/cf: linux-test5.m4
Only in openafs-1.2.7/src/config: afsconfig.h.in
Only in openafs-1.2.7/src/config: afsconfig.h.in~
diff -ru openafs-1.2.7-orig/src/libafs/MakefileProto.LINUX.in =
openafs-1.2.7/src/libafs/MakefileProto.LINUX.in
--- openafs-1.2.7-orig/src/libafs/MakefileProto.LINUX.in	2002-06-08 =
00:47:42.000000000 -0400
+++ openafs-1.2.7/src/libafs/MakefileProto.LINUX.in	2002-10-03 =
12:19:46.000000000 -0400
@@ -52,44 +52,41 @@
 # System specific build commands and flags
 CC =3D gcc
 LD =3D ld
+GCC_KOPTS=3D@LINUX_GCC_KOPTS@
 # -Wall
 <i386_linux22 i386_linux24>
-CCFLAGS =3D  $(KDEBUG) -O2 $(FOMIT) \
-	-fno-strength-reduce -pipe -march=3Di486 -malign-loops=3D2 =
-malign-jumps=3D2 \
-	-malign-functions=3D2
+P5PLUS=3D@P5PLUS_KOPTS@
+CCFLAGS =3D  $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) -pipe $(P5PLUS)
 DEFINES =3D -D__KERNEL__  -DCPU=3D586 -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF} ${KDEFINES}
 <alpha_linux_22 alpha_linux_24>
-CCFLAGS =3D $(KDEBUG) -O2 $(FOMIT) -fno-strength-reduce -pipe -mno-fp-regs =
-ffixed-8
+CCFLAGS =3D $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) -pipe -mno-fp-regs =
-ffixed-8
 DEFINES =3D -D__KERNEL__ -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
 <s390_linux22 s390_linux24>
-CCFLAGS =3D   -O $(FOMIT) -fno-strength-reduce \
-	-fno-strict-aliasing -fsigned-char=20
+CCFLAGS =3D   -O $(FOMIT) $(GCC_KOPTS) -fsigned-char=20
 DEFINES =3D -D__KERNEL__  -D__s390__ -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF}
 <sparc_linux22 sparc_linux24>
 LD =3D ld -m elf32_sparc
-CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) \
-	-fno-strength-reduce -pipe -mcpu=3Dv8 -mno-fpu -fcall-used-g5 =
-fcall-used-g7
+CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) \
+	-pipe -mcpu=3Dv8 -mno-fpu -fcall-used-g5 -fcall-used-g7
 DEFINES =3D -D__KERNEL__  -DCPU=3Dsparc -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF}
 <sparc64_linux22 sparc64_linux24>
 CC =3D sparc64-linux-gcc
 LD =3D ld -m elf64_sparc
-CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) \
-	-fno-strength-reduce -pipe -mcpu=3Dultrasparc -m64 -mno-fpu =
-mcmodel=3Dmedlow -ffixed-g4 -fcall-used-g5 -fcall-used-g7 =
-Wno-sign-compare
+CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) \
+	-pipe -mcpu=3Dultrasparc -m64 -mno-fpu -mcmodel=3Dmedlow -ffixed-g4 =
-fcall-used-g5 -fcall-used-g7 -Wno-sign-compare
 DEFINES =3D -D__KERNEL__  -DCPU=3Dsparc64 -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF}
 <ppc_linux22 ppc_linux24>
-CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) -fno-strength-reduce \
-	-fno-strict-aliasing -fsigned-char -msoft-float -pipe \
+CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) -fsigned-char =
-msoft-float -pipe \
 	-fno-builtin -ffixed-r2
 DEFINES =3D -D__KERNEL__  -D__powerpc__ -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF}
 <parisc_linux24>
-CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) \
-	-fno-strict-aliasing -fno-common -fno-strength-reduce \
-        -fno-strict-aliasing -fsigned-char -mno-space-regs =
-mfast-indirect-calls \
-        -mdisable-fpregs -ffunction-sections -march=3D1.1 =
-mschedule=3D7100
+CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) -fsigned-char =
-mno-space-regs \
+	-mfast-indirect-calls -mdisable-fpregs -ffunction-sections \
+	-march=3D1.1 -mschedule=3D7100
 DEFINES =3D -D__KERNEL__  -D__linux__ -DKERNEL -D_KERNEL -DMODULE =
${SMP_DEF}
 <ia64_linux24>
-CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) -fno-strict-aliasing -fno-common =
-pipe \
-	-ffixed-r13 -mfixed-range=3Df10-f15,f32-f127 -falign-functions=3D32 =
-mb-step
+CCFLAGS =3D   $(KDEBUG) -O2 $(FOMIT) $(GCC_KOPTS) -pipe -ffixed-r13 \
+	 -mfixed-range=3Df10-f15,f32-f127 -falign-functions=3D32 -mb-step
 DEFINES =3D -D__KERNEL__ -DKERNEL -D_KERNEL ${SMP_DEF} -DMODULE
 <all>
 INCLUDES =3D -I. -I../ -I${TOP_SRCDIR}/config

--42002020-1582993119-1035556404=:7040--