All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
@ 2015-11-16 11:05 Hannes Frederic Sowa
  2015-11-16 20:38 ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Hannes Frederic Sowa @ 2015-11-16 11:05 UTC (permalink / raw)
  To: netdev; +Cc: Hannes Frederic Sowa

Fix the following warning:

  CC      net/core/rtnetlink.o
net/core/rtnetlink.c: In function ‘rtnl_fill_ifinfo’:
net/core/rtnetlink.c:1308:1: warning: the frame size of 2864 bytes is larger than 2048 bytes [-Wframe-larger-than=]
 }
 ^

By declaring the huge stack allocations as static. We can do so because
we hold rtnl.

Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
 net/core/rtnetlink.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 504bd17..4bee37e 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1051,7 +1051,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 {
 	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtnl_link_stats64 temp;
+	static struct rtnl_link_stats64 temp;
 	const struct rtnl_link_stats64 *stats;
 	struct nlattr *attr, *af_spec;
 	struct rtnl_af_ops *af_ops;
@@ -1153,16 +1153,16 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 		if (!vfinfo)
 			goto nla_put_failure;
 		for (i = 0; i < num_vfs; i++) {
-			struct ifla_vf_info ivi;
-			struct ifla_vf_mac vf_mac;
-			struct ifla_vf_vlan vf_vlan;
-			struct ifla_vf_rate vf_rate;
-			struct ifla_vf_tx_rate vf_tx_rate;
-			struct ifla_vf_spoofchk vf_spoofchk;
-			struct ifla_vf_link_state vf_linkstate;
-			struct ifla_vf_rss_query_en vf_rss_query_en;
-			struct ifla_vf_stats vf_stats;
-			struct ifla_vf_trust vf_trust;
+			static struct ifla_vf_info ivi;
+			static struct ifla_vf_mac vf_mac;
+			static struct ifla_vf_vlan vf_vlan;
+			static struct ifla_vf_rate vf_rate;
+			static struct ifla_vf_tx_rate vf_tx_rate;
+			static struct ifla_vf_spoofchk vf_spoofchk;
+			static struct ifla_vf_link_state vf_linkstate;
+			static struct ifla_vf_rss_query_en vf_rss_query_en;
+			static struct ifla_vf_stats vf_stats;
+			static struct ifla_vf_trust vf_trust;
 
 			/*
 			 * Not all SR-IOV capable drivers support the
-- 
2.5.0

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

* Re: [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
  2015-11-16 11:05 [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo Hannes Frederic Sowa
@ 2015-11-16 20:38 ` David Miller
  2015-11-16 22:18   ` Hannes Frederic Sowa
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2015-11-16 20:38 UTC (permalink / raw)
  To: hannes; +Cc: netdev

From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Mon, 16 Nov 2015 12:05:03 +0100

> By declaring the huge stack allocations as static. We can do so
> because we hold rtnl.

Look across the tree, this is an idiom copied all over the place.
If putting a rtnl_link_stats64 object on the stack is truly a
problem, we have a lot of spots to fix.

I do not think, therefore, that this solution is tenable, we
need something that handles all cases properly.

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

* Re: [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
  2015-11-16 20:38 ` David Miller
@ 2015-11-16 22:18   ` Hannes Frederic Sowa
  2015-11-16 22:30     ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Hannes Frederic Sowa @ 2015-11-16 22:18 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Hi,

On Mon, Nov 16, 2015, at 21:38, David Miller wrote:
> From: Hannes Frederic Sowa <hannes@stressinduktion.org>
> Date: Mon, 16 Nov 2015 12:05:03 +0100
> 
> > By declaring the huge stack allocations as static. We can do so
> > because we hold rtnl.
> 
> Look across the tree, this is an idiom copied all over the place.
> If putting a rtnl_link_stats64 object on the stack is truly a
> problem, we have a lot of spots to fix.
> 
> I do not think, therefore, that this solution is tenable, we
> need something that handles all cases properly.

I just wanted to shut up the gcc warning which is added if a function
uses more than 2048 bytes of stack space. We normally don't have the
problem and could also divide the function into two, but I don't see a
general solution to the problem. Mostly they need to be custom tailored
to the specific usage.

I can have a look if we can use kmalloc based storage for the stats, but
this also means that we add another NULL pointer check and error
handling for those cases. Let me have a look!

Bye,
Hannes

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

* Re: [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
  2015-11-16 22:18   ` Hannes Frederic Sowa
@ 2015-11-16 22:30     ` Eric Dumazet
  2015-11-16 22:40       ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2015-11-16 22:30 UTC (permalink / raw)
  To: Hannes Frederic Sowa; +Cc: David Miller, netdev

On Mon, 2015-11-16 at 23:18 +0100, Hannes Frederic Sowa wrote:
> > need something that handles all cases properly.
> 
> I just wanted to shut up the gcc warning which is added if a function
> uses more than 2048 bytes of stack space. We normally don't have the
> problem and could also divide the function into two, but I don't see a
> general solution to the problem. Mostly they need to be custom tailored
> to the specific usage.
> 
> I can have a look if we can use kmalloc based storage for the stats, but
> this also means that we add another NULL pointer check and error
> handling for those cases. Let me have a look!

Simply put the code different functions with noinline_for_stack

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

* Re: [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
  2015-11-16 22:30     ` Eric Dumazet
@ 2015-11-16 22:40       ` Eric Dumazet
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2015-11-16 22:40 UTC (permalink / raw)
  To: Hannes Frederic Sowa; +Cc: David Miller, netdev

On Mon, 2015-11-16 at 14:30 -0800, Eric Dumazet wrote:
> On Mon, 2015-11-16 at 23:18 +0100, Hannes Frederic Sowa wrote:
> > > need something that handles all cases properly.
> > 
> > I just wanted to shut up the gcc warning which is added if a function
> > uses more than 2048 bytes of stack space. We normally don't have the
> > problem and could also divide the function into two, but I don't see a
> > general solution to the problem. Mostly they need to be custom tailored
> > to the specific usage.
> > 
> > I can have a look if we can use kmalloc based storage for the stats, but
> > this also means that we add another NULL pointer check and error
> > handling for those cases. Let me have a look!
> 
> Simply put the code different functions with noinline_for_stack

First step : 

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 504bd17b7456..ff109fad5a7f 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1045,15 +1045,35 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
+static noinline_for_stack bool rtnl_fill_stats(struct sk_buff *skb,
+					       struct net_device *dev)
+{
+	const struct rtnl_link_stats64 *stats;
+	struct rtnl_link_stats64 temp;
+	struct nlattr *attr;
+
+	attr = nla_reserve(skb, IFLA_STATS,
+			   sizeof(struct rtnl_link_stats));
+	if (!attr)
+		return true;
+	stats = dev_get_stats(dev, &temp);
+	copy_rtnl_link_stats(nla_data(attr), stats);
+
+	attr = nla_reserve(skb, IFLA_STATS64,
+			   sizeof(struct rtnl_link_stats64));
+	if (!attr)
+		return true;
+	copy_rtnl_link_stats64(nla_data(attr), stats);
+	return false;
+}
+
 static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 			    int type, u32 pid, u32 seq, u32 change,
 			    unsigned int flags, u32 ext_filter_mask)
 {
 	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtnl_link_stats64 temp;
-	const struct rtnl_link_stats64 *stats;
-	struct nlattr *attr, *af_spec;
+	struct nlattr *af_spec;
 	struct rtnl_af_ops *af_ops;
 	struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
 
@@ -1124,19 +1144,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	if (rtnl_phys_switch_id_fill(skb, dev))
 		goto nla_put_failure;
 
-	attr = nla_reserve(skb, IFLA_STATS,
-			sizeof(struct rtnl_link_stats));
-	if (attr == NULL)
-		goto nla_put_failure;
-
-	stats = dev_get_stats(dev, &temp);
-	copy_rtnl_link_stats(nla_data(attr), stats);
-
-	attr = nla_reserve(skb, IFLA_STATS64,
-			sizeof(struct rtnl_link_stats64));
-	if (attr == NULL)
+	if (rtnl_fill_stats(skb, dev))
 		goto nla_put_failure;
-	copy_rtnl_link_stats64(nla_data(attr), stats);
 
 	if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF) &&
 	    nla_put_u32(skb, IFLA_NUM_VF, dev_num_vf(dev->dev.parent)))

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

* Re: [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
  2015-11-17 12:48 Hannes Frederic Sowa
@ 2015-11-17 13:10 ` Eric Dumazet
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2015-11-17 13:10 UTC (permalink / raw)
  To: Hannes Frederic Sowa; +Cc: netdev, Eric Dumazet

On Tue, 2015-11-17 at 13:48 +0100, Hannes Frederic Sowa wrote:
> Fix the following warning:
> 
>   CC      net/core/rtnetlink.o
> net/core/rtnetlink.c: In function ‘rtnl_fill_ifinfo’:
> net/core/rtnetlink.c:1308:1: warning: the frame size of 2864 bytes is larger than 2048 bytes [-Wframe-larger-than=]
>  }
>  ^
> by splitting up the huge rtnl_fill_ifinfo into some smaller ones, so we
> don't have the huge frame allocations at the same time.
> 
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> ---
>  net/core/rtnetlink.c | 274 ++++++++++++++++++++++++++++-----------------------
>  1 file changed, 152 insertions(+), 122 deletions(-)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 504bd17..6f1c181 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -1045,15 +1045,156 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
>  	return 0;
>  }
>  
> +static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb,
> +					      struct net_device *dev)
> +{
> +	struct nlattr *attr;
> +	struct rtnl_link_stats64 temp;
> +	const struct rtnl_link_stats64 *stats;
> +

Please reorder this in opposite way : longest lines first



> +
> +static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
> +					       struct net_device *dev,
> +					       int vfs_num,
> +					       struct nlattr *vfinfo)
> +{
> +	struct nlattr *vf, *vfstats;
> +	struct ifla_vf_info ivi;
> +	struct ifla_vf_mac vf_mac;
> +	struct ifla_vf_vlan vf_vlan;
> +	struct ifla_vf_rate vf_rate;
> +	struct ifla_vf_tx_rate vf_tx_rate;
> +	struct ifla_vf_spoofchk vf_spoofchk;
> +	struct ifla_vf_link_state vf_linkstate;
> +	struct ifla_vf_rss_query_en vf_rss_query_en;
> +	struct ifla_vf_stats vf_stats;
> +	struct ifla_vf_trust vf_trust;

Same here.

Thanks.

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

* [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo
@ 2015-11-17 12:48 Hannes Frederic Sowa
  2015-11-17 13:10 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Hannes Frederic Sowa @ 2015-11-17 12:48 UTC (permalink / raw)
  To: netdev; +Cc: Hannes Frederic Sowa, Eric Dumazet

Fix the following warning:

  CC      net/core/rtnetlink.o
net/core/rtnetlink.c: In function ‘rtnl_fill_ifinfo’:
net/core/rtnetlink.c:1308:1: warning: the frame size of 2864 bytes is larger than 2048 bytes [-Wframe-larger-than=]
 }
 ^
by splitting up the huge rtnl_fill_ifinfo into some smaller ones, so we
don't have the huge frame allocations at the same time.

Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
 net/core/rtnetlink.c | 274 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 152 insertions(+), 122 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 504bd17..6f1c181 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1045,15 +1045,156 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
+static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb,
+					      struct net_device *dev)
+{
+	struct nlattr *attr;
+	struct rtnl_link_stats64 temp;
+	const struct rtnl_link_stats64 *stats;
+
+	stats = dev_get_stats(dev, &temp);
+
+	attr = nla_reserve(skb, IFLA_STATS,
+			   sizeof(struct rtnl_link_stats));
+	if (!attr)
+		return -EMSGSIZE;
+
+	copy_rtnl_link_stats(nla_data(attr), stats);
+
+	attr = nla_reserve(skb, IFLA_STATS64,
+			   sizeof(struct rtnl_link_stats64));
+	if (!attr)
+		return -EMSGSIZE;
+
+	copy_rtnl_link_stats64(nla_data(attr), stats);
+
+	return 0;
+}
+
+static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
+					       struct net_device *dev,
+					       int vfs_num,
+					       struct nlattr *vfinfo)
+{
+	struct nlattr *vf, *vfstats;
+	struct ifla_vf_info ivi;
+	struct ifla_vf_mac vf_mac;
+	struct ifla_vf_vlan vf_vlan;
+	struct ifla_vf_rate vf_rate;
+	struct ifla_vf_tx_rate vf_tx_rate;
+	struct ifla_vf_spoofchk vf_spoofchk;
+	struct ifla_vf_link_state vf_linkstate;
+	struct ifla_vf_rss_query_en vf_rss_query_en;
+	struct ifla_vf_stats vf_stats;
+	struct ifla_vf_trust vf_trust;
+
+	/* Not all SR-IOV capable drivers support the
+	 * spoofcheck and "RSS query enable" query.  Preset to
+	 * -1 so the user space tool can detect that the driver
+	 * didn't report anything.
+	 */
+	ivi.spoofchk = -1;
+	ivi.rss_query_en = -1;
+	ivi.trusted = -1;
+	memset(ivi.mac, 0, sizeof(ivi.mac));
+	/* The default value for VF link state is "auto"
+	 * IFLA_VF_LINK_STATE_AUTO which equals zero
+	 */
+	ivi.linkstate = 0;
+	if (dev->netdev_ops->ndo_get_vf_config(dev, vfs_num, &ivi))
+		return 0;
+
+	vf_mac.vf =
+		vf_vlan.vf =
+		vf_rate.vf =
+		vf_tx_rate.vf =
+		vf_spoofchk.vf =
+		vf_linkstate.vf =
+		vf_rss_query_en.vf =
+		vf_trust.vf = ivi.vf;
+
+	memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
+	vf_vlan.vlan = ivi.vlan;
+	vf_vlan.qos = ivi.qos;
+	vf_tx_rate.rate = ivi.max_tx_rate;
+	vf_rate.min_tx_rate = ivi.min_tx_rate;
+	vf_rate.max_tx_rate = ivi.max_tx_rate;
+	vf_spoofchk.setting = ivi.spoofchk;
+	vf_linkstate.link_state = ivi.linkstate;
+	vf_rss_query_en.setting = ivi.rss_query_en;
+	vf_trust.setting = ivi.trusted;
+	vf = nla_nest_start(skb, IFLA_VF_INFO);
+	if (!vf) {
+		nla_nest_cancel(skb, vfinfo);
+		return -EMSGSIZE;
+	}
+	if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
+	    nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
+	    nla_put(skb, IFLA_VF_RATE, sizeof(vf_rate),
+		    &vf_rate) ||
+	    nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
+		    &vf_tx_rate) ||
+	    nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
+		    &vf_spoofchk) ||
+	    nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
+		    &vf_linkstate) ||
+	    nla_put(skb, IFLA_VF_RSS_QUERY_EN,
+		    sizeof(vf_rss_query_en),
+		    &vf_rss_query_en) ||
+	    nla_put(skb, IFLA_VF_TRUST,
+		    sizeof(vf_trust), &vf_trust))
+		return -EMSGSIZE;
+	memset(&vf_stats, 0, sizeof(vf_stats));
+	if (dev->netdev_ops->ndo_get_vf_stats)
+		dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num,
+						&vf_stats);
+	vfstats = nla_nest_start(skb, IFLA_VF_STATS);
+	if (!vfstats) {
+		nla_nest_cancel(skb, vf);
+		nla_nest_cancel(skb, vfinfo);
+		return -EMSGSIZE;
+	}
+	if (nla_put_u64(skb, IFLA_VF_STATS_RX_PACKETS,
+			vf_stats.rx_packets) ||
+	    nla_put_u64(skb, IFLA_VF_STATS_TX_PACKETS,
+			vf_stats.tx_packets) ||
+	    nla_put_u64(skb, IFLA_VF_STATS_RX_BYTES,
+			vf_stats.rx_bytes) ||
+	    nla_put_u64(skb, IFLA_VF_STATS_TX_BYTES,
+			vf_stats.tx_bytes) ||
+	    nla_put_u64(skb, IFLA_VF_STATS_BROADCAST,
+			vf_stats.broadcast) ||
+	    nla_put_u64(skb, IFLA_VF_STATS_MULTICAST,
+			vf_stats.multicast))
+		return -EMSGSIZE;
+	nla_nest_end(skb, vfstats);
+	nla_nest_end(skb, vf);
+	return 0;
+}
+
+static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev)
+{
+	struct rtnl_link_ifmap map = {
+		.mem_start   = dev->mem_start,
+		.mem_end     = dev->mem_end,
+		.base_addr   = dev->base_addr,
+		.irq         = dev->irq,
+		.dma         = dev->dma,
+		.port        = dev->if_port,
+	};
+	if (nla_put(skb, IFLA_MAP, sizeof(map), &map))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
 static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 			    int type, u32 pid, u32 seq, u32 change,
 			    unsigned int flags, u32 ext_filter_mask)
 {
 	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
-	struct rtnl_link_stats64 temp;
-	const struct rtnl_link_stats64 *stats;
-	struct nlattr *attr, *af_spec;
+	struct nlattr *af_spec;
 	struct rtnl_af_ops *af_ops;
 	struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
 
@@ -1096,18 +1237,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	    nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down))
 		goto nla_put_failure;
 
-	if (1) {
-		struct rtnl_link_ifmap map = {
-			.mem_start   = dev->mem_start,
-			.mem_end     = dev->mem_end,
-			.base_addr   = dev->base_addr,
-			.irq         = dev->irq,
-			.dma         = dev->dma,
-			.port        = dev->if_port,
-		};
-		if (nla_put(skb, IFLA_MAP, sizeof(map), &map))
-			goto nla_put_failure;
-	}
+	if (rtnl_fill_link_ifmap(skb, dev))
+		goto nla_put_failure;
 
 	if (dev->addr_len) {
 		if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
@@ -1124,128 +1255,27 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	if (rtnl_phys_switch_id_fill(skb, dev))
 		goto nla_put_failure;
 
-	attr = nla_reserve(skb, IFLA_STATS,
-			sizeof(struct rtnl_link_stats));
-	if (attr == NULL)
-		goto nla_put_failure;
-
-	stats = dev_get_stats(dev, &temp);
-	copy_rtnl_link_stats(nla_data(attr), stats);
-
-	attr = nla_reserve(skb, IFLA_STATS64,
-			sizeof(struct rtnl_link_stats64));
-	if (attr == NULL)
+	if (rtnl_fill_stats(skb, dev))
 		goto nla_put_failure;
-	copy_rtnl_link_stats64(nla_data(attr), stats);
 
 	if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF) &&
 	    nla_put_u32(skb, IFLA_NUM_VF, dev_num_vf(dev->dev.parent)))
 		goto nla_put_failure;
 
