All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: Jiri Pirko <jpirko@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH] dropmon: add ability to detect when hardware	dropsrxpackets
Date: Fri, 15 May 2009 20:11:57 +0200	[thread overview]
Message-ID: <4A0DB06D.7000805@cosmosbay.com> (raw)
In-Reply-To: <20090515160702.GE7745@hmsreliant.think-freely.org>

Neil Horman a écrit :
> +static int dropmon_net_event(struct notifier_block *ev_block,
> +			unsigned long event, void *ptr)
> +{
> +	struct net_device *dev = ptr;
> +	struct dm_hw_stat_delta *new_stat = NULL;
> +	int found = 0;
> +
> +	switch (event) {
> +	case NETDEV_REGISTER:
> +		new_stat = kzalloc(sizeof(struct dm_hw_stat_delta), GFP_KERNEL);
> +
> +		if (!new_stat)
> +			goto out;
> +
> +		new_stat->dev = dev;
> +		INIT_RCU_HEAD(&new_stat->rcu);
> +		spin_lock(&trace_state_lock);
> +		list_add_rcu(&new_stat->list, &hw_stats_list);
> +		spin_unlock(&trace_state_lock);
> +		break;
> +	case NETDEV_UNREGISTER:
> +		rcu_read_lock();
> +		list_for_each_entry_rcu(new_stat, &hw_stats_list, list) {
> +			if (new_stat->dev == dev)
> +				new_stat->dev = NULL;
> +				found = 1;
> +				break;
> +		}
> +		rcu_read_unlock();

This is racy, unless caller already owns a lock.

If caller aleady owns a lock, you dont need :

rcu_read_lock()
list_for_each_entry_rcu()
rcu_read_unlock();

> +
> +		spin_lock(&trace_state_lock);
> +		if (found && (trace_state == TRACE_OFF)) {
> +			list_del_rcu(&new_stat->list);
> +			call_rcu(&new_stat->rcu, free_dm_hw_stat);
> +		}
> +		spin_unlock(&trace_state_lock);
> +		break;




Its not clear that you use trace_state_lock as the lock guarding all this.

If this is the case I suggest a plain and straight forward :

case NETDEV_UNREGISTER:
	spin_lock(&trace_state_lock);
	if (trace_state == TRACE_OFF) {
		list_for_each_entry(new_stat, &hw_stats_list, list) {
			if (new_stat->dev == dev) {
				new_stat->dev = NULL;
				list_del_rcu(&new_stat->list);
				call_rcu(&new_stat->rcu, free_dm_hw_stat);
				break;
			}
		}
	}
	spin_unlock(&trace_state_lock);
	break;



  reply	other threads:[~2009-05-15 18:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-08 19:50 [PATCH] dropmon: add ability to detect when hardware drops rx packets Neil Horman
2009-05-09  6:30 ` Eric Dumazet
2009-05-09 18:07   ` Neil Horman
2009-05-12 16:30   ` Neil Horman
2009-05-13 18:23     ` [PATCH] dropmon: add ability to detect when hardware drops rxpackets Paul E. McKenney
2009-05-14  0:45       ` Neil Horman
2009-05-14  1:03         ` [PATCH] dropmon: add ability to detect when hardware dropsrxpackets Paul E. McKenney
2009-05-14 12:33           ` Neil Horman
2009-05-14 12:44             ` Jiri Pirko
2009-05-14 16:17               ` [PATCH] dropmon: add ability to detect when hardwaredropsrxpackets Paul E. McKenney
2009-05-14 17:29               ` [PATCH] dropmon: add ability to detect when hardware dropsrxpackets Neil Horman
2009-05-15  5:49                 ` Jarek Poplawski
2009-05-15 11:01                   ` Neil Horman
2009-05-15 11:12                     ` Jarek Poplawski
2009-05-15 11:15                       ` Neil Horman
2009-05-15 11:40                         ` Jarek Poplawski
2009-05-16  0:07                           ` Paul E. McKenney
2009-05-15  6:51                 ` Jiri Pirko
2009-05-15  7:37                   ` Eric Dumazet
2009-05-15 11:12                     ` Neil Horman
2009-05-15 10:59                   ` Neil Horman
2009-05-15 11:27                     ` Jiri Pirko
2009-05-15 16:07                       ` Neil Horman
2009-05-15 18:11                         ` Eric Dumazet [this message]
2009-05-15 18:23                           ` Stephen Hemminger
2009-05-15 19:53                             ` Neil Horman
2009-05-15 19:23                           ` Neil Horman
2009-05-16 12:40                           ` Neil Horman
2009-05-18 14:46                             ` Neil Horman
2009-05-21  7:17                               ` David Miller
2009-05-21 17:36                                 ` Neil Horman
2009-05-21 22:15                                   ` David Miller
2009-05-22  0:09                                     ` Neil Horman
2009-05-15 18:18                         ` Stephen Hemminger
2009-05-15 19:12                           ` Neil Horman
2009-05-14 16:18             ` [PATCH] dropmon: add ability to detect when hardwaredropsrxpackets Paul E. McKenney

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=4A0DB06D.7000805@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=davem@davemloft.net \
    --cc=jpirko@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    /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.