Skip to content

Commit

Permalink
fix(riscv/vplic): correct max interrupt checks
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Martins <[email protected]>
  • Loading branch information
josecm authored and DavidMCerdeira committed Oct 15, 2023
1 parent f224651 commit f1fde01
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/arch/riscv/irqc/plic/vplic.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ static bool vplic_get_pend(struct vcpu* vcpu, irqid_t id)
{
bool ret = false;
struct vplic * vplic = &vcpu->vm->arch.vplic;
if (id <= PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->pend, id);
if (id < PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->pend, id);
return ret;
}

static bool vplic_get_act(struct vcpu* vcpu, irqid_t id)
{
bool ret = false;
struct vplic * vplic = &vcpu->vm->arch.vplic;
if (id <= PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->act, id);
if (id < PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->act, id);
return ret;
}

static bool vplic_get_enbl(struct vcpu* vcpu, int vcntxt, irqid_t id)
{
bool ret = false;
struct vplic * vplic = &vcpu->vm->arch.vplic;
if (id <= PLIC_MAX_INTERRUPTS) ret = !!bitmap_get(vplic->enbl[vcntxt], id);
if (id < PLIC_MAX_INTERRUPTS) ret = !!bitmap_get(vplic->enbl[vcntxt], id);
return ret;
}

Expand All @@ -60,14 +60,14 @@ static uint32_t vplic_get_prio(struct vcpu *vcpu, irqid_t id)
{
uint32_t ret = 0;
struct vplic * vplic = &vcpu->vm->arch.vplic;
if (id <= PLIC_MAX_INTERRUPTS) ret = vplic->prio[id];
if (id < PLIC_MAX_INTERRUPTS) ret = vplic->prio[id];
return ret;
}


void vplic_set_hw(struct vm *vm, irqid_t id)
{
if (id <= PLIC_MAX_INTERRUPTS) {
if (id < PLIC_MAX_INTERRUPTS) {
bitmap_set(vm->arch.vplic.hw,id);
}
}
Expand All @@ -76,7 +76,7 @@ static bool vplic_get_hw(struct vcpu* vcpu, irqid_t id)
{
bool ret = false;
struct vplic * vplic = &vcpu->vm->arch.vplic;
if (id <= PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->hw, id);
if (id < PLIC_MAX_INTERRUPTS) ret = bitmap_get(vplic->hw, id);
return ret;
}

Expand All @@ -91,7 +91,7 @@ static irqid_t vplic_next_pending(struct vcpu *vcpu, int vcntxt)
uint32_t max_prio = 0;
irqid_t int_id = 0;

for (size_t i = 0; i <= PLIC_MAX_INTERRUPTS; i++) {
for (size_t i = 0; i < PLIC_MAX_INTERRUPTS; i++) {
if (vplic_get_pend(vcpu, i) && !vplic_get_act(vcpu, i) &&
vplic_get_enbl(vcpu, vcntxt, i)) {

Expand Down Expand Up @@ -155,7 +155,7 @@ static void vplic_set_enbl(struct vcpu* vcpu, int vcntxt, irqid_t id, bool set)
{
struct vplic * vplic = &vcpu->vm->arch.vplic;
spin_lock(&vplic->lock);
if (id <= PLIC_MAX_INTERRUPTS && vplic_get_enbl(vcpu, vcntxt, id) != set) {
if (id < PLIC_MAX_INTERRUPTS && vplic_get_enbl(vcpu, vcntxt, id) != set) {
if(set){
bitmap_set(vplic->enbl[vcntxt],id);
} else {
Expand All @@ -176,7 +176,7 @@ static void vplic_set_prio(struct vcpu *vcpu, irqid_t id, uint32_t prio)
{
struct vplic *vplic = &vcpu->vm->arch.vplic;
spin_lock(&vplic->lock);
if (id <= PLIC_MAX_INTERRUPTS && vplic_get_prio(vcpu, id) != prio) {
if (id < PLIC_MAX_INTERRUPTS && vplic_get_prio(vcpu, id) != prio) {
vplic->prio[id] = prio;
if(vplic_get_hw(vcpu,id)){
plic_set_prio(id, prio);
Expand Down Expand Up @@ -221,7 +221,7 @@ void vplic_inject(struct vcpu *vcpu, irqid_t id)
{
struct vplic * vplic = &vcpu->vm->arch.vplic;
spin_lock(&vplic->lock);
if (id > 0 && id <= PLIC_MAX_INTERRUPTS && !vplic_get_pend(vcpu, id)) {
if (id > 0 && id < PLIC_MAX_INTERRUPTS && !vplic_get_pend(vcpu, id)) {

bitmap_set(vplic->pend, id);

Expand Down

0 comments on commit f1fde01

Please sign in to comment.