Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [patch] modutils 2.4.6: Make __dbe_table available to modules
@ 2001-08-13 13:43 Maciej W. Rozycki
  2001-08-13 14:19 ` Keith Owens
  2001-08-20 14:04 ` [patch] modutils 2.4.6: __dbe_table iteration #2 Maciej W. Rozycki
  0 siblings, 2 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2001-08-13 13:43 UTC (permalink / raw)
  To: Keith Owens, Ralf Baechle, Harald Koerfgen; +Cc: linux-mips, linux-mips

Hi,

 The following patch is needed for modutils to initialize __dbe_table
table pointers appropriately for modules that want to handle bus error
exceptions on MIPS.  A separate patch is needed for the kernel.

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

modutils-2.4.6-mips-dbe.patch
diff -up --recursive --new-file modutils-2.4.6.macro/include/module.h modutils-2.4.6/include/module.h
--- modutils-2.4.6.macro/include/module.h	Fri Jan  5 01:45:19 2001
+++ modutils-2.4.6/include/module.h	Sun Aug 12 13:16:13 2001
@@ -153,6 +153,10 @@ struct module
   unsigned tgt_long cleanup;
   unsigned tgt_long ex_table_start;
   unsigned tgt_long ex_table_end;
+#ifdef __mips__
+  unsigned tgt_long dbe_table_start;
+  unsigned tgt_long dbe_table_end;
+#endif
 #ifdef __alpha__
   unsigned tgt_long gp;
 #endif
diff -up --recursive --new-file modutils-2.4.6.macro/man/init_module.2 modutils-2.4.6/man/init_module.2
--- modutils-2.4.6.macro/man/init_module.2	Fri Jan  5 01:45:19 2001
+++ modutils-2.4.6/man/init_module.2	Sun Aug 12 13:17:14 2001
@@ -39,6 +39,10 @@ struct module
   void (*cleanup)(void);
   const struct exception_table_entry *ex_table_start;
   const struct exception_table_entry *ex_table_end;
+#ifdef __mips__
+  const struct exception_table_entry *dbe_table_start;
+  const struct exception_table_entry *dbe_table_end;
+#endif
 #ifdef __alpha__
   unsigned long gp;
 #endif
diff -up --recursive --new-file modutils-2.4.6.macro/obj/obj_mips.c modutils-2.4.6/obj/obj_mips.c
--- modutils-2.4.6.macro/obj/obj_mips.c	Fri Jan  5 01:45:19 2001
+++ modutils-2.4.6/obj/obj_mips.c	Sun Aug 12 16:16:26 2001
@@ -217,6 +217,15 @@ arch_create_got (struct obj_file *f)
 int
 arch_init_module (struct obj_file *f, struct module *mod)
 {
+  struct obj_section *sec;
+
+  sec = obj_find_section(f, "__dbe_table");
+  if (sec)
+    {
+      mod->dbe_table_start = sec->header.sh_addr;
+      mod->dbe_table_end = sec->header.sh_addr + sec->header.sh_size;
+    }
+
   return 1;
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] modutils 2.4.6: Make __dbe_table available to modules
  2001-08-13 13:43 [patch] modutils 2.4.6: Make __dbe_table available to modules Maciej W. Rozycki
@ 2001-08-13 14:19 ` Keith Owens
  2001-08-13 14:49   ` Maciej W. Rozycki
  2001-08-20 14:04 ` [patch] modutils 2.4.6: __dbe_table iteration #2 Maciej W. Rozycki
  1 sibling, 1 reply; 5+ messages in thread
From: Keith Owens @ 2001-08-13 14:19 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Ralf Baechle, Harald Koerfgen, linux-mips, linux-mips

On Mon, 13 Aug 2001 15:43:56 +0200 (MET DST), 
"Maciej W. Rozycki" <macro@ds2.pg.gda.pl> wrote:
> The following patch is needed for modutils to initialize __dbe_table
>table pointers appropriately for modules that want to handle bus error
>exceptions on MIPS.  A separate patch is needed for the kernel.
>
>modutils-2.4.6-mips-dbe.patch
>diff -up --recursive --new-file modutils-2.4.6.macro/include/module.h modutils-2.4.6/include/module.h
>--- modutils-2.4.6.macro/include/module.h	Fri Jan  5 01:45:19 2001
>+++ modutils-2.4.6/include/module.h	Sun Aug 12 13:16:13 2001
>@@ -153,6 +153,10 @@ struct module
>   unsigned tgt_long cleanup;
>   unsigned tgt_long ex_table_start;
>   unsigned tgt_long ex_table_end;
>+#ifdef __mips__
>+  unsigned tgt_long dbe_table_start;
>+  unsigned tgt_long dbe_table_end;
>+#endif
> #ifdef __alpha__
>   unsigned tgt_long gp;
> #endif

Checking dbe table is fine but where you placed the table in struct
modules is wrong.  You must not insert fields in the middle of struct
module, it introduces version skew between kernel and user space.  At
the very least you have moved the can_unload which will break IPv6 plus
a few other modules.

I understand why you placed it before gp, it looks like the place for
arch dependent code.  The alpha specific data is a hangover that should
never have been there.  modutils 2.3.16 added the archdata_start and
archdata_end fields specifically so each architecture did not have to
keep adding fields and causing size mismatch between kernel and
modutils.  IA64 uses those fields for its unwind data, MIPS can use
archdata for whatever it needs in a module.

In modutils, there is an arch_archdata routine for each architecture.
Most just return but obj/obj_ia64.c::arch_archdata actually does
something.  Copy that routine and create a structure containing two
fields, the start and end of the dbe table.  insmod then sets
archdata_start and archdata_end to point to the structure that points
to the dbe table.  Do not put the dbe table directly in
archdata_{start,end} in case you want to add more mips data later.

In the kernel, module.c verifies that archdata_{start,end} are valid,
if present.  It later calls module_arch_init to handle archdata.
include/asm-$(ARCH)/module.h defines macros module_map, module_unmap
and module_arch_init.  MIPS needs to define the last two.
module_arch_init is passed the struct module so it can find the arch
specific data, decode it and do what it likes with the contents.
module_unmap does any arch specific cleanup, such as removing extra
tables.

For dbe tables, define a mips module_arch_init that validates the
format of the arch specific data.  Probably all you need to do is check
that dbe start and end are inside the module.  Unless you copy the dbe
data elsewhere, module_unmap can be left as vfree.

When you want to verify the dbe table, you run the module list.  If
archdata_end >= archdata_start+2*sizeof(struct exception_table_entry *)
then archdata contains the dbe data.  If dbe_table_end > dbe_table_start
then run the table.  Checking > ignores NULL pointers.

The only other change you have to make is to init_modules().  For mips
you create pointers to the kernel dbe tables and fill in archdata start
and end in kernel_module.  Since init_module is called before kmalloc
is ready, make the kernel dbe table a static variable.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] modutils 2.4.6: Make __dbe_table available to modules
  2001-08-13 14:19 ` Keith Owens
@ 2001-08-13 14:49   ` Maciej W. Rozycki
  2001-08-13 15:14     ` Keith Owens
  0 siblings, 1 reply; 5+ messages in thread
From: Maciej W. Rozycki @ 2001-08-13 14:49 UTC (permalink / raw)
  To: Keith Owens; +Cc: Ralf Baechle, Harald Koerfgen, linux-mips, linux-mips

On Tue, 14 Aug 2001, Keith Owens wrote:

> Checking dbe table is fine but where you placed the table in struct
> modules is wrong.  You must not insert fields in the middle of struct
> module, it introduces version skew between kernel and user space.  At
> the very least you have moved the can_unload which will break IPv6 plus
> a few other modules.
[...]

 Thanks a lot for the detailed explanation.  I'll cook an improvement
soon. 

> The only other change you have to make is to init_modules().  For mips
> you create pointers to the kernel dbe tables and fill in archdata start
> and end in kernel_module.  Since init_module is called before kmalloc
> is ready, make the kernel dbe table a static variable.

 __dbe_table is initialized exactly like __ex_table, i.e. it's a separate
