virtio_p9fs: Fix kernel panic on module unload
The virtio_p9fs module event handler can be invoked multiple times. Previously, this caused p9_init_zones() and p9_register_trans() to be executed multiple times, leaking UMA zones and corrupting the transport list. During module unload, p9_destroy_zones() was also called multiple times on the same zone pointers, triggering a duplicate free kernel panic in uma_zdestroy(). This patch introduces a static reference counter in vt9p_modevent() to ensure the zones and transports are only initialized and destroyed exactly once, aligning with the approach used by other virtio drivers like vtnet. Reviewed by: kib, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D56497
This commit is contained in:
@@ -464,16 +464,22 @@ static int
|
||||
vt9p_modevent(module_t mod, int type, void *unused)
|
||||
{
|
||||
int error;
|
||||
static int loaded = 0;
|
||||
|
||||
error = 0;
|
||||
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
p9_init_zones();
|
||||
p9_register_trans(&vt9p_trans);
|
||||
if (loaded++ == 0) {
|
||||
p9_init_zones();
|
||||
p9_register_trans(&vt9p_trans);
|
||||
}
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
p9_destroy_zones();
|
||||
if (--loaded == 0) {
|
||||
p9_unregister_trans(&vt9p_trans);
|
||||
p9_destroy_zones();
|
||||
}
|
||||
break;
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user