From nobody Mon Feb 19 04:48:49 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TdVRj3xD4z59328; Mon, 19 Feb 2024 04:48:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TdVRj2Sd7z50j3; Mon, 19 Feb 2024 04:48:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708318129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qx28GCSWl9ZgY+CDBopJ2hmNR+vsv/+MjkzXOw2ZYQk=; b=v6l9mlrBkZ0it1DI057sTdwHri407C1eXy/SoWlHeoMOKutL8hrcbV3FZZH257bGn23k8p svfpuG+/7LPtNNdk92D+preATiHBfZBvhbQjM6nbcZwCXisgDoTnKcBp8Ba218c2W3w5bW W1Zthv15VqLuB9liCI+jpiQhxWsgynqPkPZIu3/xAxc32nBTlEbmP9mLJk7NG/Fiulfr1O jX5HtlJ7rCufM+YejU8CGe6CxOlEECKxfqZlI1TotoVnN6HZ1TD3AmT0ItVvnD4/UV7le/ Q1YgpairqkAinWbQnIw4RcxWNZqE+FMFCW+PWHdjfPwXWUV6m7ho0mhah1a9Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708318129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qx28GCSWl9ZgY+CDBopJ2hmNR+vsv/+MjkzXOw2ZYQk=; b=v18b33AyFmUN7nwlODhD16Wb+byFePSENAVCKBoLcjOyeguyTu4hfsWzVW2FEnx/EdApaP V8W3edxpPJDbzbOa0EtkkFBjuoYmDQKk0qekF6Ubi9J6XPMn5gQuzl/RD5yAh7kVgw1T3Y T+w/z8cwF6ve/FDT5nRJR9ZUkQW/+2kZBIY+tfqDkv1Rg+9aJvQ+GhI7iKlIiHcQJTGrrm wn39Wt03bBlN9aA8x+TiT6uLlpuNTLY0s7yCOq5Ru4Ft8q1awk3WPdycQqFayZD4JK53Ze 9jEerMLRfPw+IbrkQpw/lX8XNPuwPTU5k7cjpWI6DDU9BmxZi6n/whxOszzfHg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708318129; a=rsa-sha256; cv=none; b=YI+FHIigmp1ANpmW+uvK/jQTUdbOhREnC/sYmQtntkPD5NBTVsEamDUlvKjRj26WMXcyZh ASZzUWvd6ifBQfRynls24nuDB2BPCkjsoNz+4GRONyo3sg4iqBrMEShSAdyHuLqgVRSiI9 Ls67xrnroQhZBW+D+I8x4PeO4qL99qndBEg2Tr1W9rVN8WzfDxkKPm93g/XOoelqpgnqSY 0jIumzXLltThY5GCErMGdbOOYeQSwAXSAkRL1uE1ZdoVuiXV8KxR75NZBK6e7ZBscPxmLs oam/n7rlecRVjItsgkJ2yN4eXxAa3X0DvqBocEhThyRGgcnxRY66uSfJZai2fg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TdVRj1Sg3zKqm; Mon, 19 Feb 2024 04:48:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41J4mnq6076856; Mon, 19 Feb 2024 04:48:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41J4mnxS076853; Mon, 19 Feb 2024 04:48:49 GMT (envelope-from git) Date: Mon, 19 Feb 2024 04:48:49 GMT Message-Id: <202402190448.41J4mnxS076853@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: a51aee0a9828 - stable/14 - vtnet: Adjust for ethernet alignment. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: a51aee0a9828238ebdf2f55448d97f1f00acc5d4 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a51aee0a9828238ebdf2f55448d97f1f00acc5d4 commit a51aee0a9828238ebdf2f55448d97f1f00acc5d4 Author: Warner Losh AuthorDate: 2024-01-29 05:08:55 +0000 Commit: Warner Losh CommitDate: 2024-02-19 04:47:16 +0000 vtnet: Adjust for ethernet alignment. If the header that we add to the packet's size is 0 % 4 and we're strictly aligning, then we need to adjust where we store the header so the packet that follows will have it's struct ip header properly aligned. We do this on allocation (and when we check the length of the mbufs in the lro_nomrg case). We can't just adjust the clustersz in the softc, because it's also used to allocate the mbufs and it needs to be the proper size for that. Since we otherwise use the size of the mbuf (or sometimes the smaller size of the received packet) to compute how much we can buffer, this ensures no overflows. The 2 byte adjustment also does not affect how many packets we can receive in the lro_nomrg case. PR: 271288 Sponsored by: Netflix Reviewed by: bryanv Differential Revision: https://reviews.freebsd.org/D43224 (cherry picked from commit 3be59adbb5a2ae7600d46432d3bc82286e507e95) --- sys/dev/virtio/network/if_vtnet.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index f7ad385b3955..ab77205000d5 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1543,6 +1543,15 @@ vtnet_rx_alloc_buf(struct vtnet_softc *sc, int nbufs, struct mbuf **m_tailp) } m->m_len = size; +#ifndef __NO_STRICT_ALIGNMENT + /* + * Need to offset the mbuf if the header we're going to add + * will misalign. + */ + if (sc->vtnet_hdr_size % 4 == 0) { + m_adj(m, ETHER_ALIGN); + } +#endif if (m_head != NULL) { m_tail->m_next = m; m_tail = m; @@ -1569,6 +1578,14 @@ vtnet_rxq_replace_lro_nomrg_buf(struct vtnet_rxq *rxq, struct mbuf *m0, sc = rxq->vtnrx_sc; clustersz = sc->vtnet_rx_clustersz; +#ifndef __NO_STRICT_ALIGNMENT + /* + * Need to offset the mbuf if the header we're going to add will + * misalign, account for that here. + */ + if (sc->vtnet_hdr_size % 4 == 0) + clustersz -= ETHER_ALIGN; +#endif m_prev = NULL; m_tail = NULL; @@ -1692,6 +1709,10 @@ vtnet_rxq_enqueue_buf(struct vtnet_rxq *rxq, struct mbuf *m) header_inlined = vtnet_modern(sc) || (sc->vtnet_flags & VTNET_FLAG_MRG_RXBUFS) != 0; /* TODO: ANY_LAYOUT */ + /* + * Note: The mbuf has been already adjusted when we allocate it if we + * have to do strict alignment. + */ if (header_inlined) error = sglist_append_mbuf(sg, m); else {