diff mbox series

[net] inet_diag: add cgroup id attribute

Message ID 20200330081101.GA16030@yandex-team.ru
State Changes Requested
Delegated to: David Miller
Headers show
Series [net] inet_diag: add cgroup id attribute | expand

Commit Message

Dmitry Yakunin March 30, 2020, 8:11 a.m. UTC
This patch adds cgroup v2 id to common inet diag message attributes.
This allows investigate sockets on per cgroup basis when
net_cls/net_prio cgroup not used.

Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
Reviewed-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
 include/linux/inet_diag.h      | 6 +++++-
 include/uapi/linux/inet_diag.h | 1 +
 net/ipv4/inet_diag.c           | 7 +++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

Comments

kernel test robot March 30, 2020, 10:40 a.m. UTC | #1
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net/master]
[also build test ERROR on linus/master v5.6]
[cannot apply to net-next/master sparc-next/master next-20200327]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dmitry-Yakunin/inet_diag-add-cgroup-id-attribute/20200330-175504
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git a0ba26f37ea04e025a793ef5e5ac809221728ecb
config: um-x86_64_defconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-6) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=um SUBARCH=x86_64

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   net/ipv4/inet_diag.c: In function 'inet_diag_msg_attrs_fill':
>> net/ipv4/inet_diag.c:166:20: error: implicit declaration of function 'sock_cgroup_ptr'; did you mean 'task_cgroup_path'? [-Werror=implicit-function-declaration]
             cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
                       ^~~~~~~~~~~~~~~
                       task_cgroup_path
>> net/ipv4/inet_diag.c:166:20: warning: passing argument 1 of 'cgroup_id' makes pointer from integer without a cast [-Wint-conversion]
   In file included from include/net/netprio_cgroup.h:11:0,
                    from include/linux/netdevice.h:42,
                    from include/net/inet_sock.h:19,
                    from include/net/icmp.h:19,
                    from net/ipv4/inet_diag.c:18:
   include/linux/cgroup.h:308:19: note: expected 'struct cgroup *' but argument is of type 'int'
    static inline u64 cgroup_id(struct cgroup *cgrp)
                      ^~~~~~~~~
   cc1: some warnings being treated as errors

vim +166 net/ipv4/inet_diag.c

   142	
   143		if (net_admin && nla_put_u32(skb, INET_DIAG_MARK, sk->sk_mark))
   144			goto errout;
   145	
   146		if (ext & (1 << (INET_DIAG_CLASS_ID - 1)) ||
   147		    ext & (1 << (INET_DIAG_TCLASS - 1))) {
   148			u32 classid = 0;
   149	
   150	#ifdef CONFIG_SOCK_CGROUP_DATA
   151			classid = sock_cgroup_classid(&sk->sk_cgrp_data);
   152	#endif
   153			/* Fallback to socket priority if class id isn't set.
   154			 * Classful qdiscs use it as direct reference to class.
   155			 * For cgroup2 classid is always zero.
   156			 */
   157			if (!classid)
   158				classid = sk->sk_priority;
   159	
   160			if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid))
   161				goto errout;
   162		}
   163	
   164	#ifdef CONFIG_CGROUPS
   165		if (nla_put_u64_64bit(skb, INET_DIAG_CGROUP_ID,
 > 166				      cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
   167				      INET_DIAG_PAD))
   168			goto errout;
   169	#endif
   170	
   171		r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
   172		r->idiag_inode = sock_i_ino(sk);
   173	
   174		return 0;
   175	errout:
   176		return 1;
   177	}
   178	EXPORT_SYMBOL_GPL(inet_diag_msg_attrs_fill);
   179	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot March 30, 2020, 3:28 p.m. UTC | #2
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net/master]
[also build test ERROR on linus/master v5.6]
[cannot apply to net-next/master next-20200330]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dmitry-Yakunin/inet_diag-add-cgroup-id-attribute/20200330-175504
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git a0ba26f37ea04e025a793ef5e5ac809221728ecb
config: mips-64r6el_defconfig (attached as .config)
compiler: mips64el-linux-gcc (GCC) 5.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=5.5.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/ipv4/inet_diag.c: In function 'inet_diag_msg_attrs_fill':
>> net/ipv4/inet_diag.c:166:20: error: implicit declaration of function 'sock_cgroup_ptr' [-Werror=implicit-function-declaration]
             cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
                       ^
   net/ipv4/inet_diag.c:166:20: warning: passing argument 1 of 'cgroup_id' makes pointer from integer without a cast [-Wint-conversion]
   In file included from include/net/netprio_cgroup.h:11:0,
                    from include/linux/netdevice.h:42,
                    from include/net/inet_sock.h:19,
                    from include/net/icmp.h:19,
                    from net/ipv4/inet_diag.c:18:
   include/linux/cgroup.h:308:19: note: expected 'struct cgroup *' but argument is of type 'int'
    static inline u64 cgroup_id(struct cgroup *cgrp)
                      ^
   cc1: some warnings being treated as errors

