Give MEXTADD() another argument to make both void pointers to the
free function controlable, instead of passing the KVA of the buffer storage as the first argument. Fix all conventional users of the API to pass the KVA of the buffer as the first argument, to make this a no-op commit. Likely break the only non-convetional user of the API, after informing the relevant committer. Update the mbuf(9) manual page, which was already out of sync on this point. Bump __FreeBSD_version to 800016 as there is no way to tell how many arguments a CPP macro needs any other way. This paves the way for giving sendfile(9) a way to wait for the passed storage to have been accessed before returning. This does not affect the memory layout or size of mbufs. Parental oversight by: sam and rwatson. No MFC is anticipated.
This commit is contained in:
parent
942fe01f61
commit
cf827063a9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=175872
@ -45,8 +45,9 @@
|
||||
.Fa "struct mbuf *mbuf"
|
||||
.Fa "caddr_t buf"
|
||||
.Fa "u_int size"
|
||||
.Fa "void (*free)(void *opt_args)"
|
||||
.Fa "void *opt_args"
|
||||
.Fa "void (*free)(void *opt_arg1, void *opt_arg2)"
|
||||
.Fa "void *opt_arg1"
|
||||
.Fa "void *opt_arg2"
|
||||
.Fa "short flags"
|
||||
.Fa "int type"
|
||||
.Fc
|
||||
|
@ -734,7 +734,7 @@ ndis_ptom(m0, p)
|
||||
m->m_len = MmGetMdlByteCount(buf);
|
||||
m->m_data = MmGetMdlVirtualAddress(buf);
|
||||
MEXTADD(m, m->m_data, m->m_len, ndis_return_packet,
|
||||
p, 0, EXT_NDIS);
|
||||
m->m_data, p, 0, EXT_NDIS);
|
||||
p->np_refcnt++;
|
||||
|
||||
totlen += m->m_len;
|
||||
|
@ -2452,7 +2452,8 @@ init_cluster_mbuf(caddr_t cl, int flags, int type, uma_zone_t zone)
|
||||
m->m_ext.ref_cnt = (uint32_t *)(cl + header_size - sizeof(uint32_t));
|
||||
m->m_ext.ext_size = m_getsizefromtype(type);
|
||||
m->m_ext.ext_free = ext_free_handler;
|
||||
m->m_ext.ext_args = (void *)(uintptr_t)type;
|
||||
m->m_ext.ext_arg1 = cl;
|
||||
m->m_ext.ext_arg2 = (void *)(uintptr_t)type;
|
||||
m->m_ext.ext_type = EXT_EXTREF;
|
||||
*(m->m_ext.ref_cnt) = 1;
|
||||
DPRINTF("data=%p ref_cnt=%p\n", m->m_data, m->m_ext.ref_cnt);
|
||||
|
@ -224,7 +224,8 @@ cxgb_vm_page_to_miov(struct toepcb *toep, struct uio *uio, struct mbuf **m)
|
||||
m0->m_flags = (M_EXT|M_NOFREE);
|
||||
m0->m_ext.ext_type = EXT_EXTREF;
|
||||
m0->m_ext.ext_free = cxgb_zero_copy_free;
|
||||
m0->m_ext.ext_args = NULL;
|
||||
m0->m_ext.ext_arg1 = NULL; /* XXX: probably wrong /phk */
|
||||
m0->m_ext.ext_arg2 = NULL;
|
||||
|
||||
mv = mtomv(m0);
|
||||
mv->mv_count = seg_count;
|
||||
|
@ -458,7 +458,7 @@ hatm_rx_buffer(struct hatm_softc *sc, u_int group, u_int handle)
|
||||
if (m != NULL) {
|
||||
m->m_ext.ref_cnt = &c0->hdr.ref_cnt;
|
||||
MEXTADD(m, (void *)c0, MBUF0_SIZE,
|
||||
hatm_mbuf0_free, sc, M_PKTHDR, EXT_EXTREF);
|
||||
hatm_mbuf0_free, c0, sc, M_PKTHDR, EXT_EXTREF);
|
||||
m->m_data += MBUF0_OFFSET;
|
||||
} else
|
||||
hatm_mbuf0_free(c0, sc);
|
||||
@ -482,7 +482,7 @@ hatm_rx_buffer(struct hatm_softc *sc, u_int group, u_int handle)
|
||||
if (m != NULL) {
|
||||
m->m_ext.ref_cnt = &c1->hdr.ref_cnt;
|
||||
MEXTADD(m, (void *)c1, MBUF1_SIZE,
|
||||
hatm_mbuf1_free, sc, M_PKTHDR, EXT_EXTREF);
|
||||
hatm_mbuf1_free, c1, sc, M_PKTHDR, EXT_EXTREF);
|
||||
m->m_data += MBUF1_OFFSET;
|
||||
} else
|
||||
hatm_mbuf1_free(c1, sc);
|
||||
|
@ -164,7 +164,7 @@ isc_sendPDU(isc_session_t *sp, pduq_t *pq)
|
||||
md->m_ext.ref_cnt = &nil_refcnt;
|
||||
l = min(MCLBYTES, len);
|
||||
MEXTADD(md, pp->ds + off, l, nil_fn,
|
||||
NULL, 0, EXT_EXTREF);
|
||||
pp->ds + off, NULL, 0, EXT_EXTREF);
|
||||
md->m_len = l;
|
||||
md->m_next = NULL;
|
||||
mh->m_pkthdr.len += l;
|
||||
|
@ -719,7 +719,7 @@ lge_newbuf(sc, c, m)
|
||||
m_new->m_data = (void *)buf;
|
||||
m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN;
|
||||
MEXTADD(m_new, buf, LGE_JUMBO_FRAMELEN, lge_jfree,
|
||||
(struct lge_softc *)sc, 0, EXT_NET_DRV);
|
||||
buf, (struct lge_softc *)sc, 0, EXT_NET_DRV);
|
||||
} else {
|
||||
m_new = m;
|
||||
m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN;
|
||||
|
@ -833,8 +833,8 @@ msk_jumbo_newbuf(struct msk_if_softc *sc_if, int idx)
|
||||
return (ENOBUFS);
|
||||
}
|
||||
/* Attach the buffer to the mbuf. */
|
||||
MEXTADD(m, buf, MSK_JLEN, msk_jfree, (struct msk_if_softc *)sc_if, 0,
|
||||
EXT_NET_DRV);
|
||||
MEXTADD(m, buf, MSK_JLEN, msk_jfree, buf,
|
||||
(struct msk_if_softc *)sc_if, 0, EXT_NET_DRV);
|
||||
if ((m->m_flags & M_EXT) == 0) {
|
||||
m_freem(m);
|
||||
return (ENOBUFS);
|
||||
|
@ -2094,7 +2094,7 @@ nfe_jnewbuf(struct nfe_softc *sc, int idx)
|
||||
return (ENOBUFS);
|
||||
}
|
||||
/* Attach the buffer to the mbuf. */
|
||||
MEXTADD(m, buf, NFE_JLEN, nfe_jfree, (struct nfe_softc *)sc, 0,
|
||||
MEXTADD(m, buf, NFE_JLEN, nfe_jfree, buf, (struct nfe_softc *)sc, 0,
|
||||
EXT_NET_DRV);
|
||||
if ((m->m_flags & M_EXT) == 0) {
|
||||
m_freem(m);
|
||||
|
@ -406,11 +406,11 @@ patm_rcv_mbuf(struct patm_softc *sc, void *buf, u_int h, int hdr)
|
||||
|
||||
if ((h & ~MBUF_HMASK) == MBUF_VHANDLE) {
|
||||
MEXTADD(m, (caddr_t)buf, VMBUF_SIZE, mbp_ext_free,
|
||||
sc->vbuf_pool, M_PKTHDR, EXT_NET_DRV);
|
||||
buf, sc->vbuf_pool, M_PKTHDR, EXT_NET_DRV);
|
||||
m->m_data += VMBUF_OFFSET;
|
||||
} else {
|
||||
MEXTADD(m, (caddr_t)buf, SMBUF_SIZE, mbp_ext_free,
|
||||
sc->sbuf_pool, M_PKTHDR, EXT_NET_DRV);
|
||||
buf, sc->sbuf_pool, M_PKTHDR, EXT_NET_DRV);
|
||||
m->m_data += SMBUF_OFFSET;
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1055,7 @@ sk_jumbo_newbuf(sc_if, idx)
|
||||
return (ENOBUFS);
|
||||
}
|
||||
/* Attach the buffer to the mbuf */
|
||||
MEXTADD(m, buf, SK_JLEN, sk_jfree, (struct sk_if_softc *)sc_if, 0,
|
||||
MEXTADD(m, buf, SK_JLEN, sk_jfree, (struct sk_if_softc *)sc_if, buf, 0,
|
||||
EXT_NET_DRV);
|
||||
if ((m->m_flags & M_EXT) == 0) {
|
||||
m_freem(m);
|
||||
|
@ -1503,7 +1503,8 @@ ti_newbuf_jumbo(sc, idx, m_old)
|
||||
m[i]->m_data = (void *)sf_buf_kva(sf[i]);
|
||||
m[i]->m_len = PAGE_SIZE;
|
||||
MEXTADD(m[i], sf_buf_kva(sf[i]), PAGE_SIZE,
|
||||
sf_buf_mext, sf[i], 0, EXT_DISPOSABLE);
|
||||
sf_buf_mext, (void*)sf_buf_kva(sf[i]), sf[i],
|
||||
0, EXT_DISPOSABLE);
|
||||
m[i]->m_next = m[i+1];
|
||||
}
|
||||
/* link the buffers to the header */
|
||||
|
@ -1060,7 +1060,7 @@ wpi_alloc_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring)
|
||||
|
||||
/* attach RxBuffer to mbuf */
|
||||
MEXTADD(data->m, rbuf->vaddr, WPI_RBUF_SIZE,wpi_free_rbuf,
|
||||
rbuf,0,EXT_NET_DRV);
|
||||
rbuf->vaddr, rbuf, 0, EXT_NET_DRV);
|
||||
|
||||
if ((data->m->m_flags & M_EXT) == 0) {
|
||||
m_freem(data->m);
|
||||
@ -1631,8 +1631,8 @@ wpi_rx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc,
|
||||
}
|
||||
|
||||
/* attach Rx buffer to mbuf */
|
||||
MEXTADD(mnew,rbuf->vaddr,WPI_RBUF_SIZE, wpi_free_rbuf, rbuf, 0,
|
||||
EXT_NET_DRV);
|
||||
MEXTADD(mnew, rbuf->vaddr, WPI_RBUF_SIZE, wpi_free_rbuf,
|
||||
rbuf->vaddr, rbuf, 0, EXT_NET_DRV);
|
||||
SLIST_REMOVE_HEAD(&sc->rxq.freelist, next);
|
||||
data->m = mnew;
|
||||
|
||||
|
@ -463,7 +463,8 @@ mb_dtor_pack(void *mem, int size, void *arg)
|
||||
KASSERT((m->m_flags & M_EXT) == M_EXT, ("%s: M_EXT not set", __func__));
|
||||
KASSERT(m->m_ext.ext_buf != NULL, ("%s: ext_buf == NULL", __func__));
|
||||
KASSERT(m->m_ext.ext_free == NULL, ("%s: ext_free != NULL", __func__));
|
||||
KASSERT(m->m_ext.ext_args == NULL, ("%s: ext_args != NULL", __func__));
|
||||
KASSERT(m->m_ext.ext_arg1 == NULL, ("%s: ext_arg1 != NULL", __func__));
|
||||
KASSERT(m->m_ext.ext_arg2 == NULL, ("%s: ext_arg2 != NULL", __func__));
|
||||
KASSERT(m->m_ext.ext_size == MCLBYTES, ("%s: ext_size != MCLBYTES", __func__));
|
||||
KASSERT(m->m_ext.ext_type == EXT_PACKET, ("%s: ext_type != EXT_PACKET", __func__));
|
||||
KASSERT(*m->m_ext.ref_cnt == 1, ("%s: ref_cnt != 1", __func__));
|
||||
@ -533,7 +534,8 @@ mb_ctor_clust(void *mem, int size, void *arg, int how)
|
||||
m->m_data = m->m_ext.ext_buf;
|
||||
m->m_flags |= M_EXT;
|
||||
m->m_ext.ext_free = NULL;
|
||||
m->m_ext.ext_args = NULL;
|
||||
m->m_ext.ext_arg1 = NULL;
|
||||
m->m_ext.ext_arg2 = NULL;
|
||||
m->m_ext.ext_size = size;
|
||||
m->m_ext.ext_type = type;
|
||||
m->m_ext.ref_cnt = refcnt;
|
||||
|
@ -160,8 +160,8 @@ socow_setup(struct mbuf *m0, struct uio *uio)
|
||||
/*
|
||||
* attach to mbuf
|
||||
*/
|
||||
MEXTADD(m0, sf_buf_kva(sf), PAGE_SIZE, socow_iodone, sf, M_RDONLY,
|
||||
EXT_SFBUF);
|
||||
MEXTADD(m0, sf_buf_kva(sf), PAGE_SIZE, socow_iodone,
|
||||
(void*)sf_buf_kva(sf), sf, M_RDONLY, EXT_SFBUF);
|
||||
m0->m_len = PAGE_SIZE - offset;
|
||||
m0->m_data = (caddr_t)sf_buf_kva(sf) + offset;
|
||||
socow_stats.success++;
|
||||
|
@ -186,7 +186,7 @@ m_freem(struct mbuf *mb)
|
||||
*/
|
||||
void
|
||||
m_extadd(struct mbuf *mb, caddr_t buf, u_int size,
|
||||
void (*freef)(void *, void *), void *args, int flags, int type)
|
||||
void (*freef)(void *, void *), void *arg1, void *arg2, int flags, int type)
|
||||
{
|
||||
KASSERT(type != EXT_CLUSTER, ("%s: EXT_CLUSTER not allowed", __func__));
|
||||
|
||||
@ -199,7 +199,8 @@ m_extadd(struct mbuf *mb, caddr_t buf, u_int size,
|
||||
mb->m_data = mb->m_ext.ext_buf;
|
||||
mb->m_ext.ext_size = size;
|
||||
mb->m_ext.ext_free = freef;
|
||||
mb->m_ext.ext_args = args;
|
||||
mb->m_ext.ext_arg1 = arg1;
|
||||
mb->m_ext.ext_arg2 = arg2;
|
||||
mb->m_ext.ext_type = type;
|
||||
}
|
||||
}
|
||||
@ -254,8 +255,8 @@ mb_free_ext(struct mbuf *m)
|
||||
case EXT_EXTREF:
|
||||
KASSERT(m->m_ext.ext_free != NULL,
|
||||
("%s: ext_free not set", __func__));
|
||||
(*(m->m_ext.ext_free))(m->m_ext.ext_buf,
|
||||
m->m_ext.ext_args);
|
||||
(*(m->m_ext.ext_free))(m->m_ext.ext_arg1,
|
||||
m->m_ext.ext_arg2);
|
||||
break;
|
||||
default:
|
||||
KASSERT(m->m_ext.ext_type == 0,
|
||||
@ -271,7 +272,8 @@ mb_free_ext(struct mbuf *m)
|
||||
*/
|
||||
m->m_ext.ext_buf = NULL;
|
||||
m->m_ext.ext_free = NULL;
|
||||
m->m_ext.ext_args = NULL;
|
||||
m->m_ext.ext_arg1 = NULL;
|
||||
m->m_ext.ext_arg2 = NULL;
|
||||
m->m_ext.ref_cnt = NULL;
|
||||
m->m_ext.ext_size = 0;
|
||||
m->m_ext.ext_type = 0;
|
||||
@ -296,7 +298,8 @@ mb_dupcl(struct mbuf *n, struct mbuf *m)
|
||||
atomic_add_int(m->m_ext.ref_cnt, 1);
|
||||
n->m_ext.ext_buf = m->m_ext.ext_buf;
|
||||
n->m_ext.ext_free = m->m_ext.ext_free;
|
||||
n->m_ext.ext_args = m->m_ext.ext_args;
|
||||
n->m_ext.ext_arg1 = m->m_ext.ext_arg1;
|
||||
n->m_ext.ext_arg2 = m->m_ext.ext_arg2;
|
||||
n->m_ext.ext_size = m->m_ext.ext_size;
|
||||
n->m_ext.ref_cnt = m->m_ext.ref_cnt;
|
||||
n->m_ext.ext_type = m->m_ext.ext_type;
|
||||
|
@ -2099,7 +2099,7 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
|
||||
break;
|
||||
}
|
||||
MEXTADD(m0, sf_buf_kva(sf), PAGE_SIZE, sf_buf_mext,
|
||||
sf, M_RDONLY, EXT_SFBUF);
|
||||
(void*)sf_buf_kva(sf), sf, M_RDONLY, EXT_SFBUF);
|
||||
m0->m_data = (char *)sf_buf_kva(sf) + pgoff;
|
||||
m0->m_len = xfsize;
|
||||
|
||||
|
@ -1036,8 +1036,8 @@ wb_newbuf(sc, c, m)
|
||||
return(ENOBUFS);
|
||||
m_new->m_data = c->wb_buf;
|
||||
m_new->m_pkthdr.len = m_new->m_len = WB_BUFBYTES;
|
||||
MEXTADD(m_new, c->wb_buf, WB_BUFBYTES, wb_bfree, NULL, 0,
|
||||
EXT_NET_DRV);
|
||||
MEXTADD(m_new, c->wb_buf, WB_BUFBYTES, wb_bfree, c->wb_buf,
|
||||
NULL, 0, EXT_NET_DRV);
|
||||
} else {
|
||||
m_new = m;
|
||||
m_new->m_len = m_new->m_pkthdr.len = WB_BUFBYTES;
|
||||
|
@ -131,7 +131,8 @@ struct m_ext {
|
||||
caddr_t ext_buf; /* start of buffer */
|
||||
void (*ext_free) /* free routine if not the usual */
|
||||
(void *, void *);
|
||||
void *ext_args; /* optional argument pointer */
|
||||
void *ext_arg1; /* optional argument pointer */
|
||||
void *ext_arg2; /* optional argument pointer */
|
||||
u_int ext_size; /* size of buffer, for ext_free */
|
||||
volatile u_int *ref_cnt; /* pointer to ref count info */
|
||||
int ext_type; /* type of external storage */
|
||||
@ -586,7 +587,7 @@ m_cljset(struct mbuf *m, void *cl, int type)
|
||||
}
|
||||
|
||||
m->m_data = m->m_ext.ext_buf = cl;
|
||||
m->m_ext.ext_free = m->m_ext.ext_args = NULL;
|
||||
m->m_ext.ext_free = m->m_ext.ext_arg1 = m->m_ext.ext_arg2 = NULL;
|
||||
m->m_ext.ext_size = size;
|
||||
m->m_ext.ext_type = type;
|
||||
m->m_ext.ref_cnt = uma_find_refcnt(zone, cl);
|
||||
@ -618,8 +619,8 @@ m_last(struct mbuf *m)
|
||||
#define MGET(m, how, type) ((m) = m_get((how), (type)))
|
||||
#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
|
||||
#define MCLGET(m, how) m_clget((m), (how))
|
||||
#define MEXTADD(m, buf, size, free, args, flags, type) \
|
||||
m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type))
|
||||
#define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \
|
||||
m_extadd((m), (caddr_t)(buf), (size), (free),(arg1),(arg2),(flags), (type))
|
||||
#define m_getm(m, len, how, type) \
|
||||
m_getm2((m), (len), (how), (type), M_PKTHDR)
|
||||
|
||||
@ -745,7 +746,7 @@ int m_apply(struct mbuf *, int, int,
|
||||
int m_append(struct mbuf *, int, c_caddr_t);
|
||||
void m_cat(struct mbuf *, struct mbuf *);
|
||||
void m_extadd(struct mbuf *, caddr_t, u_int,
|
||||
void (*)(void *, void *), void *, int, int);
|
||||
void (*)(void *, void *), void *, void *, int, int);
|
||||
struct mbuf *m_collapse(struct mbuf *, int, int);
|
||||
void m_copyback(struct mbuf *, int, int, c_caddr_t);
|
||||
void m_copydata(const struct mbuf *, int, int, caddr_t);
|
||||
|
@ -57,7 +57,7 @@
|
||||
* is created, otherwise 1.
|
||||
*/
|
||||
#undef __FreeBSD_version
|
||||
#define __FreeBSD_version 800015 /* Master, propagated to newvers */
|
||||
#define __FreeBSD_version 800016 /* Master, propagated to newvers */
|
||||
|
||||
#ifndef LOCORE
|
||||
#include <sys/types.h>
|
||||
|
Loading…
Reference in New Issue
Block a user