[Patch V3 net 11/11] net: hns3: bugfix for rtnl_lock's range in the hclgevf_reset()

2018-10-27 Thread Huazhong Tan
Since hclgevf_reset_wait() is used to wait for the hardware to complete
the reset, it is not necessary to hold the rtnl_lock during
hclgevf_reset_wait(). So this patch releases the lock for the duration
of hclgevf_reset_wait().

Fixes: 6988eb2a9b77 ("net: hns3: Add support to reset the enet/ring mgmt layer")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index b224f6a..085edb9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1170,6 +1170,8 @@ static int hclgevf_reset(struct hclgevf_dev *hdev)
/* bring down the nic to stop any ongoing TX/RX */
hclgevf_notify_client(hdev, HNAE3_DOWN_CLIENT);
 
+   rtnl_unlock();
+
/* check if VF could successfully fetch the hardware reset completion
 * status from the hardware
 */
@@ -1181,12 +1183,15 @@ static int hclgevf_reset(struct hclgevf_dev *hdev)
ret);
 
dev_warn(>pdev->dev, "VF reset failed, disabling VF!\n");
+   rtnl_lock();
hclgevf_notify_client(hdev, HNAE3_UNINIT_CLIENT);
 
rtnl_unlock();
return ret;
}
 
+   rtnl_lock();
+
/* now, re-initialize the nic client and ae device*/
ret = hclgevf_reset_stack(hdev);
if (ret)
-- 
2.7.4



[Patch V3 net 06/11] net: hns3: bugfix for is_valid_csq_clean_head()

2018-10-27 Thread Huazhong Tan
The HEAD pointer of the hardware command queue maybe equal to the command
queue's next_to_use in the driver, so that does not belong to the invalid
HEAD pointer, since the hardware may not process the command in time,
causing the HEAD pointer to be too late to update. The variables' name
in this function is unreadable, so give them a more readable one.

Fixes: 3ff504908f95 ("net: hns3: fix a dead loop in hclge_cmd_csq_clean")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 68026a5..690f62e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -24,15 +24,15 @@ static int hclge_ring_space(struct hclge_cmq_ring *ring)
return ring->desc_num - used - 1;
 }
 
-static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int h)
+static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int head)
 {
-   int u = ring->next_to_use;
-   int c = ring->next_to_clean;
+   int ntu = ring->next_to_use;
+   int ntc = ring->next_to_clean;
 
-   if (unlikely(h >= ring->desc_num))
-   return 0;
+   if (ntu > ntc)
+   return head >= ntc && head <= ntu;
 
-   return u > c ? (h > c && h <= u) : (h > c || h <= u);
+   return head >= ntc || head <= ntu;
 }
 
 static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
-- 
2.7.4



[Patch V3 net 09/11] net: hns3: bugfix for handling mailbox while the command queue reinitialized

2018-10-27 Thread Huazhong Tan
In a multi-core machine, the mailbox service and reset service
will be executed at the same time. The reset service will re-initialize
the command queue, before that, the mailbox handler can only get some
invalid messages.

The HCLGE_STATE_CMD_DISABLE flag means that the command queue is not
available and needs to be reinitialized. Therefore, when the mailbox
handler recognizes this flag, it should not process the command.

Fixes: dde1a86e93ca ("net: hns3: Add mailbox support to PF driver")
Signed-off-by: Huazhong Tan 
---
V3: Fixes comments from Sergei Shtylyov
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index 04462a3..f890022 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -400,6 +400,12 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
 
/* handle all the mailbox requests in the queue */
while (!hclge_cmd_crq_empty(>hw)) {
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state)) {
+   dev_warn(>pdev->dev,
+"command queue needs re-initializing\n");
+   return;
+   }
+
desc = >desc[crq->next_to_use];
req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data;
 
-- 
2.7.4



[Patch V3 net 10/11] net: hns3: bugfix for rtnl_lock's range in the hclge_reset()

2018-10-27 Thread Huazhong Tan
Since hclge_reset_wait() is used to wait for the hardware to complete
the reset, it is not necessary to hold the rtnl_lock during
hclge_reset_wait(). So this patch releases the lock for the duration
of hclge_reset_wait().

Fixes: 6d4fab39533f ("net: hns3: Reset net device with rtnl_lock")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f3212c9..ffdd960 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2470,14 +2470,17 @@ static void hclge_reset(struct hclge_dev *hdev)
handle = >vport[0].nic;
rtnl_lock();
hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
+   rtnl_unlock();
 
if (!hclge_reset_wait(hdev)) {
+   rtnl_lock();
hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
hclge_reset_ae_dev(hdev->ae_dev);
hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
 
hclge_clear_reset_cause(hdev);
} else {
+   rtnl_lock();
/* schedule again to check pending resets later */
set_bit(hdev->reset_type, >reset_pending);
hclge_reset_task_schedule(hdev);
-- 
2.7.4



[Patch V3 net 00/11] Bugfix for the HNS3 driver

2018-10-27 Thread Huazhong Tan
This patch series include bugfix for the HNS3 ethernet
controller driver.

Change log:
V2->V3:
Fixes comments from Sergei Shtylyov
V1->V2:
Fixes the compilation break reported by kbuild test robot
http://patchwork.ozlabs.org/patch/989818/

Huazhong Tan (11):
  net: hns3: add error handler for hns3_nic_init_vector_data()
  net: hns3: add error handler for
hns3_get_ring_config/hns3_queue_to_ring
  net: hns3: bugfix for reporting unknown vector0 interrupt repeatly
problem
  net: hns3: bugfix for the initialization of command queue's spin lock
  net: hns3: remove unnecessary queue reset in the
hns3_uninit_all_ring()
  net: hns3: bugfix for is_valid_csq_clean_head()
  net: hns3: bugfix for hclge_mdio_write and hclge_mdio_read
  net: hns3: fix incorrect return value/type of some functions
  net: hns3: bugfix for handling mailbox while the command queue
reinitialized
  net: hns3: bugfix for rtnl_lock's range in the hclge_reset()
  net: hns3: bugfix for rtnl_lock's range in the hclgevf_reset()

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 105 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  26 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  42 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |   6 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   4 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  19 ++--
 9 files changed, 136 insertions(+), 76 deletions(-)

-- 
2.7.4



[Patch V3 net 01/11] net: hns3: add error handler for hns3_nic_init_vector_data()

2018-10-27 Thread Huazhong Tan
When hns3_nic_init_vector_data() failed for mapping ring to vector,
it should cancel the netif_napi_add() that have been successfully done
and then exit.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 32f3aca8..d9066c5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2821,7 +2821,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv 
*priv)
struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_tqp_vector *tqp_vector;
int ret = 0;
-   u16 i;
+   int i, j;
 
hns3_nic_set_cpumask(priv);
 
@@ -2868,13 +2868,19 @@ static int hns3_nic_init_vector_data(struct 
hns3_nic_priv *priv)
hns3_free_vector_ring_chain(tqp_vector, _ring_chain);
 
if (ret)
-   return ret;
+   goto map_ring_fail;
 
netif_napi_add(priv->netdev, _vector->napi,
   hns3_nic_common_poll, NAPI_POLL_WEIGHT);
}
 
return 0;
+
+map_ring_fail:
+   for (j = i - 1; j >= 0; j--)
+   netif_napi_del(>tqp_vector[j].napi);
+
+   return ret;
 }
 
 static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv)
-- 
2.7.4



[Patch V3 net 03/11] net: hns3: bugfix for reporting unknown vector0 interrupt repeatly problem

2018-10-27 Thread Huazhong Tan
The current driver supports handling two vector0 interrupts, reset and
mailbox. When the hardware reports an interrupt of another type of
interrupt source, if the driver does not process the interrupt and
enables the interrupt, the hardware will repeatedly report the unknown
interrupt.

Therefore, the driver enables the vector0 interrupt after clearing the
known type of interrupt source. Other conditions are not enabled.

Fixes: cd8c5c269b1d ("net: hns3: Fix for hclge_reset running repeatly problem")
Signed-off-by: Huazhong Tan 
---
 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 5234b53..2a63147 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2236,7 +2236,7 @@ static irqreturn_t hclge_misc_irq_handle(int irq, void 
*data)
}
 
/* clear the source of interrupt if it is not cause by reset */
-   if (event_cause != HCLGE_VECTOR0_EVENT_RST) {
+   if (event_cause == HCLGE_VECTOR0_EVENT_MBX) {
hclge_clear_event_cause(hdev, event_cause, clearval);
hclge_enable_vector(>misc_vector, true);
}
-- 
2.7.4



[Patch V3 net 07/11] net: hns3: bugfix for hclge_mdio_write and hclge_mdio_read

2018-10-27 Thread Huazhong Tan
When there is a PHY, the driver needs to complete some operations through
MDIO during reset reinitialization, so HCLGE_STATE_CMD_DISABLE is more
suitable than HCLGE_STATE_RST_HANDLING to prevent the MDIO operation from
being sent during the hardware reset.

Fixes: b50ae26c57cb ("net: hns3: never send command queue message to IMP when 
reset)
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 24b1f2a..0301863 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -52,7 +52,7 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, 
int regnum,
struct hclge_desc desc;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state))
return 0;
 
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
@@ -90,7 +90,7 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, 
int regnum)
struct hclge_desc desc;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state))
return 0;
 
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
-- 
2.7.4



[Patch V3 net 08/11] net: hns3: fix incorrect return value/type of some functions