vim +/sock_cgroup_ptr +166 net/ipv4/inet_diag.c

   142	
   143		if (net_admin && nla_put_u32(skb, INET_DIAG_MARK, sk->sk_mark))
   144			goto errout;
   145	
   146		if (ext & (1 << (INET_DIAG_CLASS_ID - 1)) ||
   147		    ext & (1 << (INET_DIAG_TCLASS - 1))) {
   148			u32 classid = 0;
   149	
   150	#ifdef CONFIG_SOCK_CGROUP_DATA
   151			classid = sock_cgroup_classid(&sk->sk_cgrp_data);
   152	#endif
   153			/* Fallback to socket priority if class id isn't set.
   154			 * Classful qdiscs use it as direct reference to class.
   155			 * For cgroup2 classid is always zero.
   156			 */
   157			if (!classid)
   158				classid = sk->sk_priority;
   159	
   160			if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid))
   161				goto errout;
   162		}
   163	
   164	#ifdef CONFIG_CGROUPS
   165		if (nla_put_u64_64bit(skb, INET_DIAG_CGROUP_ID,
 > 166				      cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
   167				      INET_DIAG_PAD))
   168			goto errout;
   169	#endif
   170	
   171		r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
   172		r->idiag_inode = sock_i_ino(sk);
   173	
   174		return 0;
   175	errout:
   176		return 1;
   177	}
   178	EXPORT_SYMBOL_GPL(inet_diag_msg_attrs_fill);
   179	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Eric Dumazet March 30, 2020, 4:16 p.m. UTC | #3
On 3/30/20 1:11 AM, Dmitry Yakunin wrote:
> This patch adds cgroup v2 id to common inet diag message attributes.
> This allows investigate sockets on per cgroup basis when
> net_cls/net_prio cgroup not used.
> 
> Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
> Reviewed-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> ---
>  include/linux/inet_diag.h      | 6 +++++-
>  include/uapi/linux/inet_diag.h | 1 +
>  net/ipv4/inet_diag.c           | 7 +++++++
>  3 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
> index c91cf2d..8bc5e7d 100644
> --- a/include/linux/inet_diag.h
> +++ b/include/linux/inet_diag.h
> @@ -66,7 +66,11 @@ static inline size_t inet_diag_msg_attrs_size(void)
>  		+ nla_total_size(1)  /* INET_DIAG_SKV6ONLY */
>  #endif
>  		+ nla_total_size(4)  /* INET_DIAG_MARK */
> -		+ nla_total_size(4); /* INET_DIAG_CLASS_ID */
> +		+ nla_total_size(4)  /* INET_DIAG_CLASS_ID */
> +#ifdef CONFIG_CGROUPS
> +		+ nla_total_size(8)  /* INET_DIAG_CGROUP_ID */


nla_total_size_64bit(sizeof(u64))


> +#endif
> +		;
>  }
>  int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
>  			     struct inet_diag_msg *r, int ext,
> diff --git a/include/uapi/linux/inet_diag.h b/include/uapi/linux/inet_diag.h
> index a1ff345..dc87ad6 100644
> --- a/include/uapi/linux/inet_diag.h
> +++ b/include/uapi/linux/inet_diag.h
> @@ -154,6 +154,7 @@ enum {
>  	INET_DIAG_CLASS_ID,	/* request as INET_DIAG_TCLASS */
>  	INET_DIAG_MD5SIG,
>  	INET_DIAG_ULP_INFO,
> +	INET_DIAG_CGROUP_ID,
>  	__INET_DIAG_MAX,
>  };
>  
> diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
> index 8c83775..ba0bb14 100644
> --- a/net/ipv4/inet_diag.c
> +++ b/net/ipv4/inet_diag.c
> @@ -161,6 +161,13 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
>  			goto errout;
>  	}
>  
> +#ifdef CONFIG_CGROUPS
> +	if (nla_put_u64_64bit(skb, INET_DIAG_CGROUP_ID,
> +			      cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
> +			      INET_DIAG_PAD))
> +		goto errout;
> +#endif
> +
>  	r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
>  	r->idiag_inode = sock_i_ino(sk);
>  
>
diff mbox series

Patch

diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
index c91cf2d..8bc5e7d 100644
--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -66,7 +66,11 @@  static inline size_t inet_diag_msg_attrs_size(void)
 		+ nla_total_size(1)  /* INET_DIAG_SKV6ONLY */
 #endif
 		+ nla_total_size(4)  /* INET_DIAG_MARK */
-		+ nla_total_size(4); /* INET_DIAG_CLASS_ID */
+		+ nla_total_size(4)  /* INET_DIAG_CLASS_ID */
+#ifdef CONFIG_CGROUPS
+		+ nla_total_size(8)  /* INET_DIAG_CGROUP_ID */
+#endif
+		;
 }
 int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 			     struct inet_diag_msg *r, int ext,
diff --git a/include/uapi/linux/inet_diag.h b/include/uapi/linux/inet_diag.h
index a1ff345..dc87ad6 100644
--- a/include/uapi/linux/inet_diag.h
+++ b/include/uapi/linux/inet_diag.h
@@ -154,6 +154,7 @@  enum {
 	INET_DIAG_CLASS_ID,	/* request as INET_DIAG_TCLASS */
 	INET_DIAG_MD5SIG,
 	INET_DIAG_ULP_INFO,
+	INET_DIAG_CGROUP_ID,
 	__INET_DIAG_MAX,
 };
 
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 8c83775..ba0bb14 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -161,6 +161,13 @@  int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 			goto errout;
 	}
 
+#ifdef CONFIG_CGROUPS
+	if (nla_put_u64_64bit(skb, INET_DIAG_CGROUP_ID,
+			      cgroup_id(sock_cgroup_ptr(&sk->sk_cgrp_data)),
+			      INET_DIAG_PAD))
+		goto errout;
+#endif
+
 	r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
 	r->idiag_inode = sock_i_ino(sk);