2 * QEMU PowerPC pSeries Logical Partition capabilities handling
4 * Copyright (c) 2017 David Gibson, Red Hat Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu/error-report.h"
27 #include "qapi/error.h"
28 #include "qapi/visitor.h"
29 #include "sysemu/hw_accel.h"
30 #include "exec/ram_addr.h"
31 #include "target/ppc/cpu.h"
32 #include "target/ppc/mmu-hash64.h"
33 #include "cpu-models.h"
35 #include "migration/vmstate.h"
36 #include "sysemu/tcg.h"
38 #include "hw/ppc/spapr.h"
40 typedef struct SpaprCapPossible
{
41 int num
; /* size of vals array below */
42 const char *help
; /* help text for vals */
45 * - because of the way compatibility is determined vals MUST be ordered
46 * such that later options are a superset of all preceding options.
47 * - the order of vals must be preserved, that is their index is important,
48 * however vals may be added to the end of the list so long as the above
54 typedef struct SpaprCapabilityInfo
{
56 const char *description
;
59 /* Getter and Setter Function Pointers */
60 ObjectPropertyAccessor
*get
;
61 ObjectPropertyAccessor
*set
;
63 /* Possible values if this is a custom string type */
64 SpaprCapPossible
*possible
;
65 /* Make sure the virtual hardware can support this capability */
66 void (*apply
)(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
);
67 void (*cpu_apply
)(SpaprMachineState
*spapr
, PowerPCCPU
*cpu
,
68 uint8_t val
, Error
**errp
);
69 bool (*migrate_needed
)(void *opaque
);
70 } SpaprCapabilityInfo
;
72 static void spapr_cap_get_bool(Object
*obj
, Visitor
*v
, const char *name
,
73 void *opaque
, Error
**errp
)
75 SpaprCapabilityInfo
*cap
= opaque
;
76 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
77 bool value
= spapr_get_cap(spapr
, cap
->index
) == SPAPR_CAP_ON
;
79 visit_type_bool(v
, name
, &value
, errp
);
82 static void spapr_cap_set_bool(Object
*obj
, Visitor
*v
, const char *name
,
83 void *opaque
, Error
**errp
)
85 SpaprCapabilityInfo
*cap
= opaque
;
86 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
89 if (!visit_type_bool(v
, name
, &value
, errp
)) {
93 spapr
->cmd_line_caps
[cap
->index
] = true;
94 spapr
->eff
.caps
[cap
->index
] = value
? SPAPR_CAP_ON
: SPAPR_CAP_OFF
;
98 static void spapr_cap_get_string(Object
*obj
, Visitor
*v
, const char *name
,
99 void *opaque
, Error
**errp
)
101 SpaprCapabilityInfo
*cap
= opaque
;
102 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
103 g_autofree
char *val
= NULL
;
104 uint8_t value
= spapr_get_cap(spapr
, cap
->index
);
106 if (value
>= cap
->possible
->num
) {
107 error_setg(errp
, "Invalid value (%d) for cap-%s", value
, cap
->name
);
111 val
= g_strdup(cap
->possible
->vals
[value
]);
113 visit_type_str(v
, name
, &val
, errp
);
116 static void spapr_cap_set_string(Object
*obj
, Visitor
*v
, const char *name
,
117 void *opaque
, Error
**errp
)
119 SpaprCapabilityInfo
*cap
= opaque
;
120 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
122 g_autofree
char *val
= NULL
;
124 if (!visit_type_str(v
, name
, &val
, errp
)) {
128 if (!strcmp(val
, "?")) {
129 error_setg(errp
, "%s", cap
->possible
->help
);
132 for (i
= 0; i
< cap
->possible
->num
; i
++) {
133 if (!strcasecmp(val
, cap
->possible
->vals
[i
])) {
134 spapr
->cmd_line_caps
[cap
->index
] = true;
135 spapr
->eff
.caps
[cap
->index
] = i
;
140 error_setg(errp
, "Invalid capability mode \"%s\" for cap-%s", val
,
144 static void spapr_cap_get_pagesize(Object
*obj
, Visitor
*v
, const char *name
,
145 void *opaque
, Error
**errp
)
147 SpaprCapabilityInfo
*cap
= opaque
;
148 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
149 uint8_t val
= spapr_get_cap(spapr
, cap
->index
);
150 uint64_t pagesize
= (1ULL << val
);
152 visit_type_size(v
, name
, &pagesize
, errp
);
155 static void spapr_cap_set_pagesize(Object
*obj
, Visitor
*v
, const char *name
,
156 void *opaque
, Error
**errp
)
158 SpaprCapabilityInfo
*cap
= opaque
;
159 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
163 if (!visit_type_size(v
, name
, &pagesize
, errp
)) {
167 if (!is_power_of_2(pagesize
)) {
168 error_setg(errp
, "cap-%s must be a power of 2", cap
->name
);
172 val
= ctz64(pagesize
);
173 spapr
->cmd_line_caps
[cap
->index
] = true;
174 spapr
->eff
.caps
[cap
->index
] = val
;
177 static void cap_htm_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
181 /* TODO: We don't support disabling htm yet */
185 error_setg(errp
, "No Transactional Memory support in TCG");
186 error_append_hint(errp
, "Try appending -machine cap-htm=off\n");
187 } else if (kvm_enabled() && !kvmppc_has_cap_htm()) {
189 "KVM implementation does not support Transactional Memory");
190 error_append_hint(errp
, "Try appending -machine cap-htm=off\n");
194 static void cap_vsx_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
197 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
198 CPUPPCState
*env
= &cpu
->env
;
201 /* TODO: We don't support disabling vsx yet */
204 /* Allowable CPUs in spapr_cpu_core.c should already have gotten
205 * rid of anything that doesn't do VMX */
206 g_assert(env
->insns_flags
& PPC_ALTIVEC
);
207 if (!(env
->insns_flags2
& PPC2_VSX
)) {
208 error_setg(errp
, "VSX support not available");
209 error_append_hint(errp
, "Try appending -machine cap-vsx=off\n");
213 static void cap_dfp_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
216 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
217 CPUPPCState
*env
= &cpu
->env
;
220 /* TODO: We don't support disabling dfp yet */
223 if (!(env
->insns_flags2
& PPC2_DFP
)) {
224 error_setg(errp
, "DFP support not available");
225 error_append_hint(errp
, "Try appending -machine cap-dfp=off\n");
229 SpaprCapPossible cap_cfpc_possible
= {
231 .vals
= {"broken", "workaround", "fixed"},
232 .help
= "broken - no protection, workaround - workaround available,"
233 " fixed - fixed in hardware",
236 static void cap_safe_cache_apply(SpaprMachineState
*spapr
, uint8_t val
,
240 uint8_t kvm_val
= kvmppc_get_cap_safe_cache();
242 if (tcg_enabled() && val
) {
243 /* TCG only supports broken, allow other values and print a warning */
244 warn_report("TCG doesn't support requested feature, cap-cfpc=%s",
245 cap_cfpc_possible
.vals
[val
]);
246 } else if (kvm_enabled() && (val
> kvm_val
)) {
248 "Requested safe cache capability level not supported by KVM");
249 error_append_hint(errp
, "Try appending -machine cap-cfpc=%s\n",
250 cap_cfpc_possible
.vals
[kvm_val
]);
254 SpaprCapPossible cap_sbbc_possible
= {
256 .vals
= {"broken", "workaround", "fixed"},
257 .help
= "broken - no protection, workaround - workaround available,"
258 " fixed - fixed in hardware",
261 static void cap_safe_bounds_check_apply(SpaprMachineState
*spapr
, uint8_t val
,
265 uint8_t kvm_val
= kvmppc_get_cap_safe_bounds_check();
267 if (tcg_enabled() && val
) {
268 /* TCG only supports broken, allow other values and print a warning */
269 warn_report("TCG doesn't support requested feature, cap-sbbc=%s",
270 cap_sbbc_possible
.vals
[val
]);
271 } else if (kvm_enabled() && (val
> kvm_val
)) {
273 "Requested safe bounds check capability level not supported by KVM");
274 error_append_hint(errp
, "Try appending -machine cap-sbbc=%s\n",
275 cap_sbbc_possible
.vals
[kvm_val
]);
279 SpaprCapPossible cap_ibs_possible
= {
281 /* Note workaround only maintained for compatibility */
282 .vals
= {"broken", "workaround", "fixed-ibs", "fixed-ccd", "fixed-na"},
283 .help
= "broken - no protection, workaround - count cache flush"
284 ", fixed-ibs - indirect branch serialisation,"
285 " fixed-ccd - cache count disabled,"
286 " fixed-na - fixed in hardware (no longer applicable)",
289 static void cap_safe_indirect_branch_apply(SpaprMachineState
*spapr
,
290 uint8_t val
, Error
**errp
)
293 uint8_t kvm_val
= kvmppc_get_cap_safe_indirect_branch();
295 if (tcg_enabled() && val
) {
296 /* TCG only supports broken, allow other values and print a warning */
297 warn_report("TCG doesn't support requested feature, cap-ibs=%s",
298 cap_ibs_possible
.vals
[val
]);
299 } else if (kvm_enabled() && (val
> kvm_val
)) {
301 "Requested safe indirect branch capability level not supported by KVM");
302 error_append_hint(errp
, "Try appending -machine cap-ibs=%s\n",
303 cap_ibs_possible
.vals
[kvm_val
]);
307 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)"
309 bool spapr_check_pagesize(SpaprMachineState
*spapr
, hwaddr pagesize
,
312 hwaddr maxpagesize
= (1ULL << spapr
->eff
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
]);
314 if (!kvmppc_hpt_needs_host_contiguous_pages()) {
318 if (maxpagesize
> pagesize
) {
320 "Can't support %"HWADDR_PRIu
" kiB guest pages with %"
321 HWADDR_PRIu
" kiB host pages with this KVM implementation",
322 maxpagesize
>> 10, pagesize
>> 10);
329 static void cap_hpt_maxpagesize_apply(SpaprMachineState
*spapr
,
330 uint8_t val
, Error
**errp
)
333 error_setg(errp
, "Require at least 4kiB hpt-max-page-size");
335 } else if (val
< 16) {
336 warn_report("Many guests require at least 64kiB hpt-max-page-size");
339 spapr_check_pagesize(spapr
, qemu_minrampagesize(), errp
);
342 static bool cap_hpt_maxpagesize_migrate_needed(void *opaque
)
344 return !SPAPR_MACHINE_GET_CLASS(opaque
)->pre_4_1_migration
;
347 static bool spapr_pagesize_cb(void *opaque
, uint32_t seg_pshift
,
350 unsigned maxshift
= *((unsigned *)opaque
);
352 assert(pshift
>= seg_pshift
);
354 /* Don't allow the guest to use pages bigger than the configured
356 if (pshift
> maxshift
) {
360 /* For whatever reason, KVM doesn't allow multiple pagesizes
361 * within a segment, *except* for the case of 16M pages in a 4k or
362 * 64k segment. Always exclude other cases, so that TCG and KVM
363 * guests see a consistent environment */
364 if ((pshift
!= seg_pshift
) && (pshift
!= 24)) {
371 static void ppc_hash64_filter_pagesizes(PowerPCCPU
*cpu
,
372 bool (*cb
)(void *, uint32_t, uint32_t),
375 PPCHash64Options
*opts
= cpu
->hash64_opts
;
378 bool ci_largepage
= false;
383 for (i
= 0; i
< ARRAY_SIZE(opts
->sps
); i
++) {
384 PPCHash64SegmentPageSizes
*sps
= &opts
->sps
[i
];
390 if (!sps
->page_shift
) {
394 for (j
= 0; j
< ARRAY_SIZE(sps
->enc
); j
++) {
395 PPCHash64PageSize
*ps
= &sps
->enc
[j
];
398 if (!ps
->page_shift
) {
402 if (cb(opaque
, sps
->page_shift
, ps
->page_shift
)) {
403 if (ps
->page_shift
>= 16) {
410 /* Clear rest of the row */
411 for (j
= m
; j
< ARRAY_SIZE(sps
->enc
); j
++) {
412 memset(&sps
->enc
[j
], 0, sizeof(sps
->enc
[j
]));
420 /* Clear the rest of the table */
421 for (i
= n
; i
< ARRAY_SIZE(opts
->sps
); i
++) {
422 memset(&opts
->sps
[i
], 0, sizeof(opts
->sps
[i
]));
426 opts
->flags
&= ~PPC_HASH64_CI_LARGEPAGE
;
430 static void cap_hpt_maxpagesize_cpu_apply(SpaprMachineState
*spapr
,
432 uint8_t val
, Error
**errp
)
434 unsigned maxshift
= val
;
436 ppc_hash64_filter_pagesizes(cpu
, spapr_pagesize_cb
, &maxshift
);
439 static void cap_nested_kvm_hv_apply(SpaprMachineState
*spapr
,
440 uint8_t val
, Error
**errp
)
443 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
444 CPUPPCState
*env
= &cpu
->env
;
447 /* capability disabled by default */
451 if (!(env
->insns_flags2
& PPC2_ISA300
)) {
452 error_setg(errp
, "Nested-HV only supported on POWER9 and later");
453 error_append_hint(errp
, "Try appending -machine cap-nested-hv=off\n");
458 if (!ppc_check_compat(cpu
, CPU_POWERPC_LOGICAL_3_00
, 0,
459 spapr
->max_compat_pvr
)) {
460 error_setg(errp
, "Nested-HV only supported on POWER9 and later");
461 error_append_hint(errp
,
462 "Try appending -machine max-cpu-compat=power9\n");
466 if (!kvmppc_has_cap_nested_kvm_hv()) {
468 "KVM implementation does not support Nested-HV");
469 error_append_hint(errp
,
470 "Try appending -machine cap-nested-hv=off\n");
471 } else if (kvmppc_set_cap_nested_kvm_hv(val
) < 0) {
472 error_setg(errp
, "Error enabling cap-nested-hv with KVM");
473 error_append_hint(errp
,
474 "Try appending -machine cap-nested-hv=off\n");
479 static void cap_large_decr_apply(SpaprMachineState
*spapr
,
480 uint8_t val
, Error
**errp
)
483 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
484 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
487 return; /* Disabled by default */
491 if (!ppc_check_compat(cpu
, CPU_POWERPC_LOGICAL_3_00
, 0,
492 spapr
->max_compat_pvr
)) {
493 error_setg(errp
, "Large decrementer only supported on POWER9");
494 error_append_hint(errp
, "Try -cpu POWER9\n");
497 } else if (kvm_enabled()) {
498 int kvm_nr_bits
= kvmppc_get_cap_large_decr();
501 error_setg(errp
, "No large decrementer support");
502 error_append_hint(errp
,
503 "Try appending -machine cap-large-decr=off\n");
504 } else if (pcc
->lrg_decr_bits
!= kvm_nr_bits
) {
506 "KVM large decrementer size (%d) differs to model (%d)",
507 kvm_nr_bits
, pcc
->lrg_decr_bits
);
508 error_append_hint(errp
,
509 "Try appending -machine cap-large-decr=off\n");
514 static void cap_large_decr_cpu_apply(SpaprMachineState
*spapr
,
516 uint8_t val
, Error
**errp
)
519 CPUPPCState
*env
= &cpu
->env
;
520 target_ulong lpcr
= env
->spr
[SPR_LPCR
];
523 if (kvmppc_enable_cap_large_decr(cpu
, val
)) {
524 error_setg(errp
, "No large decrementer support");
525 error_append_hint(errp
,
526 "Try appending -machine cap-large-decr=off\n");
535 ppc_store_lpcr(cpu
, lpcr
);
538 static void cap_ccf_assist_apply(SpaprMachineState
*spapr
, uint8_t val
,
542 uint8_t kvm_val
= kvmppc_get_cap_count_cache_flush_assist();
544 if (tcg_enabled() && val
) {
545 /* TCG doesn't implement anything here, but allow with a warning */
546 warn_report("TCG doesn't support requested feature, cap-ccf-assist=on");
547 } else if (kvm_enabled() && (val
> kvm_val
)) {
548 uint8_t kvm_ibs
= kvmppc_get_cap_safe_indirect_branch();
550 if (kvm_ibs
== SPAPR_CAP_FIXED_CCD
) {
552 * If we don't have CCF assist on the host, the assist
553 * instruction is a harmless no-op. It won't correctly
554 * implement the cache count flush *but* if we have
555 * count-cache-disabled in the host, that flush is
556 * unnecessary. So, specifically allow this case. This
557 * allows us to have better performance on POWER9 DD2.3,
558 * while still working on POWER9 DD2.2 and POWER8 host
564 "Requested count cache flush assist capability level not supported by KVM");
565 error_append_hint(errp
, "Try appending -machine cap-ccf-assist=off\n");
569 static void cap_fwnmi_apply(SpaprMachineState
*spapr
, uint8_t val
,
574 return; /* Disabled by default */
578 if (!kvmppc_get_fwnmi()) {
580 "Firmware Assisted Non-Maskable Interrupts(FWNMI) not supported by KVM.");
581 error_append_hint(errp
, "Try appending -machine cap-fwnmi=off\n");
586 static void cap_rpt_invalidate_apply(SpaprMachineState
*spapr
,
587 uint8_t val
, Error
**errp
)
592 /* capability disabled by default */
597 error_setg(errp
, "No H_RPT_INVALIDATE support in TCG");
598 error_append_hint(errp
,
599 "Try appending -machine cap-rpt-invalidate=off\n");
600 } else if (kvm_enabled()) {
601 if (!kvmppc_has_cap_mmu_radix()) {
602 error_setg(errp
, "H_RPT_INVALIDATE only supported on Radix");
606 if (!kvmppc_has_cap_rpt_invalidate()) {
608 "KVM implementation does not support H_RPT_INVALIDATE");
609 error_append_hint(errp
,
610 "Try appending -machine cap-rpt-invalidate=off\n");
612 kvmppc_enable_h_rpt_invalidate();
617 SpaprCapabilityInfo capability_table
[SPAPR_CAP_NUM
] = {
620 .description
= "Allow Hardware Transactional Memory (HTM)",
621 .index
= SPAPR_CAP_HTM
,
622 .get
= spapr_cap_get_bool
,
623 .set
= spapr_cap_set_bool
,
625 .apply
= cap_htm_apply
,
629 .description
= "Allow Vector Scalar Extensions (VSX)",
630 .index
= SPAPR_CAP_VSX
,
631 .get
= spapr_cap_get_bool
,
632 .set
= spapr_cap_set_bool
,
634 .apply
= cap_vsx_apply
,
638 .description
= "Allow Decimal Floating Point (DFP)",
639 .index
= SPAPR_CAP_DFP
,
640 .get
= spapr_cap_get_bool
,
641 .set
= spapr_cap_set_bool
,
643 .apply
= cap_dfp_apply
,
647 .description
= "Cache Flush on Privilege Change" VALUE_DESC_TRISTATE
,
648 .index
= SPAPR_CAP_CFPC
,
649 .get
= spapr_cap_get_string
,
650 .set
= spapr_cap_set_string
,
652 .possible
= &cap_cfpc_possible
,
653 .apply
= cap_safe_cache_apply
,
657 .description
= "Speculation Barrier Bounds Checking" VALUE_DESC_TRISTATE
,
658 .index
= SPAPR_CAP_SBBC
,
659 .get
= spapr_cap_get_string
,
660 .set
= spapr_cap_set_string
,
662 .possible
= &cap_sbbc_possible
,
663 .apply
= cap_safe_bounds_check_apply
,
668 "Indirect Branch Speculation (broken, workaround, fixed-ibs,"
669 "fixed-ccd, fixed-na)",
670 .index
= SPAPR_CAP_IBS
,
671 .get
= spapr_cap_get_string
,
672 .set
= spapr_cap_set_string
,
674 .possible
= &cap_ibs_possible
,
675 .apply
= cap_safe_indirect_branch_apply
,
677 [SPAPR_CAP_HPT_MAXPAGESIZE
] = {
678 .name
= "hpt-max-page-size",
679 .description
= "Maximum page size for Hash Page Table guests",
680 .index
= SPAPR_CAP_HPT_MAXPAGESIZE
,
681 .get
= spapr_cap_get_pagesize
,
682 .set
= spapr_cap_set_pagesize
,
684 .apply
= cap_hpt_maxpagesize_apply
,
685 .cpu_apply
= cap_hpt_maxpagesize_cpu_apply
,
686 .migrate_needed
= cap_hpt_maxpagesize_migrate_needed
,
688 [SPAPR_CAP_NESTED_KVM_HV
] = {
690 .description
= "Allow Nested KVM-HV",
691 .index
= SPAPR_CAP_NESTED_KVM_HV
,
692 .get
= spapr_cap_get_bool
,
693 .set
= spapr_cap_set_bool
,
695 .apply
= cap_nested_kvm_hv_apply
,
697 [SPAPR_CAP_LARGE_DECREMENTER
] = {
698 .name
= "large-decr",
699 .description
= "Allow Large Decrementer",
700 .index
= SPAPR_CAP_LARGE_DECREMENTER
,
701 .get
= spapr_cap_get_bool
,
702 .set
= spapr_cap_set_bool
,
704 .apply
= cap_large_decr_apply
,
705 .cpu_apply
= cap_large_decr_cpu_apply
,
707 [SPAPR_CAP_CCF_ASSIST
] = {
708 .name
= "ccf-assist",
709 .description
= "Count Cache Flush Assist via HW Instruction",
710 .index
= SPAPR_CAP_CCF_ASSIST
,
711 .get
= spapr_cap_get_bool
,
712 .set
= spapr_cap_set_bool
,
714 .apply
= cap_ccf_assist_apply
,
716 [SPAPR_CAP_FWNMI
] = {
718 .description
= "Implements PAPR FWNMI option",
719 .index
= SPAPR_CAP_FWNMI
,
720 .get
= spapr_cap_get_bool
,
721 .set
= spapr_cap_set_bool
,
723 .apply
= cap_fwnmi_apply
,
725 [SPAPR_CAP_RPT_INVALIDATE
] = {
726 .name
= "rpt-invalidate",
727 .description
= "Allow H_RPT_INVALIDATE",
728 .index
= SPAPR_CAP_RPT_INVALIDATE
,
729 .get
= spapr_cap_get_bool
,
730 .set
= spapr_cap_set_bool
,
732 .apply
= cap_rpt_invalidate_apply
,
736 static SpaprCapabilities
default_caps_with_cpu(SpaprMachineState
*spapr
,
739 SpaprMachineClass
*smc
= SPAPR_MACHINE_GET_CLASS(spapr
);
740 SpaprCapabilities caps
;
742 caps
= smc
->default_caps
;
744 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_3_00
,
745 0, spapr
->max_compat_pvr
)) {
746 caps
.caps
[SPAPR_CAP_LARGE_DECREMENTER
] = SPAPR_CAP_OFF
;
749 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_07
,
750 0, spapr
->max_compat_pvr
)) {
751 caps
.caps
[SPAPR_CAP_HTM
] = SPAPR_CAP_OFF
;
752 caps
.caps
[SPAPR_CAP_CFPC
] = SPAPR_CAP_BROKEN
;
755 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_06_PLUS
,
756 0, spapr
->max_compat_pvr
)) {
757 caps
.caps
[SPAPR_CAP_SBBC
] = SPAPR_CAP_BROKEN
;
760 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_06
,
761 0, spapr
->max_compat_pvr
)) {
762 caps
.caps
[SPAPR_CAP_VSX
] = SPAPR_CAP_OFF
;
763 caps
.caps
[SPAPR_CAP_DFP
] = SPAPR_CAP_OFF
;
764 caps
.caps
[SPAPR_CAP_IBS
] = SPAPR_CAP_BROKEN
;
767 /* This is for pseries-2.12 and older */
768 if (smc
->default_caps
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
] == 0) {
771 if (kvmppc_hpt_needs_host_contiguous_pages()) {
772 mps
= ctz64(qemu_minrampagesize());
774 mps
= 34; /* allow everything up to 16GiB, i.e. everything */
777 caps
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
] = mps
;
783 int spapr_caps_pre_load(void *opaque
)
785 SpaprMachineState
*spapr
= opaque
;
787 /* Set to default so we can tell if this came in with the migration */
788 spapr
->mig
= spapr
->def
;
792 int spapr_caps_pre_save(void *opaque
)
794 SpaprMachineState
*spapr
= opaque
;
796 spapr
->mig
= spapr
->eff
;
800 /* This has to be called from the top-level spapr post_load, not the
801 * caps specific one. Otherwise it wouldn't be called when the source
802 * caps are all defaults, which could still conflict with overridden
803 * caps on the destination */
804 int spapr_caps_post_migration(SpaprMachineState
*spapr
)
808 SpaprCapabilities dstcaps
= spapr
->eff
;
809 SpaprCapabilities srccaps
;
811 srccaps
= default_caps_with_cpu(spapr
, MACHINE(spapr
)->cpu_type
);
812 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
813 /* If not default value then assume came in with the migration */
814 if (spapr
->mig
.caps
[i
] != spapr
->def
.caps
[i
]) {
815 srccaps
.caps
[i
] = spapr
->mig
.caps
[i
];
819 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
820 SpaprCapabilityInfo
*info
= &capability_table
[i
];
822 if (srccaps
.caps
[i
] > dstcaps
.caps
[i
]) {
823 error_report("cap-%s higher level (%d) in incoming stream than on destination (%d)",
824 info
->name
, srccaps
.caps
[i
], dstcaps
.caps
[i
]);
828 if (srccaps
.caps
[i
] < dstcaps
.caps
[i
]) {
829 warn_report("cap-%s lower level (%d) in incoming stream than on destination (%d)",
830 info
->name
, srccaps
.caps
[i
], dstcaps
.caps
[i
]);
834 return ok
? 0 : -EINVAL
;
837 /* Used to generate the migration field and needed function for a spapr cap */
838 #define SPAPR_CAP_MIG_STATE(sname, cap) \
839 static bool spapr_cap_##sname##_needed(void *opaque) \
841 SpaprMachineState *spapr = opaque; \
842 bool (*needed)(void *opaque) = \
843 capability_table[cap].migrate_needed; \
845 return needed ? needed(opaque) : true && \
846 spapr->cmd_line_caps[cap] && \
847 (spapr->eff.caps[cap] != \
848 spapr->def.caps[cap]); \
851 const VMStateDescription vmstate_spapr_cap_##sname = { \
852 .name = "spapr/cap/" #sname, \
854 .minimum_version_id = 1, \
855 .needed = spapr_cap_##sname##_needed, \
856 .fields = (VMStateField[]) { \
857 VMSTATE_UINT8(mig.caps[cap], \
858 SpaprMachineState), \
859 VMSTATE_END_OF_LIST() \
863 SPAPR_CAP_MIG_STATE(htm
, SPAPR_CAP_HTM
);
864 SPAPR_CAP_MIG_STATE(vsx
, SPAPR_CAP_VSX
);
865 SPAPR_CAP_MIG_STATE(dfp
, SPAPR_CAP_DFP
);
866 SPAPR_CAP_MIG_STATE(cfpc
, SPAPR_CAP_CFPC
);
867 SPAPR_CAP_MIG_STATE(sbbc
, SPAPR_CAP_SBBC
);
868 SPAPR_CAP_MIG_STATE(ibs
, SPAPR_CAP_IBS
);
869 SPAPR_CAP_MIG_STATE(hpt_maxpagesize
, SPAPR_CAP_HPT_MAXPAGESIZE
);
870 SPAPR_CAP_MIG_STATE(nested_kvm_hv
, SPAPR_CAP_NESTED_KVM_HV
);
871 SPAPR_CAP_MIG_STATE(large_decr
, SPAPR_CAP_LARGE_DECREMENTER
);
872 SPAPR_CAP_MIG_STATE(ccf_assist
, SPAPR_CAP_CCF_ASSIST
);
873 SPAPR_CAP_MIG_STATE(fwnmi
, SPAPR_CAP_FWNMI
);
874 SPAPR_CAP_MIG_STATE(rpt_invalidate
, SPAPR_CAP_RPT_INVALIDATE
);
876 void spapr_caps_init(SpaprMachineState
*spapr
)
878 SpaprCapabilities default_caps
;
881 /* Compute the actual set of caps we should run with */
882 default_caps
= default_caps_with_cpu(spapr
, MACHINE(spapr
)->cpu_type
);
884 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
885 /* Store the defaults */
886 spapr
->def
.caps
[i
] = default_caps
.caps
[i
];
887 /* If not set on the command line then apply the default value */
888 if (!spapr
->cmd_line_caps
[i
]) {
889 spapr
->eff
.caps
[i
] = default_caps
.caps
[i
];
894 void spapr_caps_apply(SpaprMachineState
*spapr
)
898 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
899 SpaprCapabilityInfo
*info
= &capability_table
[i
];
902 * If the apply function can't set the desired level and thinks it's
903 * fatal, it should cause that.
905 info
->apply(spapr
, spapr
->eff
.caps
[i
], &error_fatal
);
909 void spapr_caps_cpu_apply(SpaprMachineState
*spapr
, PowerPCCPU
*cpu
)
913 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
914 SpaprCapabilityInfo
*info
= &capability_table
[i
];
917 * If the apply function can't set the desired level and thinks it's
918 * fatal, it should cause that.
920 if (info
->cpu_apply
) {
921 info
->cpu_apply(spapr
, cpu
, spapr
->eff
.caps
[i
], &error_fatal
);
926 void spapr_caps_add_properties(SpaprMachineClass
*smc
)
928 ObjectClass
*klass
= OBJECT_CLASS(smc
);
931 for (i
= 0; i
< ARRAY_SIZE(capability_table
); i
++) {
932 SpaprCapabilityInfo
*cap
= &capability_table
[i
];
933 g_autofree
char *name
= g_strdup_printf("cap-%s", cap
->name
);
934 g_autofree
char *desc
= g_strdup_printf("%s", cap
->description
);
936 object_class_property_add(klass
, name
, cap
->type
,
940 object_class_property_set_description(klass
, name
, desc
);