All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: madhuparnabhowmik10@gmail.com
Cc: paulmck@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, jiri@mellanox.com,
	joel@joelfernandes.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	davem@davemloft.net
Subject: Re: [Linux-kernel-mentees] [PATCH] net: core: devlink.c: Hold devlink->lock from the beginning of devlink_dpipe_table_register()
Date: Sun, 23 Feb 2020 12:01:45 +0100	[thread overview]
Message-ID: <20200223110145.GE2228@nanopsycho> (raw)
In-Reply-To: <20200223105253.30469-1-madhuparnabhowmik10@gmail.com>

Sun, Feb 23, 2020 at 11:52:53AM CET, madhuparnabhowmik10@gmail.com wrote:
>From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>
>devlink_dpipe_table_find() should be called under either
>rcu_read_lock() or devlink->lock. devlink_dpipe_table_register()
>calls devlink_dpipe_table_find() without holding the lock
>and acquires it later. Therefore hold the devlink->lock
>from the beginning of devlink_dpipe_table_register().
>
>Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>---
> net/core/devlink.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
>diff --git a/net/core/devlink.c b/net/core/devlink.c
>index 4c63c9a4c09e..61a350f59741 100644
>--- a/net/core/devlink.c
>+++ b/net/core/devlink.c
>@@ -6838,26 +6838,35 @@ int devlink_dpipe_table_register(struct devlink *devlink,
> 				 void *priv, bool counter_control_extern)
> {
> 	struct devlink_dpipe_table *table;
>+	int err = 0;
> 
>-	if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
>-		return -EEXIST;
>+	mutex_lock(&devlink->lock);
> 
>-	if (WARN_ON(!table_ops->size_get))
>-		return -EINVAL;
>+	if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name)) {
>+		err = -EEXIST;
>+		goto unlock;
>+	}
>+
>+	if (WARN_ON(!table_ops->size_get)) {
>+		err = -EINVAL;
>+		goto unlock;
>+	}


Put this check out of the lock please.


> 
> 	table = kzalloc(sizeof(*table), GFP_KERNEL);
>-	if (!table)
>-		return -ENOMEM;
>+	if (!table) {
>+		err = -ENOMEM;
>+		goto unlock;
>+	}
> 
> 	table->name = table_name;
> 	table->table_ops = table_ops;
> 	table->priv = priv;
> 	table->counter_control_extern = counter_control_extern;
> 
>-	mutex_lock(&devlink->lock);
> 	list_add_tail_rcu(&table->list, &devlink->dpipe_table_list);
>+unlock:
> 	mutex_unlock(&devlink->lock);
>-	return 0;
>+	return err;
> }
> EXPORT_SYMBOL_GPL(devlink_dpipe_table_register);
> 
>-- 
>2.17.1
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

WARNING: multiple messages have this Message-ID (diff)
From: Jiri Pirko <jiri@resnulli.us>
To: madhuparnabhowmik10@gmail.com
Cc: jiri@mellanox.com, davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, joel@joelfernandes.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	paulmck@kernel.org
Subject: Re: [PATCH] net: core: devlink.c: Hold devlink->lock from the beginning of devlink_dpipe_table_register()
Date: Sun, 23 Feb 2020 12:01:45 +0100	[thread overview]
Message-ID: <20200223110145.GE2228@nanopsycho> (raw)
In-Reply-To: <20200223105253.30469-1-madhuparnabhowmik10@gmail.com>

Sun, Feb 23, 2020 at 11:52:53AM CET, madhuparnabhowmik10@gmail.com wrote:
>From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>
>devlink_dpipe_table_find() should be called under either
>rcu_read_lock() or devlink->lock. devlink_dpipe_table_register()
>calls devlink_dpipe_table_find() without holding the lock
>and acquires it later. Therefore hold the devlink->lock
>from the beginning of devlink_dpipe_table_register().
>
>Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>---
> net/core/devlink.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
>diff --git a/net/core/devlink.c b/net/core/devlink.c
>index 4c63c9a4c09e..61a350f59741 100644
>--- a/net/core/devlink.c
>+++ b/net/core/devlink.c
>@@ -6838,26 +6838,35 @@ int devlink_dpipe_table_register(struct devlink *devlink,
> 				 void *priv, bool counter_control_extern)
> {
> 	struct devlink_dpipe_table *table;
>+	int err = 0;
> 
>-	if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
>-		return -EEXIST;
>+	mutex_lock(&devlink->lock);
> 
>-	if (WARN_ON(!table_ops->size_get))
>-		return -EINVAL;
>+	if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name)) {
>+		err = -EEXIST;
>+		goto unlock;
>+	}
>+
>+	if (WARN_ON(!table_ops->size_get)) {
>+		err = -EINVAL;
>+		goto unlock;
>+	}


Put this check out of the lock please.


> 
> 	table = kzalloc(sizeof(*table), GFP_KERNEL);
>-	if (!table)
>-		return -ENOMEM;
>+	if (!table) {
>+		err = -ENOMEM;
>+		goto unlock;
>+	}
> 
> 	table->name = table_name;
> 	table->table_ops = table_ops;
> 	table->priv = priv;
> 	table->counter_control_extern = counter_control_extern;
> 
>-	mutex_lock(&devlink->lock);
> 	list_add_tail_rcu(&table->list, &devlink->dpipe_table_list);
>+unlock:
> 	mutex_unlock(&devlink->lock);
>-	return 0;
>+	return err;
> }
> EXPORT_SYMBOL_GPL(devlink_dpipe_table_register);
> 
>-- 
>2.17.1
>

  reply	other threads:[~2020-02-23 11:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-23 10:52 [Linux-kernel-mentees] [PATCH] net: core: devlink.c: Hold devlink->lock from the beginning of devlink_dpipe_table_register() madhuparnabhowmik10
2020-02-23 10:52 ` madhuparnabhowmik10
2020-02-23 11:01 ` Jiri Pirko [this message]
2020-02-23 11:01   ` Jiri Pirko
  -- strict thread matches above, loose matches on Subject: below --
2020-02-23 11:22 [Linux-kernel-mentees] " madhuparnabhowmik10
2020-02-23 18:17 ` Jiri Pirko
2020-02-22  6:52 madhuparnabhowmik10
2020-02-23  6:43 ` Jiri Pirko
2020-02-23 10:56   ` Madhuparna Bhowmik
2020-02-21 18:09 madhuparnabhowmik10
2020-02-22  6:26 ` Jiri Pirko
2020-02-22  6:55   ` Madhuparna Bhowmik

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=20200223110145.GE2228@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=jiri@mellanox.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madhuparnabhowmik10@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@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 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.