Re: Locking for module_autoload() (was: Modules loading modules?)

2010-08-02 Thread Adam Hamsik

On Aug,Monday 2 2010, at 4:27 AM, Paul Goyette wrote:

> On Sun, 1 Aug 2010, John Nemeth wrote:
> 
>>I'm thinking the acquisition of module_lock should be pushed into
>> module_autoload() instead of having the caller acquire it for this very
>> reason.  It makes it hard to change the way locking works in the
>> MODULAR code if you expect the caller to acquire the lock.  I don't
>> know why it was done this way originally, or what the consequences (if
>> any) would be for making the change.  Andrew, any thoughts on this?
> 
> Attached are diffs for moving the locking out of each caller and into 
> module_autoload() itself.  Most of these changes are fairly trivial, but a 
> couple of them should be looked at more closely in case I've missed any 
> subtleties in the original code:
> 
>   kern/kern_syscall.c
>   net/if_ppp.c

I think that this patch has same problem as original code you can call 
module_autoload twice in same lwp. (you are holding module_lock while calling 
module_do_load).

Regards

Adam.



Re: Locking for module_autoload() (was: Modules loading modules?)

2010-08-01 Thread Paul Goyette

On Mon, 2 Aug 2010, Adam Hamsik wrote:



On Aug,Monday 2 2010, at 4:27 AM, Paul Goyette wrote:


On Sun, 1 Aug 2010, John Nemeth wrote:


   I'm thinking the acquisition of module_lock should be pushed into
module_autoload() instead of having the caller acquire it for this very
reason.  It makes it hard to change the way locking works in the
MODULAR code if you expect the caller to acquire the lock.  I don't
know why it was done this way originally, or what the consequences (if
any) would be for making the change.  Andrew, any thoughts on this?


Attached are diffs for moving the locking out of each caller and into 
module_autoload() itself.  Most of these changes are fairly trivial, but a 
couple of them should be looked at more closely in case I've missed any 
subtleties in the original code:

kern/kern_syscall.c
net/if_ppp.c


I think that this patch has same problem as original code you can call 
module_autoload twice in same lwp. (you are holding module_lock while 
calling module_do_load).


This patch wasn;t intended to solve the nested-call problem.  This patch 
only purpose was to modify the existing semantics of the module_autoload 
routine to match that of the other module routines.  In particular, 
module_autoload is the only routine that requires its caller to acquire 
the mutex first;  all the other routines do all the required locking 
internally to each routine.



-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-


Re: Locking for module_autoload() (was: Modules loading modules?)

2010-08-01 Thread Paul Goyette

On Sun, 1 Aug 2010, John Nemeth wrote:


I'm thinking the acquisition of module_lock should be pushed into
module_autoload() instead of having the caller acquire it for this very
reason.  It makes it hard to change the way locking works in the
MODULAR code if you expect the caller to acquire the lock.  I don't
know why it was done this way originally, or what the consequences (if
any) would be for making the change.  Andrew, any thoughts on this?


Attached are diffs for moving the locking out of each caller and into 
module_autoload() itself.  Most of these changes are fairly trivial, but 
a couple of them should be looked at more closely in case I've missed 
any subtleties in the original code:


kern/kern_syscall.c
net/if_ppp.c


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-Index: dev/acpi/acpi.c
===
RCS file: /cvsroot/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.208
diff -u -p -r1.208 acpi.c
--- dev/acpi/acpi.c 25 Jul 2010 12:54:46 -  1.208
+++ dev/acpi/acpi.c 2 Aug 2010 02:25:26 -
@@ -226,11 +226,8 @@ acpi_null(void)
 void
 acpi_load_verbose(void)
 {
-   if (acpi_verbose_loaded == 0) {
-   mutex_enter(&module_lock);
+   if (acpi_verbose_loaded == 0)
module_autoload("acpiverbose", MODULE_CLASS_MISC);
-   mutex_exit(&module_lock);
-   }
 }
 
 void
Index: dev/dm/dm_target.c
===
RCS file: /cvsroot/src/sys/dev/dm/dm_target.c,v
retrieving revision 1.13
diff -u -p -r1.13 dm_target.c
--- dev/dm/dm_target.c  18 May 2010 15:10:41 -  1.13
+++ dev/dm/dm_target.c  2 Aug 2010 02:25:26 -
@@ -83,9 +83,7 @@ dm_target_autoload(const char *dm_target
gen = module_gen;
 
/* Try to autoload target module */
-   mutex_enter(&module_lock);
(void) module_autoload(name, MODULE_CLASS_MISC);
-   mutex_exit(&module_lock);
} while (gen != module_gen);
 
mutex_enter(&dm_target_mutex);
Index: dev/mii/mii_physubr.c
===
RCS file: /cvsroot/src/sys/dev/mii/mii_physubr.c,v
retrieving revision 1.71
diff -u -p -r1.71 mii_physubr.c
--- dev/mii/mii_physubr.c   25 Jul 2010 14:44:34 -  1.71
+++ dev/mii/mii_physubr.c   2 Aug 2010 02:25:27 -
@@ -71,11 +71,8 @@ const char *mii_get_descr_stub(int oui, 
  */
 void mii_load_verbose(void)
 {
-   if (mii_verbose_loaded == 0) {
-   mutex_enter(&module_lock);
+   if (mii_verbose_loaded == 0)
module_autoload("miiverbose", MODULE_CLASS_MISC);
-   mutex_exit(&module_lock);
-   }
 }  
 
 static void mii_phy_statusmsg(struct mii_softc *);
Index: dev/pci/pci_subr.c
===
RCS file: /cvsroot/src/sys/dev/pci/pci_subr.c,v
retrieving revision 1.84
diff -u -p -r1.84 pci_subr.c
--- dev/pci/pci_subr.c  25 Jul 2010 14:14:25 -  1.84
+++ dev/pci/pci_subr.c  2 Aug 2010 02:25:27 -
@@ -323,11 +323,8 @@ int pciverbose_loaded = 0;
  */
 void pci_load_verbose(void)
 {
-   if (pciverbose_loaded == 0) {
-   mutex_enter(&module_lock);
+   if (pciverbose_loaded == 0)
module_autoload("pciverbose", MODULE_CLASS_MISC);
-   mutex_exit(&module_lock);
-   }
 }
 
 const char *pci_findvendor_stub(pcireg_t id_reg)
Index: dev/scsipi/scsipiconf.c
===
RCS file: /cvsroot/src/sys/dev/scsipi/scsipiconf.c,v
retrieving revision 1.39
diff -u -p -r1.39 scsipiconf.c
--- dev/scsipi/scsipiconf.c 25 Jul 2010 13:49:58 -  1.39
+++ dev/scsipi/scsipiconf.c 2 Aug 2010 02:25:27 -
@@ -107,11 +107,8 @@ scsipi_command(struct scsipi_periph *per
 void
 scsipi_load_verbose(void)
 {
-   if (scsi_verbose_loaded == 0) {
-   mutex_enter(&module_lock);
+   if (scsi_verbose_loaded == 0)
module_autoload("scsiverbose", MODULE_CLASS_MISC);
-   mutex_exit(&module_lock);
-   }
 }
 
 /*
Index: dev/usb/usb_subr.c
===
RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.174
diff -u -p -r1.174 usb_subr.c
--- dev/usb/usb_subr.c  27 Jul 2010 16:15:30 -  1.174
+++ dev/usb/usb_subr.c  2 Aug 2010 02:25:27 -
@@ -122,11 +122,8 @@ int usb_verbose_loaded = 0;
  */
 void usb_load_verbose(void)
 {
-