Commit 8875cf9c authored by David S. Miller's avatar David S. Miller

Merge branch 'ibmvnic-serialization-fixes'

Juliet Kim says:

====================
net/ibmvnic: serialization fixes

This series includes two fixes. The first improves reset code to allow
linkwatch_event to proceed during reset. The second ensures that no more
than one thread runs in reset at a time.

v2:
- Separate change param reset from do_reset()
- Return IBMVNIC_OPEN_FAILED if __ibmvnic_open fails
- Remove setting wait_for_reset to false from __ibmvnic_reset(), this
  is done in wait_for_reset()
- Move the check for force_reset_recovery from patch 1 to patch 2

v3:
- Restore reset’s successful return in open failure case

v4:
- Change resetting flag access to atomic
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5aafeb74 7ed5b31f
...@@ -1207,7 +1207,7 @@ static void ibmvnic_cleanup(struct net_device *netdev) ...@@ -1207,7 +1207,7 @@ static void ibmvnic_cleanup(struct net_device *netdev)
struct ibmvnic_adapter *adapter = netdev_priv(netdev); struct ibmvnic_adapter *adapter = netdev_priv(netdev);
/* ensure that transmissions are stopped if called by do_reset */ /* ensure that transmissions are stopped if called by do_reset */
if (adapter->resetting) if (test_bit(0, &adapter->resetting))
netif_tx_disable(netdev); netif_tx_disable(netdev);
else else
netif_tx_stop_all_queues(netdev); netif_tx_stop_all_queues(netdev);
...@@ -1428,7 +1428,7 @@ static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -1428,7 +1428,7 @@ static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
u8 proto = 0; u8 proto = 0;
netdev_tx_t ret = NETDEV_TX_OK; netdev_tx_t ret = NETDEV_TX_OK;
if (adapter->resetting) { if (test_bit(0, &adapter->resetting)) {
if (!netif_subqueue_stopped(netdev, skb)) if (!netif_subqueue_stopped(netdev, skb))
netif_stop_subqueue(netdev, queue_num); netif_stop_subqueue(netdev, queue_num);
dev_kfree_skb_any(skb); dev_kfree_skb_any(skb);
...@@ -1723,6 +1723,86 @@ static int ibmvnic_set_mac(struct net_device *netdev, void *p) ...@@ -1723,6 +1723,86 @@ static int ibmvnic_set_mac(struct net_device *netdev, void *p)
return rc; return rc;
} }
/**
* do_change_param_reset returns zero if we are able to keep processing reset
* events, or non-zero if we hit a fatal error and must halt.
*/
static int do_change_param_reset(struct ibmvnic_adapter *adapter,
struct ibmvnic_rwi *rwi,
u32 reset_state)
{
struct net_device *netdev = adapter->netdev;
int i, rc;
netdev_dbg(adapter->netdev, "Change param resetting driver (%d)\n",
rwi->reset_reason);
netif_carrier_off(netdev);
adapter->reset_reason = rwi->reset_reason;
ibmvnic_cleanup(netdev);
if (reset_state == VNIC_OPEN) {
rc = __ibmvnic_close(netdev);
if (rc)
return rc;
}
release_resources(adapter);
release_sub_crqs(adapter, 1);
release_crq_queue(adapter);
adapter->state = VNIC_PROBED;
rc = init_crq_queue(adapter);
if (rc) {
netdev_err(adapter->netdev,
"Couldn't initialize crq. rc=%d\n", rc);
return rc;
}
rc = ibmvnic_reset_init(adapter);
if (rc)
return IBMVNIC_INIT_FAILED;
/* If the adapter was in PROBE state prior to the reset,
* exit here.
*/
if (reset_state == VNIC_PROBED)
return 0;
rc = ibmvnic_login(netdev);
if (rc) {
adapter->state = reset_state;
return rc;
}
rc = init_resources(adapter);
if (rc)
return rc;
ibmvnic_disable_irqs(adapter);
adapter->state = VNIC_CLOSED;
if (reset_state == VNIC_CLOSED)
return 0;
rc = __ibmvnic_open(netdev);
if (rc)
return IBMVNIC_OPEN_FAILED;
/* refresh device's multicast list */
ibmvnic_set_multi(netdev);
/* kick napi */
for (i = 0; i < adapter->req_rx_queues; i++)
napi_schedule(&adapter->napi[i]);
return 0;
}
/** /**
* do_reset returns zero if we are able to keep processing reset events, or * do_reset returns zero if we are able to keep processing reset events, or
* non-zero if we hit a fatal error and must halt. * non-zero if we hit a fatal error and must halt.
...@@ -1738,6 +1818,8 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1738,6 +1818,8 @@ static int do_reset(struct ibmvnic_adapter *adapter,
netdev_dbg(adapter->netdev, "Re-setting driver (%d)\n", netdev_dbg(adapter->netdev, "Re-setting driver (%d)\n",
rwi->reset_reason); rwi->reset_reason);
rtnl_lock();
netif_carrier_off(netdev); netif_carrier_off(netdev);
adapter->reset_reason = rwi->reset_reason; adapter->reset_reason = rwi->reset_reason;
...@@ -1751,16 +1833,25 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1751,16 +1833,25 @@ static int do_reset(struct ibmvnic_adapter *adapter,
if (reset_state == VNIC_OPEN && if (reset_state == VNIC_OPEN &&
adapter->reset_reason != VNIC_RESET_MOBILITY && adapter->reset_reason != VNIC_RESET_MOBILITY &&
adapter->reset_reason != VNIC_RESET_FAILOVER) { adapter->reset_reason != VNIC_RESET_FAILOVER) {
rc = __ibmvnic_close(netdev); adapter->state = VNIC_CLOSING;
/* Release the RTNL lock before link state change and
* re-acquire after the link state change to allow
* linkwatch_event to grab the RTNL lock and run during
* a reset.
*/
rtnl_unlock();
rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
rtnl_lock();
if (rc) if (rc)
return rc; goto out;
if (adapter->state != VNIC_CLOSING) {
rc = -1;
goto out;
} }
if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM || adapter->state = VNIC_CLOSED;
adapter->wait_for_reset) {
release_resources(adapter);
release_sub_crqs(adapter, 1);
release_crq_queue(adapter);
} }
if (adapter->reset_reason != VNIC_RESET_NON_FATAL) { if (adapter->reset_reason != VNIC_RESET_NON_FATAL) {
...@@ -1769,9 +1860,7 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1769,9 +1860,7 @@ static int do_reset(struct ibmvnic_adapter *adapter,
*/ */
adapter->state = VNIC_PROBED; adapter->state = VNIC_PROBED;
if (adapter->wait_for_reset) { if (adapter->reset_reason == VNIC_RESET_MOBILITY) {
rc = init_crq_queue(adapter);
} else if (adapter->reset_reason == VNIC_RESET_MOBILITY) {
rc = ibmvnic_reenable_crq_queue(adapter); rc = ibmvnic_reenable_crq_queue(adapter);
release_sub_crqs(adapter, 1); release_sub_crqs(adapter, 1);
} else { } else {
...@@ -1783,31 +1872,30 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1783,31 +1872,30 @@ static int do_reset(struct ibmvnic_adapter *adapter,
if (rc) { if (rc) {
netdev_err(adapter->netdev, netdev_err(adapter->netdev,
"Couldn't initialize crq. rc=%d\n", rc); "Couldn't initialize crq. rc=%d\n", rc);
return rc; goto out;
} }
rc = ibmvnic_reset_init(adapter); rc = ibmvnic_reset_init(adapter);
if (rc) if (rc) {
return IBMVNIC_INIT_FAILED; rc = IBMVNIC_INIT_FAILED;
goto out;
}
/* If the adapter was in PROBE state prior to the reset, /* If the adapter was in PROBE state prior to the reset,
* exit here. * exit here.
*/ */
if (reset_state == VNIC_PROBED) if (reset_state == VNIC_PROBED) {
return 0; rc = 0;
goto out;
}
rc = ibmvnic_login(netdev); rc = ibmvnic_login(netdev);
if (rc) { if (rc) {
adapter->state = reset_state; adapter->state = reset_state;
return rc; goto out;
} }
if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM || if (adapter->req_rx_queues != old_num_rx_queues ||
adapter->wait_for_reset) {
rc = init_resources(adapter);
if (rc)
return rc;
} else if (adapter->req_rx_queues != old_num_rx_queues ||
adapter->req_tx_queues != old_num_tx_queues || adapter->req_tx_queues != old_num_tx_queues ||
adapter->req_rx_add_entries_per_subcrq != adapter->req_rx_add_entries_per_subcrq !=
old_num_rx_slots || old_num_rx_slots ||
...@@ -1820,32 +1908,30 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1820,32 +1908,30 @@ static int do_reset(struct ibmvnic_adapter *adapter,
rc = init_resources(adapter); rc = init_resources(adapter);
if (rc) if (rc)
return rc; goto out;
} else { } else {
rc = reset_tx_pools(adapter); rc = reset_tx_pools(adapter);
if (rc) if (rc)
return rc; goto out;
rc = reset_rx_pools(adapter); rc = reset_rx_pools(adapter);
if (rc) if (rc)
return rc; goto out;
} }
ibmvnic_disable_irqs(adapter); ibmvnic_disable_irqs(adapter);
} }
adapter->state = VNIC_CLOSED; adapter->state = VNIC_CLOSED;
if (reset_state == VNIC_CLOSED) if (reset_state == VNIC_CLOSED) {
return 0; rc = 0;
goto out;
}
rc = __ibmvnic_open(netdev); rc = __ibmvnic_open(netdev);
if (rc) { if (rc) {
if (list_empty(&adapter->rwi_list)) rc = IBMVNIC_OPEN_FAILED;
adapter->state = VNIC_CLOSED; goto out;
else
adapter->state = reset_state;
return 0;
} }
/* refresh device's multicast list */ /* refresh device's multicast list */
...@@ -1855,11 +1941,15 @@ static int do_reset(struct ibmvnic_adapter *adapter, ...@@ -1855,11 +1941,15 @@ static int do_reset(struct ibmvnic_adapter *adapter,
for (i = 0; i < adapter->req_rx_queues; i++) for (i = 0; i < adapter->req_rx_queues; i++)
napi_schedule(&adapter->napi[i]); napi_schedule(&adapter->napi[i]);
if (adapter->reset_reason != VNIC_RESET_FAILOVER && if (adapter->reset_reason != VNIC_RESET_FAILOVER)
adapter->reset_reason != VNIC_RESET_CHANGE_PARAM)
call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev); call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev);
return 0; rc = 0;
out:
rtnl_unlock();
return rc;
} }
static int do_hard_reset(struct ibmvnic_adapter *adapter, static int do_hard_reset(struct ibmvnic_adapter *adapter,
...@@ -1919,14 +2009,8 @@ static int do_hard_reset(struct ibmvnic_adapter *adapter, ...@@ -1919,14 +2009,8 @@ static int do_hard_reset(struct ibmvnic_adapter *adapter,
return 0; return 0;
rc = __ibmvnic_open(netdev); rc = __ibmvnic_open(netdev);
if (rc) { if (rc)
if (list_empty(&adapter->rwi_list)) return IBMVNIC_OPEN_FAILED;
adapter->state = VNIC_CLOSED;
else
adapter->state = reset_state;
return 0;
}
return 0; return 0;
} }
...@@ -1965,20 +2049,17 @@ static void __ibmvnic_reset(struct work_struct *work) ...@@ -1965,20 +2049,17 @@ static void __ibmvnic_reset(struct work_struct *work)
{ {
struct ibmvnic_rwi *rwi; struct ibmvnic_rwi *rwi;
struct ibmvnic_adapter *adapter; struct ibmvnic_adapter *adapter;
bool we_lock_rtnl = false;
u32 reset_state; u32 reset_state;
int rc = 0; int rc = 0;
adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset); adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);
/* netif_set_real_num_xx_queues needs to take rtnl lock here if (test_and_set_bit_lock(0, &adapter->resetting)) {
* unless wait_for_reset is set, in which case the rtnl lock schedule_delayed_work(&adapter->ibmvnic_delayed_reset,
* has already been taken before initializing the reset IBMVNIC_RESET_DELAY);
*/ return;
if (!adapter->wait_for_reset) {
rtnl_lock();
we_lock_rtnl = true;
} }
reset_state = adapter->state; reset_state = adapter->state;
rwi = get_next_rwi(adapter); rwi = get_next_rwi(adapter);
...@@ -1990,22 +2071,43 @@ static void __ibmvnic_reset(struct work_struct *work) ...@@ -1990,22 +2071,43 @@ static void __ibmvnic_reset(struct work_struct *work)
break; break;
} }
if (adapter->force_reset_recovery) { if (rwi->reset_reason == VNIC_RESET_CHANGE_PARAM) {
/* CHANGE_PARAM requestor holds rtnl_lock */
rc = do_change_param_reset(adapter, rwi, reset_state);
} else if (adapter->force_reset_recovery) {
/* Transport event occurred during previous reset */
if (adapter->wait_for_reset) {
/* Previous was CHANGE_PARAM; caller locked */
adapter->force_reset_recovery = false; adapter->force_reset_recovery = false;
rc = do_hard_reset(adapter, rwi, reset_state); rc = do_hard_reset(adapter, rwi, reset_state);
} else {
rtnl_lock();
adapter->force_reset_recovery = false;
rc = do_hard_reset(adapter, rwi, reset_state);
rtnl_unlock();
}
} else { } else {
rc = do_reset(adapter, rwi, reset_state); rc = do_reset(adapter, rwi, reset_state);
} }
kfree(rwi); kfree(rwi);
if (rc && rc != IBMVNIC_INIT_FAILED && if (rc == IBMVNIC_OPEN_FAILED) {
if (list_empty(&adapter->rwi_list))
adapter->state = VNIC_CLOSED;
else
adapter->state = reset_state;
rc = 0;
} else if (rc && rc != IBMVNIC_INIT_FAILED &&
!adapter->force_reset_recovery) !adapter->force_reset_recovery)
break; break;
rwi = get_next_rwi(adapter); rwi = get_next_rwi(adapter);
if (rwi && (rwi->reset_reason == VNIC_RESET_FAILOVER ||
rwi->reset_reason == VNIC_RESET_MOBILITY))
adapter->force_reset_recovery = true;
} }
if (adapter->wait_for_reset) { if (adapter->wait_for_reset) {
adapter->wait_for_reset = false;
adapter->reset_done_rc = rc; adapter->reset_done_rc = rc;
complete(&adapter->reset_done); complete(&adapter->reset_done);
} }
...@@ -2015,9 +2117,16 @@ static void __ibmvnic_reset(struct work_struct *work) ...@@ -2015,9 +2117,16 @@ static void __ibmvnic_reset(struct work_struct *work)
free_all_rwi(adapter); free_all_rwi(adapter);
} }
adapter->resetting = false; clear_bit_unlock(0, &adapter->resetting);
if (we_lock_rtnl) }
rtnl_unlock();
static void __ibmvnic_delayed_reset(struct work_struct *work)
{
struct ibmvnic_adapter *adapter;
adapter = container_of(work, struct ibmvnic_adapter,
ibmvnic_delayed_reset.work);
__ibmvnic_reset(&adapter->ibmvnic_reset);
} }
static int ibmvnic_reset(struct ibmvnic_adapter *adapter, static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
...@@ -2072,14 +2181,11 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter, ...@@ -2072,14 +2181,11 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
rwi->reset_reason = reason; rwi->reset_reason = reason;
list_add_tail(&rwi->list, &adapter->rwi_list); list_add_tail(&rwi->list, &adapter->rwi_list);
spin_unlock_irqrestore(&adapter->rwi_lock, flags); spin_unlock_irqrestore(&adapter->rwi_lock, flags);
adapter->resetting = true;
netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason); netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason);
schedule_work(&adapter->ibmvnic_reset); schedule_work(&adapter->ibmvnic_reset);
return 0; return 0;
err: err:
if (adapter->wait_for_reset)
adapter->wait_for_reset = false;
return -ret; return -ret;
} }
...@@ -2119,7 +2225,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget) ...@@ -2119,7 +2225,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
u16 offset; u16 offset;
u8 flags = 0; u8 flags = 0;
if (unlikely(adapter->resetting && if (unlikely(test_bit(0, &adapter->resetting) &&
adapter->reset_reason != VNIC_RESET_NON_FATAL)) { adapter->reset_reason != VNIC_RESET_NON_FATAL)) {
enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]); enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
napi_complete_done(napi, frames_processed); napi_complete_done(napi, frames_processed);
...@@ -2770,7 +2876,7 @@ static int enable_scrq_irq(struct ibmvnic_adapter *adapter, ...@@ -2770,7 +2876,7 @@ static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
return 1; return 1;
} }
if (adapter->resetting && if (test_bit(0, &adapter->resetting) &&
adapter->reset_reason == VNIC_RESET_MOBILITY) { adapter->reset_reason == VNIC_RESET_MOBILITY) {
u64 val = (0xff000000) | scrq->hw_irq; u64 val = (0xff000000) | scrq->hw_irq;
...@@ -3320,7 +3426,7 @@ static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter, ...@@ -3320,7 +3426,7 @@ static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
if (rc) { if (rc) {
if (rc == H_CLOSED) { if (rc == H_CLOSED) {
dev_warn(dev, "CRQ Queue closed\n"); dev_warn(dev, "CRQ Queue closed\n");
if (adapter->resetting) if (test_bit(0, &adapter->resetting))
ibmvnic_reset(adapter, VNIC_RESET_FATAL); ibmvnic_reset(adapter, VNIC_RESET_FATAL);
} }
...@@ -4396,7 +4502,7 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq, ...@@ -4396,7 +4502,7 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
case IBMVNIC_CRQ_XPORT_EVENT: case IBMVNIC_CRQ_XPORT_EVENT:
netif_carrier_off(netdev); netif_carrier_off(netdev);
adapter->crq.active = false; adapter->crq.active = false;
if (adapter->resetting) if (test_bit(0, &adapter->resetting))
adapter->force_reset_recovery = true; adapter->force_reset_recovery = true;
if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
dev_info(dev, "Migrated, re-enabling adapter\n"); dev_info(dev, "Migrated, re-enabling adapter\n");
...@@ -4734,7 +4840,7 @@ static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter) ...@@ -4734,7 +4840,7 @@ static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter)
return -1; return -1;
} }
if (adapter->resetting && !adapter->wait_for_reset && if (test_bit(0, &adapter->resetting) && !adapter->wait_for_reset &&
adapter->reset_reason != VNIC_RESET_MOBILITY) { adapter->reset_reason != VNIC_RESET_MOBILITY) {
if (adapter->req_rx_queues != old_num_rx_queues || if (adapter->req_rx_queues != old_num_rx_queues ||
adapter->req_tx_queues != old_num_tx_queues) { adapter->req_tx_queues != old_num_tx_queues) {
...@@ -4846,10 +4952,12 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) ...@@ -4846,10 +4952,12 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
spin_lock_init(&adapter->stats_lock); spin_lock_init(&adapter->stats_lock);
INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset); INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset);
INIT_DELAYED_WORK(&adapter->ibmvnic_delayed_reset,
__ibmvnic_delayed_reset);
INIT_LIST_HEAD(&adapter->rwi_list); INIT_LIST_HEAD(&adapter->rwi_list);
spin_lock_init(&adapter->rwi_lock); spin_lock_init(&adapter->rwi_lock);
init_completion(&adapter->init_done); init_completion(&adapter->init_done);
adapter->resetting = false; clear_bit(0, &adapter->resetting);
do { do {
rc = init_crq_queue(adapter); rc = init_crq_queue(adapter);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define IBMVNIC_INVALID_MAP -1 #define IBMVNIC_INVALID_MAP -1
#define IBMVNIC_STATS_TIMEOUT 1 #define IBMVNIC_STATS_TIMEOUT 1
#define IBMVNIC_INIT_FAILED 2 #define IBMVNIC_INIT_FAILED 2
#define IBMVNIC_OPEN_FAILED 3
/* basic structures plus 100 2k buffers */ /* basic structures plus 100 2k buffers */
#define IBMVNIC_IO_ENTITLEMENT_DEFAULT 610305 #define IBMVNIC_IO_ENTITLEMENT_DEFAULT 610305
...@@ -38,6 +39,8 @@ ...@@ -38,6 +39,8 @@
#define IBMVNIC_MAX_LTB_SIZE ((1 << (MAX_ORDER - 1)) * PAGE_SIZE) #define IBMVNIC_MAX_LTB_SIZE ((1 << (MAX_ORDER - 1)) * PAGE_SIZE)
#define IBMVNIC_BUFFER_HLEN 500 #define IBMVNIC_BUFFER_HLEN 500
#define IBMVNIC_RESET_DELAY 100
static const char ibmvnic_priv_flags[][ETH_GSTRING_LEN] = { static const char ibmvnic_priv_flags[][ETH_GSTRING_LEN] = {
#define IBMVNIC_USE_SERVER_MAXES 0x1 #define IBMVNIC_USE_SERVER_MAXES 0x1
"use-server-maxes" "use-server-maxes"
...@@ -1076,7 +1079,8 @@ struct ibmvnic_adapter { ...@@ -1076,7 +1079,8 @@ struct ibmvnic_adapter {
spinlock_t rwi_lock; spinlock_t rwi_lock;
struct list_head rwi_list; struct list_head rwi_list;
struct work_struct ibmvnic_reset; struct work_struct ibmvnic_reset;
bool resetting; struct delayed_work ibmvnic_delayed_reset;
unsigned long resetting;
bool napi_enabled, from_passive_init; bool napi_enabled, from_passive_init;
bool failover_pending; bool failover_pending;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment