~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/kvm/riscv/ebreak_test.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * RISC-V KVM ebreak test.
  4  *
  5  * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
  6  *
  7  */
  8 #include "kvm_util.h"
  9 #include "ucall_common.h"
 10 
 11 #define LABEL_ADDRESS(v) ((uint64_t)&(v))
 12 
 13 extern unsigned char sw_bp_1, sw_bp_2;
 14 static uint64_t sw_bp_addr;
 15 
 16 static void guest_code(void)
 17 {
 18         asm volatile(
 19                 ".option push\n"
 20                 ".option norvc\n"
 21                 "sw_bp_1: ebreak\n"
 22                 "sw_bp_2: ebreak\n"
 23                 ".option pop\n"
 24         );
 25         GUEST_ASSERT_EQ(READ_ONCE(sw_bp_addr), LABEL_ADDRESS(sw_bp_2));
 26 
 27         GUEST_DONE();
 28 }
 29 
 30 static void guest_breakpoint_handler(struct ex_regs *regs)
 31 {
 32         WRITE_ONCE(sw_bp_addr, regs->epc);
 33         regs->epc += 4;
 34 }
 35 
 36 int main(void)
 37 {
 38         struct kvm_vm *vm;
 39         struct kvm_vcpu *vcpu;
 40         uint64_t pc;
 41         struct kvm_guest_debug debug = {
 42                 .control = KVM_GUESTDBG_ENABLE,
 43         };
 44 
 45         TEST_REQUIRE(kvm_has_cap(KVM_CAP_SET_GUEST_DEBUG));
 46 
 47         vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 48 
 49         vm_init_vector_tables(vm);
 50         vcpu_init_vector_tables(vcpu);
 51         vm_install_exception_handler(vm, EXC_BREAKPOINT,
 52                                         guest_breakpoint_handler);
 53 
 54         /*
 55          * Enable the guest debug.
 56          * ebreak should exit to the VMM with KVM_EXIT_DEBUG reason.
 57          */
 58         vcpu_guest_debug_set(vcpu, &debug);
 59         vcpu_run(vcpu);
 60 
 61         TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_DEBUG);
 62 
 63         vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.pc), &pc);
 64         TEST_ASSERT_EQ(pc, LABEL_ADDRESS(sw_bp_1));
 65 
 66         /* skip sw_bp_1 */
 67         vcpu_set_reg(vcpu, RISCV_CORE_REG(regs.pc), pc + 4);
 68 
 69         /*
 70          * Disable all debug controls.
 71          * Guest should handle the ebreak without exiting to the VMM.
 72          */
 73         memset(&debug, 0, sizeof(debug));
 74         vcpu_guest_debug_set(vcpu, &debug);
 75 
 76         vcpu_run(vcpu);
 77 
 78         TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);
 79 
 80         kvm_vm_free(vm);
 81 
 82         return 0;
 83 }
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php