Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 02/13] net: sched: act_bpf method rename for grep-ability and consistency
From: Jamal Hadi Salim @ 2018-08-12 13:34 UTC (permalink / raw)
  To: davem; +Cc: xiyou.wangcong, jiri, netdev, kernel, Jamal Hadi Salim
In-Reply-To: <20180812133501.15278-1-jhs@emojatatu.com>

From: Jamal Hadi Salim <jhs@mojatatu.com>

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/sched/act_bpf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index 9e8a33f9fee3..9b30e62805c7 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -34,8 +34,8 @@ struct tcf_bpf_cfg {
 static unsigned int bpf_net_id;
 static struct tc_action_ops act_bpf_ops;
 
-static int tcf_bpf(struct sk_buff *skb, const struct tc_action *act,
-		   struct tcf_result *res)
+static int tcf_bpf_act(struct sk_buff *skb, const struct tc_action *act,
+		       struct tcf_result *res)
 {
 	bool at_ingress = skb_at_tc_ingress(skb);
 	struct tcf_bpf *prog = to_bpf(act);
@@ -406,7 +406,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
 	.kind		=	"bpf",
 	.type		=	TCA_ACT_BPF,
 	.owner		=	THIS_MODULE,
-	.act		=	tcf_bpf,
+	.act		=	tcf_bpf_act,
 	.dump		=	tcf_bpf_dump,
 	.cleanup	=	tcf_bpf_cleanup,
 	.init		=	tcf_bpf_init,
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 01/13] net: sched: act_connmark method rename for grep-ability and consistency
From: Jamal Hadi Salim @ 2018-08-12 13:34 UTC (permalink / raw)
  To: davem; +Cc: xiyou.wangcong, jiri, netdev, kernel, Jamal Hadi Salim
In-Reply-To: <20180812133501.15278-1-jhs@emojatatu.com>

From: Jamal Hadi Salim <jhs@mojatatu.com>

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/sched/act_connmark.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 2f9bc833d046..54c0bf54f2ac 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -31,8 +31,8 @@
 static unsigned int connmark_net_id;
 static struct tc_action_ops act_connmark_ops;
 
-static int tcf_connmark(struct sk_buff *skb, const struct tc_action *a,
-			struct tcf_result *res)
+static int tcf_connmark_act(struct sk_buff *skb, const struct tc_action *a,
+			    struct tcf_result *res)
 {
 	const struct nf_conntrack_tuple_hash *thash;
 	struct nf_conntrack_tuple tuple;
@@ -209,7 +209,7 @@ static struct tc_action_ops act_connmark_ops = {
 	.kind		=	"connmark",
 	.type		=	TCA_ACT_CONNMARK,
 	.owner		=	THIS_MODULE,
-	.act		=	tcf_connmark,
+	.act		=	tcf_connmark_act,
 	.dump		=	tcf_connmark_dump,
 	.init		=	tcf_connmark_init,
 	.walk		=	tcf_connmark_walker,
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 00/13] net: sched: actions rename for grep-ability and consistency
From: Jamal Hadi Salim @ 2018-08-12 13:34 UTC (permalink / raw)
  To: davem; +Cc: xiyou.wangcong, jiri, netdev, kernel, Jamal Hadi Salim

From: Jamal Hadi Salim <jhs@mojatatu.com>

Having a structure (example tcf_mirred) and a function with the same name is
not good for readability or grepability.

This long overdue patchset improves it and make sure there is consistency
across all actions

Jamal Hadi Salim (13):
  net: sched: act_connmark method rename for grep-ability and
    consistency
  net: sched: act_bpf method rename for grep-ability and consistency
  net: sched: act_sum method rename for grep-ability and consistency
  net: sched: act_gact method rename for grep-ability and consistency
  net: sched: act_ipt method rename for grep-ability and consistency
  net: sched: act_nat method rename for grep-ability and consistency
  net: sched: act_pedit method rename for grep-ability and consistency
  net: sched: act_police method rename for grep-ability and consistency
  net: sched: act_simple method rename for grep-ability and consistency
  net: sched: act_skbedit method rename for grep-ability and consistency
  net: sched: act_skbmod method rename for grep-ability and consistency
  net: sched: act_vlan method rename for grep-ability and consistency
  net: sched: act_mirred method rename for grep-ability and consistency

 net/sched/act_bpf.c      |  6 +++---
 net/sched/act_connmark.c |  6 +++---
 net/sched/act_csum.c     |  6 +++---
 net/sched/act_gact.c     |  6 +++---
 net/sched/act_ipt.c      |  8 ++++----
 net/sched/act_mirred.c   |  6 +++---
 net/sched/act_nat.c      |  6 +++---
 net/sched/act_pedit.c    |  6 +++---
 net/sched/act_police.c   | 16 ++++++++--------
 net/sched/act_simple.c   |  6 +++---
 net/sched/act_skbedit.c  |  6 +++---
 net/sched/act_skbmod.c   |  4 ++--
 net/sched/act_vlan.c     |  6 +++---
 13 files changed, 44 insertions(+), 44 deletions(-)

-- 
2.11.0

^ permalink raw reply

* [PATCH net-next v2] cpumask: make cpumask_next_wrap available without smp
From: Willem de Bruijn @ 2018-08-12 13:14 UTC (permalink / raw)
  To: netdev; +Cc: davem, caleb.raitto, lkp, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

The kbuild robot shows build failure on machines without CONFIG_SMP:

  drivers/net/virtio_net.c:1916:10: error:
    implicit declaration of function 'cpumask_next_wrap'

cpumask_next_wrap is exported from lib/cpumask.o, which has

    lib-$(CONFIG_SMP) += cpumask.o

same as other functions, also define it as static inline in the
NR_CPUS==1 branch in include/linux/cpumask.h.

If wrap is true and next == start, return nr_cpumask_bits, or 1.
Else wrap across the range of valid cpus, here [0].

Fixes: 2ca653d607ce ("virtio_net: Stripe queue affinities across cores.")
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 include/linux/cpumask.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 57f20a0a77949..147bdec42215d 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -159,6 +159,13 @@ static inline unsigned int cpumask_next_and(int n,
 	return n+1;
 }
 
+static inline unsigned int cpumask_next_wrap(int n, const struct cpumask *mask,
+					     int start, bool wrap)
+{
+	/* cpu0 unless stop condition, wrap and at cpu0, then nr_cpumask_bits */
+	return (wrap && n == 0);
+}
+
 /* cpu must be a valid cpu, ie 0, so there's no other choice. */
 static inline unsigned int cpumask_any_but(const struct cpumask *mask,
 					   unsigned int cpu)
-- 
2.18.0.597.ga71716f1ad-goog

^ permalink raw reply related

* [PATCH] mt76: Enable NL80211_EXT_FEATURE_CQM_RSSI_LIST
From: Kristian Evensen @ 2018-08-12 14:52 UTC (permalink / raw)
  To: linux-wireless, kvalo, netdev, linux-kernel; +Cc: Kristian Evensen

Enable the use of CQM with mt76-devices.

Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 029d54bc..3eb328ff 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -305,6 +305,8 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
 
 	wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
 
+	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
+
 	wiphy->available_antennas_tx = dev->antenna_mask;
 	wiphy->available_antennas_rx = dev->antenna_mask;
 
-- 
2.14.1

^ permalink raw reply related

* Re: [PATCH] of: mdio: Support fixed links in of_phy_get_and_connect()
From: Linus Walleij @ 2018-08-12 11:54 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Florian Fainelli, David S. Miller, netdev, Laurent Pinchart
In-Reply-To: <20180711200452.GD21430@lunn.ch>

On Wed, Jul 11, 2018 at 10:04 PM Andrew Lunn <andrew@lunn.ch> wrote:

> What probably make sense as a followup is add a
> of_phy_disconnect_and_put(). When the module is unloaded, you leak a
> fixed link, because of_phy_deregister_fixed_link() is not being
> called.

I looked at this but I get a bit confused. How to handle
cleanup of the fixed link is pretty straight forward, I'm more
concerned with the proper (today non-existing) way to clean
up after of_phy_connect() that is called for all instances.

This calls phy_connect_direct() that then does this:

/* refcount is held by phy_connect_direct() on success */
put_device(&phy->mdio.dev);

Which seems like wrong - it should keep holding that until
we do of_phy_disconnect_and_put() in that case.
The above seems like some hack, i.e. we are using the
MDIO without holding a reference or something, so it
can go away cleanly later.

Or do I have it wrong?

It's confusing, I guess these PHY's don't come and go
very much so the plug/play part isn't really exercised.

> You also hold a reference to np which does not appear to be
> released.

That seems to be covered as there is a of_node_put(phy_np);
at the end of this function already.

Balancing of_node_get()/put() is another area where there
is not (AFAICT) much stringency in the kernel. I loosely
believe this is mostly for dynamic device trees (so you do not
delete a node that is in use e.g.) and people don't use that
very much (or at all). I think most systems shut down with
a bunch of OF nodes held. :/

(Yeah another universe of cleanups the day we need it
to work.)

Yours,
Linus Walleij

^ permalink raw reply

* [PATCH net] r8169: don't use MSI-X on RTL8168g
From: Heiner Kallweit @ 2018-08-12 11:26 UTC (permalink / raw)
  To: David Miller, Realtek linux nic maintainers; +Cc: netdev@vger.kernel.org

There have been two reports that network doesn't come back on resume
from suspend when using MSI-X. Both cases affect the same chip version
(RTL8168g - version 40), on different systems. Falling back to MSI
fixes the issue.
Even though we don't really have a proof yet that the network chip
version is to blame, let's disable MSI-X for this version.

Reported-by: Steve Dodd <steved424@gmail.com>
Reported-by: Lou Reed <gogen@disroot.org>
Tested-by: Steve Dodd <steved424@gmail.com>
Tested-by: Lou Reed <gogen@disroot.org>
Fixes: 6c6aa15fdea5 ("r8169: improve interrupt handling")
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/realtek/r8169.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 344d77d9..d103e4dd 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7076,6 +7076,11 @@ static int rtl_alloc_irq(struct rtl8169_private *tp)
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
 		RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 		flags = PCI_IRQ_LEGACY;
+	} else if (tp->mac_version == RTL_GIGA_MAC_VER_40) {
+		/* This version was reported to have issues with resume
+		 * from suspend when using MSI-X
+		 */
+		flags = PCI_IRQ_LEGACY | PCI_IRQ_MSI;
 	} else {
 		flags = PCI_IRQ_ALL_TYPES;
 	}
-- 
2.18.0

^ permalink raw reply related

* want to have a try
From: Joe @ 2018-08-12  9:56 UTC (permalink / raw)
  To: netdev

Are you upset for your current business s a l e s?

We provide email C A M P A I G N service and we can bring you business l e
a d s and up your s a l e s.

Please reply today so we can send options for you.

Kind Regards,
Joe

^ permalink raw reply

* Re: [PATCH net-next] cpumask: make cpumask_next_wrap available without smp
From: Willem de Bruijn @ 2018-08-12 11:15 UTC (permalink / raw)
  To: Network Development
  Cc: David Miller, caleb.raitto, kbuild test robot, Willem de Bruijn
In-Reply-To: <20180812092014.122104-1-willemdebruijn.kernel@gmail.com>

On Sun, Aug 12, 2018 at 11:20 AM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> From: Willem de Bruijn <willemb@google.com>
>
> The kbuild robot shows build failure on machines without CONFIG_SMP:
>
>   drivers/net/virtio_net.c:1916:10: error:
>     implicit declaration of function 'cpumask_next_wrap'
>
> cpumask_next_wrap is exported from lib/cpumask.o, which has
>
>     lib-$(CONFIG_SMP) += cpumask.o
>
> same as other functions, also define it as static inline in the
> NR_CPUS==1 branch in include/linux/cpumask.h.
>
> If wrap is false, function wraps across the range of valid cpus,
> here [0]. If it is true, it returns nr_cpumask_bits, here 1.
>
> Fixes: 2ca653d607ce ("virtio_net: Stripe queue affinities across cores.")
> Signed-off-by: Willem de Bruijn <willemb@google.com>

Sent too hastily. If wrap is true and n == -1, it should still return 0.

Will send a v2.

^ permalink raw reply

* REPLY AS SOON AS POSSIBLE
From: Dr Chien Direktor von Hang Seng @ 2018-08-11 22:49 UTC (permalink / raw)
  To: Recipients

I am Vice Chairman of Hang Seng Bank, I have Important Matter to Discuss with you concerning my late client. Died without a NEXT OF KIN. Send me your private email for full details information. email me at E-Mail: draymdm@gmail.com

Regards 
Mr.Fung

^ permalink raw reply

* [PATCH net-next] cpumask: make cpumask_next_wrap available without smp
From: Willem de Bruijn @ 2018-08-12  9:20 UTC (permalink / raw)
  To: netdev; +Cc: davem, caleb.raitto, lkp, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

The kbuild robot shows build failure on machines without CONFIG_SMP:

  drivers/net/virtio_net.c:1916:10: error:
    implicit declaration of function 'cpumask_next_wrap'

cpumask_next_wrap is exported from lib/cpumask.o, which has

    lib-$(CONFIG_SMP) += cpumask.o

same as other functions, also define it as static inline in the
NR_CPUS==1 branch in include/linux/cpumask.h.

If wrap is false, function wraps across the range of valid cpus,
here [0]. If it is true, it returns nr_cpumask_bits, here 1.

Fixes: 2ca653d607ce ("virtio_net: Stripe queue affinities across cores.")
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 include/linux/cpumask.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 57f20a0a77949..c6d0967102fe3 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -159,6 +159,12 @@ static inline unsigned int cpumask_next_and(int n,
 	return n+1;
 }
 
+static inline unsigned int cpumask_next_wrap(int n, const struct cpumask *mask,
+					     int start, bool wrap)
+{
+	return wrap;	/* cpu 0 unless stop on wrap, then nr_cpumask_bits */
+}
+
 /* cpu must be a valid cpu, ie 0, so there's no other choice. */
 static inline unsigned int cpumask_any_but(const struct cpumask *mask,
 					   unsigned int cpu)
-- 
2.18.0.597.ga71716f1ad-goog

^ permalink raw reply related

* Re: [PATCH net] net/xdp: Fix suspicious RCU usage warning
From: Tariq Toukan @ 2018-08-12  8:45 UTC (permalink / raw)
  To: Alexei Starovoitov, Tariq Toukan
  Cc: Daniel Borkmann, David S. Miller, netdev, Eran Ben Elisha,
	Jesper Dangaard Brouer
In-Reply-To: <20180719213628.msccswfqkzwo5vrk@ast-mbp>



On 20/07/2018 12:36 AM, Alexei Starovoitov wrote:
> On Wed, Jul 18, 2018 at 05:13:54PM +0300, Tariq Toukan wrote:
>>
>>
>> On 17/07/2018 10:27 PM, Daniel Borkmann wrote:
>>> On 07/17/2018 06:47 PM, Alexei Starovoitov wrote:
>>>> On Tue, Jul 17, 2018 at 06:10:38PM +0300, Tariq Toukan wrote:
>>>>> Fix the warning below by calling rhashtable_lookup under
>>>>> RCU read lock.
>>>>>
>>
>> ...
>>
>>>>>    	mutex_lock(&mem_id_lock);
>>>>> +	rcu_read_lock();
>>>>>    	xa = rhashtable_lookup(mem_id_ht, &id, mem_id_rht_params);
>>>>> +	rcu_read_unlock();
>>>>>    	if (!xa) {
>>>>
>>>> if it's an actual bug rcu_read_unlock seems to be misplaced.
>>>> It silences the warn, but rcu section looks wrong.
>>>
>>> I think that whole piece in __xdp_rxq_info_unreg_mem_model() should be:
>>>
>>>     mutex_lock(&mem_id_lock);
>>>     xa = rhashtable_lookup_fast(mem_id_ht, &id, mem_id_rht_params);
>>>     if (xa && rhashtable_remove_fast(mem_id_ht, &xa->node, mem_id_rht_params) == 0)
>>>             call_rcu(&xa->rcu, __xdp_mem_allocator_rcu_free);
>>>     mutex_unlock(&mem_id_lock);
>>>
>>> Technically the RCU read side plus rhashtable_lookup() is the same, but lets
>>> use proper api. From the doc (https://lwn.net/Articles/751374/) object removal
>>> is wrapped around the RCU read side additionally, but in our case we're behind
>>> mem_id_lock for insertion/removal serialization.
>>>
>>> Cheers,
>>> Daniel
>>>
>>
>> Just as Daniel stated, I think there's no actual bug here, but we still want
>> to silence the RCU warning.
>>
>> Alexei, did you mean getting the if statement into the RCU lock critical
>> section?
> 
> If what Daniel proposes silences the warn, I'd rather do that.
> Pattern like:
>    rcu_lock;
>    val = lookup();
>    rcu_unlock;
>    if (val)
> will cause people to question the quality of the code and whether
> authors of the code understand rcu.
> There should be a way to silence the warn without adding
> "wrong on the first glance" code.
> 

I'm re-spinning this.
Can it still go to net, or better send it to bpf-next ?

^ permalink raw reply

* Re: [PATCH v2 net-next 0/2] virtio_net: Expand affinity to arbitrary numbers of cpu and vq
From: Michael S. Tsirkin @ 2018-08-12  8:44 UTC (permalink / raw)
  To: Caleb Raitto
  Cc: herbert, davem, arei.gonglei, jasowang, netdev, linux-crypto,
	Caleb Raitto
In-Reply-To: <20180810011828.199888-1-caleb.raitto@gmail.com>

On Thu, Aug 09, 2018 at 06:18:27PM -0700, Caleb Raitto wrote:
> From: Caleb Raitto <caraitto@google.com>
> 
> Virtio-net tries to pin each virtual queue rx and tx interrupt to a cpu if
> there are as many queues as cpus.
> 
> Expand this heuristic to configure a reasonable affinity setting also
> when the number of cpus != the number of virtual queues.
> 
> Patch 1 allows vqs to take an affinity mask with more than 1 cpu.
> Patch 2 generalizes the algorithm in virtnet_set_affinity beyond
> the case where #cpus == #vqs.

Acked-by: Michael S. Tsirkin <mst@redhat.com>

Let's see where does it take us.

> v2 changes:
> Renamed "virtio_net: Make vp_set_vq_affinity() take a mask." to
> "virtio: Make vp_set_vq_affinity() take a mask."
> 
> Tested:
> 
> # 16 vCPU, 16 queue pairs, Debian 9 recent net-next kernel, GCE
> 
> # Disable GCE scripts setting affinities during startup.
> #
> # Add the following to
> # /etc/default/instance_configs.cfg.template and reboot:
> [InstanceSetup]
> set_multiqueue = false
> 
> $ cd /proc/irq
> $ for i in `seq 24 60` ; do sudo grep ".*" $i/smp_affinity_list;  done
> 0-15
> 0
> 0
> 1
> 1
> 2
> 2
> 3
> 3
> 4
> 4
> 5
> 5
> 6
> 6
> 7
> 7
> 8
> 8
> 9
> 9
> 10
> 10
> 11
> 11
> 12
> 12
> 13
> 13
> 14
> 14
> 15
> 15
> 0-15
> 0-15
> 0-15
> 0-15
> 
> $ cd /sys/class/net/eth0/queues/
> $ for i in `seq 0 15` ; do sudo grep ".*" tx-$i/xps_cpus; done
> 0001
> 0002
> 0004
> 0008
> 0010
> 0020
> 0040
> 0080
> 0100
> 0200
> 0400
> 0800
> 1000
> 2000
> 4000
> 8000
> 
> # 16 vCPU, 15 queue pairs
> $ sudo ethtool -L eth0 combined 15
> 
> $ cd /proc/irq
> $ for i in `seq 24 60` ; do sudo grep ".*" $i/smp_affinity_list;  done
> 0-15
> 0-1
> 0-1
> 2
> 2
> 3
> 3
> 4
> 4
> 5
> 5
> 6
> 6
> 7
> 7
> 8
> 8
> 9
> 9
> 10
> 10
> 11
> 11
> 12
> 12
> 13
> 13
> 14
> 14
> 15
> 15
> 15
> 15
> 0-15
> 0-15
> 0-15
> 0-15
> 
> $ cd /sys/class/net/eth0/queues/
> $ for i in `seq 0 14` ; do sudo grep ".*" tx-$i/xps_cpus; done
> 0003
> 0004
> 0008
> 0010
> 0020
> 0040
> 0080
> 0100
> 0200
> 0400
> 0800
> 1000
> 2000
> 4000
> 8000
> 
> # 16 vCPU, 8 queue pairs
> $ sudo ethtool -L eth0 combined 8
> 
> $ cd /proc/irq
> $ for i in `seq 24 60` ; do sudo grep ".*" $i/smp_affinity_list;  done
> 0-15
> 0-1
> 0-1
> 2-3
> 2-3
> 4-5
> 4-5
> 6-7
> 6-7
> 8-9
> 8-9
> 10-11
> 10-11
> 12-13
> 12-13
> 14-15
> 14-15
> 9
> 9
> 10
> 10
> 11
> 11
> 12
> 12
> 13
> 13
> 14
> 14
> 15
> 15
> 15
> 15
> 0-15
> 0-15
> 0-15
> 0-15
> 
> $ cd /sys/class/net/eth0/queues/
> $ for i in `seq 0 7` ; do sudo grep ".*" tx-$i/xps_cpus; done
> 0003
> 000c
> 0030
> 00c0
> 0300
> 0c00
> 3000
> c000
> 
> # 15 vCPU, 16 queue pairs
> $ sudo ethtool -L eth0 combined 16
> $ sudo sh -c "echo 0 > /sys/devices/system/cpu/cpu15/online"
> 
> $ cd /proc/irq
> $ for i in `seq 24 60` ; do sudo grep ".*" $i/smp_affinity_list;  done
> 0-15
> 0
> 0
> 1
> 1
> 2
> 2
> 3
> 3
> 4
> 4
> 5
> 5
> 6
> 6
> 7
> 7
> 8
> 8
> 9
> 9
> 10
> 10
> 11
> 11
> 12
> 12
> 13
> 13
> 14
> 14
> 0
> 0
> 0-15
> 0-15
> 0-15
> 0-15
> 
> $ cd /sys/class/net/eth0/queues/
> $ for i in `seq 0 15` ; do sudo grep ".*" tx-$i/xps_cpus; done
> 0001
> 0002
> 0004
> 0008
> 0010
> 0020
> 0040
> 0080
> 0100
> 0200
> 0400
> 0800
> 1000
> 2000
> 4000
> 0001
> 
> # 8 vCPU, 16 queue pairs
> $ for i in `seq 8 15`; \
> do sudo sh -c "echo 0 > /sys/devices/system/cpu/cpu$i/online"; done
> 
> $ cd /proc/irq
> $ for i in `seq 24 60` ; do sudo grep ".*" $i/smp_affinity_list;  done
> 0-15
> 0
> 0
> 1
> 1
> 2
> 2
> 3
> 3
> 4
> 4
> 5
> 5
> 6
> 6
> 7
> 7
> 0
> 0
> 1
> 1
> 2
> 2
> 3
> 3
> 4
> 4
> 5
> 5
> 6
> 6
> 7
> 7
> 0-15
> 0-15
> 0-15
> 0-15
> 
> $ cd /sys/class/net/eth0/queues/
> $ for i in `seq 0 15` ; do sudo grep ".*" tx-$i/xps_cpus; done
> 0001
> 0002
> 0004
> 0008
> 0010
> 0020
> 0040
> 0080
> 0001
> 0002
> 0004
> 0008
> 0010
> 0020
> 0040
> 0080
> 
> Caleb Raitto (2):
>   virtio: Make vp_set_vq_affinity() take a mask.
>   virtio_net: Stripe queue affinities across cores.
> 
>  drivers/crypto/virtio/virtio_crypto_core.c |  4 +-
>  drivers/net/virtio_net.c                   | 46 ++++++++++++++--------
>  drivers/virtio/virtio_pci_common.c         |  7 ++--
>  drivers/virtio/virtio_pci_common.h         |  2 +-
>  include/linux/virtio_config.h              |  7 ++--
>  5 files changed, 39 insertions(+), 27 deletions(-)
> 
> -- 
> 2.18.0.597.ga71716f1ad-goog

^ permalink raw reply

* Re: [PATCH net-next 5/5] net: aquantia: bump driver version
From: Igor Russkikh @ 2018-08-12  7:53 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Andrew Lunn, David S . Miller, netdev, Simon Edelhaus
In-Reply-To: <20180809122048.3f2d0938@cakuba.netronome.com>



>> Hope the above are good enough arguments to keep up version bumps.
> 
> A reasonably successful strategy is to version your out-of-tree driver
> with corresponding kernel release versions.  Flip the equation.
> 
> E.g. current net-next will become 4.19, so all the features you're
> pushing now would in your GH repo be:
> 
> 4.19.0.${extra_numbers_if_you_want}-gh
> 
> And you still have single versioning scheme, but the "bump to version
> XYZ" commits now go into your local tree not the kernel.
> 
> As Andrew said backports make driver versions less than useful.  Not
> only feature backports to enterprise kernel, but bug fixes which have to
> go to stable.
> 

Technically yes, thats a good and manageable suggestion.

However the problem here is a human factor.

Regular users are often aware that NIC drivers are regularly
get updates, fixes etc. And they logically assume there is a
driver version in there. And what user normally does first
time he/she buys new NIC is checking driver version in system.

Obviously what user use is `ethtool -i` since thats a documented and
the only user visible tool.

What we'll get here is totally uncorrelated versioning info between inkernel
driver (some ancient version or no version at all) and vendor driver.

This will confuse user as he/she will start thinking (for example) that his
in kernel driver is "bad" and has to be updated.

Another human factor is tech support personnel, who also expect NIC drivers
to have version. We'll get tons of requests sort of "why and when you'll update
your upstream driver". It is up to date. "But why its version is not updated then?"

A lot of technical reports from fields does not include kernel version, but
(since users talk about NIC) just an "ethtool -i" output. This'll confuse us
as we have to do more queries on kernel version.

These are all legitimate expectations from non-tech people and what we trying
to do now is to keep up inkernel versioning with our local versioning.

Thus, user now sees:

version: 2.0.3.0-kern (for inkernel driver)
or
version: 2.0.6.0 (for external driver)

and can at least judge whether he needs updates or if thats OK.

As a one liner sumup:
kernel have user visible 'ethtool -i' API. Why should we drop it and deprecate it?

BR, Igor

^ permalink raw reply

* [PATCH net-next 9/9] net: hns3: Add vlan filter setting by ethtool command -K
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Peng Li <lipeng321@huawei.com>

Revision(0x20) HW does not support enabling or disabling individual
netdev's HW_VLAN_CTAG_FILTER feature, and Revision(0x21) supports
enabling or disabling individual netdev's HW_VLAN_CTAG_FILTER
feature.

Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index b28c7e142308..3554dca7a680 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1673,6 +1673,9 @@ static struct pci_driver hns3_driver = {
 /* set default feature to hns3 */
 static void hns3_set_default_feature(struct net_device *netdev)
 {
+	struct hnae3_handle *h = hns3_get_handle(netdev);
+	struct pci_dev *pdev = h->pdev;
+
 	netdev->priv_flags |= IFF_UNICAST_FLT;
 
 	netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
@@ -1706,6 +1709,9 @@ static void hns3_set_default_feature(struct net_device *netdev)
 		NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
 		NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
 		NETIF_F_GSO_UDP_TUNNEL_CSUM;
+
+	if (pdev->revision != 0x20)
+		netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
 }
 
 static int hns3_alloc_buffer(struct hns3_enet_ring *ring,
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 8/9] net: hns3: Set tx ring' tc info when netdev is up
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Yunsheng Lin
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Yunsheng Lin <linyunsheng@huawei.com>

The HNS3_RING_TX_RING_TC_REG register is used to map tx ring to
specific tc, the tx queue to tc mapping is needed by the hardware
to do the correct tx schedule.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 24 ++++++++++++++++++++++++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index b7b9ee3f4d20..b28c7e142308 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2974,6 +2974,28 @@ static void hns3_init_ring_hw(struct hns3_enet_ring *ring)
 	}
 }
 
+static void hns3_init_tx_ring_tc(struct hns3_nic_priv *priv)
+{
+	struct hnae3_knic_private_info *kinfo = &priv->ae_handle->kinfo;
+	int i;
+
+	for (i = 0; i < HNAE3_MAX_TC; i++) {
+		struct hnae3_tc_info *tc_info = &kinfo->tc_info[i];
+		int j;
+
+		if (!tc_info->enable)
+			continue;
+
+		for (j = 0; j < tc_info->tqp_count; j++) {
+			struct hnae3_queue *q;
+
+			q = priv->ring_data[tc_info->tqp_offset + j].ring->tqp;
+			hns3_write_dev(q, HNS3_RING_TX_RING_TC_REG,
+				       tc_info->tc);
+		}
+	}
+}
+
 int hns3_init_all_ring(struct hns3_nic_priv *priv)
 {
 	struct hnae3_handle *h = priv->ae_handle;
@@ -3385,6 +3407,8 @@ int hns3_nic_reset_all_ring(struct hnae3_handle *h)
 		rx_ring->next_to_use = 0;
 	}
 
+	hns3_init_tx_ring_tc(priv);
+
 	return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 0f071a0f4ff9..a02a96aee2a2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -37,6 +37,7 @@ enum hns3_nic_state {
 #define HNS3_RING_TX_RING_BASEADDR_L_REG	0x00040
 #define HNS3_RING_TX_RING_BASEADDR_H_REG	0x00044
 #define HNS3_RING_TX_RING_BD_NUM_REG		0x00048
+#define HNS3_RING_TX_RING_TC_REG		0x00050
 #define HNS3_RING_TX_RING_TAIL_REG		0x00058
 #define HNS3_RING_TX_RING_HEAD_REG		0x0005C
 #define HNS3_RING_TX_RING_FBDNUM_REG		0x00060
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 7/9] net: hns3: Remove tx ring BD len register in hns3_enet
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Yunsheng Lin
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Yunsheng Lin <linyunsheng@huawei.com>

There is no HNS3_RING_TX_RING_BD_LEN_REG register according
to UM, so this patch removes it.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 --
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h | 1 -
 2 files changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index a64d69c87f13..b7b9ee3f4d20 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2969,8 +2969,6 @@ static void hns3_init_ring_hw(struct hns3_enet_ring *ring)
 		hns3_write_dev(q, HNS3_RING_TX_RING_BASEADDR_H_REG,
 			       (u32)((dma >> 31) >> 1));
 
-		hns3_write_dev(q, HNS3_RING_TX_RING_BD_LEN_REG,
-			       hns3_buf_size2type(ring->buf_size));
 		hns3_write_dev(q, HNS3_RING_TX_RING_BD_NUM_REG,
 			       ring->desc_num / 8 - 1);
 	}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index e4b4a8f2ceaa..0f071a0f4ff9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -37,7 +37,6 @@ enum hns3_nic_state {
 #define HNS3_RING_TX_RING_BASEADDR_L_REG	0x00040
 #define HNS3_RING_TX_RING_BASEADDR_H_REG	0x00044
 #define HNS3_RING_TX_RING_BD_NUM_REG		0x00048
-#define HNS3_RING_TX_RING_BD_LEN_REG		0x0004C
 #define HNS3_RING_TX_RING_TAIL_REG		0x00058
 #define HNS3_RING_TX_RING_HEAD_REG		0x0005C
 #define HNS3_RING_TX_RING_FBDNUM_REG		0x00060
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 6/9] net: hns3: Fix desc num set to default when setting channel
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Yunsheng Lin
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Yunsheng Lin <linyunsheng@huawei.com>

When user set the channel num using "ethtool -L ethX", the desc num
of BD will set to default value, which will cause desc num set by
user lost problem.

This patch fixes it by restoring the desc num set by user when setting
channel num.

Fixes: 09f2af6405b8 ("net: hns3: add support to modify tqps number")
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c88f5e6a9b77..8510245705cc 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1267,35 +1267,37 @@ static int hclge_map_tqps_to_func(struct hclge_dev *hdev, u16 func_id,
 	return ret;
 }
 
-static int  hclge_assign_tqp(struct hclge_vport *vport,
-			     struct hnae3_queue **tqp, u16 num_tqps)
+static int  hclge_assign_tqp(struct hclge_vport *vport)
 {
+	struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
 	struct hclge_dev *hdev = vport->back;
 	int i, alloced;
 
 	for (i = 0, alloced = 0; i < hdev->num_tqps &&
-	     alloced < num_tqps; i++) {
+	     alloced < kinfo->num_tqps; i++) {
 		if (!hdev->htqp[i].alloced) {
 			hdev->htqp[i].q.handle = &vport->nic;
 			hdev->htqp[i].q.tqp_index = alloced;
-			tqp[alloced] = &hdev->htqp[i].q;
+			hdev->htqp[i].q.desc_num = kinfo->num_desc;
+			kinfo->tqp[alloced] = &hdev->htqp[i].q;
 			hdev->htqp[i].alloced = true;
 			alloced++;
 		}
 	}
-	vport->alloc_tqps = num_tqps;
+	vport->alloc_tqps = kinfo->num_tqps;
 
 	return 0;
 }
 
-static int hclge_knic_setup(struct hclge_vport *vport, u16 num_tqps)
+static int hclge_knic_setup(struct hclge_vport *vport,
+			    u16 num_tqps, u16 num_desc)
 {
 	struct hnae3_handle *nic = &vport->nic;
 	struct hnae3_knic_private_info *kinfo = &nic->kinfo;
 	struct hclge_dev *hdev = vport->back;
 	int i, ret;
 
-	kinfo->num_desc = hdev->num_desc;
+	kinfo->num_desc = num_desc;
 	kinfo->rx_buf_len = hdev->rx_buf_len;
 	kinfo->num_tc = min_t(u16, num_tqps, hdev->tm_info.num_tc);
 	kinfo->rss_size
@@ -1322,7 +1324,7 @@ static int hclge_knic_setup(struct hclge_vport *vport, u16 num_tqps)
 	if (!kinfo->tqp)
 		return -ENOMEM;
 
-	ret = hclge_assign_tqp(vport, kinfo->tqp, kinfo->num_tqps);
+	ret = hclge_assign_tqp(vport);
 	if (ret)
 		dev_err(&hdev->pdev->dev, "fail to assign TQPs %d.\n", ret);
 
@@ -1388,7 +1390,7 @@ static int hclge_vport_setup(struct hclge_vport *vport, u16 num_tqps)
 	nic->numa_node_mask = hdev->numa_node_mask;
 
 	if (hdev->ae_dev->dev_type == HNAE3_DEV_KNIC) {
-		ret = hclge_knic_setup(vport, num_tqps);
+		ret = hclge_knic_setup(vport, num_tqps, hdev->num_desc);
 		if (ret) {
 			dev_err(&hdev->pdev->dev, "knic setup failed %d\n",
 				ret);
@@ -5944,7 +5946,7 @@ static int hclge_set_channels(struct hnae3_handle *handle, u32 new_tqps_num)
 	/* Free old tqps, and reallocate with new tqp number when nic setup */
 	hclge_release_tqp(vport);
 
-	ret = hclge_knic_setup(vport, new_tqps_num);
+	ret = hclge_knic_setup(vport, new_tqps_num, kinfo->num_desc);
 	if (ret) {
 		dev_err(&hdev->pdev->dev, "setup nic fail, ret =%d\n", ret);
 		return ret;
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 5/9] net: hns3: Fix for vf vlan delete failed problem
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Yunsheng Lin
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Yunsheng Lin <linyunsheng@huawei.com>

There are only 128 entries in vf vlan table, if user has added
more than 128 vlan, fw will ignore it and disable the vf vlan
table. So when user deletes the vlan entry that has not been
set to vf vlan table, fw will return not found result and driver
treat that as error, which will cause vlan delete failed problem.

This patch fixes it by returning ok when fw returns not found
result.

Fixes: 9dba194574e3 ("{topost} net: hns3: fix for vlan table problem")
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 3b7cd6744280..c88f5e6a9b77 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4684,9 +4684,17 @@ static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, int vfid,
 			"Add vf vlan filter fail, ret =%d.\n",
 			req0->resp_code);
 	} else {
+#define HCLGE_VF_VLAN_DEL_NO_FOUND	1
 		if (!req0->resp_code)
 			return 0;
 
+		if (req0->resp_code == HCLGE_VF_VLAN_DEL_NO_FOUND) {
+			dev_warn(&hdev->pdev->dev,
+				 "vlan %d filter is not in vf vlan table\n",
+				 vlan);
+			return 0;
+		}
+
 		dev_err(&hdev->pdev->dev,
 			"Kill vf vlan filter fail, ret =%d.\n",
 			req0->resp_code);
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 4/9] net: hns3: Fix for phy link issue when using marvell phy driver
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Jian Shen
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Jian Shen <shenjian15@huawei.com>

For marvell phy m88e1510, bit SUPPORTED_FIBRE of phydev->supported
is default on. Both phy_resume() and phy_suspend() will check the
SUPPORTED_FIBRE bit and write register of fibre page.

Currently in hns3 driver, the SUPPORTED_FIBRE bit will be cleared
after phy_connect_direct() finished. Because phy_resume() is called
in phy_connect_direct(), and phy_suspend() is called when disconnect
phy device, so the operation for fibre page register is not symmetrical.
It will cause phy link issue when reload hns3 driver.

This patch fixes it by disable the SUPPORTED_FIBRE before connecting
phy.

This is a temporary scheme for DTS2018050311542. I'm contacking with
the FAE of marvell phy, wish to get a better way to deal with it.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 85a123d40e8b..398971a062f4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -202,6 +202,8 @@ int hclge_mac_connect_phy(struct hclge_dev *hdev)
 	if (!phydev)
 		return 0;
 
+	phydev->supported &= ~SUPPORTED_FIBRE;
+
 	ret = phy_connect_direct(netdev, phydev,
 				 hclge_mac_adjust_link,
 				 PHY_INTERFACE_MODE_SGMII);
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 3/9] net: hns3: Fix for information of phydev lost problem when down/up
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Fuyun Liang
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Fuyun Liang <liangfuyun1@huawei.com>

Function call of phy_connect_direct will reinitialize phydev. Some
information like advertising will be lost. Phy_connect_direct only
needs to be called once. And driver can run well. This patch adds
some functions to ensure that phy_connect_direct is called only once
to solve the information of phydev lost problem occurring when we stop
the net and open it again.

Signed-off-by: Fuyun Liang <liangfuyun1@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 24 +++++++++++++++++----
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c    | 25 ++++++++++++++++++----
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h    |  4 +++-
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 18ae11d8de73..3b7cd6744280 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3782,7 +3782,7 @@ static int hclge_ae_start(struct hnae3_handle *handle)
 {
 	struct hclge_vport *vport = hclge_get_vport(handle);
 	struct hclge_dev *hdev = vport->back;
-	int i, ret;
+	int i;
 
 	for (i = 0; i < vport->alloc_tqps; i++)
 		hclge_tqp_enable(hdev, i, 0, true);
@@ -3796,9 +3796,7 @@ static int hclge_ae_start(struct hnae3_handle *handle)
 	/* reset tqp stats */
 	hclge_reset_tqp_stats(handle);
 
-	ret = hclge_mac_start_phy(hdev);
-	if (ret)
-		return ret;
+	hclge_mac_start_phy(hdev);
 
 	return 0;
 }
@@ -5417,6 +5415,16 @@ static void hclge_get_mdix_mode(struct hnae3_handle *handle,
 		*tp_mdix = ETH_TP_MDI;
 }
 
+static int hclge_init_instance_hw(struct hclge_dev *hdev)
+{
+	return hclge_mac_connect_phy(hdev);
+}
+
+static void hclge_uninit_instance_hw(struct hclge_dev *hdev)
+{
+	hclge_mac_disconnect_phy(hdev);
+}
+
 static int hclge_init_client_instance(struct hnae3_client *client,
 				      struct hnae3_ae_dev *ae_dev)
 {
@@ -5436,6 +5444,13 @@ static int hclge_init_client_instance(struct hnae3_client *client,
 			if (ret)
 				return ret;
 
+			ret = hclge_init_instance_hw(hdev);
+			if (ret) {
+			        client->ops->uninit_instance(&vport->nic,
+			                                     0);
+			        return ret;
+			}
+
 			if (hdev->roce_client &&
 			    hnae3_dev_roce_supported(hdev)) {
 				struct hnae3_client *rc = hdev->roce_client;
@@ -5498,6 +5513,7 @@ static void hclge_uninit_client_instance(struct hnae3_client *client,
 		if (client->type == HNAE3_CLIENT_ROCE)
 			return;
 		if (client->ops->uninit_instance) {
+			hclge_uninit_instance_hw(hdev);
 			client->ops->uninit_instance(&vport->nic, 0);
 			hdev->nic_client = NULL;
 			vport->nic.client = NULL;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 2065ee2fd358..85a123d40e8b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -193,7 +193,7 @@ static void hclge_mac_adjust_link(struct net_device *netdev)
 		netdev_err(netdev, "failed to configure flow control.\n");
 }
 
-int hclge_mac_start_phy(struct hclge_dev *hdev)
+int hclge_mac_connect_phy(struct hclge_dev *hdev)
 {
 	struct net_device *netdev = hdev->vport[0].nic.netdev;
 	struct phy_device *phydev = hdev->hw.mac.phydev;
@@ -213,11 +213,29 @@ int hclge_mac_start_phy(struct hclge_dev *hdev)
 	phydev->supported &= HCLGE_PHY_SUPPORTED_FEATURES;
 	phydev->advertising = phydev->supported;
 
-	phy_start(phydev);
-
 	return 0;
 }
 
+void hclge_mac_disconnect_phy(struct hclge_dev *hdev)
+{
+	struct phy_device *phydev = hdev->hw.mac.phydev;
+
+	if (!phydev)
+		return;
+
+	phy_disconnect(phydev);
+}
+
+void hclge_mac_start_phy(struct hclge_dev *hdev)
+{
+	struct phy_device *phydev = hdev->hw.mac.phydev;
+
+	if (!phydev)
+		return;
+
+	phy_start(phydev);
+}
+
 void hclge_mac_stop_phy(struct hclge_dev *hdev)
 {
 	struct net_device *netdev = hdev->vport[0].nic.netdev;
@@ -227,5 +245,4 @@ void hclge_mac_stop_phy(struct hclge_dev *hdev)
 		return;
 
 	phy_stop(phydev);
-	phy_disconnect(phydev);
 }
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h
index bb3ce35e0d66..5fbf7dddb5d9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h
@@ -5,7 +5,9 @@
 #define __HCLGE_MDIO_H
 
 int hclge_mac_mdio_config(struct hclge_dev *hdev);
-int hclge_mac_start_phy(struct hclge_dev *hdev);
+int hclge_mac_connect_phy(struct hclge_dev *hdev);
+void hclge_mac_disconnect_phy(struct hclge_dev *hdev);
+void hclge_mac_start_phy(struct hclge_dev *hdev);
 void hclge_mac_stop_phy(struct hclge_dev *hdev);
 
 #endif
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 2/9] net: hns3: Fix for command format parsing error in hclge_is_all_function_id_zero
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Xi Wang
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Xi Wang <wangxi11@huawei.com>

According to the functional specification of hardward, the first
descriptor of response from command 'lookup vlan talbe' is not valid.
Currently, the first descriptor is parsed as normal value, which will
cause an expected error.

This patch fixes this problem by skipping the first descriptor.

Signed-off-by: Xi Wang <wangxi11@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 99dda5051f5f..18ae11d8de73 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3930,7 +3930,7 @@ static bool hclge_is_all_function_id_zero(struct hclge_desc *desc)
 #define HCLGE_FUNC_NUMBER_PER_DESC 6
 	int i, j;
 
-	for (i = 0; i < HCLGE_DESC_NUMBER; i++)
+	for (i = 1; i < HCLGE_DESC_NUMBER; i++)
 		for (j = 0; j < HCLGE_FUNC_NUMBER_PER_DESC; j++)
 			if (desc[i].data[j])
 				return false;
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 1/9] net: hns3: Add support for serdes loopback selftest
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm, Yunsheng Lin
In-Reply-To: <20180812094738.14852-1-salil.mehta@huawei.com>

From: Peng Li <lipeng321@huawei.com>

This patch adds support for serdes loopback selftest in hns3
driver.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  7 ++-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 12 +++++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 57 +++++++++++++++++++++-
 3 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 80ba95d76260..f4710e498c59 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -53,7 +53,7 @@ static const struct hns3_stats hns3_rxq_stats[] = {
 
 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
 
-#define HNS3_SELF_TEST_TPYE_NUM		1
+#define HNS3_SELF_TEST_TPYE_NUM		2
 #define HNS3_NIC_LB_TEST_PKT_NUM	1
 #define HNS3_NIC_LB_TEST_RING_ID	0
 #define HNS3_NIC_LB_TEST_PACKET_SIZE	128
@@ -78,6 +78,7 @@ static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
 		return -EOPNOTSUPP;
 
 	switch (loop) {
+	case HNAE3_MAC_INTER_LOOP_SERDES:
 	case HNAE3_MAC_INTER_LOOP_MAC:
 		ret = h->ae_algo->ops->set_loopback(h, loop, en);
 		break;
@@ -303,6 +304,10 @@ static void hns3_self_test(struct net_device *ndev,
 	st_param[HNAE3_MAC_INTER_LOOP_MAC][1] =
 			h->flags & HNAE3_SUPPORT_MAC_LOOPBACK;
 
+	st_param[HNAE3_MAC_INTER_LOOP_SERDES][0] = HNAE3_MAC_INTER_LOOP_SERDES;
+	st_param[HNAE3_MAC_INTER_LOOP_SERDES][1] =
+			h->flags & HNAE3_SUPPORT_SERDES_LOOPBACK;
+
 	if (if_running)
 		dev_close(ndev);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index cd0a4f228470..821d4c2f84bd 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -94,6 +94,7 @@ enum hclge_opcode_type {
 	HCLGE_OPC_QUERY_LINK_STATUS	= 0x0307,
 	HCLGE_OPC_CONFIG_MAX_FRM_SIZE	= 0x0308,
 	HCLGE_OPC_CONFIG_SPEED_DUP	= 0x0309,
+	HCLGE_OPC_SERDES_LOOPBACK       = 0x0315,
 
 	/* PFC/Pause commands */
 	HCLGE_OPC_CFG_MAC_PAUSE_EN      = 0x0701,
@@ -775,6 +776,17 @@ struct hclge_reset_cmd {
 	u8 fun_reset_vfid;
 	u8 rsv[22];
 };
+
+#define HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B	BIT(0)
+#define HCLGE_CMD_SERDES_DONE_B			BIT(0)
+#define HCLGE_CMD_SERDES_SUCCESS_B		BIT(1)
+struct hclge_serdes_lb_cmd {
+	u8 mask;
+	u8 enable;
+	u8 result;
+	u8 rsv[21];
+};
+
 #define HCLGE_DEFAULT_TX_BUF		0x4000	 /* 16k  bytes */
 #define HCLGE_TOTAL_PKT_BUF		0x108000 /* 1.03125M bytes */
 #define HCLGE_DEFAULT_DV		0xA000	 /* 40k byte */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index fc813b7f20e8..99dda5051f5f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -787,9 +787,10 @@ static int hclge_get_sset_count(struct hnae3_handle *handle, int stringset)
 		    hdev->hw.mac.speed == HCLGE_MAC_SPEED_1G) {
 			count += 1;
 			handle->flags |= HNAE3_SUPPORT_MAC_LOOPBACK;
-		} else {
-			count = -EOPNOTSUPP;
 		}
+
+		count ++;
+		handle->flags |= HNAE3_SUPPORT_SERDES_LOOPBACK;
 	} else if (stringset == ETH_SS_STATS) {
 		count = ARRAY_SIZE(g_mac_stats_string) +
 			ARRAY_SIZE(g_all_32bit_stats_string) +
@@ -3670,6 +3671,55 @@ static int hclge_set_mac_loopback(struct hclge_dev *hdev, bool en)
 	return ret;
 }
 
+static int hclge_set_serdes_loopback(struct hclge_dev *hdev, bool en)
+{
+#define HCLGE_SERDES_RETRY_MS	10
+#define HCLGE_SERDES_RETRY_NUM	100
+	struct hclge_serdes_lb_cmd *req;
+	struct hclge_desc desc;
+	int ret, i = 0;
+
+	req = (struct hclge_serdes_lb_cmd *)&desc.data[0];
+	hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK, false);
+
+	if (en) {
+		req->enable = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+		req->mask = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+	} else {
+		req->mask = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+	}
+
+	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+	if (ret) {
+		dev_err(&hdev->pdev->dev,
+			"serdes loopback set fail, ret = %d\n", ret);
+		return ret;
+	}
+
+	do {
+		msleep(HCLGE_SERDES_RETRY_MS);
+		hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK,
+					   true);
+		ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+		if (ret) {
+			dev_err(&hdev->pdev->dev,
+				"serdes loopback get, ret = %d\n", ret);
+			return ret;
+		}
+	} while (++i < HCLGE_SERDES_RETRY_NUM  &&
+		 !(req->result & HCLGE_CMD_SERDES_DONE_B));
+
+	if (!(req->result & HCLGE_CMD_SERDES_DONE_B)) {
+		dev_err(&hdev->pdev->dev, "serdes loopback set timeout\n");
+		return -EBUSY;
+	} else if (!(req->result & HCLGE_CMD_SERDES_SUCCESS_B)) {
+		dev_err(&hdev->pdev->dev, "serdes loopback set failed in fw\n");
+		return -EIO;
+	}
+
+	return 0;
+}
+
 static int hclge_set_loopback(struct hnae3_handle *handle,
 			      enum hnae3_loop loop_mode, bool en)
 {
@@ -3681,6 +3731,9 @@ static int hclge_set_loopback(struct hnae3_handle *handle,
 	case HNAE3_MAC_INTER_LOOP_MAC:
 		ret = hclge_set_mac_loopback(hdev, en);
 		break;
+	case HNAE3_MAC_INTER_LOOP_SERDES:
+		ret = hclge_set_serdes_loopback(hdev, en);
+		break;
 	default:
 		ret = -ENOTSUPP;
 		dev_err(&hdev->pdev->dev,
-- 
2.11.0

^ permalink raw reply related

* [PATCH net-next 0/9] Misc bug fixes & small enhancements for HNS3 Driver
From: Salil Mehta @ 2018-08-12  9:47 UTC (permalink / raw)
  To: davem
  Cc: salil.mehta, yisen.zhuang, lipeng321, mehta.salil.lnk, netdev,
	linux-kernel, linuxarm

This patch-set presents some bug fixes and minor enhancements to
HNS3 Ethernet driver.

Fuyun Liang (1):
  net: hns3: Fix for information of phydev lost problem when down/up

Jian Shen (1):
  net: hns3: Fix for phy link issue when using marvell phy driver

Peng Li (2):
  net: hns3: Add support for serdes loopback selftest
  net: hns3: Add vlan filter setting by ethtool command -K

Xi Wang (1):
  net: hns3: Fix for command format parsing error in
    hclge_is_all_function_id_zero

Yunsheng Lin (4):
  net: hns3: Fix for vf vlan delete failed problem
  net: hns3: Fix desc num set to default when setting channel
  net: hns3: Remove tx ring BD len register in hns3_enet
  net: hns3: Set tx ring' tc info when netdev is up

 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c    |  32 +++++-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h    |   2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   7 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  12 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 113 +++++++++++++++++----
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c    |  27 ++++-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.h    |   4 +-
 7 files changed, 171 insertions(+), 26 deletions(-)

-- 
2.11.0

^ permalink raw reply

* Re: [PATCH bpf-next 4/4] selftests/bpf: Selftest for bpf_skb_ancestor_cgroup_id
From: Yonghong Song @ 2018-08-12  6:58 UTC (permalink / raw)
  To: Andrey Ignatov, netdev; +Cc: ast, daniel, tj, guro, kernel-team
In-Reply-To: <fd9428a9f03598da21caa2bb0e49c958f9c8daf3.1533965421.git.rdna@fb.com>



On 8/10/18 10:35 PM, Andrey Ignatov wrote:
> Add selftests for bpf_skb_ancestor_cgroup_id helper.
> 
> test_skb_cgroup_id.sh prepares testing interface and adds tc qdisc and
> filter for it using BPF object compiled from test_skb_cgroup_id_kern.c
> program.
> 
> BPF program in test_skb_cgroup_id_kern.c gets ancestor cgroup id using
> the new helper at different levels of cgroup hierarchy that skb belongs
> to, including root level and non-existing level, and saves it to the map
> where the key is the level of corresponding cgroup and the value is its
> id.
> 
> To trigger BPF program, user space program test_skb_cgroup_id_user is
> run. It adds itself into testing cgroup and sends UDP datagram to
> link-local multicast address of testing interface. Then it reads cgroup
> ids saved in kernel for different levels from the BPF map and compares
> them with those in user space. They must be equal for every level of
> ancestry.
> 
> Example of run:
>    # ./test_skb_cgroup_id.sh
>    Wait for testing link-local IP to become available ... OK
>    Note: 8 bytes struct bpf_elf_map fixup performed due to size mismatch!
>    [PASS]

I am not able to run the test on my FC27 based VM with the latest 
bpf-next and the patch set.

[yhs@localhost bpf]$ sudo ./test_skb_cgroup_id.sh
Wait for testing link-local IP to become available .....ERROR: Timeout 
waiting for test IP to become available.
[yhs@localhost bpf]$

I am able to run test_sock_addr.sh successfully.
$ sudo ./test_sock_addr.sh
Wait for testing IPv4/IPv6 to become available .
.. OK
Test case: bind4: load prog with wrong expected attach type .. [PASS]
Test case: bind4: attach prog with wrong attach type .. [PASS]
...
Test case: sendmsg6: deny call .. [PASS]
Summary: 27 PASSED, 0 FAILED

Maybe some issues in this addr ff02::1%${TEST_IF}?

> 
> Signed-off-by: Andrey Ignatov <rdna@fb.com>
> ---
>   tools/testing/selftests/bpf/Makefile          |   9 +-
>   .../selftests/bpf/test_skb_cgroup_id.sh       |  61 ++++++
>   .../selftests/bpf/test_skb_cgroup_id_kern.c   |  47 +++++
>   .../selftests/bpf/test_skb_cgroup_id_user.c   | 187 ++++++++++++++++++
>   4 files changed, 301 insertions(+), 3 deletions(-)
>   create mode 100755 tools/testing/selftests/bpf/test_skb_cgroup_id.sh
>   create mode 100644 tools/testing/selftests/bpf/test_skb_cgroup_id_kern.c
>   create mode 100644 tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index daed162043c2..fff7fb1285fc 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -34,7 +34,8 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test
>   	test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \
>   	test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \
>   	test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \
> -	get_cgroup_id_kern.o socket_cookie_prog.o test_select_reuseport_kern.o
> +	get_cgroup_id_kern.o socket_cookie_prog.o test_select_reuseport_kern.o \
> +	test_skb_cgroup_id_kern.o
>   
>   # Order correspond to 'make run_tests' order
>   TEST_PROGS := test_kmod.sh \
> @@ -45,10 +46,11 @@ TEST_PROGS := test_kmod.sh \
>   	test_sock_addr.sh \
>   	test_tunnel.sh \
>   	test_lwt_seg6local.sh \
> -	test_lirc_mode2.sh
> +	test_lirc_mode2.sh \
> +	test_skb_cgroup_id.sh
>   
>   # Compile but not part of 'make run_tests'
> -TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr
> +TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr test_skb_cgroup_id_user
>   
>   include ../lib.mk
>   
> @@ -59,6 +61,7 @@ $(TEST_GEN_PROGS): $(BPFOBJ)
>   $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a
>   
>   $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
> +$(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
>   $(OUTPUT)/test_sock: cgroup_helpers.c
>   $(OUTPUT)/test_sock_addr: cgroup_helpers.c
>   $(OUTPUT)/test_socket_cookie: cgroup_helpers.c
> diff --git a/tools/testing/selftests/bpf/test_skb_cgroup_id.sh b/tools/testing/selftests/bpf/test_skb_cgroup_id.sh
> new file mode 100755
> index 000000000000..b75e9b52f06f
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/test_skb_cgroup_id.sh
> @@ -0,0 +1,61 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2018 Facebook
> +
> +set -eu
> +
> +wait_for_ip()
> +{
> +	local _i
> +	echo -n "Wait for testing link-local IP to become available "
> +	for _i in $(seq ${MAX_PING_TRIES}); do
> +		echo -n "."
> +		if ping -6 -q -c 1 -W 1 ff02::1%${TEST_IF} >/dev/null 2>&1; then
> +			echo " OK"
> +			return
> +		fi
> +	done
> +	echo 1>&2 "ERROR: Timeout waiting for test IP to become available."
> +	exit 1
> +}
> +
> +setup()
> +{
> +	# Create testing interfaces not to interfere with current environment.
> +	ip link add dev ${TEST_IF} type veth peer name ${TEST_IF_PEER}
> +	ip link set ${TEST_IF} up
> +	ip link set ${TEST_IF_PEER} up
> +
> +	wait_for_ip
> +
> +	tc qdisc add dev ${TEST_IF} clsact
> +	tc filter add dev ${TEST_IF} egress bpf obj ${BPF_PROG_OBJ} \
> +		sec ${BPF_PROG_SECTION} da
> +
> +	BPF_PROG_ID=$(tc filter show dev ${TEST_IF} egress | \
> +			awk '/ id / {sub(/.* id /, "", $0); print($1)}')
> +}
> +
> +cleanup()
> +{
> +	ip link del ${TEST_IF} 2>/dev/null || :
> +	ip link del ${TEST_IF_PEER} 2>/dev/null || :
> +}
> +
> +main()
> +{
> +	trap cleanup EXIT 2 3 6 15
> +	setup
> +	${PROG} ${TEST_IF} ${BPF_PROG_ID}
> +}
> +
> +DIR=$(dirname $0)
> +TEST_IF="test_cgid_1"
> +TEST_IF_PEER="test_cgid_2"
> +MAX_PING_TRIES=5
> +BPF_PROG_OBJ="${DIR}/test_skb_cgroup_id_kern.o"
> +BPF_PROG_SECTION="cgroup_id_logger"
> +BPF_PROG_ID=0
> +PROG="${DIR}/test_skb_cgroup_id_user"
> +
> +main
> diff --git a/tools/testing/selftests/bpf/test_skb_cgroup_id_kern.c b/tools/testing/selftests/bpf/test_skb_cgroup_id_kern.c
> new file mode 100644
> index 000000000000..68cf9829f5a7
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/test_skb_cgroup_id_kern.c
> @@ -0,0 +1,47 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (c) 2018 Facebook
> +
> +#include <linux/bpf.h>
> +#include <linux/pkt_cls.h>
> +
> +#include <string.h>
> +
> +#include "bpf_helpers.h"
> +
> +#define NUM_CGROUP_LEVELS	4
> +
> +struct bpf_map_def SEC("maps") cgroup_ids = {
> +	.type = BPF_MAP_TYPE_ARRAY,
> +	.key_size = sizeof(__u32),
> +	.value_size = sizeof(__u64),
> +	.max_entries = NUM_CGROUP_LEVELS,
> +};
> +
> +static __always_inline void log_nth_level(struct __sk_buff *skb, __u32 level)
> +{
> +	__u64 id;
> +
> +	/* [1] &level passed to external function that may change it, it's
> +	 *     incompatible with loop unroll.
> +	 */
> +	id = bpf_skb_ancestor_cgroup_id(skb, level);
> +	bpf_map_update_elem(&cgroup_ids, &level, &id, 0);
> +}
> +
> +SEC("cgroup_id_logger")
> +int log_cgroup_id(struct __sk_buff *skb)
> +{
> +	/* Loop unroll can't be used here due to [1]. Unrolling manually.
> +	 * Number of calls should be in sync with NUM_CGROUP_LEVELS.
> +	 */
> +	log_nth_level(skb, 0);
> +	log_nth_level(skb, 1);
> +	log_nth_level(skb, 2);
> +	log_nth_level(skb, 3);
> +
> +	return TC_ACT_OK;
> +}
> +
> +int _version SEC("version") = 1;
> +
> +char _license[] SEC("license") = "GPL";
> diff --git a/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
> new file mode 100644
> index 000000000000..c121cc59f314
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
> @@ -0,0 +1,187 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (c) 2018 Facebook
> +
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include <arpa/inet.h>
> +#include <net/if.h>
> +#include <netinet/in.h>
> +#include <sys/socket.h>
> +#include <sys/types.h>
> +
> +
> +#include <bpf/bpf.h>
> +#include <bpf/libbpf.h>
> +
> +#include "bpf_rlimit.h"
> +#include "cgroup_helpers.h"
> +
> +#define CGROUP_PATH		"/skb_cgroup_test"
> +#define NUM_CGROUP_LEVELS	4
> +
> +/* RFC 4291, Section 2.7.1 */
> +#define LINKLOCAL_MULTICAST	"ff02::1"
> +
> +static int mk_dst_addr(const char *ip, const char *iface,
> +		       struct sockaddr_in6 *dst)
> +{
> +	memset(dst, 0, sizeof(*dst));
> +
> +	dst->sin6_family = AF_INET6;
> +	dst->sin6_port = htons(1025);
> +
> +	if (inet_pton(AF_INET6, ip, &dst->sin6_addr) != 1) {
> +		log_err("Invalid IPv6: %s", ip);
> +		return -1;
> +	}
> +
> +	dst->sin6_scope_id = if_nametoindex(iface);
> +	if (!dst->sin6_scope_id) {
> +		log_err("Failed to get index of iface: %s", iface);
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +static int send_packet(const char *iface)
> +{
> +	struct sockaddr_in6 dst;
> +	char msg[] = "msg";
> +	int err = 0;
> +	int fd = -1;
> +
> +	if (mk_dst_addr(LINKLOCAL_MULTICAST, iface, &dst))
> +		goto err;
> +
> +	fd = socket(AF_INET6, SOCK_DGRAM, 0);
> +	if (fd == -1) {
> +		log_err("Failed to create UDP socket");
> +		goto err;
> +	}
> +
> +	if (sendto(fd, &msg, sizeof(msg), 0, (const struct sockaddr *)&dst,
> +		   sizeof(dst)) == -1) {
> +		log_err("Failed to send datagram");
> +		goto err;
> +	}
> +
> +	goto out;
> +err:
> +	err = -1;
> +out:
> +	if (fd >= 0)
> +		close(fd);
> +	return err;
> +}
> +
> +int get_map_fd_by_prog_id(int prog_id)
> +{
> +	struct bpf_prog_info info = {};
> +	__u32 info_len = sizeof(info);
> +	__u32 map_ids[1];
> +	int prog_fd = -1;
> +	int map_fd = -1;
> +
> +	prog_fd = bpf_prog_get_fd_by_id(prog_id);
> +	if (prog_fd < 0) {
> +		log_err("Failed to get fd by prog id %d", prog_id);
> +		goto err;
> +	}
> +
> +	info.nr_map_ids = 1;
> +	info.map_ids = (__u64) (unsigned long) map_ids;
> +
> +	if (bpf_obj_get_info_by_fd(prog_fd, &info, &info_len)) {
> +		log_err("Failed to get info by prog fd %d", prog_fd);
> +		goto err;
> +	}
> +
> +	if (!info.nr_map_ids) {
> +		log_err("No maps found for prog fd %d", prog_fd);
> +		goto err;
> +	}
> +
> +	map_fd = bpf_map_get_fd_by_id(map_ids[0]);
> +	if (map_fd < 0)
> +		log_err("Failed to get fd by map id %d", map_ids[0]);
> +err:
> +	if (prog_fd >= 0)
> +		close(prog_fd);
> +	return map_fd;
> +}
> +
> +int check_ancestor_cgroup_ids(int prog_id)
> +{
> +	__u64 actual_ids[NUM_CGROUP_LEVELS], expected_ids[NUM_CGROUP_LEVELS];
> +	__u32 level;
> +	int err = 0;
> +	int map_fd;
> +
> +	expected_ids[0] = 0x100000001;	/* root cgroup */
> +	expected_ids[1] = get_cgroup_id("");
> +	expected_ids[2] = get_cgroup_id(CGROUP_PATH);
> +	expected_ids[3] = 0; /* non-existent cgroup */
> +
> +	map_fd = get_map_fd_by_prog_id(prog_id);
> +	if (map_fd < 0)
> +		goto err;
> +
> +	for (level = 0; level < NUM_CGROUP_LEVELS; ++level) {
> +		if (bpf_map_lookup_elem(map_fd, &level, &actual_ids[level])) {
> +			log_err("Failed to lookup key %d", level);
> +			goto err;
> +		}
> +		if (actual_ids[level] != expected_ids[level]) {
> +			log_err("%llx (actual) != %llx (expected), level: %u\n",
> +				actual_ids[level], expected_ids[level], level);
> +			goto err;
> +		}
> +	}
> +
> +	goto out;
> +err:
> +	err = -1;
> +out:
> +	if (map_fd >= 0)
> +		close(map_fd);
> +	return err;
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	int cgfd = -1;
> +	int err = 0;
> +
> +	if (argc < 3) {
> +		fprintf(stderr, "Usage: %s iface prog_id\n", argv[0]);
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	if (setup_cgroup_environment())
> +		goto err;
> +
> +	cgfd = create_and_get_cgroup(CGROUP_PATH);
> +	if (!cgfd)
> +		goto err;
> +
> +	if (join_cgroup(CGROUP_PATH))
> +		goto err;
> +
> +	if (send_packet(argv[1]))
> +		goto err;
> +
> +	if (check_ancestor_cgroup_ids(atoi(argv[2])))
> +		goto err;
> +
> +	goto out;
> +err:
> +	err = -1;
> +out:
> +	close(cgfd);
> +	cleanup_cgroup_environment();
> +	printf("[%s]\n", err ? "FAIL" : "PASS");
> +	return err;
> +}
> 

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox