diff mbox series

[V2,mlx5-next,01/10] net/core: Introduce master_xmit_slave_get

Message ID 20200420075426.31462-2-maorg@mellanox.com
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series Add support to get xmit slave | expand

Commit Message

Maor Gottlieb April 20, 2020, 7:54 a.m. UTC
Add new ndo to get the xmit slave of master device.
User should release the slave when it's not longer needed.
When slave selection method is based on hash, then the user can ask to
get the xmit slave assume all the slaves can transmit by setting the
LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.

Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
---
 include/linux/netdevice.h |  3 +++
 include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

Comments

Jiri Pirko April 20, 2020, 2:01 p.m. UTC | #1
Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>Add new ndo to get the xmit slave of master device.
>User should release the slave when it's not longer needed.
>When slave selection method is based on hash, then the user can ask to
>get the xmit slave assume all the slaves can transmit by setting the
>LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>
>Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>---
> include/linux/netdevice.h |  3 +++
> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 35 insertions(+)
>
>diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>index 130a668049ab..e8852f3ad0b6 100644
>--- a/include/linux/netdevice.h
>+++ b/include/linux/netdevice.h
>@@ -1389,6 +1389,9 @@ struct net_device_ops {
> 						 struct netlink_ext_ack *extack);
> 	int			(*ndo_del_slave)(struct net_device *dev,
> 						 struct net_device *slave_dev);
>+	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>+						      struct sk_buff *skb,
>+						      u16 flags);

Please adjust the name to:
ndo_get_lag_xmit_slave



> 	netdev_features_t	(*ndo_fix_features)(struct net_device *dev,
> 						    netdev_features_t features);
> 	int			(*ndo_set_features)(struct net_device *dev,
>diff --git a/include/net/lag.h b/include/net/lag.h
>index 95b880e6fdde..c43b035989c4 100644
>--- a/include/net/lag.h
>+++ b/include/net/lag.h
>@@ -6,6 +6,38 @@
> #include <linux/if_team.h>
> #include <net/bonding.h>
> 
>+enum lag_get_slaves_flags {
>+	LAG_FLAGS_HASH_ALL_SLAVES = 1<<0

Enum name and the values should be in sync. Also sync with the ndo name.

Why exactly do you need these flags? Do you anticipate more of them?
A simple bool arg to the ndo would do I believe. Can be changed later if
needed.



>+};
>+
>+/**
>+ * master_xmit_slave_get - Get the xmit slave of master device
>+ * @skb: The packet
>+ * @flags: lag_get_slaves_flags
>+ *
>+ * This can be called from any context and does its own locking.
>+ * The returned handle has the usage count incremented and the caller must
>+ * use dev_put() to release it when it is no longer needed.
>+ * %NULL is returned if no slave is found.
>+ */
>+
>+static inline
>+struct net_device *master_xmit_get_slave(struct net_device *master_dev,

Please honor the namespace:
net_lag_get_xmit_slave

Also, just "struct net_device *dev" would be enough.



>+					 struct sk_buff *skb,
>+					 u16 flags)
>+{
>+	const struct net_device_ops *ops = master_dev->netdev_ops;
>+	struct net_device *slave = NULL;

"slave_dev" please.

Just check the ndo here and return NULL if it is not defined. That way
you avoid unnecessary NULL initialization and rcu lock.


>+
>+	rcu_read_lock();
>+	if (ops->ndo_xmit_get_slave)
>+		slave = ops->ndo_xmit_get_slave(master_dev, skb, flags);
>+	if (slave)
>+		dev_hold(slave);
>+	rcu_read_unlock();
>+	return slave;
>+}
>+
> static inline bool net_lag_port_dev_txable(const struct net_device *port_dev)
> {
> 	if (netif_is_team_port(port_dev))
>-- 
>2.17.2
>
David Ahern April 20, 2020, 5:29 p.m. UTC | #2
On 4/20/20 8:01 AM, Jiri Pirko wrote:
> Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>> Add new ndo to get the xmit slave of master device.
>> User should release the slave when it's not longer needed.
>> When slave selection method is based on hash, then the user can ask to
>> get the xmit slave assume all the slaves can transmit by setting the
>> LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>>
>> Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>> ---
>> include/linux/netdevice.h |  3 +++
>> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
>> 2 files changed, 35 insertions(+)
>>
>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>> index 130a668049ab..e8852f3ad0b6 100644
>> --- a/include/linux/netdevice.h
>> +++ b/include/linux/netdevice.h
>> @@ -1389,6 +1389,9 @@ struct net_device_ops {
>> 						 struct netlink_ext_ack *extack);
>> 	int			(*ndo_del_slave)(struct net_device *dev,
>> 						 struct net_device *slave_dev);
>> +	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>> +						      struct sk_buff *skb,
>> +						      u16 flags);
> 
> Please adjust the name to:
> ndo_get_lag_xmit_slave

I disagree. There are multiple master devices and no reason to have a
LAG specific get_slave.
Jiri Pirko April 20, 2020, 5:41 p.m. UTC | #3
Mon, Apr 20, 2020 at 07:29:15PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 8:01 AM, Jiri Pirko wrote:
>> Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>>> Add new ndo to get the xmit slave of master device.
>>> User should release the slave when it's not longer needed.
>>> When slave selection method is based on hash, then the user can ask to
>>> get the xmit slave assume all the slaves can transmit by setting the
>>> LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>>>
>>> Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>>> ---
>>> include/linux/netdevice.h |  3 +++
>>> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
>>> 2 files changed, 35 insertions(+)
>>>
>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>> index 130a668049ab..e8852f3ad0b6 100644
>>> --- a/include/linux/netdevice.h
>>> +++ b/include/linux/netdevice.h
>>> @@ -1389,6 +1389,9 @@ struct net_device_ops {
>>> 						 struct netlink_ext_ack *extack);
>>> 	int			(*ndo_del_slave)(struct net_device *dev,
>>> 						 struct net_device *slave_dev);
>>> +	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>>> +						      struct sk_buff *skb,
>>> +						      u16 flags);
>> 
>> Please adjust the name to:
>> ndo_get_lag_xmit_slave
>
>I disagree. There are multiple master devices and no reason to have a
>LAG specific get_slave.

Do you have usecase for any other non-lag master type device?
Note the ndo name can change whenever needed. I think the name should
reflect the usage.
David Ahern April 20, 2020, 5:43 p.m. UTC | #4
On 4/20/20 11:41 AM, Jiri Pirko wrote:
>>
>> I disagree. There are multiple master devices and no reason to have a
>> LAG specific get_slave.
> 
> Do you have usecase for any other non-lag master type device?
> Note the ndo name can change whenever needed. I think the name should
> reflect the usage.
> 

right now, no. But nothing about the current need is LAG specific, so
don't make it seem like it is LAG specific with the name.
Jiri Pirko April 20, 2020, 5:53 p.m. UTC | #5
Mon, Apr 20, 2020 at 07:43:14PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 11:41 AM, Jiri Pirko wrote:
>>>
>>> I disagree. There are multiple master devices and no reason to have a
>>> LAG specific get_slave.
>> 
>> Do you have usecase for any other non-lag master type device?
>> Note the ndo name can change whenever needed. I think the name should
>> reflect the usage.
>> 
>
>right now, no. But nothing about the current need is LAG specific, so
>don't make it seem like it is LAG specific with the name.

I don't care really, I just thought we can make the connection by the
name. Makes sense to me.
Jiri Pirko April 20, 2020, 5:54 p.m. UTC | #6
Mon, Apr 20, 2020 at 07:29:15PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 8:01 AM, Jiri Pirko wrote:
>> Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>>> Add new ndo to get the xmit slave of master device.
>>> User should release the slave when it's not longer needed.
>>> When slave selection method is based on hash, then the user can ask to
>>> get the xmit slave assume all the slaves can transmit by setting the
>>> LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>>>
>>> Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>>> ---
>>> include/linux/netdevice.h |  3 +++
>>> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
>>> 2 files changed, 35 insertions(+)
>>>
>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>> index 130a668049ab..e8852f3ad0b6 100644
>>> --- a/include/linux/netdevice.h
>>> +++ b/include/linux/netdevice.h
>>> @@ -1389,6 +1389,9 @@ struct net_device_ops {
>>> 						 struct netlink_ext_ack *extack);
>>> 	int			(*ndo_del_slave)(struct net_device *dev,
>>> 						 struct net_device *slave_dev);
>>> +	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>>> +						      struct sk_buff *skb,
>>> +						      u16 flags);
>> 
>> Please adjust the name to:
>> ndo_get_lag_xmit_slave
>
>I disagree. There are multiple master devices and no reason to have a
>LAG specific get_slave.

