Hallo,
On Sun, Apr 12, 2020 at 07:02:43PM +0200, Mark Kettenis wrote:
> > From: "Theo de Raadt" <[email protected]>
> > Date: Sun, 12 Apr 2020 10:28:59 -0600
> >
> > > + if ((p->p_flag & P_SYSTEM) &&
> > > + (strncmp(p->p_p->ps_comm, "softnet", 7) == 0))
> >
> > Wow that is ugly.
>
> A better approach might be to store a pointer to the softnet task's
> struct proc in a global variable and check that. That is what we do
> for the pagedaemon for example.
>
I'm not sure same thing would work for network task. Currently
there is a single instance of pagedaemon, however we hope to
have more network tasks running in parallel.
How about sticking a magic flag to proc and task? The idea is just
shown in diff below. Just idea I have not tried to compile it.
regards
sashan
--------8<---------------8<---------------8<------------------8<--------
diff --git a/sys/kern/kern_task.c b/sys/kern/kern_task.c
index 5ed4e3a7c39..0698041c3aa 100644
--- a/sys/kern/kern_task.c
+++ b/sys/kern/kern_task.c
@@ -53,6 +53,7 @@ struct taskq {
#ifdef WITNESS
struct lock_object tq_lock_object;
#endif
+ int tq_magic;
};
static const char taskq_sys_name[] = "systq";
@@ -129,6 +130,7 @@ taskq_create(const char *name, unsigned int nthreads, int
ipl,
tq->tq_nthreads = nthreads;
tq->tq_name = name;
tq->tq_flags = flags;
+ tq->tq_magic = 0;
mtx_init_flags(&tq->tq_mtx, ipl, name, 0);
TAILQ_INIT(&tq->tq_worklist);
@@ -146,6 +148,18 @@ taskq_create(const char *name, unsigned int nthreads, int
ipl,
return (tq);
}
+struct taskq *
+taskq_create_magic(const char *name, unsigned int nthreads, int ipl,
+ unsigned int flags, int magic)
+{
+ struct taskq *tq;
+
+ tq = taskq_create(nmae, nthreads, ipl, flags);
+ if (tq != NULL)
+ tq->tq_magic = magic;
+ return (tq);
+}
+
void
taskq_destroy(struct taskq *tq)
{
@@ -364,8 +378,11 @@ taskq_thread(void *xtq)
WITNESS_CHECKORDER(&tq->tq_lock_object, LOP_NEWORDER, NULL);
while (taskq_next_work(tq, &work)) {
+ struct proc *p = curproc;
WITNESS_LOCK(&tq->tq_lock_object, 0);
+ p->p_magic = tq->tq_magic;
(*work.t_func)(work.t_arg);
+ p->p_magic = 0;
WITNESS_UNLOCK(&tq->tq_lock_object, 0);
sched_pause(yield);
}
diff --git a/sys/net/if.c b/sys/net/if.c
index 176fcf849fd..442a7bcec9a 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -266,7 +266,8 @@ ifinit(void)
timeout_set(&net_tick_to, net_tick, &net_tick_to);
for (i = 0; i < NET_TASKQ; i++) {
- nettqmp[i] = taskq_create("softnet", 1, IPL_NET, TASKQ_MPSAFE);
+ nettqmp[i] = taskq_create_magic("softnet", 1, IPL_NET,
+ TASKQ_MPSAFE, 0x0030fd7ed); /* SOFTNET task */
if (nettqmp[i] == NULL)
panic("unable to create network taskq %d", i);
}
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index a25cb52951d..51ac96da5cc 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -408,6 +408,7 @@ struct proc {
union sigval p_sigval; /* For core dump/debugger XXX */
long p_sitrapno; /* For core dump/debugger XXX */
int p_sicode; /* For core dump/debugger XXX */
+ int p_magic; /* Identifies process context (for asserts) */
};
/* Status values. */