2018-10-27 Thread Huazhong Tan
There are some functions that, when they fail to send the command,
need to return the corresponding error value to its caller.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Fixes: 681ec3999b3d ("net: hns3: fix for vlan table lost problem when 
resetting")
Signed-off-by: Huazhong Tan 
---
V2: Fixes the compilation error reported by kbuild test robot
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 80 +++---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|  2 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 34 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  2 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 14 ++--
 6 files changed, 85 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index e82e4ca..055b406 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -316,8 +316,8 @@ struct hnae3_ae_ops {
int (*set_loopback)(struct hnae3_handle *handle,
enum hnae3_loop loop_mode, bool en);
 
-   void (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
-bool en_mc_pmc);
+   int (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
+   bool en_mc_pmc);
int (*set_mtu)(struct hnae3_handle *handle, int new_mtu);
 
void (*get_pauseparam)(struct hnae3_handle *handle,
@@ -391,7 +391,7 @@ struct hnae3_ae_ops {
  int vector_num,
  struct hnae3_ring_chain_node *vr_chain);
 
-   void (*reset_queue)(struct hnae3_handle *handle, u16 queue_id);
+   int (*reset_queue)(struct hnae3_handle *handle, u16 queue_id);
u32 (*get_fw_version)(struct hnae3_handle *handle);
void (*get_mdix_mode)(struct hnae3_handle *handle,
  u8 *tp_mdix_ctrl, u8 *tp_mdix);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index a80ecfb..4d919b8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -509,16 +509,18 @@ static void hns3_nic_set_rx_mode(struct net_device 
*netdev)
h->netdev_flags = new_flags;
 }
 
-void hns3_update_promisc_mode(struct net_device *netdev, u8 promisc_flags)
+int hns3_update_promisc_mode(struct net_device *netdev, u8 promisc_flags)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = priv->ae_handle;
 
if (h->ae_algo->ops->set_promisc_mode) {
-   h->ae_algo->ops->set_promisc_mode(h,
- promisc_flags & HNAE3_UPE,
- promisc_flags & HNAE3_MPE);
+   return h->ae_algo->ops->set_promisc_mode(h,
+   promisc_flags & HNAE3_UPE,
+   promisc_flags & HNAE3_MPE);
}
+
+   return 0;
 }
 
 void hns3_enable_vlan_filter(struct net_device *netdev, bool enable)
@@ -1494,18 +1496,22 @@ static int hns3_vlan_rx_kill_vid(struct net_device 
*netdev,
return ret;
 }
 
-static void hns3_restore_vlan(struct net_device *netdev)
+static int hns3_restore_vlan(struct net_device *netdev)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   int ret = 0;
u16 vid;
-   int ret;
 
for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
ret = hns3_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
-   if (ret)
-   netdev_warn(netdev, "Restore vlan: %d filter, ret:%d\n",
-   vid, ret);
+   if (ret) {
+   netdev_err(netdev, "Restore vlan: %d filter, ret:%d\n",
+  vid, ret);
+   return ret;
+   }
}
+
+   return ret;
 }
 
 static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
@@ -3247,11 +3253,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
 }
 
 /* Set mac addr if it is configured. or leave it to the AE driver */
-static void hns3_init_mac_addr(struct net_device *netdev, bool init)
+static int hns3_init_mac_addr(struct net_device *netdev, bool init)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = priv->ae_handle;
u8 mac_addr_temp[ETH_ALEN];
+   int ret = 0;
 
if (h->ae_algo->ops->get_mac_addr && init) {
h->ae_algo->ops->get_mac_addr(h, mac_addr_temp);
@@ -3266,8 +3273,9 @@ static void hns3_init_mac_addr(struct net_device *netdev, 
bool init)
}
 
if 

[Patch V3 net 05/11] net: hns3: remove unnecessary queue reset in the hns3_uninit_all_ring()

2018-10-27 Thread Huazhong Tan
It is not necessary to reset the queue in the hns3_uninit_all_ring(),
since the queue is stopped in the down operation, and will be reset
in the up operaton. And the judgment of the HCLGE_STATE_RST_HANDLING
flag in the hclge_reset_tqp() is not correct, because we need to reset
tqp during pf reset, otherwise it may cause queue not be reset to
working state problem.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
V3: Fixes comments from Sergei Shtylyov
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 3 ---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 6f0fd62..a80ecfb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3240,9 +3240,6 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
int i;
 
