Skip to content

Commit cb853de

Browse files
author
Marc Zyngier
committed
KVM: arm64: Fix debug register indexing
Commit 03fdfb2 ("KVM: arm64: Don't write junk to sysregs on reset") flipped the register number to 0 for all the debug registers in the sysreg table, hereby indicating that these registers live in a separate shadow structure. However, the author of this patch failed to realise that all the accessors are using that particular index instead of the register encoding, resulting in all the registers hitting index 0. Not quite a valid implementation of the architecture... Address the issue by fixing all the accessors to use the CRm field of the encoding, which contains the debug register index. Fixes: 03fdfb2 ("KVM: arm64: Don't write junk to sysregs on reset") Reported-by: Ricardo Koller <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected]
1 parent 26778aa commit cb853de

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,22 @@ static bool trap_bvr(struct kvm_vcpu *vcpu,
399399
struct sys_reg_params *p,
400400
const struct sys_reg_desc *rd)
401401
{
402-
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg];
402+
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->CRm];
403403

404404
if (p->is_write)
405405
reg_to_dbg(vcpu, p, rd, dbg_reg);
406406
else
407407
dbg_to_reg(vcpu, p, rd, dbg_reg);
408408

409-
trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg);
409+
trace_trap_reg(__func__, rd->CRm, p->is_write, *dbg_reg);
410410

411411
return true;
412412
}
413413

414414
static int set_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
415415
const struct kvm_one_reg *reg, void __user *uaddr)
416416
{
417-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg];
417+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->CRm];
418418

419419
if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
420420
return -EFAULT;
@@ -424,7 +424,7 @@ static int set_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
424424
static int get_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
425425
const struct kvm_one_reg *reg, void __user *uaddr)
426426
{
427-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg];
427+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->CRm];
428428

429429
if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
430430
return -EFAULT;
@@ -434,29 +434,29 @@ static int get_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
434434
static void reset_bvr(struct kvm_vcpu *vcpu,
435435
const struct sys_reg_desc *rd)
436436
{
437-
vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg] = rd->val;
437+
vcpu->arch.vcpu_debug_state.dbg_bvr[rd->CRm] = rd->val;
438438
}
439439

440440
static bool trap_bcr(struct kvm_vcpu *vcpu,
441441
struct sys_reg_params *p,
442442
const struct sys_reg_desc *rd)
443443
{
444-
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg];
444+
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->CRm];
445445

446446
if (p->is_write)
447447
reg_to_dbg(vcpu, p, rd, dbg_reg);
448448
else
449449
dbg_to_reg(vcpu, p, rd, dbg_reg);
450450

451-
trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg);
451+
trace_trap_reg(__func__, rd->CRm, p->is_write, *dbg_reg);
452452

453453
return true;
454454
}
455455

456456
static int set_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
457457
const struct kvm_one_reg *reg, void __user *uaddr)
458458
{
459-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg];
459+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->CRm];
460460

461461
if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
462462
return -EFAULT;
@@ -467,7 +467,7 @@ static int set_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
467467
static int get_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
468468
const struct kvm_one_reg *reg, void __user *uaddr)
469469
{
470-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg];
470+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->CRm];
471471

472472
if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
473473
return -EFAULT;
@@ -477,30 +477,30 @@ static int get_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
477477
static void reset_bcr(struct kvm_vcpu *vcpu,
478478
const struct sys_reg_desc *rd)
479479
{
480-
vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg] = rd->val;
480+
vcpu->arch.vcpu_debug_state.dbg_bcr[rd->CRm] = rd->val;
481481
}
482482

483483
static bool trap_wvr(struct kvm_vcpu *vcpu,
484484
struct sys_reg_params *p,
485485
const struct sys_reg_desc *rd)
486486
{
487-
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg];
487+
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->CRm];
488488

489489
if (p->is_write)
490490
reg_to_dbg(vcpu, p, rd, dbg_reg);
491491
else
492492
dbg_to_reg(vcpu, p, rd, dbg_reg);
493493

494-
trace_trap_reg(__func__, rd->reg, p->is_write,
495-
vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]);
494+
trace_trap_reg(__func__, rd->CRm, p->is_write,
495+
vcpu->arch.vcpu_debug_state.dbg_wvr[rd->CRm]);
496496

497497
return true;
498498
}
499499

500500
static int set_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
501501
const struct kvm_one_reg *reg, void __user *uaddr)
502502
{
503-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg];
503+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->CRm];
504504

505505
if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
506506
return -EFAULT;
@@ -510,7 +510,7 @@ static int set_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
510510
static int get_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
511511
const struct kvm_one_reg *reg, void __user *uaddr)
512512
{
513-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg];
513+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->CRm];
514514

515515
if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
516516
return -EFAULT;
@@ -520,29 +520,29 @@ static int get_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
520520
static void reset_wvr(struct kvm_vcpu *vcpu,
521521
const struct sys_reg_desc *rd)
522522
{
523-
vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg] = rd->val;
523+
vcpu->arch.vcpu_debug_state.dbg_wvr[rd->CRm] = rd->val;
524524
}
525525

526526
static bool trap_wcr(struct kvm_vcpu *vcpu,
527527
struct sys_reg_params *p,
528528
const struct sys_reg_desc *rd)
529529
{
530-
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg];
530+
u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->CRm];
531531

532532
if (p->is_write)
533533
reg_to_dbg(vcpu, p, rd, dbg_reg);
534534
else
535535
dbg_to_reg(vcpu, p, rd, dbg_reg);
536536

537-
trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg);
537+
trace_trap_reg(__func__, rd->CRm, p->is_write, *dbg_reg);
538538

539539
return true;
540540
}
541541

542542
static int set_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
543543
const struct kvm_one_reg *reg, void __user *uaddr)
544544
{
545-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg];
545+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->CRm];
546546

547547
if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
548548
return -EFAULT;
@@ -552,7 +552,7 @@ static int set_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
552552
static int get_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
553553
const struct kvm_one_reg *reg, void __user *uaddr)
554554
{
555-
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg];
555+
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->CRm];
556556

557557
if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
558558
return -EFAULT;
@@ -562,7 +562,7 @@ static int get_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
562562
static void reset_wcr(struct kvm_vcpu *vcpu,
563563
const struct sys_reg_desc *rd)
564564
{
565-
vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg] = rd->val;
565+
vcpu->arch.vcpu_debug_state.dbg_wcr[rd->CRm] = rd->val;
566566
}
567567

568568
static void reset_amair_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)

0 commit comments

Comments
 (0)