]> git.baikalelectronics.ru Git - kernel.git/commit
mlxsw: pci: Correctly determine if descriptor queue is full
authorIdo Schimmel <idosch@mellanox.com>
Mon, 7 Mar 2016 14:15:30 +0000 (15:15 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 7 Mar 2016 16:39:15 +0000 (11:39 -0500)
commitd817be2b49d69158bb2075c78f70a6fb32973f18
treeb318dc709a1903a7a542496bbba13e42385d84a4
parent0b1442b1e4e593e4f1864cf8d3c207de5fa0639f
mlxsw: pci: Correctly determine if descriptor queue is full

The descriptor queues for sending (SDQs) and receiving (RDQs) packets
are managed by two counters - producer and consumer - which are both
16-bit in size. A queue is considered full when the difference between
the two equals the queue's maximum number of descriptors.

However, if the producer counter overflows, then it's possible for the
full queue check to fail, as it doesn't take the overflow into account.
In such a case, descriptors already passed to the device - but for which
a completion has yet to be posted - will be overwritten, thereby causing
undefined behavior. The above can be achieved under heavy load (~30
netperf instances).

Fix that by casting the subtraction result to u16, preventing it from
being treated as a signed integer.

Fixes: bc313d30ecbc ("mlxsw: Add PCI bus implementation")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/pci.c