for (i = 0; i < h->kinfo.num_tqps; i++) {
-   if (h->ae_algo->ops->reset_queue)
-   h->ae_algo->ops->reset_queue(h, i);
-
hns3_fini_ring(priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 2a63147..4dd0506 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -6116,9 +6116,6 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
u16 queue_gid;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
-   return;
-
queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
 
ret = hclge_tqp_enable(hdev, queue_id, 0, false);
-- 
2.7.4



[Patch V3 net 02/11] net: hns3: add error handler for hns3_get_ring_config/hns3_queue_to_ring

2018-10-27 Thread Huazhong Tan
When hns3_get_ring_config()/hns3_queue_to_ring() failed during resetting,
the allocated memory has not been freed before hns3_get_ring_config() and
hns3_queue_to_ring() return. So this patch fixes the buffer not freeing
problem during resetting.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index d9066c5..6f0fd62 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3037,8 +3037,10 @@ static int hns3_queue_to_ring(struct hnae3_queue *tqp,
return ret;
 
ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX);
-   if (ret)
+   if (ret) {
+   devm_kfree(priv->dev, priv->ring_data[tqp->tqp_index].ring);
return ret;
+   }
 
return 0;
 }
@@ -3047,7 +3049,7 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
 {
struct hnae3_handle *h = priv->ae_handle;
struct pci_dev *pdev = h->pdev;
-   int i, ret;
+   int i, j, ret;
 
priv->ring_data =  devm_kzalloc(>dev,
array3_size(h->kinfo.num_tqps,
@@ -3065,6 +3067,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
 
return 0;
 err:
+   for (j = i - 1; j >= 0; j--) {
+   devm_kfree(priv->dev, priv->ring_data[j].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[j + h->kinfo.num_tqps].ring);
+   }
+
devm_kfree(>dev, priv->ring_data);
return ret;
 }
-- 
2.7.4



[Patch V3 net 04/11] net: hns3: bugfix for the initialization of command queue's spin lock

2018-10-27 Thread Huazhong Tan
The spin lock of the command queue only needs to be initialized once
when the driver initializes the command queue. It is not necessary to
initialize the spin lock when resetting. At the same time, the
modification of the queue member should be performed after acquiring
the lock.

Fixes: 3efb960f056d ("net: hns3: Refactor the initialization of command queue")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index ac13cb2..68026a5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -304,6 +304,10 @@ int hclge_cmd_queue_init(struct hclge_dev *hdev)
 {
int ret;
 
+   /* Setup the lock for command queue */
+   spin_lock_init(>hw.cmq.csq.lock);
+   spin_lock_init(>hw.cmq.crq.lock);
+
/* Setup the queue entries for use cmd queue */
hdev->hw.cmq.csq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
hdev->hw.cmq.crq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
@@ -337,18 +341,20 @@ int hclge_cmd_init(struct hclge_dev *hdev)
u32 version;
int ret;
 
+   spin_lock_bh(>hw.cmq.csq.lock);
+   spin_lock_bh(>hw.cmq.crq.lock);
+
hdev->hw.cmq.csq.next_to_clean = 0;
hdev->hw.cmq.csq.next_to_use = 0;
hdev->hw.cmq.crq.next_to_clean = 0;
hdev->hw.cmq.crq.next_to_use = 0;
 
-   /* Setup the lock for command queue */
-   spin_lock_init(>hw.cmq.csq.lock);
-   spin_lock_init(>hw.cmq.crq.lock);
-
hclge_cmd_init_regs(>hw);
clear_bit(HCLGE_STATE_CMD_DISABLE, >state);
 
+   spin_unlock_bh(>hw.cmq.crq.lock);
+   spin_unlock_bh(>hw.cmq.csq.lock);
+
ret = hclge_cmd_query_firmware_version(>hw, );
if (ret) {
dev_err(>pdev->dev,
-- 
2.7.4



Re: [Patch net 09/11] net: hns3: bugfix for handling mailbox while the command queue reinitialized

2018-10-27 Thread tanhuazhong




On 2018/10/28 3:05, Sergei Shtylyov wrote:

On 27.10.2018 5:41, Huazhong Tan wrote:


In a multi-core machine, the mailbox service and reset service
will be executed at the same time. The reset server will re-initialize
the commond queue, before that, the mailbox handler can only get some


    Command?


yes, thanks.




invalid messages.

The HCLGE_STATE_CMD_DISABLE flag means that the command queue is not
available and needs to be reinitialized. Therefore, when the mailbox
hanlder recognizes this flag, it should not process the command.


    Handler.



yes, thanks.



Fixes: dde1a86e93ca ("net: hns3: Add mailbox support to PF driver")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c

index 04462a3..6ac2fab 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -400,6 +400,12 @@ void hclge_mbx_handler(struct hclge_dev *hdev)

 /* handle all the mailbox requests in the queue */
 while (!hclge_cmd_crq_empty(>hw)) {
+    if (test_bit(HCLGE_STATE_CMD_DISABLE, >state)) {
+    dev_warn(>pdev->dev,
+ "command queue need re-initialize\n");


    Needs re-initializing.

[...]

MBR, Sergei



thanks.



.





Re: [Patch net 05/11] net: hns3: remove unnecessary queue reset in the hns3_uninit_all_ring()

2018-10-27 Thread tanhuazhong




On 2018/10/28 3:02, Sergei Shtylyov wrote:

Hello!

On 27.10.2018 5:41, Huazhong Tan wrote:


It is not necessary to reset the queue in the hns3_uninit_all_ring(),
since the queue is stopped in the down operation, and will be resetted


    s/resetted/reset/.


OK, thanks.




in the up operaton. And the judgment of the HCLGE_STATE_RST_HANDLING
flag in the hclge_reset_tqp() is not correct, because we need to reset
tqp during pf reset, otherwise it may cause queue not be resetted to


    Same here.


OK, thanks.




working state problem.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver 
for hip08 SoC")

Signed-off-by: Huazhong Tan 

[...]

MBR, Sergei







[PATCH net v5] net/ipv6: Add anycast addresses to a global hashtable

2018-10-27 Thread Jeff Barnhill
icmp6_send() function is expensive on systems with a large number of
interfaces. Every time it’s called, it has to verify that the source
address does not correspond to an existing anycast address by looping
through every device and every anycast address on the device.  This can
result in significant delays for a CPU when there are a large number of
neighbors and ND timers are frequently timing out and calling
neigh_invalidate().

Add anycast addresses to a global hashtable to allow quick searching for
matching anycast addresses.  This is based on inet6_addr_lst in addrconf.c.

Signed-off-by: Jeff Barnhill <0xeff...@gmail.com>
---
 include/net/addrconf.h |   2 +
 include/net/if_inet6.h |   8 
 net/ipv6/af_inet6.c|   5 ++
 net/ipv6/anycast.c | 121 -
 4 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 14b789a123e7..799af1a037d1 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -317,6 +317,8 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device 
*dev,
 const struct in6_addr *addr);
 bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
 const struct in6_addr *addr);
+int anycast_init(void);
+void anycast_cleanup(void);
 
 /* Device notifier */
 int register_inet6addr_notifier(struct notifier_block *nb);
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index d7578cf49c3a..a445014b981d 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -142,6 +142,14 @@ struct ipv6_ac_socklist {
struct ipv6_ac_socklist *acl_next;
 };
 
+struct ipv6_ac_addrlist {
+   struct in6_addr acal_addr;
+   possible_net_t  acal_pnet;
+   refcount_t  acal_users;
+   struct hlist_node   acal_lst; /* inet6_acaddr_lst */
+   struct rcu_head rcu;
+};
+
 struct ifacaddr6 {
struct in6_addr aca_addr;
struct fib6_info*aca_rt;
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 3f4d61017a69..ddc8a6dbfba2 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -1001,6 +1001,9 @@ static int __init inet6_init(void)
err = ip6_flowlabel_init();
if (err)
goto ip6_flowlabel_fail;
+   err = anycast_init();
+   if (err)
+   goto anycast_fail;
err = addrconf_init();
if (err)
goto addrconf_fail;
@@ -1091,6 +1094,8 @@ static int __init inet6_init(void)
 ipv6_exthdrs_fail:
addrconf_cleanup();
 addrconf_fail:
+   anycast_cleanup();
+anycast_fail:
ip6_flowlabel_cleanup();
 ip6_flowlabel_fail:
ndisc_late_cleanup();
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 4e0ff7031edd..ca51c9d57ce5 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -44,8 +44,22 @@
 
 #include 
 
+#define IN6_ADDR_HSIZE_SHIFT   8
+#define IN6_ADDR_HSIZE BIT(IN6_ADDR_HSIZE_SHIFT)
+/* anycast address hash table
+ */
+static struct hlist_head inet6_acaddr_lst[IN6_ADDR_HSIZE];
+static DEFINE_SPINLOCK(acaddr_hash_lock);
+
 static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr 
*addr);
 
+static u32 inet6_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   u32 val = ipv6_addr_hash(addr) ^ net_hash_mix(net);
+
+   return hash_32(val, IN6_ADDR_HSIZE_SHIFT);
+}
+
 /*
  * socket join an anycast group
  */
@@ -204,6 +218,73 @@ void ipv6_sock_ac_close(struct sock *sk)
rtnl_unlock();
 }
 
+static struct ipv6_ac_addrlist *acal_alloc(struct net *net,
+  const struct in6_addr *addr)
+{
+   struct ipv6_ac_addrlist *acal;
+
+   acal = kzalloc(sizeof(*acal), GFP_ATOMIC);
+   if (!acal)
+   return NULL;
+
+   acal->acal_addr = *addr;
+   write_pnet(>acal_pnet, net);
+   refcount_set(>acal_users, 1);
+   INIT_HLIST_NODE(>acal_lst);
+
+   return acal;
+}
+
+static int ipv6_add_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   unsigned int hash = inet6_acaddr_hash(net, addr);
+   struct ipv6_ac_addrlist *acal;
+   int err = 0;
+
+   spin_lock(_hash_lock);
+   hlist_for_each_entry(acal, _acaddr_lst[hash], acal_lst) {
+   if (!net_eq(read_pnet(>acal_pnet), net))
+   continue;
+   if (ipv6_addr_equal(>acal_addr, addr)) {
+   refcount_inc(>acal_users);
+   goto out;
+   }
+   }
+
+   acal = acal_alloc(net, addr);
+   if (!acal) {
+   err = -ENOMEM;
+   goto out;
+   }
+
+   hlist_add_head_rcu(>acal_lst, _acaddr_lst[hash]);
+
+out:
+   spin_unlock(_hash_lock);
+   return err;
+}
+
+static void ipv6_del_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   unsigned int hash = 

Re: [PATCH net v4] net/ipv6: Add anycast addresses to a global hashtable

2018-10-27 Thread Jeff Barnhill
You are right, David...I mistook the refcount_dec_and_test() in
aca_put() as being for the fib6_info, but it's for the aca_refcnt.
Thanks!  I'll submit a corrected patch.
On Sat, Oct 27, 2018 at 7:39 PM David Ahern  wrote:
>
> On 10/27/18 12:02 PM, Jeff Barnhill wrote:
> > @@ -275,6 +356,11 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const 
> > struct in6_addr *addr)
> >   err = -ENOMEM;
> >   goto out;
> >   }
> > + err = ipv6_add_acaddr_hash(dev_net(idev->dev), addr);
> > + if (err) {
> > + aca_put(aca);
> > + goto out;
> > + }
> >
> >   aca->aca_next = idev->ac_list;
> >   idev->ac_list = aca;
>
> you misunderstood my comment. aca_put is instead of a double call to
> fib6_info_release(f6i). You still need one call to
> fib6_info_release(f6i) for the addrconf_f6i_alloc.


Re: [PATCH] net/packet: fix packet drop as of virtio gso

2018-10-27 Thread Jianfeng Tan



On 10/8/2018 11:14 AM, Jason Wang wrote:



On 2018年09月29日 23:41, Jianfeng Tan wrote:

When we use raw socket as the vhost backend, a packet from virito with
gso offloading information, cannot be sent out in later validaton at
xmit path, as we did not set correct skb->protocol which is further used
for looking up the gso function.


Hi:

May I ask the reason for using raw socket for vhost? It was not a 
common setup with little care in the past few years. And it was slow 
since it lacks some recent improvements. Can it be replaced with e.g 
macvtap?


Hi Jason,

Apologize for late response. We are in container environment, in which 
case veth is used mostly. Either tap or macvtap cannot be put into an 
isolated netns. Another thing could be macvlan as the backend of vhost, 
which is not supported either. So unfortunately, improving raw socket is 
the only choice I suppose.


Thanks,
Jianfeng




Thanks



To fix this, we set this field according to virito hdr information.

Fixes: e858fae2b0b8f4 ("virtio_net: use common code for 
virtio_net_hdr and skb GSO conversion")


Cc: sta...@vger.kernel.org
Signed-off-by: Jianfeng Tan 
---
  include/linux/virtio_net.h | 18 ++
  net/packet/af_packet.c | 11 +++
  2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 9397628a1967..cb462f9ab7dd 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -5,6 +5,24 @@
  #include 
  #include 
  +static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,
+   const struct virtio_net_hdr *hdr)
+{
+    switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
+    case VIRTIO_NET_HDR_GSO_TCPV4:
+    case VIRTIO_NET_HDR_GSO_UDP:
+    skb->protocol = cpu_to_be16(ETH_P_IP);
+    break;
+    case VIRTIO_NET_HDR_GSO_TCPV6:
+    skb->protocol = cpu_to_be16(ETH_P_IPV6);
+    break;
+    default:
+    return -EINVAL;
+    }
+
+    return 0;
+}
+
  static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
  const struct virtio_net_hdr *hdr,
  bool little_endian)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 75c92a87e7b2..d6e94dc7e290 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2715,10 +2715,12 @@ static int tpacket_snd(struct packet_sock 
*po, struct msghdr *msg)

  }
  }
  -    if (po->has_vnet_hdr && virtio_net_hdr_to_skb(skb, vnet_hdr,
-  vio_le())) {
-    tp_len = -EINVAL;
-    goto tpacket_error;
+    if (po->has_vnet_hdr) {
+    if (virtio_net_hdr_to_skb(skb, vnet_hdr, vio_le())) {
+    tp_len = -EINVAL;
+    goto tpacket_error;
+    }
+    virtio_net_hdr_set_proto(skb, vnet_hdr);
  }
    skb->destructor = tpacket_destruct_skb;
@@ -2915,6 +2917,7 @@ static int packet_snd(struct socket *sock, 
struct msghdr *msg, size_t len)

  if (err)
  goto out_free;
  len += sizeof(vnet_hdr);
+    virtio_net_hdr_set_proto(skb, _hdr);
  }
    skb_probe_transport_header(skb, reserve);


Re: [PATCH net v4] net/ipv6: Add anycast addresses to a global hashtable

2018-10-27 Thread David Ahern
On 10/27/18 12:02 PM, Jeff Barnhill wrote:
> @@ -275,6 +356,11 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const 
> struct in6_addr *addr)
>   err = -ENOMEM;
>   goto out;
>   }
> + err = ipv6_add_acaddr_hash(dev_net(idev->dev), addr);
> + if (err) {
> + aca_put(aca);
> + goto out;
> + }
>  
>   aca->aca_next = idev->ac_list;
>   idev->ac_list = aca;

you misunderstood my comment. aca_put is instead of a double call to
fib6_info_release(f6i). You still need one call to
fib6_info_release(f6i) for the addrconf_f6i_alloc.


Re: [PATCH] bonding: fix length of actor system

2018-10-27 Thread Jay Vosburgh
Tobias Jungel  wrote:

>The attribute IFLA_BOND_AD_ACTOR_SYSTEM is sent to user space having the
>length of sizeof(bond->params.ad_actor_system) which is 8 byte. This
>patch aligns the length to ETH_ALEN to have the same MAC address exposed
>as using sysfs.
>
>fixes f87fda00b6ed2
>
>Signed-off-by: Tobias Jungel 

The patch looks fine to me, but the "fixes" line is not
formatted properly.  Please format it according to

Documentation/process/submitting-patches.rst

and resubmit your patch as V2.

-J

