Message ID | 20230703181226.19380-18-larysa.zaremba@intel.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | XDP metadata via kfuncs for ice | expand |
On 07/03, Larysa Zaremba wrote: > In order to test VLAN tag and checksum level XDP hints in > hardware-independent selfttests, implement newly added XDP hints in veth > driver. > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com> > --- > drivers/net/veth.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > > diff --git a/drivers/net/veth.c b/drivers/net/veth.c > index 614f3e3efab0..a7f2b679551d 100644 > --- a/drivers/net/veth.c > +++ b/drivers/net/veth.c > @@ -1732,6 +1732,44 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, > return 0; > } > > +static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, u16 *vlan_tag, > + __be16 *vlan_proto) > +{ > + struct veth_xdp_buff *_ctx = (void *)ctx; > + struct sk_buff *skb = _ctx->skb; > + int err; > + > + if (!skb) > + return -ENODATA; > + [..] > + err = __vlan_hwaccel_get_tag(skb, vlan_tag); We probably need to open code __vlan_hwaccel_get_tag here. Because it returns -EINVAL on !skb_vlan_tag_present where the expectation, for us, I'm assuming is -ENODATA? > + if (err) > + return err; > + > + *vlan_proto = skb->vlan_proto; > + return err; > +} > + > +static int veth_xdp_rx_csum_lvl(const struct xdp_md *ctx, u8 *csum_level) > +{ > + struct veth_xdp_buff *_ctx = (void *)ctx; > + struct sk_buff *skb = _ctx->skb; > + > + if (!skb) > + return -ENODATA; > + > + if (skb->ip_summed == CHECKSUM_UNNECESSARY) > + *csum_level = skb->csum_level; > + else if (skb->ip_summed == CHECKSUM_PARTIAL && > + skb_checksum_start_offset(skb) == skb_transport_offset(skb) || > + skb->csum_valid) > + *csum_level = 0; > + else > + return -ENODATA; > + > + return 0; > +} > + > static const struct net_device_ops veth_netdev_ops = { > .ndo_init = veth_dev_init, > .ndo_open = veth_open, > @@ -1756,6 +1794,8 @@ static const struct net_device_ops veth_netdev_ops = { > static const struct xdp_metadata_ops veth_xdp_metadata_ops = { > .xmo_rx_timestamp = veth_xdp_rx_timestamp, > .xmo_rx_hash = veth_xdp_rx_hash, > + .xmo_rx_vlan_tag = veth_xdp_rx_vlan_tag, > + .xmo_rx_csum_lvl = veth_xdp_rx_csum_lvl, > }; > > #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ > -- > 2.41.0 >
On 05/07/2023 19.25, Stanislav Fomichev wrote: > On 07/03, Larysa Zaremba wrote: >> In order to test VLAN tag and checksum level XDP hints in >> hardware-independent selfttests, implement newly added XDP hints in veth >> driver. >> >> Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com> >> --- >> drivers/net/veth.c | 40 ++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 40 insertions(+) >> >> diff --git a/drivers/net/veth.c b/drivers/net/veth.c >> index 614f3e3efab0..a7f2b679551d 100644 >> --- a/drivers/net/veth.c >> +++ b/drivers/net/veth.c >> @@ -1732,6 +1732,44 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, >> return 0; >> } >> >> +static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, u16 *vlan_tag, >> + __be16 *vlan_proto) >> +{ >> + struct veth_xdp_buff *_ctx = (void *)ctx; >> + struct sk_buff *skb = _ctx->skb; >> + int err; >> + >> + if (!skb) >> + return -ENODATA; >> + > > [..] > >> + err = __vlan_hwaccel_get_tag(skb, vlan_tag); > > We probably need to open code __vlan_hwaccel_get_tag here. Because it > returns -EINVAL on !skb_vlan_tag_present where the expectation, for us, > I'm assuming is -ENODATA? > Looking at in-tree users of __vlan_hwaccel_get_tag(), they don't use the err value for anything. Thus, we can just change __vlan_hwaccel_get_tag() to return -ENODATA instead of -EINVAL. (And also remember __vlan_get_tag() adjustmment). $ git diff diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 6ba71957851e..fb35d7dd77a2 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -540,7 +540,7 @@ static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci) struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb); if (!eth_type_vlan(veth->h_vlan_proto)) - return -EINVAL; + return -ENODATA; *vlan_tci = ntohs(veth->h_vlan_TCI); return 0; @@ -561,7 +561,7 @@ static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb, return 0; } else { *vlan_tci = 0; - return -EINVAL; + return -ENODATA; } } >> + if (err) >> + return err; >> + >> + *vlan_proto = skb->vlan_proto; >> + return err; >> +} >> + >> +static int veth_xdp_rx_csum_lvl(const struct xdp_md *ctx, u8 *csum_level) >> +{ >> + struct veth_xdp_buff *_ctx = (void *)ctx; >> + struct sk_buff *skb = _ctx->skb; >> + >> + if (!skb) >> + return -ENODATA; >> + >> + if (skb->ip_summed == CHECKSUM_UNNECESSARY) >> + *csum_level = skb->csum_level; >> + else if (skb->ip_summed == CHECKSUM_PARTIAL && >> + skb_checksum_start_offset(skb) == skb_transport_offset(skb) || >> + skb->csum_valid) >> + *csum_level = 0; >> + else >> + return -ENODATA; >> + >> + return 0; >> +} >> + [...]
On Thu, Jul 06, 2023 at 11:57:06AM +0200, Jesper Dangaard Brouer wrote: > > On 05/07/2023 19.25, Stanislav Fomichev wrote: > > On 07/03, Larysa Zaremba wrote: > > > In order to test VLAN tag and checksum level XDP hints in > > > hardware-independent selfttests, implement newly added XDP hints in veth > > > driver. > > > > > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com> > > > --- > > > drivers/net/veth.c | 40 ++++++++++++++++++++++++++++++++++++++++ > > > 1 file changed, 40 insertions(+) > > > > > > diff --git a/drivers/net/veth.c b/drivers/net/veth.c > > > index 614f3e3efab0..a7f2b679551d 100644 > > > --- a/drivers/net/veth.c > > > +++ b/drivers/net/veth.c > > > @@ -1732,6 +1732,44 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, > > > return 0; > > > } > > > +static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, u16 *vlan_tag, > > > + __be16 *vlan_proto) > > > +{ > > > + struct veth_xdp_buff *_ctx = (void *)ctx; > > > + struct sk_buff *skb = _ctx->skb; > > > + int err; > > > + > > > + if (!skb) > > > + return -ENODATA; > > > + > > > > [..] > > > > > + err = __vlan_hwaccel_get_tag(skb, vlan_tag); > > > > We probably need to open code __vlan_hwaccel_get_tag here. Because it > > returns -EINVAL on !skb_vlan_tag_present where the expectation, for us, > > I'm assuming is -ENODATA? > > > > Looking at in-tree users of __vlan_hwaccel_get_tag(), they don't use the > err value for anything. Thus, we can just change > __vlan_hwaccel_get_tag() to return -ENODATA instead of -EINVAL. (And > also remember __vlan_get_tag() adjustmment). > Seems like a good idea, will include those changes it in v3. > > $ git diff > diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h > index 6ba71957851e..fb35d7dd77a2 100644 > --- a/include/linux/if_vlan.h > +++ b/include/linux/if_vlan.h > @@ -540,7 +540,7 @@ static inline int __vlan_get_tag(const struct sk_buff > *skb, u16 *vlan_tci) > struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb); > > if (!eth_type_vlan(veth->h_vlan_proto)) > - return -EINVAL; > + return -ENODATA; > > *vlan_tci = ntohs(veth->h_vlan_TCI); > return 0; > @@ -561,7 +561,7 @@ static inline int __vlan_hwaccel_get_tag(const struct > sk_buff *skb, > return 0; > } else { > *vlan_tci = 0; > - return -EINVAL; > + return -ENODATA; > } > } > > > > > > + if (err) > > > + return err; > > > + > > > + *vlan_proto = skb->vlan_proto; > > > + return err; > > > +} > > > + > > > +static int veth_xdp_rx_csum_lvl(const struct xdp_md *ctx, u8 *csum_level) > > > +{ > > > + struct veth_xdp_buff *_ctx = (void *)ctx; > > > + struct sk_buff *skb = _ctx->skb; > > > + > > > + if (!skb) > > > + return -ENODATA; > > > + > > > + if (skb->ip_summed == CHECKSUM_UNNECESSARY) > > > + *csum_level = skb->csum_level; > > > + else if (skb->ip_summed == CHECKSUM_PARTIAL && > > > + skb_checksum_start_offset(skb) == skb_transport_offset(skb) || > > > + skb->csum_valid) > > > + *csum_level = 0; > > > + else > > > + return -ENODATA; > > > + > > > + return 0; > > > +} > > > + > [...] >
diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 614f3e3efab0..a7f2b679551d 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1732,6 +1732,44 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, return 0; } +static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, u16 *vlan_tag, + __be16 *vlan_proto) +{ + struct veth_xdp_buff *_ctx = (void *)ctx; + struct sk_buff *skb = _ctx->skb; + int err; + + if (!skb) + return -ENODATA; + + err = __vlan_hwaccel_get_tag(skb, vlan_tag); + if (err) + return err; + + *vlan_proto = skb->vlan_proto; + return err; +} + +static int veth_xdp_rx_csum_lvl(const struct xdp_md *ctx, u8 *csum_level) +{ + struct veth_xdp_buff *_ctx = (void *)ctx; + struct sk_buff *skb = _ctx->skb; + + if (!skb) + return -ENODATA; + + if (skb->ip_summed == CHECKSUM_UNNECESSARY) + *csum_level = skb->csum_level; + else if (skb->ip_summed == CHECKSUM_PARTIAL && + skb_checksum_start_offset(skb) == skb_transport_offset(skb) || + skb->csum_valid) + *csum_level = 0; + else + return -ENODATA; + + return 0; +} + static const struct net_device_ops veth_netdev_ops = { .ndo_init = veth_dev_init, .ndo_open = veth_open, @@ -1756,6 +1794,8 @@ static const struct net_device_ops veth_netdev_ops = { static const struct xdp_metadata_ops veth_xdp_metadata_ops = { .xmo_rx_timestamp = veth_xdp_rx_timestamp, .xmo_rx_hash = veth_xdp_rx_hash, + .xmo_rx_vlan_tag = veth_xdp_rx_vlan_tag, + .xmo_rx_csum_lvl = veth_xdp_rx_csum_lvl, }; #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \
In order to test VLAN tag and checksum level XDP hints in hardware-independent selfttests, implement newly added XDP hints in veth driver. Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com> --- drivers/net/veth.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)