Skip to content

Commit 9964cb1

Browse files
committed
issue: 1792164 Fix issue in tx zcopy operation
zcopy operation should allocate memory buffer to track unique counter correctly. So tcp_write() should avoid adding portion of data to existing pbuf. Signed-off-by: Igor Ivanov <[email protected]>
1 parent f4bd390 commit 9964cb1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/vma/lwip/tcp_out.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
465465
#endif /* LWIP_TSO */
466466

467467
optflags |= (apiflags & TCP_WRITE_DUMMY ? TF_SEG_OPTS_DUMMY_MSG : 0);
468+
optflags |= (apiflags & TCP_WRITE_ZEROCOPY ? TF_SEG_OPTS_ZEROCOPY : 0);
468469

469470
#if LWIP_TCP_TIMESTAMPS
470471
if ((pcb->flags & TF_TIMESTAMP)) {
@@ -535,7 +536,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
535536
#endif /* TCP_OVERSIZE_DBGCHECK */
536537

537538
if (pcb->unsent_oversize > 0) {
538-
if (!(apiflags & TCP_WRITE_FILE)) {
539+
if (!(apiflags & (TCP_WRITE_FILE | TCP_WRITE_ZEROCOPY))) {
539540
oversize = pcb->unsent_oversize;
540541
LWIP_ASSERT("inconsistent oversize vs. space", oversize_used <= space);
541542
oversize_used = oversize < len ? oversize : len;
@@ -556,10 +557,10 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u32_t len, u8_t apiflags)
556557
* the end.
557558
*/
558559
#if LWIP_TSO
559-
if (!(apiflags & TCP_WRITE_FILE) && (pos < len) && (space > 0) && (pcb->last_unsent->len > 0) &&
560+
if (!(apiflags & (TCP_WRITE_FILE | TCP_WRITE_ZEROCOPY)) && (pos < len) && (space > 0) && (pcb->last_unsent->len > 0) &&
560561
(tot_p < (int)pcb->tso.max_send_sge)) {
561562
#else
562-
if (!(apiflags & TCP_WRITE_FILE) && (pos < len) && (space > 0) && (pcb->last_unsent->len > 0)) {
563+
if (!(apiflags & (TCP_WRITE_FILE | TCP_WRITE_ZEROCOPY)) && (pos < len) && (space > 0) && (pcb->last_unsent->len > 0)) {
563564
#endif /* LWIP_TSO */
564565

565566
u16_t seglen = space < len - pos ? space : len - pos;

src/vma/sock/sockinfo_tcp.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,13 @@ ssize_t sockinfo_tcp::tx(vma_tx_call_attr_t &tx_arg)
956956
* data increments the counter.
957957
* The counter is not incremented on failure or if called with length zero.
958958
*/
959-
if ((apiflags & VMA_TX_PACKET_ZEROCOPY) && (total_tx > 0)) {
960-
atomic_fetch_and_inc(&m_zckey);
959+
if ((apiflags & VMA_TX_PACKET_ZEROCOPY) &&
960+
(total_tx > 0)) {
961+
if (m_last_zcdesc->tx.zc.id != (uint32_t)atomic_read(&m_zckey)) {
962+
si_tcp_logerr("Invalid tx zcopy operation");
963+
} else {
964+
atomic_fetch_and_inc(&m_zckey);
965+
}
961966
}
962967

963968
unlock_tcp_con();

0 commit comments

Comments
 (0)