Martin KaFai Lau
24426654ed
bpf: net: Avoid sk_setsockopt() taking sk lock when called from bpf
...
Most of the code in bpf_setsockopt(SOL_SOCKET) are duplicated from
the sk_setsockopt(). The number of supported optnames are
increasing ever and so as the duplicated code.
One issue in reusing sk_setsockopt() is that the bpf prog
has already acquired the sk lock. This patch adds a
has_current_bpf_ctx() to tell if the sk_setsockopt() is called from
a bpf prog. The bpf prog calling bpf_setsockopt() is either running
in_task() or in_serving_softirq(). Both cases have the current->bpf_ctx
initialized. Thus, the has_current_bpf_ctx() only needs to
test !!current->bpf_ctx.
This patch also adds sockopt_{lock,release}_sock() helpers
for sk_setsockopt() to use. These helpers will test
has_current_bpf_ctx() before acquiring/releasing the lock. They are
in EXPORT_SYMBOL for the ipv6 module to use in a latter patch.
Note on the change in sock_setbindtodevice(). sockopt_lock_sock()
is done in sock_setbindtodevice() instead of doing the lock_sock
in sock_bindtoindex(..., lock_sk = true).
Reviewed-by: Stanislav Fomichev <sdf@google.com >
Signed-off-by: Martin KaFai Lau <kafai@fb.com >
Link: https://lore.kernel.org/r/20220817061717.4175589-1-kafai@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org >
2022-08-18 17:06:12 -07:00
..
2022-07-28 11:44:30 +02:00
2022-08-03 14:05:39 +02:00
2022-08-04 19:30:35 -07:00
2022-07-28 11:29:36 +02:00
2022-08-10 11:01:44 -07:00
2022-08-04 18:34:05 -07:00
2022-07-25 09:42:24 +01:00
2022-08-04 10:28:48 -04:00
2022-08-02 15:06:57 -05:00
2022-07-28 11:29:36 +02:00
2022-08-06 10:25:16 -07:00
2022-08-04 19:54:32 -07:00
2022-07-26 16:58:31 +02:00
2022-08-01 21:31:22 +02:00
2022-08-07 09:53:58 -07:00
2022-07-28 00:01:30 +01:00
2022-08-05 16:32:45 -07:00
2022-08-04 12:12:54 -07:00
2022-08-06 10:19:51 -07:00
2022-08-10 14:04:32 -07:00
2022-08-04 12:12:54 -07:00
2022-08-11 13:26:09 -07:00
2022-07-28 11:29:36 +02:00
2022-07-29 18:12:35 -07:00
2022-07-29 18:07:15 -07:00
2022-08-02 12:34:03 -04:00
2022-08-02 17:14:47 -06:00
2022-08-07 17:52:35 -07:00
2022-08-04 20:00:14 -07:00
2022-08-18 17:06:12 -07:00
2022-08-04 16:57:43 -07:00
2022-08-17 11:49:23 +01:00
2022-07-22 09:07:07 -07:00
2022-08-10 09:22:18 -07:00
2022-08-09 15:03:02 -07:00
2022-08-03 09:45:08 -07:00
2022-08-02 12:19:18 -07:00
2022-08-01 12:48:15 -07:00
2022-08-07 17:52:35 -07:00
2022-08-11 12:41:07 -07:00
2022-07-28 17:36:30 -04:00
2022-07-28 17:46:14 -04:00
2022-08-08 15:16:29 -07:00
2022-07-26 07:27:48 -04:00
2022-08-03 14:41:36 -07:00
2022-08-09 09:52:28 -07:00
2022-08-02 19:24:24 -07:00
2022-08-03 00:54:11 +02:00
2022-07-22 22:04:30 +02:00
2022-08-07 17:52:35 -07:00
2022-07-25 17:45:40 +02:00
2022-08-08 18:06:46 -07:00
2022-07-28 11:29:36 +02:00
2022-08-05 16:32:45 -07:00
2022-08-08 18:06:44 -07:00
2022-07-22 16:06:03 -05:00
2022-07-26 23:13:36 +02:00
2022-07-22 14:28:22 +02:00
2022-07-28 11:29:36 +02:00
2022-07-28 11:29:36 +02:00
2022-07-28 11:29:36 +02:00
2022-07-28 11:29:36 +02:00
2022-07-27 08:50:50 -06:00
2022-08-11 13:11:49 -07:00
2022-07-21 17:19:25 -07:00
2022-07-20 15:26:05 +01:00
2022-07-22 17:24:47 -05:00
2022-08-04 20:13:46 -07:00
2022-08-01 03:21:00 -04:00
2022-08-01 03:21:00 -04:00
2022-07-22 12:53:22 +01:00
2022-07-26 12:23:01 -07:00
2022-08-02 23:56:25 -04:00
2022-08-05 16:32:45 -07:00
2022-07-27 14:04:52 +02:00
2022-08-08 18:06:44 -07:00
2022-08-03 00:54:12 +02:00
2022-07-29 18:07:19 -07:00
2022-08-02 12:34:04 -04:00
2022-08-07 10:03:24 -07:00
2022-08-03 10:35:43 -07:00
2022-08-08 16:25:56 -04:00
2022-08-09 14:11:34 -04:00
2022-07-29 20:16:58 -04:00
2022-07-23 15:28:59 -04:00
2022-07-28 11:29:36 +02:00
2022-07-27 21:35:32 +10:00
2022-08-01 08:13:21 -07:00
2022-08-02 17:14:49 -06:00
2022-08-02 17:14:47 -06:00
2022-08-02 19:24:24 -07:00
2022-08-04 18:08:34 -07:00
2022-07-21 10:39:42 +02:00
2022-08-08 18:06:43 -07:00
2022-08-05 16:32:45 -07:00
2022-08-05 16:32:45 -07:00
2022-08-10 11:07:26 -07:00
2022-07-19 15:38:04 -07:00
2022-07-26 07:28:08 -04:00
2022-07-29 12:08:44 -05:00
2022-07-28 11:29:36 +02:00
2022-08-08 22:37:19 -04:00
2022-07-28 11:29:36 +02:00
2022-07-26 09:49:12 -07:00
2022-07-28 11:29:36 +02:00
2022-07-28 11:29:36 +02:00
2022-07-28 11:29:36 +02:00
2022-07-25 13:26:14 +02:00
2022-07-21 17:46:18 -07:00
2022-07-21 17:46:18 -07:00
2022-07-21 17:46:18 -07:00
2022-07-30 14:01:28 -04:00
2022-07-26 07:27:47 -04:00
2022-08-06 17:34:06 -07:00
2022-08-02 11:17:00 -07:00
2022-08-02 15:12:13 -07:00
2022-07-28 11:29:36 +02:00
2022-08-08 11:31:40 -07:00
2022-07-29 18:07:15 -07:00
2022-07-22 16:55:44 -07:00
2022-08-10 21:47:58 -07:00
2022-08-03 16:29:08 -07:00
2022-08-17 20:40:52 -07:00
2022-07-28 11:29:36 +02:00
2022-08-05 16:32:45 -07:00
2022-08-08 18:06:44 -07:00
2022-08-08 18:06:43 -07:00
2022-07-19 15:38:04 -07:00
2022-07-28 17:29:56 +02:00
2022-08-03 23:56:20 +03:00
2022-08-05 09:41:12 -07:00
2022-08-08 22:37:24 -04:00
2022-08-06 08:59:35 -07:00
2022-07-25 13:41:22 -06:00
2022-08-01 07:42:49 +02:00
2022-07-28 12:35:12 +02:00
2022-08-02 13:46:35 -07:00