forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-0002-xen-add-helper-for-calling-notifier_call_chain-to-co.patch
155 lines (129 loc) · 4.62 KB
/
patch-0002-xen-add-helper-for-calling-notifier_call_chain-to-co.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
From 3816d82fba6c67b599c970dfe7bc8e024b7e2042 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Tue, 2 Apr 2019 07:34:53 +0200
Subject: [PATCH 2/9] xen: add helper for calling notifier_call_chain() to
common/cpu.c
Add a helper cpu_notifier_call_chain() to call notifier_call_chain()
for a cpu with a specified action, returning an errno value.
This avoids coding the same pattern multiple times.
While at it avoid side effects from using BUG_ON() by not using
cpu_online(cpu) as a parameter.
Signed-off-by: Juergen Gross <[email protected]>
Reviewed-by: Dario Faggioli <[email protected]>
Acked-by: Jan Beulich <[email protected]>
(cherry picked from commit 8d88eacb3b390984e2c483d75d8f40b3ec4be67c)
---
xen/common/cpu.c | 56 ++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index ca415babf8d2..ccf62b5e013e 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -68,11 +68,21 @@ void __init register_cpu_notifier(struct notifier_block *nb)
spin_unlock(&cpu_add_remove_lock);
}
+static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
+ struct notifier_block **nb, bool nofail)
+{
+ void *hcpu = (void *)(long)cpu;
+ int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb);
+ int ret = (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);
+
+ BUG_ON(ret && nofail);
+
+ return ret;
+}
+
static void _take_cpu_down(void *unused)
{
- void *hcpu = (void *)(long)smp_processor_id();
- int notifier_rc = notifier_call_chain(&cpu_chain, CPU_DYING, hcpu, NULL);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL, true);
__cpu_disable();
}
@@ -84,8 +94,7 @@ static int take_cpu_down(void *arg)
int cpu_down(unsigned int cpu)
{
- int err, notifier_rc;
- void *hcpu = (void *)(long)cpu;
+ int err;
struct notifier_block *nb = NULL;
if ( !cpu_hotplug_begin() )
@@ -97,12 +106,9 @@ int cpu_down(unsigned int cpu)
return -EINVAL;
}
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE, hcpu, &nb);
- if ( notifier_rc != NOTIFY_DONE )
- {
- err = notifier_to_errno(notifier_rc);
+ err = cpu_notifier_call_chain(cpu, CPU_DOWN_PREPARE, &nb, false);
+ if ( err )
goto fail;
- }
if ( unlikely(system_state < SYS_STATE_active) )
on_selected_cpus(cpumask_of(cpu), _take_cpu_down, NULL, true);
@@ -110,26 +116,24 @@ int cpu_down(unsigned int cpu)
goto fail;
__cpu_die(cpu);
- BUG_ON(cpu_online(cpu));
+ err = cpu_online(cpu);
+ BUG_ON(err);
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_DEAD, hcpu, NULL);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(cpu, CPU_DEAD, NULL, true);
send_global_virq(VIRQ_PCPU_STATE);
cpu_hotplug_done();
return 0;
fail:
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED, hcpu, &nb);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(cpu, CPU_DOWN_FAILED, &nb, true);
cpu_hotplug_done();
return err;
}
int cpu_up(unsigned int cpu)
{
- int notifier_rc, err = 0;
- void *hcpu = (void *)(long)cpu;
+ int err;
struct notifier_block *nb = NULL;
if ( !cpu_hotplug_begin() )
@@ -141,19 +145,15 @@ int cpu_up(unsigned int cpu)
return -EINVAL;
}
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu, &nb);
- if ( notifier_rc != NOTIFY_DONE )
- {
- err = notifier_to_errno(notifier_rc);
+ err = cpu_notifier_call_chain(cpu, CPU_UP_PREPARE, &nb, false);
+ if ( err )
goto fail;
- }
err = __cpu_up(cpu);
if ( err < 0 )
goto fail;
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu, NULL);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(cpu, CPU_ONLINE, NULL, true);
send_global_virq(VIRQ_PCPU_STATE);
@@ -161,18 +161,14 @@ int cpu_up(unsigned int cpu)
return 0;
fail:
- notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_CANCELED, hcpu, &nb);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(cpu, CPU_UP_CANCELED, &nb, true);
cpu_hotplug_done();
return err;
}
void notify_cpu_starting(unsigned int cpu)
{
- void *hcpu = (void *)(long)cpu;
- int notifier_rc = notifier_call_chain(
- &cpu_chain, CPU_STARTING, hcpu, NULL);
- BUG_ON(notifier_rc != NOTIFY_DONE);
+ cpu_notifier_call_chain(cpu, CPU_STARTING, NULL, true);
}
static cpumask_t frozen_cpus;
--
2.26.2