diff mbox series

[1/1] target/riscv/kvm.c: remove group setting of KVM AIA if the machine only has 1 socket

Message ID 20231218090543.22353-2-yongxuan.wang@sifive.com
State New
Headers show
Series [1/1] target/riscv/kvm.c: remove group setting of KVM AIA if the machine only has 1 socket | expand

Commit Message

Yong-Xuan Wang Dec. 18, 2023, 9:05 a.m. UTC
The emulated AIA within the Linux kernel restores the HART index
of the IMSICs according to the configured AIA settings. During
this process, the group setting is used only when the machine
partitions harts into groups. It's unnecessary to set the group
configuration if the machine has only one socket, as its address
space might not contain the group shift.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Reviewed-by: Jim Shu <jim.shu@sifive.com>
---
 target/riscv/kvm/kvm-cpu.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

Comments

Daniel Henrique Barboza Dec. 18, 2023, 9:42 p.m. UTC | #1
On 12/18/23 06:05, Yong-Xuan Wang wrote:
> The emulated AIA within the Linux kernel restores the HART index
> of the IMSICs according to the configured AIA settings. During
> this process, the group setting is used only when the machine
> partitions harts into groups. It's unnecessary to set the group
> configuration if the machine has only one socket, as its address
> space might not contain the group shift.
> 
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> Reviewed-by: Jim Shu <jim.shu@sifive.com>
> ---

Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

>   target/riscv/kvm/kvm-cpu.c | 31 +++++++++++++++++--------------
>   1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 62a1e51f0a2e..6494597157b8 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1387,21 +1387,24 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
>           exit(1);
>       }
>   
> -    socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
> -    ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> -                            KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
> -                            &socket_bits, true, NULL);
> -    if (ret < 0) {
> -        error_report("KVM AIA: failed to set group_bits");
> -        exit(1);
> -    }
>   
> -    ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> -                            KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
> -                            &group_shift, true, NULL);
> -    if (ret < 0) {
> -        error_report("KVM AIA: failed to set group_shift");
> -        exit(1);
> +    if (socket_count > 1) {
> +        socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
> +        ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> +                                KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
> +                                &socket_bits, true, NULL);
> +        if (ret < 0) {
> +            error_report("KVM AIA: failed to set group_bits");
> +            exit(1);
> +        }
> +
> +        ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
> +                                KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
> +                                &group_shift, true, NULL);
> +        if (ret < 0) {
> +            error_report("KVM AIA: failed to set group_shift");
> +            exit(1);
> +        }
>       }
>   
>       guest_bits = guest_num == 0 ? 0 :
diff mbox series

Patch

diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 62a1e51f0a2e..6494597157b8 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1387,21 +1387,24 @@  void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
         exit(1);
     }
 
-    socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
-    ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
-                            KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
-                            &socket_bits, true, NULL);
-    if (ret < 0) {
-        error_report("KVM AIA: failed to set group_bits");
-        exit(1);
-    }
 
-    ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
-                            KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
-                            &group_shift, true, NULL);
-    if (ret < 0) {
-        error_report("KVM AIA: failed to set group_shift");
-        exit(1);
+    if (socket_count > 1) {
+        socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
+        ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
+                                KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS,
+                                &socket_bits, true, NULL);
+        if (ret < 0) {
+            error_report("KVM AIA: failed to set group_bits");
+            exit(1);
+        }
+
+        ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
+                                KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT,
+                                &group_shift, true, NULL);
+        if (ret < 0) {
+            error_report("KVM AIA: failed to set group_shift");
+            exit(1);
+        }
     }
 
     guest_bits = guest_num == 0 ? 0 :