Commit Graph

3620 Commits

Author SHA1 Message Date
hangliu1
b50f1eb199 hv: riscv: get device mmio parameter
Add functions get_board_hv_device_start/get_board_hv_device_size
to get mmio device start address and size. These are needed to be
generated by config tool or runtime parsing DTS, wrap the method
here.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
3d57581eb0 hv: riscv: page number calculate
this patch calculate riscv static pages number for page pool.
riscv donot need to map guest memory. use link script address
label to map code size.
For risc-v:
1) if the platform doesn't support PCIe devices
   The address space layout for risc-v is like

  |      |
  | MMIO |
  |      |
  | ...  |
  |      |
  | RAM  |
  |      |

For all its address space, one 1GB page table is enough which cover 512G
For MMIO or RAM, if its start address and end address is 1G aligned, there's no 2M
or 4K page table is needed. if their address are not 1G aligned, two 2M page table
is enough for MMIO or RAM. The issue here is that if we neetid 4K page entries for
different page attributes. So we need to reserve enough 4K page tables for that requirement.

2) if the platform support PCI devices, for the low MMIO range, another two 2MB page
table may needed. for the high MMIO range, its depends on the max physical address bits of
the platform and the high MMIO range reserved by the BIOS.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
52e7919d9f hv: riscv: add riscv memory interface
Add hypervisor pagetable manipulate interface to riscv arch directory,
which is needed by the common interface, and add riscv ppt pgtable
structure implementation.

Tracked-On: #8831
Signed-off-by: Haicheng Li <haicheng.li@intel.com>
Co-developed-by: hangliu1 <hang1.liu@intel.com>
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
cf73187528 hv: multiarch: add arch specific set_pgentry
add pgtable callbacks set_pgentry to implement arch specific
set generic page table entry for any paging level, and remove
x86 specific tweak_exe_right/recover_exe_right callbacks, move
the logic in set_pgentry callback.

remove common set_pgentry function to avoid confusing.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
1ec40cd62f hv: multiarch: replace memset with sanitize_pte
for x86, when using a new page to set up page table,
sanitize to specific hpa page address is needed, however,
for other arch, sanitized to 0 is fine. To avoid duplicate memory
setting at the time of alloc_page and sanitize pte, replace
memset in alloc_page with sanitized pte operation.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
8ba4890677 hv: x86: modify Makefile to enable compile
enable complile for pagemisc.c and pgtable.c

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
5dcf336ab3 hv: x86: move two functions back to x86
move early_pgtable_map_uart and pgtable_create_trusty_root
to x86 code, and provide calling with x86 private header
pagemisc.h

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
9bedd785e3 hv:multiarch: move round_pde_down/round_pde_up to common
move to common/pgtable.h and change name to round_pgtl1_down/round_pgtl1_up

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
5cc6694eab hv: multiarch: move page table entry function
this patch moves function xx_offset and xx_index to common code,
Add arch interface arch_quirk/arch_pgtle_page_vaddr and
arch_pgtle_large.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
8be20c690b hv: multiarch: change to common page level
move _page_table_level to common, and rename functions and
variables to comform with pgtln style

when we refer to pgtl0e, it means the lowest translation
table entry, while the "pte" refers generic page table entry.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
6748f72d1b hv:multiarch: change main macro name
add x86 mm_common.h to map common macro name to x86 name
and chang them in common/mmu.c, replace XX_PFN_MASK with
PFN_MASK, since they are the same.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
c421a9557b hv:multiarch: move main memory interface to common
move below interface to common code.
pgtable_lookup_entry/pgtable_add_map/pgtable_modify_or_del_map

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
c911c3d38e hv: multiarch: move sanitize interface to common
The sanitized page is used to mitigate l1tf for x86, but sanitized_page_hpa
is the hpa used to set in the page table entry when delete or modify
page happens, it is by default is 0, other arch donot need to init it.
move this part to common for other arch to reuse it.

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
bab6e4010c hv: multiarch: move set_pgentry/get_pgentry
move the two function to common

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
2e4f5e79b7 hv:multiarch: move main memory structure to common
move struct pgtable and page_pool to common code and
move alloc_page/free_page/init_page_pool to common

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
hangliu1
2ab068400b hv: multiarch: move some function to common
move some funcitons like hpa2hva to common file.
change some files to include file from asm/pgtable.h to common/pgtable.h

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00
Fei Li
2470e7f064 dump: add exception dump for risc-v
Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-16 09:45:08 +08:00
Fei Li
274eec4ec2 debug: enable console and shell for risc-v
For now, BOARD should use the qemu-riscv for risc-v.
For RISC-V:
make hypervisor BOARD=qemu-riscv SCENARIO=shared ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
For x86:
make hypervisor BOARD=qemu SCENARIO=shared [ARCH=x86]

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
712568f949 shell: split arch special code
Now moved all the guest related (risc-v doesn't support VMs) and x86 specific
commands to x86_shell.c except shell_dump_host_mem.

common for guest.
> -static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv);
> -static int32_t shell_list_vcpu(__unused int32_t argc, __unused char **argv);
> -static int32_t shell_to_vm_console(int32_t argc, char **argv);
  depends on how we map guest memory.
