Re: [PATCH 3/9] disas/riscv: Move types/constants to new header file

2023-06-08 Thread LIU Zhiwei
-off-by: Christoph Müllner Reviewed-by: LIU Zhiwei Zhiwei --- disas/riscv.c | 270 +--- disas/riscv.h | 280 ++ 2 files changed, 281 insertions(+), 269 deletions(-) create mode 100644 disas/riscv.h

Re: [PATCH 7/9] disas/riscv: Provide infrastructure for vendor extensions

2023-06-08 Thread LIU Zhiwei
if (dec.op != rv_op_illegal) +break; +} +} + +if (dec.op == rv_op_illegal) +dec.opcode_data = rvi_opcode_data; Always enclose the if sentence. Otherwise, Reviewed-by: LIU Zhiwei + decode_inst_operands(&dec, isa); decode_inst_decompress(&

Re: [PATCH] fpu: Add conversions between bfloat16 and [u]int8

2023-05-31 Thread LIU Zhiwei
On 2023/6/1 1:47, Richard Henderson wrote: On 5/30/23 23:54, LIU Zhiwei wrote: We missed these functions when upstreaming the bfloat16 support. Signed-off-by: LIU Zhiwei They look ok, so far as it goes.  What will they be used for? T-Head Xuantie CPUs custom extension need these

Re: [RFC] Native Library Calls

2023-05-31 Thread LIU Zhiwei
On 2023/5/31 15:59, Alex Bennée wrote: LIU Zhiwei writes: On 2023/5/30 22:24, Yeqi Fu wrote: This patch introduces a set of feature instructions for native calls and provides helpers to translate these instructions to corresponding native functions. A shared library is also implemented

[PATCH] fpu: Add conversions between bfloat16 and [u]int8

2023-05-30 Thread LIU Zhiwei
We missed these functions when upstreaming the bfloat16 support. Signed-off-by: LIU Zhiwei --- fpu/softfloat.c | 58 + include/fpu/softfloat.h | 12 + 2 files changed, 70 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index

Re: [RFC] Native Library Calls

2023-05-30 Thread LIU Zhiwei
On 2023/5/30 22:24, Yeqi Fu wrote: This patch introduces a set of feature instructions for native calls and provides helpers to translate these instructions to corresponding native functions. A shared library is also implemented, where native functions are rewritten as feature instructions. At

Re: [PATCH] target/riscv: Move zc* out of the experimental properties

2023-05-10 Thread LIU Zhiwei
+DEFINE_PROP_BOOL("zcmp", RISCVCPU, cfg.ext_zcmp, false), +DEFINE_PROP_BOOL("zcmt", RISCVCPU, cfg.ext_zcmt, false), + Reviewed-by: LIU Zhiwei Zhiwei /* Vendor-specific custom extensions */ DEFINE_PROP_BOOL("xtheadba", RISCVCPU, cfg.ext_xtheadba, false), DEFI

Re: [PATCH v2] hw/riscv: qemu crash when NUMA nodes exceed available CPUs

2023-05-10 Thread LIU Zhiwei
report("Number of CPUs used by NUMA nodes (%d)" + " cannot exceed the number of available CPUs (%d).", + ms->numa_state->num_nodes, ms->smp.max_cpus); + exit(EXIT_FAILURE); +} Reviewed-by: LIU Zhiwei Zhiwei if

Re: [PATCH v4 38/57] tcg/riscv: Support softmmu unaligned accesses

2023-05-05 Thread LIU Zhiwei
_opc_reg(s, OPC_ADD, TCG_REG_TMP0, TCG_REG_TMP2, addr_reg); +tcg_out_opc_reg(s, OPC_ADD, TCG_REG_TMP0, TCG_REG_TMP2, addr_adj); Reviewed-by: LIU Zhiwei Zhiwei *pbase = TCG_REG_TMP0; #else if (a_mask) {

Re: [PATCH v4 2/7] target/riscv: Move pmp_get_tlb_size apart from get_physical_address_pmp

2023-04-27 Thread LIU Zhiwei
size, access_type, mode); +tlb_size = pmp_get_tlb_size(env, pa); Reviewed-by: LIU Zhiwei Zhiwei qemu_log_mask(CPU_LOG_MMU, "%s PMP address=" HWADDR_FMT_plx " ret %d prot"

Re: [PATCH v4 1/7] target/riscv: Update pmp_get_tlb_size()

2023-04-27 Thread LIU Zhiwei
~0x80001FFF, RWX) write access to 0x8000 will match PMP1. Typo here. Otherwise, Reviewed-by: LIU Zhiwei Zhiwei However we cannot cache the translation result in the TLB since this will make the write access to 0x8008 bypass the check of PMP0. So we should check all of them instead of

Re: [PATCH] hw/riscv/virt: Add a second UART for secure world

2023-04-23 Thread LIU Zhiwei
djacent to the VIRT_UART0, such as 0x1100? Otherwise, Reviewed-by: LIU Zhiwei Zhiwei [VIRT_FW_CFG] = { 0x1010, 0x18 }, [VIRT_FLASH] ={ 0x2000, 0x400 }, [VIRT_IMSIC_M] = { 0x2400, VIRT_IMSIC_MAX_SIZE }, @@ -1508,6 +1509,9 @@ s

Re: [PATCH v3 6/7] target/riscv: Make the short cut really work in pmp_hart_has_privs

2023-04-20 Thread LIU Zhiwei
On 2023/4/19 11:27, Weiwei Li wrote: We needn't check the PMP entries if there is no PMP rules. This commit doesn't give much information. If you are fixing a bug, you should point it out why the original implementation is wrong. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang ---

Re: [PATCH v3 4/7] target/riscv: Flush TLB only when pmpcfg/pmpaddr really changes

2023-04-20 Thread LIU Zhiwei
nv->pmp_state.pmp[addr_index].addr_reg != val) { +env->pmp_state.pmp[addr_index].addr_reg = val; +pmp_update_rule(env, addr_index); +tlb_flush(env_cpu(env)); +} Reviewed-by: LIU Zhiwei Zhiwei } else { qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpaddr write - locked\n");

Re: [PATCH v3 3/7] target/riscv: Flush TLB when pmpaddr is updated

2023-04-20 Thread LIU Zhiwei
pmp[addr_index].addr_reg = val; pmp_update_rule(env, addr_index); +tlb_flush(env_cpu(env)); Reviewed-by: LIU Zhiwei Zhiwei } else { qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpaddr write - locked\n");

Re: [PATCH v3 2/7] target/riscv: Move pmp_get_tlb_size apart from get_physical_address_pmp

2023-04-20 Thread LIU Zhiwei
On 2023/4/19 11:27, Weiwei Li wrote: pmp_get_tlb_size can be separated from get_physical_address_pmp and is only needed when ret == TRANSLATE_SUCCESS. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/cpu_helper.c | 21 +++-- target/riscv/pmp.c

Re: [PATCH v3 1/7] target/riscv: Update pmp_get_tlb_size()

2023-04-20 Thread LIU Zhiwei
On 2023/4/19 11:27, Weiwei Li wrote: PMP entries before the matched PMP entry(including the matched PMP entry) may overlap partial of the tlb page, which may make different regions in that page have different permission rights, such as for PMP0(0x8008~0x800F, R) and PMP1(0x80001000~0x80

Re: [PATCH v2 6/8] accel/tcg: Uncache the host address for instruction fetch when tlb size < 1

2023-04-18 Thread LIU Zhiwei
_code() => get_page_addr_code_hostp(): the TLB host address will be cached, and the following instructions can use this host address directly which may lead to the bypass of PMP related check. We can add a link to the issue in the commit message, https://gitlab.com/qemu-project/qemu/-/issues/1542 Reviewed-by: LI

Re: [PATCH 5/6] target/riscv: flush tb when PMP entry changes

2023-04-18 Thread LIU Zhiwei
On 2023/4/13 17:01, Weiwei Li wrote: The translation block may also be affected when PMP entry changes. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/pmp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index aced23c

Re: [PATCH 4/6] target/riscv: Flush TLB only when pmpcfg/pmpaddr really changes

2023-04-18 Thread LIU Zhiwei
On 2023/4/13 17:01, Weiwei Li wrote: TLB needn't be flushed when pmpcfg/pmpaddr don't changes. If we flush the tlb in pmp_update_rules, we don't need this patch. Zhiwei Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/pmp.c | 24 1 file

Re: [PATCH 3/6] target/riscv: flush tlb when pmpaddr is updated

2023-04-18 Thread LIU Zhiwei
On 2023/4/13 17:01, Weiwei Li wrote: TLB should be flushed not only for pmpcfg csr changes, but also for pmpaddr csr changes. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/pmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/pmp.c b/target/riscv/

Re: [PATCH 1/6] target/riscv: Update pmp_get_tlb_size()

2023-04-18 Thread LIU Zhiwei
On 2023/4/18 14:09, Weiwei Li wrote: On 2023/4/18 13:18, LIU Zhiwei wrote: On 2023/4/18 11:05, Weiwei Li wrote: On 2023/4/18 10:53, Alistair Francis wrote: On Thu, Apr 13, 2023 at 7:04 PM Weiwei Li wrote: Not only the matched PMP entry, Any PMP entry that overlap with partial of the

Re: [PATCH 1/6] target/riscv: Update pmp_get_tlb_size()

2023-04-17 Thread LIU Zhiwei
On 2023/4/18 11:05, Weiwei Li wrote: On 2023/4/18 10:53, Alistair Francis wrote: On Thu, Apr 13, 2023 at 7:04 PM Weiwei Li wrote: Not only the matched PMP entry, Any PMP entry that overlap with partial of the tlb page may make the regions in that page have different permission rights. So

Re: [PATCH 0/6] target/riscv: Fix PMP related problem

2023-04-17 Thread LIU Zhiwei
On 2023/4/18 11:36, Weiwei Li wrote: On 2023/4/18 11:07, LIU Zhiwei wrote: On 2023/4/13 17:01, Weiwei Li wrote: This patchset tries to fix the PMP bypass problem issue https://gitlab.com/qemu-project/qemu/-/issues/1542 Please add your analysis of this issue here. By the way, I think

Re: [PATCH 0/6] target/riscv: Fix PMP related problem

2023-04-17 Thread LIU Zhiwei
On 2023/4/13 17:01, Weiwei Li wrote: This patchset tries to fix the PMP bypass problem issue https://gitlab.com/qemu-project/qemu/-/issues/1542 Please add your analysis of this issue here. By the way, I think this problem is introduced by https://www.mail-archive.com/qemu-devel@nongnu.org/

Re: [PATCH] target/riscv: Restore the predicate() NULL check behavior

2023-04-11 Thread LIU Zhiwei
predicate() must be provided for an implemented CSR. Reported-by: Fei Wu Signed-off-by: Bin Meng Reviewed-by: LIU Zhiwei Zhiwei --- target/riscv/csr.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d522efc0b6

Re: [RFC PATCH v2] riscv: Add support for the Zfa extension

2023-04-10 Thread LIU Zhiwei
On 2023/4/1 2:28, Christoph Muellner wrote: From: Christoph Müllner This patch introduces the RISC-V Zfa extension, which introduces additional floating-point extensions: * fli (load-immediate) with pre-defined immediates * fminm/fmaxm (like fmin/fmax but with different NaN behaviour) * froun

Re: [PATCH v6 4/6] target/riscv: Add support for PC-relative translation

2023-04-04 Thread LIU Zhiwei
On 2023/4/4 16:48, liweiwei wrote: On 2023/4/4 15:07, LIU Zhiwei wrote: On 2023/4/4 11:46, liweiwei wrote: On 2023/4/4 11:12, LIU Zhiwei wrote: On 2023/4/4 10:06, Weiwei Li wrote: Add a base pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by

Re: [PATCH v6 00/25] target/riscv: MSTATUS_SUM + cleanups

2023-04-04 Thread LIU Zhiwei
et/riscv: Reduce overhead of MSTATUS_SUM change LIU Zhiwei (4): target/riscv: Extract virt enabled state from tb flags target/riscv: Add a general status enum for extensions target/riscv: Encode the FS and VS on a normal way for tb flags target/riscv: Add a tb flags field for vsta

Re: [PATCH v6 4/6] target/riscv: Add support for PC-relative translation

2023-04-04 Thread LIU Zhiwei
On 2023/4/4 11:46, liweiwei wrote: On 2023/4/4 11:12, LIU Zhiwei wrote: On 2023/4/4 10:06, Weiwei Li wrote: Add a base pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. We can get pc-relative address from following formula

Re: [PATCH v6 4/6] target/riscv: Add support for PC-relative translation

2023-04-03 Thread LIU Zhiwei
On 2023/4/4 11:12, LIU Zhiwei wrote: On 2023/4/4 10:06, Weiwei Li wrote: Add a base pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. We can get pc-relative address from following formula:    real_pc = (old)env->pc + d

Re: [PATCH v6 4/6] target/riscv: Add support for PC-relative translation

2023-04-03 Thread LIU Zhiwei
On 2023/4/4 10:06, Weiwei Li wrote: Add a base pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. We can get pc-relative address from following formula: real_pc = (old)env->pc + diff, where diff = target_pc - ctx->pc_save. Use

Re: [PATCH v6 3/6] target/riscv: Fix target address to update badaddr

2023-04-03 Thread LIU Zhiwei
On 2023/4/4 10:06, Weiwei Li wrote: Compute the target address before storing it into badaddr when mis-aligned exception is triggered. Use a target_pc temp to store the target address to avoid the confusing operation that udpate target address into cpu_pc before misalign check, then update it i

Re: [PATCH v6 6/6] target/riscv: Add pointer mask support for instruction fetch

2023-04-03 Thread LIU Zhiwei
2b64129 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3518,8 +3518,6 @@ static RISCVException write_mmte(CPURISCVState *env, int csrno, /* for machine mode pm.current is hardwired to 1 */ wpri_val |= MMTE_M_PM_CURRENT; -/* hardwiring pm.instruction bit to 0, since it'

Re: [RESEND PATCH v5 4/6] target/riscv: Add support for PC-relative translation

2023-04-03 Thread LIU Zhiwei
On 2023/4/4 10:13, liweiwei wrote: On 2023/4/4 09:58, LIU Zhiwei wrote: On 2023/4/1 20:49, Weiwei Li wrote: Add a base save_pc For PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. Sync pc before it's used or updated from tb relat

Re: [RESEND PATCH v5 4/6] target/riscv: Add support for PC-relative translation

2023-04-03 Thread LIU Zhiwei
On 2023/4/1 20:49, Weiwei Li wrote: Add a base save_pc For PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. Sync pc before it's used or updated from tb related pc: real_pc = (old)env->pc + target_pc(from tb) - ctx->save_pc Use gen_get_

Re: [RESEND PATCH v5 4/6] target/riscv: Add support for PC-relative translation

2023-04-02 Thread LIU Zhiwei
On 2023/4/2 16:17, liweiwei wrote: On 2023/4/2 08:34, LIU Zhiwei wrote: On 2023/4/1 20:49, Weiwei Li wrote: Add a base save_pc For pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. Sync pc before it's used or updated

Re: [RESEND PATCH v5 4/6] target/riscv: Add support for PC-relative translation

2023-04-01 Thread LIU Zhiwei
On 2023/4/1 20:49, Weiwei Li wrote: Add a base save_pc For pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. Sync pc before it's used or updated from tb related pc: real_pc = (old)env->pc + target_pc(from tb) - ctx->save_p

Re: [PATCH v3 5/6] target/riscv: Enable PC-relative translation in system mode

2023-03-31 Thread LIU Zhiwei
*dev, Error **errp) #ifndef CONFIG_USER_ONLY +cs->tcg_cflags |= CF_PCREL; + Reviewed-by: LIU Zhiwei Zhiwei if (cpu->cfg.ext_sstc) { riscv_timer_init(cpu); }

Re: [PATCH v2 3/5] target/riscv: Sync cpu_pc before update badaddr

2023-03-30 Thread LIU Zhiwei
te.c @@ -551,6 +551,7 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) next_pc = ctx->base.pc_next + imm; if (!has_ext(ctx, RVC)) { if ((next_pc & 0x3) != 0) { +gen_set_pc_imm(ctx, next_pc); I think this patch is better than it in v

Re: [PATCH v2 2/5] target/riscv: Update cur_pmmask/base when xl changes

2023-03-30 Thread LIU Zhiwei
mpute_xl(env); +riscv_cpu_update_mask(env); +} Reviewed-by: LIU Zhiwei Zhiwei return RISCV_EXCP_NONE; }

Re: [PATCH 1/5] target/riscv: Fix effective address for pointer mask

2023-03-28 Thread LIU Zhiwei
On 2023/3/28 11:33, liweiwei wrote: On 2023/3/28 11:18, Richard Henderson wrote: On 3/27/23 19:48, liweiwei wrote: On 2023/3/28 10:20, LIU Zhiwei wrote: On 2023/3/27 18:00, Weiwei Li wrote: Since pointer mask works on effective address, and the xl works on the generation of effective

Re: [PATCH 1/5] target/riscv: Fix effective address for pointer mask

2023-03-27 Thread LIU Zhiwei
On 2023/3/28 11:18, Richard Henderson wrote: On 3/27/23 19:48, liweiwei wrote: On 2023/3/28 10:20, LIU Zhiwei wrote: On 2023/3/27 18:00, Weiwei Li wrote: Since pointer mask works on effective address, and the xl works on the generation of effective address, so xl related calculation

Re: [PATCH v6 07/25] target/riscv: Reduce overhead of MSTATUS_SUM change

2023-03-27 Thread LIU Zhiwei
s.h" +/* + * The current MMU Modes are: + * - U 0b000 + * - S 0b001 + * - S+SUM 0b010 + * - M 0b011 + * - HLV/HLVX/HSV adds 0b100 Reviewed-by: LIU Zhiwei Zhiwei + */ +#define MMUIdx_U0 +#define MMUIdx_S

Re: [PATCH v6 06/25] target/riscv: Separate priv from mmu_idx

2023-03-27 Thread LIU Zhiwei
dx & TB_FLAGS_PRIV_MMU_MASK; -#endif +return ctx->priv; } Could you  remove the priv_level and use ctx->priv directly in this file Otherwise, Reviewed-by: LIU Zhiwei Zhiwei /* Test if priv level is M, S, or U (cannot fail). */

Re: [PATCH v6 04/25] target/riscv: Remove mstatus_hs_{fs,vs} from tb_flags

2023-03-27 Thread LIU Zhiwei
On 2023/3/25 18:54, Richard Henderson wrote: Merge with mstatus_{fs,vs}. We might perform a redundant assignment to one or the other field, but it's a trivial and saves 4 bits from TB_FLAGS. Signed-off-by: Richard Henderson Reviewed-by: LIU Zhiwei Zhiwei --- target/riscv/

Re: [PATCH 5/5] target/riscv: Add pointer mask support for instruction fetch

2023-03-27 Thread LIU Zhiwei
On 2023/3/28 9:55, liweiwei wrote: On 2023/3/28 02:04, Richard Henderson wrote: On 3/27/23 03:00, Weiwei Li wrote: @@ -1248,6 +1265,10 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,   qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n",

Re: [PATCH 4/5] target/riscv: take xl into consideration for vector address

2023-03-27 Thread LIU Zhiwei
On 2023/3/27 18:00, Weiwei Li wrote: Sign-extend the vector address when xl = 32. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/vector_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index

Re: [PATCH 3/5] target/riscv: Fix pointer mask transformation for vector address

2023-03-27 Thread LIU Zhiwei
*env, target_ulong addr) { -return (addr & env->cur_pmmask) | env->cur_pmbase; +return (addr & ~env->cur_pmmask) | env->cur_pmbase; It's my typo. Thanks. Reviewed-by: LIU Zhiwei Zhiwei } /*

Re: [PATCH 1/5] target/riscv: Fix effective address for pointer mask

2023-03-27 Thread LIU Zhiwei
On 2023/3/27 18:00, Weiwei Li wrote: Since pointer mask works on effective address, and the xl works on the generation of effective address, so xl related calculation should be done before pointer mask. Incorrect. It has been done. When updating the pm_mask,  we have already considered the e

Re: [PATCH 2/5] target/riscv: Use sign-extended data address when xl = 32

2023-03-27 Thread LIU Zhiwei
On 2023/3/27 18:00, Weiwei Li wrote: Currently, the pc use signed-extend(in gen_set_pc*) when xl = 32. And data address should use the same memory address space with it when xl = 32. So we should change their address calculation to use sign-extended address when xl = 32. Incorrect. PC sign-ext

Re: [PATCH v6 13/25] target/riscv: Introduce mmuidx_priv

2023-03-27 Thread LIU Zhiwei
On 2023/3/28 9:33, LIU Zhiwei wrote: On 2023/3/28 0:29, Richard Henderson wrote: On 3/26/23 19:07, LIU Zhiwei wrote: +static inline int mmuidx_priv(int mmu_idx) +{ +    int ret = mmu_idx & 3; +    if (ret == MMUIdx_S_SUM) { +    ret = PRV_S; +    } +    return ret; +} + Can we re

Re: [PATCH v6 13/25] target/riscv: Introduce mmuidx_priv

2023-03-27 Thread LIU Zhiwei
On 2023/3/28 0:29, Richard Henderson wrote: On 3/26/23 19:07, LIU Zhiwei wrote: +static inline int mmuidx_priv(int mmu_idx) +{ +    int ret = mmu_idx & 3; +    if (ret == MMUIdx_S_SUM) { +    ret = PRV_S; +    } +    return ret; +} + Can we remove the PRIV from the tb flags afte

Re: [PATCH v2 06/10] target/riscv: Remove riscv_cpu_virt_enabled()

2023-03-27 Thread LIU Zhiwei
On 2023/3/27 16:08, Weiwei Li wrote: Directly use env->virt_enabled instead. Suggested-by: LIU Zhiwei Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/cpu.c| 2 +- target/riscv/cpu.h| 1 - target/riscv/cpu_helper.c |

Re: [PATCH v6 13/25] target/riscv: Introduce mmuidx_priv

2023-03-26 Thread LIU Zhiwei
On 2023/3/25 18:54, Richard Henderson wrote: Use the priv level encoded into the mmu_idx, rather than starting from env->priv. We have already checked MPRV+MPP in riscv_cpu_mmu_index -- no need to repeat that. Signed-off-by: Richard Henderson --- target/riscv/internals.h | 9 + t

Re: [PATCH 0/8] target/riscv: Simplification for RVH related check and code style fix

2023-03-25 Thread LIU Zhiwei
the riscv_cpu_virt_enabled which has been called so many times. you can pick it up into this patch set if you desire. No matter what you choose, after small fix for patch 6,  for this whole patch set Reviewed-by: LIU Zhiwei Zhiwei The port is available here: https://github.com/plctlab/plct-qemu/t

[PATCH 1/1] target/riscv: Convert env->virt to a bool env->virt_enabled

2023-03-25 Thread LIU Zhiwei
Currently we only use the env->virt to encode the virtual mode enabled status. Let's make it a bool type. Signed-off-by: LIU Zhiwei --- target/riscv/cpu.h| 2 +- target/riscv/cpu_bits.h | 3 --- target/riscv/cpu_helper.c | 6 +++--- target/riscv/machine.c| 6 +++--- targ

Re: [PATCH 6/8] target/riscv: Fix format for indentation

2023-03-25 Thread LIU Zhiwei
On 2023/3/24 20:38, Weiwei Li wrote: Fix identation problems, and try to use the same indentation strategy in the same file. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang --- target/riscv/arch_dump.c| 4 +- target/riscv/cpu.c | 4 +- targe

[PATCH] target/riscv: Fix itrigger when icount is used

2023-03-24 Thread LIU Zhiwei
structions. Signed-off-by: LIU Zhiwei --- target/riscv/insn_trans/trans_privileged.c.inc | 6 ++ 1 file changed, 6 insertions(+) diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc index 59501b2780..e3bee971c6 100644 --- a/target/riscv/

[PATCH 1/4] target/riscv: Extract virt enabled state from tb flags

2023-03-24 Thread LIU Zhiwei
Virt enabled state is not a constant. So we should put it into tb flags. Thus we can use it like a constant condition at translation phase. Reported-by: Richard Henderson Signed-off-by: LIU Zhiwei --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 2 ++ target/riscv

[PATCH 3/4] target/riscv: Encode the FS and VS on a normal way for tb flags

2023-03-24 Thread LIU Zhiwei
Reuse the MSTATUS_FS and MSTATUS_VS for the tb flags positions is not a normal way. It will make us change the tb flags layout difficult. And even worse, if we want to keep tb flags for a same extension togather without a hole. Signed-off-by: LIU Zhiwei --- target/riscv/cpu.h

[PATCH 2/4] target/riscv: Add a general status enum for extensions

2023-03-24 Thread LIU Zhiwei
The pointer masking is the only extension that directly use status. The vector or float extension uses the status in an indirect way. Replace the pointer masking extension special status fields with the general status. Signed-off-by: LIU Zhiwei --- target/riscv/cpu.c | 2 +- target/riscv

[PATCH 4/4] target/riscv: Add a tb flags field for vstart

2023-03-24 Thread LIU Zhiwei
Once we mistook the vstart directly from the env->vstart. As env->vstart is not a constant, we should record it in the tb flags if we want to use it in translation. Reported-by: Richard Henderson Signed-off-by: LIU Zhiwei --- target/riscv/cpu.h

[PATCH 0/4] Fix tb flags use

2023-03-24 Thread LIU Zhiwei
We have found two places that misuse the fields from env. The patch set fixes two of them. The first is virt_enabled. And another is vstart. And for easy moving the tb flag fields, I also make the FS and VS in tb flags positions changable. LIU Zhiwei (4): target/riscv: Extract virt enabled

Re: [PATCH 2/4] target/riscv: Add a general status enum for extensions

2023-03-24 Thread LIU Zhiwei
On 2023/3/24 20:53, liweiwei wrote: On 2023/3/24 13:59, LIU Zhiwei wrote: The pointer masking is the only extension that directly use status. The vector or float extension uses the status in an indirect way. Replace the pointer masking extension special status fields with the general status

Re: [PATCH v4 1/2] target/riscv: separate priv from mmu_idx

2023-03-23 Thread LIU Zhiwei
On 2023/3/23 14:00, Wu, Fei wrote: On 3/23/2023 1:37 PM, LIU Zhiwei wrote: On 2023/3/23 10:44, Fei Wu wrote: Currently it's assumed the 2 low bits of mmu_idx map to privilege mode, this assumption won't last as we are about to add more mmu_idx. For patch set has more than 1 patc

Re: [PATCH v4 1/2] target/riscv: separate priv from mmu_idx

2023-03-22 Thread LIU Zhiwei
On 2023/3/23 10:44, Fei Wu wrote: Currently it's assumed the 2 low bits of mmu_idx map to privilege mode, this assumption won't last as we are about to add more mmu_idx. For patch set has more than 1 patch, usually add a cover letter. Signed-off-by: Fei Wu --- target/riscv/cpu.h

Re: [PATCH for-8.1 v4 12/25] target/riscv/cpu.c: redesign register_cpu_props()

2023-03-22 Thread LIU Zhiwei
Hi Daniel, I want to share my opinions about the cpu->cfg and misa. Two suggestions: 1) The cpu->cfg should be set only once in cpu initialization phrase(cpu_init_fn or cpu_realize_fn), and never changes any more in other times(for example write_misa). 2) Set the misa only when cpu->cfg is

Re: [PATCH for-8.1 v4 11/25] target/riscv/cpu.c: set cpu config in set_misa()

2023-03-22 Thread LIU Zhiwei
On 2023/3/23 10:14, LIU Zhiwei wrote: On 2023/3/23 6:19, Daniel Henrique Barboza wrote: set_misa() is setting all 'misa' related env states and nothing else. But other functions, namely riscv_cpu_validate_set_extensions(), uses the config object to do its job. This creates a need

Re: [PATCH for-8.1 v4 11/25] target/riscv/cpu.c: set cpu config in set_misa()

2023-03-22 Thread LIU Zhiwei
On 2023/3/23 6:19, Daniel Henrique Barboza wrote: set_misa() is setting all 'misa' related env states and nothing else. But other functions, namely riscv_cpu_validate_set_extensions(), uses the config object to do its job. This creates a need to set the single letter extensions in the cfg obje

Re: [PATCH for-8.1 v4 10/25] target/riscv/cpu.c: avoid set_misa() in validate_set_extensions()

2023-03-22 Thread LIU Zhiwei
sa(env, env->misa_mxl, ext); +env->misa_ext_mask = env->misa_ext = ext; Reviewed-by: LIU Zhiwei Zhiwei } #ifndef CONFIG_USER_ONLY

Re: [PATCH for-8.1 v4 09/25] target/riscv/cpu.c: remove cfg setup from riscv_cpu_init()

2023-03-22 Thread LIU Zhiwei
() */ +cpu->cfg.ext_ifencei = true; +cpu->cfg.ext_icsr = true; +cpu->cfg.pmp = true; } #endif @@ -1384,11 +1425,6 @@ static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu = RISCV_CPU(obj); -cpu->cfg.ext_ifencei = true; -cpu->cfg.ext_icsr = true; -cpu->cfg.mmu = true; -cpu->cfg.pmp = true; - Reviewed-by: LIU Zhiwei Zhiwei cpu_set_cpustate_pointers(cpu); #ifndef CONFIG_USER_ONLY

Re: [PATCH for-8.1 v4 08/25] target/riscv/cpu.c: validate extensions before riscv_timer_init()

2023-03-22 Thread LIU Zhiwei
static void riscv_cpu_realize(DeviceState *dev, Error **errp) } #ifndef CONFIG_USER_ONLY +if (cpu->cfg.ext_sstc) { +riscv_timer_init(cpu); +} + Reviewed-by: LIU Zhiwei Zhiwei if (cpu->cfg.pmu_num) { if (!riscv_pmu_init(cpu, cpu-&g

Re: [PATCH for-8.1 v4 07/25] target/riscv: move pmp and epmp validations to validate_set_extensions()

2023-03-22 Thread LIU Zhiwei
On 2023/3/23 6:19, Daniel Henrique Barboza wrote: In the near future, write_misa() will use a variation of what we have now as riscv_cpu_validate_set_extensions(). The pmp and epmp validation will be required in write_misa() I don't know why pmp and epmp should be checked in write_misa(). As

Re: [PATCH for-8.1 v4 06/25] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl()

2023-03-22 Thread LIU Zhiwei
; -break; -#endif -case MXL_RV32: -cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; - break; -default: -g_assert_not_reached(); -} -assert(env->misa_mxl_max == env->misa_mxl); - Reviewed-by: LIU Zhiwei Zhiwei riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err);

Re: [PATCH] target/riscv: reduce overhead of MSTATUS_SUM change

2023-03-21 Thread LIU Zhiwei
On 2023/3/22 14:40, Wu, Fei wrote: On 3/22/2023 11:36 AM, Wu, Fei wrote: On 3/22/2023 11:31 AM, Richard Henderson wrote: On 3/21/23 19:47, Wu, Fei wrote: You should be making use of different softmmu indexes, similar to how ARM uses a separate index for PAN (privileged access never) mode.  I

Re: [PATCH] target/riscv: reduce overhead of MSTATUS_SUM change

2023-03-21 Thread LIU Zhiwei
On 2023/3/22 10:47, Wu, Fei wrote: On 3/22/2023 9:58 AM, LIU Zhiwei wrote: On 2023/3/22 0:10, Richard Henderson wrote: On 3/20/23 23:37, fei2...@intel.com wrote: From: Fei Wu Kernel needs to access user mode memory e.g. during syscalls, the window is usually opened up for a very limited

Re: [PATCH] target/riscv: reduce overhead of MSTATUS_SUM change

2023-03-21 Thread LIU Zhiwei
On 2023/3/22 0:10, Richard Henderson wrote: On 3/20/23 23:37, fei2...@intel.com wrote: From: Fei Wu Kernel needs to access user mode memory e.g. during syscalls, the window is usually opened up for a very limited time through MSTATUS.SUM, the overhead is too much if tlb_flush() gets called f

Re: [PATCH] tcg/tcg: Avoid TS_DEAD for basic block ending

2023-03-20 Thread LIU Zhiwei
On 2023/3/21 14:06, Richard Henderson wrote: On 3/20/23 21:53, LIU Zhiwei wrote: TS_DEAD means we will release the register allocated for this temporary. But at basic block ending, we can still use the allocted register. Signed-off-by: LIU Zhiwei Test case? I have run an Ubuntu image

[PATCH] tcg/tcg: Avoid TS_DEAD for basic block ending

2023-03-20 Thread LIU Zhiwei
TS_DEAD means we will release the register allocated for this temporary. But at basic block ending, we can still use the allocted register. Signed-off-by: LIU Zhiwei --- tcg/tcg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index bb52bc060b

Re: [PATCH for-8.1 v3 05/26] target/riscv/cpu.c: add priv_spec validate/disable_exts helpers

2023-03-20 Thread LIU Zhiwei
patch, this patch looks good to me. Reviewed-by: LIU Zhiwei Zhiwei A better place to put this code is at the end of riscv_cpu_validate_set_extensions() after all the validations are completed. Add a new helper, riscv_cpu_disable_priv_spec_isa_exts(), to disable the extesions after the validati

[PATCH] target/riscv: Fix priv version dependency for vector and zfh

2023-03-20 Thread LIU Zhiwei
Vector implicitly enables zve64d, zve64f, zve32f sub extensions. As vector only requires PRIV_1_10_0, these sub extensions should not require priv version higher than that. The same for Zfh. Signed-off-by: LIU Zhiwei --- target/riscv/cpu.c | 8 1 file changed, 4 insertions(+), 4

Re: [PATCH for-8.1 v3 04/26] target/riscv: add PRIV_VERSION_LATEST

2023-03-20 Thread LIU Zhiwei
0, + +PRIV_VERSION_LATEST = PRIV_VERSION_1_12_0, Reviewed-by: LIU Zhiwei Zhiwei }; #define VEXT_VERSION_1_00_0 0x0001

Re: [PATCH for-8.1 v3 03/26] target/riscv/cpu.c: remove set_priv_version()

2023-03-20 Thread LIU Zhiwei
cfg.mmu = false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -1160,7 +1156,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } if (priv_version >= PRIV_VERSION_1_10_0) { -set_priv_version(env, priv_ve

Re: [PATCH for-8.1 v3 02/26] target/riscv/cpu.c: remove set_vext_version()

2023-03-20 Thread LIU Zhiwei
not specified, " "use the default value v1.0\n"); } -set_vext_version(env, vext_version); +env->vext_ver = vext_version; Reviewed-by: LIU Zhiwei Zhiwei } /*

Re: [PATCH for-8.1 v3 01/26] target/riscv/cpu.c: add riscv_cpu_validate_v()

2023-03-20 Thread LIU Zhiwei
-vext_version = VEXT_VERSION_1_00_0; -} else { -error_setg(errp, - "Unsupported vector spec version '%s'", - cpu->cfg.vext_spec); -return; -} -} else { -qemu_log("vector version is not specified, " - "use the default value v1.0\n"); -} -set_vext_version(env, vext_version); Reviewed-by: LIU Zhiwei Zhiwei } if (cpu->cfg.ext_j) { ext |= RVJ;

Re: Question about TCG liveness_pass_1

2023-03-18 Thread LIU Zhiwei
On 2023/3/17 22:02, Richard Henderson wrote: On 3/16/23 19:57, LIU Zhiwei wrote: Hi Richard, When I read the tcg code, I find a corner case which may be a bug in liveness_pass_1. I see all TEMP_TBs or global temps are set to TS_DEAD | TS_MEM when enter liveness_pass_1. Think about the

Re: [PATCH v4] target/riscv: fix H extension TVM trap

2023-03-17 Thread LIU Zhiwei
(env->priv == PRV_U || get_field(env->hstatus, HSTATUS_VTVM))) { riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); } else { tlb_flush(cs); @@ -403,7 +403,7 @@ void helper_hyp_tlb_flush(CPURISCVState *env) { CPUState *cs = env_cpu(env); -if (env->priv == PRV_S && riscv_cpu_virt_enabled(env)) { +if (riscv_cpu_virt_enabled(env)) { riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); } Reviewed-by: LIU Zhiwei Zhiwei

Re: [PATCH qemu v2] linux-user: Emulate /proc/cpuinfo output for riscv

2023-03-17 Thread LIU Zhiwei
p(buffer, "isa\t\t: rv64imafdc_zicsr_zifencei\n") == 0); +} else if (strstr(buffer, "mmu") != NULL) { +assert(strcmp(buffer, "mmu\t\t: sv48\n") == 0); +} else if (strstr(buffer, "uarch") != NULL) { +assert(strcmp(buffer, "uarch\t\t: qemu\n") == 0); +} +} + +fclose(fp); +return 0; +} Reviewed-by: LIU Zhiwei Zhiwei

Question about TCG liveness_pass_1

2023-03-16 Thread LIU Zhiwei
Hi Richard, When I read the tcg code, I find a corner case which may be a bug in liveness_pass_1. I see all TEMP_TBs or global temps are set to TS_DEAD | TS_MEM when enter liveness_pass_1. Think about the  sequence. 1)Write_global_temp_0 // 0->TS_DEAD, but not recorded in arg_life 2)INDEX

Re: [PATCH] disas/riscv: Add support for XThead* instructions

2023-03-15 Thread LIU Zhiwei
k for XTHEAD*. I once sent a multiple disassemble path patch set  for custom extensions. https://www.mail-archive.com/qemu-devel@nongnu.org/msg906222.html We may continue this work based on that patch set. Zhiwei Co-developed-by: LIU Zhiwei Signed-off-by: Christoph Müllner --- disas/ri

Re: [PATCH v2 07/10] contrib/gitdm: add Alibaba to the domain-map

2023-03-12 Thread LIU Zhiwei
On 2023/3/11 2:03, Alex Bennée wrote: This replaces the previous attempt to add c-sky.com so I've dropped the review/ack tags. Group everything under Alibaba now. Added as requested by LIU Zhiwei. Signed-off-by: Alex Bennée Cc: LIU Zhiwei Cc: Xuan Zhuo Cc: Guo Ren --- contrib/

Re: [PATCH] target/riscv/csr.c: fix H extension TVM trap

2023-03-10 Thread LIU Zhiwei
On 2023/3/10 17:08, CHEN Yi wrote: -Original Messages- *From:*"LIU Zhiwei" *Sent Time:*2023-03-10 10:12:10 (Friday) *To:* chenyi2...@zju.edu.cn, qemu-devel@nongnu.org *Cc:* "Palmer Dabbelt" , "Alistair Francis" , "Bin Meng&qu

Re: [PATCH] target/riscv/csr.c: fix H extension TVM trap

2023-03-09 Thread LIU Zhiwei
On 2023/3/8 20:34, chenyi2...@zju.edu.cn wrote: From: Yi Chen Trap accesses to hgatp if MSTATUS_TVM is enabled. Don't trap accesses to vsatp even if MSTATUS_TVM is enabled. By the way, do you know why mstatus_tvm and hstatus_tvm are needed? The specification said, The TVM mechanism improves

Re: [PATCH for-8.1 17/17] target/riscv: rework write_misa()

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 15:27, LIU Zhiwei wrote: On 2023/3/9 4:19, Daniel Henrique Barboza wrote: write_misa() must use as much common logic as possible, only specifying the bits that are exclusive to the CSR write operation and TCG internals. Rewrite write_misa() to work as follows: - supress RVC

Re: [PATCH for-8.1 04/17] target/riscv: add PRIV_VERSION_LATEST macro

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 4:19, Daniel Henrique Barboza wrote: PRIV_VERSION_LATEST, at this moment assigned to PRIV_VERSION_1_12_0, is used in all generic CPUs: - riscv_any_cpu_init() - rv32_base_cpu_init() - rv64_base_cpu_init() - rv128_base_cpu_init() When a new PRIV version is made available we can just

Re: [PATCH for-8.1 03/17] target/riscv/cpu.c: remove set_priv_version()

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 4:19, Daniel Henrique Barboza wrote: The setter is doing nothing special. Just set env->priv_ver directly. IMHO, No better than the older implementation. Zhiwei Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 30 +- 1 file changed

Re: [PATCH for-8.1 02/17] target/riscv/cpu.c: remove set_vext_version()

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 4:19, Daniel Henrique Barboza wrote: This setter is doing nothing else but setting env->vext_ver. Assign the value directly. IMHO, No better than the older implementation. Zhiwei Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 7 +-- 1 file changed, 1 i

Re: [PATCH for-8.1 17/17] target/riscv: rework write_misa()

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 4:19, Daniel Henrique Barboza wrote: write_misa() must use as much common logic as possible, only specifying the bits that are exclusive to the CSR write operation and TCG internals. Rewrite write_misa() to work as follows: - supress RVC right after verifying that we're not updati

Re: [PATCH for-8.1 14/17] target/riscv/cpu.c: do not allow RVE to be set

2023-03-08 Thread LIU Zhiwei
On 2023/3/9 4:19, Daniel Henrique Barboza wrote: This restriction is found at the current implementation of write_misa() in csr.c. Add it in riscv_cpu_validate_set_extensions() as well, while also removing the checks we're doing considering that I or E can be enabled. Signed-off-by: Daniel Hen

<    1   2   3   4   5   6   7   8   9   10   >