From nobody Mon Jan 29 05:14:37 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 4TNc1B1Y0Cz589H2; Mon, 29 Jan 2024 05:14:38 +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 4TNc1B12pmz4NF1; Mon, 29 Jan 2024 05:14:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706505278; 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=LURtZK8Fc5A6xmQu40vd/U6F/OqqDeyLo5JECiwTKnQ=; b=dLCa5vBho626mvWTmkzHnfC0/4TQpMF3VbiyTSvFj+HpoBFOL8CbeU9SgB77mAFVYSDUv5 fdFK+aFgXdmGTRjM6ECMenlhFtQh0VBwQsfkeVJtCgmwVf4f4y00TjebuPaBK6yuPoov6b rt8NfTgIs+RYzudw5lmwCe7uIMbq6X1p3nwpWGUFtxK+dvS8kQtPRkOwobHp6snBN6NuM3 JvUy5I+GHGRFdjfYZFB0z0QNPddS04oOVuXtzFPVfgk86tW2iumzwW4WswTi4cAEhcfNDW mqR9eVYREwO1hw3WkJoogp+hyGrraXR4jB9kOtM/MsZyEE+x/CcSVyJ5dp3lTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706505278; 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=LURtZK8Fc5A6xmQu40vd/U6F/OqqDeyLo5JECiwTKnQ=; b=qrV9SgaQAuVf/c+iprapwOhmwXkjqXvNNVy2Nze0Aduv5RiVXC9b3pHU+NkcvipNgmmHdE K+ZRih9l+Bp7soNzpvJ9nECjea4Y7eSbuLJCM9BreA/xglrxgl9TLc4yOo+BxlFtEsxUE0 XR9eeklRrZ2ahvsl72TKxb39pSgSezusU3XfV2x946e97vjpph6NX1cUMSia/ySAqxuv3i gSzB2gcnP53we34GjSG4oEOi1d9rAIBTJhoXhLASw9MTdtKhlWLmRnP5pWJsTsUDkmwzGZ GLOsWpJKQ/088bbkL5iTSOqdpMVRsOUo0SoSTFpg0IjuC/+AjYOgUM1pouRoxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706505278; a=rsa-sha256; cv=none; b=WgfnUVkIbdztcnY7HOO7FzjYgYygbv2xnytAqMu4DJ0mzkleNmM+B9bECoZ8hIqxxc7OR5 RVEuLBQHmmoOWuB/8l9ViWsTyTVhChzanrblJ9je2CeFH8kt5tqi3Ih/lhHDYuUposAavQ ibGpe4reAHZtlUsYlDfY9SY2AoFIZ7mwT4zmI+xWvl58sYLxugCSOfOP7mFMkpnSsIC4Js A3xyXLUMcwMGehmWmBPv6uk5ECs9SMnVvnyYt7d/8cuoocYRGlqZYasku6+AAHJuTOl1iw D5bYpXELy/s7c1YZvo8X7fssUTb89FPv5njD2WonTZKpGMkXVflH53zxma+BOA== 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 4TNc196vmlzf6v; Mon, 29 Jan 2024 05:14:37 +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 40T5EbX6061792; Mon, 29 Jan 2024 05:14:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40T5Eb1i061789; Mon, 29 Jan 2024 05:14:37 GMT (envelope-from git) Date: Mon, 29 Jan 2024 05:14:37 GMT Message-Id: <202401290514.40T5Eb1i061789@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3be59adbb5a2 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 3be59adbb5a2ae7600d46432d3bc82286e507e95 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3be59adbb5a2ae7600d46432d3bc82286e507e95 commit 3be59adbb5a2ae7600d46432d3bc82286e507e95 Author: Warner Losh AuthorDate: 2024-01-29 05:08:55 +0000 Commit: Warner Losh CommitDate: 2024-01-29 05:08:55 +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 --- 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 287af7751066..11c640bccdeb 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1534,6 +1534,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; @@ -1560,6 +1569,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; @@ -1683,6 +1700,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 {