Skip to content

Commit

Permalink
KVM: arm64: Reuse sys_reg() macro when searching the trap table
Browse files Browse the repository at this point in the history
Instead of having an open-coded macro, reuse the sys_reg() macro
that does the exact same thing (the encoding is slightly different,
but the ordering property is the same).

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
  • Loading branch information
Marc Zyngier committed Feb 19, 2019
1 parent b98c079 commit 09838de
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions arch/arm64/kvm/sys_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
return true;
}

#define reg_to_encoding(x) \
sys_reg((u32)(x)->Op0, (u32)(x)->Op1, \
(u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2);

/* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */
#define DBG_BCR_BVR_WCR_WVR_EL1(n) \
{ SYS_DESC(SYS_DBGBVRn_EL1(n)), \
Expand Down Expand Up @@ -1820,30 +1824,19 @@ static const struct sys_reg_desc *get_target_table(unsigned target,
}
}

#define reg_to_match_value(x) \
({ \
unsigned long val; \
val = (x)->Op0 << 14; \
val |= (x)->Op1 << 11; \
val |= (x)->CRn << 7; \
val |= (x)->CRm << 3; \
val |= (x)->Op2; \
val; \
})

static int match_sys_reg(const void *key, const void *elt)
{
const unsigned long pval = (unsigned long)key;
const struct sys_reg_desc *r = elt;

return pval - reg_to_match_value(r);
return pval - reg_to_encoding(r);
}

static const struct sys_reg_desc *find_reg(const struct sys_reg_params *params,
const struct sys_reg_desc table[],
unsigned int num)
{
unsigned long pval = reg_to_match_value(params);
unsigned long pval = reg_to_encoding(params);

return bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg);
}
Expand Down

0 comments on commit 09838de

Please sign in to comment.