From nobody Wed Oct 8 17:29:50 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47F842609F7; Wed, 25 Jun 2025 13:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857354; cv=none; b=TjzWeqFQOWyRA1ZCDRYUKYF6V5H2amv4tOhGi77DIufFy8mXD37ukc0R4kqx58O5OUU3vpzQ7pe9rO3P0L/ZDNsOK3LceLfW+pU5hLkCiQM2zIiZk7gpkT+DTer2ZXA1OEIbqdgFioOToAB275cBRmupOBBdVLIY+3L0PKVQxrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857354; c=relaxed/simple; bh=NAwf6+Q/qrG6EI6uYZH3wXeLmsbgzYePN5qMa/M14K4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uchZhzrAcbXWtqC0tWZSLLV9M9vejE3nlF3+qQZRoYMUjT8NiRk5+5blyWTfHFp5F6P0n1k/lcmIyiW+y59ZffYCQUDOS6g/0aV7O/DXkwThVAqYn72JQ0AsPn7nEFtimaXKtZlp5Thk/PjaDjFAAQwhYvNO3H8I1jYlVDWsIRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MQjg6m/1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MQjg6m/1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 938E6C4CEF3; Wed, 25 Jun 2025 13:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750857353; bh=NAwf6+Q/qrG6EI6uYZH3wXeLmsbgzYePN5qMa/M14K4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQjg6m/1C9qlCPUODcoH0JDFEtk4CIosbdfn+i6vqC/f8ej0/R8unSl3quBtgbZc2 uu8KtQBJW2ab9G7eHrDZeaEZ7aDV+8RvFpgjS6Rqy3P5w/RjhwQ+8GA7wIThGVXhBA DVj57PASE3mFzs0/NMfimvqcUPew/oyGlnQpLNH8JXJW1deu+OSMydYZvCKoK5dLbj DLuqDvK0ubgwlgN1fCHG3GGZjGVLpuNYtOUaxvgmYQa1yCOhgewvYK3pGPeio6LJ8s NAn13T1DMBbVDlI2JZkYTf8l5ntAEa+k0azt72s7LHu6h2ifN9myiBHfGPXDrm0ZIJ FLhNJ2zSLZ31g== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Keir Fraser , Steven Moreland , Frederick Mayle , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , netdev@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 1/5] vhost/vsock: Avoid allocating arbitrarily-sized SKBs Date: Wed, 25 Jun 2025 14:15:39 +0100 Message-Id: <20250625131543.5155-2-will@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250625131543.5155-1-will@kernel.org> References: <20250625131543.5155-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vhost_vsock_alloc_skb() returns NULL for packets advertising a length larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE in the packet header. However, this is only checked once the SKB has been allocated and, if the length in the packet header is zero, the SKB may not be freed immediately. Hoist the size check before the SKB allocation so that an iovec larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + the header size is rejected outright. The subsequent check on the length field in the header can then simply check that the allocated SKB is indeed large enough to hold the packet. Signed-off-by: Will Deacon --- drivers/vhost/vsock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 802153e23073..66a0f060770e 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -344,6 +344,9 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, =20 len =3D iov_length(vq->iov, out); =20 + if (len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) + return NULL; + /* len contains both payload and hdr */ skb =3D virtio_vsock_alloc_skb(len, GFP_KERNEL); if (!skb) @@ -367,8 +370,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, return skb; =20 /* The pkt is too big or the length in the header is invalid */ - if (payload_len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || - payload_len + sizeof(*hdr) > len) { + if (payload_len + sizeof(*hdr) > len) { kfree_skb(skb); return NULL; } --=20 2.50.0.714.g196bf9f422-goog From nobody Wed Oct 8 17:29:50 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10802264F9F; Wed, 25 Jun 2025 13:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857357; cv=none; b=UwEIgOdAvfgb6a6i2zVA4hSLdbAw+QlLk1R2Mxz/8RByglfhIP0q04758GxfkKElInG4ASumd0ra3m9wyiUsEjskyRkANktADqKX4qSzXlWgsuURxtiGn5AgQjrfRIGSmIAaI8GiwYuxFG3FhkW0s+mpZZREss3jLuW61+bbR6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857357; c=relaxed/simple; bh=tzu8C7G0MXN2UCFhPls8DX7uDkR2X/rKpQJD5CnqN8o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AWm6IkPfu1jbLDoNQ+I0GMcJ6GW0CM+k2ZFPfXwlcwsCrXHE1jV4zy+BW76y5iI5lgciGxwoDZXGlyiRmlDn+XMzASur4O7tkedNkgowjCfpTksQ/J4/yfPLTOSEEfDwGqkCSDsO6LZ/yNpxNuk5S9eAili5Pts3C4zk6Yqkla0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gWT6vpi5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gWT6vpi5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48213C4CEF0; Wed, 25 Jun 2025 13:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750857356; bh=tzu8C7G0MXN2UCFhPls8DX7uDkR2X/rKpQJD5CnqN8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gWT6vpi5BODHPyeVqzNQJeFoRruUOyzf+nuN/Vbk1yO1fGiePeTUm3kaWPxO5Sncu mFvn0biHHgL/IrQI4LjX3M3Ji7qn2PorTm08rNQiigEUORqJjiTfV9/Ov6LfsrVqa7 Or632OZbPTLpFo0DqhzElhPJklq+zGMaEk84XJvUNQ+qvHI+5Psc3Pof65fdnbVKGs WjBmeJM4OjItEOGxLs8PX2EdqX+u6AC3IYOPfDhU4E1bcK2shrnnRPl5h0SMnpOmPK ZZXG4KHYXsP2c9quWr2apNoJOCfS3TLkV/AAs9SsfA0Mb1XMRehXyTFzkz2y0LqMNE 1NVVuBcFQQsgQ== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Keir Fraser , Steven Moreland , Frederick Mayle , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , netdev@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 2/5] vsock/virtio: Resize receive buffers so that each SKB fits in a page Date: Wed, 25 Jun 2025 14:15:40 +0100 Message-Id: <20250625131543.5155-3-will@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250625131543.5155-1-will@kernel.org> References: <20250625131543.5155-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When allocating receive buffers for the vsock virtio RX virtqueue, an SKB is allocated with a 4140 data payload (the 44-byte packet header + VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE). Even when factoring in the SKB overhead, the resulting 8KiB allocation thanks to the rounding in kmalloc_reserve() is wasteful (~3700 unusable bytes) and results in a higher-order page allocation for the sake of a few hundred bytes of packet data. Limit the vsock virtio RX buffers to a page per SKB, resulting in much better memory utilisation and removing the need to allocate higher-order pages entirely. Signed-off-by: Will Deacon --- include/linux/virtio_vsock.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 36fb3edfa403..67ffb64325ef 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -111,7 +111,8 @@ static inline size_t virtio_vsock_skb_len(struct sk_buf= f *skb) return (size_t)(skb_end_pointer(skb) - skb->head); } =20 -#define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4) +#define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (SKB_WITH_OVERHEAD(PAGE_SIZE) \ + - VIRTIO_VSOCK_SKB_HEADROOM) #define VIRTIO_VSOCK_MAX_BUF_SIZE 0xFFFFFFFFUL #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64) =20 --=20 2.50.0.714.g196bf9f422-goog From nobody Wed Oct 8 17:29:50 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5220A266B40; Wed, 25 Jun 2025 13:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857359; cv=none; b=sN7qbIrSOhaubJRPf2kRSfrOXJFOTozeVVI2ne4lMGnTScl8Antg1hpiI3FmMrWRGbkb6MdsyyxzYCbAwB/XHS9yokNC9JjJkjpfPOrCwBkClZTH+Z4YYCu4DBcXaJ0xsm1OUHEH5fghaPzS55LCI8QZs+OoatgNWyEfj9UcSEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857359; c=relaxed/simple; bh=6FGvTFiznU/YaYWH3NC0Q28wP/NFxB0CJ852Q7yLWto=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ObJPix1RnC6GqBFCD7tSe+ERG23W8LZIUVT78/lTmeJgdxeLuFJIpIgLgLQpNEVCnNfXrWhmdHoXr6W/KR56LKdNO0bLC9u+rdBPTecVd4cGfXfTPC+Ao2CFRaIBY0SuTqZgSGulHW3iXJRiIcdkK6xY1lxHjqwNjZseHcVHVz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R65+/fuF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R65+/fuF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 016BAC4CEF5; Wed, 25 Jun 2025 13:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750857359; bh=6FGvTFiznU/YaYWH3NC0Q28wP/NFxB0CJ852Q7yLWto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R65+/fuFoMFU0nJIJeS/jVGsx/DWb6yzZE6aM/rohakai6HSG82IGaVrnWeiV/C8P brcsURjy1Z+9jZAftBRxadvrGHiqoFRBFShE3UNt+oljVf5NLZorwE/Z76eKxNwpJf LGBkUo9HdQyFKpHnVsJ+zB/vfxu326X0Q4bHUkFWSMWCT/0kF1TQFlc5F0RVT8onVO IA2GgiX/xH5wc8FIEmFI0pfii7KCjvoEOI1UcUp7hwmySLjV87u+9ac8wcMxwVJf8v NxTe1hjpUBwNRElVPZUFXEkI7Eac5F8uJAatwVidHBfuva99H+BiW0Hnpu4sJ+c9oB Q1W2ACLbErhvg== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Keir Fraser , Steven Moreland , Frederick Mayle , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , netdev@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 3/5] vhost/vsock: Allocate nonlinear SKBs for handling large receive buffers Date: Wed, 25 Jun 2025 14:15:41 +0100 Message-Id: <20250625131543.5155-4-will@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250625131543.5155-1-will@kernel.org> References: <20250625131543.5155-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When receiving a packet from a guest, vhost_vsock_handle_tx_kick() calls vhost_vsock_alloc_skb() to allocate and fill an SKB with the receive data. Unfortunately, these are always linear allocations and can therefore result in significant pressure on kmalloc() considering that the maximum packet size (VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) is a little over 64KiB, resulting in a 128KiB allocation for each packet. Rework the vsock SKB allocation so that, for sizes with page order greater than PAGE_ALLOC_COSTLY_ORDER, a nonlinear SKB is allocated instead with the packet header in the SKB and the receive data in the fragments. Signed-off-by: Will Deacon --- drivers/vhost/vsock.c | 15 +++++++++------ include/linux/virtio_vsock.h | 31 +++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 66a0f060770e..cfa4e1bcf367 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -344,11 +344,16 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, =20 len =3D iov_length(vq->iov, out); =20 - if (len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) + if (len < VIRTIO_VSOCK_SKB_HEADROOM || + len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) return NULL; =20 /* len contains both payload and hdr */ - skb =3D virtio_vsock_alloc_skb(len, GFP_KERNEL); + if (len > SKB_WITH_OVERHEAD(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) + skb =3D virtio_vsock_alloc_skb_with_frags(len, GFP_KERNEL); + else + skb =3D virtio_vsock_alloc_skb(len, GFP_KERNEL); + if (!skb) return NULL; =20 @@ -377,10 +382,8 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, =20 virtio_vsock_skb_rx_put(skb); =20 - nbytes =3D copy_from_iter(skb->data, payload_len, &iov_iter); - if (nbytes !=3D payload_len) { - vq_err(vq, "Expected %zu byte payload, got %zu bytes\n", - payload_len, nbytes); + if (skb_copy_datagram_from_iter(skb, 0, &iov_iter, payload_len)) { + vq_err(vq, "Failed to copy %zu byte payload\n", payload_len); kfree_skb(skb); return NULL; } diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 67ffb64325ef..8f9fa1cab32a 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -51,27 +51,46 @@ static inline void virtio_vsock_skb_rx_put(struct sk_bu= ff *skb) { u32 len; =20 + DEBUG_NET_WARN_ON_ONCE(skb->len); len =3D le32_to_cpu(virtio_vsock_hdr(skb)->len); =20 - if (len > 0) + if (skb_is_nonlinear(skb)) + skb->len =3D len; + else skb_put(skb, len); } =20 -static inline struct sk_buff *virtio_vsock_alloc_skb(unsigned int size, gf= p_t mask) +static inline struct sk_buff * +__virtio_vsock_alloc_skb_with_frags(unsigned int header_len, + unsigned int data_len, + gfp_t mask) { struct sk_buff *skb; + int err; =20 - if (size < VIRTIO_VSOCK_SKB_HEADROOM) - return NULL; - - skb =3D alloc_skb(size, mask); + skb =3D alloc_skb_with_frags(header_len, data_len, + PAGE_ALLOC_COSTLY_ORDER, &err, mask); if (!skb) return NULL; =20 skb_reserve(skb, VIRTIO_VSOCK_SKB_HEADROOM); + skb->data_len =3D data_len; return skb; } =20 +static inline struct sk_buff * +virtio_vsock_alloc_skb_with_frags(unsigned int size, gfp_t mask) +{ + size -=3D VIRTIO_VSOCK_SKB_HEADROOM; + return __virtio_vsock_alloc_skb_with_frags(VIRTIO_VSOCK_SKB_HEADROOM, + size, mask); +} + +static inline struct sk_buff *virtio_vsock_alloc_skb(unsigned int size, gf= p_t mask) +{ + return __virtio_vsock_alloc_skb_with_frags(size, 0, mask); +} + static inline void virtio_vsock_skb_queue_head(struct sk_buff_head *list, struct sk_buff *skb) { --=20 2.50.0.714.g196bf9f422-goog From nobody Wed Oct 8 17:29:50 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD9D267B7F; Wed, 25 Jun 2025 13:16:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857362; cv=none; b=s9Qs99Q2O5ZGuajUM/GivIYVpFilgfDHN6HQe3J74fEHtjgYWjdw+Yo4z2u6SohqFK8hAeLOjPgih5UAs5oc2g/Q/pX6maMDOb6KOdGo5fHP1Je/8HwtOeHtdj4Ez1MUK9VXGqo9pVDWosJe1TysJMEz8s23hfS/sEx4JHC7A4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857362; c=relaxed/simple; bh=Ikr9BmRhSKTp5eLQeoRaFu56Cz49I5eK9mJ0EqkLrrU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HpIdDS/UNBlU4QPQIi9KY26yq7oX01H41LELCVvObep7P4QxTjGkjRmHcxyzM++oRV/LIThl+xyzvbZvCeq6DY3bM1EToYaPOHgQjjc3QULEDq4ibJWXjUiE/duCf7jNw/s1mKmjkxMxudiQgxFEbZv7iOp0eX+oFvgYxoHehxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uzi6pbmt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uzi6pbmt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A27C9C4CEF0; Wed, 25 Jun 2025 13:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750857361; bh=Ikr9BmRhSKTp5eLQeoRaFu56Cz49I5eK9mJ0EqkLrrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uzi6pbmtdcz63Oy6YzgyGgA/fkzZu6QxuynWYcMkq0hPknSusPfyEtmOofpeR+K/q iYjEW5H2O4XTLU66YRjgYzAtBdOIAqfkZUcqJVwFERx84dDh0mAOeFF6qJPrkmbdcU 1gwo/HOsm2aZ5N0Kbjc+cuYjlnGRNnru+zcK2y0COEXgK3HrjkyhqfehfUzpIPcNsc K/tMmAtFr+g6lxWa12hoA1H7XJfZPmZ4S+roAOrFVL/3JCqQ9KGqshep4NFDL1r2Mu 7tux6AxvVBWCC02uXeQaP2pl2aJ0BISbtnMAgS/+BcL8FGmcGkcu0jCLyUC6MIo0W1 g10YY8FrM41tA== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Keir Fraser , Steven Moreland , Frederick Mayle , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , netdev@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 4/5] vsock/virtio: Rename virtio_vsock_skb_rx_put() to virtio_vsock_skb_put() Date: Wed, 25 Jun 2025 14:15:42 +0100 Message-Id: <20250625131543.5155-5-will@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250625131543.5155-1-will@kernel.org> References: <20250625131543.5155-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for using virtio_vsock_skb_rx_put() when populating SKBs on the vsock TX path, rename virtio_vsock_skb_rx_put() to virtio_vsock_skb_put(). No functional change. Signed-off-by: Will Deacon Reviewed-by: Stefano Garzarella --- drivers/vhost/vsock.c | 2 +- include/linux/virtio_vsock.h | 2 +- net/vmw_vsock/virtio_transport.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index cfa4e1bcf367..3799c0aeeec5 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -380,7 +380,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, return NULL; } =20 - virtio_vsock_skb_rx_put(skb); + virtio_vsock_skb_put(skb); =20 if (skb_copy_datagram_from_iter(skb, 0, &iov_iter, payload_len)) { vq_err(vq, "Failed to copy %zu byte payload\n", payload_len); diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 8f9fa1cab32a..d237ca0fc320 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -47,7 +47,7 @@ static inline void virtio_vsock_skb_clear_tap_delivered(s= truct sk_buff *skb) VIRTIO_VSOCK_SKB_CB(skb)->tap_delivered =3D false; } =20 -static inline void virtio_vsock_skb_rx_put(struct sk_buff *skb) +static inline void virtio_vsock_skb_put(struct sk_buff *skb) { u32 len; =20 diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transp= ort.c index f0e48e6911fc..3319be2ee3aa 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -648,7 +648,7 @@ static void virtio_transport_rx_work(struct work_struct= *work) continue; } =20 - virtio_vsock_skb_rx_put(skb); + virtio_vsock_skb_put(skb); virtio_transport_deliver_tap_pkt(skb); virtio_transport_recv_pkt(&virtio_transport, skb); } --=20 2.50.0.714.g196bf9f422-goog From nobody Wed Oct 8 17:29:50 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F15CB2690D9; Wed, 25 Jun 2025 13:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857365; cv=none; b=iFokQ1YvSMl6V9gttmuJZeDl83Cx63hNH3o8gMouTdY+Bu8SfBWQ15kuZ7UaB5BLl9X4Zpb7jWLB75yEdmL75tcbOBXohhXYuK/Buzal+ZxWbe3Y7AQlQgGTshxouN+Bjn0oOWrWbymR400Nh6jWEuludWvBGckyo8h3BQaKzl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750857365; c=relaxed/simple; bh=47+rWBkW5T9ldh2nVz1QhH5OlPRIa49bdi0RnHpxrJg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NO8nAOGEKQDu0bceynWwdwBPIu8fe06CGZJ6ZKUC9soAbvVaA+KTa/2Kp08oS9Kgo9Y9BbFaReD8cbJOrpeI17RralN/AYVlGgYnuITXcyNKsbndJIDOzwT3Gbo1ilnlXqihNj3+rktSGtR+UjDLkAHx16KNb0xzJs8HygONMYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G6clDI6u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G6clDI6u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56660C4CEEA; Wed, 25 Jun 2025 13:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750857364; bh=47+rWBkW5T9ldh2nVz1QhH5OlPRIa49bdi0RnHpxrJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6clDI6uglgTscVNsSEyVq1VgDkkZSq6qTwx3X58T2ENqGSO780wRagTtNexP10OT Bq9EjQt8y64thrAPRiVzE9sfYWDRn/oM0ad4UXLvHT/D3c8k1wXgKIuLQ6pf8f35ss iZTEs8Dn6hHacrecfqwn6vy5Qnlg10cZUiKoyAKrj4M0tU/f+GNJxds6VHaZc6odvS Xvh+vNqsZs2OInTtrsMSu47g+AZiWGA0O+dk9baAdPKDpmfpPcXh9ScHTXKt6tSmc2 Cst3A920d4vuz3GMA973XkbaKzTPmqCqWPqKjBsu0fvOp29pA6MvSiMLJSgJek6u0j FdBxwEpDWQnPg== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: Will Deacon , Keir Fraser , Steven Moreland , Frederick Mayle , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , netdev@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 5/5] vhost/vsock: Allocate nonlinear SKBs for handling large transmit buffers Date: Wed, 25 Jun 2025 14:15:43 +0100 Message-Id: <20250625131543.5155-6-will@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250625131543.5155-1-will@kernel.org> References: <20250625131543.5155-1-will@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When transmitting a vsock packet, virtio_transport_send_pkt_info() calls virtio_transport_alloc_skb() to allocate and fill SKBs with the transmit data. Unfortunately, these are always linear allocations and can therefore result in significant pressure on kmalloc() considering that the maximum packet size (VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM) is a little over 64KiB, resulting in a 128KiB allocation for each packet. Rework the vsock SKB allocation so that, for sizes with page order greater than PAGE_ALLOC_COSTLY_ORDER, a nonlinear SKB is allocated instead with the packet header in the SKB and the transmit data in the fragments. Signed-off-by: Will Deacon --- net/vmw_vsock/virtio_transport_common.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 1b5d9896edae..424eb69e84f9 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -109,7 +109,8 @@ static int virtio_transport_fill_skb(struct sk_buff *sk= b, return __zerocopy_sg_from_iter(info->msg, NULL, skb, &info->msg->msg_iter, len, NULL); =20 - return memcpy_from_msg(skb_put(skb, len), info->msg, len); + virtio_vsock_skb_put(skb); + return skb_copy_datagram_from_iter(skb, 0, &info->msg->msg_iter, len); } =20 static void virtio_transport_init_hdr(struct sk_buff *skb, @@ -261,7 +262,11 @@ static struct sk_buff *virtio_transport_alloc_skb(stru= ct virtio_vsock_pkt_info * if (!zcopy) skb_len +=3D payload_len; =20 - skb =3D virtio_vsock_alloc_skb(skb_len, GFP_KERNEL); + if (skb_len > SKB_WITH_OVERHEAD(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) + skb =3D virtio_vsock_alloc_skb_with_frags(skb_len, GFP_KERNEL); + else + skb =3D virtio_vsock_alloc_skb(skb_len, GFP_KERNEL); + if (!skb) return NULL; =20 --=20 2.50.0.714.g196bf9f422-goog