netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@monom.org>
To: netdev@vger.kernel.org, cgroups@vger.kernel.org
Cc: Daniel Wagner <daniel.wagner@bmw-carit.de>,
	"David S. Miller" <davem@davemloft.net>,
	Gao feng <gaofeng@cn.fujitsu.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	John Fastabend <john.r.fastabend@intel.com>,
	Li Zefan <lizefan@huawei.com>,
	Neil Horman <nhorman@tuxdriver.com>, Tejun Heo <tj@kernel.org>
Subject: [PATCH v2 03/10] cgroup: net_cls: Protect access to task_cls_classid() when built as module
Date: Fri, 24 Aug 2012 16:01:37 +0200	[thread overview]
Message-ID: <1345816904-21745-4-git-send-email-wagi@monom.org> (raw)
In-Reply-To: <1345816904-21745-1-git-send-email-wagi@monom.org>

From: Daniel Wagner <daniel.wagner@bmw-carit.de>

The module version of task_cls_classid() checks if net_cls_sbusys_id
is valid to indentify when it is okay to access the controller.

Instead relying on the subusys_id to be set, make it explicit
with a jump label.

Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Gao feng <gaofeng@cn.fujitsu.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: John Fastabend <john.r.fastabend@intel.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: netdev@vger.kernel.org
Cc: cgroups@vger.kernel.org
---
 include/net/cls_cgroup.h |  6 +++++-
 net/core/sock.c          |  5 +++++
 net/sched/cls_cgroup.c   | 11 +++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/net/cls_cgroup.h b/include/net/cls_cgroup.h
index 401672c..24443d2 100644
--- a/include/net/cls_cgroup.h
+++ b/include/net/cls_cgroup.h
@@ -16,6 +16,7 @@
 #include <linux/cgroup.h>
 #include <linux/hardirq.h>
 #include <linux/rcupdate.h>
+#include <linux/jump_label.h>
 
 #ifdef CONFIG_CGROUPS
 struct cgroup_cls_state
@@ -45,6 +46,9 @@ static inline u32 task_cls_classid(struct task_struct *p)
 
 #elif IS_MODULE(CONFIG_NET_CLS_CGROUP)
 
+extern struct static_key cgroup_cls_enabled;
+#define clscg_enabled static_key_false(&cgroup_cls_enabled)
+
 extern int net_cls_subsys_id;
 
 static inline u32 task_cls_classid(struct task_struct *p)
@@ -52,7 +56,7 @@ static inline u32 task_cls_classid(struct task_struct *p)
 	int id;
 	u32 classid = 0;
 
-	if (in_interrupt())
+	if (!clscg_enabled || in_interrupt())
 		return 0;
 
 	rcu_read_lock();
diff --git a/net/core/sock.c b/net/core/sock.c
index 8f67ced..8106e77 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -327,6 +327,11 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 EXPORT_SYMBOL(__sk_backlog_rcv);
 
 #if defined(CONFIG_CGROUPS)
+#if IS_MODULE(CONFIG_NET_CLS_CGROUP)
+struct static_key cgroup_cls_enabled = STATIC_KEY_INIT_FALSE;
+EXPORT_SYMBOL_GPL(cgroup_cls_enabled);
+#endif
+
 #if !defined(CONFIG_NET_CLS_CGROUP)
 int net_cls_subsys_id = -1;
 EXPORT_SYMBOL_GPL(net_cls_subsys_id);
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 7743ea8..554dc5b 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -293,6 +293,12 @@ static int __init init_cgroup_cls(void)
 	if (ret)
 		cgroup_unload_subsys(&net_cls_subsys);
 
+#if IS_MODULE(CONFIG_NET_CLS_CGROUP)
+	if (ret)
+		goto out;
+	static_key_slow_inc(&cgroup_cls_enabled);
+#endif
+
 out:
 	return ret;
 }
@@ -306,6 +312,11 @@ static void __exit exit_cgroup_cls(void)
 	synchronize_rcu();
 #endif
 
+#if IS_MODULE(CONFIG_NET_CLS_CGROUP)
+	static_key_slow_dec(&cgroup_cls_enabled);
+	rcu_barrier();
+#endif
+
 	cgroup_unload_subsys(&net_cls_subsys);
 }
 
-- 
1.7.12.rc1.16.g05a20c8

  parent reply	other threads:[~2012-08-24 14:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-24 14:01 [PATCH v2 00/10] cgroup: Assign subsystem IDs during compile time Daniel Wagner
2012-08-24 14:01 ` [PATCH v2 01/10] cgroup: net_cls: Use empty task_cls_classid() when !CONFIG_NET_CLS(_MODULE) Daniel Wagner
     [not found]   ` <1345816904-21745-2-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:22     ` Tejun Heo
2012-08-27  2:32   ` Li Zefan
2012-08-24 14:01 ` Daniel Wagner [this message]
     [not found]   ` <1345816904-21745-4-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:26     ` [PATCH v2 03/10] cgroup: net_cls: Protect access to task_cls_classid() when built as module Tejun Heo
2012-08-25 16:56       ` Daniel Wagner
     [not found]         ` <503903BD.6020208-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-28 14:47           ` Paul E. McKenney
     [not found]             ` <20120828144725.GR2961-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-08-28 16:41               ` Daniel Wagner
2012-08-24 14:01 ` [PATCH v2 05/10] cgroup: Remove CGROUP_BUILTIN_SUBSYS_COUNT Daniel Wagner
     [not found]   ` <1345816904-21745-6-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:28     ` Tejun Heo
     [not found]       ` <20120824232840.GS21325-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-08-25 16:59         ` Daniel Wagner
     [not found]           ` <5039046D.1040402-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-09-06 22:23             ` Tejun Heo
2012-08-24 14:01 ` [PATCH v2 06/10] cgroup: Assign subsystem IDs during compile time Daniel Wagner
     [not found]   ` <1345816904-21745-7-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:38     ` Tejun Heo
     [not found]       ` <20120824233810.GT21325-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-08-25 17:11         ` Daniel Wagner
     [not found]           ` <50390743.2090203-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-09-06 22:32             ` Tejun Heo
2012-08-24 14:01 ` [PATCH v2 08/10] cgroup: net_cls: Merge builtin and module version of task_cls_classid() Daniel Wagner
     [not found]   ` <1345816904-21745-9-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:41     ` Tejun Heo
     [not found] ` <1345816904-21745-1-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 14:01   ` [PATCH v2 02/10] cgroup: net_cls: Move sock_update_classid() decleration to cls_cgroup.h Daniel Wagner
2012-08-24 14:01   ` [PATCH v2 04/10] cgroup: net_prio: Protect access to task_netprioidx() when built as module Daniel Wagner
     [not found]     ` <1345816904-21745-5-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:26       ` Tejun Heo
2012-08-24 14:01   ` [PATCH v2 07/10] cgroup: net_cls: Simplify ifdef logic Daniel Wagner
     [not found]     ` <1345816904-21745-8-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:39       ` Tejun Heo
2012-08-24 14:01   ` [PATCH v2 09/10] cgroup: net_prio: " Daniel Wagner
     [not found]     ` <1345816904-21745-10-git-send-email-wagi-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-08-24 23:42       ` Tejun Heo
2012-08-24 14:01   ` [PATCH v2 10/10] cgroup: net_prio: Merge builtin and module version of task_netprioidx() Daniel Wagner
2012-08-24 15:01   ` [PATCH v2 00/10] cgroup: Assign subsystem IDs during compile time Daniel Wagner
2012-08-24 23:15   ` Tejun Heo
     [not found]     ` <20120824231528.GO21325-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-08-25 16:49       ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345816904-21745-4-git-send-email-wagi@monom.org \
    --to=wagi@monom.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=davem@davemloft.net \
    --cc=gaofeng@cn.fujitsu.com \
    --cc=jhs@mojatatu.com \
    --cc=john.r.fastabend@intel.com \
    --cc=lizefan@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).