net/packet: support mergeable feature of virtio
Subsystems (3)
PATCH v5 1/1 net/packet: support mergeable feature of virtio
From: Jianfeng Tan <[email protected]>
Packet sockets, like tap, can be used as the backend for kernel vhost. In packet sockets, virtio net header size is currently hardcoded to be the size of struct virtio_net_hdr, which is 10 bytes; however, it is not always the case: some virtio features, such as mrg_rxbuf, need virtio net header to be 12-byte long.
Mergeable buffers, as a virtio feature, is worthy of supporting: packets that are larger than one-mbuf size will be dropped in vhost worker's handle_rx if mrg_rxbuf feature is not used, but large packets cannot be avoided and increasing mbuf's size is not economical.
With this virtio feature enabled by virtio-user, packet sockets with hardcoded 10-byte virtio net header will parse mac head incorrectly in packet_snd by taking the last two bytes of virtio net header as part of mac header.
This incorrect mac header parsing will cause packet to be dropped due to invalid ether head checking in later under-layer device packet receiving.
By adding extra field vnet_hdr_sz with utilizing holes in struct packet_sock to record currently used virtio net header size and supporting extra sockopt PACKET_VNET_HDR_SZ to set specified vnet_hdr_sz, packet sockets can know the exact length of virtio net header that virtio user gives.
In packet_snd, tpacket_snd and packet_recvmsg, instead of using hardcoded virtio net header size, it can get the exact vnet_hdr_sz from corresponding packet_sock, and parse mac header correctly based on this information to avoid the packets being mistakenly dropped.
---
V4 -> V5:
* add READ_ONCE() macro when initializing local vnet_hdr_sz variable;
* fix some nits.
include/uapi/linux/if_packet.h | 1 + net/packet/af_packet.c | 85 +++++++++++++++++++++------------- net/packet/diag.c | 2 +- net/packet/internal.h | 2 +- 4 files changed, 57 insertions(+), 33 deletions(-)
include/uapi/linux/if_packet.h +1 -0
@@ -59,6 +59,7 @@ struct sockaddr_ll {#define PACKET_ROLLOVER_STATS 21#define PACKET_FANOUT_DATA 22#define PACKET_IGNORE_OUTGOING 23 +#define PACKET_VNET_HDR_SZ 24#define PACKET_FANOUT_HASH 0#define PACKET_FANOUT_LB 1
net/packet/af_packet.c +54 -31
212 lines not on this page · raw message
net/packet/diag.c +1 -1
@@ -27,7 +27,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb) pinfo.pdi_flags |=PDI_AUXDATA ;if (po->origdev) pinfo.pdi_flags |=PDI_ORIGDEV ; -if (po->has_vnet_hdr) +if (po->vnet_hdr_sz) pinfo.pdi_flags |=PDI_VNETHDR ;if (po->tp_loss) pinfo.pdi_flags |=PDI_LOSS ;
net/packet/internal.h +1 -1
@@ -119,9 +119,9 @@ struct packet_sock {unsigned int running;/* bind_lock must be held */ unsigned int auxdata:1, /* writer must hold sock lock */ origdev:1, - has_vnet_hdr:1, tp_loss:1, tp_tx_has_off:1; +u8 vnet_hdr_sz;int pressure;int ifindex;/* bound device */ __be16 num;
Signature · 1 line
2.19.1.6.gb485710b
Willem de Bruijn
maintainerQuoted 30 lines · 沈安琪(凛玥)
From: Jianfeng Tan <[email protected]>
Packet sockets, like tap, can be used as the backend for kernel vhost. In packet sockets, virtio net header size is currently hardcoded to be the size of struct
virtio_net_hdr, which is 10 bytes; however, it is not always the case: some virtio features, such asmrg_rxbuf, need virtio net header to be 12-byte long.Mergeable buffers, as a virtio feature, is worthy of supporting: packets that are larger than one-mbuf size will be dropped in vhost worker's
handle_rxifmrg_rxbuffeature is not used, but large packets cannot be avoided and increasing mbuf's size is not economical.With this virtio feature enabled by virtio-user, packet sockets with hardcoded 10-byte virtio net header will parse mac head incorrectly in
packet_sndby taking the last two bytes of virtio net header as part of mac header.
This incorrect mac header parsing will cause packet to be dropped due to invalid ether head checking in later under-layer device packet receiving.By adding extra field
vnet_hdr_szwith utilizing holes in structpacket_sockto record currently used virtio net header size and supporting extra sockoptPACKET_VNET_HDR_SZto set specifiedvnet_hdr_sz, packet sockets can know the exact length of virtio net header that virtio user gives.
Inpacket_snd,tpacket_sndandpacket_recvmsg, instead of using hardcoded virtio net header size, it can get the exactvnet_hdr_szfrom correspondingpacket_sock, and parse mac header correctly based on this information to avoid the packets being mistakenly dropped.
Quoted 3 lines
Signed-off-by Jianfeng Tan <[email protected]>Co-developed-by Anqi Shen <[email protected]>Signed-off-by Anqi Shen <[email protected]>
Another patch set was just merged that this will have merge conflicts with. Please respin.
Quoted 31 lines · Willem de Bruijn
Quoted 30 lines · 沈安琪(凛玥)
From: Jianfeng Tan <[email protected]>
Packet sockets, like tap, can be used as the backend for kernel vhost. In packet sockets, virtio net header size is currently hardcoded to be the size of struct
virtio_net_hdr, which is 10 bytes; however, it is not always the case: some virtio features, such asmrg_rxbuf, need virtio net header to be 12-byte long.Mergeable buffers, as a virtio feature, is worthy of supporting: packets that are larger than one-mbuf size will be dropped in vhost worker's
handle_rxifmrg_rxbuffeature is not used, but large packets cannot be avoided and increasing mbuf's size is not economical.With this virtio feature enabled by virtio-user, packet sockets with hardcoded 10-byte virtio net header will parse mac head incorrectly in
packet_sndby taking the last two bytes of virtio net header as part of mac header.
This incorrect mac header parsing will cause packet to be dropped due to invalid ether head checking in later under-layer device packet receiving.By adding extra field
vnet_hdr_szwith utilizing holes in structpacket_sockto record currently used virtio net header size and supporting extra sockoptPACKET_VNET_HDR_SZto set specifiedvnet_hdr_sz, packet sockets can know the exact length of virtio net header that virtio user gives.
Inpacket_snd,tpacket_sndandpacket_recvmsg, instead of using hardcoded virtio net header size, it can get the exactvnet_hdr_szfrom correspondingpacket_sock, and parse mac header correctly based on this information to avoid the packets being mistakenly dropped.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Jianfeng Tan <[email protected]>Co-developed-by Anqi Shen <[email protected]>Signed-off-by Anqi Shen <[email protected]>Another patch set was just merged that this will have merge conflicts with. Please respin.
Sure thing. We are going to rebase it. The recently-merged patch compacted all bit flags into one long flags field and getting the bit information through the helper function.
Since our patch removes has_vnet_hdr bit and uses vnet_hdr_sz, which cannot fit in one bit, to indicate whether the packet sock has vnet header or not, we plan to remove PACKET_SOCK_HAS_VNET_HDR from packet_sock_flags and keep the u8 field vnet_hdr_sz in struct packet_sock. After modification, the packet_sock struct will be following:
@@ -119,9 +119,9 @@ struct packet_sock {
unsigned long flags;
int ifindex; /* bound device */
+ u8 vnet_hdr_sz;
__be16 num;
I wonder whether this rebase plan looks appropriate for you and am looking forward to your advice here.
If we are good on the rebasing plan, we will soon send out next version with conflicts resolved. :) Thanks a lot.
Willem de Bruijn
maintainerQuoted 62 lines · 沈安琪(凛玥)
Quoted 31 lines · Willem de Bruijn
Quoted 30 lines · 沈安琪(凛玥)
From: Jianfeng Tan <[email protected]>
Packet sockets, like tap, can be used as the backend for kernel vhost. In packet sockets, virtio net header size is currently hardcoded to be the size of struct
virtio_net_hdr, which is 10 bytes; however, it is not always the case: some virtio features, such asmrg_rxbuf, need virtio net header to be 12-byte long.Mergeable buffers, as a virtio feature, is worthy of supporting: packets that are larger than one-mbuf size will be dropped in vhost worker's
handle_rxifmrg_rxbuffeature is not used, but large packets cannot be avoided and increasing mbuf's size is not economical.With this virtio feature enabled by virtio-user, packet sockets with hardcoded 10-byte virtio net header will parse mac head incorrectly in
packet_sndby taking the last two bytes of virtio net header as part of mac header.
This incorrect mac header parsing will cause packet to be dropped due to invalid ether head checking in later under-layer device packet receiving.By adding extra field
vnet_hdr_szwith utilizing holes in structpacket_sockto record currently used virtio net header size and supporting extra sockoptPACKET_VNET_HDR_SZto set specifiedvnet_hdr_sz, packet sockets can know the exact length of virtio net header that virtio user gives.
Inpacket_snd,tpacket_sndandpacket_recvmsg, instead of using hardcoded virtio net header size, it can get the exactvnet_hdr_szfrom correspondingpacket_sock, and parse mac header correctly based on this information to avoid the packets being mistakenly dropped.Quoted 7 lines
Quoted 3 lines
Signed-off-by Jianfeng Tan <[email protected]>Co-developed-by Anqi Shen <[email protected]>Signed-off-by Anqi Shen <[email protected]>Another patch set was just merged that this will have merge conflicts with. Please respin.
Sure thing. We are going to rebase it. The recently-merged patch compacted all bit flags into one long flags field and getting the bit information through the helper function.
Since our patch removes
has_vnet_hdrbit and usesvnet_hdr_sz, which cannot fit in one bit, to indicate whether the packet sock has vnet header or not, we plan to removePACKET_SOCK_HAS_VNET_HDRfrompacket_sock_flagsand keep the u8 fieldvnet_hdr_szin structpacket_sock. After modification, thepacket_sockstruct will be following:(quoted diff) +1
-0@@ -119,9 +119,9 @@ struct packet_sock { unsigned long flags; int ifindex; /* bound device */ + u8 vnet_hdr_sz; __be16 num;I wonder whether this rebase plan looks appropriate for you and am looking forward to your advice here.
Quoted 2 lines
If we are good on the rebasing plan, we will soon send out next version with conflicts resolved. :) Thanks a lot.
Makes sense to me.