>---
> drivers/net/bonding/bond_netlink.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/drivers/net/bonding/bond_netlink.c 
>b/drivers/net/bonding/bond_netlink.c
>index 9697977b80f0..6b9ad8673218 100644
>--- a/drivers/net/bonding/bond_netlink.c
>+++ b/drivers/net/bonding/bond_netlink.c
>@@ -638,8 +638,7 @@ static int bond_fill_info(struct sk_buff *skb,
>   goto nla_put_failure;
> 
>   if (nla_put(skb, IFLA_BOND_AD_ACTOR_SYSTEM,
>-  sizeof(bond->params.ad_actor_system),
>-  >params.ad_actor_system))
>+  ETH_ALEN, >params.ad_actor_system))
>   goto nla_put_failure;
>   }
>   if (!bond_3ad_get_active_agg_info(bond, )) {
>

---
-Jay Vosburgh, jay.vosbu...@canonical.com


Re: Fw: [Bug 201423] New: eth0: hw csum failure

2018-10-27 Thread Andre Tomt

On 26.10.2018 13:45, Andre Tomt wrote:

On 25.10.2018 19:38, Eric Dumazet wrote:



On 10/24/2018 12:41 PM, Andre Tomt wrote:


It eventually showed up again with mlx4, on 4.18.16 + fix and also on 
4.19. I still do not have a useful packet capture.


It is running a torrent client serving up various linux distributions.



Have you also applied this fix ?

https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=db4f1be3ca9b0ef7330763d07bf4ace83ad6f913 





No. I've applied it now to 4.19 and will report back if anything shows up.


Just hit it on the simpler server; no VRF, no tunnels, no nat/conntrack. 
Only a basic stateless nftables ruleset and a vlan netdev (unlikely to 
be the one triggering this I guess; it has only v4 traffic).


On 4.19 + above commit:

[158269.360271] p0xe0: hw csum failure
[158269.360286] CPU: 3 PID: 0 Comm: swapper/3 Tainted: P   O  
4.19.0-1 #1
[158269.360287] Hardware name: Supermicro Super Server/X10SRL-F, BIOS 2.0b 
05/02/2017
[158269.360288] Call Trace:
[158269.360290]  
[158269.360295]  dump_stack+0x5c/0x7b
[158269.360299]  __skb_gro_checksum_complete+0x9a/0xa0
[158269.360301]  udp6_gro_receive+0x211/0x290
[158269.360303]  ipv6_gro_receive+0x1b1/0x3a0
[158269.360306]  ? ip_sublist_rcv_finish+0x70/0x70
[158269.360307]  dev_gro_receive+0x3a0/0x620
[158269.360309]  ? __build_skb+0x25/0xe0
[158269.360310]  napi_gro_frags+0xa8/0x220
[158269.360314]  mlx4_en_process_rx_cq+0xa01/0xb40 [mlx4_en]
[158269.360322]  ? mlx4_cq_completion+0x23/0x70 [mlx4_core]
[158269.360325]  ? mlx4_eq_int+0x373/0xc80 [mlx4_core]
[158269.360327]  mlx4_en_poll_rx_cq+0x55/0xf0 [mlx4_en]
[158269.360329]  net_rx_action+0xe0/0x2e0
[158269.360330]  __do_softirq+0xd8/0x2ff
[158269.360333]  irq_exit+0xbd/0xd0
[158269.360334]  do_IRQ+0x85/0xd0
[158269.360336]  common_interrupt+0xf/0xf
[158269.360337]  
[158269.360339] RIP: 0010:cpuidle_enter_state+0xb3/0x310
[158269.360340] Code: 31 ff e8 e0 e0 bb ff 45 84 f6 74 17 9c 58 0f 1f 44 00 00 f6 c4 
02 0f 85 3f 02 00 00 31 ff e8 64 cc c0 ff fb 66 0f 1f 44 00 00 <4c> 29 fb 48 ba 
cf f7 53 e3 a5 9b c4 20 48 89 d8 48 c1 fb 3f 48 f7
[158269.360341] RSP: 0018:af28c634bea8 EFLAGS: 0246 ORIG_RAX: 
ffd9
[158269.360342] RAX: 9a9f7fae0fc0 RBX: 8ff1f4ff622a RCX: 
001f
[158269.360343] RDX: 8ff1f4ff622a RSI: 22983893 RDI: 

[158269.360343] RBP: 0001 R08: 0002 R09: 
00020840
[158269.360344] R10: af28c634be88 R11: 0036 R12: 
9a9f7fae9aa8
[158269.360344] R13: aa0ac638 R14:  R15: 
8ff1f4f09d43
[158269.360347]  ? cpuidle_enter_state+0x90/0x310
[158269.360349]  do_idle+0x1d0/0x240
[158269.360351]  cpu_startup_entry+0x5f/0x70
[158269.360352]  start_secondary+0x185/0x1a0
[158269.360354]  secondary_startup_64+0xa4/0xb0


[PATCH net] rtnetlink: Disallow FDB configuration for non-Ethernet device

2018-10-27 Thread Ido Schimmel
When an FDB entry is configured, the address is validated to have the
length of an Ethernet address, but the device for which the address is
configured can be of any type.

The above can result in the use of uninitialized memory when the address
is later compared against existing addresses since 'dev->addr_len' is
used and it may be greater than ETH_ALEN, as with ip6tnl devices.

Fix this by making sure that FDB entries are only configured for
Ethernet devices.

BUG: KMSAN: uninit-value in memcmp+0x11d/0x180 lib/string.c:863
CPU: 1 PID: 4318 Comm: syz-executor998 Not tainted 4.19.0-rc3+ #49
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0x14b/0x190 lib/dump_stack.c:113
  kmsan_report+0x183/0x2b0 mm/kmsan/kmsan.c:956
  __msan_warning+0x70/0xc0 mm/kmsan/kmsan_instr.c:645
  memcmp+0x11d/0x180 lib/string.c:863
  dev_uc_add_excl+0x165/0x7b0 net/core/dev_addr_lists.c:464
  ndo_dflt_fdb_add net/core/rtnetlink.c:3463 [inline]
  rtnl_fdb_add+0x1081/0x1270 net/core/rtnetlink.c:3558
  rtnetlink_rcv_msg+0xa0b/0x1530 net/core/rtnetlink.c:4715
  netlink_rcv_skb+0x36e/0x5f0 net/netlink/af_netlink.c:2454
  rtnetlink_rcv+0x50/0x60 net/core/rtnetlink.c:4733
  netlink_unicast_kernel net/netlink/af_netlink.c:1317 [inline]
  netlink_unicast+0x1638/0x1720 net/netlink/af_netlink.c:1343
  netlink_sendmsg+0x1205/0x1290 net/netlink/af_netlink.c:1908
  sock_sendmsg_nosec net/socket.c:621 [inline]
  sock_sendmsg net/socket.c:631 [inline]
  ___sys_sendmsg+0xe70/0x1290 net/socket.c:2114
  __sys_sendmsg net/socket.c:2152 [inline]
  __do_sys_sendmsg net/socket.c:2161 [inline]
  __se_sys_sendmsg+0x2a3/0x3d0 net/socket.c:2159
  __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2159
  do_syscall_64+0xb8/0x100 arch/x86/entry/common.c:291
  entry_SYSCALL_64_after_hwframe+0x63/0xe7
RIP: 0033:0x440ee9
Code: e8 cc ab 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7
48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff
ff 0f 83 bb 0a fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:7fff6a93b518 EFLAGS: 0213 ORIG_RAX: 002e
RAX: ffda RBX:  RCX: 00440ee9
RDX:  RSI: 2240 RDI: 0003
RBP:  R08: 004002c8 R09: 004002c8
R10: 004002c8 R11: 0213 R12: b4b0
R13: 00401ec0 R14:  R15: 

Uninit was created at:
  kmsan_save_stack_with_flags mm/kmsan/kmsan.c:256 [inline]
  kmsan_internal_poison_shadow+0xb8/0x1b0 mm/kmsan/kmsan.c:181
  kmsan_kmalloc+0x98/0x100 mm/kmsan/kmsan_hooks.c:91
  kmsan_slab_alloc+0x10/0x20 mm/kmsan/kmsan_hooks.c:100
  slab_post_alloc_hook mm/slab.h:446 [inline]
  slab_alloc_node mm/slub.c:2718 [inline]
  __kmalloc_node_track_caller+0x9e7/0x1160 mm/slub.c:4351
  __kmalloc_reserve net/core/skbuff.c:138 [inline]
  __alloc_skb+0x2f5/0x9e0 net/core/skbuff.c:206
  alloc_skb include/linux/skbuff.h:996 [inline]
  netlink_alloc_large_skb net/netlink/af_netlink.c:1189 [inline]
  netlink_sendmsg+0xb49/0x1290 net/netlink/af_netlink.c:1883
  sock_sendmsg_nosec net/socket.c:621 [inline]
  sock_sendmsg net/socket.c:631 [inline]
  ___sys_sendmsg+0xe70/0x1290 net/socket.c:2114
  __sys_sendmsg net/socket.c:2152 [inline]
  __do_sys_sendmsg net/socket.c:2161 [inline]
  __se_sys_sendmsg+0x2a3/0x3d0 net/socket.c:2159
  __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2159
  do_syscall_64+0xb8/0x100 arch/x86/entry/common.c:291
  entry_SYSCALL_64_after_hwframe+0x63/0xe7

Fixes: 090096bf3db1 ("net: generic fdb support for drivers without 
ndo_fdb_")
Signed-off-by: Ido Schimmel 
Reported-and-tested-by: syzbot+3a288d5f5530b9013...@syzkaller.appspotmail.com
Reported-and-tested-by: syzbot+d53ab4e92a1db0411...@syzkaller.appspotmail.com
Cc: Vlad Yasevich 
---
 net/core/rtnetlink.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index f679c7a7d761..728a97f9f700 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3600,6 +3600,11 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct 
nlmsghdr *nlh,
return -EINVAL;
}
 
+   if (dev->type != ARPHRD_ETHER) {
+   NL_SET_ERR_MSG(extack, "invalid device type");
+   return -EINVAL;
+   }
+
addr = nla_data(tb[NDA_LLADDR]);
 
err = fdb_vid_parse(tb[NDA_VLAN], , extack);
@@ -3704,6 +3709,11 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct 
nlmsghdr *nlh,
return -EINVAL;
}
 
+   if (dev->type != ARPHRD_ETHER) {
+   NL_SET_ERR_MSG(extack, "invalid device type");
+   return -EINVAL;
+   }
+
addr = nla_data(tb[NDA_LLADDR]);
 
err = fdb_vid_parse(tb[NDA_VLAN], , extack);
-- 
2.17.2



4.19 - tons of hw csum failure errors

2018-10-27 Thread Nikola Ciprich
Hi,

just wanted to report, thet after switching to 4.19 (fro 4.14.x, so maybe
the problem appeared somewhere between), I'm getting tons of similar
messages:

