Skip to content

Commit 00e83ab

Browse files
mstsirkingregkh
authored andcommitted
virtio_net: fix PAGE_SIZE > 64k
[ Upstream commit d0fa28f00052391b5df328f502fbbdd4444938b7 ] I don't have any guests with PAGE_SIZE > 64k but the code seems to be clearly broken in that case as PAGE_SIZE / MERGEABLE_BUFFER_ALIGN will need more than 8 bit and so the code in mergeable_ctx_to_buf_address does not give us the actual true size. Cc: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c64f419 commit 00e83ab

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/net/virtio_net.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ module_param(gso, bool, 0444);
4747
*/
4848
DECLARE_EWMA(pkt_len, 1, 64)
4949

50+
/* With mergeable buffers we align buffer address and use the low bits to
51+
* encode its true size. Buffer size is up to 1 page so we need to align to
52+
* square root of page size to ensure we reserve enough bits to encode the true
53+
* size.
54+
*/
55+
#define MERGEABLE_BUFFER_MIN_ALIGN_SHIFT ((PAGE_SHIFT + 1) / 2)
56+
5057
/* Minimum alignment for mergeable packet buffers. */
51-
#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
58+
#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, \
59+
1 << MERGEABLE_BUFFER_MIN_ALIGN_SHIFT)
5260

5361
#define VIRTNET_DRIVER_VERSION "1.0.0"
5462

0 commit comments

Comments
 (0)