Thread (22 messages) read the whole thread 22 messages, 2 authors, 2025-09-04

Re: [PATCH v4 bpf-next/net 3/5] bpf: Introduce SK_BPF_MEMCG_FLAGS and SK_BPF_MEMCG_SOCK_ISOLATED.

From: Martin KaFai Lau <martin.lau@linux.dev>
Date: 2025-09-02 20:02:14
Also in: bpf

On 8/28/25 6:00 PM, Kuniyuki Iwashima wrote:
quoted hunk ↗ jump to hunk
  static int sol_socket_sockopt(struct sock *sk, int optname,
  			      char *optval, int *optlen,
  			      bool getopt)
@@ -5284,6 +5313,7 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
  	case SO_BINDTOIFINDEX:
  	case SO_TXREHASH:
  	case SK_BPF_CB_FLAGS:
+	case SK_BPF_MEMCG_FLAGS:
  		if (*optlen != sizeof(int))
  			return -EINVAL;
  		break;
@@ -5293,8 +5323,15 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
  		return -EINVAL;
  	}
  
-	if (optname == SK_BPF_CB_FLAGS)
+	switch (optname) {
+	case SK_BPF_CB_FLAGS:
  		return sk_bpf_set_get_cb_flags(sk, optval, getopt);
+	case SK_BPF_MEMCG_FLAGS:
I would remove the getsockopt only support from the other hooks that cannot do 
the setsockopt. There are other ways for them to read sk->sk_memcg if it is 
really needed.
+		if (!IS_ENABLED(CONFIG_MEMCG) || !getopt)
+			return -EOPNOTSUPP;
+
+		return sk_bpf_get_memcg_flags(sk, optval);
Instead, do this only in bpf_sock_create_getsockopt.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help