Skip to content

Commit ae98a4a

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/sysreg-cleanup-5.20 into kvmarm-master/next
* kvm-arm64/sysreg-cleanup-5.20: : . : Long overdue cleanup of the sysreg userspace access, : with extra scrubbing on the vgic side of things. : From the cover letter: : : "Schspa Shi recently reported[1] that some of the vgic code interacting : with userspace was reading uninitialised stack memory, and although : that read wasn't used any further, it prompted me to revisit this part : of the code. : : Needless to say, this area of the kernel is pretty crufty, and shows a : bunch of issues in other parts of the KVM/arm64 infrastructure. This : series tries to remedy a bunch of them: : : - Sanitise the way we deal with sysregs from userspace: at the moment, : each and every .set_user/.get_user callback has to implement its own : userspace accesses (directly or indirectly). It'd be much better if : that was centralised so that we can reason about it. : : - Enforce that all AArch64 sysregs are 64bit. Always. This was sort of : implied by the code, but it took some effort to convince myself that : this was actually the case. : : - Move the vgic-v3 sysreg userspace accessors to the userspace : callbacks instead of hijacking the vcpu trap callback. This allows : us to reuse the sysreg infrastructure. : : - Consolidate userspace accesses for both GICv2, GICv3 and common code : as much as possible. : : - Cleanup a bunch of not-very-useful helpers, tidy up some of the code : as we touch it. : : [1] https://lore.kernel.org/r/[email protected]" : . KVM: arm64: Get rid or outdated comments KVM: arm64: Descope kvm_arm_sys_reg_{get,set}_reg() KVM: arm64: Get rid of find_reg_by_id() KVM: arm64: vgic: Tidy-up calls to vgic_{get,set}_common_attr() KVM: arm64: vgic: Consolidate userspace access for base address setting KVM: arm64: vgic-v2: Add helper for legacy dist/cpuif base address setting KVM: arm64: vgic: Use {get,put}_user() instead of copy_{from.to}_user KVM: arm64: vgic-v2: Consolidate userspace access for MMIO registers KVM: arm64: vgic-v3: Consolidate userspace access for MMIO registers KVM: arm64: vgic-v3: Use u32 to manage the line level from userspace KVM: arm64: vgic-v3: Convert userspace accessors over to FIELD_GET/FIELD_PREP KVM: arm64: vgic-v3: Make the userspace accessors use sysreg API KVM: arm64: vgic-v3: Push user access into vgic_v3_cpu_sysregs_uaccess() KVM: arm64: vgic-v3: Simplify vgic_v3_has_cpu_sysregs_attr() KVM: arm64: Get rid of reg_from/to_user() KVM: arm64: Consolidate sysreg userspace accesses KVM: arm64: Rely on index_to_param() for size checks on userspace access KVM: arm64: Introduce generic get_user/set_user helpers for system registers KVM: arm64: Reorder handling of invariant sysregs from userspace KVM: arm64: Add get_reg_by_id() as a sys_reg_desc retrieving helper Signed-off-by: Marc Zyngier <[email protected]>
2 parents aeb7942 + 4274d42 commit ae98a4a

File tree

11 files changed

+547
-601
lines changed

11 files changed

+547
-601
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,6 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
714714

715715
unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
716716
int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
717-
int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
718-
int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
719717

720718
int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
721719
struct kvm_vcpu_events *events);

arch/arm64/kvm/arm.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,18 +1420,11 @@ void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
14201420
static int kvm_vm_ioctl_set_device_addr(struct kvm *kvm,
14211421
struct kvm_arm_device_addr *dev_addr)
14221422
{
1423-
unsigned long dev_id, type;
1424-
1425-
dev_id = (dev_addr->id & KVM_ARM_DEVICE_ID_MASK) >>
1426-
KVM_ARM_DEVICE_ID_SHIFT;
1427-
type = (dev_addr->id & KVM_ARM_DEVICE_TYPE_MASK) >>
1428-
KVM_ARM_DEVICE_TYPE_SHIFT;
1429-
1430-
switch (dev_id) {
1423+
switch (FIELD_GET(KVM_ARM_DEVICE_ID_MASK, dev_addr->id)) {
14311424
case KVM_ARM_DEVICE_VGIC_V2:
14321425
if (!vgic_present)
14331426
return -ENXIO;
1434-
return kvm_vgic_addr(kvm, type, &dev_addr->addr, true);
1427+
return kvm_set_legacy_vgic_v2_addr(kvm, dev_addr);
14351428
default:
14361429
return -ENODEV;
14371430
}

0 commit comments

Comments
 (0)