Skip to content

Commit 13ce2da

Browse files
mfijalkoAlexei Starovoitov
authored andcommitted
xsk: add new netlink attribute dedicated for ZC max frags
Introduce new netlink attribute NETDEV_A_DEV_XDP_ZC_MAX_SEGS that will carry maximum fragments that underlying ZC driver is able to handle on TX side. It is going to be included in netlink response only when driver supports ZC. Any value higher than 1 implies multi-buffer ZC support on underlying device. Signed-off-by: Maciej Fijalkowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 07428da commit 13ce2da

File tree

8 files changed

+25
-1
lines changed

8 files changed

+25
-1
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ attribute-sets:
6262
type: u64
6363
enum: xdp-act
6464
enum-as-flags: true
65+
-
66+
name: xdp_zc_max_segs
67+
doc: max fragment count supported by ZC driver
68+
type: u32
69+
checks:
70+
min: 1
6571

6672
operations:
6773
list:

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,7 @@ struct net_device {
22502250
#define GRO_MAX_SIZE (8 * 65535u)
22512251
unsigned int gro_max_size;
22522252
unsigned int gro_ipv4_max_size;
2253+
unsigned int xdp_zc_max_segs;
22532254
rx_handler_func_t __rcu *rx_handler;
22542255
void __rcu *rx_handler_data;
22552256

include/uapi/linux/netdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum {
4141
NETDEV_A_DEV_IFINDEX = 1,
4242
NETDEV_A_DEV_PAD,
4343
NETDEV_A_DEV_XDP_FEATURES,
44+
NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
4445

4546
__NETDEV_A_DEV_MAX,
4647
NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1)

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10613,6 +10613,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1061310613
dev_net_set(dev, &init_net);
1061410614

1061510615
dev->gso_max_size = GSO_LEGACY_MAX_SIZE;
10616+
dev->xdp_zc_max_segs = 1;
1061610617
dev->gso_max_segs = GSO_MAX_SEGS;
1061710618
dev->gro_max_size = GRO_LEGACY_MAX_SIZE;
1061810619
dev->gso_ipv4_max_size = GSO_LEGACY_MAX_SIZE;

net/core/netdev-genl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,
2525
return -EINVAL;
2626
}
2727

28+
if (netdev->xdp_features & NETDEV_XDP_ACT_XSK_ZEROCOPY) {
29+
if (nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
30+
netdev->xdp_zc_max_segs)) {
31+
genlmsg_cancel(rsp, hdr);
32+
return -EINVAL;
33+
}
34+
}
35+
2836
genlmsg_end(rsp, hdr);
2937

3038
return 0;

tools/include/uapi/linux/netdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum {
4141
NETDEV_A_DEV_IFINDEX = 1,
4242
NETDEV_A_DEV_PAD,
4343
NETDEV_A_DEV_XDP_FEATURES,
44+
NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
4445

4546
__NETDEV_A_DEV_MAX,
4647
NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1)

tools/lib/bpf/libbpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,10 @@ struct bpf_xdp_query_opts {
11051105
__u32 skb_prog_id; /* output */
11061106
__u8 attach_mode; /* output */
11071107
__u64 feature_flags; /* output */
1108+
__u32 xdp_zc_max_segs; /* output */
11081109
size_t :0;
11091110
};
1110-
#define bpf_xdp_query_opts__last_field feature_flags
1111+
#define bpf_xdp_query_opts__last_field xdp_zc_max_segs
11111112

11121113
LIBBPF_API int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags,
11131114
const struct bpf_xdp_attach_opts *opts);

tools/lib/bpf/netlink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct xdp_id_md {
4545

4646
struct xdp_features_md {
4747
int ifindex;
48+
__u32 xdp_zc_max_segs;
4849
__u64 flags;
4950
};
5051

@@ -421,6 +422,9 @@ static int parse_xdp_features(struct nlmsghdr *nh, libbpf_dump_nlmsg_t fn,
421422
return NL_CONT;
422423

423424
md->flags = libbpf_nla_getattr_u64(tb[NETDEV_A_DEV_XDP_FEATURES]);
425+
if (tb[NETDEV_A_DEV_XDP_ZC_MAX_SEGS])
426+
md->xdp_zc_max_segs =
427+
libbpf_nla_getattr_u32(tb[NETDEV_A_DEV_XDP_ZC_MAX_SEGS]);
424428
return NL_DONE;
425429
}
426430

@@ -493,6 +497,7 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
493497
return libbpf_err(err);
494498

495499
opts->feature_flags = md.flags;
500+
opts->xdp_zc_max_segs = md.xdp_zc_max_segs;
496501

497502
skip_feature_flags:
498503
return 0;

0 commit comments

Comments
 (0)