On Thu, Oct 22, 2020 at 5:44 PM Jakub Kicinski <k...@kernel.org> wrote: > > On Thu, 22 Oct 2020 12:59:45 -0700 Xie He wrote: > > > > But I also see some drivers that want to pad the skb to a strange > > length, and don't set their special min_mtu to match this length. For > > example: > > > > drivers/net/ethernet/packetengines/yellowfin.c wants to pad the skb to > > a dynamically calculated value. > > > > drivers/net/ethernet/ti/cpsw.c, cpsw_new.c and tlan.c want to pad the > > skb to macro defined values. > > > > drivers/net/ethernet/intel/iavf/iavf_txrx.c wants to pad the skb to > > IAVF_MIN_TX_LEN (17). > > > > drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c wants to pad the skb to > > 17. > > Hm, I see, that would be a slight loss of functionality if we started > requiring 64B, for example, while the driver could in practice xmit > 17B frames (would matter only to VFs, but nonetheless).
I think requiring the length to be at least some value won't solve the problem for all drivers. For example: drivers/net/ethernet/packetengines/yellowfin.c pads the skb to 32-byte boundaries in the memory (no matter how long the length is). drivers/net/ethernet/adaptec/starfire.c pads the skb so that the length is multiples of 4. drivers/net/ethernet/sun/cassini.c pads the skb to cp->min_frame_size, which may be 255, 60, or 97. > > Another solution I can think of is to add a "skb_shared" check to > > "__skb_pad", so that if __skb_pad encounters a shared skb, it just > > returns an error. The driver would think this is a memory allocation > > failure. This way we can ensure shared skbs are not modified. > > I'm not sure if we want to be adding checks to __skb_pad() to handle > what's effectively a pktgen specific condition. > > We could create a new field in struct netdevice for min_frame_len, but I > think your patch is the simplest solution. Let's see if anyone objects. > > BTW it seems like there is more drivers which will need the flag > cleared, e.g. drivers/net/ethernet/broadcom/bnxt/bnxt.c? My patch isn't complete. Because there are so many drivers with this problem, I feel it's hard to solve them all at once. So I only grepped "skb_padto" under "drivers/net/ethernet". There are other drivers under "ethernet" using "skb_pad", "skb_put_padto" or "eth_skb_pad". There are also (fake) Ethernet drivers under "drivers/net/wireless". I feel it'd take a long time and also be error-prone to solve them all, so I feel it'd be the best if there are other solutions.