Date: Sat, 2 May 2020 23:46:30 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360574 - in head: share/man/man9 sys/dev/cxgbe sys/dev/cxgbe/crypto sys/dev/cxgbe/tom sys/kern sys/sys Message-ID: <202005022346.042NkUYk078455@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Sat May 2 23:46:29 2020 New Revision: 360574 URL: https://svnweb.freebsd.org/changeset/base/360574 Log: Step 2.2: o Shrink sglist(9) functions to work with multipage mbufs down from four functions to two. o Don't use 'struct mbuf_ext_pgs *' as argument, use struct mbuf. o Rename to something matching _epg. Reviewed by: gallatin Differential Revision: https://reviews.freebsd.org/D24598 Modified: head/share/man/man9/sglist.9 head/sys/dev/cxgbe/crypto/t4_kern_tls.c head/sys/dev/cxgbe/t4_sge.c head/sys/dev/cxgbe/tom/t4_cpl_io.c head/sys/kern/subr_bus_dma.c head/sys/kern/subr_sglist.c head/sys/sys/sglist.h Modified: head/share/man/man9/sglist.9 ============================================================================== --- head/share/man/man9/sglist.9 Sat May 2 23:38:13 2020 (r360573) +++ head/share/man/man9/sglist.9 Sat May 2 23:46:29 2020 (r360574) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 28, 2019 +.Dd April 24, 2020 .Dt SGLIST 9 .Os .Sh NAME @@ -34,9 +34,8 @@ .Nm sglist_alloc , .Nm sglist_append , .Nm sglist_append_bio , -.Nm sglist_append_ext_pgs, -.Nm sglist_append_mb_ext_pgs, .Nm sglist_append_mbuf , +.Nm sglist_append_mbuf_epg, .Nm sglist_append_phys , .Nm sglist_append_sglist , .Nm sglist_append_uio , @@ -46,8 +45,7 @@ .Nm sglist_clone , .Nm sglist_consume_uio , .Nm sglist_count , -.Nm sglist_count_ext_pgs , -.Nm sglist_count_mb_ext_pgs , +.Nm sglist_count_mbuf_epg , .Nm sglist_count_vmpages , .Nm sglist_free , .Nm sglist_hold , @@ -68,10 +66,8 @@ .Ft int .Fn sglist_append_bio "struct sglist *sg" "struct bio *bp" .Ft int -.Fn sglist_append_ext_pgs "struct sglist *sg" "struct mbuf_ext_pgs *ext_pgs" "size_t offset" "size_t len" +.Fn sglist_append_mbuf_epg "struct sglist *sg" "struct mbuf *m" "size_t offset" "size_t len" .Ft int -.Fn sglist_append_mb_ext_pgs "struct sglist *sg" "struct mbuf *m" -.Ft int .Fn sglist_append_mbuf "struct sglist *sg" "struct mbuf *m" .Ft int .Fn sglist_append_phys "struct sglist *sg" "vm_paddr_t paddr" "size_t len" @@ -92,10 +88,8 @@ .Ft int .Fn sglist_count "void *buf" "size_t len" .Ft int -.Fn sglist_count_ext_pgs "struct mbuf_ext_pgs *ext_pgs" "size_t offset" "size_t len" +.Fn sglist_count_mbuf_epg "struct mbuf *m" "size_t offset" "size_t len" .Ft int -.Fn sglist_count_mb_ext_pgs "struct mbuf *m" -.Ft int .Fn sglist_count_vmpages "vm_page_t *m" "size_t pgoff" "size_t len" .Ft void .Fn sglist_free "struct sglist *sg" @@ -158,20 +152,15 @@ and is bytes long. .Pp The -.Nm sglist_count_ext_pgs +.Nm sglist_count_mbuf_epg function returns the number of scatter/gather list elements needed to describe -the unmapped external mbuf buffer -.Fa ext_pgs . +the external multipage mbuf buffer +.Fa m . The ranges start at an offset of .Fa offset relative to the start of the buffer and is .Fa len bytes long. -The -.Nm sglist_count_mb_ext_pgs -function returns the number of scatter/gather list elements needed to describe -the physical address ranges of a single unmapped mbuf -.Fa m . .Pp The .Nm sglist_count_vmpages @@ -265,9 +254,11 @@ to the scatter/gather list .Fa sg . .Pp The -.Nm sglist_append_ext_pgs -function appends the physical address ranges described by the unmapped -external mbuf buffer +.Nm sglist_append_mbuf_epg +function appends the physical address ranges described by the +external multipage +.Xr mbuf 9 +buffer .Fa ext_pgs to the scatter/gather list .Fa sg . @@ -278,17 +269,9 @@ within and continue for .Fa len bytes. -.Pp -The -.Nm sglist_append_mb_ext_pgs -function appends the physical address ranges described by the unmapped -mbuf -.Fa m -to the scatter/gather list -.Fa sg . Note that unlike .Nm sglist_append_mbuf , -.Nm sglist_append_mb_ext_pgs +.Nm sglist_append_mbuf_epg only adds ranges for a single mbuf, not an entire mbuf chain. .Pp Modified: head/sys/dev/cxgbe/crypto/t4_kern_tls.c ============================================================================== --- head/sys/dev/cxgbe/crypto/t4_kern_tls.c Sat May 2 23:38:13 2020 (r360573) +++ head/sys/dev/cxgbe/crypto/t4_kern_tls.c Sat May 2 23:46:29 2020 (r360574) @@ -1064,7 +1064,7 @@ ktls_wr_len(struct tlspcb *tlsp, struct mbuf *m, struc wr_len += roundup2(imm_len, 16); /* TLS record payload via DSGL. */ - *nsegsp = sglist_count_ext_pgs(m_tls, ext_pgs->hdr_len + offset, + *nsegsp = sglist_count_mbuf_epg(m_tls, ext_pgs->hdr_len + offset, plen - (ext_pgs->hdr_len + offset)); wr_len += ktls_sgl_size(*nsegsp); @@ -1799,7 +1799,7 @@ ktls_write_tls_wr(struct tlspcb *tlsp, struct sge_txq /* Recalculate 'nsegs' if cached value is not available. */ if (nsegs == 0) - nsegs = sglist_count_ext_pgs(m_tls, ext_pgs->hdr_len + + nsegs = sglist_count_mbuf_epg(m_tls, ext_pgs->hdr_len + offset, plen - (ext_pgs->hdr_len + offset)); /* Calculate the size of the TLS work request. */ @@ -2067,7 +2067,7 @@ ktls_write_tls_wr(struct tlspcb *tlsp, struct sge_txq /* SGL for record payload */ sglist_reset(txq->gl); - if (sglist_append_ext_pgs(txq->gl, m_tls, ext_pgs->hdr_len + offset, + if (sglist_append_mbuf_epg(txq->gl, m_tls, ext_pgs->hdr_len + offset, plen - (ext_pgs->hdr_len + offset)) != 0) { #ifdef INVARIANTS panic("%s: failed to append sglist", __func__); Modified: head/sys/dev/cxgbe/t4_sge.c ============================================================================== --- head/sys/dev/cxgbe/t4_sge.c Sat May 2 23:38:13 2020 (r360573) +++ head/sys/dev/cxgbe/t4_sge.c Sat May 2 23:46:29 2020 (r360574) @@ -2413,23 +2413,21 @@ m_advance(struct mbuf **pm, int *poffset, int len) static inline int count_mbuf_ext_pgs(struct mbuf *m, int skip, vm_paddr_t *nextaddr) { - struct mbuf_ext_pgs *ext_pgs; vm_paddr_t paddr; int i, len, off, pglen, pgoff, seglen, segoff; int nsegs = 0; MBUF_EXT_PGS_ASSERT(m); - ext_pgs = &m->m_ext_pgs; off = mtod(m, vm_offset_t); len = m->m_len; off += skip; len -= skip; - if (ext_pgs->hdr_len != 0) { - if (off >= ext_pgs->hdr_len) { - off -= ext_pgs->hdr_len; + if (m->m_ext_pgs.hdr_len != 0) { + if (off >= m->m_ext_pgs.hdr_len) { + off -= m->m_ext_pgs.hdr_len; } else { - seglen = ext_pgs->hdr_len - off; + seglen = m->m_ext_pgs.hdr_len - off; segoff = off; seglen = min(seglen, len); off = 0; @@ -2441,9 +2439,9 @@ count_mbuf_ext_pgs(struct mbuf *m, int skip, vm_paddr_ *nextaddr = paddr + seglen; } } - pgoff = ext_pgs->first_pg_off; - for (i = 0; i < ext_pgs->npgs && len > 0; i++) { - pglen = mbuf_ext_pg_len(ext_pgs, i, pgoff); + pgoff = m->m_ext_pgs.first_pg_off; + for (i = 0; i < m->m_ext_pgs.npgs && len > 0; i++) { + pglen = mbuf_ext_pg_len(&m->m_ext_pgs, i, pgoff); if (off >= pglen) { off -= pglen; pgoff = 0; @@ -2461,7 +2459,7 @@ count_mbuf_ext_pgs(struct mbuf *m, int skip, vm_paddr_ pgoff = 0; }; if (len != 0) { - seglen = min(len, ext_pgs->trail_len - off); + seglen = min(len, m->m_ext_pgs.trail_len - off); len -= seglen; paddr = pmap_kextract((vm_offset_t)&m->m_epg_trail[off]); if (*nextaddr != paddr) @@ -5838,9 +5836,12 @@ write_ethofld_wr(struct cxgbe_rate_tag *cst, struct fw immhdrs -= m0->m_len; continue; } - - sglist_append(&sg, mtod(m0, char *) + immhdrs, - m0->m_len - immhdrs); + if (m0->m_flags & M_NOMAP) + sglist_append_mbuf_epg(&sg, m0, + mtod(m0, vm_offset_t), m0->m_len); + else + sglist_append(&sg, mtod(m0, char *) + immhdrs, + m0->m_len - immhdrs); immhdrs = 0; } MPASS(sg.sg_nseg == nsegs); Modified: head/sys/dev/cxgbe/tom/t4_cpl_io.c ============================================================================== --- head/sys/dev/cxgbe/tom/t4_cpl_io.c Sat May 2 23:38:13 2020 (r360573) +++ head/sys/dev/cxgbe/tom/t4_cpl_io.c Sat May 2 23:46:29 2020 (r360574) @@ -611,7 +611,8 @@ write_tx_sgl(void *dst, struct mbuf *start, struct mbu i = -1; for (m = start; m != stop; m = m->m_next) { if (m->m_flags & M_NOMAP) - rc = sglist_append_mb_ext_pgs(&sg, m); + rc = sglist_append_mbuf_epg(&sg, m, + mtod(m, vm_offset_t), m->m_len); else rc = sglist_append(&sg, mtod(m, void *), m->m_len); if (__predict_false(rc != 0)) @@ -742,7 +743,8 @@ t4_push_frames(struct adapter *sc, struct toepcb *toep break; } #endif - n = sglist_count_mb_ext_pgs(m); + n = sglist_count_mbuf_epg(m, + mtod(m, vm_offset_t), m->m_len); } else n = sglist_count(mtod(m, void *), m->m_len); Modified: head/sys/kern/subr_bus_dma.c ============================================================================== --- head/sys/kern/subr_bus_dma.c Sat May 2 23:38:13 2020 (r360573) +++ head/sys/kern/subr_bus_dma.c Sat May 2 23:46:29 2020 (r360574) @@ -116,14 +116,12 @@ _bus_dmamap_load_plist(bus_dma_tag_t dmat, bus_dmamap_ * Load an unmapped mbuf */ static int -_bus_dmamap_load_unmapped_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, +_bus_dmamap_load_mbuf_epg(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf *m, bus_dma_segment_t *segs, int *nsegs, int flags) { - struct mbuf_ext_pgs *ext_pgs; int error, i, off, len, pglen, pgoff, seglen, segoff; MBUF_EXT_PGS_ASSERT(m); - ext_pgs = &m->m_ext_pgs; len = m->m_len; error = 0; @@ -131,11 +129,11 @@ _bus_dmamap_load_unmapped_mbuf_sg(bus_dma_tag_t dmat, /* Skip over any data removed from the front. */ off = mtod(m, vm_offset_t); - if (ext_pgs->hdr_len != 0) { - if (off >= ext_pgs->hdr_len) { - off -= ext_pgs->hdr_len; + if (m->m_ext_pgs.hdr_len != 0) { + if (off >= m->m_ext_pgs.hdr_len) { + off -= m->m_ext_pgs.hdr_len; } else { - seglen = ext_pgs->hdr_len - off; + seglen = m->m_ext_pgs.hdr_len - off; segoff = off; seglen = min(seglen, len); off = 0; @@ -145,9 +143,9 @@ _bus_dmamap_load_unmapped_mbuf_sg(bus_dma_tag_t dmat, flags, segs, nsegs); } } - pgoff = ext_pgs->first_pg_off; - for (i = 0; i < ext_pgs->npgs && error == 0 && len > 0; i++) { - pglen = mbuf_ext_pg_len(ext_pgs, i, pgoff); + pgoff = m->m_ext_pgs.first_pg_off; + for (i = 0; i < m->m_ext_pgs.npgs && error == 0 && len > 0; i++) { + pglen = mbuf_ext_pg_len(&m->m_ext_pgs, i, pgoff); if (off >= pglen) { off -= pglen; pgoff = 0; @@ -163,9 +161,9 @@ _bus_dmamap_load_unmapped_mbuf_sg(bus_dma_tag_t dmat, pgoff = 0; }; if (len != 0 && error == 0) { - KASSERT((off + len) <= ext_pgs->trail_len, + KASSERT((off + len) <= m->m_ext_pgs.trail_len, ("off + len > trail (%d + %d > %d)", off, len, - ext_pgs->trail_len)); + m->m_ext_pgs.trail_len)); error = _bus_dmamap_load_buffer(dmat, map, &m->m_epg_trail[off], len, kernel_pmap, flags, segs, nsegs); @@ -187,7 +185,7 @@ _bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmama for (m = m0; m != NULL && error == 0; m = m->m_next) { if (m->m_len > 0) { if ((m->m_flags & M_NOMAP) != 0) - error = _bus_dmamap_load_unmapped_mbuf_sg(dmat, + error = _bus_dmamap_load_mbuf_epg(dmat, map, m, segs, nsegs, flags); else error = _bus_dmamap_load_buffer(dmat, map, Modified: head/sys/kern/subr_sglist.c ============================================================================== --- head/sys/kern/subr_sglist.c Sat May 2 23:38:13 2020 (r360573) +++ head/sys/kern/subr_sglist.c Sat May 2 23:46:29 2020 (r360574) @@ -223,9 +223,8 @@ sglist_count_vmpages(vm_page_t *m, size_t pgoff, size_ * describe an EXT_PGS buffer. */ int -sglist_count_ext_pgs(struct mbuf *m, size_t off, size_t len) +sglist_count_mbuf_epg(struct mbuf *m, size_t off, size_t len) { - struct mbuf_ext_pgs *ext_pgs = &m->m_ext_pgs; vm_paddr_t nextaddr, paddr; size_t seglen, segoff; int i, nsegs, pglen, pgoff; @@ -234,11 +233,11 @@ sglist_count_ext_pgs(struct mbuf *m, size_t off, size_ return (0); nsegs = 0; - if (ext_pgs->hdr_len != 0) { - if (off >= ext_pgs->hdr_len) { - off -= ext_pgs->hdr_len; + if (m->m_ext_pgs.hdr_len != 0) { + if (off >= m->m_ext_pgs.hdr_len) { + off -= m->m_ext_pgs.hdr_len; } else { - seglen = ext_pgs->hdr_len - off; + seglen = m->m_ext_pgs.hdr_len - off; segoff = off; seglen = MIN(seglen, len); off = 0; @@ -248,9 +247,9 @@ sglist_count_ext_pgs(struct mbuf *m, size_t off, size_ } } nextaddr = 0; - pgoff = ext_pgs->first_pg_off; - for (i = 0; i < ext_pgs->npgs && len > 0; i++) { - pglen = mbuf_ext_pg_len(ext_pgs, i, pgoff); + pgoff = m->m_ext_pgs.first_pg_off; + for (i = 0; i < m->m_ext_pgs.npgs && len > 0; i++) { + pglen = mbuf_ext_pg_len(&m->m_ext_pgs, i, pgoff); if (off >= pglen) { off -= pglen; pgoff = 0; @@ -268,7 +267,7 @@ sglist_count_ext_pgs(struct mbuf *m, size_t off, size_ pgoff = 0; }; if (len != 0) { - seglen = MIN(len, ext_pgs->trail_len - off); + seglen = MIN(len, m->m_ext_pgs.trail_len - off); len -= seglen; nsegs += sglist_count(&m->m_epg_trail[off], seglen); } @@ -277,18 +276,6 @@ sglist_count_ext_pgs(struct mbuf *m, size_t off, size_ } /* - * Determine the number of scatter/gather list elements needed to - * describe an EXT_PGS mbuf. - */ -int -sglist_count_mb_ext_pgs(struct mbuf *m) -{ - - MBUF_EXT_PGS_ASSERT(m); - return (sglist_count_ext_pgs(m, mtod(m, vm_offset_t), m->m_len)); -} - -/* * Allocate a scatter/gather list along with 'nsegs' segments. The * 'mflags' parameters are the same as passed to malloc(9). The caller * should use sglist_free() to free this list. @@ -390,24 +377,25 @@ sglist_append_phys(struct sglist *sg, vm_paddr_t paddr } /* - * Append the segments to describe an EXT_PGS buffer to a - * scatter/gather list. If there are insufficient segments, then this - * fails with EFBIG. + * Append the segments of single multi-page mbuf. + * If there are insufficient segments, then this fails with EFBIG. */ int -sglist_append_ext_pgs(struct sglist *sg, struct mbuf *m, size_t off, size_t len) +sglist_append_mbuf_epg(struct sglist *sg, struct mbuf *m, size_t off, + size_t len) { - struct mbuf_ext_pgs *ext_pgs = &m->m_ext_pgs; size_t seglen, segoff; vm_paddr_t paddr; int error, i, pglen, pgoff; + MBUF_EXT_PGS_ASSERT(m); + error = 0; - if (ext_pgs->hdr_len != 0) { - if (off >= ext_pgs->hdr_len) { - off -= ext_pgs->hdr_len; + if (m->m_ext_pgs.hdr_len != 0) { + if (off >= m->m_ext_pgs.hdr_len) { + off -= m->m_ext_pgs.hdr_len; } else { - seglen = ext_pgs->hdr_len - off; + seglen = m->m_ext_pgs.hdr_len - off; segoff = off; seglen = MIN(seglen, len); off = 0; @@ -416,9 +404,9 @@ sglist_append_ext_pgs(struct sglist *sg, struct mbuf * &m->m_epg_hdr[segoff], seglen); } } - pgoff = ext_pgs->first_pg_off; - for (i = 0; i < ext_pgs->npgs && error == 0 && len > 0; i++) { - pglen = mbuf_ext_pg_len(ext_pgs, i, pgoff); + pgoff = m->m_ext_pgs.first_pg_off; + for (i = 0; i < m->m_ext_pgs.npgs && error == 0 && len > 0; i++) { + pglen = mbuf_ext_pg_len(&m->m_ext_pgs, i, pgoff); if (off >= pglen) { off -= pglen; pgoff = 0; @@ -434,7 +422,7 @@ sglist_append_ext_pgs(struct sglist *sg, struct mbuf * pgoff = 0; }; if (error == 0 && len > 0) { - seglen = MIN(len, ext_pgs->trail_len - off); + seglen = MIN(len, m->m_ext_pgs.trail_len - off); len -= seglen; error = sglist_append(sg, &m->m_epg_trail[off], seglen); @@ -445,20 +433,6 @@ sglist_append_ext_pgs(struct sglist *sg, struct mbuf * } /* - * Append the segments to describe an EXT_PGS mbuf to a scatter/gather - * list. If there are insufficient segments, then this fails with - * EFBIG. - */ -int -sglist_append_mb_ext_pgs(struct sglist *sg, struct mbuf *m) -{ - - /* for now, all unmapped mbufs are assumed to be EXT_PGS */ - MBUF_EXT_PGS_ASSERT(m); - return (sglist_append_ext_pgs(sg, m, mtod(m, vm_offset_t), m->m_len)); -} - -/* * Append the segments that describe a single mbuf chain to a * scatter/gather list. If there are insufficient segments, then this * fails with EFBIG. @@ -478,7 +452,8 @@ sglist_append_mbuf(struct sglist *sg, struct mbuf *m0) for (m = m0; m != NULL; m = m->m_next) { if (m->m_len > 0) { if ((m->m_flags & M_NOMAP) != 0) - error = sglist_append_mb_ext_pgs(sg, m); + error = sglist_append_mbuf_epg(sg, m, + mtod(m, vm_offset_t), m->m_len); else error = sglist_append(sg, m->m_data, m->m_len); Modified: head/sys/sys/sglist.h ============================================================================== --- head/sys/sys/sglist.h Sat May 2 23:38:13 2020 (r360573) +++ head/sys/sys/sglist.h Sat May 2 23:46:29 2020 (r360574) @@ -87,10 +87,9 @@ sglist_hold(struct sglist *sg) struct sglist *sglist_alloc(int nsegs, int mflags); int sglist_append(struct sglist *sg, void *buf, size_t len); int sglist_append_bio(struct sglist *sg, struct bio *bp); -int sglist_append_ext_pgs(struct sglist *sg, struct mbuf *m, size_t off, - size_t len); -int sglist_append_mb_ext_pgs(struct sglist *sg, struct mbuf *m); int sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); +int sglist_append_mbuf_epg(struct sglist *sg, struct mbuf *m0, size_t off, + size_t len); int sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, size_t len); int sglist_append_sglist(struct sglist *sg, struct sglist *source, @@ -104,8 +103,7 @@ struct sglist *sglist_build(void *buf, size_t len, int struct sglist *sglist_clone(struct sglist *sg, int mflags); int sglist_consume_uio(struct sglist *sg, struct uio *uio, size_t resid); int sglist_count(void *buf, size_t len); -int sglist_count_ext_pgs(struct mbuf *m, size_t off, size_t len); -int sglist_count_mb_ext_pgs(struct mbuf *m); +int sglist_count_mbuf_epg(struct mbuf *m, size_t off, size_t len); int sglist_count_vmpages(vm_page_t *m, size_t pgoff, size_t len); void sglist_free(struct sglist *sg); int sglist_join(struct sglist *first, struct sglist *second);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005022346.042NkUYk078455>