-	if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent
-	    && (ext_filter_mask & RTEXT_FILTER_VF)) {
+	if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent &&
+	    ext_filter_mask & RTEXT_FILTER_VF) {
 		int i;
-
-		struct nlattr *vfinfo, *vf, *vfstats;
+		struct nlattr *vfinfo;
 		int num_vfs = dev_num_vf(dev->dev.parent);
 
 		vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST);
 		if (!vfinfo)
 			goto nla_put_failure;
 		for (i = 0; i < num_vfs; i++) {
-			struct ifla_vf_info ivi;
-			struct ifla_vf_mac vf_mac;
-			struct ifla_vf_vlan vf_vlan;
-			struct ifla_vf_rate vf_rate;
-			struct ifla_vf_tx_rate vf_tx_rate;
-			struct ifla_vf_spoofchk vf_spoofchk;
-			struct ifla_vf_link_state vf_linkstate;
-			struct ifla_vf_rss_query_en vf_rss_query_en;
-			struct ifla_vf_stats vf_stats;
-			struct ifla_vf_trust vf_trust;
-
-			/*
-			 * Not all SR-IOV capable drivers support the
-			 * spoofcheck and "RSS query enable" query.  Preset to
-			 * -1 so the user space tool can detect that the driver
-			 * didn't report anything.
-			 */
-			ivi.spoofchk = -1;
-			ivi.rss_query_en = -1;
-			ivi.trusted = -1;
-			memset(ivi.mac, 0, sizeof(ivi.mac));
-			/* The default value for VF link state is "auto"
-			 * IFLA_VF_LINK_STATE_AUTO which equals zero
-			 */
-			ivi.linkstate = 0;
-			if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
-				break;
-			vf_mac.vf =
-				vf_vlan.vf =
-				vf_rate.vf =
-				vf_tx_rate.vf =
-				vf_spoofchk.vf =
-				vf_linkstate.vf =
-				vf_rss_query_en.vf =
-				vf_trust.vf = ivi.vf;
-
-			memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
-			vf_vlan.vlan = ivi.vlan;
-			vf_vlan.qos = ivi.qos;
-			vf_tx_rate.rate = ivi.max_tx_rate;
-			vf_rate.min_tx_rate = ivi.min_tx_rate;
-			vf_rate.max_tx_rate = ivi.max_tx_rate;
-			vf_spoofchk.setting = ivi.spoofchk;
-			vf_linkstate.link_state = ivi.linkstate;
-			vf_rss_query_en.setting = ivi.rss_query_en;
-			vf_trust.setting = ivi.trusted;
-			vf = nla_nest_start(skb, IFLA_VF_INFO);
-			if (!vf) {
-				nla_nest_cancel(skb, vfinfo);
-				goto nla_put_failure;
-			}
-			if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
-			    nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
-			    nla_put(skb, IFLA_VF_RATE, sizeof(vf_rate),
-				    &vf_rate) ||
-			    nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
-				    &vf_tx_rate) ||
-			    nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
-				    &vf_spoofchk) ||
-			    nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
-				    &vf_linkstate) ||
-			    nla_put(skb, IFLA_VF_RSS_QUERY_EN,
-				    sizeof(vf_rss_query_en),
-				    &vf_rss_query_en) ||
-			    nla_put(skb, IFLA_VF_TRUST,
-				    sizeof(vf_trust), &vf_trust))
+			if (rtnl_fill_vfinfo(skb, dev, i, vfinfo))
 				goto nla_put_failure;
