KVM/arm64 fixes for 5.10, take #4
Subsystems (4)
Marc Zyngier
maintainerHi Paolo,
This is hopefully the last set of fixes for 5.10. We have a linker script fix addressing the alignment requirement for the way we now build the EL2 code, and a fix for a long standing bug affecting userspace access to the GICR_TYPER registers.
Please pull,
M.
The following changes since commit ed4ffaf49bf9ce1002b516d8c6aa04937b7950bc:
KVM: arm64: Handle SCXTNUM_ELx traps (2020-11-12 21:22:46 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.10-4
for you to fetch changes up to 23bde34771f1ea92fb5e6682c0d8c04304d34b3b:
KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace (2020-11-17 18:51:09 +0000)
----------------------------------------------------------------
KVM/arm64 fixes for v5.10, take #4
- Fix alignment of the new HYP sections
- Fix GICR_TYPER access from userspace
----------------------------------------------------------------
Jamie Iles (1):
KVM: arm64: Correctly align nVHE percpu data
Zenghui Yu (1):
KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace
arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 5 +++++ arch/arm64/kvm/vgic/vgic-mmio-v3.c | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 1/2 KVM: arm64: Correctly align nVHE percpu data
From: Jamie Iles <[email protected]>
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The PERCPU_INPUT macro would then align the data to a page boundary:
#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;
but then when the final vmlinux linking happens the hypervisor percpu data is included after page alignment and so the offsets potentially don't match. On my build I saw that the .hyp.data..percpu section was at address 0x20 and then the percpu data would begin at 0x1000 (because of the page alignment in PERCPU_INPUT), but when linked into vmlinux, everything would be shifted down by 0x20 bytes.
This manifests as one of the CPUs getting lost when running kvm-unit-tests or starting any VM and subsequent soft lockup on a Cortex A72 device.
--- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp.lds.S +5 -0
@@ -13,6 +13,11 @@ SECTIONS { HYP_SECTION(.text) + /* + * .hyp..data..percpu needs to be page aligned to maintain the same + * alignment for when linking into vmlinux. + */ + . = ALIGN(PAGE_SIZE); HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) }
Signature · 6 lines
2.28.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 2/2 KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace
In reply to Marc ZyngierFrom: Zenghui Yu <[email protected]>
It was recently reported that if GICR_TYPER is accessed before the RD base address is set, we'll suffer from the unset @rdreg dereferencing. Oops...
gpa_t last_rdist_typer = rdreg->base + GICR_TYPER + (rdreg->free_index - 1) * KVM_VGIC_V3_REDIST_SIZE;
It's "expected" that users will access registers in the redistributor if the RD has been properly configured (e.g., the RD base address is set). But it hasn't yet been covered by the existing documentation.
Per discussion on the list [1], the reporting of the GICR_TYPER.Last bit for userspace never actually worked. And it's difficult for us to emulate it correctly given that userspace has the flexibility to access it any time. Let's just drop the reporting of the Last bit for userspace for now (userspace should have full knowledge about it anyway) and it at least prevents kernel from panic ;-)
[1] https://lore.kernel.org/kvmarm/[email protected]/
--- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
arch/arm64/kvm/vgic/vgic-mmio-v3.c +20 -2
@@ -273,6 +273,23 @@ static unsigned long vgic_mmio_read_v3r_typer(struct kvm_vcpu *vcpu,return extract_bytes (value, addr &7 , len); } +static unsigned long vgic_uaccess_read_v3r_typer (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +unsigned long mpidr =kvm_vcpu_get_mpidr_aff (vcpu); +int target_vcpu_id = vcpu->vcpu_id; +u64 value; + + value = (u64)(mpidr &GENMASK (23 ,0 )) <<32 ; + value |= ((target_vcpu_id &0xffff ) <<8 ); + +if (vgic_has_its (vcpu->kvm)) + value |=GICR_TYPER_PLPIS ; + +/* reporting of the Last bit is not supported for userspace */ +return extract_bytes (value, addr &7 , len); +} +static unsigned long vgic_mmio_read_v3r_iidr (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len) {
@@ -593,8 +610,9 @@ static const struct vgic_register_region vgic_v3_rd_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_IIDR , vgic_mmio_read_v3r_iidr, vgic_mmio_write_wi,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_TYPER , - vgic_mmio_read_v3r_typer, vgic_mmio_write_wi,8 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_TYPER , + vgic_mmio_read_v3r_typer, vgic_mmio_write_wi, + vgic_uaccess_read_v3r_typer, vgic_mmio_uaccess_write_wi,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), REGISTER_DESC_WITH_LENGTH(GICR_WAKER, vgic_mmio_read_raz, vgic_mmio_write_wi, 4,
Signature · 6 lines
2.28.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm