All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <cdall@linaro.org>
To: Marc Zyngier <marc.zyngier@arm.com>
Cc: Eric Auger <eric.auger@redhat.com>,
	eric.auger.pro@gmail.com, christoffer.dall@linaro.org,
	andre.przywara@arm.com, vijayak@caviumnetworks.com,
	Vijaya.Kumar@cavium.com, peter.maydell@linaro.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Prasun.Kapoor@cavium.com, drjones@redhat.com,
	pbonzini@redhat.com, dgilbert@redhat.com, quintela@redhat.com,
	bjsprakash.linux@gmail.com
Subject: Re: [PATCH v7 22/24] KVM: arm64: vgic-its: ITT save and restore
Date: Mon, 8 May 2017 13:49:56 +0200	[thread overview]
Message-ID: <20170508114956.GC28342@cbox> (raw)
In-Reply-To: <87shkgiy5m.fsf@on-the-bus.cambridge.arm.com>

On Sun, May 07, 2017 at 02:39:33PM +0100, Marc Zyngier wrote:
> On Sat, May 06 2017 at  4:24:41 pm BST, Eric Auger <eric.auger@redhat.com> wrote:
> > Implement routines to save and restore device ITT and their
> > interrupt table entries (ITE).
> >
> > Signed-off-by: Eric Auger <eric.auger@redhat.com>
> > Reviewed-by: Christoffer Dall <cdall@linaro.org>
> >
> > ---
> > v6 -> v7:
> > - added Christoffer's R-b
> >
> > v5 -> v6:
> > - accomodate vgic_its_alloc_ite change of proto
> > - check LPI ID on restore, check eventid offset
> > - initializations on separate line
> > - coming after device save/restore
> > - add_lpi does config and pending bit sync
> >
> > v4 -> v5:
> > - ITE are now sorted by eventid on the flush
> > - rename *flush* into *save*
> > - use macros for shits and masks
> > - pass ite_esz to vgic_its_save_ite
> >
> > v3 -> v4:
> > - lookup_table and compute_next_eventid_offset become static in this
> >   patch
> > - remove static along with vgic_its_flush/restore_itt to avoid
> >   compilation warnings
> > - next field only computed with a shift (mask removed)
> > - handle the case where the last element has not been found
> >
> > v2 -> v3:
> > - add return 0 in vgic_its_restore_ite (was in subsequent patch)
> >
> > v2: creation
> > ---
> >  virt/kvm/arm/vgic/vgic-its.c | 116 +++++++++++++++++++++++++++++++++++++++++--
> >  virt/kvm/arm/vgic/vgic.h     |   4 ++
> >  2 files changed, 117 insertions(+), 3 deletions(-)
> >
> > diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> > index 3dea626..adb3d9e 100644
> > --- a/virt/kvm/arm/vgic/vgic-its.c
> > +++ b/virt/kvm/arm/vgic/vgic-its.c
> > @@ -1750,7 +1750,7 @@ static u32 compute_next_devid_offset(struct list_head *h,
> >  	return min_t(u32, next_offset, VITS_DTE_MAX_DEVID_OFFSET);
> >  }
> >  
> > -u32 compute_next_eventid_offset(struct list_head *h, struct its_ite *ite)
> > +static u32 compute_next_eventid_offset(struct list_head *h, struct its_ite *ite)
> >  {
> >  	struct its_ite *next;
> >  	u32 next_offset;
> > @@ -1827,14 +1827,124 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, int esz,
> >  	return ret;
> >  }
> >  
> > +/**
> > + * vgic_its_save_ite - Save an interrupt translation entry at @gpa
> > + */
> > +static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev,
> > +			      struct its_ite *ite, gpa_t gpa, int ite_esz)
> > +{
> > +	struct kvm *kvm = its->dev->kvm;
> > +	u32 next_offset;
> > +	u64 val;
> > +
> > +	next_offset = compute_next_eventid_offset(&dev->itt_head, ite);
> > +	val = ((u64)next_offset << KVM_ITS_ITE_NEXT_SHIFT) |
> > +	       ((u64)ite->lpi << KVM_ITS_ITE_PINTID_SHIFT) |
> > +		ite->collection->collection_id;
> > +	val = cpu_to_le64(val);
> > +	return kvm_write_guest(kvm, gpa, &val, ite_esz);
> > +}
> > +
> > +/**
> > + * vgic_its_restore_ite - restore an interrupt translation entry
> > + * @event_id: id used for indexing
> > + * @ptr: pointer to the ITE entry
> > + * @opaque: pointer to the its_device
> > + */
> > +static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,
> > +				void *ptr, void *opaque)
> > +{
> > +	struct its_device *dev = (struct its_device *)opaque;
> > +	struct its_collection *collection;
> > +	struct kvm *kvm = its->dev->kvm;
> > +	struct kvm_vcpu *vcpu = NULL;
> > +	u64 val;
> > +	u64 *p = (u64 *)ptr;
> > +	struct vgic_irq *irq;
> > +	u32 coll_id, lpi_id;
> > +	struct its_ite *ite;
> > +	u32 offset;
> > +
> > +	val = *p;
> > +
> > +	val = le64_to_cpu(val);
> > +
> > +	coll_id = val & KVM_ITS_ITE_ICID_MASK;
> > +	lpi_id = (val & KVM_ITS_ITE_PINTID_MASK) >> KVM_ITS_ITE_PINTID_SHIFT;
> > +
> > +	if (!lpi_id)
> > +		return 1; /* invalid entry, no choice but to scan next entry */
> > +
> > +	if (lpi_id < VGIC_MIN_LPI)
> > +		return -EINVAL;
> > +
> > +	offset = val >> KVM_ITS_ITE_NEXT_SHIFT;
> > +	if (event_id + offset >= BIT_ULL(dev->num_eventid_bits))
> > +		return -EINVAL;
> > +
> > +	collection = find_collection(its, coll_id);
> > +	if (!collection)
> > +		return -EINVAL;
> > +
> > +	ite = vgic_its_alloc_ite(dev, collection, lpi_id, event_id);
> > +	if (IS_ERR(ite))
> > +		return PTR_ERR(ite);
> > +
> > +	if (its_is_collection_mapped(collection))
> > +		vcpu = kvm_get_vcpu(kvm, collection->target_addr);
> > +
> > +	irq = vgic_add_lpi(kvm, lpi_id, vcpu);
> > +	if (IS_ERR(irq))
> > +		return PTR_ERR(irq);
> 
> Same remark as the previous patch: the its_ite structure should be freed
> on failure. Otherwise, I suspect we end0up leaking memory.
> 

This error would be propagated back to vgic_its_restore_dte() which
(folllowing our discussion on the previous patch) will clean up the
dte including freeing all ITEs associated with the device's ITT.

Thanks,
-Christoffer

> Thanks,
> 
> 	M.
> -- 
> Jazz is not dead, it just smell funny.

WARNING: multiple messages have this Message-ID (diff)
From: cdall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 22/24] KVM: arm64: vgic-its: ITT save and restore
Date: Mon, 8 May 2017 13:49:56 +0200	[thread overview]
Message-ID: <20170508114956.GC28342@cbox> (raw)
In-Reply-To: <87shkgiy5m.fsf@on-the-bus.cambridge.arm.com>

