Merge ~paelzer/ubuntu/+source/qemu:fix-1832622-ppc-spectre-bionic into ubuntu/+source/qemu:ubuntu/bionic-devel

Proposed by Christian Ehrhardt  on 2019-06-13
Status: Merged
Approved by: Christian Ehrhardt  on 2019-06-26
Approved revision: 32e74e3f62c3f5c94e3f90b8fad0a2f4472e2f92
Merge reported by: Christian Ehrhardt 
Merged at revision: 32e74e3f62c3f5c94e3f90b8fad0a2f4472e2f92
Proposed branch: ~paelzer/ubuntu/+source/qemu:fix-1832622-ppc-spectre-bionic
Merge into: ubuntu/+source/qemu:ubuntu/bionic-devel
Diff against target: 629 lines (+589/-0)
6 files modified
debian/changelog (+7/-0)
debian/patches/series (+4/-0)
debian/patches/ubuntu/lp-1832622-0001-target-ppc-Factor-out-the-parsing-in-kvmppc_get_cpu_.patch (+101/-0)
debian/patches/ubuntu/lp-1832622-0002-target-ppc-spapr-Add-workaround-option-to-SPAPR_CAP_.patch (+159/-0)
debian/patches/ubuntu/lp-1832622-0003-ppc-spapr-caps-Change-migration-macro-to-take-full-s.patch (+79/-0)
debian/patches/ubuntu/lp-1832622-0004-target-ppc-spapr-Add-SPAPR_CAP_CCF_ASSIST.patch (+239/-0)
Reviewer Review Type Date Requested Status
Rafael David Tinoco 2019-06-13 Approve on 2019-06-26
Canonical Server packageset reviewers 2019-06-13 Pending
Ubuntu Server Dev import team 2019-06-13 Pending
Review via email: mp+368751@code.launchpad.net
To post a comment you must log in.
Christian Ehrhardt  (paelzer) wrote :

Related test PPA at [1].
This is based on the provided backports for 2.11

[1]: https://launchpad.net/~paelzer/+archive/ubuntu/bug-1832622-qemu-spectre-ppc

Paride Legovini (legovini) wrote :

Looks good from a formal point view; the packages in the PPA seem to be working as expected, however I don't think I can test the specific fix.

Rafael David Tinoco (rafaeldtinoco) wrote :

I did a full bionic review into eoan merge request, sorry, they are all linked so I guess it is no biggie. This was my comment there:

https://code.launchpad.net/~paelzer/ubuntu/+source/qemu/+git/qemu/+merge/368748/comments/964720

I think you missed one clarification I asked about:

"""
Your comment:

"remove context dependencies on post-2.11 capabilities and migration state"

was made due to positional changes, right ?

Cause I can see only the enum index as diff from upstream.
"""

I'm referring to a note to your cherry-pick/backport in:

commit 8ff43ee404d3e295839d1fd4e9e6571ca7a62a66 (v3.1.0-2772-g8ff43ee404)
Author: Suraj Jitindar Singh <email address hidden>
Date: Fri Mar 1 00:19:12 2019

    target/ppc/spapr: Add SPAPR_CAP_CCF_ASSIST

Cause all difference I could find from upstream was the enum + 1.

I'm more curious then pointing out something here.
----

+1 from me.

Rafael David Tinoco (rafaeldtinoco) wrote :

Forgot to approve =). +1.

review: Approve
Christian Ehrhardt  (paelzer) wrote :

Yes it was just context changes for other options being missing in 2.11

Christian Ehrhardt  (paelzer) wrote :

