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
533 * be copied.533 * be copied.
534 */534 */
535#define SK_USER_DATA_NOCOPY 1UL535#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)
537 538
538/**539/**
539 * sk_user_data_is_nocopy - Test if sk_user_data pointer must not be copied540 * 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
20/* The caller must hold the reuseport_lock */20/* The caller must hold the reuseport_lock */
21void bpf_sk_reuseport_detach(struct sock *sk)21void bpf_sk_reuseport_detach(struct sock *sk)
22{22{
23 struct sock __rcu **socks;23 uintptr_t sk_user_data;
24 24
25 write_lock_bh(&sk->sk_callback_lock);25 write_lock_bh(&sk->sk_callback_lock);
26 socks = sk->sk_user_data;26 sk_user_data = (uintptr_t)sk->sk_user_data;
27 if (socks) {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);
28 WRITE_ONCE(sk->sk_user_data, NULL);31 WRITE_ONCE(sk->sk_user_data, NULL);
29 /*32 /*
30 * Do not move this NULL assignment outside of33 * 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
252 struct sock *free_osk = NULL, *osk, *nsk;255 struct sock *free_osk = NULL, *osk, *nsk;
253 struct sock_reuseport *reuse;256 struct sock_reuseport *reuse;
254 u32 index = *(u32 *)key;257 u32 index = *(u32 *)key;
258 uintptr_t sk_user_data;
255 struct socket *socket;259 struct socket *socket;
256 int err, fd;260 int err, fd;
257 261
@@ -305,7 +309,9 @@ int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, void *key, · 47 unmodified lines
305 if (err)309 if (err)
306 goto put_file_unlock;310 goto put_file_unlock;
307 311
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);
309 rcu_assign_pointer(array->ptrs[index], nsk);315 rcu_assign_pointer(array->ptrs[index], nsk);
310 free_osk = osk;316 free_osk = osk;
311 err = 0;317 err = 0;
tools/lib/bpf/hashmap.h+8−4
@@ -11,14 +11,18 @@ · 10 unmodified lines
11#include <stdbool.h>11#include <stdbool.h>
12#include <stddef.h>12#include <stddef.h>
13#include <limits.h>13#include <limits.h>
14#ifndef __WORDSIZE
15#define __WORDSIZE (__SIZEOF_LONG__ * 8)
16#endif
17 14
18static inline size_t hash_bits(size_t h, int bits)15static inline size_t hash_bits(size_t h, int bits)
19{16{
20 /* shuffle bits and return requested number of upper bits */17 /* 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
22}26}
23 27
24typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);28typedef 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
789 }789 }
790 790
791 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER);791 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER);
792 if (err) {792 if (!err) {
793 printf("Failed empty parser prog detach\n");793 printf("Failed empty parser prog detach\n");
794 goto out_sockmap;794 goto out_sockmap;
795 }795 }
796 796
797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT);797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT);
798 if (err) {798 if (!err) {
799 printf("Failed empty verdict prog detach\n");799 printf("Failed empty verdict prog detach\n");
800 goto out_sockmap;800 goto out_sockmap;
801 }801 }
802 802
803 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);803 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);
804 if (err) {804 if (!err) {
805 printf("Failed empty msg verdict prog detach\n");805 printf("Failed empty msg verdict prog detach\n");
806 goto out_sockmap;806 goto out_sockmap;
807 }807 }
@@ -1090,19 +1090,19 @@ static void test_sockmap(unsigned int tasks, void *data) · 282 unmodified lines
1090 assert(status == 0);1090 assert(status == 0);
1091 }1091 }
1092 1092
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);
1094 if (!err) {1094 if (!err) {
1095 printf("Detached an invalid prog type.\n");1095 printf("Detached an invalid prog type.\n");
1096 goto out_sockmap;1096 goto out_sockmap;
1097 }1097 }
1098 1098
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);
1100 if (err) {1100 if (err) {
1101 printf("Failed parser prog detach\n");1101 printf("Failed parser prog detach\n");
1102 goto out_sockmap;1102 goto out_sockmap;
1103 }1103 }
1104 1104
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);
1106 if (err) {1106 if (err) {
1107 printf("Failed parser prog detach\n");1107 printf("Failed parser prog detach\n");
1108 goto out_sockmap;1108 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