Skip to content

Commit 19f3e7e

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Register AArch64 system register entries with the sysreg xarray
In order to reduce the number of lookups that we have to perform when handling a sysreg, register each AArch64 sysreg descriptor with the global xarray. The index of the descriptor is stored as a 10 bit field in the data word. Subsequent patches will retrieve and use the stored index. Reviewed-by: Joey Gouly <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 7fd498f commit 19f3e7e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,9 @@ int kvm_handle_cp10_id(struct kvm_vcpu *vcpu);
10781078
void kvm_reset_sys_regs(struct kvm_vcpu *vcpu);
10791079

10801080
int __init kvm_sys_reg_table_init(void);
1081+
struct sys_reg_desc;
1082+
int __init populate_sysreg_config(const struct sys_reg_desc *sr,
1083+
unsigned int idx);
10811084
int __init populate_nv_trap_config(void);
10821085

10831086
bool lock_all_vcpus(struct kvm *kvm);

arch/arm64/kvm/emulate-nested.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,14 @@ static const complex_condition_check ccc[] = {
427427
* [19:14] bit number in the FGT register (6 bits)
428428
* [20] trap polarity (1 bit)
429429
* [25:21] FG filter (5 bits)
430-
* [62:26] Unused (37 bits)
430+
* [35:26] Main SysReg table index (10 bits)
431+
* [62:36] Unused (27 bits)
431432
* [63] RES0 - Must be zero, as lost on insertion in the xarray
432433
*/
433434
#define TC_CGT_BITS 10
434435
#define TC_FGT_BITS 4
435436
#define TC_FGF_BITS 5
437+
#define TC_SRI_BITS 10
436438

437439
union trap_config {
438440
u64 val;
@@ -442,7 +444,8 @@ union trap_config {
442444
unsigned long bit:6; /* Bit number */
443445
unsigned long pol:1; /* Polarity */
444446
unsigned long fgf:TC_FGF_BITS; /* Fine Grained Filter */
445-
unsigned long unused:37; /* Unused, should be zero */
447+
unsigned long sri:TC_SRI_BITS; /* SysReg Index */
448+
unsigned long unused:27; /* Unused, should be zero */
446449
unsigned long mbz:1; /* Must Be Zero */
447450
};
448451
};
@@ -1868,6 +1871,38 @@ int __init populate_nv_trap_config(void)
18681871
return ret;
18691872
}
18701873

1874+
int __init populate_sysreg_config(const struct sys_reg_desc *sr,
1875+
unsigned int idx)
1876+
{
1877+
union trap_config tc;
1878+
u32 encoding;
1879+
void *ret;
1880+
1881+
/*
1882+
* 0 is a valid value for the index, but not for the storage.
1883+
* We'll store (idx+1), so check against an offset'd limit.
1884+
*/
1885+
if (idx >= (BIT(TC_SRI_BITS) - 1)) {
1886+
kvm_err("sysreg %s (%d) out of range\n", sr->name, idx);
1887+
return -EINVAL;
1888+
}
1889+
1890+
encoding = sys_reg(sr->Op0, sr->Op1, sr->CRn, sr->CRm, sr->Op2);
1891+
tc = get_trap_config(encoding);
1892+
1893+
if (tc.sri) {
1894+
kvm_err("sysreg %s (%d) duplicate entry (%d)\n",
1895+
sr->name, idx - 1, tc.sri);
1896+
return -EINVAL;
1897+
}
1898+
1899+
tc.sri = idx + 1;
1900+
ret = xa_store(&sr_forward_xa, encoding,
1901+
xa_mk_value(tc.val), GFP_KERNEL);
1902+
1903+
return xa_err(ret);
1904+
}
1905+
18711906
static enum trap_behaviour get_behaviour(struct kvm_vcpu *vcpu,
18721907
const struct trap_bits *tb)
18731908
{

arch/arm64/kvm/sys_regs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3972,6 +3972,7 @@ int __init kvm_sys_reg_table_init(void)
39723972
struct sys_reg_params params;
39733973
bool valid = true;
39743974
unsigned int i;
3975+
int ret = 0;
39753976

39763977
/* Make sure tables are unique and in order. */
39773978
valid &= check_sysreg_table(sys_reg_descs, ARRAY_SIZE(sys_reg_descs), false);
@@ -3995,5 +3996,13 @@ int __init kvm_sys_reg_table_init(void)
39953996
if (!first_idreg)
39963997
return -EINVAL;
39973998

3998-
return populate_nv_trap_config();
3999+
ret = populate_nv_trap_config();
4000+
4001+
for (i = 0; !ret && i < ARRAY_SIZE(sys_reg_descs); i++)
4002+
ret = populate_sysreg_config(sys_reg_descs + i, i);
4003+
4004+
for (i = 0; !ret && i < ARRAY_SIZE(sys_insn_descs); i++)
4005+
ret = populate_sysreg_config(sys_insn_descs + i, i);
4006+
4007+
return ret;
39994008
}

0 commit comments

Comments
 (0)