From: Michael Ellerman When the iseries_veth driver module is unloaded there is the potential for an oops and also some memory leakage. Because the HvLpEvent_unregisterHandler() function did no synchronisation, it was possible for the handler that was being unregistered to be running on another CPU *after* HvLpEvent_unregisterHandler() had returned. This could cause the iseries_veth driver to leave work in the events work queue after the module had been unloaded. When that work was eventually executed we got an oops. In addition some of the data structures in the iseries_veth driver were not being correctly freed when the module was unloaded. This is the first patch, which makes HvLpEvent_unregisterHandler() work. Signed-off-by: Michael Ellerman Signed-off-by: Andrew Morton --- 25-akpm/arch/ppc64/kernel/HvLpEvent.c | 8 ++++++++ 25-akpm/include/asm-ppc64/iSeries/HvLpEvent.h | 3 +++ 2 files changed, 11 insertions(+) diff -puN arch/ppc64/kernel/HvLpEvent.c~ppc64-make-hvlpevent_unregisterhandler-work arch/ppc64/kernel/HvLpEvent.c --- 25/arch/ppc64/kernel/HvLpEvent.c~ppc64-make-hvlpevent_unregisterhandler-work Wed Jan 12 14:50:17 2005 +++ 25-akpm/arch/ppc64/kernel/HvLpEvent.c Wed Jan 12 14:50:17 2005 @@ -34,10 +34,18 @@ int HvLpEvent_registerHandler( HvLpEvent int HvLpEvent_unregisterHandler( HvLpEvent_Type eventType ) { int rc = 1; + + might_sleep(); + if ( eventType < HvLpEvent_Type_NumTypes ) { if ( !lpEventHandlerPaths[eventType] ) { lpEventHandler[eventType] = NULL; rc = 0; + + /* We now sleep until all other CPUs have scheduled. This ensures that + * the deletion is seen by all other CPUs, and that the deleted handler + * isn't still running on another CPU when we return. */ + synchronize_kernel(); } } return rc; diff -puN include/asm-ppc64/iSeries/HvLpEvent.h~ppc64-make-hvlpevent_unregisterhandler-work include/asm-ppc64/iSeries/HvLpEvent.h --- 25/include/asm-ppc64/iSeries/HvLpEvent.h~ppc64-make-hvlpevent_unregisterhandler-work Wed Jan 12 14:50:17 2005 +++ 25-akpm/include/asm-ppc64/iSeries/HvLpEvent.h Wed Jan 12 14:50:17 2005 @@ -75,6 +75,9 @@ typedef void (*LpEventHandler)(struct Hv extern int HvLpEvent_registerHandler( HvLpEvent_Type eventType, LpEventHandler hdlr); // Unregister a handler for an event type +// This call will sleep until the handler being removed is guaranteed to +// be no longer executing on any CPU. Do not call with locks held. +// // returns 0 on success // Unregister will fail if there are any paths open for the type extern int HvLpEvent_unregisterHandler( HvLpEvent_Type eventType ); _