Btw, did you notice that Maor is passing "lag" named values in the flags?
David Ahern April 20, 2020, 5:56 p.m. UTC | #7
On 4/20/20 11:54 AM, Jiri Pirko wrote:
> Mon, Apr 20, 2020 at 07:29:15PM CEST, dsahern@gmail.com wrote:
>> On 4/20/20 8:01 AM, Jiri Pirko wrote:
>>> Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>>>> Add new ndo to get the xmit slave of master device.
>>>> User should release the slave when it's not longer needed.
>>>> When slave selection method is based on hash, then the user can ask to
>>>> get the xmit slave assume all the slaves can transmit by setting the
>>>> LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>>>>
>>>> Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>>>> ---
>>>> include/linux/netdevice.h |  3 +++
>>>> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
>>>> 2 files changed, 35 insertions(+)
>>>>
>>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>>> index 130a668049ab..e8852f3ad0b6 100644
>>>> --- a/include/linux/netdevice.h
>>>> +++ b/include/linux/netdevice.h
>>>> @@ -1389,6 +1389,9 @@ struct net_device_ops {
>>>> 						 struct netlink_ext_ack *extack);
>>>> 	int			(*ndo_del_slave)(struct net_device *dev,
>>>> 						 struct net_device *slave_dev);
>>>> +	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>>>> +						      struct sk_buff *skb,
>>>> +						      u16 flags);
>>>
>>> Please adjust the name to:
>>> ndo_get_lag_xmit_slave
>>
>> I disagree. There are multiple master devices and no reason to have a
>> LAG specific get_slave.
> 
> Btw, did you notice that Maor is passing "lag" named values in the flags?
> 

yes. I disagree with enum name, but having LAG in the name of a flag is
fine. To me that is the right place for a LAG specific request of a
generic ndo in core code.
Jiri Pirko April 20, 2020, 6:01 p.m. UTC | #8
Mon, Apr 20, 2020 at 07:56:58PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 11:54 AM, Jiri Pirko wrote:
>> Mon, Apr 20, 2020 at 07:29:15PM CEST, dsahern@gmail.com wrote:
>>> On 4/20/20 8:01 AM, Jiri Pirko wrote:
>>>> Mon, Apr 20, 2020 at 09:54:17AM CEST, maorg@mellanox.com wrote:
>>>>> Add new ndo to get the xmit slave of master device.
>>>>> User should release the slave when it's not longer needed.
>>>>> When slave selection method is based on hash, then the user can ask to
>>>>> get the xmit slave assume all the slaves can transmit by setting the
>>>>> LAG_FLAGS_HASH_ALL_SLAVES bit in the flags argument.
>>>>>
>>>>> Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
>>>>> ---
>>>>> include/linux/netdevice.h |  3 +++
>>>>> include/net/lag.h         | 32 ++++++++++++++++++++++++++++++++
>>>>> 2 files changed, 35 insertions(+)
>>>>>
>>>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>>>> index 130a668049ab..e8852f3ad0b6 100644
>>>>> --- a/include/linux/netdevice.h
>>>>> +++ b/include/linux/netdevice.h
>>>>> @@ -1389,6 +1389,9 @@ struct net_device_ops {
>>>>> 						 struct netlink_ext_ack *extack);
>>>>> 	int			(*ndo_del_slave)(struct net_device *dev,
>>>>> 						 struct net_device *slave_dev);
>>>>> +	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
>>>>> +						      struct sk_buff *skb,
>>>>> +						      u16 flags);
>>>>
>>>> Please adjust the name to:
>>>> ndo_get_lag_xmit_slave
>>>
>>> I disagree. There are multiple master devices and no reason to have a
>>> LAG specific get_slave.
>> 
>> Btw, did you notice that Maor is passing "lag" named values in the flags?
>> 
>
>yes. I disagree with enum name, but having LAG in the name of a flag is
>fine. To me that is the right place for a LAG specific request of a
>generic ndo in core code.

Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
this is ever going to be used for other master. And if so, could be very
easily renamed then...
David Ahern April 20, 2020, 6:04 p.m. UTC | #9
On 4/20/20 12:01 PM, Jiri Pirko wrote:
> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
> this is ever going to be used for other master. And if so, could be very
> easily renamed then...

