From nobody Mon Feb 19 04:50:03 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 4TdVT81qWTz59392; Mon, 19 Feb 2024 04:50:04 +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 4TdVT81PBsz51Xl; Mon, 19 Feb 2024 04:50:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708318204; 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=Drq4MoSuWuVGK9mzaVllbASm5nfNbTVa1Qr9E9T1f+0=; b=jDzKDi9bW7HChfdIADoXhil7wrsTYSWyNfwA1U9jD24Nhc/vf23PzLK8EYVAyr3LmD+dP/ BoDT8VF9gjlMWyt5Eky6aBbQBsu4FJH5PQvjv2ZW0DoFJqSLP36tQ9MWuk4qtvn5LRPASt xXaKjA7JYIBN2AlcfcVQP/qG+isX33yIJmTe8HVnnDZtrer3NXHMQG/pmW2rINS0J2Lly5 4Be/uGGO0osEnjvXgIPHRp2IsFEkt10N1P9KSy5AXVmNgrXercOAqG4qW09LE80AYkX4Qa 5/Y9l/tt96TngE6mmF3zl2P5bm5gFWU90/dG7efdsV/pA96Y+b2Y3Rq2nbLToQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708318204; 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=Drq4MoSuWuVGK9mzaVllbASm5nfNbTVa1Qr9E9T1f+0=; b=mCzw0fBcDGetAttEpQwSJ7/oyLlGT4oSQI4YORhRlIf7pIEozOl5yCCLZcborx9T3KsAl5 mwUkwgXueOwlBKnb/hiWpI+EbBRd5ouwESrcWAZMPYdkzmbOfhSiQntNQiF0r/EJ22AWRq NbtozCT3KVPawhxpZsDXxInLE58sfq6gI4NmvfmQIny+4f2ZlD2v8oTCBaTtH+XaLh4aeV ULz7o22fURBmgmIK4cOEEP6eQW4suTy3v2MicgbB2hLTxU4nR06Z/Ms/FGSQDNAEEYIsjA hf5xr844j2Y4qP1WICRrVdNbb8/qDlpNWrqvxZfHOzCu9EI/qHlCUN9NvbNeyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708318204; a=rsa-sha256; cv=none; b=ydvNCnMWNtLPn3HuvQBJ82OFyCxNGoDdQ8hwSG1O4tSjgyU9C1elzOjka64Lz6yQ1JZOod fuEYRaCv0jwaWNhShzWecS9/4yTNDtWDJt9UfrSiRFNRJHeCDxeG4ct/VMorgv329+3/yO FIl2aKyzflt8N/B1BMEAdpfgBU5mc16TGrheO/maMAf0/kpQ29MRqaj6Xjk6FopHbjifcp KwR/J3xOISektSjO43ByeYKS9gYms7XM8MUxKSyeLgwZD5Sp/fJjN95GZME5mbUzLebLiL 0FLsEUv8YqSrGgpmcnLoVCC2eVMe7OGDG39A28D267BaCFIxR9U1kHW0hyltow== 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 4TdVT809hrzKnM; Mon, 19 Feb 2024 04:50:04 +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 41J4o3vt079710; Mon, 19 Feb 2024 04:50:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41J4o36B079706; Mon, 19 Feb 2024 04:50:03 GMT (envelope-from git) Date: Mon, 19 Feb 2024 04:50:03 GMT Message-Id: <202402190450.41J4o36B079706@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: 778eb6e1f666 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 778eb6e1f6668864a6eddd2f6f9bcc2aa26344f3 Auto-Submitted: auto-generated The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=778eb6e1f6668864a6eddd2f6f9bcc2aa26344f3 commit 778eb6e1f6668864a6eddd2f6f9bcc2aa26344f3 Author: Warner Losh AuthorDate: 2024-01-29 05:08:55 +0000 Commit: Warner Losh CommitDate: 2024-02-19 04:46:43 +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 9737e964a591..3945826f91a0 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1545,6 +1545,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; @@ -1571,6 +1580,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; @@ -1694,6 +1711,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 {