Oct 27 09:06:27 xxx kernel: br501: hw csum failure
Oct 27 09:06:27 xxx kernel: CPU: 8 PID: 0 Comm: swapper/8 Tainted: G
E 4.19.0lb7.00_01_PRE04 #1
Oct 27 09:06:27 xxx kernel: Hardware name: Supermicro Super Server/X11DDW-NT, 
BIOS 2.0b 03/07/2018
Oct 27 09:06:27 xxx kernel: Call Trace:
Oct 27 09:06:27 xxx kernel:  
Oct 27 09:06:27 xxx kernel:  dump_stack+0x5a/0x73
Oct 27 09:06:27 xxx kernel:  __skb_checksum_complete+0xba/0xc0
Oct 27 09:06:27 xxx kernel:  tcp_error+0x108/0x180 [nf_conntrack]
Oct 27 09:06:27 xxx kernel:  nf_conntrack_in+0xd2/0x4b0 [nf_conntrack]
Oct 27 09:06:27 xxx kernel:  ? csum_partial+0xd/0x20
Oct 27 09:06:27 xxx kernel:  nf_hook_slow+0x3d/0xb0
Oct 27 09:06:27 xxx kernel:  ip_rcv+0xb5/0xd0
Oct 27 09:06:27 xxx kernel:  ? ip_rcv_finish_core.isra.12+0x370/0x370
Oct 27 09:06:27 xxx kernel:  __netif_receive_skb_one_core+0x52/0x70
Oct 27 09:06:27 xxx kernel:  process_backlog+0xa3/0x150
Oct 27 09:06:27 xxx kernel:  net_rx_action+0x2af/0x3f0
Oct 27 09:06:27 xxx kernel:  __do_softirq+0xd1/0x28c
Oct 27 09:06:27 xxx kernel:  irq_exit+0xde/0xf0
Oct 27 09:06:27 xxx kernel:  do_IRQ+0x54/0xe0
Oct 27 09:06:27 xxx kernel:  common_interrupt+0xf/0xf
Oct 27 09:06:27 xxx kernel:  
Oct 27 09:06:27 xxx kernel: RIP: 0010:cpuidle_enter_state+0xb6/0x2e0
Oct 27 09:06:27 xxx kernel: Code: 7e e8 ee 84 b2 ff 8b 5d 04 49 89 c6 0f 1f 44 
00 00 31 ff e8 bc 95 b2 ff 80 7c 24 03 00 0f 85 93 01 00 00 fb 66 0f 1f 44 00 
00 <4d> 29 fe 48 ba cf f7 5
3 e3 a5 9b c4 20 4c 89 f0 49 c1 fe 3f 48 f7
Oct 27 09:06:27 xxx kernel: RSP: 0018:c90018b17e88 EFLAGS: 0246 
ORIG_RAX: ffdb
Oct 27 09:06:27 xxx kernel: RAX: 888faf822600 RBX: 0008 RCX: 
001f
Oct 27 09:06:27 xxx kernel: RDX:  RSI: 0002 RDI: 

Oct 27 09:06:27 xxx kernel: RBP: e8a029a8 R08: 0002 R09: 
ffe9afdaa39e3efa
Oct 27 09:06:27 xxx kernel: R10: 0377 R11: 0008 R12: 
0008
Oct 27 09:06:27 xxx kernel: R13: 0003 R14: 000d6670b7ca R15: 
000d564db458
Oct 27 09:06:27 xxx kernel:  ? cpuidle_enter_state+0xa4/0x2e0
Oct 27 09:06:27 xxx kernel:  do_idle+0x1e4/0x290
Oct 27 09:06:27 xxx kernel:  cpu_startup_entry+0x6f/0x80
Oct 27 09:06:27 xxx kernel:  start_secondary+0x1aa/0x200
Oct 27 09:06:27 xxx kernel:  secondary_startup_64+0xa4/0xb0

it's being reported for various kernel threads (swapper, ksoftirqd, ...)


I tried applying

commit db4f1be3ca9b0ef7330763d07bf4ace83ad6f913
Author: Sean Tranchetti 
Date:   Tue Oct 23 16:04:31 2018 -0600

net: udp: fix handling of CHECKSUM_COMPLETE packets

but to no avail..

the system is running virtual machines and using openvswitch with
following simple topology:

[root@xxx tmp]# ovs-vsctl show
22519243-4f9e-47dc-ac8c-3635f6595c4d
Bridge brovs
Port brovs
Interface brovs
type: internal
Port "bond0"
Interface "eth2"
Interface "eth3"
Port "vnet0"
tag: 502
Interface "vnet0"
Port brdef
tag: 0
Interface brdef
type: internal
Port "br51"
tag: 51
Interface "br51"
type: internal
Port "br50"
tag: 50
Interface "br50"
type: internal
Port "br501"
tag: 501
Interface "br501"
type: internal
ovs_version: "2.5.0"

is this some known problem? may I provide some additional info?

BR

nik


-- 
-
Ing. Nikola CIPRICH
LinuxBox.cz, s.r.o.
28. rijna 168, 709 00 Ostrava

tel.:   +420 591 166 214
fax:+420 596 621 273
mobil:  +420 777 093 799

www.linuxbox.cz

mobil servis: +420 737 238 656
email servis: ser...@linuxbox.cz
-


Re: [Patch net 09/11] net: hns3: bugfix for handling mailbox while the command queue reinitialized

2018-10-27 Thread Sergei Shtylyov

On 27.10.2018 5:41, Huazhong Tan wrote:


In a multi-core machine, the mailbox service and reset service
will be executed at the same time. The reset server will re-initialize
the commond queue, before that, the mailbox handler can only get some


   Command?


invalid messages.

The HCLGE_STATE_CMD_DISABLE flag means that the command queue is not
available and needs to be reinitialized. Therefore, when the mailbox
hanlder recognizes this flag, it should not process the command.


   Handler.



Fixes: dde1a86e93ca ("net: hns3: Add mailbox support to PF driver")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index 04462a3..6ac2fab 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -400,6 +400,12 @@ void hclge_mbx_handler(struct hclge_dev *hdev)

/* handle all the mailbox requests in the queue */
while (!hclge_cmd_crq_empty(>hw)) {
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state)) {
+   dev_warn(>pdev->dev,
+"command queue need re-initialize\n");


   Needs re-initializing.

[...]

MBR, Sergei



Re: [Patch net 05/11] net: hns3: remove unnecessary queue reset in the hns3_uninit_all_ring()

2018-10-27 Thread Sergei Shtylyov

Hello!

On 27.10.2018 5:41, Huazhong Tan wrote:


It is not necessary to reset the queue in the hns3_uninit_all_ring(),
since the queue is stopped in the down operation, and will be resetted


   s/resetted/reset/.


in the up operaton. And the judgment of the HCLGE_STATE_RST_HANDLING
flag in the hclge_reset_tqp() is not correct, because we need to reset
tqp during pf reset, otherwise it may cause queue not be resetted to


   Same here.


working state problem.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 

[...]

MBR, Sergei



[PATCH net v4] net/ipv6: Add anycast addresses to a global hashtable

2018-10-27 Thread Jeff Barnhill
icmp6_send() function is expensive on systems with a large number of
interfaces. Every time it’s called, it has to verify that the source
address does not correspond to an existing anycast address by looping
through every device and every anycast address on the device.  This can
result in significant delays for a CPU when there are a large number of
neighbors and ND timers are frequently timing out and calling
neigh_invalidate().

Add anycast addresses to a global hashtable to allow quick searching for
matching anycast addresses.  This is based on inet6_addr_lst in addrconf.c.

Signed-off-by: Jeff Barnhill <0xeff...@gmail.com>
---
 include/net/addrconf.h |   2 +
 include/net/if_inet6.h |   8 
 net/ipv6/af_inet6.c|   5 +++
 net/ipv6/anycast.c | 120 -
 4 files changed, 133 insertions(+), 2 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 14b789a123e7..799af1a037d1 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -317,6 +317,8 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device 
*dev,
 const struct in6_addr *addr);
 bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
 const struct in6_addr *addr);
+int anycast_init(void);
+void anycast_cleanup(void);
 
 /* Device notifier */
 int register_inet6addr_notifier(struct notifier_block *nb);
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index d7578cf49c3a..a445014b981d 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -142,6 +142,14 @@ struct ipv6_ac_socklist {
struct ipv6_ac_socklist *acl_next;
 };
 
+struct ipv6_ac_addrlist {
+   struct in6_addr acal_addr;
+   possible_net_t  acal_pnet;
+   refcount_t  acal_users;
+   struct hlist_node   acal_lst; /* inet6_acaddr_lst */
+   struct rcu_head rcu;
+};
+
 struct ifacaddr6 {
struct in6_addr aca_addr;
struct fib6_info*aca_rt;
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 3f4d61017a69..ddc8a6dbfba2 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -1001,6 +1001,9 @@ static int __init inet6_init(void)
err = ip6_flowlabel_init();
if (err)
goto ip6_flowlabel_fail;
+   err = anycast_init();
+   if (err)
+   goto anycast_fail;
err = addrconf_init();
if (err)
goto addrconf_fail;
@@ -1091,6 +1094,8 @@ static int __init inet6_init(void)
 ipv6_exthdrs_fail:
addrconf_cleanup();
 addrconf_fail:
+   anycast_cleanup();
+anycast_fail:
ip6_flowlabel_cleanup();
 ip6_flowlabel_fail:
ndisc_late_cleanup();
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 4e0ff7031edd..45585010908a 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -44,8 +44,22 @@
 
 #include 
 
+#define IN6_ADDR_HSIZE_SHIFT   8
+#define IN6_ADDR_HSIZE BIT(IN6_ADDR_HSIZE_SHIFT)
+/* anycast address hash table
+ */
+static struct hlist_head inet6_acaddr_lst[IN6_ADDR_HSIZE];
+static DEFINE_SPINLOCK(acaddr_hash_lock);
+
 static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr 
*addr);
 
+static u32 inet6_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   u32 val = ipv6_addr_hash(addr) ^ net_hash_mix(net);
+
+   return hash_32(val, IN6_ADDR_HSIZE_SHIFT);
+}
+
 /*
  * socket join an anycast group
  */
@@ -204,6 +218,73 @@ void ipv6_sock_ac_close(struct sock *sk)
rtnl_unlock();
 }
 
