dummynet: don't use per-vnet locks to protect global data.

The ref_count counter is global (i.e. not per-vnet) so we can't use a
per-vnet lock to protect it. Moreover, in callouts curvnet is not set,
so we'd end up panicing when trying to use DN_BH_WLOCK().

Instead we use the global sched_lock, which is already used when
evaluating ref_count (in unload_dn_aqm()).

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D34059
This commit is contained in:
Kristof Provost 2022-01-27 11:41:21 +01:00
parent 5e8e302087
commit 3f3e4f3c74
4 changed files with 22 additions and 4 deletions

View File

@ -597,8 +597,10 @@ aqm_pie_init(struct dn_queue *q)
}
pst = q->aqm_status;
dummynet_sched_lock();
/* increase reference count for PIE module */
pie_desc.ref_count++;
dummynet_sched_unlock();
pst->pq = q;
pst->parms = pprms;
@ -632,9 +634,9 @@ pie_callout_cleanup(void *x)
mtx_unlock(&pst->lock_mtx);
mtx_destroy(&pst->lock_mtx);
free(x, M_DUMMYNET);
DN_BH_WLOCK();
dummynet_sched_lock();
pie_desc.ref_count--;
DN_BH_WUNLOCK();
dummynet_sched_unlock();
}
/*

View File

@ -581,7 +581,7 @@ fqpie_callout_cleanup(void *x)
mtx_destroy(&pst->lock_mtx);
psi_extra = q->psi_extra;
DN_BH_WLOCK();
dummynet_sched_lock();
psi_extra->nr_active_q--;
/* when all sub-queues are destroyed, free flows fq_pie extra vars memory */
@ -590,7 +590,7 @@ fqpie_callout_cleanup(void *x)
free(psi_extra, M_DUMMYNET);
fq_pie_desc.ref_count--;
}
DN_BH_WUNLOCK();
dummynet_sched_unlock();
}
/*
@ -1061,7 +1061,9 @@ fq_pie_new_sched(struct dn_sch_inst *_si)
pie_init(&flows[i], schk);
}
dummynet_sched_lock();
fq_pie_desc.ref_count++;
dummynet_sched_unlock();
return 0;
}

View File

@ -399,6 +399,8 @@ VNET_DECLARE(struct dn_parms, dn_cfg);
#define V_dn_cfg VNET(dn_cfg)
int dummynet_io(struct mbuf **, struct ip_fw_args *);
void dummynet_sched_lock(void);
void dummynet_sched_unlock(void);
void dummynet_task(void *context, int pending);
void dn_reschedule(void);
struct dn_pkt_tag * dn_tag_get(struct mbuf *m);

View File

@ -109,6 +109,18 @@ dummynet(void *arg)
taskqueue_enqueue(dn_tq, &dn_task);
}
void
dummynet_sched_lock(void)
{
mtx_lock(&sched_mtx);
}
void
dummynet_sched_unlock(void)
{
mtx_unlock(&sched_mtx);
}
void
dn_reschedule(void)
{