aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-04-24 17:16:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-24 17:16:40 -0400
commit24cac7009cb1b211f1c793ecb6a462c03dc35818 (patch)
tree3c1e77363ed730b38a9c4bd842a187a8250d34b7
parent6d08b06e67cd117f6992c46611dfb4ce267cd71e (diff)
parentd19efb729f10339f91c35003d480dc718cae3b3c (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: 1) Fix rtnl deadlock in ipvs, from Julian Anastasov. 2) s390 qeth fixes from Julian Wiedmann (control IO completion stalls, bad MAC address update sequence, request side races on command IO timeouts). 3) Handle seq_file overflow properly in l2tp, from Guillaume Nault. 4) Fix VLAN priority mappings in cpsw driver, from Ivan Khoronzhuk. 5) Packet scheduler ife action fixes (malformed TLV lengths, etc.) from Alexander Aring. 6) Fix out of bounds access in tcp md5 option parser, from Jann Horn. 7) Missing netlink attribute policies in rtm_ipv6_policy table, from Eric Dumazet. 8) Missing socket address length checks in l2tp and pppoe connect, from Guillaume Nault. 9) Fix netconsole over team and bonding, from Xin Long. 10) Fix race with AF_PACKET socket state bitfields, from Willem de Bruijn. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (51 commits) ice: Fix insufficient memory issue in ice_aq_manage_mac_read sfc: ARFS filter IDs net: ethtool: Add missing kernel doc for FEC parameters packet: fix bitfield update race ice: Do not check INTEVENT bit for OICR interrupts ice: Fix incorrect comment for action type ice: Fix initialization for num_nodes_added igb: Fix the transmission mode of queue 0 for Qav mode ixgbevf: ensure xdp_ring resources are free'd on error exit team: fix netconsole setup over team amd-xgbe: Only use the SFP supported transceiver signals amd-xgbe: Improve KR auto-negotiation and training amd-xgbe: Add pre/post auto-negotiation phy hooks pppoe: check sockaddr length in pppoe_connect() l2tp: check sockaddr length in pppol2tp_connect() net: phy: marvell: clear wol event before setting it ipv6: add RTA_TABLE and RTA_PREFSRC to rtm_ipv6_policy bonding: do not set slave_dev npinfo before slave_enable_netpoll in bond_enslave tcp: don't read out-of-bounds opsize ibmvnic: Clean actual number of RX or TX pools ...
-rw-r--r--drivers/net/bonding/bond_main.c3
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-common.h8
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c16
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-main.c1
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-mdio.c24
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-pci.c2
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c196
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe.h9
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c4
-rw-r--r--drivers/net/ethernet/intel/ice/ice_adminq_cmd.h2
-rw-r--r--drivers/net/ethernet/intel/ice/ice_common.c22
-rw-r--r--drivers/net/ethernet/intel/ice/ice_hw_autogen.h2
-rw-r--r--drivers/net/ethernet/intel/ice/ice_main.c4
-rw-r--r--drivers/net/ethernet/intel/ice/ice_sched.c4
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c17
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c2
-rw-r--r--drivers/net/ethernet/sfc/ef10.c80
-rw-r--r--drivers/net/ethernet/sfc/efx.c143
-rw-r--r--drivers/net/ethernet/sfc/efx.h21
-rw-r--r--drivers/net/ethernet/sfc/farch.c41
-rw-r--r--drivers/net/ethernet/sfc/net_driver.h36
-rw-r--r--drivers/net/ethernet/sfc/rx.c62
-rw-r--r--drivers/net/ethernet/ti/cpsw.c2
-rw-r--r--drivers/net/phy/marvell.c9
-rw-r--r--drivers/net/ppp/pppoe.c4
-rw-r--r--drivers/net/team/team.c19
-rw-r--r--drivers/s390/net/qeth_core.h2
-rw-r--r--drivers/s390/net/qeth_core_main.c158
-rw-r--r--drivers/s390/net/qeth_core_mpc.h12
-rw-r--r--drivers/s390/net/qeth_l2_main.c59
-rw-r--r--include/linux/bpf.h4
-rw-r--r--include/linux/ethtool.h2
-rw-r--r--include/net/ife.h3
-rw-r--r--include/net/llc_conn.h1
-rw-r--r--kernel/bpf/core.c45
-rw-r--r--kernel/bpf/sockmap.c3
-rw-r--r--kernel/trace/bpf_trace.c25
-rw-r--r--net/bridge/netfilter/ebtables.c11
-rw-r--r--net/ife/ife.c38
-rw-r--r--net/ipv4/tcp_input.c7
-rw-r--r--net/ipv6/netfilter/Kconfig55
-rw-r--r--net/ipv6/route.c2
-rw-r--r--net/ipv6/seg6_iptunnel.c2
-rw-r--r--net/l2tp/l2tp_debugfs.c5
-rw-r--r--net/l2tp/l2tp_ppp.c12
-rw-r--r--net/llc/af_llc.c21
-rw-r--r--net/llc/llc_c_ac.c9
-rw-r--r--net/llc/llc_conn.c22
-rw-r--r--net/netfilter/Kconfig1
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c8
-rw-r--r--net/netfilter/ipvs/ip_vs_sync.c155
-rw-r--r--net/netfilter/nf_conntrack_expect.c5
-rw-r--r--net/netfilter/nf_conntrack_extend.c2
-rw-r--r--net/netfilter/nf_conntrack_sip.c16
-rw-r--r--net/netfilter/nf_tables_api.c69
-rw-r--r--net/netfilter/xt_connmark.c49
-rw-r--r--net/packet/af_packet.c60
-rw-r--r--net/packet/internal.h10
-rw-r--r--net/sched/act_ife.c9
-rw-r--r--net/strparser/strparser.c2
-rw-r--r--tools/testing/selftests/bpf/.gitignore3
-rw-r--r--tools/testing/selftests/bpf/test_sock.c1
-rw-r--r--tools/testing/selftests/bpf/test_sock_addr.c1
-rwxr-xr-xtools/testing/selftests/bpf/test_sock_addr.sh4
64 files changed, 1163 insertions, 463 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b7b113018853..718e4914e3a0 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1660,8 +1660,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
1660 } /* switch(bond_mode) */ 1660 } /* switch(bond_mode) */
1661 1661
1662#ifdef CONFIG_NET_POLL_CONTROLLER 1662#ifdef CONFIG_NET_POLL_CONTROLLER
1663 slave_dev->npinfo = bond->dev->npinfo; 1663 if (bond->dev->npinfo) {
1664 if (slave_dev->npinfo) {
1665 if (slave_enable_netpoll(new_slave)) { 1664 if (slave_enable_netpoll(new_slave)) {
1666 netdev_info(bond_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n"); 1665 netdev_info(bond_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
1667 res = -EBUSY; 1666 res = -EBUSY;
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
index 7ea72ef11a55..d272dc6984ac 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
@@ -1321,6 +1321,10 @@
1321#define MDIO_VEND2_AN_STAT 0x8002 1321#define MDIO_VEND2_AN_STAT 0x8002
1322#endif 1322#endif
1323 1323
1324#ifndef MDIO_VEND2_PMA_CDR_CONTROL
1325#define MDIO_VEND2_PMA_CDR_CONTROL 0x8056
1326#endif
1327
1324#ifndef MDIO_CTRL1_SPEED1G 1328#ifndef MDIO_CTRL1_SPEED1G
1325#define MDIO_CTRL1_SPEED1G (MDIO_CTRL1_SPEED10G & ~BMCR_SPEED100) 1329#define MDIO_CTRL1_SPEED1G (MDIO_CTRL1_SPEED10G & ~BMCR_SPEED100)
1326#endif 1330#endif
@@ -1369,6 +1373,10 @@
1369#define XGBE_AN_CL37_TX_CONFIG_MASK 0x08 1373#define XGBE_AN_CL37_TX_CONFIG_MASK 0x08
1370#define XGBE_AN_CL37_MII_CTRL_8BIT 0x0100 1374#define XGBE_AN_CL37_MII_CTRL_8BIT 0x0100
1371 1375
1376#define XGBE_PMA_CDR_TRACK_EN_MASK 0x01
1377#define XGBE_PMA_CDR_TRACK_EN_OFF 0x00
1378#define XGBE_PMA_CDR_TRACK_EN_ON 0x01
1379
1372/* Bit setting and getting macros 1380/* Bit setting and getting macros
1373 * The get macro will extract the current bit field value from within 1381 * The get macro will extract the current bit field value from within
1374 * the variable 1382 * the variable
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
index 7d128be61310..b91143947ed2 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
@@ -519,6 +519,22 @@ void xgbe_debugfs_init(struct xgbe_prv_data *pdata)
519 "debugfs_create_file failed\n"); 519 "debugfs_create_file failed\n");
520 } 520 }
521 521
522 if (pdata->vdata->an_cdr_workaround) {
523 pfile = debugfs_create_bool("an_cdr_workaround", 0600,
524 pdata->xgbe_debugfs,
525 &pdata->debugfs_an_cdr_workaround);
526 if (!pfile)
527 netdev_err(pdata->netdev,
528 "debugfs_create_bool failed\n");
529
530 pfile = debugfs_create_bool("an_cdr_track_early", 0600,
531 pdata->xgbe_debugfs,
532 &pdata->debugfs_an_cdr_track_early);
533 if (!pfile)
534 netdev_err(pdata->netdev,
535 "debugfs_create_bool failed\n");
536 }
537
522 kfree(buf); 538 kfree(buf);
523} 539}
524 540
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
index 795e556d4a3f..441d0973957b 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
@@ -349,6 +349,7 @@ int xgbe_config_netdev(struct xgbe_prv_data *pdata)
349 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); 349 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
350 350
351 /* Call MDIO/PHY initialization routine */ 351 /* Call MDIO/PHY initialization routine */
352 pdata->debugfs_an_cdr_workaround = pdata->vdata->an_cdr_workaround;
352 ret = pdata->phy_if.phy_init(pdata); 353 ret = pdata->phy_if.phy_init(pdata);
353 if (ret) 354 if (ret)
354 return ret; 355 return ret;
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
index 072b9f664597..1b45cd73a258 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
@@ -432,11 +432,16 @@ static void xgbe_an73_disable(struct xgbe_prv_data *pdata)
432 xgbe_an73_set(pdata, false, false); 432 xgbe_an73_set(pdata, false, false);
433 xgbe_an73_disable_interrupts(pdata); 433 xgbe_an73_disable_interrupts(pdata);
434 434
435 pdata->an_start = 0;
436
435 netif_dbg(pdata, link, pdata->netdev, "CL73 AN disabled\n"); 437 netif_dbg(pdata, link, pdata->netdev, "CL73 AN disabled\n");
436} 438}
437 439
438static void xgbe_an_restart(struct xgbe_prv_data *pdata) 440static void xgbe_an_restart(struct xgbe_prv_data *pdata)
439{ 441{
442 if (pdata->phy_if.phy_impl.an_pre)
443 pdata->phy_if.phy_impl.an_pre(pdata);
444
440 switch (pdata->an_mode) { 445 switch (pdata->an_mode) {
441 case XGBE_AN_MODE_CL73: 446 case XGBE_AN_MODE_CL73:
442 case XGBE_AN_MODE_CL73_REDRV: 447 case XGBE_AN_MODE_CL73_REDRV:
@@ -453,6 +458,9 @@ static void xgbe_an_restart(struct xgbe_prv_data *pdata)
453 458
454static void xgbe_an_disable(struct xgbe_prv_data *pdata) 459static void xgbe_an_disable(struct xgbe_prv_data *pdata)
455{ 460{
461 if (pdata->phy_if.phy_impl.an_post)
462 pdata->phy_if.phy_impl.an_post(pdata);
463
456 switch (pdata->an_mode) { 464 switch (pdata->an_mode) {
457 case XGBE_AN_MODE_CL73: 465 case XGBE_AN_MODE_CL73:
458 case XGBE_AN_MODE_CL73_REDRV: 466 case XGBE_AN_MODE_CL73_REDRV:
@@ -505,11 +513,11 @@ static enum xgbe_an xgbe_an73_tx_training(struct xgbe_prv_data *pdata,
505 XMDIO_WRITE(pdata, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL, 513 XMDIO_WRITE(pdata, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL,
506 reg); 514 reg);
507 515
508 if (pdata->phy_if.phy_impl.kr_training_post)
509 pdata->phy_if.phy_impl.kr_training_post(pdata);
510
511 netif_dbg(pdata, link, pdata->netdev, 516 netif_dbg(pdata, link, pdata->netdev,
512 "KR training initiated\n"); 517 "KR training initiated\n");
518
519 if (pdata->phy_if.phy_impl.kr_training_post)
520 pdata->phy_if.phy_impl.kr_training_post(pdata);
513 } 521 }
514 522
515 return XGBE_AN_PAGE_RECEIVED; 523 return XGBE_AN_PAGE_RECEIVED;
@@ -637,11 +645,11 @@ static enum xgbe_an xgbe_an73_incompat_link(struct xgbe_prv_data *pdata)
637 return XGBE_AN_NO_LINK; 645 return XGBE_AN_NO_LINK;
638 } 646 }
639 647
640 xgbe_an73_disable(pdata); 648 xgbe_an_disable(pdata);
641 649
642 xgbe_switch_mode(pdata); 650 xgbe_switch_mode(pdata);
643 651
644 xgbe_an73_restart(pdata); 652 xgbe_an_restart(pdata);
645 653
646 return XGBE_AN_INCOMPAT_LINK; 654 return XGBE_AN_INCOMPAT_LINK;
647} 655}
@@ -820,6 +828,9 @@ static void xgbe_an37_state_machine(struct xgbe_prv_data *pdata)
820 pdata->an_result = pdata->an_state; 828 pdata->an_result = pdata->an_state;
821 pdata->an_state = XGBE_AN_READY; 829 pdata->an_state = XGBE_AN_READY;
822 830
831 if (pdata->phy_if.phy_impl.an_post)
832 pdata->phy_if.phy_impl.an_post(pdata);
833
823 netif_dbg(pdata, link, pdata->netdev, "CL37 AN result: %s\n", 834 netif_dbg(pdata, link, pdata->netdev, "CL37 AN result: %s\n",
824 xgbe_state_as_string(pdata->an_result)); 835 xgbe_state_as_string(pdata->an_result));
825 } 836 }
@@ -903,6 +914,9 @@ again:
903 pdata->kx_state = XGBE_RX_BPA; 914 pdata->kx_state = XGBE_RX_BPA;
904 pdata->an_start = 0; 915 pdata->an_start = 0;
905 916
917 if (pdata->phy_if.phy_impl.an_post)
918 pdata->phy_if.phy_impl.an_post(pdata);
919
906 netif_dbg(pdata, link, pdata->netdev, "CL73 AN result: %s\n", 920 netif_dbg(pdata, link, pdata->netdev, "CL73 AN result: %s\n",
907 xgbe_state_as_string(pdata->an_result)); 921 xgbe_state_as_string(pdata->an_result));
908 } 922 }
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
index eb23f9ba1a9a..82d1f416ee2a 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
@@ -456,6 +456,7 @@ static const struct xgbe_version_data xgbe_v2a = {
456 .irq_reissue_support = 1, 456 .irq_reissue_support = 1,
457 .tx_desc_prefetch = 5, 457 .tx_desc_prefetch = 5,
458 .rx_desc_prefetch = 5, 458 .rx_desc_prefetch = 5,
459 .an_cdr_workaround = 1,
459}; 460};
460 461
461static const struct xgbe_version_data xgbe_v2b = { 462static const struct xgbe_version_data xgbe_v2b = {
@@ -470,6 +471,7 @@ static const struct xgbe_version_data xgbe_v2b = {
470 .irq_reissue_support = 1, 471 .irq_reissue_support = 1,
471 .tx_desc_prefetch = 5, 472 .tx_desc_prefetch = 5,
472 .rx_desc_prefetch = 5, 473 .rx_desc_prefetch = 5,
474 .an_cdr_workaround = 1,
473}; 475};
474 476
475static const struct pci_device_id xgbe_pci_table[] = { 477static const struct pci_device_id xgbe_pci_table[] = {
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
index 3304a291aa96..aac884314000 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
@@ -147,6 +147,14 @@
147/* Rate-change complete wait/retry count */ 147/* Rate-change complete wait/retry count */
148#define XGBE_RATECHANGE_COUNT 500 148#define XGBE_RATECHANGE_COUNT 500
149 149
150/* CDR delay values for KR support (in usec) */
151#define XGBE_CDR_DELAY_INIT 10000
152#define XGBE_CDR_DELAY_INC 10000
153#define XGBE_CDR_DELAY_MAX 100000
154
155/* RRC frequency during link status check */
156#define XGBE_RRC_FREQUENCY 10
157
150enum xgbe_port_mode { 158enum xgbe_port_mode {
151 XGBE_PORT_MODE_RSVD = 0, 159 XGBE_PORT_MODE_RSVD = 0,
152 XGBE_PORT_MODE_BACKPLANE, 160 XGBE_PORT_MODE_BACKPLANE,
@@ -245,6 +253,10 @@ enum xgbe_sfp_speed {
245#define XGBE_SFP_BASE_VENDOR_SN 4 253#define XGBE_SFP_BASE_VENDOR_SN 4
246#define XGBE_SFP_BASE_VENDOR_SN_LEN 16 254#define XGBE_SFP_BASE_VENDOR_SN_LEN 16
247 255
256#define XGBE_SFP_EXTD_OPT1 1
257#define XGBE_SFP_EXTD_OPT1_RX_LOS BIT(1)
258#define XGBE_SFP_EXTD_OPT1_TX_FAULT BIT(3)
259
248#define XGBE_SFP_EXTD_DIAG 28 260#define XGBE_SFP_EXTD_DIAG 28
249#define XGBE_SFP_EXTD_DIAG_ADDR_CHANGE BIT(2) 261#define XGBE_SFP_EXTD_DIAG_ADDR_CHANGE BIT(2)
250 262
@@ -324,6 +336,7 @@ struct xgbe_phy_data {
324 336
325 unsigned int sfp_gpio_address; 337 unsigned int sfp_gpio_address;
326 unsigned int sfp_gpio_mask; 338 unsigned int sfp_gpio_mask;
339 unsigned int sfp_gpio_inputs;
327 unsigned int sfp_gpio_rx_los; 340 unsigned int sfp_gpio_rx_los;
328 unsigned int sfp_gpio_tx_fault; 341 unsigned int sfp_gpio_tx_fault;
329 unsigned int sfp_gpio_mod_absent; 342 unsigned int sfp_gpio_mod_absent;
@@ -355,6 +368,10 @@ struct xgbe_phy_data {
355 unsigned int redrv_addr; 368 unsigned int redrv_addr;
356 unsigned int redrv_lane; 369 unsigned int redrv_lane;
357 unsigned int redrv_model; 370 unsigned int redrv_model;
371
372 /* KR AN support */
373 unsigned int phy_cdr_notrack;
374 unsigned int phy_cdr_delay;
358}; 375};
359 376
360/* I2C, MDIO and GPIO lines are muxed, so only one device at a time */ 377/* I2C, MDIO and GPIO lines are muxed, so only one device at a time */
@@ -974,6 +991,49 @@ static void xgbe_phy_sfp_external_phy(struct xgbe_prv_data *pdata)
974 phy_data->sfp_phy_avail = 1; 991 phy_data->sfp_phy_avail = 1;
975} 992}
976 993
994static bool xgbe_phy_check_sfp_rx_los(struct xgbe_phy_data *phy_data)
995{
996 u8 *sfp_extd = phy_data->sfp_eeprom.extd;
997
998 if (!(sfp_extd[XGBE_SFP_EXTD_OPT1] & XGBE_SFP_EXTD_OPT1_RX_LOS))
999 return false;
1000
1001 if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_RX_LOS)
1002 return false;
1003
1004 if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_rx_los))
1005 return true;
1006
1007 return false;
1008}
1009
1010static bool xgbe_phy_check_sfp_tx_fault(struct xgbe_phy_data *phy_data)
1011{
1012 u8 *sfp_extd = phy_data->sfp_eeprom.extd;
1013
1014 if (!(sfp_extd[XGBE_SFP_EXTD_OPT1] & XGBE_SFP_EXTD_OPT1_TX_FAULT))
1015 return false;
1016
1017 if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_TX_FAULT)
1018 return false;
1019
1020 if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_tx_fault))
1021 return true;
1022
1023 return false;
1024}
1025
1026static bool xgbe_phy_check_sfp_mod_absent(struct xgbe_phy_data *phy_data)
1027{
1028 if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_MOD_ABSENT)
1029 return false;
1030
1031 if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_mod_absent))
1032 return true;
1033
1034 return false;
1035}
1036
977static bool xgbe_phy_belfuse_parse_quirks(struct xgbe_prv_data *pdata) 1037static bool xgbe_phy_belfuse_parse_quirks(struct xgbe_prv_data *pdata)
978{ 1038{
979 struct xgbe_phy_data *phy_data = pdata->phy_data; 1039 struct xgbe_phy_data *phy_data = pdata->phy_data;
@@ -1019,6 +1079,10 @@ static void xgbe_phy_sfp_parse_eeprom(struct xgbe_prv_data *pdata)
1019 if (sfp_base[XGBE_SFP_BASE_EXT_ID] != XGBE_SFP_EXT_ID_SFP) 1079 if (sfp_base[XGBE_SFP_BASE_EXT_ID] != XGBE_SFP_EXT_ID_SFP)
1020 return; 1080 return;
1021 1081
1082 /* Update transceiver signals (eeprom extd/options) */
1083 phy_data->sfp_tx_fault = xgbe_phy_check_sfp_tx_fault(phy_data);
1084 phy_data->sfp_rx_los = xgbe_phy_check_sfp_rx_los(phy_data);
1085
1022 if (xgbe_phy_sfp_parse_quirks(pdata)) 1086 if (xgbe_phy_sfp_parse_quirks(pdata))
1023 return; 1087 return;
1024 1088
@@ -1184,7 +1248,6 @@ put:
1184static void xgbe_phy_sfp_signals(struct xgbe_prv_data *pdata) 1248static void xgbe_phy_sfp_signals(struct xgbe_prv_data *pdata)
1185{ 1249{
1186 struct xgbe_phy_data *phy_data = pdata->phy_data; 1250 struct xgbe_phy_data *phy_data = pdata->phy_data;
1187 unsigned int gpio_input;
1188 u8 gpio_reg, gpio_ports[2]; 1251 u8 gpio_reg, gpio_ports[2];
1189 int ret; 1252 int ret;
1190 1253
@@ -1199,23 +1262,9 @@ static void xgbe_phy_sfp_signals(struct xgbe_prv_data *pdata)
1199 return; 1262 return;
1200 } 1263 }
1201 1264
1202 gpio_input = (gpio_ports[1] << 8) | gpio_ports[0]; 1265 phy_data->sfp_gpio_inputs = (gpio_ports[1] << 8) | gpio_ports[0];
1203
1204 if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_MOD_ABSENT) {
1205 /* No GPIO, just assume the module is present for now */
1206 phy_data->sfp_mod_absent = 0;
1207 } else {
1208 if (!(gpio_input & (1 << phy_data->sfp_gpio_mod_absent)))
1209 phy_data->sfp_mod_absent = 0;
1210 }
1211
1212 if (!(phy_data->sfp_gpio_mask & XGBE_GPIO_NO_RX_LOS) &&
1213 (gpio_input & (1 << phy_data->sfp_gpio_rx_los)))
1214 phy_data->sfp_rx_los = 1;
1215 1266
1216 if (!(phy_data->sfp_gpio_mask & XGBE_GPIO_NO_TX_FAULT) && 1267 phy_data->sfp_mod_absent = xgbe_phy_check_sfp_mod_absent(phy_data);
1217 (gpio_input & (1 << phy_data->sfp_gpio_tx_fault)))
1218 phy_data->sfp_tx_fault = 1;
1219} 1268}
1220 1269
1221static void xgbe_phy_sfp_mod_absent(struct xgbe_prv_data *pdata) 1270static void xgbe_phy_sfp_mod_absent(struct xgbe_prv_data *pdata)
@@ -2361,7 +2410,7 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
2361 return 1; 2410 return 1;
2362 2411
2363 /* No link, attempt a receiver reset cycle */ 2412 /* No link, attempt a receiver reset cycle */
2364 if (phy_data->rrc_count++) { 2413 if (phy_data->rrc_count++ > XGBE_RRC_FREQUENCY) {
2365 phy_data->rrc_count = 0; 2414 phy_data->rrc_count = 0;
2366 xgbe_phy_rrc(pdata); 2415 xgbe_phy_rrc(pdata);
2367 } 2416 }
@@ -2669,6 +2718,103 @@ static bool xgbe_phy_port_enabled(struct xgbe_prv_data *pdata)
2669 return true; 2718 return true;
2670} 2719}
2671 2720
2721static void xgbe_phy_cdr_track(struct xgbe_prv_data *pdata)
2722{
2723 struct xgbe_phy_data *phy_data = pdata->phy_data;
2724
2725 if (!pdata->debugfs_an_cdr_workaround)
2726 return;
2727
2728 if (!phy_data->phy_cdr_notrack)
2729 return;
2730
2731 usleep_range(phy_data->phy_cdr_delay,
2732 phy_data->phy_cdr_delay + 500);
2733
2734 XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
2735 XGBE_PMA_CDR_TRACK_EN_MASK,
2736 XGBE_PMA_CDR_TRACK_EN_ON);
2737
2738 phy_data->phy_cdr_notrack = 0;
2739}
2740
2741static void xgbe_phy_cdr_notrack(struct xgbe_prv_data *pdata)
2742{
2743 struct xgbe_phy_data *phy_data = pdata->phy_data;
2744
2745 if (!pdata->debugfs_an_cdr_workaround)
2746 return;
2747
2748 if (phy_data->phy_cdr_notrack)
2749 return;
2750
2751 XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
2752 XGBE_PMA_CDR_TRACK_EN_MASK,
2753 XGBE_PMA_CDR_TRACK_EN_OFF);
2754
2755 xgbe_phy_rrc(pdata);
2756
2757 phy_data->phy_cdr_notrack = 1;
2758}
2759
2760static void xgbe_phy_kr_training_post(struct xgbe_prv_data *pdata)
2761{
2762 if (!pdata->debugfs_an_cdr_track_early)
2763 xgbe_phy_cdr_track(pdata);
2764}
2765
2766static void xgbe_phy_kr_training_pre(struct xgbe_prv_data *pdata)
2767{
2768 if (pdata->debugfs_an_cdr_track_early)
2769 xgbe_phy_cdr_track(pdata);
2770}
2771
2772static void xgbe_phy_an_post(struct xgbe_prv_data *pdata)
2773{
2774 struct xgbe_phy_data *phy_data = pdata->phy_data;
2775
2776 switch (pdata->an_mode) {
2777 case XGBE_AN_MODE_CL73:
2778 case XGBE_AN_MODE_CL73_REDRV:
2779 if (phy_data->cur_mode != XGBE_MODE_KR)
2780 break;
2781
2782 xgbe_phy_cdr_track(pdata);
2783
2784 switch (pdata->an_result) {
2785 case XGBE_AN_READY:
2786 case XGBE_AN_COMPLETE:
2787 break;
2788 default:
2789 if (phy_data->phy_cdr_delay < XGBE_CDR_DELAY_MAX)
2790 phy_data->phy_cdr_delay += XGBE_CDR_DELAY_INC;
2791 else
2792 phy_data->phy_cdr_delay = XGBE_CDR_DELAY_INIT;
2793 break;
2794 }
2795 break;
2796 default:
2797 break;
2798 }
2799}
2800
2801static void xgbe_phy_an_pre(struct xgbe_prv_data *pdata)
2802{
2803 struct xgbe_phy_data *phy_data = pdata->phy_data;
2804
2805 switch (pdata->an_mode) {
2806 case XGBE_AN_MODE_CL73:
2807 case XGBE_AN_MODE_CL73_REDRV:
2808 if (phy_data->cur_mode != XGBE_MODE_KR)
2809 break;
2810
2811 xgbe_phy_cdr_notrack(pdata);
2812 break;
2813 default:
2814 break;
2815 }
2816}
2817
2672static void xgbe_phy_stop(struct xgbe_prv_data *pdata) 2818static void xgbe_phy_stop(struct xgbe_prv_data *pdata)
2673{ 2819{
2674 struct xgbe_phy_data *phy_data = pdata->phy_data; 2820 struct xgbe_phy_data *phy_data = pdata->phy_data;
@@ -2680,6 +2826,9 @@ static void xgbe_phy_stop(struct xgbe_prv_data *pdata)
2680 xgbe_phy_sfp_reset(phy_data); 2826 xgbe_phy_sfp_reset(phy_data);
2681 xgbe_phy_sfp_mod_absent(pdata); 2827 xgbe_phy_sfp_mod_absent(pdata);
2682 2828
2829 /* Reset CDR support */
2830 xgbe_phy_cdr_track(pdata);
2831
2683 /* Power off the PHY */ 2832 /* Power off the PHY */
2684 xgbe_phy_power_off(pdata); 2833 xgbe_phy_power_off(pdata);
2685 2834
@@ -2712,6 +2861,9 @@ static int xgbe_phy_start(struct xgbe_prv_data *pdata)
2712 /* Start in highest supported mode */ 2861 /* Start in highest supported mode */
2713 xgbe_phy_set_mode(pdata, phy_data->start_mode); 2862 xgbe_phy_set_mode(pdata, phy_data->start_mode);
2714 2863
2864 /* Reset CDR support */
2865 xgbe_phy_cdr_track(pdata);
2866
2715 /* After starting the I2C controller, we can check for an SFP */ 2867 /* After starting the I2C controller, we can check for an SFP */
2716 switch (phy_data->port_mode) { 2868 switch (phy_data->port_mode) {
2717 case XGBE_PORT_MODE_SFP: 2869 case XGBE_PORT_MODE_SFP:
@@ -3019,6 +3171,8 @@ static int xgbe_phy_init(struct xgbe_prv_data *pdata)
3019 } 3171 }
3020 } 3172 }
3021 3173
3174 phy_data->phy_cdr_delay = XGBE_CDR_DELAY_INIT;
3175
3022 /* Register for driving external PHYs */ 3176 /* Register for driving external PHYs */
3023 mii = devm_mdiobus_alloc(pdata->dev); 3177 mii = devm_mdiobus_alloc(pdata->dev);
3024 if (!mii) { 3178 if (!mii) {
@@ -3071,4 +3225,10 @@ void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *phy_if)
3071 phy_impl->an_advertising = xgbe_phy_an_advertising; 3225 phy_impl->an_advertising = xgbe_phy_an_advertising;
3072 3226
3073 phy_impl->an_outcome = xgbe_phy_an_outcome; 3227 phy_impl->an_outcome = xgbe_phy_an_outcome;
3228
3229 phy_impl->an_pre = xgbe_phy_an_pre;
3230 phy_impl->an_post = xgbe_phy_an_post;
3231
3232 phy_impl->kr_training_pre = xgbe_phy_kr_training_pre;
3233 phy_impl->kr_training_post = xgbe_phy_kr_training_post;
3074} 3234}
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
index ad102c8bac7b..95d4b56448c6 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
@@ -833,6 +833,7 @@ struct xgbe_hw_if {
833/* This structure represents implementation specific routines for an 833/* This structure represents implementation specific routines for an
834 * implementation of a PHY. All routines are required unless noted below. 834 * implementation of a PHY. All routines are required unless noted below.
835 * Optional routines: 835 * Optional routines:
836 * an_pre, an_post
836 * kr_training_pre, kr_training_post 837 * kr_training_pre, kr_training_post
837 */ 838 */
838struct xgbe_phy_impl_if { 839struct xgbe_phy_impl_if {
@@ -875,6 +876,10 @@ struct xgbe_phy_impl_if {
875 /* Process results of auto-negotiation */ 876 /* Process results of auto-negotiation */
876 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *); 877 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
877 878
879 /* Pre/Post auto-negotiation support */
880 void (*an_pre)(struct xgbe_prv_data *);
881 void (*an_post)(struct xgbe_prv_data *);
882
878 /* Pre/Post KR training enablement support */ 883 /* Pre/Post KR training enablement support */
879 void (*kr_training_pre)(struct xgbe_prv_data *); 884 void (*kr_training_pre)(struct xgbe_prv_data *);
880 void (*kr_training_post)(struct xgbe_prv_data *); 885 void (*kr_training_post)(struct xgbe_prv_data *);
@@ -989,6 +994,7 @@ struct xgbe_version_data {
989 unsigned int irq_reissue_support; 994 unsigned int irq_reissue_support;
990 unsigned int tx_desc_prefetch; 995 unsigned int tx_desc_prefetch;
991 unsigned int rx_desc_prefetch; 996 unsigned int rx_desc_prefetch;
997 unsigned int an_cdr_workaround;
992}; 998};
993 999
994struct xgbe_vxlan_data { 1000struct xgbe_vxlan_data {
@@ -1257,6 +1263,9 @@ struct xgbe_prv_data {
1257 unsigned int debugfs_xprop_reg; 1263 unsigned int debugfs_xprop_reg;
1258 1264
1259 unsigned int debugfs_xi2c_reg; 1265 unsigned int debugfs_xi2c_reg;
1266
1267 bool debugfs_an_cdr_workaround;
1268 bool debugfs_an_cdr_track_early;
1260}; 1269};
1261 1270
1262/* Function prototypes*/ 1271/* Function prototypes*/
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 2df01ad98df7..6e8d6a6f6aaf 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1128,7 +1128,7 @@ static void clean_rx_pools(struct ibmvnic_adapter *adapter)
1128 if (!adapter->rx_pool) 1128 if (!adapter->rx_pool)
1129 return; 1129 return;
1130 1130
1131 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); 1131 rx_scrqs = adapter->num_active_rx_pools;
1132 rx_entries = adapter->req_rx_add_entries_per_subcrq; 1132 rx_entries = adapter->req_rx_add_entries_per_subcrq;
1133 1133
1134 /* Free any remaining skbs in the rx buffer pools */ 1134 /* Free any remaining skbs in the rx buffer pools */
@@ -1177,7 +1177,7 @@ static void clean_tx_pools(struct ibmvnic_adapter *adapter)
1177 if (!adapter->tx_pool || !adapter->tso_pool) 1177 if (!adapter->tx_pool || !adapter->tso_pool)
1178 return; 1178 return;
1179 1179
1180 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); 1180 tx_scrqs = adapter->num_active_tx_pools;
1181 1181
1182 /* Free any remaining skbs in the tx buffer pools */ 1182 /* Free any remaining skbs in the tx buffer pools */
1183 for (i = 0; i < tx_scrqs; i++) { 1183 for (i = 0; i < tx_scrqs; i++) {
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 5b13ca1bd85f..7dc5f045e969 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -586,7 +586,7 @@ struct ice_sw_rule_lg_act {
586#define ICE_LG_ACT_MIRROR_VSI_ID_S 3 586#define ICE_LG_ACT_MIRROR_VSI_ID_S 3
587#define ICE_LG_ACT_MIRROR_VSI_ID_M (0x3FF << ICE_LG_ACT_MIRROR_VSI_ID_S) 587#define ICE_LG_ACT_MIRROR_VSI_ID_M (0x3FF << ICE_LG_ACT_MIRROR_VSI_ID_S)
588 588
589 /* Action type = 5 - Large Action */ 589 /* Action type = 5 - Generic Value */
590#define ICE_LG_ACT_GENERIC 0x5 590#define ICE_LG_ACT_GENERIC 0x5
591#define ICE_LG_ACT_GENERIC_VALUE_S 3 591#define ICE_LG_ACT_GENERIC_VALUE_S 3
592#define ICE_LG_ACT_GENERIC_VALUE_M (0xFFFF << ICE_LG_ACT_GENERIC_VALUE_S) 592#define ICE_LG_ACT_GENERIC_VALUE_M (0xFFFF << ICE_LG_ACT_GENERIC_VALUE_S)
diff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c
index 21977ec984c4..71d032cc5fa7 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.c
+++ b/drivers/net/ethernet/intel/ice/ice_common.c
@@ -78,6 +78,7 @@ ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
78 struct ice_aq_desc desc; 78 struct ice_aq_desc desc;
79 enum ice_status status; 79 enum ice_status status;
80 u16 flags; 80 u16 flags;
81 u8 i;
81 82
82 cmd = &desc.params.mac_read; 83 cmd = &desc.params.mac_read;
83 84
@@ -98,8 +99,16 @@ ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
98 return ICE_ERR_CFG; 99 return ICE_ERR_CFG;
99 } 100 }
100 101
101 ether_addr_copy(hw->port_info->mac.lan_addr, resp->mac_addr); 102 /* A single port can report up to two (LAN and WoL) addresses */
102 ether_addr_copy(hw->port_info->mac.perm_addr, resp->mac_addr); 103 for (i = 0; i < cmd->num_addr; i++)
104 if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
105 ether_addr_copy(hw->port_info->mac.lan_addr,
106 resp[i].mac_addr);
107 ether_addr_copy(hw->port_info->mac.perm_addr,
108 resp[i].mac_addr);
109 break;
110 }
111
103 return 0; 112 return 0;
104} 113}
105 114
@@ -464,9 +473,12 @@ enum ice_status ice_init_hw(struct ice_hw *hw)
464 if (status) 473 if (status)
465 goto err_unroll_sched; 474 goto err_unroll_sched;
466 475
467 /* Get port MAC information */ 476 /* Get MAC information */
468 mac_buf_len = sizeof(struct ice_aqc_manage_mac_read_resp); 477 /* A single port can report up to two (LAN and WoL) addresses */
469 mac_buf = devm_kzalloc(ice_hw_to_dev(hw), mac_buf_len, GFP_KERNEL); 478 mac_buf = devm_kcalloc(ice_hw_to_dev(hw), 2,
479 sizeof(struct ice_aqc_manage_mac_read_resp),
480 GFP_KERNEL);
481 mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
470 482
471 if (!mac_buf) { 483 if (!mac_buf) {
472 status = ICE_ERR_NO_MEMORY; 484 status = ICE_ERR_NO_MEMORY;
diff --git a/drivers/net/ethernet/intel/ice/ice_hw_autogen.h b/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
index 1b9e2ef48a9d..499904874b3f 100644
--- a/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
+++ b/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
@@ -121,8 +121,6 @@
121#define PFINT_FW_CTL_CAUSE_ENA_S 30 121#define PFINT_FW_CTL_CAUSE_ENA_S 30
122#define PFINT_FW_CTL_CAUSE_ENA_M BIT(PFINT_FW_CTL_CAUSE_ENA_S) 122#define PFINT_FW_CTL_CAUSE_ENA_M BIT(PFINT_FW_CTL_CAUSE_ENA_S)
123#define PFINT_OICR 0x0016CA00 123#define PFINT_OICR 0x0016CA00
124#define PFINT_OICR_INTEVENT_S 0
125#define PFINT_OICR_INTEVENT_M BIT(PFINT_OICR_INTEVENT_S)
126#define PFINT_OICR_HLP_RDY_S 14 124#define PFINT_OICR_HLP_RDY_S 14
127#define PFINT_OICR_HLP_RDY_M BIT(PFINT_OICR_HLP_RDY_S) 125#define PFINT_OICR_HLP_RDY_M BIT(PFINT_OICR_HLP_RDY_S)
128#define PFINT_OICR_CPM_RDY_S 15 126#define PFINT_OICR_CPM_RDY_S 15
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 210b7910f1cd..5299caf55a7f 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -1722,9 +1722,6 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1722 oicr = rd32(hw, PFINT_OICR); 1722 oicr = rd32(hw, PFINT_OICR);
1723 ena_mask = rd32(hw, PFINT_OICR_ENA); 1723 ena_mask = rd32(hw, PFINT_OICR_ENA);
1724 1724
1725 if (!(oicr & PFINT_OICR_INTEVENT_M))
1726 goto ena_intr;
1727
1728 if (oicr & PFINT_OICR_GRST_M) { 1725 if (oicr & PFINT_OICR_GRST_M) {
1729 u32 reset; 1726 u32 reset;
1730 /* we have a reset warning */ 1727 /* we have a reset warning */
@@ -1782,7 +1779,6 @@ static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1782 } 1779 }
1783 ret = IRQ_HANDLED; 1780 ret = IRQ_HANDLED;
1784 1781
1785ena_intr:
1786 /* re-enable interrupt causes that are not handled during this pass */ 1782 /* re-enable interrupt causes that are not handled during this pass */
1787 wr32(hw, PFINT_OICR_ENA, ena_mask); 1783 wr32(hw, PFINT_OICR_ENA, ena_mask);
1788 if (!test_bit(__ICE_DOWN, pf->state)) { 1784 if (!test_bit(__ICE_DOWN, pf->state)) {
diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c
index f16ff3e4a840..2e6c1d92cc88 100644
--- a/drivers/net/ethernet/intel/ice/ice_sched.c
+++ b/drivers/net/ethernet/intel/ice/ice_sched.c
@@ -751,14 +751,14 @@ ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
751 u16 num_added = 0; 751 u16 num_added = 0;
752 u32 temp; 752 u32 temp;
753 753
754 *num_nodes_added = 0;
755
754 if (!num_nodes) 756 if (!num_nodes)
755 return status; 757 return status;
756 758
757 if (!parent || layer < hw->sw_entry_point_layer) 759 if (!parent || layer < hw->sw_entry_point_layer)
758 return ICE_ERR_PARAM; 760 return ICE_ERR_PARAM;
759 761
760 *num_nodes_added = 0;
761
762 /* max children per node per layer */ 762 /* max children per node per layer */
763 max_child_nodes = 763 max_child_nodes =
764 le16_to_cpu(hw->layer_info[parent->tx_sched_layer].max_children); 764 le16_to_cpu(hw->layer_info[parent->tx_sched_layer].max_children);
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index c1c0bc30a16d..cce7ada89255 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -1700,7 +1700,22 @@ static void igb_configure_cbs(struct igb_adapter *adapter, int queue,
1700 WARN_ON(hw->mac.type != e1000_i210); 1700 WARN_ON(hw->mac.type != e1000_i210);
1701 WARN_ON(queue < 0 || queue > 1); 1701 WARN_ON(queue < 0 || queue > 1);
1702 1702
1703 if (enable) { 1703 if (enable || queue == 0) {
1704 /* i210 does not allow the queue 0 to be in the Strict
1705 * Priority mode while the Qav mode is enabled, so,
1706 * instead of disabling strict priority mode, we give
1707 * queue 0 the maximum of credits possible.
1708 *
1709 * See section 8.12.19 of the i210 datasheet, "Note:
1710 * Queue0 QueueMode must be set to 1b when
1711 * TransmitMode is set to Qav."
1712 */
1713 if (queue == 0 && !enable) {
1714 /* max "linkspeed" idleslope in kbps */
1715 idleslope = 1000000;
1716 hicredit = ETH_FRAME_LEN;
1717 }
1718
1704 set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_HIGH); 1719 set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_HIGH);
1705 set_queue_mode(hw, queue, QUEUE_MODE_STREAM_RESERVATION); 1720 set_queue_mode(hw, queue, QUEUE_MODE_STREAM_RESERVATION);
1706 1721
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 3d9033f26eff..e3d04f226d57 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -3420,7 +3420,7 @@ static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter)
3420 if (!err) 3420 if (!err)
3421 continue; 3421 continue;
3422 hw_dbg(&adapter->hw, "Allocation for XDP Queue %u failed\n", j); 3422 hw_dbg(&adapter->hw, "Allocation for XDP Queue %u failed\n", j);
3423 break; 3423 goto err_setup_tx;
3424 } 3424 }
3425 3425
3426 return 0; 3426 return 0;
diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c
index 83ce229f4eb7..63036d9bf3e6 100644
--- a/drivers/net/ethernet/sfc/ef10.c
+++ b/drivers/net/ethernet/sfc/ef10.c
@@ -3999,29 +3999,6 @@ static void efx_ef10_prepare_flr(struct efx_nic *efx)
3999 atomic_set(&efx->active_queues, 0); 3999 atomic_set(&efx->active_queues, 0);
4000} 4000}
4001 4001
4002static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
4003 const struct efx_filter_spec *right)
4004{
4005 if ((left->match_flags ^ right->match_flags) |
4006 ((left->flags ^ right->flags) &
4007 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
4008 return false;
4009
4010 return memcmp(&left->outer_vid, &right->outer_vid,
4011 sizeof(struct efx_filter_spec) -
4012 offsetof(struct efx_filter_spec, outer_vid)) == 0;
4013}
4014
4015static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
4016{
4017 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
4018 return jhash2((const u32 *)&spec->outer_vid,
4019 (sizeof(struct efx_filter_spec) -
4020 offsetof(struct efx_filter_spec, outer_vid)) / 4,
4021 0);
4022 /* XXX should we randomise the initval? */
4023}
4024
4025/* Decide whether a filter should be exclusive or else should allow 4002/* Decide whether a filter should be exclusive or else should allow
4026 * delivery to additional recipients. Currently we decide that 4003 * delivery to additional recipients. Currently we decide that
4027 * filters for specific local unicast MAC and IP addresses are 4004 * filters for specific local unicast MAC and IP addresses are
@@ -4346,7 +4323,7 @@ static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4346 goto out_unlock; 4323 goto out_unlock;
4347 match_pri = rc; 4324 match_pri = rc;
4348 4325
4349 hash = efx_ef10_filter_hash(spec); 4326 hash = efx_filter_spec_hash(spec);
4350 is_mc_recip = efx_filter_is_mc_recipient(spec); 4327 is_mc_recip = efx_filter_is_mc_recipient(spec);
4351 if (is_mc_recip) 4328 if (is_mc_recip)
4352 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); 4329 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
@@ -4378,7 +4355,7 @@ static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4378 if (!saved_spec) { 4355 if (!saved_spec) {
4379 if (ins_index < 0) 4356 if (ins_index < 0)
4380 ins_index = i; 4357 ins_index = i;
4381 } else if (efx_ef10_filter_equal(spec, saved_spec)) { 4358 } else if (efx_filter_spec_equal(spec, saved_spec)) {
4382 if (spec->priority < saved_spec->priority && 4359 if (spec->priority < saved_spec->priority &&
4383 spec->priority != EFX_FILTER_PRI_AUTO) { 4360 spec->priority != EFX_FILTER_PRI_AUTO) {
4384 rc = -EPERM; 4361 rc = -EPERM;
@@ -4762,27 +4739,62 @@ static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4762static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, 4739static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4763 unsigned int filter_idx) 4740 unsigned int filter_idx)
4764{ 4741{
4742 struct efx_filter_spec *spec, saved_spec;
4765 struct efx_ef10_filter_table *table; 4743 struct efx_ef10_filter_table *table;
4766 struct efx_filter_spec *spec; 4744 struct efx_arfs_rule *rule = NULL;
4767 bool ret; 4745 bool ret = true, force = false;
4746 u16 arfs_id;
4768 4747
4769 down_read(&efx->filter_sem); 4748 down_read(&efx->filter_sem);
4770 table = efx->filter_state; 4749 table = efx->filter_state;
4771 down_write(&table->lock); 4750 down_write(&table->lock);
4772 spec = efx_ef10_filter_entry_spec(table, filter_idx); 4751 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4773 4752
4774 if (!spec || spec->priority != EFX_FILTER_PRI_HINT) { 4753 if (!spec || spec->priority != EFX_FILTER_PRI_HINT)
4775 ret = true;
4776 goto out_unlock; 4754 goto out_unlock;
4777 }
4778 4755
4779 if (!rps_may_expire_flow(efx->net_dev, spec->dmaq_id, flow_id, 0)) { 4756 spin_lock_bh(&efx->rps_hash_lock);
4780 ret = false; 4757 if (!efx->rps_hash_table) {
4781 goto out_unlock; 4758 /* In the absence of the table, we always return 0 to ARFS. */
4759 arfs_id = 0;
4760 } else {
4761 rule = efx_rps_hash_find(efx, spec);
4762 if (!rule)
4763 /* ARFS table doesn't know of this filter, so remove it */
4764 goto expire;
4765 arfs_id = rule->arfs_id;
4766 ret = efx_rps_check_rule(rule, filter_idx, &force);
4767 if (force)
4768 goto expire;
4769 if (!ret) {
4770 spin_unlock_bh(&efx->rps_hash_lock);
4771 goto out_unlock;
4772 }
4782 } 4773 }
4783 4774 if (!rps_may_expire_flow(efx->net_dev, spec->dmaq_id, flow_id, arfs_id))
4775 ret = false;
4776 else if (rule)
4777 rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
4778expire:
4779 saved_spec = *spec; /* remove operation will kfree spec */
4780 spin_unlock_bh(&efx->rps_hash_lock);
4781 /* At this point (since we dropped the lock), another thread might queue
4782 * up a fresh insertion request (but the actual insertion will be held
4783 * up by our possession of the filter table lock). In that case, it
4784 * will set rule->filter_id to EFX_ARFS_FILTER_ID_PENDING, meaning that
4785 * the rule is not removed by efx_rps_hash_del() below.
4786 */
4784 ret = efx_ef10_filter_remove_internal(efx, 1U << spec->priority, 4787 ret = efx_ef10_filter_remove_internal(efx, 1U << spec->priority,
4785 filter_idx, true) == 0; 4788 filter_idx, true) == 0;
4789 /* While we can't safely dereference rule (we dropped the lock), we can
4790 * still test it for NULL.
4791 */
4792 if (ret && rule) {
4793 /* Expiring, so remove entry from ARFS table */
4794 spin_lock_bh(&efx->rps_hash_lock);
4795 efx_rps_hash_del(efx, &saved_spec);
4796 spin_unlock_bh(&efx->rps_hash_lock);
4797 }
4786out_unlock: 4798out_unlock:
4787 up_write(&table->lock); 4799 up_write(&table->lock);
4788 up_read(&efx->filter_sem); 4800 up_read(&efx->filter_sem);
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 692dd729ee2a..a4ebd8715494 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -3027,6 +3027,10 @@ static int efx_init_struct(struct efx_nic *efx,
3027 mutex_init(&efx->mac_lock); 3027 mutex_init(&efx->mac_lock);
3028#ifdef CONFIG_RFS_ACCEL 3028#ifdef CONFIG_RFS_ACCEL
3029 mutex_init(&efx->rps_mutex); 3029 mutex_init(&efx->rps_mutex);
3030 spin_lock_init(&efx->rps_hash_lock);
3031 /* Failure to allocate is not fatal, but may degrade ARFS performance */
3032 efx->rps_hash_table = kcalloc(EFX_ARFS_HASH_TABLE_SIZE,
3033 sizeof(*efx->rps_hash_table), GFP_KERNEL);
3030#endif 3034#endif
3031 efx->phy_op = &efx_dummy_phy_operations; 3035 efx->phy_op = &efx_dummy_phy_operations;
3032 efx->mdio.dev = net_dev; 3036 efx->mdio.dev = net_dev;
@@ -3070,6 +3074,10 @@ static void efx_fini_struct(struct efx_nic *efx)
3070{ 3074{
3071 int i; 3075 int i;
3072 3076
3077#ifdef CONFIG_RFS_ACCEL
3078 kfree(efx->rps_hash_table);
3079#endif
3080
3073 for (i = 0; i < EFX_MAX_CHANNELS; i++) 3081 for (i = 0; i < EFX_MAX_CHANNELS; i++)
3074 kfree(efx->channel[i]); 3082 kfree(efx->channel[i]);
3075 3083
@@ -3092,6 +3100,141 @@ void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
3092 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); 3100 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
3093} 3101}
3094 3102
3103bool efx_filter_spec_equal(const struct efx_filter_spec *left,
3104 const struct efx_filter_spec *right)
3105{
3106 if ((left->match_flags ^ right->match_flags) |
3107 ((left->flags ^ right->flags) &
3108 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3109 return false;
3110
3111 return memcmp(&left->outer_vid, &right->outer_vid,
3112 sizeof(struct efx_filter_spec) -
3113 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3114}
3115
3116u32 efx_filter_spec_hash(const struct efx_filter_spec *spec)
3117{
3118 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3119 return jhash2((const u32 *)&spec->outer_vid,
3120 (sizeof(struct efx_filter_spec) -
3121 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3122 0);
3123}
3124
3125#ifdef CONFIG_RFS_ACCEL
3126bool efx_rps_check_rule(struct efx_arfs_rule *rule, unsigned int filter_idx,
3127 bool *force)
3128{
3129 if (rule->filter_id == EFX_ARFS_FILTER_ID_PENDING) {
3130 /* ARFS is currently updating this entry, leave it */
3131 return false;
3132 }
3133 if (rule->filter_id == EFX_ARFS_FILTER_ID_ERROR) {
3134 /* ARFS tried and failed to update this, so it's probably out
3135 * of date. Remove the filter and the ARFS rule entry.
3136 */
3137 rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
3138 *force = true;
3139 return true;
3140 } else if (WARN_ON(rule->filter_id != filter_idx)) { /* can't happen */
3141 /* ARFS has moved on, so old filter is not needed. Since we did
3142 * not mark the rule with EFX_ARFS_FILTER_ID_REMOVING, it will
3143 * not be removed by efx_rps_hash_del() subsequently.
3144 */
3145 *force = true;
3146 return true;
3147 }
3148 /* Remove it iff ARFS wants to. */
3149 return true;
3150}
3151
3152struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
3153 const struct efx_filter_spec *spec)
3154{
3155 u32 hash = efx_filter_spec_hash(spec);
3156
3157 WARN_ON(!spin_is_locked(&efx->rps_hash_lock));
3158 if (!efx->rps_hash_table)
3159 return NULL;
3160 return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];
3161}
3162
3163struct efx_arfs_rule *efx_rps_hash_find(struct efx_nic *efx,
3164 const struct efx_filter_spec *spec)
3165{
3166 struct efx_arfs_rule *rule;
3167 struct hlist_head *head;
3168 struct hlist_node *node;
3169
3170 head = efx_rps_hash_bucket(efx, spec);
3171 if (!head)
3172 return NULL;
3173 hlist_for_each(node, head) {
3174 rule = container_of(node, struct efx_arfs_rule, node);
3175 if (efx_filter_spec_equal(spec, &rule->spec))
3176 return rule;
3177 }
3178 return NULL;
3179}
3180
3181struct efx_arfs_rule *efx_rps_hash_add(struct efx_nic *efx,
3182 const struct efx_filter_spec *spec,
3183 bool *new)
3184{
3185 struct efx_arfs_rule *rule;
3186 struct hlist_head *head;
3187 struct hlist_node *node;
3188
3189 head = efx_rps_hash_bucket(efx, spec);
3190 if (!head)
3191 return NULL;
3192 hlist_for_each(node, head) {
3193 rule = container_of(node, struct efx_arfs_rule, node);
3194 if (efx_filter_spec_equal(spec, &rule->spec)) {
3195 *new = false;
3196 return rule;
3197 }
3198 }
3199 rule = kmalloc(sizeof(*rule), GFP_ATOMIC);
3200 *new = true;
3201 if (rule) {
3202 memcpy(&rule->spec, spec, sizeof(rule->spec));
3203 hlist_add_head(&rule->node, head);
3204 }
3205 return rule;
3206}
3207
3208void efx_rps_hash_del(struct efx_nic *efx, const struct efx_filter_spec *spec)
3209{
3210 struct efx_arfs_rule *rule;
3211 struct hlist_head *head;
3212 struct hlist_node *node;
3213
3214 head = efx_rps_hash_bucket(efx, spec);
3215 if (WARN_ON(!head))
3216 return;
3217 hlist_for_each(node, head) {
3218 rule = container_of(node, struct efx_arfs_rule, node);
3219 if (efx_filter_spec_equal(spec, &rule->spec)) {
3220 /* Someone already reused the entry. We know that if
3221 * this check doesn't fire (i.e. filter_id == REMOVING)
3222 * then the REMOVING mark was put there by our caller,
3223 * because caller is holding a lock on filter table and
3224 * only holders of that lock set REMOVING.
3225 */
3226 if (rule->filter_id != EFX_ARFS_FILTER_ID_REMOVING)
3227 return;
3228 hlist_del(node);
3229 kfree(rule);
3230 return;
3231 }
3232 }
3233 /* We didn't find it. */
3234 WARN_ON(1);
3235}
3236#endif
3237
3095/* RSS contexts. We're using linked lists and crappy O(n) algorithms, because 3238/* RSS contexts. We're using linked lists and crappy O(n) algorithms, because
3096 * (a) this is an infrequent control-plane operation and (b) n is small (max 64) 3239 * (a) this is an infrequent control-plane operation and (b) n is small (max 64)
3097 */ 3240 */
diff --git a/drivers/net/ethernet/sfc/efx.h b/drivers/net/ethernet/sfc/efx.h
index a3140e16fcef..3f759ebdcf10 100644
--- a/drivers/net/ethernet/sfc/efx.h
+++ b/drivers/net/ethernet/sfc/efx.h
@@ -186,6 +186,27 @@ static inline void efx_filter_rfs_expire(struct work_struct *data) {}
186#endif 186#endif
187bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec); 187bool efx_filter_is_mc_recipient(const struct efx_filter_spec *spec);
188 188
189bool efx_filter_spec_equal(const struct efx_filter_spec *left,
190 const struct efx_filter_spec *right);
191u32 efx_filter_spec_hash(const struct efx_filter_spec *spec);
192
193#ifdef CONFIG_RFS_ACCEL
194bool efx_rps_check_rule(struct efx_arfs_rule *rule, unsigned int filter_idx,
195 bool *force);
196
197struct efx_arfs_rule *efx_rps_hash_find(struct efx_nic *efx,
198 const struct efx_filter_spec *spec);
199
200/* @new is written to indicate if entry was newly added (true) or if an old
201 * entry was found and returned (false).
202 */
203struct efx_arfs_rule *efx_rps_hash_add(struct efx_nic *efx,
204 const struct efx_filter_spec *spec,
205 bool *new);
206
207void efx_rps_hash_del(struct efx_nic *efx, const struct efx_filter_spec *spec);
208#endif
209
189/* RSS contexts */ 210/* RSS contexts */
190struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx); 211struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx);
191struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id); 212struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id);
diff --git a/drivers/net/ethernet/sfc/farch.c b/drivers/net/ethernet/sfc/farch.c
index 7174ef5e5c5e..c72adf8b52ea 100644
--- a/drivers/net/ethernet/sfc/farch.c
+++ b/drivers/net/ethernet/sfc/farch.c
@@ -2905,18 +2905,45 @@ bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
2905{ 2905{
2906 struct efx_farch_filter_state *state = efx->filter_state; 2906 struct efx_farch_filter_state *state = efx->filter_state;
2907 struct efx_farch_filter_table *table; 2907 struct efx_farch_filter_table *table;
2908 bool ret = false; 2908 bool ret = false, force = false;
2909 u16 arfs_id;
2909 2910
2910 down_write(&state->lock); 2911 down_write(&state->lock);
2912 spin_lock_bh(&efx->rps_hash_lock);
2911 table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP]; 2913 table = &state->table[EFX_FARCH_FILTER_TABLE_RX_IP];
2912 if (test_bit(index, table->used_bitmap) && 2914 if (test_bit(index, table->used_bitmap) &&
2913 table->spec[index].priority == EFX_FILTER_PRI_HINT && 2915 table->spec[index].priority == EFX_FILTER_PRI_HINT) {
2914 rps_may_expire_flow(efx->net_dev, table->spec[index].dmaq_id, 2916 struct efx_arfs_rule *rule = NULL;
2915 flow_id, 0)) { 2917 struct efx_filter_spec spec;
2916 efx_farch_filter_table_clear_entry(efx, table, index); 2918
2917 ret = true; 2919 efx_farch_filter_to_gen_spec(&spec, &table->spec[index]);
2920 if (!efx->rps_hash_table) {
2921 /* In the absence of the table, we always returned 0 to
2922 * ARFS, so use the same to query it.
2923 */
2924 arfs_id = 0;
2925 } else {
2926 rule = efx_rps_hash_find(efx, &spec);
2927 if (!rule) {
2928 /* ARFS table doesn't know of this filter, remove it */
2929 force = true;
2930 } else {
2931 arfs_id = rule->arfs_id;
2932 if (!efx_rps_check_rule(rule, index, &force))
2933 goto out_unlock;
2934 }
2935 }
2936 if (force || rps_may_expire_flow(efx->net_dev, spec.dmaq_id,
2937 flow_id, arfs_id)) {
2938 if (rule)
2939 rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
2940 efx_rps_hash_del(efx, &spec);
2941 efx_farch_filter_table_clear_entry(efx, table, index);
2942 ret = true;
2943 }
2918 } 2944 }
2919 2945out_unlock:
2946 spin_unlock_bh(&efx->rps_hash_lock);
2920 up_write(&state->lock); 2947 up_write(&state->lock);
2921 return ret; 2948 return ret;
2922} 2949}
diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h
index eea3808b3f25..65568925c3ef 100644
--- a/drivers/net/ethernet/sfc/net_driver.h
+++ b/drivers/net/ethernet/sfc/net_driver.h
@@ -734,6 +734,35 @@ struct efx_rss_context {
734}; 734};
735 735
736#ifdef CONFIG_RFS_ACCEL 736#ifdef CONFIG_RFS_ACCEL
737/* Order of these is important, since filter_id >= %EFX_ARFS_FILTER_ID_PENDING
738 * is used to test if filter does or will exist.
739 */
740#define EFX_ARFS_FILTER_ID_PENDING -1
741#define EFX_ARFS_FILTER_ID_ERROR -2
742#define EFX_ARFS_FILTER_ID_REMOVING -3
743/**
744 * struct efx_arfs_rule - record of an ARFS filter and its IDs
745 * @node: linkage into hash table
746 * @spec: details of the filter (used as key for hash table). Use efx->type to
747 * determine which member to use.
748 * @rxq_index: channel to which the filter will steer traffic.
749 * @arfs_id: filter ID which was returned to ARFS
750 * @filter_id: index in software filter table. May be
751 * %EFX_ARFS_FILTER_ID_PENDING if filter was not inserted yet,
752 * %EFX_ARFS_FILTER_ID_ERROR if filter insertion failed, or
753 * %EFX_ARFS_FILTER_ID_REMOVING if expiry is currently removing the filter.
754 */
755struct efx_arfs_rule {
756 struct hlist_node node;
757 struct efx_filter_spec spec;
758 u16 rxq_index;
759 u16 arfs_id;
760 s32 filter_id;
761};
762
763/* Size chosen so that the table is one page (4kB) */
764#define EFX_ARFS_HASH_TABLE_SIZE 512
765
737/** 766/**
738 * struct efx_async_filter_insertion - Request to asynchronously insert a filter 767 * struct efx_async_filter_insertion - Request to asynchronously insert a filter
739 * @net_dev: Reference to the netdevice 768 * @net_dev: Reference to the netdevice
@@ -873,6 +902,10 @@ struct efx_async_filter_insertion {
873 * @rps_expire_channel's @rps_flow_id 902 * @rps_expire_channel's @rps_flow_id
874 * @rps_slot_map: bitmap of in-flight entries in @rps_slot 903 * @rps_slot_map: bitmap of in-flight entries in @rps_slot
875 * @rps_slot: array of ARFS insertion requests for efx_filter_rfs_work() 904 * @rps_slot: array of ARFS insertion requests for efx_filter_rfs_work()
905 * @rps_hash_lock: Protects ARFS filter mapping state (@rps_hash_table and
906 * @rps_next_id).
907 * @rps_hash_table: Mapping between ARFS filters and their various IDs
908 * @rps_next_id: next arfs_id for an ARFS filter
876 * @active_queues: Count of RX and TX queues that haven't been flushed and drained. 909 * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
877 * @rxq_flush_pending: Count of number of receive queues that need to be flushed. 910 * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
878 * Decremented when the efx_flush_rx_queue() is called. 911 * Decremented when the efx_flush_rx_queue() is called.
@@ -1029,6 +1062,9 @@ struct efx_nic {
1029 unsigned int rps_expire_index; 1062 unsigned int rps_expire_index;
1030 unsigned long rps_slot_map; 1063 unsigned long rps_slot_map;
1031 struct efx_async_filter_insertion rps_slot[EFX_RPS_MAX_IN_FLIGHT]; 1064 struct efx_async_filter_insertion rps_slot[EFX_RPS_MAX_IN_FLIGHT];
1065 spinlock_t rps_hash_lock;
1066 struct hlist_head *rps_hash_table;
1067 u32 rps_next_id;
1032#endif 1068#endif
1033 1069
1034 atomic_t active_queues; 1070 atomic_t active_queues;
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index 9c593c661cbf..64a94f242027 100644
--- a/drivers/net/ethernet/sfc/rx.c
+++ b/drivers/net/ethernet/sfc/rx.c
@@ -834,9 +834,29 @@ static void efx_filter_rfs_work(struct work_struct *data)
834 struct efx_nic *efx = netdev_priv(req->net_dev); 834 struct efx_nic *efx = netdev_priv(req->net_dev);
835 struct efx_channel *channel = efx_get_channel(efx, req->rxq_index); 835 struct efx_channel *channel = efx_get_channel(efx, req->rxq_index);
836 int slot_idx = req - efx->rps_slot; 836 int slot_idx = req - efx->rps_slot;
837 struct efx_arfs_rule *rule;
838 u16 arfs_id = 0;
837 int rc; 839 int rc;
838 840
839 rc = efx->type->filter_insert(efx, &req->spec, true); 841 rc = efx->type->filter_insert(efx, &req->spec, true);
842 if (efx->rps_hash_table) {
843 spin_lock_bh(&efx->rps_hash_lock);
844 rule = efx_rps_hash_find(efx, &req->spec);
845 /* The rule might have already gone, if someone else's request
846 * for the same spec was already worked and then expired before
847 * we got around to our work. In that case we have nothing
848 * tying us to an arfs_id, meaning that as soon as the filter
849 * is considered for expiry it will be removed.
850 */
851 if (rule) {
852 if (rc < 0)
853 rule->filter_id = EFX_ARFS_FILTER_ID_ERROR;
854 else
855 rule->filter_id = rc;
856 arfs_id = rule->arfs_id;
857 }
858 spin_unlock_bh(&efx->rps_hash_lock);
859 }
840 if (rc >= 0) { 860 if (rc >= 0) {
841 /* Remember this so we can check whether to expire the filter 861 /* Remember this so we can check whether to expire the filter
842 * later. 862 * later.
@@ -848,18 +868,18 @@ static void efx_filter_rfs_work(struct work_struct *data)
848 868
849 if (req->spec.ether_type == htons(ETH_P_IP)) 869 if (req->spec.ether_type == htons(ETH_P_IP))
850 netif_info(efx, rx_status, efx->net_dev, 870 netif_info(efx, rx_status, efx->net_dev,
851 "steering %s %pI4:%u:%pI4:%u to queue %u [flow %u filter %d]\n", 871 "steering %s %pI4:%u:%pI4:%u to queue %u [flow %u filter %d id %u]\n",
852 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP", 872 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
853 req->spec.rem_host, ntohs(req->spec.rem_port), 873 req->spec.rem_host, ntohs(req->spec.rem_port),
854 req->spec.loc_host, ntohs(req->spec.loc_port), 874 req->spec.loc_host, ntohs(req->spec.loc_port),
855 req->rxq_index, req->flow_id, rc); 875 req->rxq_index, req->flow_id, rc, arfs_id);
856 else 876 else
857 netif_info(efx, rx_status, efx->net_dev, 877 netif_info(efx, rx_status, efx->net_dev,
858 "steering %s [%pI6]:%u:[%pI6]:%u to queue %u [flow %u filter %d]\n", 878 "steering %s [%pI6]:%u:[%pI6]:%u to queue %u [flow %u filter %d id %u]\n",
859 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP", 879 (req->spec.ip_proto == IPPROTO_TCP) ? "TCP" : "UDP",
860 req->spec.rem_host, ntohs(req->spec.rem_port), 880 req->spec.rem_host, ntohs(req->spec.rem_port),
861 req->spec.loc_host, ntohs(req->spec.loc_port), 881 req->spec.loc_host, ntohs(req->spec.loc_port),
862 req->rxq_index, req->flow_id, rc); 882 req->rxq_index, req->flow_id, rc, arfs_id);
863 } 883 }
864 884
865 /* Release references */ 885 /* Release references */
@@ -872,8 +892,10 @@ int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
872{ 892{
873 struct efx_nic *efx = netdev_priv(net_dev); 893 struct efx_nic *efx = netdev_priv(net_dev);
874 struct efx_async_filter_insertion *req; 894 struct efx_async_filter_insertion *req;
895 struct efx_arfs_rule *rule;
875 struct flow_keys fk; 896 struct flow_keys fk;
876 int slot_idx; 897 int slot_idx;
898 bool new;
877 int rc; 899 int rc;
878 900
879 /* find a free slot */ 901 /* find a free slot */
@@ -926,12 +948,42 @@ int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
926 req->spec.rem_port = fk.ports.src; 948 req->spec.rem_port = fk.ports.src;
927 req->spec.loc_port = fk.ports.dst; 949 req->spec.loc_port = fk.ports.dst;
928 950
951 if (efx->rps_hash_table) {
952 /* Add it to ARFS hash table */
953 spin_lock(&efx->rps_hash_lock);
954 rule = efx_rps_hash_add(efx, &req->spec, &new);
955 if (!rule) {
956 rc = -ENOMEM;
957 goto out_unlock;
958 }
959 if (new)
960 rule->arfs_id = efx->rps_next_id++ % RPS_NO_FILTER;
961 rc = rule->arfs_id;
962 /* Skip if existing or pending filter already does the right thing */
963 if (!new && rule->rxq_index == rxq_index &&
964 rule->filter_id >= EFX_ARFS_FILTER_ID_PENDING)
965 goto out_unlock;
966 rule->rxq_index = rxq_index;
967 rule->filter_id = EFX_ARFS_FILTER_ID_PENDING;
968 spin_unlock(&efx->rps_hash_lock);
969 } else {
970 /* Without an ARFS hash table, we just use arfs_id 0 for all
971 * filters. This means if multiple flows hash to the same
972 * flow_id, all but the most recently touched will be eligible
973 * for expiry.
974 */
975 rc = 0;
976 }
977
978 /* Queue the request */
929 dev_hold(req->net_dev = net_dev); 979 dev_hold(req->net_dev = net_dev);
930 INIT_WORK(&req->work, efx_filter_rfs_work); 980 INIT_WORK(&req->work, efx_filter_rfs_work);
931 req->rxq_index = rxq_index; 981 req->rxq_index = rxq_index;
932 req->flow_id = flow_id; 982 req->flow_id = flow_id;
933 schedule_work(&req->work); 983 schedule_work(&req->work);
934 return 0; 984 return rc;
985out_unlock:
986 spin_unlock(&efx->rps_hash_lock);
935out_clear: 987out_clear:
936 clear_bit(slot_idx, &efx->rps_slot_map); 988 clear_bit(slot_idx, &efx->rps_slot_map);
937 return rc; 989 return rc;
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 30371274409d..74f828412055 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -129,7 +129,7 @@ do { \
129 129
130#define RX_PRIORITY_MAPPING 0x76543210 130#define RX_PRIORITY_MAPPING 0x76543210
131#define TX_PRIORITY_MAPPING 0x33221100 131#define TX_PRIORITY_MAPPING 0x33221100
132#define CPDMA_TX_PRIORITY_MAP 0x01234567 132#define CPDMA_TX_PRIORITY_MAP 0x76543210
133 133
134#define CPSW_VLAN_AWARE BIT(1) 134#define CPSW_VLAN_AWARE BIT(1)
135#define CPSW_RX_VLAN_ENCAP BIT(2) 135#define CPSW_RX_VLAN_ENCAP BIT(2)
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index c22e8e383247..25e2a099b71c 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1393,6 +1393,15 @@ static int m88e1318_set_wol(struct phy_device *phydev,
1393 if (err < 0) 1393 if (err < 0)
1394 goto error; 1394 goto error;
1395 1395
1396 /* If WOL event happened once, the LED[2] interrupt pin
1397 * will not be cleared unless we reading the interrupt status
1398 * register. If interrupts are in use, the normal interrupt
1399 * handling will clear the WOL event. Clear the WOL event
1400 * before enabling it if !phy_interrupt_is_valid()
1401 */
1402 if (!phy_interrupt_is_valid(phydev))
1403 phy_read(phydev, MII_M1011_IEVENT);
1404
1396 /* Enable the WOL interrupt */ 1405 /* Enable the WOL interrupt */
1397 err = __phy_modify(phydev, MII_88E1318S_PHY_CSIER, 0, 1406 err = __phy_modify(phydev, MII_88E1318S_PHY_CSIER, 0,
1398 MII_88E1318S_PHY_CSIER_WOL_EIE); 1407 MII_88E1318S_PHY_CSIER_WOL_EIE);
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index 1483bc7b01e1..7df07337d69c 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -620,6 +620,10 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
620 lock_sock(sk); 620 lock_sock(sk);
621 621
622 error = -EINVAL; 622 error = -EINVAL;
623
624 if (sockaddr_len != sizeof(struct sockaddr_pppox))
625 goto end;
626
623 if (sp->sa_protocol != PX_PROTO_OE) 627 if (sp->sa_protocol != PX_PROTO_OE)
624 goto end; 628 goto end;
625 629
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index acbe84967834..ddb6bf85a59c 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -1072,14 +1072,11 @@ static void team_port_leave(struct team *team, struct team_port *port)
1072} 1072}
1073 1073
1074#ifdef CONFIG_NET_POLL_CONTROLLER 1074#ifdef CONFIG_NET_POLL_CONTROLLER
1075static int team_port_enable_netpoll(struct team *team, struct team_port *port) 1075static int __team_port_enable_netpoll(struct team_port *port)
1076{ 1076{
1077 struct netpoll *np; 1077 struct netpoll *np;
1078 int err; 1078 int err;
1079 1079
1080 if (!team->dev->npinfo)
1081 return 0;
1082
1083 np = kzalloc(sizeof(*np), GFP_KERNEL); 1080 np = kzalloc(sizeof(*np), GFP_KERNEL);
1084 if (!np) 1081 if (!np)
1085 return -ENOMEM; 1082 return -ENOMEM;
@@ -1093,6 +1090,14 @@ static int team_port_enable_netpoll(struct team *team, struct team_port *port)
1093 return err; 1090 return err;
1094} 1091}
1095 1092
1093static int team_port_enable_netpoll(struct team_port *port)
1094{
1095 if (!port->team->dev->npinfo)
1096 return 0;
1097
1098 return __team_port_enable_netpoll(port);
1099}
1100
1096static void team_port_disable_netpoll(struct team_port *port) 1101static void team_port_disable_netpoll(struct team_port *port)
1097{ 1102{
1098 struct netpoll *np = port->np; 1103 struct netpoll *np = port->np;
@@ -1107,7 +1112,7 @@ static void team_port_disable_netpoll(struct team_port *port)
1107 kfree(np); 1112 kfree(np);
1108} 1113}
1109#else 1114#else
1110static int team_port_enable_netpoll(struct team *team, struct team_port *port) 1115static int team_port_enable_netpoll(struct team_port *port)
1111{ 1116{
1112 return 0; 1117 return 0;
1113} 1118}
@@ -1221,7 +1226,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
1221 goto err_vids_add; 1226 goto err_vids_add;
1222 } 1227 }
1223 1228
1224 err = team_port_enable_netpoll(team, port); 1229 err = team_port_enable_netpoll(port);
1225 if (err) { 1230 if (err) {
1226 netdev_err(dev, "Failed to enable netpoll on device %s\n", 1231 netdev_err(dev, "Failed to enable netpoll on device %s\n",
1227 portname); 1232 portname);
@@ -1918,7 +1923,7 @@ static int team_netpoll_setup(struct net_device *dev,
1918 1923
1919 mutex_lock(&team->lock); 1924 mutex_lock(&team->lock);
1920 list_for_each_entry(port, &team->port_list, list) { 1925 list_for_each_entry(port, &team->port_list, list) {
1921 err = team_port_enable_netpoll(team, port); 1926 err = __team_port_enable_netpoll(port);
1922 if (err) { 1927 if (err) {
1923 __team_netpoll_cleanup(team); 1928 __team_netpoll_cleanup(team);
1924 break; 1929 break;
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index 4326715dc13e..78b98b3e7efa 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -557,7 +557,6 @@ enum qeth_prot_versions {
557enum qeth_cmd_buffer_state { 557enum qeth_cmd_buffer_state {
558 BUF_STATE_FREE, 558 BUF_STATE_FREE,
559 BUF_STATE_LOCKED, 559 BUF_STATE_LOCKED,
560 BUF_STATE_PROCESSED,
561}; 560};
562 561
563enum qeth_cq { 562enum qeth_cq {
@@ -601,7 +600,6 @@ struct qeth_channel {
601 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO]; 600 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
602 atomic_t irq_pending; 601 atomic_t irq_pending;
603 int io_buf_no; 602 int io_buf_no;
604 int buf_no;
605}; 603};
606 604
607/** 605/**
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 04fefa5bb08d..dffd820731f2 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -706,7 +706,6 @@ void qeth_clear_ipacmd_list(struct qeth_card *card)
706 qeth_put_reply(reply); 706 qeth_put_reply(reply);
707 } 707 }
708 spin_unlock_irqrestore(&card->lock, flags); 708 spin_unlock_irqrestore(&card->lock, flags);
709 atomic_set(&card->write.irq_pending, 0);
710} 709}
711EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list); 710EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
712 711
@@ -818,7 +817,6 @@ void qeth_clear_cmd_buffers(struct qeth_channel *channel)
818 817
819 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) 818 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
820 qeth_release_buffer(channel, &channel->iob[cnt]); 819 qeth_release_buffer(channel, &channel->iob[cnt]);
821 channel->buf_no = 0;
822 channel->io_buf_no = 0; 820 channel->io_buf_no = 0;
823} 821}
824EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers); 822EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
@@ -924,7 +922,6 @@ static int qeth_setup_channel(struct qeth_channel *channel)
924 kfree(channel->iob[cnt].data); 922 kfree(channel->iob[cnt].data);
925 return -ENOMEM; 923 return -ENOMEM;
926 } 924 }
927 channel->buf_no = 0;
928 channel->io_buf_no = 0; 925 channel->io_buf_no = 0;
929 atomic_set(&channel->irq_pending, 0); 926 atomic_set(&channel->irq_pending, 0);
930 spin_lock_init(&channel->iob_lock); 927 spin_lock_init(&channel->iob_lock);
@@ -1100,16 +1097,9 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1100{ 1097{
1101 int rc; 1098 int rc;
1102 int cstat, dstat; 1099 int cstat, dstat;
1103 struct qeth_cmd_buffer *buffer; 1100 struct qeth_cmd_buffer *iob = NULL;
1104 struct qeth_channel *channel; 1101 struct qeth_channel *channel;
1105 struct qeth_card *card; 1102 struct qeth_card *card;
1106 struct qeth_cmd_buffer *iob;
1107 __u8 index;
1108
1109 if (__qeth_check_irb_error(cdev, intparm, irb))
1110 return;
1111 cstat = irb->scsw.cmd.cstat;
1112 dstat = irb->scsw.cmd.dstat;
1113 1103
1114 card = CARD_FROM_CDEV(cdev); 1104 card = CARD_FROM_CDEV(cdev);
1115 if (!card) 1105 if (!card)
@@ -1127,6 +1117,19 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1127 channel = &card->data; 1117 channel = &card->data;
1128 QETH_CARD_TEXT(card, 5, "data"); 1118 QETH_CARD_TEXT(card, 5, "data");
1129 } 1119 }
1120
1121 if (qeth_intparm_is_iob(intparm))
1122 iob = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
1123
1124 if (__qeth_check_irb_error(cdev, intparm, irb)) {
1125 /* IO was terminated, free its resources. */
1126 if (iob)
1127 qeth_release_buffer(iob->channel, iob);
1128 atomic_set(&channel->irq_pending, 0);
1129 wake_up(&card->wait_q);
1130 return;
1131 }
1132
1130 atomic_set(&channel->irq_pending, 0); 1133 atomic_set(&channel->irq_pending, 0);
1131 1134
1132 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC)) 1135 if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
@@ -1150,6 +1153,10 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1150 /* we don't have to handle this further */ 1153 /* we don't have to handle this further */
1151 intparm = 0; 1154 intparm = 0;
1152 } 1155 }
1156
1157 cstat = irb->scsw.cmd.cstat;
1158 dstat = irb->scsw.cmd.dstat;
1159
1153 if ((dstat & DEV_STAT_UNIT_EXCEP) || 1160 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
1154 (dstat & DEV_STAT_UNIT_CHECK) || 1161 (dstat & DEV_STAT_UNIT_CHECK) ||
1155 (cstat)) { 1162 (cstat)) {
@@ -1182,25 +1189,15 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
1182 channel->state = CH_STATE_RCD_DONE; 1189 channel->state = CH_STATE_RCD_DONE;
1183 goto out; 1190 goto out;
1184 } 1191 }
1185 if (intparm) {
1186 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
1187 buffer->state = BUF_STATE_PROCESSED;
1188 }
1189 if (channel == &card->data) 1192 if (channel == &card->data)
1190 return; 1193 return;
1191 if (channel == &card->read && 1194 if (channel == &card->read &&
1192 channel->state == CH_STATE_UP) 1195 channel->state == CH_STATE_UP)
1193 __qeth_issue_next_read(card); 1196 __qeth_issue_next_read(card);
1194 1197
1195 iob = channel->iob; 1198 if (iob && iob->callback)
1196 index = channel->buf_no; 1199 iob->callback(iob->channel, iob);
1197 while (iob[index].state == BUF_STATE_PROCESSED) {
1198 if (iob[index].callback != NULL)
1199 iob[index].callback(channel, iob + index);
1200 1200
1201 index = (index + 1) % QETH_CMD_BUFFER_NO;
1202 }
1203 channel->buf_no = index;
1204out: 1201out:
1205 wake_up(&card->wait_q); 1202 wake_up(&card->wait_q);
1206 return; 1203 return;
@@ -1870,8 +1867,8 @@ static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1870 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0); 1867 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1871 QETH_DBF_TEXT(SETUP, 6, "noirqpnd"); 1868 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1872 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 1869 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1873 rc = ccw_device_start(channel->ccwdev, 1870 rc = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1874 &channel->ccw, (addr_t) iob, 0, 0); 1871 (addr_t) iob, 0, 0, QETH_TIMEOUT);
1875 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 1872 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1876 1873
1877 if (rc) { 1874 if (rc) {
@@ -1888,7 +1885,6 @@ static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
1888 if (channel->state != CH_STATE_UP) { 1885 if (channel->state != CH_STATE_UP) {
1889 rc = -ETIME; 1886 rc = -ETIME;
1890 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc); 1887 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
1891 qeth_clear_cmd_buffers(channel);
1892 } else 1888 } else
1893 rc = 0; 1889 rc = 0;
1894 return rc; 1890 return rc;
@@ -1942,8 +1938,8 @@ static int qeth_idx_activate_channel(struct qeth_channel *channel,
1942 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0); 1938 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
1943 QETH_DBF_TEXT(SETUP, 6, "noirqpnd"); 1939 QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
1944 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 1940 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1945 rc = ccw_device_start(channel->ccwdev, 1941 rc = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1946 &channel->ccw, (addr_t) iob, 0, 0); 1942 (addr_t) iob, 0, 0, QETH_TIMEOUT);
1947 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 1943 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1948 1944
1949 if (rc) { 1945 if (rc) {
@@ -1964,7 +1960,6 @@ static int qeth_idx_activate_channel(struct qeth_channel *channel,
1964 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n", 1960 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1965 dev_name(&channel->ccwdev->dev)); 1961 dev_name(&channel->ccwdev->dev));
1966 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME); 1962 QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
1967 qeth_clear_cmd_buffers(channel);
1968 return -ETIME; 1963 return -ETIME;
1969 } 1964 }
1970 return qeth_idx_activate_get_answer(channel, idx_reply_cb); 1965 return qeth_idx_activate_get_answer(channel, idx_reply_cb);
@@ -2166,8 +2161,8 @@ int qeth_send_control_data(struct qeth_card *card, int len,
2166 2161
2167 QETH_CARD_TEXT(card, 6, "noirqpnd"); 2162 QETH_CARD_TEXT(card, 6, "noirqpnd");
2168 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 2163 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
2169 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 2164 rc = ccw_device_start_timeout(CARD_WDEV(card), &card->write.ccw,
2170 (addr_t) iob, 0, 0); 2165 (addr_t) iob, 0, 0, event_timeout);
2171 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); 2166 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
2172 if (rc) { 2167 if (rc) {
2173 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: " 2168 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
@@ -2199,8 +2194,6 @@ int qeth_send_control_data(struct qeth_card *card, int len,
2199 } 2194 }
2200 } 2195 }
2201 2196
2202 if (reply->rc == -EIO)
2203 goto error;
2204 rc = reply->rc; 2197 rc = reply->rc;
2205 qeth_put_reply(reply); 2198 qeth_put_reply(reply);
2206 return rc; 2199 return rc;
@@ -2211,10 +2204,6 @@ time_err:
2211 list_del_init(&reply->list); 2204 list_del_init(&reply->list);
2212 spin_unlock_irqrestore(&reply->card->lock, flags); 2205 spin_unlock_irqrestore(&reply->card->lock, flags);
2213 atomic_inc(&reply->received); 2206 atomic_inc(&reply->received);
2214error:
2215 atomic_set(&card->write.irq_pending, 0);
2216 qeth_release_buffer(iob->channel, iob);
2217 card->write.buf_no = (card->write.buf_no + 1) % QETH_CMD_BUFFER_NO;
2218 rc = reply->rc; 2207 rc = reply->rc;
2219 qeth_put_reply(reply); 2208 qeth_put_reply(reply);
2220 return rc; 2209 return rc;
@@ -3033,28 +3022,23 @@ static int qeth_send_startlan(struct qeth_card *card)
3033 return rc; 3022 return rc;
3034} 3023}
3035 3024
3036static int qeth_default_setadapterparms_cb(struct qeth_card *card, 3025static int qeth_setadpparms_inspect_rc(struct qeth_ipa_cmd *cmd)
3037 struct qeth_reply *reply, unsigned long data)
3038{ 3026{
3039 struct qeth_ipa_cmd *cmd; 3027 if (!cmd->hdr.return_code)
3040
3041 QETH_CARD_TEXT(card, 4, "defadpcb");
3042
3043 cmd = (struct qeth_ipa_cmd *) data;
3044 if (cmd->hdr.return_code == 0)
3045 cmd->hdr.return_code = 3028 cmd->hdr.return_code =
3046 cmd->data.setadapterparms.hdr.return_code; 3029 cmd->data.setadapterparms.hdr.return_code;
3047 return 0; 3030 return cmd->hdr.return_code;
3048} 3031}
3049 3032
3050static int qeth_query_setadapterparms_cb(struct qeth_card *card, 3033static int qeth_query_setadapterparms_cb(struct qeth_card *card,
3051 struct qeth_reply *reply, unsigned long data) 3034 struct qeth_reply *reply, unsigned long data)
3052{ 3035{
3053 struct qeth_ipa_cmd *cmd; 3036 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3054 3037
3055 QETH_CARD_TEXT(card, 3, "quyadpcb"); 3038 QETH_CARD_TEXT(card, 3, "quyadpcb");
3039 if (qeth_setadpparms_inspect_rc(cmd))
3040 return 0;
3056 3041
3057 cmd = (struct qeth_ipa_cmd *) data;
3058 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) { 3042 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) {
3059 card->info.link_type = 3043 card->info.link_type =
3060 cmd->data.setadapterparms.data.query_cmds_supp.lan_type; 3044 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
@@ -3062,7 +3046,7 @@ static int qeth_query_setadapterparms_cb(struct qeth_card *card,
3062 } 3046 }
3063 card->options.adp.supported_funcs = 3047 card->options.adp.supported_funcs =
3064 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds; 3048 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
3065 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd); 3049 return 0;
3066} 3050}
3067 3051
3068static struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card, 3052static struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
@@ -3154,22 +3138,20 @@ EXPORT_SYMBOL_GPL(qeth_query_ipassists);
3154static int qeth_query_switch_attributes_cb(struct qeth_card *card, 3138static int qeth_query_switch_attributes_cb(struct qeth_card *card,
3155 struct qeth_reply *reply, unsigned long data) 3139 struct qeth_reply *reply, unsigned long data)
3156{ 3140{
3157 struct qeth_ipa_cmd *cmd; 3141 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
3158 struct qeth_switch_info *sw_info;
3159 struct qeth_query_switch_attributes *attrs; 3142 struct qeth_query_switch_attributes *attrs;
3143 struct qeth_switch_info *sw_info;
3160 3144
3161 QETH_CARD_TEXT(card, 2, "qswiatcb"); 3145 QETH_CARD_TEXT(card, 2, "qswiatcb");
3162 cmd = (struct qeth_ipa_cmd *) data; 3146 if (qeth_setadpparms_inspect_rc(cmd))
3163 sw_info = (struct qeth_switch_info *)reply->param; 3147 return 0;
3164 if (cmd->data.setadapterparms.hdr.return_code == 0) {
3165 attrs = &cmd->data.setadapterparms.data.query_switch_attributes;
3166 sw_info->capabilities = attrs->capabilities;
3167 sw_info->settings = attrs->settings;
3168 QETH_CARD_TEXT_(card, 2, "%04x%04x", sw_info->capabilities,
3169 sw_info->settings);
3170 }
3171 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
3172 3148
3149 sw_info = (struct qeth_switch_info *)reply->param;
3150 attrs = &cmd->data.setadapterparms.data.query_switch_attributes;
3151 sw_info->capabilities = attrs->capabilities;
3152 sw_info->settings = attrs->settings;
3153 QETH_CARD_TEXT_(card, 2, "%04x%04x", sw_info->capabilities,
3154 sw_info->settings);
3173 return 0; 3155 return 0;
3174} 3156}
3175 3157
@@ -4207,16 +4189,13 @@ EXPORT_SYMBOL_GPL(qeth_do_send_packet);
4207static int qeth_setadp_promisc_mode_cb(struct qeth_card *card, 4189static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
4208 struct qeth_reply *reply, unsigned long data) 4190 struct qeth_reply *reply, unsigned long data)
4209{ 4191{
4210 struct qeth_ipa_cmd *cmd; 4192 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4211 struct qeth_ipacmd_setadpparms *setparms; 4193 struct qeth_ipacmd_setadpparms *setparms;
4212 4194
4213 QETH_CARD_TEXT(card, 4, "prmadpcb"); 4195 QETH_CARD_TEXT(card, 4, "prmadpcb");
4214 4196
4215 cmd = (struct qeth_ipa_cmd *) data;
4216 setparms = &(cmd->data.setadapterparms); 4197 setparms = &(cmd->data.setadapterparms);
4217 4198 if (qeth_setadpparms_inspect_rc(cmd)) {
4218 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
4219 if (cmd->hdr.return_code) {
4220 QETH_CARD_TEXT_(card, 4, "prmrc%x", cmd->hdr.return_code); 4199 QETH_CARD_TEXT_(card, 4, "prmrc%x", cmd->hdr.return_code);
4221 setparms->data.mode = SET_PROMISC_MODE_OFF; 4200 setparms->data.mode = SET_PROMISC_MODE_OFF;
4222 } 4201 }
@@ -4286,18 +4265,18 @@ EXPORT_SYMBOL_GPL(qeth_get_stats);
4286static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card, 4265static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
4287 struct qeth_reply *reply, unsigned long data) 4266 struct qeth_reply *reply, unsigned long data)
4288{ 4267{
4289 struct qeth_ipa_cmd *cmd; 4268 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4290 4269
4291 QETH_CARD_TEXT(card, 4, "chgmaccb"); 4270 QETH_CARD_TEXT(card, 4, "chgmaccb");
4271 if (qeth_setadpparms_inspect_rc(cmd))
4272 return 0;
4292 4273
4293 cmd = (struct qeth_ipa_cmd *) data;
4294 if (!card->options.layer2 || 4274 if (!card->options.layer2 ||
4295 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) { 4275 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
4296 ether_addr_copy(card->dev->dev_addr, 4276 ether_addr_copy(card->dev->dev_addr,
4297 cmd->data.setadapterparms.data.change_addr.addr); 4277 cmd->data.setadapterparms.data.change_addr.addr);
4298 card->info.mac_bits |= QETH_LAYER2_MAC_READ; 4278 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
4299 } 4279 }
4300 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4301 return 0; 4280 return 0;
4302} 4281}
4303 4282
@@ -4328,13 +4307,15 @@ EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
4328static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card, 4307static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4329 struct qeth_reply *reply, unsigned long data) 4308 struct qeth_reply *reply, unsigned long data)
4330{ 4309{
4331 struct qeth_ipa_cmd *cmd; 4310 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
4332 struct qeth_set_access_ctrl *access_ctrl_req; 4311 struct qeth_set_access_ctrl *access_ctrl_req;
4333 int fallback = *(int *)reply->param; 4312 int fallback = *(int *)reply->param;
4334 4313
4335 QETH_CARD_TEXT(card, 4, "setaccb"); 4314 QETH_CARD_TEXT(card, 4, "setaccb");
4315 if (cmd->hdr.return_code)
4316 return 0;
4317 qeth_setadpparms_inspect_rc(cmd);
4336 4318
4337 cmd = (struct qeth_ipa_cmd *) data;
4338 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl; 4319 access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
4339 QETH_DBF_TEXT_(SETUP, 2, "setaccb"); 4320 QETH_DBF_TEXT_(SETUP, 2, "setaccb");
4340 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name); 4321 QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
@@ -4407,7 +4388,6 @@ static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
4407 card->options.isolation = card->options.prev_isolation; 4388 card->options.isolation = card->options.prev_isolation;
4408 break; 4389 break;
4409 } 4390 }
4410 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
4411 return 0; 4391 return 0;
4412} 4392}
4413 4393
@@ -4695,14 +4675,15 @@ out:
4695static int qeth_setadpparms_query_oat_cb(struct qeth_card *card, 4675static int qeth_setadpparms_query_oat_cb(struct qeth_card *card,
4696 struct qeth_reply *reply, unsigned long data) 4676 struct qeth_reply *reply, unsigned long data)
4697{ 4677{
4698 struct qeth_ipa_cmd *cmd; 4678 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4699 struct qeth_qoat_priv *priv; 4679 struct qeth_qoat_priv *priv;
4700 char *resdata; 4680 char *resdata;
4701 int resdatalen; 4681 int resdatalen;
4702 4682
4703 QETH_CARD_TEXT(card, 3, "qoatcb"); 4683 QETH_CARD_TEXT(card, 3, "qoatcb");
4684 if (qeth_setadpparms_inspect_rc(cmd))
4685 return 0;
4704 4686
4705 cmd = (struct qeth_ipa_cmd *)data;
4706 priv = (struct qeth_qoat_priv *)reply->param; 4687 priv = (struct qeth_qoat_priv *)reply->param;
4707 resdatalen = cmd->data.setadapterparms.hdr.cmdlength; 4688 resdatalen = cmd->data.setadapterparms.hdr.cmdlength;
4708 resdata = (char *)data + 28; 4689 resdata = (char *)data + 28;
@@ -4796,21 +4777,18 @@ out:
4796static int qeth_query_card_info_cb(struct qeth_card *card, 4777static int qeth_query_card_info_cb(struct qeth_card *card,
4797 struct qeth_reply *reply, unsigned long data) 4778 struct qeth_reply *reply, unsigned long data)
4798{ 4779{
4799 struct qeth_ipa_cmd *cmd; 4780 struct carrier_info *carrier_info = (struct carrier_info *)reply->param;
4781 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
4800 struct qeth_query_card_info *card_info; 4782 struct qeth_query_card_info *card_info;
4801 struct carrier_info *carrier_info;
4802 4783
4803 QETH_CARD_TEXT(card, 2, "qcrdincb"); 4784 QETH_CARD_TEXT(card, 2, "qcrdincb");
4804 carrier_info = (struct carrier_info *)reply->param; 4785 if (qeth_setadpparms_inspect_rc(cmd))
4805 cmd = (struct qeth_ipa_cmd *)data; 4786 return 0;
4806 card_info = &cmd->data.setadapterparms.data.card_info;
4807 if (cmd->data.setadapterparms.hdr.return_code == 0) {
4808 carrier_info->card_type = card_info->card_type;
4809 carrier_info->port_mode = card_info->port_mode;
4810 carrier_info->port_speed = card_info->port_speed;
4811 }
4812 4787
4813 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd); 4788 card_info = &cmd->data.setadapterparms.data.card_info;
4789 carrier_info->card_type = card_info->card_type;
4790 carrier_info->port_mode = card_info->port_mode;
4791 carrier_info->port_speed = card_info->port_speed;
4814 return 0; 4792 return 0;
4815} 4793}
4816 4794
@@ -4857,7 +4835,7 @@ int qeth_vm_request_mac(struct qeth_card *card)
4857 goto out; 4835 goto out;
4858 } 4836 }
4859 4837
4860 ccw_device_get_id(CARD_DDEV(card), &id); 4838 ccw_device_get_id(CARD_RDEV(card), &id);
4861 request->resp_buf_len = sizeof(*response); 4839 request->resp_buf_len = sizeof(*response);
4862 request->resp_version = DIAG26C_VERSION2; 4840 request->resp_version = DIAG26C_VERSION2;
4863 request->op_code = DIAG26C_GET_MAC; 4841 request->op_code = DIAG26C_GET_MAC;
@@ -6563,10 +6541,14 @@ static int __init qeth_core_init(void)
6563 mutex_init(&qeth_mod_mutex); 6541 mutex_init(&qeth_mod_mutex);
6564 6542
6565 qeth_wq = create_singlethread_workqueue("qeth_wq"); 6543 qeth_wq = create_singlethread_workqueue("qeth_wq");
6544 if (!qeth_wq) {
6545 rc = -ENOMEM;
6546 goto out_err;
6547 }
6566 6548
6567 rc = qeth_register_dbf_views(); 6549 rc = qeth_register_dbf_views();
6568 if (rc) 6550 if (rc)
6569 goto out_err; 6551 goto dbf_err;
6570 qeth_core_root_dev = root_device_register("qeth"); 6552 qeth_core_root_dev = root_device_register("qeth");
6571 rc = PTR_ERR_OR_ZERO(qeth_core_root_dev); 6553 rc = PTR_ERR_OR_ZERO(qeth_core_root_dev);
6572 if (rc) 6554 if (rc)
@@ -6603,6 +6585,8 @@ slab_err:
6603 root_device_unregister(qeth_core_root_dev); 6585 root_device_unregister(qeth_core_root_dev);
6604register_err: 6586register_err:
6605 qeth_unregister_dbf_views(); 6587 qeth_unregister_dbf_views();
6588dbf_err:
6589 destroy_workqueue(qeth_wq);
6606out_err: 6590out_err:
6607 pr_err("Initializing the qeth device driver failed\n"); 6591 pr_err("Initializing the qeth device driver failed\n");
6608 return rc; 6592 return rc;
diff --git a/drivers/s390/net/qeth_core_mpc.h b/drivers/s390/net/qeth_core_mpc.h
index 619f897b4bb0..f4d1ec0b8f5a 100644
--- a/drivers/s390/net/qeth_core_mpc.h
+++ b/drivers/s390/net/qeth_core_mpc.h
@@ -35,6 +35,18 @@ extern unsigned char IPA_PDU_HEADER[];
35#define QETH_HALT_CHANNEL_PARM -11 35#define QETH_HALT_CHANNEL_PARM -11
36#define QETH_RCD_PARM -12 36#define QETH_RCD_PARM -12
37 37
38static inline bool qeth_intparm_is_iob(unsigned long intparm)
39{
40 switch (intparm) {
41 case QETH_CLEAR_CHANNEL_PARM:
42 case QETH_HALT_CHANNEL_PARM:
43 case QETH_RCD_PARM:
44 case 0:
45 return false;
46 }
47 return true;
48}
49
38/*****************************************************************************/ 50/*****************************************************************************/
39/* IP Assist related definitions */ 51/* IP Assist related definitions */
40/*****************************************************************************/ 52/*****************************************************************************/
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 2ad6f12f3d49..b8079f2a65b3 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -121,13 +121,10 @@ static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
121 QETH_CARD_TEXT(card, 2, "L2Setmac"); 121 QETH_CARD_TEXT(card, 2, "L2Setmac");
122 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); 122 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
123 if (rc == 0) { 123 if (rc == 0) {
124 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
125 ether_addr_copy(card->dev->dev_addr, mac);
126 dev_info(&card->gdev->dev, 124 dev_info(&card->gdev->dev,
127 "MAC address %pM successfully registered on device %s\n", 125 "MAC address %pM successfully registered on device %s\n",
128 card->dev->dev_addr, card->dev->name); 126 mac, card->dev->name);
129 } else { 127 } else {
130 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
131 switch (rc) { 128 switch (rc) {
132 case -EEXIST: 129 case -EEXIST:
133 dev_warn(&card->gdev->dev, 130 dev_warn(&card->gdev->dev,
@@ -142,19 +139,6 @@ static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
142 return rc; 139 return rc;
143} 140}
144 141
145static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
146{
147 int rc;
148
149 QETH_CARD_TEXT(card, 2, "L2Delmac");
150 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
151 return 0;
152 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
153 if (rc == 0)
154 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
155 return rc;
156}
157
158static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac) 142static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
159{ 143{
160 enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ? 144 enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ?
@@ -519,6 +503,7 @@ static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
519{ 503{
520 struct sockaddr *addr = p; 504 struct sockaddr *addr = p;
521 struct qeth_card *card = dev->ml_priv; 505 struct qeth_card *card = dev->ml_priv;
506 u8 old_addr[ETH_ALEN];
522 int rc = 0; 507 int rc = 0;
523 508
524 QETH_CARD_TEXT(card, 3, "setmac"); 509 QETH_CARD_TEXT(card, 3, "setmac");
@@ -530,14 +515,35 @@ static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
530 return -EOPNOTSUPP; 515 return -EOPNOTSUPP;
531 } 516 }
532 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN); 517 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
518 if (!is_valid_ether_addr(addr->sa_data))
519 return -EADDRNOTAVAIL;
520
533 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 521 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
534 QETH_CARD_TEXT(card, 3, "setmcREC"); 522 QETH_CARD_TEXT(card, 3, "setmcREC");
535 return -ERESTARTSYS; 523 return -ERESTARTSYS;
536 } 524 }
537 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); 525
538 if (!rc || (rc == -ENOENT)) 526 if (!qeth_card_hw_is_reachable(card)) {
539 rc = qeth_l2_send_setmac(card, addr->sa_data); 527 ether_addr_copy(dev->dev_addr, addr->sa_data);
540 return rc ? -EINVAL : 0; 528 return 0;
529 }
530
531 /* don't register the same address twice */
532 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
533 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
534 return 0;
535
536 /* add the new address, switch over, drop the old */
537 rc = qeth_l2_send_setmac(card, addr->sa_data);
538 if (rc)
539 return rc;
540 ether_addr_copy(old_addr, dev->dev_addr);
541 ether_addr_copy(dev->dev_addr, addr->sa_data);
542
543 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
544 qeth_l2_remove_mac(card, old_addr);
545 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
546 return 0;
541} 547}
542 548
543static void qeth_promisc_to_bridge(struct qeth_card *card) 549static void qeth_promisc_to_bridge(struct qeth_card *card)
@@ -1067,8 +1073,9 @@ static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1067 goto out_remove; 1073 goto out_remove;
1068 } 1074 }
1069 1075
1070 if (card->info.type != QETH_CARD_TYPE_OSN) 1076 if (card->info.type != QETH_CARD_TYPE_OSN &&
1071 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); 1077 !qeth_l2_send_setmac(card, card->dev->dev_addr))
1078 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
1072 1079
1073 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { 1080 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1074 if (card->info.hwtrap && 1081 if (card->info.hwtrap &&
@@ -1338,8 +1345,8 @@ static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1338 qeth_prepare_control_data(card, len, iob); 1345 qeth_prepare_control_data(card, len, iob);
1339 QETH_CARD_TEXT(card, 6, "osnoirqp"); 1346 QETH_CARD_TEXT(card, 6, "osnoirqp");
1340 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 1347 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1341 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 1348 rc = ccw_device_start_timeout(CARD_WDEV(card), &card->write.ccw,
1342 (addr_t) iob, 0, 0); 1349 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
1343 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); 1350 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1344 if (rc) { 1351 if (rc) {
1345 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " 1352 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 95a7abd0ee92..486e65e3db26 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -339,8 +339,8 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
339void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs, 339void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs,
340 struct bpf_prog *old_prog); 340 struct bpf_prog *old_prog);
341int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array, 341int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
342 __u32 __user *prog_ids, u32 request_cnt, 342 u32 *prog_ids, u32 request_cnt,
343 __u32 __user *prog_cnt); 343 u32 *prog_cnt);
344int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, 344int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
345 struct bpf_prog *exclude_prog, 345 struct bpf_prog *exclude_prog,
346 struct bpf_prog *include_prog, 346 struct bpf_prog *include_prog,
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index ebe41811ed34..b32cd2062f18 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -310,6 +310,8 @@ bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
310 * fields should be ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS 310 * fields should be ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS
311 * instead of the latter), any change to them will be overwritten 311 * instead of the latter), any change to them will be overwritten
312 * by kernel. Returns a negative error code or zero. 312 * by kernel. Returns a negative error code or zero.
313 * @get_fecparam: Get the network device Forward Error Correction parameters.
314 * @set_fecparam: Set the network device Forward Error Correction parameters.
313 * 315 *
314 * All operations are optional (i.e. the function pointer may be set 316 * All operations are optional (i.e. the function pointer may be set
315 * to %NULL) and callers must take this into account. Callers must 317 * to %NULL) and callers must take this into account. Callers must
diff --git a/include/net/ife.h b/include/net/ife.h
index 44b9c00f7223..e117617e3c34 100644
--- a/include/net/ife.h
+++ b/include/net/ife.h
@@ -12,7 +12,8 @@
12void *ife_encode(struct sk_buff *skb, u16 metalen); 12void *ife_encode(struct sk_buff *skb, u16 metalen);
13void *ife_decode(struct sk_buff *skb, u16 *metalen); 13void *ife_decode(struct sk_buff *skb, u16 *metalen);
14 14
15void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen); 15void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
16 u16 *dlen, u16 *totlen);
16int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen, 17int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
17 const void *dval); 18 const void *dval);
18 19
diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h
index 5c40f118c0fa..df528a623548 100644
--- a/include/net/llc_conn.h
+++ b/include/net/llc_conn.h
@@ -97,6 +97,7 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb)
97 97
98struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority, 98struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority,
99 struct proto *prot, int kern); 99 struct proto *prot, int kern);
100void llc_sk_stop_all_timers(struct sock *sk, bool sync);
100void llc_sk_free(struct sock *sk); 101void llc_sk_free(struct sock *sk);
101 102
102void llc_sk_reset(struct sock *sk); 103void llc_sk_reset(struct sock *sk);
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index d315b393abdd..ba03ec39efb3 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1572,13 +1572,32 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs)
1572 return cnt; 1572 return cnt;
1573} 1573}
1574 1574
1575static bool bpf_prog_array_copy_core(struct bpf_prog **prog,
1576 u32 *prog_ids,
1577 u32 request_cnt)
1578{
1579 int i = 0;
1580
1581 for (; *prog; prog++) {
1582 if (*prog == &dummy_bpf_prog.prog)
1583 continue;
1584 prog_ids[i] = (*prog)->aux->id;
1585 if (++i == request_cnt) {
1586 prog++;
1587 break;
1588 }
1589 }
1590
1591 return !!(*prog);
1592}
1593
1575int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs, 1594int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1576 __u32 __user *prog_ids, u32 cnt) 1595 __u32 __user *prog_ids, u32 cnt)
1577{ 1596{
1578 struct bpf_prog **prog; 1597 struct bpf_prog **prog;
1579 unsigned long err = 0; 1598 unsigned long err = 0;
1580 u32 i = 0, *ids;
1581 bool nospc; 1599 bool nospc;
1600 u32 *ids;
1582 1601
1583 /* users of this function are doing: 1602 /* users of this function are doing:
1584 * cnt = bpf_prog_array_length(); 1603 * cnt = bpf_prog_array_length();
@@ -1595,16 +1614,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1595 return -ENOMEM; 1614 return -ENOMEM;
1596 rcu_read_lock(); 1615 rcu_read_lock();
1597 prog = rcu_dereference(progs)->progs; 1616 prog = rcu_dereference(progs)->progs;
1598 for (; *prog; prog++) { 1617 nospc = bpf_prog_array_copy_core(prog, ids, cnt);
1599 if (*prog == &dummy_bpf_prog.prog)
1600 continue;
1601 ids[i] = (*prog)->aux->id;
1602 if (++i == cnt) {
1603 prog++;
1604 break;
1605 }
1606 }
1607 nospc = !!(*prog);
1608 rcu_read_unlock(); 1618 rcu_read_unlock();
1609 err = copy_to_user(prog_ids, ids, cnt * sizeof(u32)); 1619 err = copy_to_user(prog_ids, ids, cnt * sizeof(u32));
1610 kfree(ids); 1620 kfree(ids);
@@ -1683,22 +1693,25 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
1683} 1693}
1684 1694
1685int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array, 1695int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
1686 __u32 __user *prog_ids, u32 request_cnt, 1696 u32 *prog_ids, u32 request_cnt,
1687 __u32 __user *prog_cnt) 1697 u32 *prog_cnt)
1688{ 1698{
1699 struct bpf_prog **prog;
1689 u32 cnt = 0; 1700 u32 cnt = 0;
1690 1701
1691 if (array) 1702 if (array)
1692 cnt = bpf_prog_array_length(array); 1703 cnt = bpf_prog_array_length(array);
1693 1704
1694 if (copy_to_user(prog_cnt, &cnt, sizeof(cnt))) 1705 *prog_cnt = cnt;
1695 return -EFAULT;
1696 1706
1697 /* return early if user requested only program count or nothing to copy */ 1707 /* return early if user requested only program count or nothing to copy */
1698 if (!request_cnt || !cnt) 1708 if (!request_cnt || !cnt)
1699 return 0; 1709 return 0;
1700 1710
1701 return bpf_prog_array_copy_to_user(array, prog_ids, request_cnt); 1711 /* this function is called under trace/bpf_trace.c: bpf_event_mutex */
1712 prog = rcu_dereference_check(array, 1)->progs;
1713 return bpf_prog_array_copy_core(prog, prog_ids, request_cnt) ? -ENOSPC
1714 : 0;
1702} 1715}
1703 1716
1704static void bpf_prog_free_deferred(struct work_struct *work) 1717static void bpf_prog_free_deferred(struct work_struct *work)
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 8dd9210d7db7..a3b21385e947 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -1442,9 +1442,6 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
1442 attr->value_size != 4 || attr->map_flags & ~SOCK_CREATE_FLAG_MASK) 1442 attr->value_size != 4 || attr->map_flags & ~SOCK_CREATE_FLAG_MASK)
1443 return ERR_PTR(-EINVAL); 1443 return ERR_PTR(-EINVAL);
1444 1444
1445 if (attr->value_size > KMALLOC_MAX_SIZE)
1446 return ERR_PTR(-E2BIG);
1447
1448 err = bpf_tcp_ulp_register(); 1445 err = bpf_tcp_ulp_register();
1449 if (err && err != -EEXIST) 1446 if (err && err != -EEXIST)
1450 return ERR_PTR(err); 1447 return ERR_PTR(err);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index d88e96d4e12c..56ba0f2a01db 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -977,6 +977,7 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info)
977{ 977{
978 struct perf_event_query_bpf __user *uquery = info; 978 struct perf_event_query_bpf __user *uquery = info;
979 struct perf_event_query_bpf query = {}; 979 struct perf_event_query_bpf query = {};
980 u32 *ids, prog_cnt, ids_len;
980 int ret; 981 int ret;
981 982
982 if (!capable(CAP_SYS_ADMIN)) 983 if (!capable(CAP_SYS_ADMIN))
@@ -985,16 +986,32 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info)
985 return -EINVAL; 986 return -EINVAL;
986 if (copy_from_user(&query, uquery, sizeof(query))) 987 if (copy_from_user(&query, uquery, sizeof(query)))
987 return -EFAULT; 988 return -EFAULT;
988 if (query.ids_len > BPF_TRACE_MAX_PROGS) 989
990 ids_len = query.ids_len;
991 if (ids_len > BPF_TRACE_MAX_PROGS)
989 return -E2BIG; 992 return -E2BIG;
993 ids = kcalloc(ids_len, sizeof(u32), GFP_USER | __GFP_NOWARN);
994 if (!ids)
995 return -ENOMEM;
996 /*
997 * The above kcalloc returns ZERO_SIZE_PTR when ids_len = 0, which
998 * is required when user only wants to check for uquery->prog_cnt.
999 * There is no need to check for it since the case is handled
1000 * gracefully in bpf_prog_array_copy_info.
1001 */
990 1002
991 mutex_lock(&bpf_event_mutex); 1003 mutex_lock(&bpf_event_mutex);
992 ret = bpf_prog_array_copy_info(event->tp_event->prog_array, 1004 ret = bpf_prog_array_copy_info(event->tp_event->prog_array,
993 uquery->ids, 1005 ids,
994 query.ids_len, 1006 ids_len,
995 &uquery->prog_cnt); 1007 &prog_cnt);
996 mutex_unlock(&bpf_event_mutex); 1008 mutex_unlock(&bpf_event_mutex);
997 1009
1010 if (copy_to_user(&uquery->prog_cnt, &prog_cnt, sizeof(prog_cnt)) ||
1011 copy_to_user(uquery->ids, ids, ids_len * sizeof(u32)))
1012 ret = -EFAULT;
1013
1014 kfree(ids);
998 return ret; 1015 return ret;
999} 1016}
1000 1017
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index 032e0fe45940..28a4c3490359 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1825,13 +1825,14 @@ static int compat_table_info(const struct ebt_table_info *info,
1825{ 1825{
1826 unsigned int size = info->entries_size; 1826 unsigned int size = info->entries_size;
1827 const void *entries = info->entries; 1827 const void *entries = info->entries;
1828 int ret;
1829 1828
1830 newinfo->entries_size = size; 1829 newinfo->entries_size = size;
1831 1830 if (info->nentries) {
1832 ret = xt_compat_init_offsets(NFPROTO_BRIDGE, info->nentries); 1831 int ret = xt_compat_init_offsets(NFPROTO_BRIDGE,
1833 if (ret) 1832 info->nentries);
1834 return ret; 1833 if (ret)
1834 return ret;
1835 }
1835 1836
1836 return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info, 1837 return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info,
1837 entries, newinfo); 1838 entries, newinfo);
diff --git a/net/ife/ife.c b/net/ife/ife.c
index 7d1ec76e7f43..13bbf8cb6a39 100644
--- a/net/ife/ife.c
+++ b/net/ife/ife.c
@@ -69,6 +69,9 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)
69 int total_pull; 69 int total_pull;
70 u16 ifehdrln; 70 u16 ifehdrln;
71 71
72 if (!pskb_may_pull(skb, skb->dev->hard_header_len + IFE_METAHDRLEN))
73 return NULL;
74
72 ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len); 75 ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len);
73 ifehdrln = ntohs(ifehdr->metalen); 76 ifehdrln = ntohs(ifehdr->metalen);
74 total_pull = skb->dev->hard_header_len + ifehdrln; 77 total_pull = skb->dev->hard_header_len + ifehdrln;
@@ -92,12 +95,43 @@ struct meta_tlvhdr {
92 __be16 len; 95 __be16 len;
93}; 96};
94 97
98static bool __ife_tlv_meta_valid(const unsigned char *skbdata,
99 const unsigned char *ifehdr_end)
100{
101 const struct meta_tlvhdr *tlv;
102 u16 tlvlen;
103
104 if (unlikely(skbdata + sizeof(*tlv) > ifehdr_end))
105 return false;
106
107 tlv = (const struct meta_tlvhdr *)skbdata;
108 tlvlen = ntohs(tlv->len);
109
110 /* tlv length field is inc header, check on minimum */
111 if (tlvlen < NLA_HDRLEN)
112 return false;
113
114 /* overflow by NLA_ALIGN check */
115 if (NLA_ALIGN(tlvlen) < tlvlen)
116 return false;
117
118 if (unlikely(skbdata + NLA_ALIGN(tlvlen) > ifehdr_end))
119 return false;
120
121 return true;
122}
123
95/* Caller takes care of presenting data in network order 124/* Caller takes care of presenting data in network order
96 */ 125 */
97void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen) 126void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
127 u16 *dlen, u16 *totlen)
98{ 128{
99 struct meta_tlvhdr *tlv = (struct meta_tlvhdr *) skbdata; 129 struct meta_tlvhdr *tlv;
130
131 if (!__ife_tlv_meta_valid(skbdata, ifehdr_end))
132 return NULL;
100 133
134 tlv = (struct meta_tlvhdr *)skbdata;
101 *dlen = ntohs(tlv->len) - NLA_HDRLEN; 135 *dlen = ntohs(tlv->len) - NLA_HDRLEN;
102 *attrtype = ntohs(tlv->type); 136 *attrtype = ntohs(tlv->type);
103 137
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 367def6ddeda..e51c644484dc 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3868,11 +3868,8 @@ const u8 *tcp_parse_md5sig_option(const struct tcphdr *th)
3868 int length = (th->doff << 2) - sizeof(*th); 3868 int length = (th->doff << 2) - sizeof(*th);
3869 const u8 *ptr = (const u8 *)(th + 1); 3869 const u8 *ptr = (const u8 *)(th + 1);
3870 3870
3871 /* If the TCP option is too short, we can short cut */ 3871 /* If not enough data remaining, we can short cut */
3872 if (length < TCPOLEN_MD5SIG) 3872 while (length >= TCPOLEN_MD5SIG) {
3873 return NULL;
3874
3875 while (length > 0) {
3876 int opcode = *ptr++; 3873 int opcode = *ptr++;
3877 int opsize; 3874 int opsize;
3878 3875
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index ccbfa83e4bb0..ce77bcc2490c 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -48,6 +48,34 @@ config NFT_CHAIN_ROUTE_IPV6
48 fields such as the source, destination, flowlabel, hop-limit and 48 fields such as the source, destination, flowlabel, hop-limit and
49 the packet mark. 49 the packet mark.
50 50
51if NF_NAT_IPV6
52
53config NFT_CHAIN_NAT_IPV6
54 tristate "IPv6 nf_tables nat chain support"
55 help
56 This option enables the "nat" chain for IPv6 in nf_tables. This
57 chain type is used to perform Network Address Translation (NAT)
58 packet transformations such as the source, destination address and
59 source and destination ports.
60
61config NFT_MASQ_IPV6
62 tristate "IPv6 masquerade support for nf_tables"
63 depends on NFT_MASQ
64 select NF_NAT_MASQUERADE_IPV6
65 help
66 This is the expression that provides IPv4 masquerading support for
67 nf_tables.
68
69config NFT_REDIR_IPV6
70 tristate "IPv6 redirect support for nf_tables"
71 depends on NFT_REDIR
72 select NF_NAT_REDIRECT
73 help
74 This is the expression that provides IPv4 redirect support for
75 nf_tables.
76
77endif # NF_NAT_IPV6
78
51config NFT_REJECT_IPV6 79config NFT_REJECT_IPV6
52 select NF_REJECT_IPV6 80 select NF_REJECT_IPV6
53 default NFT_REJECT 81 default NFT_REJECT
@@ -107,39 +135,12 @@ config NF_NAT_IPV6
107 135
108if NF_NAT_IPV6 136if NF_NAT_IPV6
109 137
110config NFT_CHAIN_NAT_IPV6
111 depends on NF_TABLES_IPV6
112 tristate "IPv6 nf_tables nat chain support"
113 help
114 This option enables the "nat" chain for IPv6 in nf_tables. This
115 chain type is used to perform Network Address Translation (NAT)
116 packet transformations such as the source, destination address and
117 source and destination ports.
118
119config NF_NAT_MASQUERADE_IPV6 138config NF_NAT_MASQUERADE_IPV6
120 tristate "IPv6 masquerade support" 139 tristate "IPv6 masquerade support"
121 help 140 help
122 This is the kernel functionality to provide NAT in the masquerade 141 This is the kernel functionality to provide NAT in the masquerade
123 flavour (automatic source address selection) for IPv6. 142 flavour (automatic source address selection) for IPv6.
124 143
125config NFT_MASQ_IPV6
126 tristate "IPv6 masquerade support for nf_tables"
127 depends on NF_TABLES_IPV6
128 depends on NFT_MASQ
129 select NF_NAT_MASQUERADE_IPV6
130 help
131 This is the expression that provides IPv4 masquerading support for
132 nf_tables.
133
134config NFT_REDIR_IPV6
135 tristate "IPv6 redirect support for nf_tables"
136 depends on NF_TABLES_IPV6
137 depends on NFT_REDIR
138 select NF_NAT_REDIRECT
139 help
140 This is the expression that provides IPv4 redirect support for
141 nf_tables.
142
143endif # NF_NAT_IPV6 144endif # NF_NAT_IPV6
144 145
145config IP6_NF_IPTABLES 146config IP6_NF_IPTABLES
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 49b954d6d0fa..cde7d8251377 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3975,6 +3975,7 @@ void rt6_mtu_change(struct net_device *dev, unsigned int mtu)
3975 3975
3976static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { 3976static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
3977 [RTA_GATEWAY] = { .len = sizeof(struct in6_addr) }, 3977 [RTA_GATEWAY] = { .len = sizeof(struct in6_addr) },
3978 [RTA_PREFSRC] = { .len = sizeof(struct in6_addr) },
3978 [RTA_OIF] = { .type = NLA_U32 }, 3979 [RTA_OIF] = { .type = NLA_U32 },
3979 [RTA_IIF] = { .type = NLA_U32 }, 3980 [RTA_IIF] = { .type = NLA_U32 },
3980 [RTA_PRIORITY] = { .type = NLA_U32 }, 3981 [RTA_PRIORITY] = { .type = NLA_U32 },
@@ -3986,6 +3987,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
3986 [RTA_EXPIRES] = { .type = NLA_U32 }, 3987 [RTA_EXPIRES] = { .type = NLA_U32 },
3987 [RTA_UID] = { .type = NLA_U32 }, 3988 [RTA_UID] = { .type = NLA_U32 },
3988 [RTA_MARK] = { .type = NLA_U32 }, 3989 [RTA_MARK] = { .type = NLA_U32 },
3990 [RTA_TABLE] = { .type = NLA_U32 },
3989}; 3991};
3990 3992
3991static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh, 3993static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index f343e6f0fc95..5fe139484919 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -136,7 +136,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
136 isrh->nexthdr = proto; 136 isrh->nexthdr = proto;
137 137
138 hdr->daddr = isrh->segments[isrh->first_segment]; 138 hdr->daddr = isrh->segments[isrh->first_segment];
139 set_tun_src(net, ip6_dst_idev(dst)->dev, &hdr->daddr, &hdr->saddr); 139 set_tun_src(net, dst->dev, &hdr->daddr, &hdr->saddr);
140 140
141#ifdef CONFIG_IPV6_SEG6_HMAC 141#ifdef CONFIG_IPV6_SEG6_HMAC
142 if (sr_has_hmac(isrh)) { 142 if (sr_has_hmac(isrh)) {
diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c
index b8f9d45bfeb1..7f1e842ef05a 100644
--- a/net/l2tp/l2tp_debugfs.c
+++ b/net/l2tp/l2tp_debugfs.c
@@ -106,8 +106,11 @@ static void l2tp_dfs_seq_stop(struct seq_file *p, void *v)
106 return; 106 return;
107 107
108 /* Drop reference taken by last invocation of l2tp_dfs_next_tunnel() */ 108 /* Drop reference taken by last invocation of l2tp_dfs_next_tunnel() */
109 if (pd->tunnel) 109 if (pd->tunnel) {
110 l2tp_tunnel_dec_refcount(pd->tunnel); 110 l2tp_tunnel_dec_refcount(pd->tunnel);
111 pd->tunnel = NULL;
112 pd->session = NULL;
113 }
111} 114}
112 115
113static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v) 116static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v)
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 7d0c963680e6..1fd9e145076a 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -619,6 +619,13 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
619 lock_sock(sk); 619 lock_sock(sk);
620 620
621 error = -EINVAL; 621 error = -EINVAL;
622
623 if (sockaddr_len != sizeof(struct sockaddr_pppol2tp) &&
624 sockaddr_len != sizeof(struct sockaddr_pppol2tpv3) &&
625 sockaddr_len != sizeof(struct sockaddr_pppol2tpin6) &&
626 sockaddr_len != sizeof(struct sockaddr_pppol2tpv3in6))
627 goto end;
628
622 if (sp->sa_protocol != PX_PROTO_OL2TP) 629 if (sp->sa_protocol != PX_PROTO_OL2TP)
623 goto end; 630 goto end;
624 631
@@ -1618,8 +1625,11 @@ static void pppol2tp_seq_stop(struct seq_file *p, void *v)
1618 return; 1625 return;
1619 1626
1620 /* Drop reference taken by last invocation of pppol2tp_next_tunnel() */ 1627 /* Drop reference taken by last invocation of pppol2tp_next_tunnel() */
1621 if (pd->tunnel) 1628 if (pd->tunnel) {
1622 l2tp_tunnel_dec_refcount(pd->tunnel); 1629 l2tp_tunnel_dec_refcount(pd->tunnel);
1630 pd->tunnel = NULL;
1631 pd->session = NULL;
1632 }
1623} 1633}
1624 1634
1625static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v) 1635static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 6d29b2b94e84..cb80ebb38311 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -189,7 +189,6 @@ static int llc_ui_release(struct socket *sock)
189{ 189{
190 struct sock *sk = sock->sk; 190 struct sock *sk = sock->sk;
191 struct llc_sock *llc; 191 struct llc_sock *llc;
192 struct llc_sap *sap;
193 192
194 if (unlikely(sk == NULL)) 193 if (unlikely(sk == NULL))
195 goto out; 194 goto out;
@@ -200,15 +199,19 @@ static int llc_ui_release(struct socket *sock)
200 llc->laddr.lsap, llc->daddr.lsap); 199 llc->laddr.lsap, llc->daddr.lsap);
201 if (!llc_send_disc(sk)) 200 if (!llc_send_disc(sk))
202 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); 201 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
203 sap = llc->sap; 202 if (!sock_flag(sk, SOCK_ZAPPED)) {
204 /* Hold this for release_sock(), so that llc_backlog_rcv() could still 203 struct llc_sap *sap = llc->sap;
205 * use it. 204
206 */ 205 /* Hold this for release_sock(), so that llc_backlog_rcv()
207 llc_sap_hold(sap); 206 * could still use it.
208 if (!sock_flag(sk, SOCK_ZAPPED)) 207 */
208 llc_sap_hold(sap);
209 llc_sap_remove_socket(llc->sap, sk); 209 llc_sap_remove_socket(llc->sap, sk);
210 release_sock(sk); 210 release_sock(sk);
211 llc_sap_put(sap); 211 llc_sap_put(sap);
212 } else {
213 release_sock(sk);
214 }
212 if (llc->dev) 215 if (llc->dev)
213 dev_put(llc->dev); 216 dev_put(llc->dev);
214 sock_put(sk); 217 sock_put(sk);
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
index 163121192aca..4d78375f9872 100644
--- a/net/llc/llc_c_ac.c
+++ b/net/llc/llc_c_ac.c
@@ -1099,14 +1099,7 @@ int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1099 1099
1100int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb) 1100int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1101{ 1101{
1102 struct llc_sock *llc = llc_sk(sk); 1102 llc_sk_stop_all_timers(sk, false);
1103
1104 del_timer(&llc->pf_cycle_timer.timer);
1105 del_timer(&llc->ack_timer.timer);
1106 del_timer(&llc->rej_sent_timer.timer);
1107 del_timer(&llc->busy_state_timer.timer);
1108 llc->ack_must_be_send = 0;
1109 llc->ack_pf = 0;
1110 return 0; 1103 return 0;
1111} 1104}
1112 1105
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index 110e32bcb399..c0ac522b48a1 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -961,6 +961,26 @@ out:
961 return sk; 961 return sk;
962} 962}
963 963
964void llc_sk_stop_all_timers(struct sock *sk, bool sync)
965{
966 struct llc_sock *llc = llc_sk(sk);
967
968 if (sync) {
969 del_timer_sync(&llc->pf_cycle_timer.timer);
970 del_timer_sync(&llc->ack_timer.timer);
971 del_timer_sync(&llc->rej_sent_timer.timer);
972 del_timer_sync(&llc->busy_state_timer.timer);
973 } else {
974 del_timer(&llc->pf_cycle_timer.timer);
975 del_timer(&llc->ack_timer.timer);
976 del_timer(&llc->rej_sent_timer.timer);
977 del_timer(&llc->busy_state_timer.timer);
978 }
979
980 llc->ack_must_be_send = 0;
981 llc->ack_pf = 0;
982}
983
964/** 984/**
965 * llc_sk_free - Frees a LLC socket 985 * llc_sk_free - Frees a LLC socket
966 * @sk - socket to free 986 * @sk - socket to free
@@ -973,7 +993,7 @@ void llc_sk_free(struct sock *sk)
973 993
974 llc->state = LLC_CONN_OUT_OF_SVC; 994 llc->state = LLC_CONN_OUT_OF_SVC;
975 /* Stop all (possibly) running timers */ 995 /* Stop all (possibly) running timers */
976 llc_conn_ac_stop_all_timers(sk, NULL); 996 llc_sk_stop_all_timers(sk, true);
977#ifdef DEBUG_LLC_CONN_ALLOC 997#ifdef DEBUG_LLC_CONN_ALLOC
978 printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __func__, 998 printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __func__,
979 skb_queue_len(&llc->pdu_unack_q), 999 skb_queue_len(&llc->pdu_unack_q),
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 704b3832dbad..44d8a55e9721 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -594,6 +594,7 @@ config NFT_QUOTA
594config NFT_REJECT 594config NFT_REJECT
595 default m if NETFILTER_ADVANCED=n 595 default m if NETFILTER_ADVANCED=n
596 tristate "Netfilter nf_tables reject support" 596 tristate "Netfilter nf_tables reject support"
597 depends on !NF_TABLES_INET || (IPV6!=m || m)
597 help 598 help
598 This option adds the "reject" expression that you can use to 599 This option adds the "reject" expression that you can use to
599 explicitly deny and notify via TCP reset/ICMP informational errors 600 explicitly deny and notify via TCP reset/ICMP informational errors
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 5ebde4b15810..f36098887ad0 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -2384,11 +2384,7 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2384 strlcpy(cfg.mcast_ifn, dm->mcast_ifn, 2384 strlcpy(cfg.mcast_ifn, dm->mcast_ifn,
2385 sizeof(cfg.mcast_ifn)); 2385 sizeof(cfg.mcast_ifn));
2386 cfg.syncid = dm->syncid; 2386 cfg.syncid = dm->syncid;
2387 rtnl_lock();
2388 mutex_lock(&ipvs->sync_mutex);
2389 ret = start_sync_thread(ipvs, &cfg, dm->state); 2387 ret = start_sync_thread(ipvs, &cfg, dm->state);
2390 mutex_unlock(&ipvs->sync_mutex);
2391 rtnl_unlock();
2392 } else { 2388 } else {
2393 mutex_lock(&ipvs->sync_mutex); 2389 mutex_lock(&ipvs->sync_mutex);
2394 ret = stop_sync_thread(ipvs, dm->state); 2390 ret = stop_sync_thread(ipvs, dm->state);
@@ -3481,12 +3477,8 @@ static int ip_vs_genl_new_daemon(struct netns_ipvs *ipvs, struct nlattr **attrs)
3481 if (ipvs->mixed_address_family_dests > 0) 3477 if (ipvs->mixed_address_family_dests > 0)
3482 return -EINVAL; 3478 return -EINVAL;
3483 3479
3484 rtnl_lock();
3485 mutex_lock(&ipvs->sync_mutex);
3486 ret = start_sync_thread(ipvs, &c, 3480 ret = start_sync_thread(ipvs, &c,
3487 nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE])); 3481 nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]));
3488 mutex_unlock(&ipvs->sync_mutex);
3489 rtnl_unlock();
3490 return ret; 3482 return ret;
3491} 3483}
3492 3484
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index fbaf3bd05b2e..001501e25625 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -49,6 +49,7 @@
49#include <linux/kthread.h> 49#include <linux/kthread.h>
50#include <linux/wait.h> 50#include <linux/wait.h>
51#include <linux/kernel.h> 51#include <linux/kernel.h>
52#include <linux/sched/signal.h>
52 53
53#include <asm/unaligned.h> /* Used for ntoh_seq and hton_seq */ 54#include <asm/unaligned.h> /* Used for ntoh_seq and hton_seq */
54 55
@@ -1360,15 +1361,9 @@ static void set_mcast_pmtudisc(struct sock *sk, int val)
1360/* 1361/*
1361 * Specifiy default interface for outgoing multicasts 1362 * Specifiy default interface for outgoing multicasts
1362 */ 1363 */
1363static int set_mcast_if(struct sock *sk, char *ifname) 1364static int set_mcast_if(struct sock *sk, struct net_device *dev)
1364{ 1365{
1365 struct net_device *dev;
1366 struct inet_sock *inet = inet_sk(sk); 1366 struct inet_sock *inet = inet_sk(sk);
1367 struct net *net = sock_net(sk);
1368
1369 dev = __dev_get_by_name(net, ifname);
1370 if (!dev)
1371 return -ENODEV;
1372 1367
1373 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if) 1368 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if)
1374 return -EINVAL; 1369 return -EINVAL;
@@ -1396,19 +1391,14 @@ static int set_mcast_if(struct sock *sk, char *ifname)
1396 * in the in_addr structure passed in as a parameter. 1391 * in the in_addr structure passed in as a parameter.
1397 */ 1392 */
1398static int 1393static int
1399join_mcast_group(struct sock *sk, struct in_addr *addr, char *ifname) 1394join_mcast_group(struct sock *sk, struct in_addr *addr, struct net_device *dev)
1400{ 1395{
1401 struct net *net = sock_net(sk);
1402 struct ip_mreqn mreq; 1396 struct ip_mreqn mreq;
1403 struct net_device *dev;
1404 int ret; 1397 int ret;
1405 1398
1406 memset(&mreq, 0, sizeof(mreq)); 1399 memset(&mreq, 0, sizeof(mreq));
1407 memcpy(&mreq.imr_multiaddr, addr, sizeof(struct in_addr)); 1400 memcpy(&mreq.imr_multiaddr, addr, sizeof(struct in_addr));
1408 1401
1409 dev = __dev_get_by_name(net, ifname);
1410 if (!dev)
1411 return -ENODEV;
1412 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if) 1402 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if)
1413 return -EINVAL; 1403 return -EINVAL;
1414 1404
@@ -1423,15 +1413,10 @@ join_mcast_group(struct sock *sk, struct in_addr *addr, char *ifname)
1423 1413
1424#ifdef CONFIG_IP_VS_IPV6 1414#ifdef CONFIG_IP_VS_IPV6
1425static int join_mcast_group6(struct sock *sk, struct in6_addr *addr, 1415static int join_mcast_group6(struct sock *sk, struct in6_addr *addr,
1426 char *ifname) 1416 struct net_device *dev)
1427{ 1417{
1428 struct net *net = sock_net(sk);
1429 struct net_device *dev;
1430 int ret; 1418 int ret;
1431 1419
1432 dev = __dev_get_by_name(net, ifname);
1433 if (!dev)
1434 return -ENODEV;
1435 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if) 1420 if (sk->sk_bound_dev_if && dev->ifindex != sk->sk_bound_dev_if)
1436 return -EINVAL; 1421 return -EINVAL;
1437 1422
@@ -1443,24 +1428,18 @@ static int join_mcast_group6(struct sock *sk, struct in6_addr *addr,
1443} 1428}
1444#endif 1429#endif
1445 1430
1446static int bind_mcastif_addr(struct socket *sock, char *ifname) 1431static int bind_mcastif_addr(struct socket *sock, struct net_device *dev)
1447{ 1432{
1448 struct net *net = sock_net(sock->sk);
1449 struct net_device *dev;
1450 __be32 addr; 1433 __be32 addr;
1451 struct sockaddr_in sin; 1434 struct sockaddr_in sin;
1452 1435
1453 dev = __dev_get_by_name(net, ifname);
1454 if (!dev)
1455 return -ENODEV;
1456
1457 addr = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE); 1436 addr = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE);
1458 if (!addr) 1437 if (!addr)
1459 pr_err("You probably need to specify IP address on " 1438 pr_err("You probably need to specify IP address on "
1460 "multicast interface.\n"); 1439 "multicast interface.\n");
1461 1440
1462 IP_VS_DBG(7, "binding socket with (%s) %pI4\n", 1441 IP_VS_DBG(7, "binding socket with (%s) %pI4\n",
1463 ifname, &addr); 1442 dev->name, &addr);
1464 1443
1465 /* Now bind the socket with the address of multicast interface */ 1444 /* Now bind the socket with the address of multicast interface */
1466 sin.sin_family = AF_INET; 1445 sin.sin_family = AF_INET;
@@ -1493,7 +1472,8 @@ static void get_mcast_sockaddr(union ipvs_sockaddr *sa, int *salen,
1493/* 1472/*
1494 * Set up sending multicast socket over UDP 1473 * Set up sending multicast socket over UDP
1495 */ 1474 */
1496static struct socket *make_send_sock(struct netns_ipvs *ipvs, int id) 1475static int make_send_sock(struct netns_ipvs *ipvs, int id,
1476 struct net_device *dev, struct socket **sock_ret)
1497{ 1477{
1498 /* multicast addr */ 1478 /* multicast addr */
1499 union ipvs_sockaddr mcast_addr; 1479 union ipvs_sockaddr mcast_addr;
@@ -1505,9 +1485,10 @@ static struct socket *make_send_sock(struct netns_ipvs *ipvs, int id)
1505 IPPROTO_UDP, &sock); 1485 IPPROTO_UDP, &sock);
1506 if (result < 0) { 1486 if (result < 0) {
1507 pr_err("Error during creation of socket; terminating\n"); 1487 pr_err("Error during creation of socket; terminating\n");
1508 return ERR_PTR(result); 1488 goto error;
1509 } 1489 }
1510 result = set_mcast_if(sock->sk, ipvs->mcfg.mcast_ifn); 1490 *sock_ret = sock;
1491 result = set_mcast_if(sock->sk, dev);
1511 if (result < 0) { 1492 if (result < 0) {
1512 pr_err("Error setting outbound mcast interface\n"); 1493 pr_err("Error setting outbound mcast interface\n");
1513 goto error; 1494 goto error;
@@ -1522,7 +1503,7 @@ static struct socket *make_send_sock(struct netns_ipvs *ipvs, int id)
1522 set_sock_size(sock->sk, 1, result); 1503 set_sock_size(sock->sk, 1, result);
1523 1504
1524 if (AF_INET == ipvs->mcfg.mcast_af) 1505 if (AF_INET == ipvs->mcfg.mcast_af)
1525 result = bind_mcastif_addr(sock, ipvs->mcfg.mcast_ifn); 1506 result = bind_mcastif_addr(sock, dev);
1526 else 1507 else
1527 result = 0; 1508 result = 0;
1528 if (result < 0) { 1509 if (result < 0) {
@@ -1538,19 +1519,18 @@ static struct socket *make_send_sock(struct netns_ipvs *ipvs, int id)
1538 goto error; 1519 goto error;
1539 } 1520 }
1540 1521
1541 return sock; 1522 return 0;
1542 1523
1543error: 1524error:
1544 sock_release(sock); 1525 return result;
1545 return ERR_PTR(result);
1546} 1526}
1547 1527
1548 1528
1549/* 1529/*
1550 * Set up receiving multicast socket over UDP 1530 * Set up receiving multicast socket over UDP
1551 */ 1531 */
1552static struct socket *make_receive_sock(struct netns_ipvs *ipvs, int id, 1532static int make_receive_sock(struct netns_ipvs *ipvs, int id,
1553 int ifindex) 1533 struct net_device *dev, struct socket **sock_ret)
1554{ 1534{
1555 /* multicast addr */ 1535 /* multicast addr */
1556 union ipvs_sockaddr mcast_addr; 1536 union ipvs_sockaddr mcast_addr;
@@ -1562,8 +1542,9 @@ static struct socket *make_receive_sock(struct netns_ipvs *ipvs, int id,
1562 IPPROTO_UDP, &sock); 1542 IPPROTO_UDP, &sock);
1563 if (result < 0) { 1543 if (result < 0) {
1564 pr_err("Error during creation of socket; terminating\n"); 1544 pr_err("Error during creation of socket; terminating\n");
1565 return ERR_PTR(result); 1545 goto error;
1566 } 1546 }
1547 *sock_ret = sock;
1567 /* it is equivalent to the REUSEADDR option in user-space */ 1548 /* it is equivalent to the REUSEADDR option in user-space */
1568 sock->sk->sk_reuse = SK_CAN_REUSE; 1549 sock->sk->sk_reuse = SK_CAN_REUSE;
1569 result = sysctl_sync_sock_size(ipvs); 1550 result = sysctl_sync_sock_size(ipvs);
@@ -1571,7 +1552,7 @@ static struct socket *make_receive_sock(struct netns_ipvs *ipvs, int id,
1571 set_sock_size(sock->sk, 0, result); 1552 set_sock_size(sock->sk, 0, result);
1572 1553
1573 get_mcast_sockaddr(&mcast_addr, &salen, &ipvs->bcfg, id); 1554 get_mcast_sockaddr(&mcast_addr, &salen, &ipvs->bcfg, id);
1574 sock->sk->sk_bound_dev_if = ifindex; 1555 sock->sk->sk_bound_dev_if = dev->ifindex;
1575 result = sock->ops->bind(sock, (struct sockaddr *)&mcast_addr, salen); 1556 result = sock->ops->bind(sock, (struct sockaddr *)&mcast_addr, salen);
1576 if (result < 0) { 1557 if (result < 0) {
1577 pr_err("Error binding to the multicast addr\n"); 1558 pr_err("Error binding to the multicast addr\n");
@@ -1582,21 +1563,20 @@ static struct socket *make_receive_sock(struct netns_ipvs *ipvs, int id,
1582#ifdef CONFIG_IP_VS_IPV6 1563#ifdef CONFIG_IP_VS_IPV6
1583 if (ipvs->bcfg.mcast_af == AF_INET6) 1564 if (ipvs->bcfg.mcast_af == AF_INET6)
1584 result = join_mcast_group6(sock->sk, &mcast_addr.in6.sin6_addr, 1565 result = join_mcast_group6(sock->sk, &mcast_addr.in6.sin6_addr,
1585 ipvs->bcfg.mcast_ifn); 1566 dev);
1586 else 1567 else
1587#endif 1568#endif
1588 result = join_mcast_group(sock->sk, &mcast_addr.in.sin_addr, 1569 result = join_mcast_group(sock->sk, &mcast_addr.in.sin_addr,
1589 ipvs->bcfg.mcast_ifn); 1570 dev);
1590 if (result < 0) { 1571 if (result < 0) {
1591 pr_err("Error joining to the multicast group\n"); 1572 pr_err("Error joining to the multicast group\n");
1592 goto error; 1573 goto error;
1593 } 1574 }
1594 1575
1595 return sock; 1576 return 0;
1596 1577
1597error: 1578error:
1598 sock_release(sock); 1579 return result;
1599 return ERR_PTR(result);
1600} 1580}
1601 1581
1602 1582
@@ -1778,13 +1758,12 @@ static int sync_thread_backup(void *data)
1778int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c, 1758int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1779 int state) 1759 int state)
1780{ 1760{
1781 struct ip_vs_sync_thread_data *tinfo; 1761 struct ip_vs_sync_thread_data *tinfo = NULL;
1782 struct task_struct **array = NULL, *task; 1762 struct task_struct **array = NULL, *task;
1783 struct socket *sock;
1784 struct net_device *dev; 1763 struct net_device *dev;
1785 char *name; 1764 char *name;
1786 int (*threadfn)(void *data); 1765 int (*threadfn)(void *data);
1787 int id, count, hlen; 1766 int id = 0, count, hlen;
1788 int result = -ENOMEM; 1767 int result = -ENOMEM;
1789 u16 mtu, min_mtu; 1768 u16 mtu, min_mtu;
1790 1769
@@ -1792,6 +1771,18 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1792 IP_VS_DBG(7, "Each ip_vs_sync_conn entry needs %zd bytes\n", 1771 IP_VS_DBG(7, "Each ip_vs_sync_conn entry needs %zd bytes\n",
1793 sizeof(struct ip_vs_sync_conn_v0)); 1772 sizeof(struct ip_vs_sync_conn_v0));
1794 1773
1774 /* Do not hold one mutex and then to block on another */
1775 for (;;) {
1776 rtnl_lock();
1777 if (mutex_trylock(&ipvs->sync_mutex))
1778 break;
1779 rtnl_unlock();
1780 mutex_lock(&ipvs->sync_mutex);
1781 if (rtnl_trylock())
1782 break;
1783 mutex_unlock(&ipvs->sync_mutex);
1784 }
1785
1795 if (!ipvs->sync_state) { 1786 if (!ipvs->sync_state) {
1796 count = clamp(sysctl_sync_ports(ipvs), 1, IPVS_SYNC_PORTS_MAX); 1787 count = clamp(sysctl_sync_ports(ipvs), 1, IPVS_SYNC_PORTS_MAX);
1797 ipvs->threads_mask = count - 1; 1788 ipvs->threads_mask = count - 1;
@@ -1810,7 +1801,8 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1810 dev = __dev_get_by_name(ipvs->net, c->mcast_ifn); 1801 dev = __dev_get_by_name(ipvs->net, c->mcast_ifn);
1811 if (!dev) { 1802 if (!dev) {
1812 pr_err("Unknown mcast interface: %s\n", c->mcast_ifn); 1803 pr_err("Unknown mcast interface: %s\n", c->mcast_ifn);
1813 return -ENODEV; 1804 result = -ENODEV;
1805 goto out_early;
1814 } 1806 }
1815 hlen = (AF_INET6 == c->mcast_af) ? 1807 hlen = (AF_INET6 == c->mcast_af) ?
1816 sizeof(struct ipv6hdr) + sizeof(struct udphdr) : 1808 sizeof(struct ipv6hdr) + sizeof(struct udphdr) :
@@ -1827,26 +1819,30 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1827 c->sync_maxlen = mtu - hlen; 1819 c->sync_maxlen = mtu - hlen;
1828 1820
1829 if (state == IP_VS_STATE_MASTER) { 1821 if (state == IP_VS_STATE_MASTER) {
1822 result = -EEXIST;
1830 if (ipvs->ms) 1823 if (ipvs->ms)
1831 return -EEXIST; 1824 goto out_early;
1832 1825
1833 ipvs->mcfg = *c; 1826 ipvs->mcfg = *c;
1834 name = "ipvs-m:%d:%d"; 1827 name = "ipvs-m:%d:%d";
1835 threadfn = sync_thread_master; 1828 threadfn = sync_thread_master;
1836 } else if (state == IP_VS_STATE_BACKUP) { 1829 } else if (state == IP_VS_STATE_BACKUP) {
1830 result = -EEXIST;
1837 if (ipvs->backup_threads) 1831 if (ipvs->backup_threads)
1838 return -EEXIST; 1832 goto out_early;
1839 1833
1840 ipvs->bcfg = *c; 1834 ipvs->bcfg = *c;
1841 name = "ipvs-b:%d:%d"; 1835 name = "ipvs-b:%d:%d";
1842 threadfn = sync_thread_backup; 1836 threadfn = sync_thread_backup;
1843 } else { 1837 } else {
1844 return -EINVAL; 1838 result = -EINVAL;
1839 goto out_early;
1845 } 1840 }
1846 1841
1847 if (state == IP_VS_STATE_MASTER) { 1842 if (state == IP_VS_STATE_MASTER) {
1848 struct ipvs_master_sync_state *ms; 1843 struct ipvs_master_sync_state *ms;
1849 1844
1845 result = -ENOMEM;
1850 ipvs->ms = kcalloc(count, sizeof(ipvs->ms[0]), GFP_KERNEL); 1846 ipvs->ms = kcalloc(count, sizeof(ipvs->ms[0]), GFP_KERNEL);
1851 if (!ipvs->ms) 1847 if (!ipvs->ms)
1852 goto out; 1848 goto out;
@@ -1862,39 +1858,38 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1862 } else { 1858 } else {
1863 array = kcalloc(count, sizeof(struct task_struct *), 1859 array = kcalloc(count, sizeof(struct task_struct *),
1864 GFP_KERNEL); 1860 GFP_KERNEL);
1861 result = -ENOMEM;
1865 if (!array) 1862 if (!array)
1866 goto out; 1863 goto out;
1867 } 1864 }
1868 1865
1869 tinfo = NULL;
1870 for (id = 0; id < count; id++) { 1866 for (id = 0; id < count; id++) {
1871 if (state == IP_VS_STATE_MASTER) 1867 result = -ENOMEM;
1872 sock = make_send_sock(ipvs, id);
1873 else
1874 sock = make_receive_sock(ipvs, id, dev->ifindex);
1875 if (IS_ERR(sock)) {
1876 result = PTR_ERR(sock);
1877 goto outtinfo;
1878 }
1879 tinfo = kmalloc(sizeof(*tinfo), GFP_KERNEL); 1868 tinfo = kmalloc(sizeof(*tinfo), GFP_KERNEL);
1880 if (!tinfo) 1869 if (!tinfo)
1881 goto outsocket; 1870 goto out;
1882 tinfo->ipvs = ipvs; 1871 tinfo->ipvs = ipvs;
1883 tinfo->sock = sock; 1872 tinfo->sock = NULL;
1884 if (state == IP_VS_STATE_BACKUP) { 1873 if (state == IP_VS_STATE_BACKUP) {
1885 tinfo->buf = kmalloc(ipvs->bcfg.sync_maxlen, 1874 tinfo->buf = kmalloc(ipvs->bcfg.sync_maxlen,
1886 GFP_KERNEL); 1875 GFP_KERNEL);
1887 if (!tinfo->buf) 1876 if (!tinfo->buf)
1888 goto outtinfo; 1877 goto out;
1889 } else { 1878 } else {
1890 tinfo->buf = NULL; 1879 tinfo->buf = NULL;
1891 } 1880 }
1892 tinfo->id = id; 1881 tinfo->id = id;
1882 if (state == IP_VS_STATE_MASTER)
1883 result = make_send_sock(ipvs, id, dev, &tinfo->sock);
1884 else
1885 result = make_receive_sock(ipvs, id, dev, &tinfo->sock);
1886 if (result < 0)
1887 goto out;
1893 1888
1894 task = kthread_run(threadfn, tinfo, name, ipvs->gen, id); 1889 task = kthread_run(threadfn, tinfo, name, ipvs->gen, id);
1895 if (IS_ERR(task)) { 1890 if (IS_ERR(task)) {
1896 result = PTR_ERR(task); 1891 result = PTR_ERR(task);
1897 goto outtinfo; 1892 goto out;
1898 } 1893 }
1899 tinfo = NULL; 1894 tinfo = NULL;
1900 if (state == IP_VS_STATE_MASTER) 1895 if (state == IP_VS_STATE_MASTER)
@@ -1911,20 +1906,20 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1911 ipvs->sync_state |= state; 1906 ipvs->sync_state |= state;
1912 spin_unlock_bh(&ipvs->sync_buff_lock); 1907 spin_unlock_bh(&ipvs->sync_buff_lock);
1913 1908
1909 mutex_unlock(&ipvs->sync_mutex);
1910 rtnl_unlock();
1911
1914 /* increase the module use count */ 1912 /* increase the module use count */
1915 ip_vs_use_count_inc(); 1913 ip_vs_use_count_inc();
1916 1914
1917 return 0; 1915 return 0;
1918 1916
1919outsocket: 1917out:
1920 sock_release(sock); 1918 /* We do not need RTNL lock anymore, release it here so that
1921 1919 * sock_release below and in the kthreads can use rtnl_lock
1922outtinfo: 1920 * to leave the mcast group.
1923 if (tinfo) { 1921 */
1924 sock_release(tinfo->sock); 1922 rtnl_unlock();
1925 kfree(tinfo->buf);
1926 kfree(tinfo);
1927 }
1928 count = id; 1923 count = id;
1929 while (count-- > 0) { 1924 while (count-- > 0) {
1930 if (state == IP_VS_STATE_MASTER) 1925 if (state == IP_VS_STATE_MASTER)
@@ -1932,13 +1927,23 @@ outtinfo:
1932 else 1927 else
1933 kthread_stop(array[count]); 1928 kthread_stop(array[count]);
1934 } 1929 }
1935 kfree(array);
1936
1937out:
1938 if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) { 1930 if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) {
1939 kfree(ipvs->ms); 1931 kfree(ipvs->ms);
1940 ipvs->ms = NULL; 1932 ipvs->ms = NULL;
1941 } 1933 }
1934 mutex_unlock(&ipvs->sync_mutex);
1935 if (tinfo) {
1936 if (tinfo->sock)
1937 sock_release(tinfo->sock);
1938 kfree(tinfo->buf);
1939 kfree(tinfo);
1940 }
1941 kfree(array);
1942 return result;
1943
1944out_early:
1945 mutex_unlock(&ipvs->sync_mutex);
1946 rtnl_unlock();
1942 return result; 1947 return result;
1943} 1948}
1944 1949
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 8ef21d9f9a00..4b2b3d53acfc 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -252,7 +252,7 @@ static inline int expect_clash(const struct nf_conntrack_expect *a,
252static inline int expect_matches(const struct nf_conntrack_expect *a, 252static inline int expect_matches(const struct nf_conntrack_expect *a,
253 const struct nf_conntrack_expect *b) 253 const struct nf_conntrack_expect *b)
254{ 254{
255 return a->master == b->master && a->class == b->class && 255 return a->master == b->master &&
256 nf_ct_tuple_equal(&a->tuple, &b->tuple) && 256 nf_ct_tuple_equal(&a->tuple, &b->tuple) &&
257 nf_ct_tuple_mask_equal(&a->mask, &b->mask) && 257 nf_ct_tuple_mask_equal(&a->mask, &b->mask) &&
258 net_eq(nf_ct_net(a->master), nf_ct_net(b->master)) && 258 net_eq(nf_ct_net(a->master), nf_ct_net(b->master)) &&
@@ -421,6 +421,9 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
421 h = nf_ct_expect_dst_hash(net, &expect->tuple); 421 h = nf_ct_expect_dst_hash(net, &expect->tuple);
422 hlist_for_each_entry_safe(i, next, &nf_ct_expect_hash[h], hnode) { 422 hlist_for_each_entry_safe(i, next, &nf_ct_expect_hash[h], hnode) {
423 if (expect_matches(i, expect)) { 423 if (expect_matches(i, expect)) {
424 if (i->class != expect->class)
425 return -EALREADY;
426
424 if (nf_ct_remove_expect(i)) 427 if (nf_ct_remove_expect(i))
425 break; 428 break;
426 } else if (expect_clash(i, expect)) { 429 } else if (expect_clash(i, expect)) {
diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c
index 9fe0ddc333fb..277bbfe26478 100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -9,6 +9,7 @@
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 */ 10 */
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/kmemleak.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/mutex.h> 14#include <linux/mutex.h>
14#include <linux/rcupdate.h> 15#include <linux/rcupdate.h>
@@ -71,6 +72,7 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
71 rcu_read_unlock(); 72 rcu_read_unlock();
72 73
73 alloc = max(newlen, NF_CT_EXT_PREALLOC); 74 alloc = max(newlen, NF_CT_EXT_PREALLOC);
75 kmemleak_not_leak(old);
74 new = __krealloc(old, alloc, gfp); 76 new = __krealloc(old, alloc, gfp);
75 if (!new) 77 if (!new)
76 return NULL; 78 return NULL;
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 4dbb5bad4363..908e51e2dc2b 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -938,11 +938,19 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,
938 datalen, rtp_exp, rtcp_exp, 938 datalen, rtp_exp, rtcp_exp,
939 mediaoff, medialen, daddr); 939 mediaoff, medialen, daddr);
940 else { 940 else {
941 if (nf_ct_expect_related(rtp_exp) == 0) { 941 /* -EALREADY handling works around end-points that send
942 if (nf_ct_expect_related(rtcp_exp) != 0) 942 * SDP messages with identical port but different media type,
943 nf_ct_unexpect_related(rtp_exp); 943 * we pretend expectation was set up.
944 else 944 */
945 int errp = nf_ct_expect_related(rtp_exp);
946
947 if (errp == 0 || errp == -EALREADY) {
948 int errcp = nf_ct_expect_related(rtcp_exp);
949
950 if (errcp == 0 || errcp == -EALREADY)
945 ret = NF_ACCEPT; 951 ret = NF_ACCEPT;
952 else if (errp == 0)
953 nf_ct_unexpect_related(rtp_exp);
946 } 954 }
947 } 955 }
948 nf_ct_expect_put(rtcp_exp); 956 nf_ct_expect_put(rtcp_exp);
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 9134cc429ad4..04d4e3772584 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2361,41 +2361,46 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2361 } 2361 }
2362 2362
2363 if (nlh->nlmsg_flags & NLM_F_REPLACE) { 2363 if (nlh->nlmsg_flags & NLM_F_REPLACE) {
2364 if (nft_is_active_next(net, old_rule)) { 2364 if (!nft_is_active_next(net, old_rule)) {
2365 trans = nft_trans_rule_add(&ctx, NFT_MSG_DELRULE,
2366 old_rule);
2367 if (trans == NULL) {
2368 err = -ENOMEM;
2369 goto err2;
2370 }
2371 nft_deactivate_next(net, old_rule);
2372 chain->use--;
2373 list_add_tail_rcu(&rule->list, &old_rule->list);
2374 } else {
2375 err = -ENOENT; 2365 err = -ENOENT;
2376 goto err2; 2366 goto err2;
2377 } 2367 }
2378 } else if (nlh->nlmsg_flags & NLM_F_APPEND) 2368 trans = nft_trans_rule_add(&ctx, NFT_MSG_DELRULE,
2379 if (old_rule) 2369 old_rule);
2380 list_add_rcu(&rule->list, &old_rule->list); 2370 if (trans == NULL) {
2381 else 2371 err = -ENOMEM;
2382 list_add_tail_rcu(&rule->list, &chain->rules); 2372 goto err2;
2383 else { 2373 }
2384 if (old_rule) 2374 nft_deactivate_next(net, old_rule);
2385 list_add_tail_rcu(&rule->list, &old_rule->list); 2375 chain->use--;
2386 else
2387 list_add_rcu(&rule->list, &chain->rules);
2388 }
2389 2376
2390 if (nft_trans_rule_add(&ctx, NFT_MSG_NEWRULE, rule) == NULL) { 2377 if (nft_trans_rule_add(&ctx, NFT_MSG_NEWRULE, rule) == NULL) {
2391 err = -ENOMEM; 2378 err = -ENOMEM;
2392 goto err3; 2379 goto err2;
2380 }
2381
2382 list_add_tail_rcu(&rule->list, &old_rule->list);
2383 } else {
2384 if (nft_trans_rule_add(&ctx, NFT_MSG_NEWRULE, rule) == NULL) {
2385 err = -ENOMEM;
2386 goto err2;
2387 }
2388
2389 if (nlh->nlmsg_flags & NLM_F_APPEND) {
2390 if (old_rule)
2391 list_add_rcu(&rule->list, &old_rule->list);
2392 else
2393 list_add_tail_rcu(&rule->list, &chain->rules);
2394 } else {
2395 if (old_rule)
2396 list_add_tail_rcu(&rule->list, &old_rule->list);
2397 else
2398 list_add_rcu(&rule->list, &chain->rules);
2399 }
2393 } 2400 }
2394 chain->use++; 2401 chain->use++;
2395 return 0; 2402 return 0;
2396 2403
2397err3:
2398 list_del_rcu(&rule->list);
2399err2: 2404err2:
2400 nf_tables_rule_destroy(&ctx, rule); 2405 nf_tables_rule_destroy(&ctx, rule);
2401err1: 2406err1:
@@ -3207,18 +3212,20 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
3207 3212
3208 err = ops->init(set, &desc, nla); 3213 err = ops->init(set, &desc, nla);
3209 if (err < 0) 3214 if (err < 0)
3210 goto err2; 3215 goto err3;
3211 3216
3212 err = nft_trans_set_add(&ctx, NFT_MSG_NEWSET, set); 3217 err = nft_trans_set_add(&ctx, NFT_MSG_NEWSET, set);
3213 if (err < 0) 3218 if (err < 0)
3214 goto err3; 3219 goto err4;
3215 3220
3216 list_add_tail_rcu(&set->list, &table->sets); 3221 list_add_tail_rcu(&set->list, &table->sets);
3217 table->use++; 3222 table->use++;
3218 return 0; 3223 return 0;
3219 3224
3220err3: 3225err4:
3221 ops->destroy(set); 3226 ops->destroy(set);
3227err3:
3228 kfree(set->name);
3222err2: 3229err2:
3223 kvfree(set); 3230 kvfree(set);
3224err1: 3231err1:
@@ -5738,7 +5745,7 @@ static void nft_chain_commit_update(struct nft_trans *trans)
5738 struct nft_base_chain *basechain; 5745 struct nft_base_chain *basechain;
5739 5746
5740 if (nft_trans_chain_name(trans)) 5747 if (nft_trans_chain_name(trans))
5741 strcpy(trans->ctx.chain->name, nft_trans_chain_name(trans)); 5748 swap(trans->ctx.chain->name, nft_trans_chain_name(trans));
5742 5749
5743 if (!nft_is_base_chain(trans->ctx.chain)) 5750 if (!nft_is_base_chain(trans->ctx.chain))
5744 return; 5751 return;
diff --git a/net/netfilter/xt_connmark.c b/net/netfilter/xt_connmark.c
index 773da82190dc..94df000abb92 100644
--- a/net/netfilter/xt_connmark.c
+++ b/net/netfilter/xt_connmark.c
@@ -36,11 +36,10 @@ MODULE_ALIAS("ipt_connmark");
36MODULE_ALIAS("ip6t_connmark"); 36MODULE_ALIAS("ip6t_connmark");
37 37
38static unsigned int 38static unsigned int
39connmark_tg_shift(struct sk_buff *skb, 39connmark_tg_shift(struct sk_buff *skb, const struct xt_connmark_tginfo2 *info)
40 const struct xt_connmark_tginfo1 *info,
41 u8 shift_bits, u8 shift_dir)
42{ 40{
43 enum ip_conntrack_info ctinfo; 41 enum ip_conntrack_info ctinfo;
42 u_int32_t new_targetmark;
44 struct nf_conn *ct; 43 struct nf_conn *ct;
45 u_int32_t newmark; 44 u_int32_t newmark;
46 45
@@ -51,34 +50,39 @@ connmark_tg_shift(struct sk_buff *skb,
51 switch (info->mode) { 50 switch (info->mode) {
52 case XT_CONNMARK_SET: 51 case XT_CONNMARK_SET:
53 newmark = (ct->mark & ~info->ctmask) ^ info->ctmark; 52 newmark = (ct->mark & ~info->ctmask) ^ info->ctmark;
54 if (shift_dir == D_SHIFT_RIGHT) 53 if (info->shift_dir == D_SHIFT_RIGHT)
55 newmark >>= shift_bits; 54 newmark >>= info->shift_bits;
56 else 55 else
57 newmark <<= shift_bits; 56 newmark <<= info->shift_bits;
57
58 if (ct->mark != newmark) { 58 if (ct->mark != newmark) {
59 ct->mark = newmark; 59 ct->mark = newmark;
60 nf_conntrack_event_cache(IPCT_MARK, ct); 60 nf_conntrack_event_cache(IPCT_MARK, ct);
61 } 61 }
62 break; 62 break;
63 case XT_CONNMARK_SAVE: 63 case XT_CONNMARK_SAVE:
64 newmark = (ct->mark & ~info->ctmask) ^ 64 new_targetmark = (skb->mark & info->nfmask);
65 (skb->mark & info->nfmask); 65 if (info->shift_dir == D_SHIFT_RIGHT)
66 if (shift_dir == D_SHIFT_RIGHT) 66 new_targetmark >>= info->shift_bits;
67 newmark >>= shift_bits;
68 else 67 else
69 newmark <<= shift_bits; 68 new_targetmark <<= info->shift_bits;
69
70 newmark = (ct->mark & ~info->ctmask) ^
71 new_targetmark;
70 if (ct->mark != newmark) { 72 if (ct->mark != newmark) {
71 ct->mark = newmark; 73 ct->mark = newmark;
72 nf_conntrack_event_cache(IPCT_MARK, ct); 74 nf_conntrack_event_cache(IPCT_MARK, ct);
73 } 75 }
74 break; 76 break;
75 case XT_CONNMARK_RESTORE: 77 case XT_CONNMARK_RESTORE:
76 newmark = (skb->mark & ~info->nfmask) ^ 78 new_targetmark = (ct->mark & info->ctmask);
77 (ct->mark & info->ctmask); 79 if (info->shift_dir == D_SHIFT_RIGHT)
78 if (shift_dir == D_SHIFT_RIGHT) 80 new_targetmark >>= info->shift_bits;
79 newmark >>= shift_bits;
80 else 81 else
81 newmark <<= shift_bits; 82 new_targetmark <<= info->shift_bits;
83
84 newmark = (skb->mark & ~info->nfmask) ^
85 new_targetmark;
82 skb->mark = newmark; 86 skb->mark = newmark;
83 break; 87 break;
84 } 88 }
@@ -89,8 +93,14 @@ static unsigned int
89connmark_tg(struct sk_buff *skb, const struct xt_action_param *par) 93connmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
90{ 94{
91 const struct xt_connmark_tginfo1 *info = par->targinfo; 95 const struct xt_connmark_tginfo1 *info = par->targinfo;
92 96 const struct xt_connmark_tginfo2 info2 = {
93 return connmark_tg_shift(skb, info, 0, 0); 97 .ctmark = info->ctmark,
98 .ctmask = info->ctmask,
99 .nfmask = info->nfmask,
100 .mode = info->mode,
101 };
102
103 return connmark_tg_shift(skb, &info2);
94} 104}
95 105
96static unsigned int 106static unsigned int
@@ -98,8 +108,7 @@ connmark_tg_v2(struct sk_buff *skb, const struct xt_action_param *par)
98{ 108{
99 const struct xt_connmark_tginfo2 *info = par->targinfo; 109 const struct xt_connmark_tginfo2 *info = par->targinfo;
100 110
101 return connmark_tg_shift(skb, (const struct xt_connmark_tginfo1 *)info, 111 return connmark_tg_shift(skb, info);
102 info->shift_bits, info->shift_dir);
103} 112}
104 113
105static int connmark_tg_check(const struct xt_tgchk_param *par) 114static int connmark_tg_check(const struct xt_tgchk_param *par)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c31b0687396a..01f3515cada0 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -329,11 +329,11 @@ static void packet_pick_tx_queue(struct net_device *dev, struct sk_buff *skb)
329 skb_set_queue_mapping(skb, queue_index); 329 skb_set_queue_mapping(skb, queue_index);
330} 330}
331 331
332/* register_prot_hook must be invoked with the po->bind_lock held, 332/* __register_prot_hook must be invoked through register_prot_hook
333 * or from a context in which asynchronous accesses to the packet 333 * or from a context in which asynchronous accesses to the packet
334 * socket is not possible (packet_create()). 334 * socket is not possible (packet_create()).
335 */ 335 */
336static void register_prot_hook(struct sock *sk) 336static void __register_prot_hook(struct sock *sk)
337{ 337{
338 struct packet_sock *po = pkt_sk(sk); 338 struct packet_sock *po = pkt_sk(sk);
339 339
@@ -348,8 +348,13 @@ static void register_prot_hook(struct sock *sk)
348 } 348 }
349} 349}
350 350
351/* {,__}unregister_prot_hook() must be invoked with the po->bind_lock 351static void register_prot_hook(struct sock *sk)
352 * held. If the sync parameter is true, we will temporarily drop 352{
353 lockdep_assert_held_once(&pkt_sk(sk)->bind_lock);
354 __register_prot_hook(sk);
355}
356
357/* If the sync parameter is true, we will temporarily drop
353 * the po->bind_lock and do a synchronize_net to make sure no 358 * the po->bind_lock and do a synchronize_net to make sure no
354 * asynchronous packet processing paths still refer to the elements 359 * asynchronous packet processing paths still refer to the elements
355 * of po->prot_hook. If the sync parameter is false, it is the 360 * of po->prot_hook. If the sync parameter is false, it is the
@@ -359,6 +364,8 @@ static void __unregister_prot_hook(struct sock *sk, bool sync)
359{ 364{
360 struct packet_sock *po = pkt_sk(sk); 365 struct packet_sock *po = pkt_sk(sk);
361 366
367 lockdep_assert_held_once(&po->bind_lock);
368
362 po->running = 0; 369 po->running = 0;
363 370
364 if (po->fanout) 371 if (po->fanout)
@@ -3252,7 +3259,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
3252 3259
3253 if (proto) { 3260 if (proto) {
3254 po->prot_hook.type = proto; 3261 po->prot_hook.type = proto;
3255 register_prot_hook(sk); 3262 __register_prot_hook(sk);
3256 } 3263 }
3257 3264
3258 mutex_lock(&net->packet.sklist_lock); 3265 mutex_lock(&net->packet.sklist_lock);
@@ -3732,12 +3739,18 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3732 3739
3733 if (optlen != sizeof(val)) 3740 if (optlen != sizeof(val))
3734 return -EINVAL; 3741 return -EINVAL;
3735 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
3736 return -EBUSY;
3737 if (copy_from_user(&val, optval, sizeof(val))) 3742 if (copy_from_user(&val, optval, sizeof(val)))
3738 return -EFAULT; 3743 return -EFAULT;
3739 po->tp_loss = !!val; 3744
3740 return 0; 3745 lock_sock(sk);
3746 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
3747 ret = -EBUSY;
3748 } else {
3749 po->tp_loss = !!val;
3750 ret = 0;
3751 }
3752 release_sock(sk);
3753 return ret;
3741 } 3754 }
3742 case PACKET_AUXDATA: 3755 case PACKET_AUXDATA:
3743 { 3756 {
@@ -3748,7 +3761,9 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3748 if (copy_from_user(&val, optval, sizeof(val))) 3761 if (copy_from_user(&val, optval, sizeof(val)))
3749 return -EFAULT; 3762 return -EFAULT;
3750 3763
3764 lock_sock(sk);
3751 po->auxdata = !!val; 3765 po->auxdata = !!val;
3766 release_sock(sk);
3752 return 0; 3767 return 0;
3753 } 3768 }
3754 case PACKET_ORIGDEV: 3769 case PACKET_ORIGDEV:
@@ -3760,7 +3775,9 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3760 if (copy_from_user(&val, optval, sizeof(val))) 3775 if (copy_from_user(&val, optval, sizeof(val)))
3761 return -EFAULT; 3776 return -EFAULT;
3762 3777
3778 lock_sock(sk);
3763 po->origdev = !!val; 3779 po->origdev = !!val;
3780 release_sock(sk);
3764 return 0; 3781 return 0;
3765 } 3782 }
3766 case PACKET_VNET_HDR: 3783 case PACKET_VNET_HDR:
@@ -3769,15 +3786,20 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3769 3786
3770 if (sock->type != SOCK_RAW) 3787 if (sock->type != SOCK_RAW)
3771 return -EINVAL; 3788 return -EINVAL;
3772 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
3773 return -EBUSY;
3774 if (optlen < sizeof(val)) 3789 if (optlen < sizeof(val))
3775 return -EINVAL; 3790 return -EINVAL;
3776 if (copy_from_user(&val, optval, sizeof(val))) 3791 if (copy_from_user(&val, optval, sizeof(val)))
3777 return -EFAULT; 3792 return -EFAULT;
3778 3793
3779 po->has_vnet_hdr = !!val; 3794 lock_sock(sk);
3780 return 0; 3795 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
3796 ret = -EBUSY;
3797 } else {
3798 po->has_vnet_hdr = !!val;
3799 ret = 0;
3800 }
3801 release_sock(sk);
3802 return ret;
3781 } 3803 }
3782 case PACKET_TIMESTAMP: 3804 case PACKET_TIMESTAMP:
3783 { 3805 {
@@ -3815,11 +3837,17 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3815 3837
3816 if (optlen != sizeof(val)) 3838 if (optlen != sizeof(val))
3817 return -EINVAL; 3839 return -EINVAL;
3818 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
3819 return -EBUSY;
3820 if (copy_from_user(&val, optval, sizeof(val))) 3840 if (copy_from_user(&val, optval, sizeof(val)))
3821 return -EFAULT; 3841 return -EFAULT;
3822 po->tp_tx_has_off = !!val; 3842
3843 lock_sock(sk);
3844 if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
3845 ret = -EBUSY;
3846 } else {
3847 po->tp_tx_has_off = !!val;
3848 ret = 0;
3849 }
3850 release_sock(sk);
3823 return 0; 3851 return 0;
3824 } 3852 }
3825 case PACKET_QDISC_BYPASS: 3853 case PACKET_QDISC_BYPASS:
diff --git a/net/packet/internal.h b/net/packet/internal.h
index a1d2b2319ae9..3bb7c5fb3bff 100644
--- a/net/packet/internal.h
+++ b/net/packet/internal.h
@@ -112,10 +112,12 @@ struct packet_sock {
112 int copy_thresh; 112 int copy_thresh;
113 spinlock_t bind_lock; 113 spinlock_t bind_lock;
114 struct mutex pg_vec_lock; 114 struct mutex pg_vec_lock;
115 unsigned int running:1, /* prot_hook is attached*/ 115 unsigned int running; /* bind_lock must be held */
116 auxdata:1, 116 unsigned int auxdata:1, /* writer must hold sock lock */
117 origdev:1, 117 origdev:1,
118 has_vnet_hdr:1; 118 has_vnet_hdr:1,
119 tp_loss:1,
120 tp_tx_has_off:1;
119 int pressure; 121 int pressure;
120 int ifindex; /* bound device */ 122 int ifindex; /* bound device */
121 __be16 num; 123 __be16 num;
@@ -125,8 +127,6 @@ struct packet_sock {
125 enum tpacket_versions tp_version; 127 enum tpacket_versions tp_version;
126 unsigned int tp_hdrlen; 128 unsigned int tp_hdrlen;
127 unsigned int tp_reserve; 129 unsigned int tp_reserve;
128 unsigned int tp_loss:1;
129 unsigned int tp_tx_has_off:1;
130 unsigned int tp_tstamp; 130 unsigned int tp_tstamp;
131 struct net_device __rcu *cached_dev; 131 struct net_device __rcu *cached_dev;
132 int (*xmit)(struct sk_buff *skb); 132 int (*xmit)(struct sk_buff *skb);
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index a5994cf0512b..8527cfdc446d 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -652,7 +652,7 @@ static int find_decode_metaid(struct sk_buff *skb, struct tcf_ife_info *ife,
652 } 652 }
653 } 653 }
654 654
655 return 0; 655 return -ENOENT;
656} 656}
657 657
658static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, 658static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
@@ -682,7 +682,12 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
682 u16 mtype; 682 u16 mtype;
683 u16 dlen; 683 u16 dlen;
684 684
685 curr_data = ife_tlv_meta_decode(tlv_data, &mtype, &dlen, NULL); 685 curr_data = ife_tlv_meta_decode(tlv_data, ifehdr_end, &mtype,
686 &dlen, NULL);
687 if (!curr_data) {
688 qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
689 return TC_ACT_SHOT;
690 }
686 691
687 if (find_decode_metaid(skb, ife, mtype, dlen, curr_data)) { 692 if (find_decode_metaid(skb, ife, mtype, dlen, curr_data)) {
688 /* abuse overlimits to count when we receive metadata 693 /* abuse overlimits to count when we receive metadata
diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index 805b139756db..092bebc70048 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -67,7 +67,7 @@ static void strp_abort_strp(struct strparser *strp, int err)
67 67
68static void strp_start_timer(struct strparser *strp, long timeo) 68static void strp_start_timer(struct strparser *strp, long timeo)
69{ 69{
70 if (timeo) 70 if (timeo && timeo != LONG_MAX)
71 mod_delayed_work(strp_wq, &strp->msg_timer_work, timeo); 71 mod_delayed_work(strp_wq, &strp->msg_timer_work, timeo);
72} 72}
73 73
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 9cf83f895d98..5e1ab2f0eb79 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -12,3 +12,6 @@ test_tcpbpf_user
12test_verifier_log 12test_verifier_log
13feature 13feature
14test_libbpf_open 14test_libbpf_open
15test_sock
16test_sock_addr
17urandom_read
diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c
index 73bb20cfb9b7..f4d99fabc56d 100644
--- a/tools/testing/selftests/bpf/test_sock.c
+++ b/tools/testing/selftests/bpf/test_sock.c
@@ -13,6 +13,7 @@
13#include <bpf/bpf.h> 13#include <bpf/bpf.h>
14 14
15#include "cgroup_helpers.h" 15#include "cgroup_helpers.h"
16#include "bpf_rlimit.h"
16 17
17#ifndef ARRAY_SIZE 18#ifndef ARRAY_SIZE
18# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 19# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c
index d488f20926e8..2950f80ba7fb 100644
--- a/tools/testing/selftests/bpf/test_sock_addr.c
+++ b/tools/testing/selftests/bpf/test_sock_addr.c
@@ -15,6 +15,7 @@
15#include <bpf/libbpf.h> 15#include <bpf/libbpf.h>
16 16
17#include "cgroup_helpers.h" 17#include "cgroup_helpers.h"
18#include "bpf_rlimit.h"
18 19
19#define CG_PATH "/foo" 20#define CG_PATH "/foo"
20#define CONNECT4_PROG_PATH "./connect4_prog.o" 21#define CONNECT4_PROG_PATH "./connect4_prog.o"
diff --git a/tools/testing/selftests/bpf/test_sock_addr.sh b/tools/testing/selftests/bpf/test_sock_addr.sh
index c6e1dcf992c4..9832a875a828 100755
--- a/tools/testing/selftests/bpf/test_sock_addr.sh
+++ b/tools/testing/selftests/bpf/test_sock_addr.sh
@@ -4,7 +4,7 @@ set -eu
4 4
5ping_once() 5ping_once()
6{ 6{
7 ping -q -c 1 -W 1 ${1%%/*} >/dev/null 2>&1 7 ping -${1} -q -c 1 -W 1 ${2%%/*} >/dev/null 2>&1
8} 8}
9 9
10wait_for_ip() 10wait_for_ip()
@@ -13,7 +13,7 @@ wait_for_ip()
13 echo -n "Wait for testing IPv4/IPv6 to become available " 13 echo -n "Wait for testing IPv4/IPv6 to become available "
14 for _i in $(seq ${MAX_PING_TRIES}); do 14 for _i in $(seq ${MAX_PING_TRIES}); do
15 echo -n "." 15 echo -n "."
16 if ping_once ${TEST_IPv4} && ping_once ${TEST_IPv6}; then 16 if ping_once 4 ${TEST_IPv4} && ping_once 6 ${TEST_IPv6}; then
17 echo " OK" 17 echo " OK"
18 return 18 return
19 fi 19 fi