mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-01 11:21:51 +00:00
xdp: Add xdp_txq_info to xdp_buff
Add xdp_txq_info as the Tx counterpart to xdp_rxq_info. At the moment only the device is added. Other fields (queue_index) can be added as use cases arise. >From a UAPI perspective, add egress_ifindex to xdp context for bpf programs to see the Tx device. Update the verifier to only allow accesses to egress_ifindex by XDP programs with BPF_XDP_DEVMAP expected attach type. Signed-off-by: David Ahern <dsahern@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://lore.kernel.org/bpf/20200529220716.75383-4-dsahern@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
fbee97feed
commit
64b59025c1
5 changed files with 29 additions and 0 deletions
|
@ -61,12 +61,17 @@ struct xdp_rxq_info {
|
||||||
struct xdp_mem_info mem;
|
struct xdp_mem_info mem;
|
||||||
} ____cacheline_aligned; /* perf critical, avoid false-sharing */
|
} ____cacheline_aligned; /* perf critical, avoid false-sharing */
|
||||||
|
|
||||||
|
struct xdp_txq_info {
|
||||||
|
struct net_device *dev;
|
||||||
|
};
|
||||||
|
|
||||||
struct xdp_buff {
|
struct xdp_buff {
|
||||||
void *data;
|
void *data;
|
||||||
void *data_end;
|
void *data_end;
|
||||||
void *data_meta;
|
void *data_meta;
|
||||||
void *data_hard_start;
|
void *data_hard_start;
|
||||||
struct xdp_rxq_info *rxq;
|
struct xdp_rxq_info *rxq;
|
||||||
|
struct xdp_txq_info *txq;
|
||||||
u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
|
u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3707,6 +3707,8 @@ struct xdp_md {
|
||||||
/* Below access go through struct xdp_rxq_info */
|
/* Below access go through struct xdp_rxq_info */
|
||||||
__u32 ingress_ifindex; /* rxq->dev->ifindex */
|
__u32 ingress_ifindex; /* rxq->dev->ifindex */
|
||||||
__u32 rx_queue_index; /* rxq->queue_index */
|
__u32 rx_queue_index; /* rxq->queue_index */
|
||||||
|
|
||||||
|
__u32 egress_ifindex; /* txq->dev->ifindex */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum sk_action {
|
enum sk_action {
|
||||||
|
|
|
@ -476,8 +476,11 @@ static struct xdp_buff *dev_map_run_prog(struct net_device *dev,
|
||||||
struct xdp_buff *xdp,
|
struct xdp_buff *xdp,
|
||||||
struct bpf_prog *xdp_prog)
|
struct bpf_prog *xdp_prog)
|
||||||
{
|
{
|
||||||
|
struct xdp_txq_info txq = { .dev = dev };
|
||||||
u32 act;
|
u32 act;
|
||||||
|
|
||||||
|
xdp->txq = &txq;
|
||||||
|
|
||||||
act = bpf_prog_run_xdp(xdp_prog, xdp);
|
act = bpf_prog_run_xdp(xdp_prog, xdp);
|
||||||
switch (act) {
|
switch (act) {
|
||||||
case XDP_PASS:
|
case XDP_PASS:
|
||||||
|
|
|
@ -7015,6 +7015,13 @@ static bool xdp_is_valid_access(int off, int size,
|
||||||
const struct bpf_prog *prog,
|
const struct bpf_prog *prog,
|
||||||
struct bpf_insn_access_aux *info)
|
struct bpf_insn_access_aux *info)
|
||||||
{
|
{
|
||||||
|
if (prog->expected_attach_type != BPF_XDP_DEVMAP) {
|
||||||
|
switch (off) {
|
||||||
|
case offsetof(struct xdp_md, egress_ifindex):
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type == BPF_WRITE) {
|
if (type == BPF_WRITE) {
|
||||||
if (bpf_prog_is_dev_bound(prog->aux)) {
|
if (bpf_prog_is_dev_bound(prog->aux)) {
|
||||||
switch (off) {
|
switch (off) {
|
||||||
|
@ -7985,6 +7992,16 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type,
|
||||||
offsetof(struct xdp_rxq_info,
|
offsetof(struct xdp_rxq_info,
|
||||||
queue_index));
|
queue_index));
|
||||||
break;
|
break;
|
||||||
|
case offsetof(struct xdp_md, egress_ifindex):
|
||||||
|
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_buff, txq),
|
||||||
|
si->dst_reg, si->src_reg,
|
||||||
|
offsetof(struct xdp_buff, txq));
|
||||||
|
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_txq_info, dev),
|
||||||
|
si->dst_reg, si->dst_reg,
|
||||||
|
offsetof(struct xdp_txq_info, dev));
|
||||||
|
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
|
||||||
|
offsetof(struct net_device, ifindex));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return insn - insn_buf;
|
return insn - insn_buf;
|
||||||
|
|
|
@ -3706,6 +3706,8 @@ struct xdp_md {
|
||||||
/* Below access go through struct xdp_rxq_info */
|
/* Below access go through struct xdp_rxq_info */
|
||||||
__u32 ingress_ifindex; /* rxq->dev->ifindex */
|
__u32 ingress_ifindex; /* rxq->dev->ifindex */
|
||||||
__u32 rx_queue_index; /* rxq->queue_index */
|
__u32 rx_queue_index; /* rxq->queue_index */
|
||||||
|
|
||||||
|
__u32 egress_ifindex; /* txq->dev->ifindex */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum sk_action {
|
enum sk_action {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue