From nobody Mon Feb 19 07:00:28 2024 X-Original-To: dev-commits-src-branches@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 4TdYMc6KKzz59qSV; Mon, 19 Feb 2024 07:00:28 +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 4TdYMc4Xhxz43Q6; Mon, 19 Feb 2024 07:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708326028; 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=cgZHsEYClGwcTcEHN8iZhbYynWSzpEy7aLKt+dOMNpU=; b=k5KjodTJu6pz8iJIz1FHC3LNMJ/jAuQzw9AQVI/2jqA9m/qZ8z8t0rzDZmh/nXsn0Ew87F ZSkl7+5/zNrqe5PSGbEQg9kvjZLoTttu6IIAU5za3GKpZ6MG49n1Lq1hKMRlgkwqy7v1s0 1wDBUe5ci31Id5DsAPm6RrTo01rhoZTo8x15vReK8PiD5OdVhtLt+rIw1QU+h2HH1U8VkB 5E4VBsPNsqikVTqwYqgxb6a/ix8a+xxqnCuyHtMaFyAXSk77i9DNlu83/iZf09FUJ09Kag NVZMHAZQlheZnUsG9G84fcmc+hx8oZL7v2QZTmmMphvLRI6AqY99TjpnCT+32g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708326028; 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=cgZHsEYClGwcTcEHN8iZhbYynWSzpEy7aLKt+dOMNpU=; b=IzkmHcbeE2XmbyM+5mX/hraf+hFLUONj0O0Na6e5ZDRhB95slomaSnl7KE5iyNUv5b1bR0 V8M+W39yfhOq81YrsGGxbTfR9lJNIMN/fap1TlGb2nEj5rXcYYk4tFThws6mNz60GoQkvk mZGKMQub3sOikyZlUEWuuNZnxhBlqfh6caM8Yn2voOQH72nOraWsf9l4Hep+F7w5bJse+f 9Tvgr/XXRghiu7Ft5t7JwSIoPDxei6r6qildG67sjg0cwZmDGqtkQAIf2opJEzJKH3lyTG KOE39ckNjxLpK0gi1QwAneq3Ob/V9a9yDcWbYJ4mILdZDVmlJKpBMID87P2gjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708326028; a=rsa-sha256; cv=none; b=iDvPEcmJHpzTp6k/4k2rKndIx4mNle3CT/cdaLQlARWF5iaR9uXLiAHGybwM/A2qNmmwtx GJ2v+ZYzjbLnzscq1boqV3i5XMoQEHc5q1EkqMOOqJKRG86Hp5Khfi2KNqpm3rFxXaTMcW L+4ZLmB5/mYThvBBZL7Djxt89znfeU0f1uQewV7znyxaMsSDQ1NEoMNpSTTDy1Dz+1JbUY 4X/SSWPb7k4+QMVD+JuO2J59x1jU50jj50632L7IB3cWZBF8d9BCmyRUpf+LCQoXc4TXSM rD3DINzRUpJEwXeYSXm9a8ru4hElIWIkHaJmoqEzziEtaXkrlLxQvYLNHCboaw== 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 4TdYMc3bcVzPSN; Mon, 19 Feb 2024 07:00:28 +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 41J70SB0006608; Mon, 19 Feb 2024 07:00:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41J70S62006605; Mon, 19 Feb 2024 07:00:28 GMT (envelope-from git) Date: Mon, 19 Feb 2024 07:00:28 GMT Message-Id: <202402190700.41J70S62006605@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: 67aff34d9ad0 - releng/13.3 - vtnet: Account for the padding when selecting allocation size List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/releng/13.3 X-Git-Reftype: branch X-Git-Commit: 67aff34d9ad00761b2e2b1197c4bc1e856bb6959 Auto-Submitted: auto-generated The branch releng/13.3 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=67aff34d9ad00761b2e2b1197c4bc1e856bb6959 commit 67aff34d9ad00761b2e2b1197c4bc1e856bb6959 Author: Warner Losh AuthorDate: 2024-02-05 05:43:39 +0000 Commit: Warner Losh CommitDate: 2024-02-19 06:59:46 +0000 vtnet: Account for the padding when selecting allocation size While we account for the padding in the length of the mbuf we use, we do not account for it when we 'guess' the size of the mbuf to allocate based in the MTU of the device. This leads to a situation where we might fail if the mtu is close to a bucket size (say 2018) such that the added padding would push us over the edge for a full-sized packet. mtu of 2018 is super rare (2016 and 2020 would both work), but fix it none-the-less. It's a shame we can't just set VTNET_RX_HEADER_PAD to 2 in this case. The 4 seems hard-coded somewhere I've not found documented (I think it's in the protocol given the comments about VIRTIO_F_ANY_LAYOUT). Sponsored by: Netflix Reviewed by: bz Differential Revision: https://reviews.freebsd.org/D43656 (cherry picked from commit d9e0e42627613b56abf0f8fa1ad601e5690d775c) (cherry picked from commit 1dc264a126b13e0e20b13bbcd69451c5d4b63f7c) Approved-by: re (cperciva) --- sys/dev/virtio/network/if_vtnet.c | 9 +++++++++ sys/dev/virtio/network/if_vtnetvar.h | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index 3945826f91a0..ae35d658e1bb 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1237,6 +1237,15 @@ vtnet_rx_cluster_size(struct vtnet_softc *sc, int mtu) } else framesz = sizeof(struct vtnet_rx_header); framesz += sizeof(struct ether_vlan_header) + mtu; +#ifndef __NO_STRICT_ALIGNMENT + /* + * Account for the offsetting we'll do elsewhere so we allocate the + * right size for the mtu. + */ + if (sc->vtnet_hdr_size % 4 == 0) { + framesz += ETHER_ALIGN; + } +#endif if (framesz <= MCLBYTES) return (MCLBYTES); diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h index 318066421072..e4c1934dfc81 100644 --- a/sys/dev/virtio/network/if_vtnetvar.h +++ b/sys/dev/virtio/network/if_vtnetvar.h @@ -232,7 +232,13 @@ vtnet_software_lro(struct vtnet_softc *sc) */ #define VTNET_VLAN_FILTER_NWORDS (4096 / 32) -/* We depend on these being the same size (and same layout). */ +/* + * We depend on all of the hdr structures being even, and matching the standard + * length. As well, we depend on two being identally sized (with the same + * layout). + */ +CTASSERT(sizeof(struct virtio_net_hdr_v1) == 12); +CTASSERT(sizeof(struct virtio_net_hdr) == 10); CTASSERT(sizeof(struct virtio_net_hdr_mrg_rxbuf) == sizeof(struct virtio_net_hdr_v1));