From owner-svn-src-all@freebsd.org Sat Feb 25 08:07:30 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4123DCEC3BE; Sat, 25 Feb 2017 08:07:30 +0000 (UTC) (envelope-from cy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1BAFA8F2; Sat, 25 Feb 2017 08:07:30 +0000 (UTC) (envelope-from cy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1P87Tme028665; Sat, 25 Feb 2017 08:07:29 GMT (envelope-from cy@FreeBSD.org) Received: (from cy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1P87SpI028662; Sat, 25 Feb 2017 08:07:28 GMT (envelope-from cy@FreeBSD.org) Message-Id: <201702250807.v1P87SpI028662@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cy set sender to cy@FreeBSD.org using -f From: Cy Schubert Date: Sat, 25 Feb 2017 08:07:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r314251 - in stable: 10/contrib/ipfilter/lib 10/sys/contrib/ipfilter/netinet 11/contrib/ipfilter/lib 11/sys/contrib/ipfilter/netinet X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Feb 2017 08:07:30 -0000 Author: cy Date: Sat Feb 25 08:07:28 2017 New Revision: 314251 URL: https://svnweb.freebsd.org/changeset/base/314251 Log: MFC r312787: Currently the fragment info is placed at the top of the linked list under a shared read lock. This patch attempts to upgrade the lock to an exclusive write lock. If the exclusive write lock fails to be obtained, the current fragment is not placed at the head of the list. This portion of the patch was inspired by NetBSD ip_frag.c r1.4 (which effectively removed the section of code that performed the reordering). The patch to sys/contrib/ipfilter/netinet/ip_compat.h adds the MUTEX_TRY_UPGRADE macro to support the patch to ip_frag.c. The patch to contrib/ipfilter/lib/rwlock_emul.c supports this patch by emulating the mutex in userspace when exercised by ipftest(1). Inspired by: NetBSD ip_frag.c r1.4 Modified: stable/11/contrib/ipfilter/lib/rwlock_emul.c stable/11/sys/contrib/ipfilter/netinet/ip_compat.h stable/11/sys/contrib/ipfilter/netinet/ip_frag.c Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/10/contrib/ipfilter/lib/rwlock_emul.c stable/10/sys/contrib/ipfilter/netinet/ip_compat.h stable/10/sys/contrib/ipfilter/netinet/ip_frag.c Directory Properties: stable/10/ (props changed) Modified: stable/11/contrib/ipfilter/lib/rwlock_emul.c ============================================================================== --- stable/11/contrib/ipfilter/lib/rwlock_emul.c Sat Feb 25 06:11:59 2017 (r314250) +++ stable/11/contrib/ipfilter/lib/rwlock_emul.c Sat Feb 25 08:07:28 2017 (r314251) @@ -56,6 +56,27 @@ void eMrwlock_write_enter(rw, file, line } +void eMrwlock_try_upgrade(rw, file, line) + eMrwlock_t *rw; + char *file; + int line; +{ + if (rw->eMrw_magic != EMM_MAGIC) { + fprintf(stderr, "%s:eMrwlock_write_enter(%p): bad magic: %#x\n", + rw->eMrw_owner, rw, rw->eMrw_magic); + abort(); + } + if (rw->eMrw_read != 0 || rw->eMrw_write != 0) { + fprintf(stderr, + "%s:eMrwlock_try_upgrade(%p): already locked: %d/%d\n", + rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write); + abort(); + } + rw->eMrw_write++; + rw->eMrw_heldin = file; + rw->eMrw_heldat = line; +} + void eMrwlock_downgrade(rw, file, line) eMrwlock_t *rw; char *file; Modified: stable/11/sys/contrib/ipfilter/netinet/ip_compat.h ============================================================================== --- stable/11/sys/contrib/ipfilter/netinet/ip_compat.h Sat Feb 25 06:11:59 2017 (r314250) +++ stable/11/sys/contrib/ipfilter/netinet/ip_compat.h Sat Feb 25 08:07:28 2017 (r314251) @@ -165,6 +165,7 @@ struct ether_addr { # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk) # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk) # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk) +# define MUTEX_TRY_UPGRADE(x) rw_try_upgrade(&(x)->ipf_lk) # define RWLOCK_INIT(x,y) rw_init(&(x)->ipf_lk, (y)) # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk) # define RWLOCK_EXIT(x) do { \ @@ -420,6 +421,8 @@ extern void freembt __P((mb_t *)); # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \ __FILE__, __LINE__) +# define MUTEX_TRY_UPGRADE(x) eMrwlock_try_upgrade(&(x)->ipf_emu, \ + __FILE__, __LINE__) # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \ __FILE__, __LINE__) # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y) @@ -670,6 +673,7 @@ extern char *ipf_getifname __P((struct i # define READ_ENTER(x) ; # define WRITE_ENTER(x) ; # define MUTEX_DOWNGRADE(x) ; +# define MUTEX_TRY_UPGRADE(x) ; # define RWLOCK_INIT(x, y) ; # define RWLOCK_EXIT(x) ; # define RW_DESTROY(x) ; Modified: stable/11/sys/contrib/ipfilter/netinet/ip_frag.c ============================================================================== --- stable/11/sys/contrib/ipfilter/netinet/ip_frag.c Sat Feb 25 06:11:59 2017 (r314250) +++ stable/11/sys/contrib/ipfilter/netinet/ip_frag.c Sat Feb 25 08:07:28 2017 (r314251) @@ -745,7 +745,7 @@ ipf_frag_lookup(softc, softf, fin, table } else if (off == 0) f->ipfr_seen0 = 1; - if (f != table[idx]) { + if (f != table[idx] && MUTEX_TRY_UPGRADE(lock)) { ipfr_t **fp; /* @@ -763,6 +763,7 @@ ipf_frag_lookup(softc, softf, fin, table table[idx]->ipfr_hprev = &f->ipfr_hnext; f->ipfr_hprev = table + idx; table[idx] = f; + MUTEX_DOWNGRADE(lock); } /*