> -static int32_t shell_dump_guest_mem(int32_t argc, char **argv);

common concept but arch special implementation.
> -static int32_t shell_vcpu_dumpreg(int32_t argc, char **argv);
> -static int32_t shell_show_cpu_int(__unused int32_t argc, __unused char **argv);
> -static int32_t shell_show_ptdev_info(__unused int32_t argc, __unused char **argv);
> -static int32_t shell_reboot(int32_t argc, char **argv);

x86 special
> -static int32_t shell_show_vioapic_info(int32_t argc, char **argv);
> -static int32_t shell_show_ioapic_info(__unused int32_t argc, __unused char **argv);
> -static int32_t shell_cpuid(int32_t argc, char **argv);
> -static int32_t shell_rdmsr(int32_t argc, char **argv);
> -static int32_t shell_wrmsr(int32_t argc, char **argv);

common but not added for now.
> -static int32_t shell_dump_host_mem(int32_t argc, char **argv);

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
b26ef37519 log: move print_hv_banner as common
Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
f687574a58 vuart: add dummy vuart for risc-v
vUART will not enable before VM could be created.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
df5a5f2657 vuart_config: separate vuart config from vm config file
Not add mmio vuart support now.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
f3ab8291f4 intx: abstruct intx inject for VM
Now only x86 is implemented. RISC-V needs vPLIC support.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
ab32f6c033 config: add VMCS9900 CONFIG
Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
eea9a21796 vuart: move x86 special code into x86
Only x86 has local APIC pass-thru. For release mode, the console_vmexit_callback
is empty, complier should optimize this unuseful check.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
b82a6fea8b smap: risc-v should implement enable and disable APIs
And should align the name with other ARCHs.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
0774a517a0 mmu: add dummy APIs for risc-v
This patch doesn's wrap a arch_xxx.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
0a13d0c7a4 uart16550: add a CONFIG to enable PCI uart16550
Now doesn't want introduce the PCI module since PCI CFG access should be arch
special.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
83d56e0edb vm: add necessary dummy APIs
get_vm_from_vmid,is_paused_vm and is_poweroff_vm should be common APIs.
But now doesn't implement them as common for not introduce more VM related
data structure and APIs.

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 14:45:12 +08:00
Fei Li
ac1c79641e cmdline: move cmdline to x86
Now risc-v doesn't support cmdline

Tracked-On: #8805
Signed-off-by: Fei Li <fei1.li@intel.com>
2025-10-14 14:45:12 +08:00
Shiqing Gao
9d95a6adb6 hv: riscv: fix stack allocation in cpu_ctx_save/cpu_ctx_restore
The RISC-V calling convention defines a full descending stack, where 'sp'
points to the last used stack address. The current implementation of
cpu_ctx_save() subtracts only CPU_REGS_OFFSET_SCRATCH from 'sp', which
allocates 8 bytes too few and may overwrite the caller's stack contents.

Fix this by adjusting CPU_REGS_OFFSET_LAST to include the last slot,
ensuring the full context save/restore area is properly reserved.

Fixes: 6276763cd (hv: riscv: implement cpu_ctx_save and cpu_ctx_restore)

Tracked-On: #8827
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-14 09:45:17 +08:00
Jian Jun Chen
3449b62dfb hv: risc-v: use tp register directly for arch_get_pcpu_id
Use tp register directly for arch_get_pcpu_id. This can eliminate the
unnecessary mv instruction.

Tracked-On: #8791
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-10 17:14:22 +08:00
Jian Jun Chen
0a8eb09454 hv: riscv: fix the implementation of send_ipi
send_single_ipi/send_dest_ipi_mask are calling sbi_send_ipi. According
to SBI spec:
- uint64_t hart_mask is a scalar bit-vector containing hartids
- uint64_t hart_mask_base is the starting hartid from which the
  bit-vector must be computed

Logical pCPU ID and pCPU ID mask need to be converted to physical hart
ID mask and physical hart ID base.

Tracked-On: #8811
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-10 11:15:17 +08:00
Haicheng Li
bd0e83fa5f io: add risc-v mmio read and write APIs with memory order
Follow multi-arch, add risc-v MMIO APIs with memory order, without
PIO support.

Tracked-On: #8807
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Co-developed-by:  Fei Li <fei1.li@intel.com>
Signed-off-by: Fei Li <fei1.li@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
2025-10-09 17:15:06 +08:00
Fei Li
b6854ac4bd io: move common IO operation out of arch
MMIO read/write without memory order should be common ARCH, without
PIO support shouldn't use PIO APIs, so implement them as empty.

Tracked-On: #8807
Signed-off-by: Fei Li <fei1.li@intel.com>
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
2025-10-09 17:15:06 +08:00
Xue Bosheng
5f59c02a81 hv: init sched and run idle thread in risicv AP initialization
init sched and call run_idle_thred in init_pcpu_comm_post to switch to idle
thread after AP initialization finish.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
82ca737400 hv: move schedule source code out of x86 macro
schedule.c and sched_noop are common module instead of x86 specific, so
move them out of x86 macro, and need set SCHEDULER to be SCHED_NOOP
in scenario file for riscv build.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
69f7c14191 hv: move trace.c out of x86
some trace API is required by other module, so move trace.c out of x86,
it needs add ACRNTRACE_ENABLE = n in scenario file for riscv, could remove
ACRNTRACE_ENABLE = n when trace in riscv is fully supported.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
034cccb7a4 hv: fix build issue in schedule module
change header file from asm/per_cpu.h to per_cpu.h in sched_noop.c and
sched_prio.c, remove return of sched_iorr_del_timer function.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
6de0e4b681 hv: add dummy function for riscv support
add dummy function "need_offline", "need_shutdown_vm", "shutdown_vm_from_idle"
to support riscv.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Haicheng Li
fb82f3b931 hv: implement cpu dead and cpu idle for riscv
implement arch_cpu_dead and arch_cpu_do_idle for riscv, arch_cpu_dead and
arch_cpu_do_idle will be called by common module.

Tracked-On: #8812
Signed-off-by: Haicheng Li <haicheng.li@outlook.com>
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
4875a4a919 hv: refine cpu dead and cpu idle implementation
cpu_dead calls arch_cpu_dead, cpu_do_idle calls arch_cpu_do_idle,
arch_cpu_dead and arch_cpu_do_idle are required to be implemented by
each architecture.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
ca63f62af3 hv: move run_idle_thread to schedule file
move run_idle_thread and default_idle to schedule file as common
function.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Haicheng Li
65927b4f03 hv: add arch_switch_to support for riscv
add stack_frame definition, and implement acrh_switch_to for riscv.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Signed-off-by: Haicheng Li <haicheng.li@outlook.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
d8970404e3 hv: move stack_frame out of vcpu
stack_frame is not only for vcpu thread, host thread needs
it, so move stack_frame out of vcpu file.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
e278b38ec4 hv: move percpu delivery mode and idle mode from common to x86
delivery mode and idle mode are x86 specific percpu, so move it from common to
x86 arch, also change the name of mode_to_idle to be idle_mode, change the name
of mode_to_kick_pcpu to be kick_pcpu_mode.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Haicheng Li
b03dc25119 hv: add arch_send_reschedule_request implementation for riscv support
implement arch_send_reschedule_request for riscv, it calls send_single_ipi to
kick cpu.

Tracked-On: #8812
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Reviewed-by: Yifan Liu  <yifan1.liu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Xue Bosheng
974e8c63ea hv: refine make_reschedule_request in schedule module
add arch_send_reschedule_request, which is called by make_reschedule_request, for X86
arch_send_reschedule_request will call kick_pcpu, arch_send_reschedule_request is arch
public API, which is needed to be implemented by each architecture.

Tracked-On: #8812
Signed-off-by: Xue Bosheng <bosheng.xue@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 12:31:07 +08:00
Yi Y Sun
6abe2e950c hv: riscv: build timer and softirq
This patch moves timer.c and softirq.c out from x86 to
make them be built for risc-v too.

Tracked-On: #8816
Signed-off-by: Yi Y Sun <yi.y.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 11:15:01 +08:00
Yi Y Sun
64055b49be hv: riscv: initialize timer
This patch calls timer_init() to initialize timer for
pcpu on risc-v platform.

Tracked-On: #8816
Signed-off-by: Yi Y Sun <yi.y.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-30 11:15:01 +08:00