ppc: Force CPU threads count to be a power of 2.
RFC PATCH 1/1 ppc: Force CPU threads count to be a power of 2.
PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.
Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.
Signed-off-by Bharata B Rao <[email protected]>
--- target-ppc/translate_init.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target-ppc/translate_init.c +8 -0
@@ -18,6 +18,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include <math.h> #include "disas/bfd.h" #include "exec/gdbstub.h" #include <sysemu/kvm.h>
@@ -7979,6 +7980,7 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)Error *local_err =NULL ;#if !defined(CONFIG_USER_ONLY )int max_smt =kvm_enabled () ?kvmppc_smt_threads () :1 ; +int threads_shift;#endif #if !defined(CONFIG_USER_ONLY )
@@ -7987,6 +7989,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) max_smt, kvm_enabled() ? "KVM" : "TCG"); return; } + threads_shift =log2 (smp_threads); +if (smp_threads != (1 << threads_shift)) { +error_setg (errp,"Cannot support %d threads on PPC with %s" , + smp_threads,kvm_enabled () ?"KVM" :"TCG" ); +return ; + }#endif if (kvm_enabled ()) {
Signature · 1 line
1.7.11.7
target-ppc/translate_init.c static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) · line 8000
Quoted 13 lines · Bharata B Rao
target-ppc/translate_init.c +6
-0@@ -7987,6 +7989,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) max_smt, kvm_enabled() ? "KVM" : "TCG"); return; } + threads_shift =log2 (smp_threads); +if (smp_threads != (1 << threads_shift)) { +error_setg (errp,"Cannot support %d threads on PPC with %s" , + smp_threads,kvm_enabled () ?"KVM" :"TCG" ); +return ; + }#endif if (kvm_enabled ()) {
I'd suggest adding "(must be power of 2)" to the error message somewhere.
with that,
Acked-by Stewart Smith <[email protected]>