From owner-svn-src-all@FreeBSD.ORG Tue Jun 10 17:17:45 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2E406C30; Tue, 10 Jun 2014 17:17:45 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 01CC52CD3; Tue, 10 Jun 2014 17:17:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5AHHiXx012909; Tue, 10 Jun 2014 17:17:44 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5AHHiAR012908; Tue, 10 Jun 2014 17:17:44 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201406101717.s5AHHiAR012908@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 10 Jun 2014 17:17:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r267333 - stable/10/sys/dev/netmap X-SVN-Group: stable-10 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.18 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: Tue, 10 Jun 2014 17:17:45 -0000 Author: luigi Date: Tue Jun 10 17:17:44 2014 New Revision: 267333 URL: http://svnweb.freebsd.org/changeset/base/267333 Log: MFC 267328: change the netmap mbuf destructor so the same code works also on FreeBSD 9. For head and 10 this change has no effect, but on stable/9 it would cause panics when using emulated netmap on top of a standard device driver. MFC after: 3 days Modified: stable/10/sys/dev/netmap/netmap_generic.c Modified: stable/10/sys/dev/netmap/netmap_generic.c ============================================================================== --- stable/10/sys/dev/netmap/netmap_generic.c Tue Jun 10 17:05:41 2014 (r267332) +++ stable/10/sys/dev/netmap/netmap_generic.c Tue Jun 10 17:17:44 2014 (r267333) @@ -102,24 +102,30 @@ __FBSDID("$FreeBSD$"); * mbuf wrappers */ -/* mbuf destructor, also need to change the type to EXT_EXTREF, +/* + * mbuf destructor, also need to change the type to EXT_EXTREF, * add an M_NOFREE flag, and then clear the flag and * chain into uma_zfree(zone_pack, mf) * (or reinstall the buffer ?) + * + * On FreeBSD 9 the destructor is called as ext_free(ext_arg1, ext_arg2) + * whereas newer version have ext_free(m, ext_arg1, ext_arg2) + * For compatibility we set ext_arg1 = m on allocation so we have + * the same code on both. */ #define SET_MBUF_DESTRUCTOR(m, fn) do { \ - (m)->m_ext.ext_free = (void *)fn; \ - (m)->m_ext.ext_type = EXT_EXTREF; \ -} while (0) + (m)->m_ext.ext_free = (void *)fn; \ + (m)->m_ext.ext_type = EXT_EXTREF; \ + } while (0) static void -netmap_default_mbuf_destructor(struct mbuf *m) +netmap_default_mbuf_destructor(struct mbuf *m) { - /* restore original mbuf */ - m->m_ext.ext_buf = m->m_data = m->m_ext.ext_arg1; - m->m_ext.ext_arg1 = NULL; + /* restore original data pointer and type */ + m->m_ext.ext_buf = m->m_data = m->m_ext.ext_arg2; m->m_ext.ext_type = EXT_PACKET; m->m_ext.ext_free = NULL; + m->m_ext.ext_arg1 = m->m_ext.ext_arg2 = NULL; if (*(m->m_ext.ref_cnt) == 0) *(m->m_ext.ref_cnt) = 1; uma_zfree(zone_pack, m); @@ -131,7 +137,8 @@ netmap_get_mbuf(int len) struct mbuf *m; m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR | M_NOFREE); if (m) { - m->m_ext.ext_arg1 = m->m_ext.ext_buf; // XXX save + m->m_ext.ext_arg1 = m; /* FreeBSD 9 compat */ + m->m_ext.ext_arg2 = m->m_ext.ext_buf; /* save original */ m->m_ext.ext_free = (void *)netmap_default_mbuf_destructor; m->m_ext.ext_type = EXT_EXTREF; ND(5, "create m %p refcnt %d", m, *m->m_ext.ref_cnt);