Module Name:    src
Committed By:   ozaki-r
Date:           Mon Aug 19 07:45:31 UTC 2024

Modified Files:
        src/sys/net: bpf.c bpfdesc.h

Log Message:
bpf: restore wakeup softint

This change fixes the issue that fownsignal which can take an
adaptive mutex is called inside a pserialize read section in
bpf_deliver.

Fix issue #4 (only the latter of two) in PR#58596


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/net/bpf.c
cvs rdiff -u -r1.48 -r1.49 src/sys/net/bpfdesc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf.c
diff -u src/sys/net/bpf.c:1.255 src/sys/net/bpf.c:1.256
--- src/sys/net/bpf.c:1.255	Thu Aug 15 11:23:39 2024
+++ src/sys/net/bpf.c	Mon Aug 19 07:45:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.255 2024/08/15 11:23:39 riastradh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.256 2024/08/19 07:45:31 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.255 2024/08/15 11:23:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.256 2024/08/19 07:45:31 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -268,6 +268,7 @@ static int	bpf_poll(struct file *, int);
 static int	bpf_stat(struct file *, struct stat *);
 static int	bpf_close(struct file *);
 static int	bpf_kqfilter(struct file *, struct knote *);
+static void	bpf_softintr(void *);
 
 static const struct fileops bpf_fileops = {
 	.fo_name = "bpf",
@@ -602,6 +603,7 @@ bpfopen(dev_t dev, int flag, int mode, s
 	d->bd_atime = d->bd_mtime = d->bd_btime;
 	callout_init(&d->bd_callout, CALLOUT_MPSAFE);
 	selinit(&d->bd_sel);
+	d->bd_sih = softint_establish(SOFTINT_CLOCK, bpf_softintr, d);
 	d->bd_jitcode = NULL;
 	d->bd_rfilter = NULL;
 	d->bd_wfilter = NULL;
@@ -660,6 +662,7 @@ bpf_close(struct file *fp)
 	bpf_freed(d);
 	callout_destroy(&d->bd_callout);
 	seldestroy(&d->bd_sel);
+	softint_disestablish(d->bd_sih);
 	mutex_obj_free(d->bd_mtx);
 	mutex_obj_free(d->bd_buf_mtx);
 	cv_destroy(&d->bd_cv);
@@ -798,11 +801,21 @@ bpf_wakeup(struct bpf_d *d)
 	mutex_exit(d->bd_buf_mtx);
 
 	if (d->bd_async)
-		fownsignal(d->bd_pgid, SIGIO, 0, 0, NULL);
+		softint_schedule(d->bd_sih);
 	selnotify(&d->bd_sel, 0, 0);
 }
 
 static void
+bpf_softintr(void *cookie)
+{
+	struct bpf_d *d;
+
+	d = cookie;
+	if (d->bd_async)
+		fownsignal(d->bd_pgid, SIGIO, 0, 0, NULL);
+}
+
+static void
 bpf_timed_out(void *arg)
 {
 	struct bpf_d *d = arg;

Index: src/sys/net/bpfdesc.h
diff -u src/sys/net/bpfdesc.h:1.48 src/sys/net/bpfdesc.h:1.49
--- src/sys/net/bpfdesc.h:1.48	Wed Jun  9 15:44:15 2021
+++ src/sys/net/bpfdesc.h	Mon Aug 19 07:45:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfdesc.h,v 1.48 2021/06/09 15:44:15 martin Exp $	*/
+/*	$NetBSD: bpfdesc.h,v 1.49 2024/08/19 07:45:31 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -113,7 +113,6 @@ struct bpf_d {
 	pid_t		bd_pid;		/* corresponding PID */
 	/* DEPRECATED. Keep it to avoid breaking kvm(3) users */
 	LIST_ENTRY(bpf_d) _bd_list;	/* list of all BPF's */
-	/* DEPRECATED. Keep it to avoid breaking kvm(3) users */
 	void		*bd_sih;	/* soft interrupt handle */
 	struct timespec bd_atime;	/* access time */
 	struct timespec bd_mtime;	/* modification time */

Reply via email to