core code should be generic, not specific and renamed at a later date
when a second use case arises.
Jiri Pirko April 20, 2020, 6:48 p.m. UTC | #10
Mon, Apr 20, 2020 at 08:04:01PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 12:01 PM, Jiri Pirko wrote:
>> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
>> this is ever going to be used for other master. And if so, could be very
>> easily renamed then...
>
>core code should be generic, not specific and renamed at a later date
>when a second use case arises.

Yeah, I guess we just have to agree to disagree :)
Maor Gottlieb April 20, 2020, 6:56 p.m. UTC | #11
On 4/20/2020 9:48 PM, Jiri Pirko wrote:
> Mon, Apr 20, 2020 at 08:04:01PM CEST, dsahern@gmail.com wrote:
>> On 4/20/20 12:01 PM, Jiri Pirko wrote:
>>> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
>>> this is ever going to be used for other master. And if so, could be very
>>> easily renamed then...
>> core code should be generic, not specific and renamed at a later date
>> when a second use case arises.
> Yeah, I guess we just have to agree to disagree :)

So I am remaining with the flags. Any suggestion for better name for the 
enum? Should I move master_xmit_get_slave from lag.h to netdevice.h?
>
David Ahern April 20, 2020, 7:02 p.m. UTC | #12
On 4/20/20 12:56 PM, Maor Gottlieb wrote:
> 
> On 4/20/2020 9:48 PM, Jiri Pirko wrote:
>> Mon, Apr 20, 2020 at 08:04:01PM CEST, dsahern@gmail.com wrote:
>>> On 4/20/20 12:01 PM, Jiri Pirko wrote:
>>>> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
>>>> this is ever going to be used for other master. And if so, could be
>>>> very
>>>> easily renamed then...
>>> core code should be generic, not specific and renamed at a later date
>>> when a second use case arises.
>> Yeah, I guess we just have to agree to disagree :)
> 
> So I am remaining with the flags. Any suggestion for better name for the
> enum? Should I move master_xmit_get_slave from lag.h to netdevice.h?
>>

IMHO, yes, that is a better place.

generic ndo name and implementation.
type specific flag as needed.

This is consistent with net_device and ndo - both generic concepts -
with specifics relegated to flags (e.g., IFF_*)
Jiri Pirko April 21, 2020, 5:37 a.m. UTC | #13
Mon, Apr 20, 2020 at 09:02:58PM CEST, dsahern@gmail.com wrote:
>On 4/20/20 12:56 PM, Maor Gottlieb wrote:
>> 
>> On 4/20/2020 9:48 PM, Jiri Pirko wrote:
>>> Mon, Apr 20, 2020 at 08:04:01PM CEST, dsahern@gmail.com wrote:
>>>> On 4/20/20 12:01 PM, Jiri Pirko wrote:
>>>>> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
>>>>> this is ever going to be used for other master. And if so, could be
>>>>> very
>>>>> easily renamed then...
>>>> core code should be generic, not specific and renamed at a later date
>>>> when a second use case arises.
>>> Yeah, I guess we just have to agree to disagree :)
>> 
>> So I am remaining with the flags. Any suggestion for better name for the
>> enum? Should I move master_xmit_get_slave from lag.h to netdevice.h?
>>>
>
>IMHO, yes, that is a better place.
>
>generic ndo name and implementation.
>type specific flag as needed.
>
>This is consistent with net_device and ndo - both generic concepts -
>with specifics relegated to flags (e.g., IFF_*)

