Skip to content

Commit c3c16f2

Browse files
anambiarinAlexei Starovoitov
authored andcommitted
bpf: Add rx_queue_mapping to bpf_sock
Add "rx_queue_mapping" to bpf_sock. This gives read access for the existing field (sk_rx_queue_mapping) of struct sock from bpf_sock. Semantics for the bpf_sock rx_queue_mapping access are similar to sk_rx_queue_get(), i.e the value NO_QUEUE_MAPPING is not allowed and -1 is returned in that case. This is useful for transmit queue selection based on the received queue index which is cached in the socket in the receive path. v3: Addressed review comments to add usecase in patch description, and fixed default value for rx_queue_mapping. v2: fixed build error for CONFIG_XPS wrapping, reported by kbuild test robot <[email protected]> Signed-off-by: Amritha Nambiar <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e255d32 commit c3c16f2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,7 @@ struct bpf_sock {
36123612
__u32 dst_ip4;
36133613
__u32 dst_ip6[4];
36143614
__u32 state;
3615+
__s32 rx_queue_mapping;
36153616
};
36163617

36173618
struct bpf_tcp_sock {

net/core/filter.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6849,6 +6849,7 @@ bool bpf_sock_is_valid_access(int off, int size, enum bpf_access_type type,
68496849
case offsetof(struct bpf_sock, protocol):
68506850
case offsetof(struct bpf_sock, dst_port):
68516851
case offsetof(struct bpf_sock, src_port):
6852+
case offsetof(struct bpf_sock, rx_queue_mapping):
68526853
case bpf_ctx_range(struct bpf_sock, src_ip4):
68536854
case bpf_ctx_range_till(struct bpf_sock, src_ip6[0], src_ip6[3]):
68546855
case bpf_ctx_range(struct bpf_sock, dst_ip4):
@@ -7897,6 +7898,23 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_type type,
78977898
skc_state),
78987899
target_size));
78997900
break;
7901+
case offsetof(struct bpf_sock, rx_queue_mapping):
7902+
#ifdef CONFIG_XPS
7903+
*insn++ = BPF_LDX_MEM(
7904+
BPF_FIELD_SIZEOF(struct sock, sk_rx_queue_mapping),
7905+
si->dst_reg, si->src_reg,
7906+
bpf_target_off(struct sock, sk_rx_queue_mapping,
7907+
sizeof_field(struct sock,
7908+
sk_rx_queue_mapping),
7909+
target_size));
7910+
*insn++ = BPF_JMP_IMM(BPF_JNE, si->dst_reg, NO_QUEUE_MAPPING,
7911+
1);
7912+
*insn++ = BPF_MOV64_IMM(si->dst_reg, -1);
7913+
#else
7914+
*insn++ = BPF_MOV64_IMM(si->dst_reg, -1);
7915+
*target_size = 2;
7916+
#endif
7917+
break;
79007918
}
79017919

79027920
return insn - insn_buf;

0 commit comments

Comments
 (0)