-			memset(&vf_stats, 0, sizeof(vf_stats));
-			if (dev->netdev_ops->ndo_get_vf_stats)
-				dev->netdev_ops->ndo_get_vf_stats(dev, i,
-								  &vf_stats);
-			vfstats = nla_nest_start(skb, IFLA_VF_STATS);
-			if (!vfstats) {
-				nla_nest_cancel(skb, vf);
-				nla_nest_cancel(skb, vfinfo);
-				goto nla_put_failure;
-			}
-			if (nla_put_u64(skb, IFLA_VF_STATS_RX_PACKETS,
-					vf_stats.rx_packets) ||
-			    nla_put_u64(skb, IFLA_VF_STATS_TX_PACKETS,
-					vf_stats.tx_packets) ||
-			    nla_put_u64(skb, IFLA_VF_STATS_RX_BYTES,
-					vf_stats.rx_bytes) ||
-			    nla_put_u64(skb, IFLA_VF_STATS_TX_BYTES,
-					vf_stats.tx_bytes) ||
-			    nla_put_u64(skb, IFLA_VF_STATS_BROADCAST,
-					vf_stats.broadcast) ||
-			    nla_put_u64(skb, IFLA_VF_STATS_MULTICAST,
-					vf_stats.multicast))
-				goto nla_put_failure;
-			nla_nest_end(skb, vfstats);
-			nla_nest_end(skb, vf);
 		}
+
 		nla_nest_end(skb, vfinfo);
 	}
 
-- 
2.5.0

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

end of thread, other threads:[~2015-11-17 13:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-16 11:05 [PATCH net] rtnetlink: fix frame size warning in rtnl_fill_ifinfo Hannes Frederic Sowa
2015-11-16 20:38 ` David Miller
2015-11-16 22:18   ` Hannes Frederic Sowa
2015-11-16 22:30     ` Eric Dumazet
2015-11-16 22:40       ` Eric Dumazet
2015-11-17 12:48 Hannes Frederic Sowa
2015-11-17 13:10 ` Eric Dumazet

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.