History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Alexei Starovoitov says: ==================== pull-request: bpf 2020-07-09 The following pull-request contains BPF updates for your *net* tree. We've added 4 non-merge commits during the last 1 day(s) which contain a total of 4 files changed, 26 insertions(+), 15 deletions(-). The main changes are: 1) fix crash in libbpf on 32-bit archs, from Jakub and Andrii. 2) fix crash when l2tp and bpf_sk_reuseport conflict, from Martin. ====================

David S. Miller committed 6 years ago

Commit 45ae8362 parents ca68d56 b2f9f154 files · +26 −15Browse files

Unified · Split

4 files
  1. include/net/sock.h +2 −1
  2. kernel/bpf/reuseport_array.c +10 −4
  3. tools/lib/bpf/hashmap.h +8 −4
  4. tools/testing/selftests/bpf/test_maps.c +6 −6
include/net/sock.h+2−1
@@ -533,7 +533,8 @@ enum sk_pacing { · 532 unmodified lines
533533 * be copied.
534534 */
535535 #define SK_USER_DATA_NOCOPY 1UL
536−#define SK_USER_DATA_PTRMASK ~(SK_USER_DATA_NOCOPY)
536+#define SK_USER_DATA_BPF 2UL /* Managed by BPF */
537+#define SK_USER_DATA_PTRMASK ~(SK_USER_DATA_NOCOPY | SK_USER_DATA_BPF)
537538
538539 /**
539540 * sk_user_data_is_nocopy - Test if sk_user_data pointer must not be copied
kernel/bpf/reuseport_array.c+10−4
@@ -20,11 +20,14 @@ static struct reuseport_array *reuseport_array(struct bpf_map *map) · 19 unmodified lines
2020 /* The caller must hold the reuseport_lock */
2121 void bpf_sk_reuseport_detach(struct sock *sk)
2222 {
23− struct sock __rcu **socks;
23+ uintptr_t sk_user_data;
2424
2525 write_lock_bh(&sk->sk_callback_lock);
26− socks = sk->sk_user_data;
27− if (socks) {
26+ sk_user_data = (uintptr_t)sk->sk_user_data;
27+ if (sk_user_data & SK_USER_DATA_BPF) {
28+ struct sock __rcu **socks;
29+
30+ socks = (void *)(sk_user_data & SK_USER_DATA_PTRMASK);
2831 WRITE_ONCE(sk->sk_user_data, NULL);
2932 /*
3033 * Do not move this NULL assignment outside of
@@ -252,6 +255,7 @@ int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, void *key, · 221 unmodified lines
252255 struct sock *free_osk = NULL, *osk, *nsk;
253256 struct sock_reuseport *reuse;
254257 u32 index = *(u32 *)key;
258+ uintptr_t sk_user_data;
255259 struct socket *socket;
256260 int err, fd;
257261
@@ -305,7 +309,9 @@ int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, void *key, · 47 unmodified lines
305309 if (err)
306310 goto put_file_unlock;
307311
308− WRITE_ONCE(nsk->sk_user_data, &array->ptrs[index]);
312+ sk_user_data = (uintptr_t)&array->ptrs[index] | SK_USER_DATA_NOCOPY |
313+ SK_USER_DATA_BPF;
314+ WRITE_ONCE(nsk->sk_user_data, (void *)sk_user_data);
309315 rcu_assign_pointer(array->ptrs[index], nsk);
310316 free_osk = osk;
311317 err = 0;
tools/lib/bpf/hashmap.h+8−4
@@ -11,14 +11,18 @@ · 10 unmodified lines
1111 #include <stdbool.h>
1212 #include <stddef.h>
1313 #include <limits.h>
14−#ifndef __WORDSIZE
15−#define __WORDSIZE (__SIZEOF_LONG__ * 8)
16−#endif
1714
1815 static inline size_t hash_bits(size_t h, int bits)
1916 {
2017 /* shuffle bits and return requested number of upper bits */
21− return (h * 11400714819323198485llu) >> (__WORDSIZE - bits);
18+#if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
19+ /* LP64 case */
20+ return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
21+#elif (__SIZEOF_SIZE_T__ <= __SIZEOF_LONG__)
22+ return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits);
23+#else
24+# error "Unsupported size_t size"
25+#endif
2226 }
2327
2428 typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);
tools/testing/selftests/bpf/test_maps.c+6−6
@@ -789,19 +789,19 @@ static void test_sockmap(unsigned int tasks, void *data) · 788 unmodified lines
789789 }
790790
791791 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER);
792− if (err) {
792+ if (!err) {
793793 printf("Failed empty parser prog detach\n");
794794 goto out_sockmap;
795795 }
796796
797797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT);
798− if (err) {
798+ if (!err) {
799799 printf("Failed empty verdict prog detach\n");
800800 goto out_sockmap;
801801 }
802802
803803 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);
804− if (err) {
804+ if (!err) {
805805 printf("Failed empty msg verdict prog detach\n");
806806 goto out_sockmap;
807807 }
@@ -1090,19 +1090,19 @@ static void test_sockmap(unsigned int tasks, void *data) · 282 unmodified lines
10901090 assert(status == 0);
10911091 }
10921092
1093− err = bpf_prog_detach(map_fd_rx, __MAX_BPF_ATTACH_TYPE);
1093+ err = bpf_prog_detach2(parse_prog, map_fd_rx, __MAX_BPF_ATTACH_TYPE);
10941094 if (!err) {
10951095 printf("Detached an invalid prog type.\n");
10961096 goto out_sockmap;
10971097 }
10981098
1099− err = bpf_prog_detach(map_fd_rx, BPF_SK_SKB_STREAM_PARSER);
1099+ err = bpf_prog_detach2(parse_prog, map_fd_rx, BPF_SK_SKB_STREAM_PARSER);
11001100 if (err) {
11011101 printf("Failed parser prog detach\n");
11021102 goto out_sockmap;
11031103 }
11041104
1105− err = bpf_prog_detach(map_fd_rx, BPF_SK_SKB_STREAM_VERDICT);
1105+ err = bpf_prog_detach2(verdict_prog, map_fd_rx, BPF_SK_SKB_STREAM_VERDICT);
11061106 if (err) {
11071107 printf("Failed parser prog detach\n");
11081108 goto out_sockmap;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t