From owner-freebsd-net@FreeBSD.ORG Fri Nov 23 11:31:38 2007 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2DF8B16A419 for ; Fri, 23 Nov 2007 11:31:38 +0000 (UTC) (envelope-from max@love2party.net) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.177]) by mx1.freebsd.org (Postfix) with ESMTP id A00AA13C4CE for ; Fri, 23 Nov 2007 11:31:37 +0000 (UTC) (envelope-from max@love2party.net) Received: from amd64.laiers.local (dslb-088-066-054-138.pools.arcor-ip.net [88.66.54.138]) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis) id 0MKxQS-1IvWkL1TWq-0001PI; Fri, 23 Nov 2007 12:31:36 +0100 From: Max Laier Organization: FreeBSD To: freebsd-net@freebsd.org Date: Fri, 23 Nov 2007 12:32:02 +0100 User-Agent: KMail/1.9.7 X-Face: ,,8R(x[kmU]tKN@>gtH1yQE4aslGdu+2]; R]*pL,U>^H?)gW@49@wdJ`H<%}*_BD U_or=\mOZf764&nYj=JYbR1PW0ud>|!~, , CPC.1-D$FG@0h3#'5"k{V]a~. X-Provags-ID: V01U2FsdGVkX188Vna28nS1H5nOVweGIN2hYaEgVu6uZsLsGv6 5UDr4qS+N9zrDlc0GaEc3Z5+kU9dr2v6fSjkimB5bXKP9ieYYh DNzxpKYrDvZYFNv6TTA89sbsDhNwaTs4OBmY/zRt3o= Cc: freebsd-current@freebsd.org Subject: Switch pfil(9) to rmlocks X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Nov 2007 11:31:38 -0000 --nextPart1358903.aygpQnVcZM Content-Type: multipart/mixed; boundary="Boundary-01=_0orRHee3jeSal9c" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_0orRHee3jeSal9c Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, attached is a diff to switch the pfil(9) subsystem to rmlocks, which are=20 more suited for the task. I'd like some exposure before doing the=20 switch, but I don't expect any fallout. This email is going through the=20 patched pfil already - twice. =2D-=20 /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News --Boundary-01=_0orRHee3jeSal9c Content-Type: text/x-diff; charset="us-ascii"; name="pfil.rmlock.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pfil.rmlock.diff" Index: pfil.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/net/pfil.c,v retrieving revision 1.14 diff -u -r1.14 pfil.c =2D-- pfil.c 2 Feb 2006 03:13:15 -0000 1.14 +++ pfil.c 23 Nov 2007 09:06:12 -0000 @@ -34,7 +34,7 @@ #include #include #include =2D#include +#include #include #include #include @@ -66,11 +66,12 @@ pfil_run_hooks(struct pfil_head *ph, struct mbuf **mp, struct ifnet *ifp, int dir, struct inpcb *inp) { + struct rm_priotracker rmpt; struct packet_filter_hook *pfh; struct mbuf *m =3D *mp; int rv =3D 0; =20 =2D PFIL_RLOCK(ph); + PFIL_RLOCK(ph, &rmpt); KASSERT(ph->ph_nhooks >=3D 0, ("Pfil hook count dropped < 0")); for (pfh =3D pfil_hook_get(dir, ph); pfh !=3D NULL; pfh =3D TAILQ_NEXT(pfh, pfil_link)) { @@ -80,7 +81,7 @@ break; } } =2D PFIL_RUNLOCK(ph); + PFIL_RUNLOCK(ph, &rmpt); =09 *mp =3D m; return (rv); @@ -104,7 +105,7 @@ } PFIL_LIST_UNLOCK(); =20 =2D rw_init(&ph->ph_mtx, "PFil hook read/write mutex"); + PFIL_LOCK_INIT(ph); PFIL_WLOCK(ph); ph->ph_nhooks =3D 0; =20 @@ -143,7 +144,7 @@ free(pfh, M_IFADDR); TAILQ_FOREACH_SAFE(pfh, &ph->ph_out, pfil_link, pfnext) free(pfh, M_IFADDR); =2D rw_destroy(&ph->ph_mtx); + PFIL_LOCK_DESTROY(ph); =09 return (0); } Index: pfil.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/net/pfil.h,v retrieving revision 1.16 diff -u -r1.16 pfil.h =2D-- pfil.h 8 Jun 2007 12:43:25 -0000 1.16 +++ pfil.h 23 Nov 2007 10:07:52 -0000 @@ -37,7 +37,7 @@ #include #include #include =2D#include +#include =20 struct mbuf; struct ifnet; @@ -69,7 +69,7 @@ pfil_list_t ph_out; int ph_type; int ph_nhooks; =2D struct rwlock ph_mtx; + struct rmlock ph_lock; union { u_long phu_val; void *phu_ptr; @@ -93,10 +93,13 @@ struct pfil_head *pfil_head_get(int, u_long); =20 #define PFIL_HOOKED(p) ((p)->ph_nhooks > 0) =2D#define PFIL_RLOCK(p) rw_rlock(&(p)->ph_mtx) =2D#define PFIL_WLOCK(p) rw_wlock(&(p)->ph_mtx) =2D#define PFIL_RUNLOCK(p) rw_runlock(&(p)->ph_mtx) =2D#define PFIL_WUNLOCK(p) rw_wunlock(&(p)->ph_mtx) +#define PFIL_LOCK_INIT(p) \ + rm_init(&(p)->ph_lock, "PFil hook read/write mutex", LO_RECURSABLE) +#define PFIL_LOCK_DESTROY(p) rm_destroy(&(p)->ph_lock) +#define PFIL_RLOCK(p, t) rm_rlock(&(p)->ph_lock, (t)) +#define PFIL_WLOCK(p) rm_wlock(&(p)->ph_lock) +#define PFIL_RUNLOCK(p, t) rm_runlock(&(p)->ph_lock, (t)) +#define PFIL_WUNLOCK(p) rm_wunlock(&(p)->ph_lock) #define PFIL_LIST_LOCK() mtx_lock(&pfil_global_lock) #define PFIL_LIST_UNLOCK() mtx_unlock(&pfil_global_lock) =20 --Boundary-01=_0orRHee3jeSal9c-- --nextPart1358903.aygpQnVcZM Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQBHRro0XyyEoT62BG0RAgY8AJwMKInml8vHn2NiixsHhQypPVx54wCdERxk oRAzo5XwbyCWozTdm6bJZEY= =5Yeg -----END PGP SIGNATURE----- --nextPart1358903.aygpQnVcZM--