On Sun, May 07, 2017 at 02:39:33PM +0100, Marc Zyngier wrote:
> On Sat, May 06 2017 at  4:24:41 pm BST, Eric Auger <eric.auger@redhat.com> wrote:
> > Implement routines to save and restore device ITT and their
> > interrupt table entries (ITE).
> >
> > Signed-off-by: Eric Auger <eric.auger@redhat.com>
> > Reviewed-by: Christoffer Dall <cdall@linaro.org>
> >
> > ---
> > v6 -> v7:
> > - added Christoffer's R-b
> >
> > v5 -> v6:
> > - accomodate vgic_its_alloc_ite change of proto
> > - check LPI ID on restore, check eventid offset
> > - initializations on separate line
> > - coming after device save/restore
> > - add_lpi does config and pending bit sync
> >
> > v4 -> v5:
> > - ITE are now sorted by eventid on the flush
> > - rename *flush* into *save*
> > - use macros for shits and masks
> > - pass ite_esz to vgic_its_save_ite
> >
> > v3 -> v4:
> > - lookup_table and compute_next_eventid_offset become static in this
> >   patch
> > - remove static along with vgic_its_flush/restore_itt to avoid
> >   compilation warnings
> > - next field only computed with a shift (mask removed)
> > - handle the case where the last element has not been found
> >
> > v2 -> v3:
> > - add return 0 in vgic_its_restore_ite (was in subsequent patch)
> >
> > v2: creation
> > ---
> >  virt/kvm/arm/vgic/vgic-its.c | 116 +++++++++++++++++++++++++++++++++++++++++--
> >  virt/kvm/arm/vgic/vgic.h     |   4 ++
> >  2 files changed, 117 insertions(+), 3 deletions(-)
> >
> > diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> > index 3dea626..adb3d9e 100644
> > --- a/virt/kvm/arm/vgic/vgic-its.c
> > +++ b/virt/kvm/arm/vgic/vgic-its.c
> > @@ -1750,7 +1750,7 @@ static u32 compute_next_devid_offset(struct list_head *h,
> >  	return min_t(u32, next_offset, VITS_DTE_MAX_DEVID_OFFSET);
> >  }
> >  
> > -u32 compute_next_eventid_offset(struct list_head *h, struct its_ite *ite)
> > +static u32 compute_next_eventid_offset(struct list_head *h, struct its_ite *ite)
> >  {
> >  	struct its_ite *next;
> >  	u32 next_offset;
> > @@ -1827,14 +1827,124 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, int esz,
> >  	return ret;
> >  }
> >  
> > +/**
> > + * vgic_its_save_ite - Save an interrupt translation entry at @gpa
> > + */
> > +static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev,
> > +			      struct its_ite *ite, gpa_t gpa, int ite_esz)
> > +{
> > +	struct kvm *kvm = its->dev->kvm;
> > +	u32 next_offset;
> > +	u64 val;
> > +
> > +	next_offset = compute_next_eventid_offset(&dev->itt_head, ite);
> > +	val = ((u64)next_offset << KVM_ITS_ITE_NEXT_SHIFT) |
> > +	       ((u64)ite->lpi << KVM_ITS_ITE_PINTID_SHIFT) |
> > +		ite->collection->collection_id;
> > +	val = cpu_to_le64(val);
> > +	return kvm_write_guest(kvm, gpa, &val, ite_esz);
> > +}
> > +
> > +/**
> > + * vgic_its_restore_ite - restore an interrupt translation entry
> > + * @event_id: id used for indexing
> > + * @ptr: pointer to the ITE entry
> > + * @opaque: pointer to the its_device
> > + */
> > +static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,
> > +				void *ptr, void *opaque)
> > +{
> > +	struct its_device *dev = (struct its_device *)opaque;
> > +	struct its_collection *collection;
> > +	struct kvm *kvm = its->dev->kvm;
> > +	struct kvm_vcpu *vcpu = NULL;
> > +	u64 val;
> > +	u64 *p = (u64 *)ptr;
> > +	struct vgic_irq *irq;
> > +	u32 coll_id, lpi_id;
> > +	struct its_ite *ite;
> > +	u32 offset;
> > +
> > +	val = *p;
> > +
> > +	val = le64_to_cpu(val);
> > +
> > +	coll_id = val & KVM_ITS_ITE_ICID_MASK;
> > +	lpi_id = (val & KVM_ITS_ITE_PINTID_MASK) >> KVM_ITS_ITE_PINTID_SHIFT;
> > +
> > +	if (!lpi_id)
> > +		return 1; /* invalid entry, no choice but to scan next entry */
> > +
> > +	if (lpi_id < VGIC_MIN_LPI)
> > +		return -EINVAL;
> > +
> > +	offset = val >> KVM_ITS_ITE_NEXT_SHIFT;
> > +	if (event_id + offset >= BIT_ULL(dev->num_eventid_bits))
> > +		return -EINVAL;
> > +
> > +	collection = find_collection(its, coll_id);
> > +	if (!collection)
> > +		return -EINVAL;
> > +
> > +	ite = vgic_its_alloc_ite(dev, collection, lpi_id, event_id);
> > +	if (IS_ERR(ite))
> > +		return PTR_ERR(ite);
> > +
> > +	if (its_is_collection_mapped(collection))
> > +		vcpu = kvm_get_vcpu(kvm, collection->target_addr);
> > +
> > +	irq = vgic_add_lpi(kvm, lpi_id, vcpu);
> > +	if (IS_ERR(irq))
> > +		return PTR_ERR(irq);
> 
> Same remark as the previous patch: the its_ite structure should be freed
> on failure. Otherwise, I suspect we end0up leaking memory.
> 

This error would be propagated back to vgic_its_restore_dte() which
(folllowing our discussion on the previous patch) will clean up the
dte including freeing all ITEs associated with the device's ITT.

Thanks,
-Christoffer

> Thanks,
> 
> 	M.
> -- 
> Jazz is not dead, it just smell funny.

  parent reply	other threads:[~2017-05-08 11:50 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06 15:24 [PATCH v7 00/24] vITS save/restore Eric Auger
2017-05-06 15:24 ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 01/24] KVM: arm/arm64: Add ITS save/restore API documentation Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 11:54   ` Marc Zyngier
2017-05-07 11:54     ` Marc Zyngier
2017-05-07 17:05     ` Auger Eric
2017-05-07 17:05       ` Auger Eric
2017-05-08  9:14       ` Marc Zyngier
2017-05-08  9:14         ` Marc Zyngier
2017-05-08 11:21         ` Christoffer Dall
2017-05-08 11:21           ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 02/24] KVM: arm/arm64: Add GICV3 pending table save " Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 11:56   ` Marc Zyngier
2017-05-07 11:56     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 03/24] KVM: arm/arm64: vgic-its: rename itte into ite Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 04/24] arm/arm64: vgic: turn vgic_find_mmio_region into public Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 05/24] KVM: arm64: vgic-its: KVM_DEV_ARM_VGIC_GRP_ITS_REGS group Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 06/24] KVM: arm/arm64: vgic: expose (un)lock_all_vcpus Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 07/24] KVM: arm64: vgic-its: Implement vgic_its_has_attr_regs and attr_regs_access Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 11:57   ` Marc Zyngier
2017-05-07 11:57     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 08/24] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_creadr Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 09/24] KVM: arm64: vgic-its: Introduce migration ABI infrastructure Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-08 12:23   ` Christoffer Dall
2017-05-08 12:23     ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 10/24] KVM: arm64: vgic-its: Implement vgic_mmio_uaccess_write_its_iidr Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-08 12:24   ` Christoffer Dall
2017-05-08 12:24     ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 11/24] KVM: arm64: vgic-its: Interpret MAPD Size field and check related errors Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 12/24] KVM: arm64: vgic-its: Interpret MAPD ITT_addr field Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-06 15:24 ` [PATCH v7 13/24] KVM: arm64: vgic-its: Check the device id matches TYPER DEVBITS range Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 12:01   ` Marc Zyngier
2017-05-07 12:01     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 14/24] KVM: arm64: vgic-v3: vgic_v3_lpi_sync_pending_status Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 12:13   ` Marc Zyngier
2017-05-07 12:13     ` Marc Zyngier
2017-05-08 12:26   ` Christoffer Dall
2017-05-08 12:26     ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 15/24] KVM: arm64: vgic-its: Read config and pending bit in add_lpi() Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 12:16   ` Marc Zyngier
2017-05-07 12:16     ` Marc Zyngier
2017-05-08 12:28   ` Christoffer Dall
2017-05-08 12:28     ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 16/24] KVM: arm64: vgic-its: KVM_DEV_ARM_ITS_SAVE/RESTORE_TABLES Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:00   ` Marc Zyngier
2017-05-07 13:00     ` Marc Zyngier
2017-05-07 13:51     ` Marc Zyngier
2017-05-07 13:51       ` Marc Zyngier
2017-05-07 15:19       ` Christoffer Dall
2017-05-07 15:19         ` Christoffer Dall
2017-05-07 17:33       ` Auger Eric
2017-05-07 17:33         ` Auger Eric
2017-05-08 12:29   ` Christoffer Dall
2017-05-08 12:29     ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 17/24] KVM: arm64: vgic-its: vgic_its_alloc_ite/device Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:02   ` Marc Zyngier
2017-05-07 13:02     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 18/24] KVM: arm64: vgic-its: Add infrastructure for table lookup Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:05   ` Marc Zyngier
2017-05-07 13:05     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 19/24] KVM: arm64: vgic-its: Collection table save/restore Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:12   ` Marc Zyngier
2017-05-07 13:12     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 20/24] KVM: arm64: vgic-its: vgic_its_check_id returns the entry's GPA Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:14   ` Marc Zyngier
2017-05-07 13:14     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 21/24] KVM: arm64: vgic-its: Device table save/restore Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:30   ` Marc Zyngier
2017-05-07 13:30     ` Marc Zyngier
2017-05-07 17:22     ` Auger Eric
2017-05-07 17:22       ` Auger Eric
2017-05-08 11:30     ` Christoffer Dall
2017-05-08 11:30       ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 22/24] KVM: arm64: vgic-its: ITT save and restore Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:39   ` Marc Zyngier
2017-05-07 13:39     ` Marc Zyngier
2017-05-07 17:24     ` Auger Eric
2017-05-07 17:24       ` Auger Eric
2017-05-08 11:49     ` Christoffer Dall [this message]
2017-05-08 11:49       ` Christoffer Dall
2017-05-06 15:24 ` [PATCH v7 23/24] KVM: arm64: vgic-its: Fix pending table sync Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:42   ` Marc Zyngier
2017-05-07 13:42     ` Marc Zyngier
2017-05-06 15:24 ` [PATCH v7 24/24] KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES Eric Auger
2017-05-06 15:24   ` Eric Auger
2017-05-07 13:44   ` Marc Zyngier
2017-05-07 13:44     ` Marc Zyngier

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=20170508114956.GC28342@cbox \
    --to=cdall@linaro.org \
    --cc=Prasun.Kapoor@cavium.com \
    --cc=Vijaya.Kumar@cavium.com \
    --cc=andre.przywara@arm.com \
    --cc=bjsprakash.linux@gmail.com \
    --cc=christoffer.dall@linaro.org \
    --cc=dgilbert@redhat.com \
    --cc=drjones@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=quintela@redhat.com \
    --cc=vijayak@caviumnetworks.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.