ELF section with pointers to the start and the end computed in a linker
script.  Thus it is fine.  The table has actually been present in the
kernel for quite some time already. 

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] modutils 2.4.6: Make __dbe_table available to modules
  2001-08-13 14:49   ` Maciej W. Rozycki
@ 2001-08-13 15:14     ` Keith Owens
  0 siblings, 0 replies; 5+ messages in thread
From: Keith Owens @ 2001-08-13 15:14 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Ralf Baechle, Harald Koerfgen, linux-mips, linux-mips

On Mon, 13 Aug 2001 16:49:22 +0200 (MET DST), 
"Maciej W. Rozycki" <macro@ds2.pg.gda.pl> wrote:
>On Tue, 14 Aug 2001, Keith Owens wrote:
>> The only other change you have to make is to init_modules().  For mips
>> you create pointers to the kernel dbe tables and fill in archdata start
>> and end in kernel_module.  Since init_module is called before kmalloc
>> is ready, make the kernel dbe table a static variable.
>
> __dbe_table is initialized exactly like __ex_table, i.e. it's a separate
>ELF section with pointers to the start and the end computed in a linker
>script.  Thus it is fine.  The table has actually been present in the
>kernel for quite some time already. 

You still need this:

struct archdata {
  const struct exception_table_entry *dbe_table_start;
  const struct exception_table_entry *dbe_table_end;
};

In init_module:

#ifdef __mips__
  {
    extern const struct exception_table_entry __start___dbe_table[];
    extern const struct exception_table_entry __stop___dbe_table[];
    static struct archdata archdata_mips =
      { __start___dbe_table, __end___dbe_table };
    kernel_module.archdata_start = (char *)&archdata_mips;
    kernel_module.archdata_end = kernel_module.archdata_start +
	sizeof(archdata_mips);
  }
#endif

I really need to add an arch specific init_module routine as well,
instead of conditional code in init_module, but that means changing all
architectures.  Not today.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch] modutils 2.4.6: __dbe_table iteration #2
  2001-08-13 13:43 [patch] modutils 2.4.6: Make __dbe_table available to modules Maciej W. Rozycki
  2001-08-13 14:19 ` Keith Owens
@ 2001-08-20 14:04 ` Maciej W. Rozycki
  1 sibling, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2001-08-20 14:04 UTC (permalink / raw)
  To: Keith Owens, Ralf Baechle; +Cc: linux-mips, linux-mips

Hi,

 Following is a modutils patch that complements __dbe_table handling for
modules for mips.

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

modutils-2.4.6-mips-dbe.patch
diff -up --recursive --new-file modutils-2.4.6.macro/obj/obj_mips.c modutils-2.4.6/obj/obj_mips.c
--- modutils-2.4.6.macro/obj/obj_mips.c	Fri Jan  5 01:45:19 2001
+++ modutils-2.4.6/obj/obj_mips.c	Mon Aug 20 03:47:36 2001
@@ -232,7 +232,26 @@ arch_finalize_section_address(struct obj
 }
 
 int
-arch_archdata (struct obj_file *fin, struct obj_section *sec)
+arch_archdata (struct obj_file *f, struct obj_section *archdata_sec)
 {
+  struct archdata {
+    unsigned tgt_long dbe_table_start;
+    unsigned tgt_long dbe_table_end;
+  } *ad;
+  struct obj_section *sec;
+
+  free(archdata_sec->contents);
+  archdata_sec->contents = xmalloc(sizeof(struct archdata));
+  memset(archdata_sec->contents, 0, sizeof(struct archdata));
+  archdata_sec->header.sh_size = sizeof(struct archdata);
+
+  ad = (struct archdata *)(archdata_sec->contents);
+
+  sec = obj_find_section(f, "__dbe_table");
+  if (sec) {
+    ad->dbe_table_start = sec->header.sh_addr;
+    ad->dbe_table_end = sec->header.sh_addr + sec->header.sh_size;
+  }
+
   return 0;
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-08-20 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-13 13:43 [patch] modutils 2.4.6: Make __dbe_table available to modules Maciej W. Rozycki
2001-08-13 14:19 ` Keith Owens
2001-08-13 14:49   ` Maciej W. Rozycki
2001-08-13 15:14     ` Keith Owens
2001-08-20 14:04 ` [patch] modutils 2.4.6: __dbe_table iteration #2 Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox