All of lore.kernel.org
 help / color / mirror / Atom feed
* Attempt to auto-load em_cmp.ko results in negative module refcnt
@ 2015-02-16 10:59 Ignacy Gawedzki
  2015-02-16 15:03 ` Ignacy Gawedzki
  0 siblings, 1 reply; 9+ messages in thread
From: Ignacy Gawedzki @ 2015-02-16 10:59 UTC (permalink / raw)
  To: netdev

Hi,

This simple test case

  tc qdisc add dev eth0 root handle 1: htb
  tc class add dev eth0 root classid 1: htb rate 1Gbit
  tc class add dev eth0 parent 1: classid 1:1 htb rate 1Gbit
  tc filter add dev eth0 parent 1: basic match 'cmp(u8 at 0 eq 0)' classid 1:1

fails with the following

  RTNETLINK answers: No such file or directory
  We have an error talking to the kernel

if em_cmp.ko is not loaded beforehand.

After that, lsmod shows that em_cmp.ko is loaded indeed, but its usage count
is -1 and an attempd to unload the module results in a "BUG at
kernel/module.c:752".

This has been broken pretty recently, I'm currently attempting a git bisect on
this.

-- 
Ignacy Gawędzki
R&D Engineer
Green Communications

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Attempt to auto-load em_cmp.ko results in negative module refcnt
  2015-02-16 10:59 Attempt to auto-load em_cmp.ko results in negative module refcnt Ignacy Gawedzki
@ 2015-02-16 15:03 ` Ignacy Gawedzki
  2015-02-16 18:13   ` [PATCH net] ematch: Fix auto-loading of ematch modules Ignacy Gawędzki
  0 siblings, 1 reply; 9+ messages in thread
From: Ignacy Gawedzki @ 2015-02-16 15:03 UTC (permalink / raw)
  To: netdev

On Mon, Feb 16, 2015 at 11:59:12AM +0100, thus spake Ignacy Gawedzki:
> This has been broken pretty recently, I'm currently attempting a git bisect on
> this.

Okay, the bisect tells this appeared with
e513cc1c07e2ab93a4514eec9833e031df3e30bb, FWIW.

-- 
Ignacy Gawędzki
R&D Engineer
Green Communications

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net] ematch: Fix auto-loading of ematch modules.
  2015-02-16 15:03 ` Ignacy Gawedzki
@ 2015-02-16 18:13   ` Ignacy Gawędzki
  2015-02-16 18:36     ` Cong Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Ignacy Gawędzki @ 2015-02-16 18:13 UTC (permalink / raw)
  To: netdev

In tcf_em_validate(), when calling tcf_em_lookup(), don't put the resulting
pointer directly into em->ops, if the function is to possibly return -EAGAIN
after module auto-loading.  Otherwise, module_put() will be called by
tcf_em_tree_destroy() on em->ops->owner, while it has already been called by
tcf_em_validate() before return.

Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
---
 net/sched/ematch.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index 6742200..39fbe2f 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -176,6 +176,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
 {
 	int err = -EINVAL;
 	struct tcf_ematch_hdr *em_hdr = nla_data(nla);
+	struct tcf_ematch_ops *em_ops;
 	int data_len = nla_len(nla) - sizeof(*em_hdr);
 	void *data = (void *) em_hdr + sizeof(*em_hdr);
 	struct net *net = dev_net(qdisc_dev(tp->q));
@@ -213,27 +214,29 @@ static int tcf_em_validate(struct tcf_proto *tp,
 		 * here. Be aware, the destroy function assumes that the
 		 * module is held if the ops field is non zero.
 		 */
-		em->ops = tcf_em_lookup(em_hdr->kind);
+		em_ops = tcf_em_lookup(em_hdr->kind);
 
-		if (em->ops == NULL) {
+		if (em_ops == NULL) {
 			err = -ENOENT;
 #ifdef CONFIG_MODULES
 			__rtnl_unlock();
 			request_module("ematch-kind-%u", em_hdr->kind);
 			rtnl_lock();
-			em->ops = tcf_em_lookup(em_hdr->kind);
-			if (em->ops) {
+			em_ops = tcf_em_lookup(em_hdr->kind);
+			if (em_ops) {
 				/* We dropped the RTNL mutex in order to
 				 * perform the module load. Tell the caller
 				 * to replay the request.
 				 */
-				module_put(em->ops->owner);
+				module_put(em_ops->owner);
 				err = -EAGAIN;
 			}
 #endif
 			goto errout;
 		}
 
+		em->ops = em_ops;
+
 		/* ematch module provides expected length of data, so we
 		 * can do a basic sanity check.
 		 */
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net] ematch: Fix auto-loading of ematch modules.
  2015-02-16 18:13   ` [PATCH net] ematch: Fix auto-loading of ematch modules Ignacy Gawędzki
@ 2015-02-16 18:36     ` Cong Wang
  2015-02-16 18:50       ` Ignacy Gawędzki
  0 siblings, 1 reply; 9+ messages in thread
From: Cong Wang @ 2015-02-16 18:36 UTC (permalink / raw)
  To: Ignacy Gawędzki, netdev

On Mon, Feb 16, 2015 at 10:13 AM, Ignacy Gawędzki
<ignacy.gawedzki@green-communications.fr> wrote:
> In tcf_em_validate(), when calling tcf_em_lookup(), don't put the resulting
> pointer directly into em->ops, if the function is to possibly return -EAGAIN
> after module auto-loading.  Otherwise, module_put() will be called by
> tcf_em_tree_destroy() on em->ops->owner, while it has already been called by
> tcf_em_validate() before return.
>

Or simply reset em->ops to NULL after module_put()?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net] ematch: Fix auto-loading of ematch modules.
  2015-02-16 18:36     ` Cong Wang
@ 2015-02-16 18:50       ` Ignacy Gawędzki
  2015-02-17 18:00         ` Cong Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Ignacy Gawędzki @ 2015-02-16 18:50 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev

On Mon, Feb 16, 2015 at 10:36:06AM -0800, thus spake Cong Wang:
> On Mon, Feb 16, 2015 at 10:13 AM, Ignacy Gawędzki
> <ignacy.gawedzki@green-communications.fr> wrote:
> > In tcf_em_validate(), when calling tcf_em_lookup(), don't put the resulting
> > pointer directly into em->ops, if the function is to possibly return -EAGAIN
> > after module auto-loading.  Otherwise, module_put() will be called by
> > tcf_em_tree_destroy() on em->ops->owner, while it has already been called by
> > tcf_em_validate() before return.
> >
> 
> Or simply reset em->ops to NULL after module_put()?

Yeah, why not.  I just got my inspiration from what's done in cls_api.c and
act_api.c.  What do you think, should the same simplification be applied to
cls_api.c?

-- 
Ignacy Gawędzki
R&D Engineer
Green Communications

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net] ematch: Fix auto-loading of ematch modules.
  2015-02-16 18:50       ` Ignacy Gawędzki
@ 2015-02-17 18:00         ` Cong Wang
  2015-02-17 19:15           ` [PATCH net v2] " Ignacy Gawędzki
  0 siblings, 1 reply; 9+ messages in thread
From: Cong Wang @ 2015-02-17 18:00 UTC (permalink / raw)
  To: Ignacy Gawędzki, Cong Wang, netdev

On Mon, Feb 16, 2015 at 10:50 AM, Ignacy Gawędzki
<ignacy.gawedzki@green-communications.fr> wrote:
> On Mon, Feb 16, 2015 at 10:36:06AM -0800, thus spake Cong Wang:
>> On Mon, Feb 16, 2015 at 10:13 AM, Ignacy Gawędzki
>> <ignacy.gawedzki@green-communications.fr> wrote:
>> > In tcf_em_validate(), when calling tcf_em_lookup(), don't put the resulting
>> > pointer directly into em->ops, if the function is to possibly return -EAGAIN
>> > after module auto-loading.  Otherwise, module_put() will be called by
>> > tcf_em_tree_destroy() on em->ops->owner, while it has already been called by
>> > tcf_em_validate() before return.
>> >
>>
>> Or simply reset em->ops to NULL after module_put()?
>
> Yeah, why not.  I just got my inspiration from what's done in cls_api.c and
> act_api.c.  What do you think, should the same simplification be applied to
> cls_api.c?
>

I prefer the smaller change, we don't have to align with cls_api.c.
Yeah, you can always clean it up for net-next.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net v2] ematch: Fix auto-loading of ematch modules.
  2015-02-17 18:00         ` Cong Wang
@ 2015-02-17 19:15           ` Ignacy Gawędzki
  2015-02-18  5:17             ` Cong Wang
  2015-02-20 20:31             ` David Miller
  0 siblings, 2 replies; 9+ messages in thread
From: Ignacy Gawędzki @ 2015-02-17 19:15 UTC (permalink / raw)
  To: netdev

In tcf_em_validate(), after calling request_module() to load the
kind-specific module, set em->ops to NULL before returning -EAGAIN, so
that module_put() is not called again by tcf_em_tree_destroy().

Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
---
 net/sched/ematch.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index 6742200..fbb7ebf 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -228,6 +228,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
 				 * to replay the request.
 				 */
 				module_put(em->ops->owner);
+				em->ops = NULL;
 				err = -EAGAIN;
 			}
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net v2] ematch: Fix auto-loading of ematch modules.
  2015-02-17 19:15           ` [PATCH net v2] " Ignacy Gawędzki
@ 2015-02-18  5:17             ` Cong Wang
  2015-02-20 20:31             ` David Miller
  1 sibling, 0 replies; 9+ messages in thread
From: Cong Wang @ 2015-02-18  5:17 UTC (permalink / raw)
  To: Ignacy Gawędzki, netdev

On Tue, Feb 17, 2015 at 11:15 AM, Ignacy Gawędzki
<ignacy.gawedzki@green-communications.fr> wrote:
> In tcf_em_validate(), after calling request_module() to load the
> kind-specific module, set em->ops to NULL before returning -EAGAIN, so
> that module_put() is not called again by tcf_em_tree_destroy().
>
> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>


Acked-by: Cong Wang <cwang@twopensource.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net v2] ematch: Fix auto-loading of ematch modules.
  2015-02-17 19:15           ` [PATCH net v2] " Ignacy Gawędzki
  2015-02-18  5:17             ` Cong Wang
@ 2015-02-20 20:31             ` David Miller
  1 sibling, 0 replies; 9+ messages in thread
From: David Miller @ 2015-02-20 20:31 UTC (permalink / raw)
  To: ignacy.gawedzki; +Cc: netdev

From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Date: Tue, 17 Feb 2015 20:15:20 +0100

> In tcf_em_validate(), after calling request_module() to load the
> kind-specific module, set em->ops to NULL before returning -EAGAIN, so
> that module_put() is not called again by tcf_em_tree_destroy().
> 
> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-02-20 20:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-16 10:59 Attempt to auto-load em_cmp.ko results in negative module refcnt Ignacy Gawedzki
2015-02-16 15:03 ` Ignacy Gawedzki
2015-02-16 18:13   ` [PATCH net] ematch: Fix auto-loading of ematch modules Ignacy Gawędzki
2015-02-16 18:36     ` Cong Wang
2015-02-16 18:50       ` Ignacy Gawędzki
2015-02-17 18:00         ` Cong Wang
2015-02-17 19:15           ` [PATCH net v2] " Ignacy Gawędzki
2015-02-18  5:17             ` Cong Wang
2015-02-20 20:31             ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.