This migrated, closing forgotten MP

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index a736aad..8ea15ce 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+qemu (1:2.11+dfsg-1ubuntu7.16) bionic; urgency=medium
7+
8+ * d/p/ubuntu/lp-1832622-*: count cache flush Spectre v2 mitigation for ppc64
9+ (LP: #1832622)
10+
11+ -- Christian Ehrhardt <christian.ehrhardt@canonical.com> Thu, 13 Jun 2019 08:08:33 +0200
12+
13 qemu (1:2.11+dfsg-1ubuntu7.15) bionic; urgency=medium
14
15 * d/p/ubuntu/define-ubuntu-machine-types.patch: fix wily machine type being
16diff --git a/debian/patches/series b/debian/patches/series
17index f42b259..86efeb1 100644
18--- a/debian/patches/series
19+++ b/debian/patches/series
20@@ -87,3 +87,7 @@ ubuntu/enable-md-clear.patch
21 CVE-2018-20815.patch
22 CVE-2019-9824.patch
23 ubuntu/lp-1830704-s390x-cpumodel-ignore-csske-for-expansion.patch
24+ubuntu/lp-1832622-0001-target-ppc-Factor-out-the-parsing-in-kvmppc_get_cpu_.patch
25+ubuntu/lp-1832622-0002-target-ppc-spapr-Add-workaround-option-to-SPAPR_CAP_.patch
26+ubuntu/lp-1832622-0003-ppc-spapr-caps-Change-migration-macro-to-take-full-s.patch
27+ubuntu/lp-1832622-0004-target-ppc-spapr-Add-SPAPR_CAP_CCF_ASSIST.patch
28diff --git a/debian/patches/ubuntu/lp-1832622-0001-target-ppc-Factor-out-the-parsing-in-kvmppc_get_cpu_.patch b/debian/patches/ubuntu/lp-1832622-0001-target-ppc-Factor-out-the-parsing-in-kvmppc_get_cpu_.patch
29new file mode 100644
30index 0000000..44412f5
31--- /dev/null
32+++ b/debian/patches/ubuntu/lp-1832622-0001-target-ppc-Factor-out-the-parsing-in-kvmppc_get_cpu_.patch
33@@ -0,0 +1,101 @@
34+From 8fea70440eb0d095442de7e80d586a285cf96be5 Mon Sep 17 00:00:00 2001
35+From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
36+Date: Fri, 11 May 2018 16:25:07 +1000
37+Subject: [PATCH] target/ppc: Factor out the parsing in
38+ kvmppc_get_cpu_characteristics()
39+
40+Factor out the parsing of struct kvm_ppc_cpu_char in
41+kvmppc_get_cpu_characteristics() into a separate function for each cap
42+for simplicity.
43+
44+Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
45+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
46+
47+Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=8fea70440eb0d095442de7e80d586a285cf96be5
48+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1832622
49+Last-Update: 2019-06-13
50+
51+---
52+ target/ppc/kvm.c | 59 ++++++++++++++++++++++++++++++++----------------
53+ 1 file changed, 39 insertions(+), 20 deletions(-)
54+
55+diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
56+index cbe13b18d1..2c0c34e125 100644
57+--- a/target/ppc/kvm.c
58++++ b/target/ppc/kvm.c
59+@@ -2412,6 +2412,41 @@ bool kvmppc_has_cap_mmu_hash_v3(void)
60+ return cap_mmu_hash_v3;
61+ }
62+
63++static int parse_cap_ppc_safe_cache(struct kvm_ppc_cpu_char c)
64++{
65++ if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_L1D_FLUSH_PR) {
66++ return 2;
67++ } else if ((c.character & c.character_mask & H_CPU_CHAR_L1D_THREAD_PRIV) &&
68++ (c.character & c.character_mask
69++ & (H_CPU_CHAR_L1D_FLUSH_ORI30 | H_CPU_CHAR_L1D_FLUSH_TRIG2))) {
70++ return 1;
71++ }
72++
73++ return 0;
74++}
75++
76++static int parse_cap_ppc_safe_bounds_check(struct kvm_ppc_cpu_char c)
77++{
78++ if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR) {
79++ return 2;
80++ } else if (c.character & c.character_mask & H_CPU_CHAR_SPEC_BAR_ORI31) {
81++ return 1;
82++ }
83++
84++ return 0;
85++}
86++
87++static int parse_cap_ppc_safe_indirect_branch(struct kvm_ppc_cpu_char c)
88++{
89++ if (c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) {
90++ return SPAPR_CAP_FIXED_CCD;
91++ } else if (c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED) {
92++ return SPAPR_CAP_FIXED_IBS;
93++ }
94++
95++ return 0;
96++}
97++
98+ static void kvmppc_get_cpu_characteristics(KVMState *s)
99+ {
100+ struct kvm_ppc_cpu_char c;
101+@@ -2430,26 +2465,10 @@ static void kvmppc_get_cpu_characteristics(KVMState *s)
102+ if (ret < 0) {
103+ return;
104+ }
105+- /* Parse and set cap_ppc_safe_cache */
106+- if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_L1D_FLUSH_PR) {
107+- cap_ppc_safe_cache = 2;
108+- } else if ((c.character & c.character_mask & H_CPU_CHAR_L1D_THREAD_PRIV) &&
109+- (c.character & c.character_mask
110+- & (H_CPU_CHAR_L1D_FLUSH_ORI30 | H_CPU_CHAR_L1D_FLUSH_TRIG2))) {
111+- cap_ppc_safe_cache = 1;
112+- }
113+- /* Parse and set cap_ppc_safe_bounds_check */
114+- if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR) {
115+- cap_ppc_safe_bounds_check = 2;
116+- } else if (c.character & c.character_mask & H_CPU_CHAR_SPEC_BAR_ORI31) {
117+- cap_ppc_safe_bounds_check = 1;
118+- }
119+- /* Parse and set cap_ppc_safe_indirect_branch */
120+- if (c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) {
121+- cap_ppc_safe_indirect_branch = SPAPR_CAP_FIXED_CCD;
122+- } else if (c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED) {
123+- cap_ppc_safe_indirect_branch = SPAPR_CAP_FIXED_IBS;
124+- }
125++
126++ cap_ppc_safe_cache = parse_cap_ppc_safe_cache(c);
127++ cap_ppc_safe_bounds_check = parse_cap_ppc_safe_bounds_check(c);
128++ cap_ppc_safe_indirect_branch = parse_cap_ppc_safe_indirect_branch(c);
129+ }
130+
131+ int kvmppc_get_cap_safe_cache(void)
132+--
133+2.21.0
134+
135diff --git a/debian/patches/ubuntu/lp-1832622-0002-target-ppc-spapr-Add-workaround-option-to-SPAPR_CAP_.patch b/debian/patches/ubuntu/lp-1832622-0002-target-ppc-spapr-Add-workaround-option-to-SPAPR_CAP_.patch
136new file mode 100644
137index 0000000..58b3e88
138--- /dev/null
139+++ b/debian/patches/ubuntu/lp-1832622-0002-target-ppc-spapr-Add-workaround-option-to-SPAPR_CAP_.patch
140@@ -0,0 +1,159 @@
141+From 399b2896d4948a1ec0278d896ea3a561df768d64 Mon Sep 17 00:00:00 2001
142+From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
143+Date: Fri, 1 Mar 2019 14:19:11 +1100
144+Subject: [PATCH 1/2] target/ppc/spapr: Add workaround option to SPAPR_CAP_IBS
145+
146+The spapr_cap SPAPR_CAP_IBS is used to indicate the level of capability
147+for mitigations for indirect branch speculation. Currently the available
148+values are broken (default), fixed-ibs (fixed by serialising indirect
149+branches) and fixed-ccd (fixed by diabling the count cache).
150+
151+Introduce a new value for this capability denoted workaround, meaning that
152+software can work around the issue by flushing the count cache on
153+context switch. This option is available if the hypervisor sets the
154+H_CPU_BEHAV_FLUSH_COUNT_CACHE flag in the cpu behaviours returned from
155+the KVM_PPC_GET_CPU_CHAR ioctl.
156+
157+Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
158+Message-Id: <20190301031912.28809-1-sjitindarsingh@gmail.com>
159+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
160+
161+Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=399b2896d4948a1ec0278d896ea3a561df768d64
162+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1832622
163+Last-Update: 2019-06-13
164+
165+---
166+ hw/ppc/spapr_caps.c | 21 ++++++++++-----------
167+ hw/ppc/spapr_hcall.c | 5 +++++
168+ include/hw/ppc/spapr.h | 7 +++++++
169+ target/ppc/kvm.c | 8 +++++++-
170+ 4 files changed, 29 insertions(+), 12 deletions(-)
171+
172+diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
173+index faab472d06..ca35b5153d 100644
174+--- a/hw/ppc/spapr_caps.c
175++++ b/hw/ppc/spapr_caps.c
176+@@ -276,11 +276,13 @@ static void cap_safe_bounds_check_apply(sPAPRMachineState *spapr, uint8_t val,
177+ }
178+
179+ sPAPRCapPossible cap_ibs_possible = {
180+- .num = 4,
181++ .num = 5,
182+ /* Note workaround only maintained for compatibility */
183+- .vals = {"broken", "workaround", "fixed-ibs", "fixed-ccd"},
184+- .help = "broken - no protection, fixed-ibs - indirect branch serialisation,"
185+- " fixed-ccd - cache count disabled",
186++ .vals = {"broken", "workaround", "fixed-ibs", "fixed-ccd", "fixed-na"},
187++ .help = "broken - no protection, workaround - count cache flush"
188++ ", fixed-ibs - indirect branch serialisation,"
189++ " fixed-ccd - cache count disabled,"
190++ " fixed-na - fixed in hardware (no longer applicable)",
191+ };
192+
193+ static void cap_safe_indirect_branch_apply(sPAPRMachineState *spapr,
194+@@ -288,15 +290,11 @@ static void cap_safe_indirect_branch_apply(sPAPRMachineState *spapr,
195+ {
196+ uint8_t kvm_val = kvmppc_get_cap_safe_indirect_branch();
197+
198+- if (val == SPAPR_CAP_WORKAROUND) { /* Can only be Broken or Fixed */
199+- error_setg(errp,
200+-"Requested safe indirect branch capability level \"workaround\" not valid, try cap-ibs=%s",
201+- cap_ibs_possible.vals[kvm_val]);
202+- } else if (tcg_enabled() && val) {
203++ if (tcg_enabled() && val) {
204+ /* TODO - for now only allow broken for TCG */
205+ error_setg(errp,
206+ "Requested safe indirect branch capability level not supported by tcg, try a different value for cap-ibs");
207+- } else if (kvm_enabled() && val && (val != kvm_val)) {
208++ } else if (kvm_enabled() && (val > kvm_val)) {
209+ error_setg(errp,
210+ "Requested safe indirect branch capability level not supported by kvm, try cap-ibs=%s",
211+ cap_ibs_possible.vals[kvm_val]);
212+@@ -494,7 +492,8 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
213+ [SPAPR_CAP_IBS] = {
214+ .name = "ibs",
215+ .description =
216+- "Indirect Branch Speculation (broken, fixed-ibs, fixed-ccd)",
217++ "Indirect Branch Speculation (broken, workaround, fixed-ibs,"
218++ "fixed-ccd, fixed-na)",
219+ .index = SPAPR_CAP_IBS,
220+ .get = spapr_cap_get_string,
221+ .set = spapr_cap_set_string,
222+diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
223+index 476bad6271..4aa8036fc0 100644
224+--- a/hw/ppc/spapr_hcall.c
225++++ b/hw/ppc/spapr_hcall.c
226+@@ -1723,12 +1723,17 @@ static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
227+ }
228+
229+ switch (safe_indirect_branch) {
230++ case SPAPR_CAP_FIXED_NA:
231++ break;
232+ case SPAPR_CAP_FIXED_CCD:
233+ characteristics |= H_CPU_CHAR_CACHE_COUNT_DIS;
234+ break;
235+ case SPAPR_CAP_FIXED_IBS:
236+ characteristics |= H_CPU_CHAR_BCCTRL_SERIALISED;
237+ break;
238++ case SPAPR_CAP_WORKAROUND:
239++ behaviour |= H_CPU_BEHAV_FLUSH_COUNT_CACHE;
240++ break;
241+ default: /* broken */
242+ assert(safe_indirect_branch == SPAPR_CAP_BROKEN);
243+ break;
244+diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
245+index 8efc5e0779..a7f3b1bfdd 100644
246+--- a/include/hw/ppc/spapr.h
247++++ b/include/hw/ppc/spapr.h
248+@@ -85,12 +85,17 @@ typedef enum {
249+ /* Bool Caps */
250+ #define SPAPR_CAP_OFF 0x00
251+ #define SPAPR_CAP_ON 0x01
252++
253+ /* Custom Caps */
254++
255++/* Generic */
256+ #define SPAPR_CAP_BROKEN 0x00
257+ #define SPAPR_CAP_WORKAROUND 0x01
258+ #define SPAPR_CAP_FIXED 0x02
259++/* SPAPR_CAP_IBS (cap-ibs) */
260+ #define SPAPR_CAP_FIXED_IBS 0x02
261+ #define SPAPR_CAP_FIXED_CCD 0x03
262++#define SPAPR_CAP_FIXED_NA 0x10 /* Lets leave a bit of a gap... */
263+
264+ typedef struct sPAPRCapabilities sPAPRCapabilities;
265+ struct sPAPRCapabilities {
266+@@ -339,9 +344,11 @@ struct sPAPRMachineState {
267+ #define H_CPU_CHAR_HON_BRANCH_HINTS PPC_BIT(5)
268+ #define H_CPU_CHAR_THR_RECONF_TRIG PPC_BIT(6)
269+ #define H_CPU_CHAR_CACHE_COUNT_DIS PPC_BIT(7)
270++#define H_CPU_CHAR_BCCTR_FLUSH_ASSIST PPC_BIT(9)
271+ #define H_CPU_BEHAV_FAVOUR_SECURITY PPC_BIT(0)
272+ #define H_CPU_BEHAV_L1D_FLUSH_PR PPC_BIT(1)
273+ #define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR PPC_BIT(2)
274++#define H_CPU_BEHAV_FLUSH_COUNT_CACHE PPC_BIT(5)
275+
276+ /* Each control block has to be on a 4K boundary */
277+ #define H_CB_ALIGNMENT 4096
278+diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
279+index f0f5bf9391..4d46314276 100644
280+--- a/target/ppc/kvm.c
281++++ b/target/ppc/kvm.c
282+@@ -2392,7 +2392,13 @@ static int parse_cap_ppc_safe_bounds_check(struct kvm_ppc_cpu_char c)
283+
284+ static int parse_cap_ppc_safe_indirect_branch(struct kvm_ppc_cpu_char c)
285+ {
286+- if (c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) {
287++ if ((~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_FLUSH_COUNT_CACHE) &&
288++ (~c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) &&
289++ (~c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED)) {
290++ return SPAPR_CAP_FIXED_NA;
291++ } else if (c.behaviour & c.behaviour_mask & H_CPU_BEHAV_FLUSH_COUNT_CACHE) {
292++ return SPAPR_CAP_WORKAROUND;
293++ } else if (c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) {
294+ return SPAPR_CAP_FIXED_CCD;
295+ } else if (c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED) {
296+ return SPAPR_CAP_FIXED_IBS;
297+--
298+2.21.0
299+
300diff --git a/debian/patches/ubuntu/lp-1832622-0003-ppc-spapr-caps-Change-migration-macro-to-take-full-s.patch b/debian/patches/ubuntu/lp-1832622-0003-ppc-spapr-caps-Change-migration-macro-to-take-full-s.patch
301new file mode 100644
302index 0000000..edc84b7
303--- /dev/null
304+++ b/debian/patches/ubuntu/lp-1832622-0003-ppc-spapr-caps-Change-migration-macro-to-take-full-s.patch
305@@ -0,0 +1,79 @@
306+From 8c5909c41916f25b47bfdc465059a926603c1319 Mon Sep 17 00:00:00 2001
307+From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
308+Date: Thu, 15 Feb 2018 11:44:41 +1100
309+Subject: [PATCH] ppc/spapr-caps: Change migration macro to take full spapr-cap
310+ name
311+
312+Change the macro that generates the vmstate migration field and the needed
313+function for the spapr-caps to take the full spapr-cap name. This has
314+the benefit of meaning this instance will be picked up when greping
315+for the spapr-caps and making it more obvious what this macro is doing.
316+
317+Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
318+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
319+
320+Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=8c5909c41916f25b47bfdc465059a926603c1319
321+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1832622
322+Last-Update: 2019-06-13
323+
324+---
325+ hw/ppc/spapr_caps.c | 30 +++++++++++++++---------------
326+ 1 file changed, 15 insertions(+), 15 deletions(-)
327+
328+diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
329+index 62efdaee38..e69d308560 100644
330+--- a/hw/ppc/spapr_caps.c
331++++ b/hw/ppc/spapr_caps.c
332+@@ -350,34 +350,34 @@ int spapr_caps_post_migration(sPAPRMachineState *spapr)
333+ }
334+
335+ /* Used to generate the migration field and needed function for a spapr cap */
336+-#define SPAPR_CAP_MIG_STATE(cap, ccap) \
337+-static bool spapr_cap_##cap##_needed(void *opaque) \
338++#define SPAPR_CAP_MIG_STATE(sname, cap) \
339++static bool spapr_cap_##sname##_needed(void *opaque) \
340+ { \
341+ sPAPRMachineState *spapr = opaque; \
342+ \
343+- return spapr->cmd_line_caps[SPAPR_CAP_##ccap] && \
344+- (spapr->eff.caps[SPAPR_CAP_##ccap] != \
345+- spapr->def.caps[SPAPR_CAP_##ccap]); \
346++ return spapr->cmd_line_caps[cap] && \
347++ (spapr->eff.caps[cap] != \
348++ spapr->def.caps[cap]); \
349+ } \
350+ \
351+-const VMStateDescription vmstate_spapr_cap_##cap = { \
352+- .name = "spapr/cap/" #cap, \
353++const VMStateDescription vmstate_spapr_cap_##sname = { \
354++ .name = "spapr/cap/" #sname, \
355+ .version_id = 1, \
356+ .minimum_version_id = 1, \
357+- .needed = spapr_cap_##cap##_needed, \
358++ .needed = spapr_cap_##sname##_needed, \
359+ .fields = (VMStateField[]) { \
360+- VMSTATE_UINT8(mig.caps[SPAPR_CAP_##ccap], \
361++ VMSTATE_UINT8(mig.caps[cap], \
362+ sPAPRMachineState), \
363+ VMSTATE_END_OF_LIST() \
364+ }, \
365+ }
366+
367+-SPAPR_CAP_MIG_STATE(htm, HTM);
368+-SPAPR_CAP_MIG_STATE(vsx, VSX);
369+-SPAPR_CAP_MIG_STATE(dfp, DFP);
370+-SPAPR_CAP_MIG_STATE(cfpc, CFPC);
371+-SPAPR_CAP_MIG_STATE(sbbc, SBBC);
372+-SPAPR_CAP_MIG_STATE(ibs, IBS);
373++SPAPR_CAP_MIG_STATE(htm, SPAPR_CAP_HTM);
374++SPAPR_CAP_MIG_STATE(vsx, SPAPR_CAP_VSX);
375++SPAPR_CAP_MIG_STATE(dfp, SPAPR_CAP_DFP);
376++SPAPR_CAP_MIG_STATE(cfpc, SPAPR_CAP_CFPC);
377++SPAPR_CAP_MIG_STATE(sbbc, SPAPR_CAP_SBBC);
378++SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);
379+
380+ void spapr_caps_reset(sPAPRMachineState *spapr)
381+ {
382+--
383+2.21.0
384+
385diff --git a/debian/patches/ubuntu/lp-1832622-0004-target-ppc-spapr-Add-SPAPR_CAP_CCF_ASSIST.patch b/debian/patches/ubuntu/lp-1832622-0004-target-ppc-spapr-Add-SPAPR_CAP_CCF_ASSIST.patch
386new file mode 100644
387index 0000000..21969ec
388--- /dev/null
389+++ b/debian/patches/ubuntu/lp-1832622-0004-target-ppc-spapr-Add-SPAPR_CAP_CCF_ASSIST.patch
390@@ -0,0 +1,239 @@
391+From 77012c6029ae15328f04ddcb713f459cdacffef9 Mon Sep 17 00:00:00 2001
392+From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
393+Date: Fri, 1 Mar 2019 14:19:12 +1100
394+Subject: [PATCH] target/ppc/spapr: Add SPAPR_CAP_CCF_ASSIST
395+
396+Introduce a new spapr_cap SPAPR_CAP_CCF_ASSIST to be used to indicate
397+the requirement for a hw-assisted version of the count cache flush
398+workaround.
399+
400+The count cache flush workaround is a software workaround which can be
401+used to flush the count cache on context switch. Some revisions of
402+hardware may have a hardware accelerated flush, in which case the
403+software flush can be shortened. This cap is used to set the
404+availability of such hardware acceleration for the count cache flush
405+routine.
406+
407+The availability of such hardware acceleration is indicated by the
408+H_CPU_CHAR_BCCTR_FLUSH_ASSIST flag being set in the characteristics
409+returned from the KVM_PPC_GET_CPU_CHAR ioctl.
410+
411+Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
412+Message-Id: <20190301031912.28809-2-sjitindarsingh@gmail.com>
413+[dwg: Small style fixes]
414+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
415+(cherry picked from commit 8ff43ee404d3e295839d1fd4e9e6571ca7a62a66)
416+* remove context dependencies on post-2.11 capabilities and migration
417+ state
418+* adjust SPAPR_CAP_CCF_ASSIST to be next avail index (SPAPR_CAP_IBS + 1)
419+Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
420+(cherry picked from commit 2cdaf75db8ac825cb4b8b6a00b7bb114941cc51d)
421+Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
422+
423+Author: Michael Roth <mdroth@linux.vnet.ibm.com>
424+Origin: upstream, https://git.qemu.org/?p=qemu.git;a=commit;h=8ff43ee404d3e295839d1fd4e9e6571ca7a62a66
425+Origin: backport, https://github.com/mdroth/qemu/commit/77012c6029ae15328f04ddcb713f459cdacffef9
426+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1832622
427+Last-Update: 2019-06-13
428+
429+---
430+ hw/ppc/spapr.c | 2 ++
431+ hw/ppc/spapr_caps.c | 25 +++++++++++++++++++++++++
432+ hw/ppc/spapr_hcall.c | 5 +++++
433+ include/hw/ppc/spapr.h | 5 ++++-
434+ target/ppc/kvm.c | 16 ++++++++++++++++
435+ target/ppc/kvm_ppc.h | 6 ++++++
436+ 6 files changed, 58 insertions(+), 1 deletion(-)
437+
438+diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
439+index 90ea7f367c..3a9ca6342e 100644
440+--- a/hw/ppc/spapr.c
441++++ b/hw/ppc/spapr.c
442+@@ -1754,6 +1754,7 @@ static const VMStateDescription vmstate_spapr = {
443+ &vmstate_spapr_cap_cfpc,
444+ &vmstate_spapr_cap_sbbc,
445+ &vmstate_spapr_cap_ibs,
446++ &vmstate_spapr_cap_ccf_assist,
447+ NULL
448+ }
449+ };
450+@@ -3733,6 +3734,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
451+ smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_BROKEN;
452+ smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_BROKEN;
453+ smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_BROKEN;
454++ smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF;
455+ spapr_caps_add_properties(smc, &error_abort);
456+ }
457+
458+diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
459+index cabbd4a0bc..0041c112ec 100644
460+--- a/hw/ppc/spapr_caps.c
461++++ b/hw/ppc/spapr_caps.c
462+@@ -264,6 +264,21 @@ static void cap_safe_indirect_branch_apply(sPAPRMachineState *spapr,
463+
464+ #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)"
465+
466++static void cap_ccf_assist_apply(sPAPRMachineState *spapr, uint8_t val,
467++ Error **errp)
468++{
469++ uint8_t kvm_val = kvmppc_get_cap_count_cache_flush_assist();
470++
471++ if (tcg_enabled() && val) {
472++ /* TODO - for now only allow broken for TCG */
473++ error_setg(errp,
474++"Requested count cache flush assist capability level not supported by tcg, try cap-ccf-assist=off");
475++ } else if (kvm_enabled() && (val > kvm_val)) {
476++ error_setg(errp,
477++"Requested count cache flush assist capability level not supported by kvm, try cap-ccf-assist=off");
478++ }
479++}
480++
481+ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
482+ [SPAPR_CAP_HTM] = {
483+ .name = "htm",
484+@@ -327,6 +342,15 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
485+ .possible = &cap_ibs_possible,
486+ .apply = cap_safe_indirect_branch_apply,
487+ },
488++ [SPAPR_CAP_CCF_ASSIST] = {
489++ .name = "ccf-assist",
490++ .description = "Count Cache Flush Assist via HW Instruction",
491++ .index = SPAPR_CAP_CCF_ASSIST,
492++ .get = spapr_cap_get_bool,
493++ .set = spapr_cap_set_bool,
494++ .type = "bool",
495++ .apply = cap_ccf_assist_apply,
496++ },
497+ };
498+
499+ static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr,
500+@@ -446,6 +470,7 @@ SPAPR_CAP_MIG_STATE(dfp, SPAPR_CAP_DFP);
501+ SPAPR_CAP_MIG_STATE(cfpc, SPAPR_CAP_CFPC);
502+ SPAPR_CAP_MIG_STATE(sbbc, SPAPR_CAP_SBBC);
503+ SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);
504++SPAPR_CAP_MIG_STATE(ccf_assist, SPAPR_CAP_CCF_ASSIST);
505+
506+ void spapr_caps_reset(sPAPRMachineState *spapr)
507+ {
508+diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
509+index 779d097bd7..1660ef1d63 100644
510+--- a/hw/ppc/spapr_hcall.c
511++++ b/hw/ppc/spapr_hcall.c
512+@@ -1666,6 +1666,8 @@ static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
513+ uint8_t safe_cache = spapr_get_cap(spapr, SPAPR_CAP_CFPC);
514+ uint8_t safe_bounds_check = spapr_get_cap(spapr, SPAPR_CAP_SBBC);
515+ uint8_t safe_indirect_branch = spapr_get_cap(spapr, SPAPR_CAP_IBS);
516++ uint8_t count_cache_flush_assist = spapr_get_cap(spapr,
517++ SPAPR_CAP_CCF_ASSIST);
518+
519+ switch (safe_cache) {
520+ case SPAPR_CAP_WORKAROUND:
521+@@ -1706,6 +1708,9 @@ static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
522+ break;
523+ case SPAPR_CAP_WORKAROUND:
524+ behaviour |= H_CPU_BEHAV_FLUSH_COUNT_CACHE;
525++ if (count_cache_flush_assist) {
526++ characteristics |= H_CPU_CHAR_BCCTR_FLUSH_ASSIST;
527++ }
528+ break;
529+ default: /* broken */
530+ assert(safe_indirect_branch == SPAPR_CAP_BROKEN);
531+diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
532+index 15cdcb3ef6..011afb62d7 100644
533+--- a/include/hw/ppc/spapr.h
534++++ b/include/hw/ppc/spapr.h
535+@@ -66,8 +66,10 @@ typedef enum {
536+ #define SPAPR_CAP_SBBC 0x04
537+ /* Indirect Branch Serialisation */
538+ #define SPAPR_CAP_IBS 0x05
539++/* Count Cache Flush Assist HW Instruction */
540++#define SPAPR_CAP_CCF_ASSIST 0x06
541+ /* Num Caps */
542+-#define SPAPR_CAP_NUM (SPAPR_CAP_IBS + 1)
543++#define SPAPR_CAP_NUM (SPAPR_CAP_CCF_ASSIST + 1)
544+
545+ /*
546+ * Capability Values
547+@@ -781,6 +783,7 @@ extern const VMStateDescription vmstate_spapr_cap_dfp;
548+ extern const VMStateDescription vmstate_spapr_cap_cfpc;
549+ extern const VMStateDescription vmstate_spapr_cap_sbbc;
550+ extern const VMStateDescription vmstate_spapr_cap_ibs;
551++extern const VMStateDescription vmstate_spapr_cap_ccf_assist;
552+
553+ static inline uint8_t spapr_get_cap(sPAPRMachineState *spapr, int cap)
554+ {
555+diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
556+index 89b52eb1d4..b8bb16bc59 100644
557+--- a/target/ppc/kvm.c
558++++ b/target/ppc/kvm.c
559+@@ -95,6 +95,7 @@ static int cap_ppc_pvr_compat;
560+ static int cap_ppc_safe_cache;
561+ static int cap_ppc_safe_bounds_check;
562+ static int cap_ppc_safe_indirect_branch;
563++static int cap_ppc_count_cache_flush_assist;
564+
565+ static uint32_t debug_inst_opcode;
566+
567+@@ -2505,6 +2506,14 @@ static int parse_cap_ppc_safe_indirect_branch(struct kvm_ppc_cpu_char c)
568+ return 0;
569+ }
570+
571++static int parse_cap_ppc_count_cache_flush_assist(struct kvm_ppc_cpu_char c)
572++{
573++ if (c.character & c.character_mask & H_CPU_CHAR_BCCTR_FLUSH_ASSIST) {
574++ return 1;
575++ }
576++ return 0;
577++}
578++
579+ static void kvmppc_get_cpu_characteristics(KVMState *s)
580+ {
581+ struct kvm_ppc_cpu_char c;
582+@@ -2527,6 +2536,8 @@ static void kvmppc_get_cpu_characteristics(KVMState *s)
583+ cap_ppc_safe_cache = parse_cap_ppc_safe_cache(c);
584+ cap_ppc_safe_bounds_check = parse_cap_ppc_safe_bounds_check(c);
585+ cap_ppc_safe_indirect_branch = parse_cap_ppc_safe_indirect_branch(c);
586++ cap_ppc_count_cache_flush_assist =
587++ parse_cap_ppc_count_cache_flush_assist(c);
588+ }
589+
590+ int kvmppc_get_cap_safe_cache(void)
591+@@ -2544,6 +2555,11 @@ int kvmppc_get_cap_safe_indirect_branch(void)
592+ return cap_ppc_safe_indirect_branch;
593+ }
594+
595++int kvmppc_get_cap_count_cache_flush_assist(void)
596++{
597++ return cap_ppc_count_cache_flush_assist;
598++}
599++
600+ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
601+ {
602+ uint32_t host_pvr = mfpvr();
603+diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
604+index 39830baa77..d634b7139e 100644
605+--- a/target/ppc/kvm_ppc.h
606++++ b/target/ppc/kvm_ppc.h
607+@@ -62,6 +62,7 @@ bool kvmppc_has_cap_mmu_hash_v3(void);
608+ int kvmppc_get_cap_safe_cache(void);
609+ int kvmppc_get_cap_safe_bounds_check(void);
610+ int kvmppc_get_cap_safe_indirect_branch(void);
611++int kvmppc_get_cap_count_cache_flush_assist(void);
612+ int kvmppc_enable_hwrng(void);
613+ int kvmppc_put_books_sregs(PowerPCCPU *cpu);
614+ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
615+@@ -308,6 +309,11 @@ static inline int kvmppc_get_cap_safe_indirect_branch(void)
616+ return 0;
617+ }
618+
619++static inline int kvmppc_get_cap_count_cache_flush_assist(void)
620++{
621++ return 0;
622++}
623++
624+ static inline int kvmppc_enable_hwrng(void)
625+ {
626+ return -1;
627+--
628+2.21.0
629+

Subscribers

People subscribed via source and target branches