Skip to content

Commit 915efd8

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
xdp: bpf_xdp_metadata use EOPNOTSUPP for no driver support
When driver doesn't implement a bpf_xdp_metadata kfunc the fallback implementation returns EOPNOTSUPP, which indicate device driver doesn't implement this kfunc. Currently many drivers also return EOPNOTSUPP when the hint isn't available, which is ambiguous from an API point of view. Instead change drivers to return ENODATA in these cases. There can be natural cases why a driver doesn't provide any hardware info for a specific hint, even on a frame to frame basis (e.g. PTP). Lets keep these cases as separate return codes. When describing the return values, adjust the function kernel-doc layout to get proper rendering for the return values. Fixes: ab46182 ("net/mlx4_en: Support RX XDP metadata") Fixes: bc8d405 ("net/mlx5e: Support RX XDP metadata") Fixes: 306531f ("veth: Support RX XDP metadata") Fixes: 3d76a4d ("bpf: XDP metadata RX kfuncs") Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Acked-by: Tariq Toukan <[email protected]> Link: https://lore.kernel.org/r/167940675120.2718408.8176058626864184420.stgit@firesoul Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 10ec8ca commit 915efd8

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

Documentation/networking/xdp-rx-metadata.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ metadata is supported, this set will grow:
2323
An XDP program can use these kfuncs to read the metadata into stack
2424
variables for its own consumption. Or, to pass the metadata on to other
2525
consumers, an XDP program can store it into the metadata area carried
26-
ahead of the packet.
26+
ahead of the packet. Not all packets will necessary have the requested
27+
metadata available in which case the driver returns ``-ENODATA``.
2728

2829
Not all kfuncs have to be implemented by the device driver; when not
29-
implemented, the default ones that return ``-EOPNOTSUPP`` will be used.
30+
implemented, the default ones that return ``-EOPNOTSUPP`` will be used
31+
to indicate the device driver have not implemented this kfunc.
32+
3033

3134
Within an XDP frame, the metadata layout (accessed via ``xdp_buff``) is
3235
as follows::

drivers/net/ethernet/mellanox/mlx4/en_rx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
674674
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
675675

676676
if (unlikely(_ctx->ring->hwtstamp_rx_filter != HWTSTAMP_FILTER_ALL))
677-
return -EOPNOTSUPP;
677+
return -ENODATA;
678678

679679
*timestamp = mlx4_en_get_hwtstamp(_ctx->mdev,
680680
mlx4_en_get_cqe_ts(_ctx->cqe));
@@ -686,7 +686,7 @@ int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
686686
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
687687

688688
if (unlikely(!(_ctx->dev->features & NETIF_F_RXHASH)))
689-
return -EOPNOTSUPP;
689+
return -ENODATA;
690690

691691
*hash = be32_to_cpu(_ctx->cqe->immed_rss_invalid);
692692
return 0;

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
162162
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
163163

164164
if (unlikely(!mlx5e_rx_hw_stamp(_ctx->rq->tstamp)))
165-
return -EOPNOTSUPP;
165+
return -ENODATA;
166166

167167
*timestamp = mlx5e_cqe_ts_to_ns(_ctx->rq->ptp_cyc2time,
168168
_ctx->rq->clock, get_cqe_ts(_ctx->cqe));
@@ -174,7 +174,7 @@ static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
174174
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
175175

176176
if (unlikely(!(_ctx->xdp.rxq->dev->features & NETIF_F_RXHASH)))
177-
return -EOPNOTSUPP;
177+
return -ENODATA;
178178

179179
*hash = be32_to_cpu(_ctx->cqe->rss_hash_result);
180180
return 0;

drivers/net/veth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ static int veth_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
16101610
struct veth_xdp_buff *_ctx = (void *)ctx;
16111611

16121612
if (!_ctx->skb)
1613-
return -EOPNOTSUPP;
1613+
return -ENODATA;
16141614

16151615
*timestamp = skb_hwtstamps(_ctx->skb)->hwtstamp;
16161616
return 0;
@@ -1621,7 +1621,7 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
16211621
struct veth_xdp_buff *_ctx = (void *)ctx;
16221622

16231623
if (!_ctx->skb)
1624-
return -EOPNOTSUPP;
1624+
return -ENODATA;
16251625

16261626
*hash = skb_get_hash(_ctx->skb);
16271627
return 0;

net/core/xdp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,10 @@ __diag_ignore_all("-Wmissing-prototypes",
720720
* @ctx: XDP context pointer.
721721
* @timestamp: Return value pointer.
722722
*
723-
* Returns 0 on success or ``-errno`` on error.
723+
* Return:
724+
* * Returns 0 on success or ``-errno`` on error.
725+
* * ``-EOPNOTSUPP`` : means device driver does not implement kfunc
726+
* * ``-ENODATA`` : means no RX-timestamp available for this frame
724727
*/
725728
__bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
726729
{
@@ -732,7 +735,10 @@ __bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *tim
732735
* @ctx: XDP context pointer.
733736
* @hash: Return value pointer.
734737
*
735-
* Returns 0 on success or ``-errno`` on error.
738+
* Return:
739+
* * Returns 0 on success or ``-errno`` on error.
740+
* * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
741+
* * ``-ENODATA`` : means no RX-hash available for this frame
736742
*/
737743
__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash)
738744
{

0 commit comments

Comments
 (0)