hw/intc/aplic: Fix msicfgaddrH in split mode
PATCH v2 1/1 hw/intc/aplic: Fix msicfgaddrH in split mode
Add hart_bits and guest_bits to msicfgaddrH in KVM irqchip split mode.
Also remove the redundant left shift when loading kvm_msicfgaddrH in riscv_aplic_msi_send().
Rationale:
static void riscv_aplic_msi_send(RISCVAPLICState *aplic,
uint32_t hart_idx, uint32_t guest_idx,
uint32_t eiid)
{
uint64_t addr;
MemTxResult result;
RISCVAPLICState *aplic_m;
uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH;
...
if (aplic->kvm_splitmode) {
msicfgaddr = aplic->kvm_msicfgaddr;
1. msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32);
}
...
lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) &
APLIC_xMSICFGADDRH_LHXS_MASK;
lhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) &
APLIC_xMSICFGADDRH_LHXW_MASK;
hhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) &
APLIC_xMSICFGADDRH_HHXS_MASK;
hhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) &
APLIC_xMSICFGADDRH_HHXW_MASK;
...
group_idx = hart_idx >> lhxw;
addr = msicfgaddr;
2. addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK))
<< 32;
addr |= ((uint64_t)(group_idx &
APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) <<
APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs);
3. addr |= ((uint64_t)(hart_idx &
APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) <<
APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs);
4. addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs));
addr <<= APLIC_xMSICFGADDR_PPN_SHIFT;
...
}Since msicfgaddrH is left-shifted at (2), the left shift at (1) is redundant.
At (3) and (4), hart_idx and guest_idx are masked/shifted using lhxw and lhxs, which are extracted from the LHXW/LHXS fields of msicfgaddrH. However, riscv_aplic_set_kvm_msicfgaddr() did not program the LHXW/LHXS fields into kvm_msicfgaddrH, so lhxs/lhxw always read as zero, and the hart/guest idxs were never encoded into the MSI address. Fix this by programming hart_bits (LHXW) and guest_bits (LHXS) into kvm_msicfgaddrH in riscv_aplic_set_kvm_msicfgaddr().
---
Changes in v2:
- Add rationale.
--- hw/intc/riscv_aplic.c | 13 +++++++++---- hw/riscv/aia.c | 6 +++++- include/hw/intc/riscv_aplic.h | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-)
hw/intc/riscv_aplic.c +9 -4
@@ -182,7 +182,8 @@ bool riscv_use_emulated_aplic(bool msimode)return kvm_kernel_irqchip_split (); } -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits) {if (!kvm_enabled ()) {return ;
@@ -191,8 +192,12 @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr)if (riscv_use_emulated_aplic (aplic->msimode)) { addr >>= APLIC_xMSICFGADDR_PPN_SHIFT; aplic->kvm_msicfgaddr =extract64 (addr,0 ,32 ); - aplic->kvm_msicfgaddrH =extract64 (addr,32 ,32 ) & -APLIC_MMSICFGADDRH_VALID_MASK ; + aplic->kvm_msicfgaddrH = + ((hart_bits & APLIC_xMSICFGADDRH_LHXW_MASK) << + APLIC_xMSICFGADDRH_LHXW_SHIFT) | + ((guest_bits & APLIC_xMSICFGADDRH_LHXS_MASK) << + APLIC_xMSICFGADDRH_LHXS_SHIFT) | + (extract64 (addr,32 ,32 ) & APLIC_xMSICFGADDRH_BAPPN_MASK); } }
@@ -404,7 +409,7 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic,if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; - msicfgaddrH = ((uint64_t )aplic->kvm_msicfgaddrH <<32 ); + msicfgaddrH = aplic->kvm_msicfgaddrH; }else { msicfgaddr = aplic_m->mmsicfgaddr; msicfgaddrH = aplic_m->mmsicfgaddrH;
hw/riscv/aia.c +5 -1
@@ -38,6 +38,7 @@ DeviceState *riscv_create_aia(MemoryRegion *container, {int i;hwaddr addr =0 ; +uint32_t hart_bits, guest_bits;DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ;
@@ -93,7 +94,10 @@ DeviceState *riscv_create_aia(MemoryRegion *container, msimode, false, aplic_m_dev);if (kvm_enabled () && msimode) { -riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr); + hart_bits =imsic_num_bits (hart_count); + guest_bits =imsic_num_bits (aia_guests +1 ); +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr, + hart_bits, guest_bits); }return kvm_enabled () ? aplic_s_dev : aplic_m_dev;
include/hw/intc/riscv_aplic.h +2 -1
@@ -78,7 +78,8 @@ struct RISCVAPLICState {void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode);bool riscv_use_emulated_aplic (bool msimode); -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits); DeviceState *riscv_aplic_create(MemoryRegion *container, hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts,
Signature · 1 line
2.53.0
Quoted 60 lines · BillXiang
Add
hart_bitsandguest_bitsto msicfgaddrH in KVM irqchip split mode.
Also remove the redundant left shift when loadingkvm_msicfgaddrHinriscv_aplic_msi_send().Rationale:
static void riscv_aplic_msi_send(RISCVAPLICState *aplic,uint32_t hart_idx, uint32_t guest_idx, uint32_t eiid) { uint64_t addr; MemTxResult result; RISCVAPLICState *aplic_m; uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; ... if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; 1. msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32); } ... lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & APLIC_xMSICFGADDRH_LHXS_MASK; lhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) & APLIC_xMSICFGADDRH_LHXW_MASK; hhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) & APLIC_xMSICFGADDRH_HHXS_MASK; hhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) & APLIC_xMSICFGADDRH_HHXW_MASK; ... group_idx = hart_idx >> lhxw; addr = msicfgaddr; 2. addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; addr |= ((uint64_t)(group_idx & APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) << APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs); 3. addr |= ((uint64_t)(hart_idx & APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) << APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs); 4. addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; ... }Since msicfgaddrH is left-shifted at (2), the left shift at (1) is redundant.
At (3) and (4),
hart_idxandguest_idxare masked/shifted using lhxw and lhxs, which are extracted from the LHXW/LHXS fields of msicfgaddrH. However,riscv_aplic_set_kvm_msicfgaddr()did not program the LHXW/LHXS fields intokvm_msicfgaddrH, so lhxs/lhxw always read as zero, and the hart/guest idxs were never encoded into the MSI address. Fix this by programminghart_bits(LHXW) andguest_bits(LHXS) intokvm_msicfgaddrHinriscv_aplic_set_kvm_msicfgaddr().
Quoted 2 lines
Signed-off-by BillXiang <[email protected]>---
Quoted 84 lines
Changes in v2:
- Add rationale.--- hw/intc/riscv_aplic.c | 13 +++++++++---- hw/riscv/aia.c | 6 +++++- include/hw/intc/riscv_aplic.h | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-)hw/intc/riscv_aplic.c +9
-4@@ -182,7 +182,8 @@ bool riscv_use_emulated_aplic(bool msimode)return kvm_kernel_irqchip_split (); } -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits) {if (!kvm_enabled ()) {return ;@@ -191,8 +192,12 @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr)if (riscv_use_emulated_aplic (aplic->msimode)) { addr >>= APLIC_xMSICFGADDR_PPN_SHIFT; aplic->kvm_msicfgaddr =extract64 (addr,0 ,32 ); - aplic->kvm_msicfgaddrH =extract64 (addr,32 ,32 ) & -APLIC_MMSICFGADDRH_VALID_MASK ; + aplic->kvm_msicfgaddrH = + ((hart_bits & APLIC_xMSICFGADDRH_LHXW_MASK) << + APLIC_xMSICFGADDRH_LHXW_SHIFT) | + ((guest_bits & APLIC_xMSICFGADDRH_LHXS_MASK) << + APLIC_xMSICFGADDRH_LHXS_SHIFT) | + (extract64 (addr,32 ,32 ) & APLIC_xMSICFGADDRH_BAPPN_MASK); } }@@ -404,7 +409,7 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic,if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; - msicfgaddrH = ((uint64_t )aplic->kvm_msicfgaddrH <<32 ); + msicfgaddrH = aplic->kvm_msicfgaddrH; }else { msicfgaddr = aplic_m->mmsicfgaddr; msicfgaddrH = aplic_m->mmsicfgaddrH;hw/riscv/aia.c +5
-1@@ -38,6 +38,7 @@ DeviceState *riscv_create_aia(MemoryRegion *container, {int i;hwaddr addr =0 ; +uint32_t hart_bits, guest_bits;DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ;@@ -93,7 +94,10 @@ DeviceState *riscv_create_aia(MemoryRegion *container, msimode, false, aplic_m_dev);if (kvm_enabled () && msimode) { -riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr); + hart_bits =imsic_num_bits (hart_count); + guest_bits =imsic_num_bits (aia_guests +1 ); +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr, + hart_bits, guest_bits); }return kvm_enabled () ? aplic_s_dev : aplic_m_dev;include/hw/intc/riscv_aplic.h +2
-1@@ -78,7 +78,8 @@ struct RISCVAPLICState {void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode);bool riscv_use_emulated_aplic (bool msimode); -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits); DeviceState *riscv_aplic_create(MemoryRegion *container, hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts,
Quoted 85 lines · BillXiang
Add
hart_bitsandguest_bitsto msicfgaddrH in KVM irqchip split mode.
Also remove the redundant left shift when loadingkvm_msicfgaddrHinriscv_aplic_msi_send().Rationale:
static void riscv_aplic_msi_send(RISCVAPLICState *aplic,uint32_t hart_idx, uint32_t guest_idx, uint32_t eiid) { uint64_t addr; MemTxResult result; RISCVAPLICState *aplic_m; uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; ... if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; 1. msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32); } ... lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & APLIC_xMSICFGADDRH_LHXS_MASK; lhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) & APLIC_xMSICFGADDRH_LHXW_MASK; hhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) & APLIC_xMSICFGADDRH_HHXS_MASK; hhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) & APLIC_xMSICFGADDRH_HHXW_MASK; ... group_idx = hart_idx >> lhxw; addr = msicfgaddr; 2. addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; addr |= ((uint64_t)(group_idx & APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) << APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs); 3. addr |= ((uint64_t)(hart_idx & APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) << APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs); 4. addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; ... }Since msicfgaddrH is left-shifted at (2), the left shift at (1) is redundant.
At (3) and (4),
hart_idxandguest_idxare masked/shifted using lhxw and lhxs, which are extracted from the LHXW/LHXS fields of msicfgaddrH. However,riscv_aplic_set_kvm_msicfgaddr()did not program the LHXW/LHXS fields intokvm_msicfgaddrH, so lhxs/lhxw always read as zero, and the hart/guest idxs were never encoded into the MSI address. Fix this by programminghart_bits(LHXW) andguest_bits(LHXS) intokvm_msicfgaddrHinriscv_aplic_set_kvm_msicfgaddr().Signed-off-by BillXiang <[email protected]>---
Changes in v2:
- Add rationale.--- hw/intc/riscv_aplic.c | 13 +++++++++---- hw/riscv/aia.c | 6 +++++- include/hw/intc/riscv_aplic.h | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-)hw/intc/riscv_aplic.c +2
-1@@ -182,7 +182,8 @@ bool riscv_use_emulated_aplic(bool msimode)return kvm_kernel_irqchip_split (); } -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits) {if (!kvm_enabled ()) {return ;
hw/intc/riscv_aplic.c void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) · line 195
Quoted 5 lines
hw/intc/riscv_aplic.c +0
-2@@ -191,8 +192,12 @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr)if (riscv_use_emulated_aplic (aplic->msimode)) { addr >>= APLIC_xMSICFGADDR_PPN_SHIFT; aplic->kvm_msicfgaddr =extract64 (addr,0 ,32 ); - aplic->kvm_msicfgaddrH =extract64 (addr,32 ,32 ) & -APLIC_MMSICFGADDRH_VALID_MASK ;
Is it necessary to perform boundary checks on hart_bits/guest_bits ? Just like:
+ assert(hart_bits <= APLIC_xMSICFGADDRH_LHXW_MASK); + assert(guest_bits <= APLIC_xMSICFGADDRH_LHXS_MASK);
Otherwise,
Thanks,
Nutty
Quoted 56 lines
hw/intc/riscv_aplic.c +7
-1+ aplic->kvm_msicfgaddrH = + ((hart_bits & APLIC_xMSICFGADDRH_LHXW_MASK) << + APLIC_xMSICFGADDRH_LHXW_SHIFT) | + ((guest_bits & APLIC_xMSICFGADDRH_LHXS_MASK) << + APLIC_xMSICFGADDRH_LHXS_SHIFT) | + (extract64 (addr,32 ,32 ) & APLIC_xMSICFGADDRH_BAPPN_MASK); } }@@ -404,7 +409,7 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic,if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; - msicfgaddrH = ((uint64_t )aplic->kvm_msicfgaddrH <<32 ); + msicfgaddrH = aplic->kvm_msicfgaddrH; }else { msicfgaddr = aplic_m->mmsicfgaddr; msicfgaddrH = aplic_m->mmsicfgaddrH;hw/riscv/aia.c +5
-1@@ -38,6 +38,7 @@ DeviceState *riscv_create_aia(MemoryRegion *container, {int i;hwaddr addr =0 ; +uint32_t hart_bits, guest_bits;DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ;@@ -93,7 +94,10 @@ DeviceState *riscv_create_aia(MemoryRegion *container, msimode, false, aplic_m_dev);if (kvm_enabled () && msimode) { -riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr); + hart_bits =imsic_num_bits (hart_count); + guest_bits =imsic_num_bits (aia_guests +1 ); +riscv_aplic_set_kvm_msicfgaddr (RISCV_APLIC (aplic_s_dev), addr, + hart_bits, guest_bits); }return kvm_enabled () ? aplic_s_dev : aplic_m_dev;include/hw/intc/riscv_aplic.h +2
-1@@ -78,7 +78,8 @@ struct RISCVAPLICState {void riscv_aplic_add_child (DeviceState *parent,DeviceState *child);bool riscv_is_kvm_aia_aplic_imsic (bool msimode);bool riscv_use_emulated_aplic (bool msimode); -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, +uint32_t hart_bits,uint32_t guest_bits); DeviceState *riscv_aplic_create(MemoryRegion *container, hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts,
Quoted 90 lines · Nutty.Liu
Quoted 88 lines · BillXiang
Add
hart_bitsandguest_bitsto msicfgaddrH in KVM irqchip split mode.
Also remove the redundant left shift when loadingkvm_msicfgaddrHinriscv_aplic_msi_send().Rationale:
static voidriscv_aplic_msi_send(RISCVAPLICState *aplic, uint32_t hart_idx, uint32_t guest_idx, uint32_t eiid)
{
uint64_taddr;
MemTxResult result;
RISCVAPLICState*aplic_m;
uint32_tlhxs, lhxw, hhxs, hhxw,group_idx, msicfgaddr, msicfgaddrH;...
if (
aplic->kvm_splitmode) {
msicfgaddr =aplic->kvm_msicfgaddr;
1. msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32); }
...lhxs = (msicfgaddrH >>
APLIC_xMSICFGADDRH_LHXS_SHIFT) &APLIC_xMSICFGADDRH_LHXS_MASK;
lhxw = (msicfgaddrH >>APLIC_xMSICFGADDRH_LHXW_SHIFT) &APLIC_xMSICFGADDRH_LHXW_MASK;
hhxs = (msicfgaddrH >>APLIC_xMSICFGADDRH_HHXS_SHIFT) &APLIC_xMSICFGADDRH_HHXS_MASK;
hhxw = (msicfgaddrH >>APLIC_xMSICFGADDRH_HHXW_SHIFT) &APLIC_xMSICFGADDRH_HHXW_MASK;
...
group_idx=hart_idx>> lhxw;addr = msicfgaddr;
2. addr |= ((uint64_t)(msicfgaddrH &APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32;
addr |= ((uint64_t)(group_idx &APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) <<APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs);
3. addr |= ((uint64_t)(hart_idx &APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) <<APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs);
4. addr |= (uint64_t)(guest_idx &APLIC_xMSICFGADDR_PPN_HART(lhxs)); addr <<=APLIC_xMSICFGADDR_PPN_SHIFT;
...
}Since msicfgaddrH is left-shifted at (2), the left shift at (1) is redundant.
At (3) and (4),
hart_idxandguest_idxare masked/shifted using lhxw and lhxs, which are extracted from the LHXW/LHXS fields of msicfgaddrH. However,riscv_aplic_set_kvm_msicfgaddr()did not program the LHXW/LHXS fields intokvm_msicfgaddrH, so lhxs/lhxw always read as zero, and the hart/guest idxs were never encoded into the MSI address. Fix this by programminghart_bits(LHXW) andguest_bits(LHXS) intokvm_msicfgaddrHinriscv_aplic_set_kvm_msicfgaddr().Signed-off-by BillXiang <[email protected]>---
Changes in v2:
- Add rationale.
---
hw/intc/riscv_aplic.c | 13 +++++++++---- hw/riscv/aia.c | 6 +++++-include/hw/intc/riscv_aplic.h| 3 ++-3 files changed, 16 insertions(+), 6 deletions(-)hw/intc/riscv_aplic.c +2
-1@@ -182,7 +182,8 @@ bool riscv_use_emulated_aplic(bool msimode) return kvm_kernel_irqchip_split(); } -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr) +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, + uint32_t hart_bits, uint32_t guest_bits) { if (!kvm_enabled()) { return;@@ -191,8 +192,12 @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) if (riscv_use_emulated_aplic(aplic->msimode)) {
Quoted 8 lines
hw/intc/riscv_aplic.c void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) · line 195
Quoted 4 lines
hw/intc/riscv_aplic.c +0
-2addr >>= APLIC_xMSICFGADDR_PPN_SHIFT; aplic->kvm_msicfgaddr = extract64(addr, 0, 32); - aplic->kvm_msicfgaddrH = extract64(addr, 32, 32) & - APLIC_MMSICFGADDRH_VALID_MASK;Is it necessary to perform boundary checks on hart_bits/guest_bits ? Just like:
+assert(hart_bits <= APLIC_xMSICFGADDRH_LHXW_MASK); +assert(guest_bits <= APLIC_xMSICFGADDRH_LHXS_MASK);
Thank you for the review. I'll add it to v3.
Regards,
Bill
Quoted 60 lines
Otherwise,
Reviewed-by Nutty Liu <[email protected]>Thanks,
NuttyQuoted 54 lines
hw/intc/riscv_aplic.c +7
-1+ aplic->kvm_msicfgaddrH = + ((hart_bits & APLIC_xMSICFGADDRH_LHXW_MASK) << + APLIC_xMSICFGADDRH_LHXW_SHIFT) | + ((guest_bits & APLIC_xMSICFGADDRH_LHXS_MASK) << + APLIC_xMSICFGADDRH_LHXS_SHIFT) | + (extract64(addr, 32, 32) & APLIC_xMSICFGADDRH_BAPPN_MASK); } }@@ -404,7 +409,7 @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, if (aplic->kvm_splitmode) { msicfgaddr = aplic->kvm_msicfgaddr; - msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32); + msicfgaddrH = aplic->kvm_msicfgaddrH; } else { msicfgaddr = aplic_m->mmsicfgaddr; msicfgaddrH = aplic_m->mmsicfgaddrH;hw/riscv/aia.c +5
-1@@ -38,6 +38,7 @@ DeviceState *riscv_create_aia(MemoryRegion *container, { int i; hwaddr addr = 0; + uint32_t hart_bits, guest_bits; DeviceState *aplic_s_dev = NULL; DeviceState *aplic_m_dev = NULL;@@ -93,7 +94,10 @@ DeviceState *riscv_create_aia(MemoryRegion *container, msimode, false, aplic_m_dev); if (kvm_enabled() && msimode) { - riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s_dev), addr); + hart_bits = imsic_num_bits(hart_count); + guest_bits = imsic_num_bits(aia_guests + 1); + riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s_dev), addr, + hart_bits, guest_bits); } return kvm_enabled() ? aplic_s_dev : aplic_m_dev;include/hw/intc/ renamed from include/hw/intc/riscv_aplic.h +0
-0
riscv_aplic.h
index62d2b33ade..d3ee2e537a100644include/hw/intc/riscv_aplic.h +2
-1@@ -78,7 +78,8 @@ struct RISCVAPLICState { void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); bool riscv_is_kvm_aia_aplic_imsic(bool msimode); bool riscv_use_emulated_aplic(bool msimode); -void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr); +void riscv_aplic_set_kvm_msicfgaddr (RISCVAPLICState *aplic,hwaddr addr, + uint32_t hart_bits, uint32_t guest_bits); DeviceState *riscv_aplic_create(MemoryRegion *container,hwaddr addr, hwaddr size,
uint32_thartid_base,uint32_tnum_harts,