+static struct ipv6_ac_addrlist *acal_alloc(struct net *net,
+  const struct in6_addr *addr)
+{
+   struct ipv6_ac_addrlist *acal;
+
+   acal = kzalloc(sizeof(*acal), GFP_ATOMIC);
+   if (!acal)
+   return NULL;
+
+   acal->acal_addr = *addr;
+   write_pnet(>acal_pnet, net);
+   refcount_set(>acal_users, 1);
+   INIT_HLIST_NODE(>acal_lst);
+
+   return acal;
+}
+
+static int ipv6_add_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   unsigned int hash = inet6_acaddr_hash(net, addr);
+   struct ipv6_ac_addrlist *acal;
+   int err = 0;
+
+   spin_lock(_hash_lock);
+   hlist_for_each_entry(acal, _acaddr_lst[hash], acal_lst) {
+   if (!net_eq(read_pnet(>acal_pnet), net))
+   continue;
+   if (ipv6_addr_equal(>acal_addr, addr)) {
+   refcount_inc(>acal_users);
+   goto out;
+   }
+   }
+
+   acal = acal_alloc(net, addr);
+   if (!acal) {
+   err = -ENOMEM;
+   goto out;
+   }
+
+   hlist_add_head_rcu(>acal_lst, _acaddr_lst[hash]);
+
+out:
+   spin_unlock(_hash_lock);
+   return err;
+}
+
+static void ipv6_del_acaddr_hash(struct net *net, const struct in6_addr *addr)
+{
+   unsigned int hash = 

[iproute PATCH] utils.h: provide fallback CLOCK_TAI definition

2018-10-27 Thread Peter Korsgaard
q_{etf,taprio}.c uses CLOCK_TAI, which isn't exposed by glibc < 2.21 or
uClibc, breaking the build. Provide a fallback definition like it is done
for IPPROTO_MPLS and others.

Signed-off-by: Peter Korsgaard 
---
 include/utils.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/utils.h b/include/utils.h
index 258d630e..685d2c1d 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -126,6 +126,10 @@ struct ipx_addr {
 #define IPPROTO_MPLS   137
 #endif
 
+#ifndef CLOCK_TAI
+# define CLOCK_TAI 11
+#endif
+
 __u32 get_addr32(const char *name);
 int get_addr_1(inet_prefix *dst, const char *arg, int family);
 int get_prefix_1(inet_prefix *dst, char *arg, int family);
-- 
2.11.0



Re: checksumming on non-local forward path

2018-10-27 Thread Andrew Lunn
> What would you think of a flag on the receiving end like,
> "CHECKSUM_INVALID_BUT_UNNECESSARY"? It would be treated as
> CHECKSUM_UNNECESSARY in the case that the the packet is locally
> received. But if the packet is going to be forwarded instead, then
> skb_checksum_help is called on it before forwarding onward.
> 
> AFAICT, wireguard isn't the only thing that could benefit from this:
> virtio is another case where it's not always necessary for the sender
> to call skb_checksum_help, when the receiver could just do it
> conditionally based on whether it's being forwarded.

Hi Jason

It is the sort of thing which breaks in hard to find ways. I've run
network simulations with machine instances running in containers. It
used veth pairs to connect the instances to a central 'switching'
namespace which did the interconnect between the instances, using lots
of bridges. After a while, my simulation got bigger than a single host
could support. So i split it over multiple servers, using GRE tunnels
between the bridges. It took me a while to notice the network was
actually in two segments, because frames going over GRE were getting
tossed with checksum issues. It was not the GRE tunnel at fault. It
took a while to trace it back to where the checksumming was turned
off, a TAP interface i think, but i don't remember.

How do you reliably decide if a frame needs checksums, when you cannot
peer down the pipe of bridges, veth, GRE tunnels and TAP interfaces
the frame is about to take?

   Andrew



[PATCH] bonding: fix length of actor system

2018-10-27 Thread Tobias Jungel
The attribute IFLA_BOND_AD_ACTOR_SYSTEM is sent to user space having the
length of sizeof(bond->params.ad_actor_system) which is 8 byte. This
patch aligns the length to ETH_ALEN to have the same MAC address exposed
as using sysfs.

fixes f87fda00b6ed2

Signed-off-by: Tobias Jungel 
---
 drivers/net/bonding/bond_netlink.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/bonding/bond_netlink.c 
b/drivers/net/bonding/bond_netlink.c
index 9697977b80f0..6b9ad8673218 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -638,8 +638,7 @@ static int bond_fill_info(struct sk_buff *skb,
goto nla_put_failure;
 
if (nla_put(skb, IFLA_BOND_AD_ACTOR_SYSTEM,
-   sizeof(bond->params.ad_actor_system),
-   >params.ad_actor_system))
+   ETH_ALEN, >params.ad_actor_system))
goto nla_put_failure;
}
if (!bond_3ad_get_active_agg_info(bond, )) {



[PATCH] net/packet: support vhost mrg_rxbuf

2018-10-27 Thread Jianfeng Tan
Previouly, virtio net header size is hardcoded to be 10, which makes
the feature mrg_rxbuf not available.

We redefine PACKET_VNET_HDR ioctl which treats user input as boolean,
but now as int, 0, 10, 12, or everything else be treated as 10.

There will be one case which is treated differently: if user input is
12, previously, the header size will be 10; but now it's 12.

Signed-off-by: Jianfeng Tan 
---
 net/packet/af_packet.c | 97 ++
 net/packet/diag.c  |  2 +-
 net/packet/internal.h  |  2 +-
 3 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ec3095f13aae..1bd7f4cdcc80 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1999,18 +1999,24 @@ static unsigned int run_filter(struct sk_buff *skb,
 }
 
 static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb,
-  size_t *len)
+  size_t *len, int vnet_hdr_len)
 {
+   int res;
struct virtio_net_hdr vnet_hdr;
 
-   if (*len < sizeof(vnet_hdr))
+   if (*len < vnet_hdr_len)
return -EINVAL;
-   *len -= sizeof(vnet_hdr);
+   *len -= vnet_hdr_len;
 
if (virtio_net_hdr_from_skb(skb, _hdr, vio_le(), true, 0))
return -EINVAL;
 
-   return memcpy_to_msg(msg, (void *)_hdr, sizeof(vnet_hdr));
+   res = memcpy_to_msg(msg, (void *)_hdr, sizeof(vnet_hdr));
+   if (res == 0)
+   iov_iter_advance(>msg_iter,
+vnet_hdr_len - sizeof(vnet_hdr));
+
+   return res;
 }
 
 /*
@@ -2206,11 +2212,13 @@ static int tpacket_rcv(struct sk_buff *skb, struct 
net_device *dev,
  po->tp_reserve;
} else {
unsigned int maclen = skb_network_offset(skb);
+   int vnet_hdr_sz = READ_ONCE(po->vnet_hdr_sz);
+
netoff = TPACKET_ALIGN(po->tp_hdrlen +
   (maclen < 16 ? 16 : maclen)) +
   po->tp_reserve;
-   if (po->has_vnet_hdr) {
-   netoff += sizeof(struct virtio_net_hdr);
+   if (vnet_hdr_sz) {
+   netoff += vnet_hdr_sz;
do_vnet = true;
}
macoff = netoff - maclen;
@@ -2429,19 +2437,6 @@ static int __packet_snd_vnet_parse(struct virtio_net_hdr 
*vnet_hdr, size_t len)
return 0;
 }
 
-static int packet_snd_vnet_parse(struct msghdr *msg, size_t *len,
-struct virtio_net_hdr *vnet_hdr)
-{
-   if (*len < sizeof(*vnet_hdr))
-   return -EINVAL;
-   *len -= sizeof(*vnet_hdr);
-
-   if (!copy_from_iter_full(vnet_hdr, sizeof(*vnet_hdr), >msg_iter))
-   return -EFAULT;
-
-   return __packet_snd_vnet_parse(vnet_hdr, *len);
-}
-
 static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
void *frame, struct net_device *dev, void *data, int tp_len,
__be16 proto, unsigned char *addr, int hlen, int copylen,
@@ -2609,6 +2604,7 @@ static int tpacket_snd(struct packet_sock *po, struct 
msghdr *msg)
int len_sum = 0;
int status = TP_STATUS_AVAILABLE;
int hlen, tlen, copylen = 0;
+   int vnet_hdr_sz;
 
mutex_lock(>pg_vec_lock);
 
@@ -2648,7 +2644,8 @@ static int tpacket_snd(struct packet_sock *po, struct 
msghdr *msg)
size_max = po->tx_ring.frame_size
- (po->tp_hdrlen - sizeof(struct sockaddr_ll));
 
-   if ((size_max > dev->mtu + reserve + VLAN_HLEN) && !po->has_vnet_hdr)
+   vnet_hdr_sz = READ_ONCE(po->vnet_hdr_sz);
+   if ((size_max > dev->mtu + reserve + VLAN_HLEN) && !vnet_hdr_sz)
size_max = dev->mtu + reserve + VLAN_HLEN;
 
do {
@@ -2668,10 +2665,10 @@ static int tpacket_snd(struct packet_sock *po, struct 
msghdr *msg)
status = TP_STATUS_SEND_REQUEST;
hlen = LL_RESERVED_SPACE(dev);
tlen = dev->needed_tailroom;
-   if (po->has_vnet_hdr) {
+   if (vnet_hdr_sz) {
vnet_hdr = data;
-   data += sizeof(*vnet_hdr);
-   tp_len -= sizeof(*vnet_hdr);
+   data += vnet_hdr_sz;
+   tp_len -= vnet_hdr_sz;
if (tp_len < 0 ||
__packet_snd_vnet_parse(vnet_hdr, tp_len)) {
tp_len = -EINVAL;
@@ -2696,7 +2693,7 @@ static int tpacket_snd(struct packet_sock *po, struct 
msghdr *msg)
  addr, hlen, copylen, );
if (likely(tp_len >= 0) &&
tp_len > dev->mtu + reserve &&
-   !po->has_vnet_hdr &&
+   !vnet_hdr_sz &&
!packet_extra_vlan_len_allowed(dev, skb))
   

[PATCH] can: hi311x: Use level-triggered interrupt

2018-10-27 Thread Lukas Wunner
If the hi3110 shares the SPI bus with another traffic-intensive device
and packets are received in high volume (by a separate machine sending
with "cangen -g 0 -i -x"), reception stops after a few minutes and the
counter in /proc/interrupts stops incrementing.  Bus state is "active".
Bringing the interface down and back up reconvenes the reception.  The
issue is not observed when the hi3110 is the sole device on the SPI bus.

Using a level-triggered interrupt makes the issue go away and lets the
hi3110 successfully receive 2 GByte over the course of 5 days while a
ks8851 Ethernet chip on the same SPI bus handles 6 GByte of traffic.

Unfortunately the hi3110 datasheet is mum on the trigger type.  The pin
description on page 3 only specifies the polarity (active high):
http://www.holtic.com/documents/371-hi-3110_v-rev-kpdf.do

Cc: Mathias Duckeck 
Cc: Akshay Bhat 
Cc: Casey Fitzpatrick 
Signed-off-by: Lukas Wunner 
---
 Documentation/devicetree/bindings/net/can/holt_hi311x.txt | 2 +-
 drivers/net/can/spi/hi311x.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/holt_hi311x.txt 
b/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
index 903a78da65be..3a9926f99937 100644
--- a/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
+++ b/Documentation/devicetree/bindings/net/can/holt_hi311x.txt
@@ -17,7 +17,7 @@ Example:
reg = <1>;
clocks = <>;
interrupt-parent = <>;
-   interrupts = <13 IRQ_TYPE_EDGE_RISING>;
+   interrupts = <13 IRQ_TYPE_LEVEL_HIGH>;
vdd-supply = <>;
xceiver-supply = <>;
};
diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 53e320c92a8b..ddaf46239e39 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -760,7 +760,7 @@ static int hi3110_open(struct net_device *net)
 {
struct hi3110_priv *priv = netdev_priv(net);
struct spi_device *spi = priv->spi;
-   unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_RISING;
+   unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_HIGH;
int ret;
 
ret = open_candev(net);
-- 
2.19.1



[Patch V2 net 01/11] net: hns3: add error handler for hns3_nic_init_vector_data()

2018-10-27 Thread Huazhong Tan
When hns3_nic_init_vector_data() failed for mapping ring to vector,
it should cancel the netif_napi_add() that have been successfully done
and then exit.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 32f3aca8..d9066c5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2821,7 +2821,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv 
*priv)
struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_tqp_vector *tqp_vector;
int ret = 0;
-   u16 i;
+   int i, j;
 
hns3_nic_set_cpumask(priv);
 
@@ -2868,13 +2868,19 @@ static int hns3_nic_init_vector_data(struct 
hns3_nic_priv *priv)
hns3_free_vector_ring_chain(tqp_vector, _ring_chain);
 
if (ret)
-   return ret;
+   goto map_ring_fail;
 
netif_napi_add(priv->netdev, _vector->napi,
   hns3_nic_common_poll, NAPI_POLL_WEIGHT);
}
 
return 0;
+
+map_ring_fail:
+   for (j = i - 1; j >= 0; j--)
+   netif_napi_del(>tqp_vector[j].napi);
+
+   return ret;
 }
 
 static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv)
-- 
2.7.4



[Patch V2 net 04/11] net: hns3: bugfix for the initialization of command queue's spin lock

2018-10-27 Thread Huazhong Tan
The spin lock of the command queue only needs to be initialized once
when the driver initializes the command queue. It is not necessary to
initialize the spin lock when resetting. At the same time, the
modification of the queue member should be performed after acquiring
the lock.

Fixes: 3efb960f056d ("net: hns3: Refactor the initialization of command queue")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index ac13cb2..68026a5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -304,6 +304,10 @@ int hclge_cmd_queue_init(struct hclge_dev *hdev)
 {
int ret;
 
+   /* Setup the lock for command queue */
+   spin_lock_init(>hw.cmq.csq.lock);
+   spin_lock_init(>hw.cmq.crq.lock);
+
/* Setup the queue entries for use cmd queue */
hdev->hw.cmq.csq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
hdev->hw.cmq.crq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
@@ -337,18 +341,20 @@ int hclge_cmd_init(struct hclge_dev *hdev)
u32 version;
int ret;
 
