ena: Add locking assertions
ENA silently assumed that ena_up, ena_down and ena_start_xmit routines should be called within locked context. Driver's logic heavily assumes on concurrent access to those routines, so for safety and better documentation about this assumption, the locking assertions were added to the above functions. The assertion was added only for the main steps (skipping the helper functions) which can be called from multiple places including the kernel and the driver itself. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
This commit is contained in:
parent
77160654a1
commit
cb98c439d6
@ -2092,6 +2092,8 @@ ena_up(struct ena_adapter *adapter)
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
ENA_LOCK_ASSERT(adapter);
|
||||||
|
|
||||||
if (unlikely(device_is_attached(adapter->pdev) == 0)) {
|
if (unlikely(device_is_attached(adapter->pdev) == 0)) {
|
||||||
ena_log(adapter->pdev, ERR, "device is not attached!\n");
|
ena_log(adapter->pdev, ERR, "device is not attached!\n");
|
||||||
return (ENXIO);
|
return (ENXIO);
|
||||||
@ -2465,6 +2467,8 @@ ena_down(struct ena_adapter *adapter)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
ENA_LOCK_ASSERT(adapter);
|
||||||
|
|
||||||
if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter))
|
if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -480,12 +480,16 @@ struct ena_adapter {
|
|||||||
#define ENA_RING_MTX_LOCK(_ring) mtx_lock(&(_ring)->ring_mtx)
|
#define ENA_RING_MTX_LOCK(_ring) mtx_lock(&(_ring)->ring_mtx)
|
||||||
#define ENA_RING_MTX_TRYLOCK(_ring) mtx_trylock(&(_ring)->ring_mtx)
|
#define ENA_RING_MTX_TRYLOCK(_ring) mtx_trylock(&(_ring)->ring_mtx)
|
||||||
#define ENA_RING_MTX_UNLOCK(_ring) mtx_unlock(&(_ring)->ring_mtx)
|
#define ENA_RING_MTX_UNLOCK(_ring) mtx_unlock(&(_ring)->ring_mtx)
|
||||||
|
#define ENA_RING_MTX_ASSERT(_ring) \
|
||||||
|
mtx_assert(&(_ring)->ring_mtx, MA_OWNED)
|
||||||
|
|
||||||
#define ENA_LOCK_INIT(adapter) \
|
#define ENA_LOCK_INIT(adapter) \
|
||||||
sx_init(&(adapter)->global_lock, "ENA global lock")
|
sx_init(&(adapter)->global_lock, "ENA global lock")
|
||||||
#define ENA_LOCK_DESTROY(adapter) sx_destroy(&(adapter)->global_lock)
|
#define ENA_LOCK_DESTROY(adapter) sx_destroy(&(adapter)->global_lock)
|
||||||
#define ENA_LOCK_LOCK(adapter) sx_xlock(&(adapter)->global_lock)
|
#define ENA_LOCK_LOCK(adapter) sx_xlock(&(adapter)->global_lock)
|
||||||
#define ENA_LOCK_UNLOCK(adapter) sx_unlock(&(adapter)->global_lock)
|
#define ENA_LOCK_UNLOCK(adapter) sx_unlock(&(adapter)->global_lock)
|
||||||
|
#define ENA_LOCK_ASSERT(adapter) \
|
||||||
|
sx_assert(&(adapter)->global_lock, SA_XLOCKED)
|
||||||
|
|
||||||
#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
|
#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
|
||||||
#define clamp_val(val, lo, hi) clamp_t(__typeof(val), val, lo, hi)
|
#define clamp_val(val, lo, hi) clamp_t(__typeof(val), val, lo, hi)
|
||||||
|
@ -1075,6 +1075,8 @@ ena_start_xmit(struct ena_ring *tx_ring)
|
|||||||
int ena_qid;
|
int ena_qid;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
ENA_RING_MTX_ASSERT(tx_ring);
|
||||||
|
|
||||||
if (unlikely((if_getdrvflags(adapter->ifp) & IFF_DRV_RUNNING) == 0))
|
if (unlikely((if_getdrvflags(adapter->ifp) & IFF_DRV_RUNNING) == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user