038-net-mvneta-Fix-the-CPU-choice-in-mvneta_percpu_elect.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From: Gregory CLEMENT <gregory.clement@free-electrons.com>
  2. Date: Thu, 4 Feb 2016 22:09:24 +0100
  3. Subject: [PATCH] net: mvneta: Fix the CPU choice in mvneta_percpu_elect
  4. When passing to the management of multiple RX queue, the
  5. mvneta_percpu_elect function was broken. The use of the modulo can lead
  6. to elect the wrong cpu. For example with rxq_def=2, if the CPU 2 goes
  7. offline and then online, we ended with the third RX queue activated in
  8. the same time on CPU 0 and CPU2, which lead to a kernel crash.
  9. With this fix, we don't try to get "the closer" CPU if the default CPU is
  10. gone, now we just use CPU 0 which always be there. Thanks to this, the
  11. code becomes more readable, easier to maintain and more predicable.
  12. Cc: stable@vger.kernel.org
  13. Fixes: 2dcf75e2793c ("net: mvneta: Associate RX queues with each CPU")
  14. Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
  15. Signed-off-by: David S. Miller <davem@davemloft.net>
  16. ---
  17. --- a/drivers/net/ethernet/marvell/mvneta.c
  18. +++ b/drivers/net/ethernet/marvell/mvneta.c
  19. @@ -2851,9 +2851,14 @@ static void mvneta_percpu_disable(void *
  20. static void mvneta_percpu_elect(struct mvneta_port *pp)
  21. {
  22. - int online_cpu_idx, max_cpu, cpu, i = 0;
  23. + int elected_cpu = 0, max_cpu, cpu, i = 0;
  24. +
  25. + /* Use the cpu associated to the rxq when it is online, in all
  26. + * the other cases, use the cpu 0 which can't be offline.
  27. + */
  28. + if (cpu_online(pp->rxq_def))
  29. + elected_cpu = pp->rxq_def;
  30. - online_cpu_idx = pp->rxq_def % num_online_cpus();
  31. max_cpu = num_present_cpus();
  32. for_each_online_cpu(cpu) {
  33. @@ -2864,7 +2869,7 @@ static void mvneta_percpu_elect(struct m
  34. if ((rxq % max_cpu) == cpu)
  35. rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
  36. - if (i == online_cpu_idx)
  37. + if (cpu == elected_cpu)
  38. /* Map the default receive queue queue to the
  39. * elected CPU
  40. */
  41. @@ -2875,7 +2880,7 @@ static void mvneta_percpu_elect(struct m
  42. * the CPU bound to the default RX queue
  43. */
  44. if (txq_number == 1)
  45. - txq_map = (i == online_cpu_idx) ?
  46. + txq_map = (cpu == elected_cpu) ?
  47. MVNETA_CPU_TXQ_ACCESS(1) : 0;
  48. else
  49. txq_map = mvreg_read(pp, MVNETA_CPU_MAP(cpu)) &