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