From e00224d9ff393517c827e5e827f7638a9eaff812 Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Wed, 14 Jul 2021 15:19:57 +1000 Subject: executor/common_kvm_ppc64: fix KVM support Turns out the ifuzz on powerpc did not ever properly work. This fixes syz_kvm_setup_cpu$ppc64: Enable the PAPR KVM capability (otherwise KVM_RUN fails right away). Finish generated sequences with the software debug breakpoint as there is no x86's "hlt" variant on POWER and otherwise KVM won't exit. Add exception handlers, use the software debug breakpoint instruction to trigger immediate exit from KVM with the only exception of the decrementer interrupt handler (timer) to recharge the timer and continue. Define and use endianness selection flag (Big vs. Little endian). Define the code generator similar to kvm_gen.cc which for now contains 2 simple tests and the decrementer interrupt handler code. Add test cases to the executor so "bin/linux_ppc64le/syz-executor test" can run some sensible tests. The tests copy 0xbadc0de around similar to x86 and uses gpr[3] is a return value register (similar to EAX). Signed-off-by: Alexey Kardashevskiy --- executor/kvm_ppc64le.S | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 executor/kvm_ppc64le.S (limited to 'executor/kvm_ppc64le.S') diff --git a/executor/kvm_ppc64le.S b/executor/kvm_ppc64le.S new file mode 100644 index 000000000..0a177229c --- /dev/null +++ b/executor/kvm_ppc64le.S @@ -0,0 +1,39 @@ +// Copyright 2021 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// kvm_gen.cc generates machine code from this file and saves it into kvm_ppc64le.S.h. + +// +build + +#include "kvm.h" + +#define LOAD64(rn,name) \ + lis rn,name##@highest; \ + ori rn,rn,name##@higher; \ + rldicr rn,rn,32,31; \ + oris rn,rn,name##@h; \ + ori rn,rn,name##@l + +.global kvm_ppc64_mr, kvm_ppc64_mr_end +kvm_ppc64_mr: + LOAD64(5, 0xbadc0de) + mr 4,5 + mr 3,4 +kvm_ppc64_mr_end: + +.global kvm_ppc64_ld, kvm_ppc64_ld_end +kvm_ppc64_ld: + LOAD64(15, 0xbadc0de) + // Last double word of vma[24] + LOAD64(25, 24 * 0x10000 - 8) + std 15, 0(25) + ld 3, 0(25) +kvm_ppc64_ld_end: + +.global kvm_ppc64_recharge_dec, kvm_ppc64_recharge_dec_end +kvm_ppc64_recharge_dec: + LOAD64(20,0x7ffffff) +#define SPRN_DEC 0x016 /* Decrement Register */ + mtspr SPRN_DEC,20 + rfid +kvm_ppc64_recharge_dec_end: -- cgit mrf-deployment