diff mbox series

target/riscv/kvm: Fix the group bit setting of AIA

Message ID 20240821075040.498945-2-ajones@ventanamicro.com (mailing list archive)
State New, archived
Headers show
Series target/riscv/kvm: Fix the group bit setting of AIA | expand

Commit Message

Andrew Jones Aug. 21, 2024, 7:50 a.m. UTC
Just as the hart bit setting of the AIA should be calculated as
ceil(log2(max_hart_id + 1)) the group bit setting should be
calculated as ceil(log2(max_group_id + 1)). The hart bits are
implemented by passing max_hart_id to find_last_bit() and adding
one to the result. Do the same for the group bit setting.

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
 target/riscv/kvm/kvm-cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Daniel Henrique Barboza Aug. 22, 2024, 8:18 p.m. UTC | #1
On 8/21/24 4:50 AM, Andrew Jones wrote:
> Just as the hart bit setting of the AIA should be calculated as
> ceil(log2(max_hart_id + 1)) the group bit setting should be
> calculated as ceil(log2(max_group_id + 1)). The hart bits are
> implemented by passing max_hart_id to find_last_bit() and adding
> one to the result. Do the same for the group bit setting.
> 
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> ---

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

>   target/riscv/kvm/kvm-cpu.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index f6e3156b8d2f..341af901c5b0 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1695,6 +1695,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
>       uint64_t max_hart_per_socket = 0;
>       uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr;
>       uint64_t socket_bits, hart_bits, guest_bits;
> +    uint64_t max_group_id;
>   
>       aia_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_RISCV_AIA, false);
>   
> @@ -1742,7 +1743,8 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
>   
>   
>       if (socket_count > 1) {
> -        socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
> +        max_group_id = socket_count - 1;
> +        socket_bits = find_last_bit(&max_group_id, 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);
Alistair Francis Aug. 26, 2024, 12:28 a.m. UTC | #2
On Wed, Aug 21, 2024 at 5:51 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> Just as the hart bit setting of the AIA should be calculated as
> ceil(log2(max_hart_id + 1)) the group bit setting should be
> calculated as ceil(log2(max_group_id + 1)). The hart bits are
> implemented by passing max_hart_id to find_last_bit() and adding
> one to the result. Do the same for the group bit setting.
>
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  target/riscv/kvm/kvm-cpu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index f6e3156b8d2f..341af901c5b0 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1695,6 +1695,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
>      uint64_t max_hart_per_socket = 0;
>      uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr;
>      uint64_t socket_bits, hart_bits, guest_bits;
> +    uint64_t max_group_id;
>
>      aia_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_RISCV_AIA, false);
>
> @@ -1742,7 +1743,8 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
>
>
>      if (socket_count > 1) {
> -        socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
> +        max_group_id = socket_count - 1;
> +        socket_bits = find_last_bit(&max_group_id, 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);
> --
> 2.45.2
>
>
diff mbox series

Patch

diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index f6e3156b8d2f..341af901c5b0 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1695,6 +1695,7 @@  void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
     uint64_t max_hart_per_socket = 0;
     uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr;
     uint64_t socket_bits, hart_bits, guest_bits;
+    uint64_t max_group_id;
 
     aia_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_RISCV_AIA, false);
 
@@ -1742,7 +1743,8 @@  void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
 
 
     if (socket_count > 1) {
-        socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1;
+        max_group_id = socket_count - 1;
+        socket_bits = find_last_bit(&max_group_id, 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);