041-net-mvneta-The-mvneta_percpu_elect-function-should-b.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From: Gregory CLEMENT <gregory.clement@free-electrons.com>
  2. Date: Thu, 4 Feb 2016 22:09:28 +0100
  3. Subject: [PATCH] net: mvneta: The mvneta_percpu_elect function should be
  4. atomic
  5. Electing a CPU must be done in an atomic way: it should be done after or
  6. before the removal/insertion of a CPU and this function is not reentrant.
  7. During the loop of mvneta_percpu_elect we associates the queues to the
  8. CPUs, if there is a topology change during this loop, then the mapping
  9. between the CPUs and the queues could be wrong. During this loop the
  10. interrupt mask is also updating for each CPUs, It should not be changed
  11. in the same time by other part of the driver.
  12. This patch adds spinlock to create the needed critical sections.
  13. Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
  14. Signed-off-by: David S. Miller <davem@davemloft.net>
  15. ---
  16. --- a/drivers/net/ethernet/marvell/mvneta.c
  17. +++ b/drivers/net/ethernet/marvell/mvneta.c
  18. @@ -370,6 +370,10 @@ struct mvneta_port {
  19. struct net_device *dev;
  20. struct notifier_block cpu_notifier;
  21. int rxq_def;
  22. + /* Protect the access to the percpu interrupt registers,
  23. + * ensuring that the configuration remains coherent.
  24. + */
  25. + spinlock_t lock;
  26. /* Core clock */
  27. struct clk *clk;
  28. @@ -2857,6 +2861,12 @@ static void mvneta_percpu_elect(struct m
  29. {
  30. int elected_cpu = 0, max_cpu, cpu, i = 0;
  31. + /* Electing a CPU must be done in an atomic way: it should be
  32. + * done after or before the removal/insertion of a CPU and
  33. + * this function is not reentrant.
  34. + */
  35. + spin_lock(&pp->lock);
  36. +
  37. /* Use the cpu associated to the rxq when it is online, in all
  38. * the other cases, use the cpu 0 which can't be offline.
  39. */
  40. @@ -2900,6 +2910,7 @@ static void mvneta_percpu_elect(struct m
  41. i++;
  42. }
  43. + spin_unlock(&pp->lock);
  44. };
  45. static int mvneta_percpu_notifier(struct notifier_block *nfb,
  46. @@ -2954,8 +2965,13 @@ static int mvneta_percpu_notifier(struct
  47. case CPU_DOWN_PREPARE:
  48. case CPU_DOWN_PREPARE_FROZEN:
  49. netif_tx_stop_all_queues(pp->dev);
  50. + /* Thanks to this lock we are sure that any pending
  51. + * cpu election is done
  52. + */
  53. + spin_lock(&pp->lock);
  54. /* Mask all ethernet port interrupts */
  55. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  56. + spin_unlock(&pp->lock);
  57. napi_synchronize(&port->napi);
  58. napi_disable(&port->napi);