Why there is need for flags? Why a single bool can't do as I suggested?
Do you see any usecase for another flag?
Maor Gottlieb April 21, 2020, 5:43 a.m. UTC | #14
On 4/21/2020 8:37 AM, Jiri Pirko wrote:
> Mon, Apr 20, 2020 at 09:02:58PM CEST, dsahern@gmail.com wrote:
>> On 4/20/20 12:56 PM, Maor Gottlieb wrote:
>>> On 4/20/2020 9:48 PM, Jiri Pirko wrote:
>>>> Mon, Apr 20, 2020 at 08:04:01PM CEST, dsahern@gmail.com wrote:
>>>>> On 4/20/20 12:01 PM, Jiri Pirko wrote:
>>>>>> Generic ndo with lag-specific arg? Odd. Plus, there is a small chance
>>>>>> this is ever going to be used for other master. And if so, could be
>>>>>> very
>>>>>> easily renamed then...
>>>>> core code should be generic, not specific and renamed at a later date
>>>>> when a second use case arises.
>>>> Yeah, I guess we just have to agree to disagree :)
>>> So I am remaining with the flags. Any suggestion for better name for the
>>> enum? Should I move master_xmit_get_slave from lag.h to netdevice.h?
>> IMHO, yes, that is a better place.
>>
>> generic ndo name and implementation.
>> type specific flag as needed.
>>
>> This is consistent with net_device and ndo - both generic concepts -
>> with specifics relegated to flags (e.g., IFF_*)
> Why there is need for flags? Why a single bool can't do as I suggested?
> Do you see any usecase for another flag?

Currently no. I am okay with single bool.
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 130a668049ab..e8852f3ad0b6 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1389,6 +1389,9 @@  struct net_device_ops {
 						 struct netlink_ext_ack *extack);
 	int			(*ndo_del_slave)(struct net_device *dev,
 						 struct net_device *slave_dev);
+	struct net_device*	(*ndo_xmit_get_slave)(struct net_device *master_dev,
+						      struct sk_buff *skb,
+						      u16 flags);
 	netdev_features_t	(*ndo_fix_features)(struct net_device *dev,
 						    netdev_features_t features);
 	int			(*ndo_set_features)(struct net_device *dev,
diff --git a/include/net/lag.h b/include/net/lag.h
index 95b880e6fdde..c43b035989c4 100644
--- a/include/net/lag.h
+++ b/include/net/lag.h
@@ -6,6 +6,38 @@ 
 #include <linux/if_team.h>
 #include <net/bonding.h>
 
+enum lag_get_slaves_flags {
+	LAG_FLAGS_HASH_ALL_SLAVES = 1<<0
+};
+
+/**
+ * master_xmit_slave_get - Get the xmit slave of master device
+ * @skb: The packet
+ * @flags: lag_get_slaves_flags
+ *
+ * This can be called from any context and does its own locking.
+ * The returned handle has the usage count incremented and the caller must
+ * use dev_put() to release it when it is no longer needed.
+ * %NULL is returned if no slave is found.
+ */
+
+static inline
+struct net_device *master_xmit_get_slave(struct net_device *master_dev,
+					 struct sk_buff *skb,
+					 u16 flags)
+{
+	const struct net_device_ops *ops = master_dev->netdev_ops;
+	struct net_device *slave = NULL;
+
+	rcu_read_lock();
+	if (ops->ndo_xmit_get_slave)
+		slave = ops->ndo_xmit_get_slave(master_dev, skb, flags);
+	if (slave)
+		dev_hold(slave);
+	rcu_read_unlock();
+	return slave;
+}
+
 static inline bool net_lag_port_dev_txable(const struct net_device *port_dev)
 {
 	if (netif_is_team_port(port_dev))