From owner-svn-src-head@FreeBSD.ORG Thu Sep 11 07:16:16 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 73CFAABC; Thu, 11 Sep 2014 07:16:16 +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 5E4F49FF; Thu, 11 Sep 2014 07:16:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8B7GGP5056973; Thu, 11 Sep 2014 07:16:16 GMT (envelope-from rwatson@FreeBSD.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8B7GF7C056969; Thu, 11 Sep 2014 07:16:15 GMT (envelope-from rwatson@FreeBSD.org) Message-Id: <201409110716.s8B7GF7C056969@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: rwatson set sender to rwatson@FreeBSD.org using -f From: Robert Watson Date: Thu, 11 Sep 2014 07:16:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271420 - in head/sys: dev/cxgbe/common sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Sep 2014 07:16:16 -0000 Author: rwatson Date: Thu Sep 11 07:16:15 2014 New Revision: 271420 URL: http://svnweb.freebsd.org/changeset/base/271420 Log: Add new a M_START() mbuf macro that returns a pointer to the start of an mbuf's storage (internal or external). Add a new M_SIZE() mbuf macro that returns the size of an mbuf's storage (internal or external). These contrast with m_data and m_len, which are with respect to data in the buffer, rather than the buffer itself. Rewrite M_LEADINGSPACE() and M_TRAILINGSPACE() in terms of M_START() and M_SIZE(). This is done as we currently have many instances of using mbuf flags to generate pointers or lengths for internal storage in header and regular mbufs, as well as to external storage. Rather than replicate this logic throughout the network stack, centralising the implementation will make it easier for us to refine mbuf storage. This should also help reduce bugs by limiting the amount of mbuf-type-specific pointer arithmetic. Followup changes will propagate use of the macros throughout the stack. M_SIZE() conflicts with one macro in the Chelsio driver; rename that macro in a slightly unsatisfying way to eliminate the collision. MFC after: 3 days Obtained from: jeff (with enhancements) Sponsored by: EMC / Isilon Storage Division Reviewed by: bz, glebius, np Differential Revision: https://reviews.freebsd.org/D753 Modified: head/sys/dev/cxgbe/common/t4_regs.h head/sys/sys/mbuf.h Modified: head/sys/dev/cxgbe/common/t4_regs.h ============================================================================== --- head/sys/dev/cxgbe/common/t4_regs.h Thu Sep 11 06:17:56 2014 (r271419) +++ head/sys/dev/cxgbe/common/t4_regs.h Thu Sep 11 07:16:15 2014 (r271420) @@ -1073,9 +1073,9 @@ #define A_SGE_FL_BUFFER_SIZE0 0x1044 #define S_SIZE 4 -#define M_SIZE 0xfffffffU +#define CXGBE_M_SIZE 0xfffffffU #define V_SIZE(x) ((x) << S_SIZE) -#define G_SIZE(x) (((x) >> S_SIZE) & M_SIZE) +#define G_SIZE(x) (((x) >> S_SIZE) & CXGBE_M_SIZE) #define A_SGE_FL_BUFFER_SIZE1 0x1048 #define A_SGE_FL_BUFFER_SIZE2 0x104c Modified: head/sys/sys/mbuf.h ============================================================================== --- head/sys/sys/mbuf.h Thu Sep 11 06:17:56 2014 (r271419) +++ head/sys/sys/mbuf.h Thu Sep 11 07:16:15 2014 (r271420) @@ -843,29 +843,50 @@ m_last(struct mbuf *m) } while (0) /* + * Return the address of the start of the buffer associated with an mbuf, + * handling external storage, packet-header mbufs, and regular data mbufs. + */ +#define M_START(m) \ + (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_buf : \ + ((m)->m_flags & M_PKTHDR) ? &(m)->m_pktdat[0] : \ + &(m)->m_dat[0]) + +/* + * Return the size of the buffer associated with an mbuf, handling external + * storage, packet-header mbufs, and regular data mbufs. + */ +#define M_SIZE(m) \ + (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \ + ((m)->m_flags & M_PKTHDR) ? MHLEN : \ + MLEN) + +/* * Compute the amount of space available before the current start of data in * an mbuf. * * The M_WRITABLE() is a temporary, conservative safety measure: the burden * of checking writability of the mbuf data area rests solely with the caller. + * + * NB: In previous versions, M_LEADINGSPACE() would only check M_WRITABLE() + * for mbufs with external storage. We now allow mbuf-embedded data to be + * read-only as well. */ #define M_LEADINGSPACE(m) \ - ((m)->m_flags & M_EXT ? \ - (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ - (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ - (m)->m_data - (m)->m_dat) + (M_WRITABLE(m) ? ((m)->m_data - M_START(m)) : 0) /* * Compute the amount of space available after the end of data in an mbuf. * * The M_WRITABLE() is a temporary, conservative safety measure: the burden * of checking writability of the mbuf data area rests solely with the caller. + * + * NB: In previous versions, M_TRAILINGSPACE() would only check M_WRITABLE() + * for mbufs with external storage. We now allow mbuf-embedded data to be + * read-only as well. */ #define M_TRAILINGSPACE(m) \ - ((m)->m_flags & M_EXT ? \ - (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \ - - ((m)->m_data + (m)->m_len) : 0) : \ - &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)) + (M_WRITABLE(m) ? \ + ((M_START(m) + M_SIZE(m)) - ((m)->m_data + (m)->m_len)) : 0) /* * Arrange to prepend space of size plen to mbuf m. If a new mbuf must be