+   spin_lock_bh(>hw.cmq.csq.lock);
+   spin_lock_bh(>hw.cmq.crq.lock);
+
hdev->hw.cmq.csq.next_to_clean = 0;
hdev->hw.cmq.csq.next_to_use = 0;
hdev->hw.cmq.crq.next_to_clean = 0;
hdev->hw.cmq.crq.next_to_use = 0;
 
-   /* Setup the lock for command queue */
-   spin_lock_init(>hw.cmq.csq.lock);
-   spin_lock_init(>hw.cmq.crq.lock);
-
hclge_cmd_init_regs(>hw);
clear_bit(HCLGE_STATE_CMD_DISABLE, >state);
 
+   spin_unlock_bh(>hw.cmq.crq.lock);
+   spin_unlock_bh(>hw.cmq.csq.lock);
+
ret = hclge_cmd_query_firmware_version(>hw, );
if (ret) {
dev_err(>pdev->dev,
-- 
2.7.4



[Patch V2 net 02/11] net: hns3: add error handler for hns3_get_ring_config/hns3_queue_to_ring

2018-10-27 Thread Huazhong Tan
When hns3_get_ring_config()/hns3_queue_to_ring() failed during resetting,
the allocated memory has not been freed before hns3_get_ring_config() and
hns3_queue_to_ring() return. So this patch fixes the buffer not freeing
problem during resetting.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index d9066c5..6f0fd62 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3037,8 +3037,10 @@ static int hns3_queue_to_ring(struct hnae3_queue *tqp,
return ret;
 
ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX);
-   if (ret)
+   if (ret) {
+   devm_kfree(priv->dev, priv->ring_data[tqp->tqp_index].ring);
return ret;
+   }
 
return 0;
 }
@@ -3047,7 +3049,7 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
 {
struct hnae3_handle *h = priv->ae_handle;
struct pci_dev *pdev = h->pdev;
-   int i, ret;
+   int i, j, ret;
 
priv->ring_data =  devm_kzalloc(>dev,
array3_size(h->kinfo.num_tqps,
@@ -3065,6 +3067,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
 
return 0;
 err:
+   for (j = i - 1; j >= 0; j--) {
+   devm_kfree(priv->dev, priv->ring_data[j].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[j + h->kinfo.num_tqps].ring);
+   }
+
devm_kfree(>dev, priv->ring_data);
return ret;
 }
-- 
2.7.4



[Patch V2 net 10/11] net: hns3: bugfix for rtnl_lock's range in the hclge_reset()

2018-10-27 Thread Huazhong Tan
Since hclge_reset_wait() is used to wait for the hardware to complete
the reset, it is not necessary to hold the rtnl_lock during
hclge_reset_wait(). So this patch release the lock for the duration
of hclge_reset_wait().

Fixes: 6d4fab39533f ("net: hns3: Reset net device with rtnl_lock")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f3212c9..ffdd960 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2470,14 +2470,17 @@ static void hclge_reset(struct hclge_dev *hdev)
handle = >vport[0].nic;
rtnl_lock();
hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
+   rtnl_unlock();
 
if (!hclge_reset_wait(hdev)) {
+   rtnl_lock();
hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
hclge_reset_ae_dev(hdev->ae_dev);
hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
 
hclge_clear_reset_cause(hdev);
} else {
+   rtnl_lock();
/* schedule again to check pending resets later */
set_bit(hdev->reset_type, >reset_pending);
hclge_reset_task_schedule(hdev);
-- 
2.7.4



[Patch V2 net 00/11] Bugfix for the HNS3 driver

2018-10-27 Thread Huazhong Tan
This patch series include bugfix for the HNS3 ethernet
controller driver.

Change log:
V1->V2:
Fixes the compilation break reported by kbuild test robot
http://patchwork.ozlabs.org/patch/989818/

Huazhong Tan (11):
  net: hns3: add error handler for hns3_nic_init_vector_data()
  net: hns3: add error handler for
hns3_get_ring_config/hns3_queue_to_ring
  net: hns3: bugfix for reporting unknown vector0 interrupt repeatly
problem
  net: hns3: bugfix for the initialization of command queue's spin lock
  net: hns3: remove unnecessary queue reset in the
hns3_uninit_all_ring()
  net: hns3: bugfix for is_valid_csq_clean_head()
  net: hns3: bugfix for hclge_mdio_write and hclge_mdio_read
  net: hns3: fix incorrect return value/type of some functions
  net: hns3: bugfix for handling mailbox while the command queue
reinitialized
  net: hns3: bugfix for rtnl_lock's range in the hclge_reset()
  net: hns3: bugfix for rtnl_lock's range in the hclgevf_reset()

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 105 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  26 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  42 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |   6 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   4 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  19 ++--
 9 files changed, 136 insertions(+), 76 deletions(-)

-- 
2.7.4



[Patch V2 net 03/11] net: hns3: bugfix for reporting unknown vector0 interrupt repeatly problem

2018-10-27 Thread Huazhong Tan
The current driver supports handling two vector0 interrupts, reset and
mailbox. When the hardware reports an interrupt of another type of
interrupt source, if the driver does not process the interrupt and
enables the interrupt, the hardware will repeatedly report the unknown
interrupt.

Therefore, the driver enables the vector0 interrupt after clearing the
known type of interrupt source. Other conditions are not enabled.

Fixes: cd8c5c269b1d ("net: hns3: Fix for hclge_reset running repeatly problem")
Signed-off-by: Huazhong Tan 
---
 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 5234b53..2a63147 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2236,7 +2236,7 @@ static irqreturn_t hclge_misc_irq_handle(int irq, void 
*data)
}
 
/* clear the source of interrupt if it is not cause by reset */
-   if (event_cause != HCLGE_VECTOR0_EVENT_RST) {
+   if (event_cause == HCLGE_VECTOR0_EVENT_MBX) {
hclge_clear_event_cause(hdev, event_cause, clearval);
hclge_enable_vector(>misc_vector, true);
}
-- 
2.7.4



[Patch V2 net 07/11] net: hns3: bugfix for hclge_mdio_write and hclge_mdio_read

2018-10-27 Thread Huazhong Tan
When there is a PHY, the driver needs to complete some operations through
MDIO during reset reinitialization, so HCLGE_STATE_CMD_DISABLE is more
suitable than HCLGE_STATE_RST_HANDLING to prevent the MDIO operation from
being sent during the hardware reset.

Fixes: b50ae26c57cb ("net: hns3: never send command queue message to IMP when 
reset)
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 24b1f2a..0301863 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -52,7 +52,7 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, 
int regnum,
struct hclge_desc desc;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state))
return 0;
 
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
@@ -90,7 +90,7 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, 
int regnum)
struct hclge_desc desc;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state))
return 0;
 
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
-- 
2.7.4



[Patch V2 net 08/11] net: hns3: fix incorrect return value/type of some functions

