From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 33/55] KVM: arm64: vgic: Handle ITS related GICv3 redistributor registers
Date: Tue, 2 Aug 2016 16:33:45 +0200 [thread overview]
Message-ID: <20160802143345.GN32244@cbox> (raw)
In-Reply-To: <57A0721E.7010905@arm.com>
On Tue, Aug 02, 2016 at 11:12:46AM +0100, Marc Zyngier wrote:
> On 02/08/16 10:40, Andre Przywara wrote:
> > Hi,
> >
> > On 01/08/16 19:20, Christoffer Dall wrote:
> >> On Fri, Jul 22, 2016 at 06:28:50PM +0100, Marc Zyngier wrote:
> >>> From: Andre Przywara <andre.przywara@arm.com>
> >>>
> >>> In the GICv3 redistributor there are the PENDBASER and PROPBASER
> >>> registers which we did not emulate so far, as they only make sense
> >>> when having an ITS. In preparation for that emulate those MMIO
> >>> accesses by storing the 64-bit data written into it into a variable
> >>> which we later read in the ITS emulation.
> >>> We also sanitise the registers, making sure RES0 regions are respected
> >>> and checking for valid memory attributes.
> >>>
> >>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> >>> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
> >>> Tested-by: Eric Auger <eric.auger@redhat.com>
> >>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> >>> ---
> >>> include/kvm/arm_vgic.h | 13 ++++
> >>> virt/kvm/arm/vgic/vgic-mmio-v3.c | 153 ++++++++++++++++++++++++++++++++++++++-
> >>> virt/kvm/arm/vgic/vgic-mmio.h | 8 ++
> >>> virt/kvm/arm/vgic/vgic-v3.c | 11 ++-
> >>> 4 files changed, 181 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
> >>> index 450b4da..df2dec5 100644
> >>> --- a/include/kvm/arm_vgic.h
> >>> +++ b/include/kvm/arm_vgic.h
> >>> @@ -146,6 +146,14 @@ struct vgic_dist {
> >>> struct vgic_irq *spis;
> >>>
> >>> struct vgic_io_device dist_iodev;
> >>> +
> >>> + /*
> >>> + * Contains the attributes and gpa of the LPI configuration table.
> >>> + * Since we report GICR_TYPER.CommonLPIAff as 0b00, we can share
> >>> + * one address across all redistributors.
> >>> + * GICv3 spec: 6.1.2 "LPI Configuration tables"
> >>> + */
> >>> + u64 propbaser;
> >>> };
> >>>
> >>> struct vgic_v2_cpu_if {
> >>> @@ -200,6 +208,11 @@ struct vgic_cpu {
> >>> */
> >>> struct vgic_io_device rd_iodev;
> >>> struct vgic_io_device sgi_iodev;
> >>> +
> >>> + /* Contains the attributes and gpa of the LPI pending tables. */
> >>> + u64 pendbaser;
> >>> +
> >>> + bool lpis_enabled;
> >>> };
> >>>
> >>> int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
> >>> diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c
> >>> index bfcafbd..278bfbb 100644
> >>> --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c
> >>> +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c
> >>> @@ -29,6 +29,19 @@ static unsigned long extract_bytes(unsigned long data, unsigned int offset,
> >>> return (data >> (offset * 8)) & GENMASK_ULL(num * 8 - 1, 0);
> >>> }
> >>>
> >>> +/* allows updates of any half of a 64-bit register (or the whole thing) */
> >>> +static u64 update_64bit_reg(u64 reg, unsigned int offset, unsigned int len,
> >>> + unsigned long val)
> >>> +{
> >>> + int lower = (offset & 4) * 8;
> >>> + int upper = lower + 8 * len - 1;
> >>> +
> >>> + reg &= ~GENMASK_ULL(upper, lower);
> >>> + val &= GENMASK_ULL(len * 8 - 1, 0);
> >>> +
> >>> + return reg | ((u64)val << lower);
> >>> +}
> >>> +
> >>> static unsined long vgic_mmio_read_v3_misc(struct kvm_vcpu *vcpu,
> >>> gpa_t addr, unsigned int len)
> >>> {
> >>> @@ -152,6 +165,142 @@ static unsigned long vgic_mmio_read_v3_idregs(struct kvm_vcpu *vcpu,
> >>> return 0;
> >>> }
> >>>
> >>> +/* We want to avoid outer shareable. */
> >>> +u64 vgic_sanitise_shareability(u64 field)
> >>> +{
> >>> + switch (field) {
> >>> + case GIC_BASER_OuterShareable:
> >>> + return GIC_BASER_InnerShareable;
> >>> + default:
> >>> + return field;
> >>> + }
> >>> +}
> >>> +
> >>> +/* Avoid any inner non-cacheable mapping. */
> >>> +u64 vgic_sanitise_inner_cacheability(u64 field)
> >>> +{
> >>> + switch (field) {
> >>> + case GIC_BASER_CACHE_nCnB:
> >>> + case GIC_BASER_CACHE_nC:
> >>> + return GIC_BASER_CACHE_RaWb;
> >>> + default:
> >>> + return field;
> >>> + }
> >>> +}
> >>> +
> >>> +/* Non-cacheable or same-as-inner are OK. */
> >>> +u64 vgic_sanitise_outer_cacheability(u64 field)
> >>> +{
> >>> + switch (field) {
> >>> + case GIC_BASER_CACHE_SameAsInner:
> >>> + case GIC_BASER_CACHE_nC:
> >>> + return field;
> >>> + default:
> >>> + return GIC_BASER_CACHE_nC;
> >>> + }
> >>> +}
> >>> +
> >>> +u64 vgic_sanitise_field(u64 reg, u64 field_mask, int field_shift,
> >>> + u64 (*sanitise_fn)(u64))
> >>> +{
> >>> + u64 field = (reg & field_mask) >> field_shift;
> >>> +
> >>> + field = sanitise_fn(field) << field_shift;
> >>> + return (reg & ~field_mask) | field;
> >>> +}
> >>> +
> >>> +#define PROPBASER_RES0_MASK \
> >>> + (GENMASK_ULL(63, 59) | GENMASK_ULL(55, 52) | GENMASK_ULL(6, 5))
> >>> +#define PENDBASER_RES0_MASK \
> >>> + (BIT_ULL(63) | GENMASK_ULL(61, 59) | GENMASK_ULL(55, 52) | \
> >>> + GENMASK_ULL(15, 12) | GENMASK_ULL(6, 0))
> >>> +
> >>> +static u64 vgic_sanitise_pendbaser(u64 reg)
> >>> +{
> >>> + reg = vgic_sanitise_field(reg, GICR_PENDBASER_SHAREABILITY_MASK,
> >>> + GICR_PENDBASER_SHAREABILITY_SHIFT,
> >>> + vgic_sanitise_shareability);
> >>> + reg = vgic_sanitise_field(reg, GICR_PENDBASER_INNER_CACHEABILITY_MASK,
> >>> + GICR_PENDBASER_INNER_CACHEABILITY_SHIFT,
> >>> + vgic_sanitise_inner_cacheability);
> >>> + reg = vgic_sanitise_field(reg, GICR_PENDBASER_OUTER_CACHEABILITY_MASK,
> >>> + GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT,
> >>> + vgic_sanitise_outer_cacheability);
> >>> +
> >>> + reg &= ~PENDBASER_RES0_MASK;
> >>> + reg &= ~GENMASK_ULL(51, 48);
> >>> +
> >>> + return reg;
> >>> +}
> >>> +
> >>> +static u64 vgic_sanitise_propbaser(u64 reg)
> >>> +{
> >>> + reg = vgic_sanitise_field(reg, GICR_PROPBASER_SHAREABILITY_MASK,
> >>> + GICR_PROPBASER_SHAREABILITY_SHIFT,
> >>> + vgic_sanitise_shareability);
> >>> + reg = vgic_sanitise_field(reg, GICR_PROPBASER_INNER_CACHEABILITY_MASK,
> >>> + GICR_PROPBASER_INNER_CACHEABILITY_SHIFT,
> >>> + vgic_sanitise_inner_cacheability);
> >>> + reg = vgic_sanitise_field(reg, GICR_PROPBASER_OUTER_CACHEABILITY_MASK,
> >>> + GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT,
> >>> + vgic_sanitise_outer_cacheability);
> >>> +
> >>> + reg &= ~PROPBASER_RES0_MASK;
> >>> + reg &= ~GENMASK_ULL(51, 48);
> >>> + return reg;
> >>> +}
> >>> +
> >>> +static unsigned long vgic_mmio_read_propbase(struct kvm_vcpu *vcpu,
> >>> + gpa_t addr, unsigned int len)
> >>> +{
> >>> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> >>> +
> >>> + return extract_bytes(dist->propbaser, addr & 7, len);
> >>> +}
> >>> +
> >>> +static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu,
> >>> + gpa_t addr, unsigned int len,
> >>> + unsigned long val)
> >>> +{
> >>> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> >>> + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> >>> + u64 propbaser = dist->propbaser;
> >>> +
> >>> + /* Storing a value with LPIs already enabled is undefined */
> >>> + if (vgic_cpu->lpis_enabled)
> >>> + return;
> >>> +
> >>> + propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
> >>> + propbaser = vgic_sanitise_propbaser(propbaser);
> >>> +
> >>> + dist->propbaser = propbaser;
> >>
> >> Which guarantees do we have that this will always be a single atomic
> >> write?
> >
> > At least on arm64 - which is the only architecture this code is
> > compiling for at the moment - I don't see why this shouldn't be a single
> > write:
> > str x19, [x22,#3544]
> > is what my setup here creates.
> >
> > Do we need something stronger? Do we want to postpone this to the point
> > when we get arm(32) support?
>
> This is a *device*. It shouldn't be affected by whatever drives it.
>
> Now, and more to the point: the write shouldn't have to be atomic. All
> 64bit registers should be able to cope with 32bit writes to it, as
> described in the architecture spec (IHI0069C 8.1.3).
That's not my concern. My concern is that you have two CPUs updating
the propbaser, once after the other, and you end up with a mix of the
two updates. If this C-code can ever become two 32-bit writes, for
example, and these can happen in parallel you can end up with something
like that.
If there is not valid expectation from guest software that a real device
stores either one or the other value, then it's fine to leave it as is.
Thinking about it, any sane guest would probably synchronize multiple
writes to this register itself?
>
> The important thing to ensure is that we don't use that value as long it
> can change, which means that we can't use it as long as LPIs are
> disabled. Which means that things like update_lpi_config() shouldn't
> even try and read from memory if LPIs are not enabled.
>
I agree with this too, but that wasn't what my comment was targeting.
Thanks,
-Christoffer
next prev parent reply other threads:[~2016-08-02 14:33 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-22 17:28 [PULL] KVM/ARM updates for Linux 4.8, take #1 Marc Zyngier
2016-07-22 17:28 ` [PATCH 01/55] arm/arm64: KVM: Add a protection parameter to create_hyp_mappings Marc Zyngier
2016-07-22 17:28 ` [PATCH 02/55] arm64: Add PTE_HYP_XN page table flag Marc Zyngier
2016-07-22 17:28 ` [PATCH 03/55] arm/arm64: KVM: Enforce HYP read-only mapping of the kernel's rodata section Marc Zyngier
2016-07-22 17:28 ` [PATCH 04/55] arm/arm64: KVM: Map the HYP text as read-only Marc Zyngier
2016-07-22 17:28 ` [PATCH 05/55] arm/arm64: KVM: Make default HYP mappings non-excutable Marc Zyngier
2016-07-22 17:28 ` [PATCH 06/55] KVM: arm/arm64: The GIC is dead, long live the GIC Marc Zyngier
2016-07-22 17:28 ` [PATCH 07/55] arm64: KVM: Merged page tables documentation Marc Zyngier
2016-07-22 17:28 ` [PATCH 08/55] arm64: KVM: Always reference __hyp_panic_string via its kernel VA Marc Zyngier
2016-07-22 17:28 ` [PATCH 09/55] arm/arm64: KVM: Remove hyp_kern_va helper Marc Zyngier
2016-07-22 17:28 ` [PATCH 10/55] arm64: KVM: Kill HYP_PAGE_OFFSET Marc Zyngier
2016-07-22 17:28 ` [PATCH 11/55] arm64: Add ARM64_HYP_OFFSET_LOW capability Marc Zyngier
2016-07-22 17:28 ` [PATCH 12/55] arm64: KVM: Define HYP offset masks Marc Zyngier
2016-07-22 17:28 ` [PATCH 13/55] arm64: KVM: Refactor kern_hyp_va to deal with multiple offsets Marc Zyngier
2016-07-22 17:28 ` [PATCH 14/55] arm/arm64: KVM: Export __hyp_text_start/end symbols Marc Zyngier
2016-07-22 17:28 ` [PATCH 15/55] arm64: KVM: Runtime detection of lower HYP offset Marc Zyngier
2016-07-22 17:28 ` [PATCH 16/55] arm/arm64: KVM: Always have merged page tables Marc Zyngier
2016-07-22 17:28 ` [PATCH 17/55] arm64: KVM: Simplify HYP init/teardown Marc Zyngier
2016-07-22 17:28 ` [PATCH 18/55] arm/arm64: KVM: Drop boot_pgd Marc Zyngier
2016-07-22 17:28 ` [PATCH 19/55] arm/arm64: KVM: Kill free_boot_hyp_pgd Marc Zyngier
2016-07-22 17:28 ` [PATCH 20/55] arm: KVM: Simplify HYP init Marc Zyngier
2016-07-22 17:28 ` [PATCH 21/55] arm: KVM: Allow hyp teardown Marc Zyngier
2016-07-22 17:28 ` [PATCH 22/55] arm/arm64: KVM: Prune unused #defines Marc Zyngier
2016-07-22 17:28 ` [PATCH 23/55] arm/arm64: KVM: Check that IDMAP doesn't intersect with VA range Marc Zyngier
2016-07-22 17:28 ` [PATCH 24/55] arm/arm64: Get rid of KERN_TO_HYP Marc Zyngier
2016-07-22 17:28 ` [PATCH 25/55] arm64: KVM: Clean up a condition Marc Zyngier
2016-07-22 17:28 ` [PATCH 26/55] KVM: arm/arm64: vgic: Move redistributor kvm_io_devices Marc Zyngier
2016-07-22 17:28 ` [PATCH 27/55] KVM: arm/arm64: vgic: Check return value for kvm_register_vgic_device Marc Zyngier
2016-07-22 17:28 ` [PATCH 28/55] KVM: Extend struct kvm_msi to hold a 32-bit device ID Marc Zyngier
2016-07-22 17:28 ` [PATCH 29/55] KVM: arm/arm64: Extend arch CAP checks to allow per-VM capabilities Marc Zyngier
2016-07-22 17:28 ` [PATCH 30/55] KVM: kvm_io_bus: Add kvm_io_bus_get_dev() call Marc Zyngier
2016-07-22 17:28 ` [PATCH 31/55] KVM: arm/arm64: vgic: Add refcounting for IRQs Marc Zyngier
2016-07-22 17:28 ` [PATCH 32/55] irqchip/gic-v3: Refactor and add GICv3 definitions Marc Zyngier
2016-07-22 17:28 ` [PATCH 33/55] KVM: arm64: vgic: Handle ITS related GICv3 redistributor registers Marc Zyngier
2016-08-01 18:20 ` Christoffer Dall
2016-08-02 9:40 ` Andre Przywara
2016-08-02 10:12 ` Marc Zyngier
2016-08-02 14:33 ` Christoffer Dall [this message]
2016-08-02 14:46 ` Marc Zyngier
2016-08-02 14:55 ` Christoffer Dall
2016-08-02 15:01 ` Marc Zyngier
2016-07-22 17:28 ` [PATCH 34/55] KVM: arm64: vgic-its: Introduce ITS emulation file with MMIO framework Marc Zyngier
2016-07-22 17:28 ` [PATCH 35/55] KVM: arm64: vgic-its: Introduce new KVM ITS device Marc Zyngier
2016-07-22 17:28 ` [PATCH 36/55] KVM: arm64: vgic-its: Implement basic ITS register handlers Marc Zyngier
2016-07-22 17:28 ` [PATCH 37/55] KVM: arm64: vgic-its: Connect LPIs to the VGIC emulation Marc Zyngier
2016-07-22 17:28 ` [PATCH 38/55] KVM: arm64: vgic-its: Read initial LPI pending table Marc Zyngier
2016-07-22 17:28 ` [PATCH 39/55] KVM: arm64: vgic-its: Allow updates of LPI configuration table Marc Zyngier
2016-07-22 17:28 ` [PATCH 40/55] KVM: arm64: vgic-its: Implement ITS command queue command handlers Marc Zyngier
2016-07-22 17:28 ` [PATCH 41/55] KVM: arm64: vgic-its: Implement MSI injection in ITS emulation Marc Zyngier
2016-08-01 18:20 ` Christoffer Dall
2016-08-02 10:18 ` Marc Zyngier
2016-08-04 10:47 ` Christoffer Dall
2016-07-22 17:28 ` [PATCH 42/55] KVM: arm64: vgic-its: Enable ITS emulation as a virtual MSI controller Marc Zyngier
2016-07-22 17:29 ` [PATCH 43/55] KVM: arm/arm64: Fix vGICv2 KVM_DEV_ARM_VGIC_GRP_CPU/DIST_REGS Marc Zyngier
2016-07-22 17:29 ` [PATCH 44/55] irqchip/gicv3-its: Restore all cacheability attributes Marc Zyngier
2016-07-22 17:29 ` [PATCH 45/55] KVM: arm64: vgic-its: Generalize use of vgic_get_irq_kref Marc Zyngier
2016-07-22 17:29 ` [PATCH 46/55] KVM: arm64: vgic-its: Fix handling of indirect tables Marc Zyngier
2016-07-22 17:29 ` [PATCH 47/55] KVM: arm64: vgic-its: Fix vgic_its_check_device_id BE handling Marc Zyngier
2016-07-22 17:29 ` [PATCH 48/55] KVM: arm64: vgic-its: Fix misleading nr_entries in vgic_its_check_device_id Marc Zyngier
2016-07-22 17:29 ` [PATCH 49/55] KVM: arm64: vgic-its: Validate the device table L1 entry Marc Zyngier
2016-07-22 17:29 ` [PATCH 50/55] KVM: arm64: vgic-its: Fix L2 entry validation for indirect tables Marc Zyngier
2016-07-22 17:29 ` [PATCH 51/55] KVM: arm64: vgic-its: Add collection allocator/destructor Marc Zyngier
2016-07-22 17:29 ` [PATCH 52/55] KVM: arm64: vgic-its: Add pointer to corresponding kvm_device Marc Zyngier
2016-07-22 17:29 ` [PATCH 53/55] KVM: arm64: vgic-its: Turn device_id validation into generic ID validation Marc Zyngier
2016-07-22 17:29 ` [PATCH 54/55] KVM: arm64: vgic-its: Make vgic_its_cmd_handle_mapi similar to other handlers Marc Zyngier
2016-07-22 17:29 ` [PATCH 55/55] KVM: arm64: vgic-its: Simplify MAPI error handling Marc Zyngier
2016-07-22 19:50 ` [PULL] KVM/ARM updates for Linux 4.8, take #1 Radim Krčmář
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160802143345.GN32244@cbox \
--to=christoffer.dall@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).