On Mon, Feb 24, 2025 at 04:24:15PM +0800, Yong-Xuan Wang wrote:
> Currently QEMU will continue to create the IMSIC devices and enable the
> AIA extension for guest OS when the host kernel doesn't support the AIA
> extension. This will cause an illegal instruction exception when the
> guest OS access the AIA CSRs. Add additional checks to ensure the
> guest OS only uses the IMSIC devices when the host kernel supports
> the AIA extension.
> 
> Signed-off-by: Yong-Xuan Wang <yongxuan.w...@sifive.com>
> ---
>  hw/intc/riscv_imsic.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c
> index dc8162c0a7c9..8c64f2c21274 100644
> --- a/hw/intc/riscv_imsic.c
> +++ b/hw/intc/riscv_imsic.c
> @@ -375,12 +375,21 @@ static void riscv_imsic_realize(DeviceState *dev, Error 
> **errp)
>  
>      /* Force select AIA feature and setup CSR read-modify-write callback */
>      if (env) {
> -        if (!imsic->mmode) {
> -            rcpu->cfg.ext_ssaia = true;
> -            riscv_cpu_set_geilen(env, imsic->num_pages - 1);
> +        if (kvm_enabled()) {
> +            if (!rcpu->cfg.ext_ssaia) {
> +                error_report("Host machine doesn't support AIA extension. "
> +                             "Do not use IMSIC as interrupt controller.");
> +                exit(1);
> +            }
>          } else {
> -            rcpu->cfg.ext_smaia = true;
> +            if (!imsic->mmode) {
> +                rcpu->cfg.ext_ssaia = true;
> +                riscv_cpu_set_geilen(env, imsic->num_pages - 1);
> +            } else {
> +                rcpu->cfg.ext_smaia = true;
> +            }
>          }
> +
>          riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PRV_S,
>                                        riscv_imsic_rmw, imsic);
>      }
> -- 
> 2.17.1
> 
>

Reviewed-by: Andrew Jones <ajo...@ventanamicro.com>

Reply via email to