Subject: Re: M_READONLY
To: None <thorpej@shagadelic.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-net
Date: 09/21/2004 20:10:53
--NextPart-20040921200516-0035900
Content-Type: Text/Plain; charset=us-ascii

> > although i prefer M_EXT_READONLY because the most of mbufs are R/W,
> > M_EXT_RW is also ok for me.
> 
> I suggested the "explicitly mark it RW" because the "implicit RO" 
> behavior has been around for a fairly long time, and there is external 
> code that depends on it, almost certainly.

here's a patch.

as an exception, i made MEXTMALLOC "implicit R/W".
is it ok for you?

YAMAMOTO Takashi

--NextPart-20040921200516-0035900
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="a.diff"

Index: dev/pci/if_ti.c
===================================================================
--- dev/pci/if_ti.c	(revision 887)
+++ dev/pci/if_ti.c	(revision 888)
@@ -906,6 +906,7 @@ static int ti_newbuf_jumbo(sc, i, m)
 		/* Attach the buffer to the mbuf. */
 		MEXTADD(m_new, (void *)buf, ETHER_MAX_LEN_JUMBO,
 		    M_DEVBUF, ti_jfree, sc);
+		m_new->m_flags |= M_EXT_RW;
 		m_new->m_len = m_new->m_pkthdr.len = ETHER_MAX_LEN_JUMBO;
 	} else {
 		m_new = m;
Index: dev/pci/if_dge.c
===================================================================
--- dev/pci/if_dge.c	(revision 887)
+++ dev/pci/if_dge.c	(revision 888)
@@ -2129,6 +2129,7 @@ dge_add_rxbuf(struct dge_softc *sc, int 
 
 	m->m_len = m->m_pkthdr.len = DGE_BUFFER_SIZE;
 	MEXTADD(m, buf, DGE_BUFFER_SIZE, M_DEVBUF, dge_freebuf, sc);
+	m->m_flags |= M_EXT_RW;
 
 	if (rxs->rxs_mbuf != NULL)
 		bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap);
Index: dev/pci/if_bge.c
===================================================================
--- dev/pci/if_bge.c	(revision 887)
+++ dev/pci/if_bge.c	(revision 888)
@@ -955,6 +955,7 @@ bge_newbuf_jumbo(sc, i, m)
 		m_new->m_len = m_new->m_pkthdr.len = BGE_JUMBO_FRAMELEN;
 		MEXTADD(m_new, buf, BGE_JUMBO_FRAMELEN, M_DEVBUF,
 		    bge_jfree, sc);
+		m_new->m_flags |= M_EXT_RW;
 	} else {
 		m_new = m;
 		m_new->m_data = m_new->m_ext.ext_buf;
Index: sys/mbuf.h
===================================================================
--- sys/mbuf.h	(revision 887)
+++ sys/mbuf.h	(revision 888)
@@ -292,6 +292,7 @@ MBUF_DEFINE(mbuf, MHLEN, MLEN);
 #define	M_EXT_CLUSTER	0x01000000	/* ext is a cluster */
 #define	M_EXT_PAGES	0x02000000	/* ext_pgs is valid */
 #define	M_EXT_ROMAP	0x04000000	/* ext mapping is r-o at MMU */
+#define	M_EXT_RW	0x08000000	/* ext storage is writable */
 
 /* for source-level compatibility */
 #define	M_CLUSTER	M_EXT_CLUSTER
@@ -519,7 +520,7 @@ do {									\
 	if ((m)->m_ext.ext_buf != NULL) {				\
 		(m)->m_data = (m)->m_ext.ext_buf;			\
 		(m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |	\
-				M_EXT|M_CLUSTER;			\
+				M_EXT|M_CLUSTER|M_EXT_RW;		\
 		(m)->m_ext.ext_size = (size);				\
 		(m)->m_ext.ext_free = NULL;				\
 		(m)->m_ext.ext_arg = (pool_cache);			\
@@ -539,7 +540,8 @@ do {									\
 	    (caddr_t)malloc((size), mbtypes[(m)->m_type], (how));	\
 	if ((m)->m_ext.ext_buf != NULL) {				\
 		(m)->m_data = (m)->m_ext.ext_buf;			\
-		(m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) | M_EXT;\
+		(m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |	\
+				M_EXT|M_EXT_RW;				\
 		(m)->m_ext.ext_size = (size);				\
 		(m)->m_ext.ext_free = NULL;				\
 		(m)->m_ext.ext_arg = NULL;				\
@@ -636,12 +638,13 @@ do {									\
 
 /*
  * Determine if an mbuf's data area is read-only.  This is true
- * for non-cluster external storage and for clusters that are
- * being referenced by more than one mbuf.
+ * if external storage is read-only mapped, or not marked as R/W,
+ * or referenced by more than one mbuf.
  */
 #define	M_READONLY(m)							\
 	(((m)->m_flags & M_EXT) != 0 &&					\
-	  (((m)->m_flags & M_CLUSTER) == 0 || MCLISREFERENCED(m)))
+	  (((m)->m_flags & (M_EXT_ROMAP|M_EXT_RW)) != M_EXT_RW ||	\
+	  MCLISREFERENCED(m)))
 
 /*
  * Determine if an mbuf's data area is read-only at the MMU.

--NextPart-20040921200516-0035900--