2018-10-27 Thread Huazhong Tan
There are some functions that, when they fail to execute a send command,
need to return the corresponding error value to its caller.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Fixes: 681ec3999b3d ("net: hns3: fix for vlan table lost problem when 
resetting")
Signed-off-by: Huazhong Tan 
---
V2: Fix the compilation error reported by kbuild test robot
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 80 +++---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|  2 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 34 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  2 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 14 ++--
 6 files changed, 85 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index e82e4ca..055b406 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -316,8 +316,8 @@ struct hnae3_ae_ops {
int (*set_loopback)(struct hnae3_handle *handle,
enum hnae3_loop loop_mode, bool en);
 
-   void (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
-bool en_mc_pmc);
+   int (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
+   bool en_mc_pmc);
int (*set_mtu)(struct hnae3_handle *handle, int new_mtu);
 
void (*get_pauseparam)(struct hnae3_handle *handle,
@@ -391,7 +391,7 @@ struct hnae3_ae_ops {
  int vector_num,
  struct hnae3_ring_chain_node *vr_chain);
 
-   void (*reset_queue)(struct hnae3_handle *handle, u16 queue_id);
+   int (*reset_queue)(struct hnae3_handle *handle, u16 queue_id);
u32 (*get_fw_version)(struct hnae3_handle *handle);
void (*get_mdix_mode)(struct hnae3_handle *handle,
  u8 *tp_mdix_ctrl, u8 *tp_mdix);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index a80ecfb..4d919b8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -509,16 +509,18 @@ static void hns3_nic_set_rx_mode(struct net_device 
*netdev)
h->netdev_flags = new_flags;
 }
 
-void hns3_update_promisc_mode(struct net_device *netdev, u8 promisc_flags)
+int hns3_update_promisc_mode(struct net_device *netdev, u8 promisc_flags)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = priv->ae_handle;
 
if (h->ae_algo->ops->set_promisc_mode) {
-   h->ae_algo->ops->set_promisc_mode(h,
- promisc_flags & HNAE3_UPE,
- promisc_flags & HNAE3_MPE);
+   return h->ae_algo->ops->set_promisc_mode(h,
+   promisc_flags & HNAE3_UPE,
+   promisc_flags & HNAE3_MPE);
}
+
+   return 0;
 }
 
 void hns3_enable_vlan_filter(struct net_device *netdev, bool enable)
@@ -1494,18 +1496,22 @@ static int hns3_vlan_rx_kill_vid(struct net_device 
*netdev,
return ret;
 }
 
-static void hns3_restore_vlan(struct net_device *netdev)
+static int hns3_restore_vlan(struct net_device *netdev)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   int ret = 0;
u16 vid;
-   int ret;
 
for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
ret = hns3_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
-   if (ret)
-   netdev_warn(netdev, "Restore vlan: %d filter, ret:%d\n",
-   vid, ret);
+   if (ret) {
+   netdev_err(netdev, "Restore vlan: %d filter, ret:%d\n",
+  vid, ret);
+   return ret;
+   }
}
+
+   return ret;
 }
 
 static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
@@ -3247,11 +3253,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
 }
 
 /* Set mac addr if it is configured. or leave it to the AE driver */
-static void hns3_init_mac_addr(struct net_device *netdev, bool init)
+static int hns3_init_mac_addr(struct net_device *netdev, bool init)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = priv->ae_handle;
u8 mac_addr_temp[ETH_ALEN];
+   int ret = 0;
 
if (h->ae_algo->ops->get_mac_addr && init) {
h->ae_algo->ops->get_mac_addr(h, mac_addr_temp);
@@ -3266,8 +3273,9 @@ static void hns3_init_mac_addr(struct net_device *netdev, 
bool init)
}
 
if 

[Patch V2 net 06/11] net: hns3: bugfix for is_valid_csq_clean_head()

2018-10-27 Thread Huazhong Tan
The HEAD pointer of the hardware command queue maybe equal to the command
queue's next_to_use the driver, so that does not belong to the invalid
HEAD pointer, since the hardware may not process the command in time,
causing the HEAD pointer to be too late to update. The variables' name
in this function is unreadable, so give them a more readable one.

Fixes: 3ff504908f95 ("net: hns3: fix a dead loop in hclge_cmd_csq_clean")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 68026a5..690f62e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -24,15 +24,15 @@ static int hclge_ring_space(struct hclge_cmq_ring *ring)
return ring->desc_num - used - 1;
 }
 
-static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int h)
+static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int head)
 {
-   int u = ring->next_to_use;
-   int c = ring->next_to_clean;
+   int ntu = ring->next_to_use;
+   int ntc = ring->next_to_clean;
 
-   if (unlikely(h >= ring->desc_num))
-   return 0;
+   if (ntu > ntc)
+   return head >= ntc && head <= ntu;
 
-   return u > c ? (h > c && h <= u) : (h > c || h <= u);
+   return head >= ntc || head <= ntu;
 }
 
 static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
-- 
2.7.4



[Patch V2 net 05/11] net: hns3: remove unnecessary queue reset in the hns3_uninit_all_ring()

2018-10-27 Thread Huazhong Tan
It is not necessary to reset the queue in the hns3_uninit_all_ring(),
since the queue is stopped in the down operation, and will be resetted
in the up operaton. And the judgment of the HCLGE_STATE_RST_HANDLING
flag in the hclge_reset_tqp() is not correct, because we need to reset
tqp during pf reset, otherwise it may cause queue not be resetted to
working state problem.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 3 ---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 6f0fd62..a80ecfb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3240,9 +3240,6 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
int i;
 
for (i = 0; i < h->kinfo.num_tqps; i++) {
-   if (h->ae_algo->ops->reset_queue)
-   h->ae_algo->ops->reset_queue(h, i);
-
hns3_fini_ring(priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 2a63147..4dd0506 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -6116,9 +6116,6 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
u16 queue_gid;
int ret;
 
-   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
-   return;
-
queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
 
ret = hclge_tqp_enable(hdev, queue_id, 0, false);
-- 
2.7.4



[Patch V2 net 09/11] net: hns3: bugfix for handling mailbox while the command queue reinitialized

2018-10-27 Thread Huazhong Tan
In a multi-core machine, the mailbox service and reset service
will be executed at the same time. The reset server will re-initialize
the commond queue, before that, the mailbox handler can only get some
invalid messages.

The HCLGE_STATE_CMD_DISABLE flag means that the command queue is not
available and needs to be reinitialized. Therefore, when the mailbox
hanlder recognizes this flag, it should not process the command.

Fixes: dde1a86e93ca ("net: hns3: Add mailbox support to PF driver")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index 04462a3..6ac2fab 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -400,6 +400,12 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
 
/* handle all the mailbox requests in the queue */
while (!hclge_cmd_crq_empty(>hw)) {
+   if (test_bit(HCLGE_STATE_CMD_DISABLE, >state)) {
+   dev_warn(>pdev->dev,
+"command queue need re-initialize\n");
+   return;
+   }
+
desc = >desc[crq->next_to_use];
req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data;
 
-- 
2.7.4



[Patch V2 net 11/11] net: hns3: bugfix for rtnl_lock's range in the hclgevf_reset()

2018-10-27 Thread Huazhong Tan
Since hclgevf_reset_wait() is used to wait for the hardware to complete
the reset, it is not necessary to hold the rtnl_lock during
hclgevf_reset_wait(). So this patch release the lock for the duration
of hclgevf_reset_wait().

Fixes: 6988eb2a9b77 ("net: hns3: Add support to reset the enet/ring mgmt layer")
Signed-off-by: Huazhong Tan 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index b224f6a..085edb9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1170,6 +1170,8 @@ static int hclgevf_reset(struct hclgevf_dev *hdev)
/* bring down the nic to stop any ongoing TX/RX */
hclgevf_notify_client(hdev, HNAE3_DOWN_CLIENT);
 
+   rtnl_unlock();
+
/* check if VF could successfully fetch the hardware reset completion
 * status from the hardware
 */
@@ -1181,12 +1183,15 @@ static int hclgevf_reset(struct hclgevf_dev *hdev)
ret);
 
dev_warn(>pdev->dev, "VF reset failed, disabling VF!\n");
+   rtnl_lock();
hclgevf_notify_client(hdev, HNAE3_UNINIT_CLIENT);
 
rtnl_unlock();
return ret;
}
 
+   rtnl_lock();
+
/* now, re-initialize the nic client and ae device*/
ret = hclgevf_reset_stack(hdev);
if (ret)
-- 
2.7.4



Re: [net:master 17/19] net//bridge/br_multicast.c:1432:32: error: 'union ' has no member named 'ip6'; did you mean 'ip4'?

2018-10-27 Thread Nikolay Aleksandrov
On 27/10/2018 03:50, kbuild test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git master
> head:   aab456dfa404f3a16d6f1780e62a6a8533c4d008
> commit: 5a2de63fd1a59c30c02526d427bc014b98adf508 [17/19] bridge: do not add 
> port to router list when receives query with source 0.0.0.0
> config: powerpc-defconfig (attached as .config)
> compiler: powerpc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
> wget 
> https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
> ~/bin/make.cross
> chmod +x ~/bin/make.cross
> git checkout 5a2de63fd1a59c30c02526d427bc014b98adf508
> # save the attached .config to linux build tree
> GCC_VERSION=7.2.0 make.cross ARCH=powerpc 
> 
> All errors (new ones prefixed by >>):
> 
>net//bridge/br_multicast.c: In function 'br_multicast_query_received':
>>> net//bridge/br_multicast.c:1432:32: error: 'union ' has no 
>>> member named 'ip6'; did you mean 'ip4'?
>   !ipv6_addr_any(>u.ip6)))
>^~~
>ip4
> 
> vim +1432 net//bridge/br_multicast.c
> 
>   1414
>   1415static void br_multicast_query_received(struct net_bridge *br,
>   1416struct net_bridge_port 
> *port,
>   1417struct 
> bridge_mcast_other_query *query,
>   1418struct br_ip *saddr,
>   1419unsigned long max_delay)
>   1420{
>   1421if (!br_multicast_select_querier(br, port, saddr))
>   1422return;
>   1423
>   1424br_multicast_update_query_timer(br, query, max_delay);
>   1425
>   1426/* Based on RFC4541, section 2.1.1 IGMP Forwarding 
> Rules,
>   1427 * the arrival port for IGMP Queries where the source 
> address
>   1428 * is 0.0.0.0 should not be added to router port list.
>   1429 */
>   1430if ((saddr->proto == htons(ETH_P_IP) && saddr->u.ip4) ||
>   1431(saddr->proto == htons(ETH_P_IPV6) &&
>> 1432  !ipv6_addr_any(>u.ip6)))
>   1433br_multicast_mark_router(br, port);
>   1434}
>   1435
> 
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://lists.01.org/pipermail/kbuild-all   Intel Corporation
> 

Should've seen this one coming when reviewing the patch, ip6 is defined
only when IPv6 is configured.
I'll send a fix in a minute after running a few tests.

Thanks.


[PATCH] xfrm: Fix error return code in xfrm_output_one()

2018-10-27 Thread Wei Yongjun
xfrm_output_one() does not return a error code when there is
no dst_entry attached to the skb, it is still possible crash
with a NULL pointer dereference in xfrm_output_resume(). Fix
it by return error code -EHOSTUNREACH.

Fixes: 9e1437937807 ("xfrm: Fix NULL pointer dereference when skb_dst_force 
clears the dst_entry.")
Signed-off-by: Wei Yongjun 
---
 net/xfrm/xfrm_output.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 4ae87c5c..fef6b2d 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -102,6 +102,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
skb_dst_force(skb);
if (!skb_dst(skb)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+   err = -EHOSTUNREACH;
goto error_nolock;
}