OSDN Git Service

i40e/i40evf: use cmpxchg64 when updating private flags in ethtool
authorJacob Keller <jacob.e.keller@intel.com>
Fri, 23 Jun 2017 08:24:50 +0000 (04:24 -0400)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Fri, 25 Aug 2017 21:46:34 +0000 (14:46 -0700)
commit841c950d67c6facde32a8644ced20c04aebb7dd8
tree40940c57be54a3058491e582cb0cad345c8ac562
parent10a955ff62e56fe13dae1f29aabc04bc589eaf46
i40e/i40evf: use cmpxchg64 when updating private flags in ethtool

When a user gives an invalid command to change a private flag which is
not supported, either because it is read-only, or the device is not
capable of the feature, we simply ignore the request.

A naive solution would simply be to report error codes when one of the
flags was not supported. However, this causes problems because it makes
the operation not atomic. If a user requests multiple private flags
together at once we could end up changing one before failing at the
second flag.

We can do a bit better if we instead update a temporary copy of the
flags variable in the loop, and then copy it into place after. If we
aren't careful this has the pitfall of potentially silently overwriting
any changes caused by other threads.

Avoid this by using cmpxchg64 which will compare and swap the flags
variable only if it currently matched the old value. We'll report
-EAGAIN in the (hopefully rare!) case where the cmpxchg64 fails.

This ensures that we can properly report when flags are not supported in
an atomic fashion without the risk of overwriting other threads changes.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_ethtool.c
drivers/net/ethernet/intel/i40evf/i40evf_ethtool.c