Commit 8d4698f7 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

bridge: don't allow setting hello time to zero

Dushan Tcholich reports that on his system ksoftirqd can consume
between %6 to %10 of cpu time, and cause ~200 context switches per
second.

He then correlated this with a report by bdupree@techfinesse.com:

	http://marc.info/?l=linux-kernel&m=119613299024398&w=2

and the culprit cause seems to be starting the bridge interface.
In particular, when starting the bridge interface, his scripts
are specifying a hello timer interval of "0".

The bridge hello time can't be safely set to values less than 1
second, otherwise it is possible to end up with a runaway timer.
Signed-off-by: default avatarStephen Hemminger <shemminger@vyatta.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d315492b
...@@ -188,15 +188,21 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ...@@ -188,15 +188,21 @@ static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
return 0; return 0;
case BRCTL_SET_BRIDGE_HELLO_TIME: case BRCTL_SET_BRIDGE_HELLO_TIME:
{
unsigned long t = clock_t_to_jiffies(args[1]);
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (t < HZ)
return -EINVAL;
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
br->bridge_hello_time = clock_t_to_jiffies(args[1]); br->bridge_hello_time = t;
if (br_is_root_bridge(br)) if (br_is_root_bridge(br))
br->hello_time = br->bridge_hello_time; br->hello_time = br->bridge_hello_time;
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
return 0; return 0;
}
case BRCTL_SET_BRIDGE_MAX_AGE: case BRCTL_SET_BRIDGE_MAX_AGE:
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
......
...@@ -29,11 +29,12 @@ ...@@ -29,11 +29,12 @@
*/ */
static ssize_t store_bridge_parm(struct device *d, static ssize_t store_bridge_parm(struct device *d,
const char *buf, size_t len, const char *buf, size_t len,
void (*set)(struct net_bridge *, unsigned long)) int (*set)(struct net_bridge *, unsigned long))
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
char *endp; char *endp;
unsigned long val; unsigned long val;
int err;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
...@@ -43,9 +44,9 @@ static ssize_t store_bridge_parm(struct device *d, ...@@ -43,9 +44,9 @@ static ssize_t store_bridge_parm(struct device *d,
return -EINVAL; return -EINVAL;
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
(*set)(br, val); err = (*set)(br, val);
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
return len; return err ? err : len;
} }
...@@ -56,12 +57,13 @@ static ssize_t show_forward_delay(struct device *d, ...@@ -56,12 +57,13 @@ static ssize_t show_forward_delay(struct device *d,
return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
} }
static void set_forward_delay(struct net_bridge *br, unsigned long val) static int set_forward_delay(struct net_bridge *br, unsigned long val)
{ {
unsigned long delay = clock_t_to_jiffies(val); unsigned long delay = clock_t_to_jiffies(val);
br->forward_delay = delay; br->forward_delay = delay;
if (br_is_root_bridge(br)) if (br_is_root_bridge(br))
br->bridge_forward_delay = delay; br->bridge_forward_delay = delay;
return 0;
} }
static ssize_t store_forward_delay(struct device *d, static ssize_t store_forward_delay(struct device *d,
...@@ -80,12 +82,17 @@ static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, ...@@ -80,12 +82,17 @@ static ssize_t show_hello_time(struct device *d, struct device_attribute *attr,
jiffies_to_clock_t(to_bridge(d)->hello_time)); jiffies_to_clock_t(to_bridge(d)->hello_time));
} }
static void set_hello_time(struct net_bridge *br, unsigned long val) static int set_hello_time(struct net_bridge *br, unsigned long val)
{ {
unsigned long t = clock_t_to_jiffies(val); unsigned long t = clock_t_to_jiffies(val);
if (t < HZ)
return -EINVAL;
br->hello_time = t; br->hello_time = t;
if (br_is_root_bridge(br)) if (br_is_root_bridge(br))
br->bridge_hello_time = t; br->bridge_hello_time = t;
return 0;
} }
static ssize_t store_hello_time(struct device *d, static ssize_t store_hello_time(struct device *d,
...@@ -104,12 +111,13 @@ static ssize_t show_max_age(struct device *d, struct device_attribute *attr, ...@@ -104,12 +111,13 @@ static ssize_t show_max_age(struct device *d, struct device_attribute *attr,
jiffies_to_clock_t(to_bridge(d)->max_age)); jiffies_to_clock_t(to_bridge(d)->max_age));
} }
static void set_max_age(struct net_bridge *br, unsigned long val) static int set_max_age(struct net_bridge *br, unsigned long val)
{ {
unsigned long t = clock_t_to_jiffies(val); unsigned long t = clock_t_to_jiffies(val);
br->max_age = t; br->max_age = t;
if (br_is_root_bridge(br)) if (br_is_root_bridge(br))
br->bridge_max_age = t; br->bridge_max_age = t;
return 0;
} }
static ssize_t store_max_age(struct device *d, struct device_attribute *attr, static ssize_t store_max_age(struct device *d, struct device_attribute *attr,
...@@ -126,9 +134,10 @@ static ssize_t show_ageing_time(struct device *d, ...@@ -126,9 +134,10 @@ static ssize_t show_ageing_time(struct device *d,
return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
} }
static void set_ageing_time(struct net_bridge *br, unsigned long val) static int set_ageing_time(struct net_bridge *br, unsigned long val)
{ {
br->ageing_time = clock_t_to_jiffies(val); br->ageing_time = clock_t_to_jiffies(val);
return 0;
} }
static ssize_t store_ageing_time(struct device *d, static ssize_t store_ageing_time(struct device *d,
...@@ -180,9 +189,10 @@ static ssize_t show_priority(struct device *d, struct device_attribute *attr, ...@@ -180,9 +189,10 @@ static ssize_t show_priority(struct device *d, struct device_attribute *attr,
(br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
} }
static void set_priority(struct net_bridge *br, unsigned long val) static int set_priority(struct net_bridge *br, unsigned long val)
{ {
br_stp_set_bridge_priority(br, (u16) val); br_stp_set_bridge_priority(br, (u16) val);
return 0;
} }
static ssize_t store_priority(struct device *d, struct device_attribute *attr, static ssize_t store_priority(struct device *d, struct device_attribute *attr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment