diff mbox series

[RFC,v1,07/10] target/loongarch: Implement kvm_arch_handle_exit

Message ID 20230420093606.3366969-8-zhaotianrui@loongson.cn (mailing list archive)
State New, archived
Headers show
Series Add loongarch kvm accel support | expand

Commit Message

zhaotianrui April 20, 2023, 9:36 a.m. UTC
Implement kvm_arch_handle_exit for loongarch. In this
function, the KVM_EXIT_LOONGARCH_IOCSR is handled,
we read or write the iocsr address space by the addr,
length and is_write argument in kvm_run.

Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
 target/loongarch/kvm.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé April 20, 2023, 10 a.m. UTC | #1
On 20/4/23 11:36, Tianrui Zhao wrote:
> Implement kvm_arch_handle_exit for loongarch. In this
> function, the KVM_EXIT_LOONGARCH_IOCSR is handled,
> we read or write the iocsr address space by the addr,
> length and is_write argument in kvm_run.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>   target/loongarch/kvm.c | 24 +++++++++++++++++++++++-
>   1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/target/loongarch/kvm.c b/target/loongarch/kvm.c
> index f8772bbb27..4ce343d276 100644
> --- a/target/loongarch/kvm.c
> +++ b/target/loongarch/kvm.c
> @@ -499,7 +499,29 @@ bool kvm_arch_cpu_check_are_resettable(void)
>   
>   int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
>   {
> -    return 0;
> +    int ret = 0;
> +    LoongArchCPU *cpu = LOONGARCH_CPU(cs);
> +    CPULoongArchState *env = &cpu->env;
> +    MemTxAttrs attrs = {};
> +
> +    attrs.requester_id = env_cpu(env)->cpu_index;
> +
> +    DPRINTF("%s\n", __func__);

Please use trace events instead of DPRINTF(), as we are trying to remove
these.

> +    switch (run->exit_reason) {
> +    case KVM_EXIT_LOONGARCH_IOCSR:
> +        address_space_rw(&env->address_space_iocsr,
> +                         run->iocsr_io.phys_addr,
> +                         attrs,
> +                         run->iocsr_io.data,
> +                         run->iocsr_io.len,
> +                         run->iocsr_io.is_write);
> +        break;
> +    default:
> +        ret = -1;
> +        fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);

Would warn_report() be more appropriate here?

> +        break;
> +    }
> +    return ret;
>   }
>   
>   void kvm_arch_accel_class_init(ObjectClass *oc)
zhaotianrui April 20, 2023, 11:06 a.m. UTC | #2
在 2023年04月20日 18:00, Philippe Mathieu-Daudé 写道:
> On 20/4/23 11:36, Tianrui Zhao wrote:
>> Implement kvm_arch_handle_exit for loongarch. In this
>> function, the KVM_EXIT_LOONGARCH_IOCSR is handled,
>> we read or write the iocsr address space by the addr,
>> length and is_write argument in kvm_run.
>>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>>   target/loongarch/kvm.c | 24 +++++++++++++++++++++++-
>>   1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/target/loongarch/kvm.c b/target/loongarch/kvm.c
>> index f8772bbb27..4ce343d276 100644
>> --- a/target/loongarch/kvm.c
>> +++ b/target/loongarch/kvm.c
>> @@ -499,7 +499,29 @@ bool kvm_arch_cpu_check_are_resettable(void)
>>     int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
>>   {
>> -    return 0;
>> +    int ret = 0;
>> +    LoongArchCPU *cpu = LOONGARCH_CPU(cs);
>> +    CPULoongArchState *env = &cpu->env;
>> +    MemTxAttrs attrs = {};
>> +
>> +    attrs.requester_id = env_cpu(env)->cpu_index;
>> +
>> +    DPRINTF("%s\n", __func__);
>
> Please use trace events instead of DPRINTF(), as we are trying to remove
> these.
Thanks, I will replace it with trace events.

Thanks
Tianrui Zhao
>
>> +    switch (run->exit_reason) {
>> +    case KVM_EXIT_LOONGARCH_IOCSR:
>> +        address_space_rw(&env->address_space_iocsr,
>> +                         run->iocsr_io.phys_addr,
>> +                         attrs,
>> +                         run->iocsr_io.data,
>> +                         run->iocsr_io.len,
>> +                         run->iocsr_io.is_write);
>> +        break;
>> +    default:
>> +        ret = -1;
>> +        fprintf(stderr, "KVM: unknown exit reason %d\n", 
>> run->exit_reason);
>
> Would warn_report() be more appropriate here?
Thanks, I will use warn_report() here.

Thanks
Tianrui Zhao
>
>> +        break;
>> +    }
>> +    return ret;
>>   }
>>     void kvm_arch_accel_class_init(ObjectClass *oc)
diff mbox series

Patch

diff --git a/target/loongarch/kvm.c b/target/loongarch/kvm.c
index f8772bbb27..4ce343d276 100644
--- a/target/loongarch/kvm.c
+++ b/target/loongarch/kvm.c
@@ -499,7 +499,29 @@  bool kvm_arch_cpu_check_are_resettable(void)
 
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
-    return 0;
+    int ret = 0;
+    LoongArchCPU *cpu = LOONGARCH_CPU(cs);
+    CPULoongArchState *env = &cpu->env;
+    MemTxAttrs attrs = {};
+
+    attrs.requester_id = env_cpu(env)->cpu_index;
+
+    DPRINTF("%s\n", __func__);
+    switch (run->exit_reason) {
+    case KVM_EXIT_LOONGARCH_IOCSR:
+        address_space_rw(&env->address_space_iocsr,
+                         run->iocsr_io.phys_addr,
+                         attrs,
+                         run->iocsr_io.data,
+                         run->iocsr_io.len,
+                         run->iocsr_io.is_write);
+        break;
+    default:
+        ret = -1;
+        fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
+        break;
+    }
+    return ret;
 }
 
 void kvm_arch_accel_class_init(ObjectClass *oc)