[PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check

2015-06-28 Thread SF Markus Elfring
From: Markus Elfring elfr...@users.sourceforge.net

Another update suggestion was taken into account after a patch was applied
from static source code analysis.

Markus Elfring (2):
  Delete an unnecessary check before the function call kfree
  One function call less in tce_iommu_attach_group() after kzalloc() failure

 drivers/vfio/vfio_iommu_spapr_tce.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] vfio: powerpc/spapr: Delete an unnecessary check before the function call kfree

2015-06-28 Thread SF Markus Elfring
From: Markus Elfring elfr...@users.sourceforge.net
Date: Sun, 28 Jun 2015 17:43:48 +0200

The kfree() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring elfr...@users.sourceforge.net
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c 
b/drivers/vfio/vfio_iommu_spapr_tce.c
index 0582b72..50ddfac 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -1215,7 +1215,7 @@ static int tce_iommu_attach_group(void *iommu_data,
}
 
 unlock_exit:
-   if (ret  tcegrp)
+   if (ret)
kfree(tcegrp);
 
mutex_unlock(container-lock);
-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure

2015-06-28 Thread SF Markus Elfring
From: Markus Elfring elfr...@users.sourceforge.net
Date: Sun, 28 Jun 2015 17:58:42 +0200

The kfree() function was called even if a previous memory allocation
try failed.

This implementation detail could be improved by the introduction
of another jump label.

Signed-off-by: Markus Elfring elfr...@users.sourceforge.net
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c 
b/drivers/vfio/vfio_iommu_spapr_tce.c
index 50ddfac..2523075 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data,
tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL);
if (!tcegrp) {
ret = -ENOMEM;
-   goto unlock_exit;
+   goto unlock_container;
}
 
if (!table_group-ops || !table_group-ops-take_ownership ||
@@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data,
 unlock_exit:
if (ret)
kfree(tcegrp);
-
+unlock_container:
mutex_unlock(container-lock);
 
return ret;
-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/3] arm: KVM: VFP lazy switch in KVM Host Mode may save upto 98%

2015-06-28 Thread Mario Smarduch
Hi Marc, Christoffer -

to clarify - this series may be causing a conflict with the arm64
basic approach, and arm32 exit code touch ups.

The intent for this series  is more of an RFC or preview, to get some
feedback - if this approach is sensible (I guess later applied to
arm64 as well if it is).

Thanks,
- Mario


On 06/24/2015 08:30 PM, Mario Smarduch wrote:
 Currently we do a lazy VFP switch in Hyp mode, but once we exit and re-enter 
 hyp
 mode we trap again on VFP access. This mode has shown around 30-50% 
 improvement
 running hackbench and lmbench.
 
 This patch series extends lazy VFP switch beyond Hyp mode to KVM host mode.
 
 1 - On guest access we switch from host to guest and set a flag accessible to 
 host
 2 - On exit to KVM host, VFP state is restored on vcpu_put if flag is marked 
 (1)
 3 - Otherwise guest is resumed and continues to use its VFP registers. 
 4 - In case of 2 on VM entry we set VFP trap flag to repeat 1.
 
 If guest does not access VFP registers them implemenation remains the same.
 
 Executing hackbench on Fast Models and Exynos arm32 board shows good
 results. Considering all exits 2% of the time KVM host lazy vfp switch is 
 invoked.
 
 Howeverr this patch set requires more burn in time and testing under various 
 loads.
 
 Currently ARM32 is addressed later ARM64.
 
 Mario Smarduch (3):
   define headers and offsets to mange VFP state
   Implement lazy VFP switching outside of Hyp Mode
   Add VFP lazy switch hooks in Host KVM
 
  arch/arm/include/asm/kvm_asm.h  |1 +
  arch/arm/include/asm/kvm_host.h |3 +++
  arch/arm/kernel/asm-offsets.c   |1 +
  arch/arm/kvm/arm.c  |   15 
  arch/arm/kvm/interrupts.S   |   49 
 +--
  5 files changed, 51 insertions(+), 18 deletions(-)
 

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 10/13] KVM: arm64: sync LPI properties and status between guest and KVM

2015-06-28 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:53:26AM +0100, Andre Przywara wrote:
 The properties and status of the GICv3 LPIs are hold in tables in
 (guest) memory. To achieve reasonable performance, we cache this
 data in our own data structures, so we need to sync those two views
 from time to time. This behaviour is well described in the GICv3 spec
 and is also exercised by hardware, so the sync points are well known.
 
 Provide functions that read the guest memory and store the
 information from the property and status table in the kernel.
 
 Signed-off-by: Andre Przywara andre.przyw...@arm.com
 ---
  virt/kvm/arm/its-emul.c | 140 
 
  1 file changed, 140 insertions(+)
 
 diff --git a/virt/kvm/arm/its-emul.c b/virt/kvm/arm/its-emul.c
 index f75fb9e..afd440e 100644
 --- a/virt/kvm/arm/its-emul.c
 +++ b/virt/kvm/arm/its-emul.c
 @@ -50,6 +50,7 @@ struct its_itte {
   struct its_collection *collection;
   u32 lpi;
   u32 event_id;
 + u8 priority;
   bool enabled;
   unsigned long *pending;
  };
 @@ -70,7 +71,140 @@ static struct its_itte *find_itte_by_lpi(struct kvm *kvm, 
 int lpi)
   return NULL;
  }
  
 +#define LPI_PROP_ENABLE_BIT(p)   ((p)  LPI_PROP_ENABLED)
 +#define LPI_PROP_PRIORITY(p) ((p)  0xfc)
 +
 +/* stores the priority and enable bit for a given LPI */
 +static void update_lpi_property(struct kvm *kvm, struct its_itte *itte, u8 
 prop)
 +{
 + itte-priority = LPI_PROP_PRIORITY(prop);
 + itte-enabled  = LPI_PROP_ENABLE_BIT(prop);
 +}
 +
 +#define GIC_LPI_OFFSET 8192
 +
 +/* We scan the table in chunks the size of the smallest page size */
 +#define CHUNK_SIZE 4096U
 +
  #define BASER_BASE_ADDRESS(x) ((x)  0xf000ULL)
 +#define PROPBASE_TSIZE(x) (1U  (x  0x1f))
 +
 +/*
 + * Scan the whole LPI property table and put the LPI configuration
 + * data in our own data structures. This relies on the LPI being
 + * mapped before.
 + * We scan from two sides:
 + * 1) for each byte in the table we care for the ones being enabled
 + * 2) for each mapped LPI we look into the table to spot LPIs being disabled
 + * Must be called with the ITS lock held.
 + */
 +static bool its_update_lpi_properties(struct kvm *kvm)
 +{
 + struct vgic_dist *dist = kvm-arch.vgic;
 + u8 *prop;
 + u32 tsize;
 + gpa_t propbase;
 + int lpi = GIC_LPI_OFFSET;
 + struct its_itte *itte;
 + struct its_device *device;
 + int ret;
 +
 + propbase = BASER_BASE_ADDRESS(dist-propbaser);
 + tsize = PROPBASE_TSIZE(dist-propbaser);
 +
 + prop = kmalloc(CHUNK_SIZE, GFP_KERNEL);
 + if (!prop)
 + return false;
 +
 + while (tsize  0) {
 + int chunksize = min(tsize, CHUNK_SIZE);
 +
 + ret = kvm_read_guest(kvm, propbase, prop, chunksize);
 + if (ret) {
 + kfree(prop);
 + break;
 + }
 +
 + /*
 +  * Updating the status for all allocated LPIs. We catch
 +  * those LPIs that get disabled. We really don't care
 +  * about unmapped LPIs, as they need to be updated
 +  * later manually anyway once they get mapped.
 +  */
 + for_each_lpi(device, itte, kvm) {
 + /*
 +  * Is the LPI covered by that part of the table we
 +  * are currently looking at?
 +  */
 + if (itte-lpi  lpi)
 + continue;
 + if (itte-lpi = lpi + chunksize)
 + continue;
 +
 + update_lpi_property(kvm, itte,
 + prop[itte-lpi - lpi]);
 + }
 + tsize -= chunksize;
 + lpi += chunksize;
 + propbase += chunksize;
 + }
 +
 + kfree(prop);
 + return true;
 +}
 +
 +/*
 + * Scan the whole LPI pending table and sync the pending bit in there
 + * with our own data structures. This relies on the LPI being
 + * mapped before.
 + * Must be called with the ITS lock held.
 + */
 +static bool its_sync_lpi_pending_table(struct kvm_vcpu *vcpu)
 +{
 + struct vgic_dist *dist = vcpu-kvm-arch.vgic;
 + unsigned long *pendmask;
 + u32 nr_lpis;
 + gpa_t pendbase;
 + int lpi = GIC_LPI_OFFSET;
 + struct its_itte *itte;
 + struct its_device *device;
 + int ret;
 + int lpi_bit, nr_bits;
 +
 + pendbase = BASER_BASE_ADDRESS(dist-pendbaser[vcpu-vcpu_id]);
 + nr_lpis = GIC_LPI_OFFSET;
 +
 + pendmask = kmalloc(CHUNK_SIZE, GFP_KERNEL);
 + if (!pendmask)
 + return false;
 +
 + while (nr_lpis  0) {
 + nr_bits = min(nr_lpis, CHUNK_SIZE * 8);
 +
 + ret = kvm_read_guest(vcpu-kvm, pendbase, pendmask,
 +  nr_bits / 8);
 + if (ret)
 + break;
 +
 + for_each_lpi(device, itte, 

Re: [PATCH 02/13] KVM: extend struct kvm_msi to hold a 32-bit device ID

2015-06-28 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:53:18AM +0100, Andre Przywara wrote:
 The ARM GICv3 ITS MSI controller requires a device ID to be able to
 assign the proper interrupt vector. On real hardware, this ID is
 sampled from the bus. To be able to emulate an ITS controller, extend
 the KVM MSI interface to let userspace provide such a device ID. For
 PCI devices, the device ID is simply the 16-bit bus-device-function
 triplet, which should be easily available to the userland tool.
 
 Signed-off-by: Andre Przywara andre.przyw...@arm.com
 ---
  Documentation/virtual/kvm/api.txt | 8 ++--
  include/uapi/linux/kvm.h  | 4 +++-
  2 files changed, 9 insertions(+), 3 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 9fa2bf8..891d64a 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2121,10 +2121,14 @@ struct kvm_msi {
   __u32 address_hi;
   __u32 data;
   __u32 flags;
 - __u8  pad[16];
 + __u32 devid;
 + __u8  pad[12];
  };
  
 -No flags are defined so far. The corresponding field must be 0.
 +flags: KVM_MSI_VALID_DEVID: devid is valid, otherwise ignored.

I don't see what the 'otherwise ignored' part of the sentence here is
meant to say, that the flags field is otherwise ignored for other value?
That's not what the current API doc specifies, it specifies that the
remainder of the field must be 0.

 +devid: If KVM_MSI_VALID_DEVID is set, contains a value to identify the device
 +   that wrote the MSI message. For PCI, this is usually a BFD
 +   identifier in the lower 16 bits.

I assume plus something else that uniquely identifies the PCI
controller?

-Christoffer

  
  
  4.71 KVM_CREATE_PIT2
 diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
 index 4b60056..2a23705 100644
 --- a/include/uapi/linux/kvm.h
 +++ b/include/uapi/linux/kvm.h
 @@ -965,12 +965,14 @@ struct kvm_one_reg {
   __u64 addr;
  };
  
 +#define KVM_MSI_VALID_DEVID  (1U  0)
  struct kvm_msi {
   __u32 address_lo;
   __u32 address_hi;
   __u32 data;
   __u32 flags;
 - __u8  pad[16];
 + __u32 devid;
 + __u8  pad[12];
  };
  
  struct kvm_arm_device_addr {
 -- 
 2.3.5
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 07/13] KVM: arm64: implement basic ITS register handlers

2015-06-28 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:53:23AM +0100, Andre Przywara wrote:
 Add emulation for some basic MMIO registers used in the ITS emulation.
 This includes:
 - GITS_{CTLR,TYPER,IIDR}
 - ID registers
 - GITS_{CBASER,CREAD,CWRITER}
   those implement the ITS command buffer handling
 
 Signed-off-by: Andre Przywara andre.przyw...@arm.com
 ---
  include/kvm/arm_vgic.h |   3 +
  include/linux/irqchip/arm-gic-v3.h |   8 ++
  virt/kvm/arm/its-emul.c| 172 
 +
  virt/kvm/arm/its-emul.h|   1 +
  virt/kvm/arm/vgic-v3-emul.c|   2 +
  5 files changed, 186 insertions(+)
 
 diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
 index d76c2d9..3b8e3a1 100644
 --- a/include/kvm/arm_vgic.h
 +++ b/include/kvm/arm_vgic.h
 @@ -159,6 +159,9 @@ struct vgic_io_device {
  struct vgic_its {
   boolenabled;
   spinlock_t  lock;
 + u64 cbaser;
 + int creadr;
 + int cwriter;
  };
  
  struct vgic_dist {
 diff --git a/include/linux/irqchip/arm-gic-v3.h 
 b/include/linux/irqchip/arm-gic-v3.h
 index df4e527..0b450c7 100644
 --- a/include/linux/irqchip/arm-gic-v3.h
 +++ b/include/linux/irqchip/arm-gic-v3.h
 @@ -179,15 +179,23 @@
  #define GITS_BASER   0x0100
  #define GITS_IDREGS_BASE 0xffd0
  #define GITS_PIDR2   GICR_PIDR2
 +#define GITS_PIDR4   0xffd0
 +#define GITS_CIDR0   0xfff0
 +#define GITS_CIDR1   0xfff4
 +#define GITS_CIDR2   0xfff8
 +#define GITS_CIDR3   0xfffc
  
  #define GITS_TRANSLATER  0x10040
  
  #define GITS_CTLR_ENABLE (1U  0)
  #define GITS_CTLR_QUIESCENT  (1U  31)
  
 +#define GITS_TYPER_PLPIS (1UL  0)
 +#define GITS_TYPER_IDBITS_SHIFT  8
  #define GITS_TYPER_DEVBITS_SHIFT 13
  #define GITS_TYPER_DEVBITS(r)r)  
 GITS_TYPER_DEVBITS_SHIFT)  0x1f) + 1)
  #define GITS_TYPER_PTA   (1UL  19)
 +#define GITS_TYPER_HWCOLLCNT_SHIFT   24
  
  #define GITS_CBASER_VALID(1UL  63)
  #define GITS_CBASER_nCnB (0UL  59)
 diff --git a/virt/kvm/arm/its-emul.c b/virt/kvm/arm/its-emul.c
 index 7b283ce..82bc34a 100644
 --- a/virt/kvm/arm/its-emul.c
 +++ b/virt/kvm/arm/its-emul.c
 @@ -32,10 +32,62 @@
  #include vgic.h
  #include its-emul.h
  
 +#define BASER_BASE_ADDRESS(x) ((x)  0xf000ULL)
 +
 +/* distributor lock is hold by the VGIC MMIO handler */
  static bool handle_mmio_misc_gits(struct kvm_vcpu *vcpu,
 struct kvm_exit_mmio *mmio,
 phys_addr_t offset)
  {
 + struct vgic_its *its = vcpu-kvm-arch.vgic.its;
 + u32 reg;
 + bool was_enabled;
 +
 + switch (offset  ~3) {
 + case 0x00:  /* GITS_CTLR */
 + /* We never defer any command execution. */
 + reg = GITS_CTLR_QUIESCENT;
 + if (its-enabled)
 + reg |= GITS_CTLR_ENABLE;
 + was_enabled = its-enabled;
 + vgic_reg_access(mmio, reg, offset  3,
 + ACCESS_READ_VALUE | ACCESS_WRITE_VALUE);
 + its-enabled = !!(reg  GITS_CTLR_ENABLE);
 + return !was_enabled  its-enabled;
 + case 0x04:  /* GITS_IIDR */
 + reg = (PRODUCT_ID_KVM  24) | (IMPLEMENTER_ARM  0);
 + vgic_reg_access(mmio, reg, offset  3,
 + ACCESS_READ_VALUE | ACCESS_WRITE_IGNORED);
 + break;
 + case 0x08:  /* GITS_TYPER */
 + /*
 +  * We use linear CPU numbers for redistributor addressing,
 +  * so GITS_TYPER.PTA is 0.
 +  * To avoid memory waste on the guest side, we keep the
 +  * number of IDBits and DevBits low for the time being.
 +  * This could later be made configurable by userland.
 +  * Since we have all collections in linked list, we claim
 +  * that we can hold all of the collection tables in our
 +  * own memory and that the ITT entry size is 1 byte (the
 +  * smallest possible one).
 +  */
 + reg = GITS_TYPER_PLPIS;
 + reg |= 0xff  GITS_TYPER_HWCOLLCNT_SHIFT;
 + reg |= 0x0f  GITS_TYPER_DEVBITS_SHIFT;
 + reg |= 0x0f  GITS_TYPER_IDBITS_SHIFT;
 + vgic_reg_access(mmio, reg, offset  3,
 + ACCESS_READ_VALUE | ACCESS_WRITE_IGNORED);
 + break;
 + case 0x0c:
 + /* The upper 32bits of TYPER are all 0 for the time being.
 +  * Should we need more than 256 collections, we can enable
 +  * some bits in here.
 +  */
 + vgic_reg_access(mmio, NULL, offset  3,
 +  

Re: [PATCH 11/13] KVM: arm64: implement ITS command queue command handlers

2015-06-28 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:53:27AM +0100, Andre Przywara wrote:
 The connection between a device, an event ID, the LPI number and the
 allocated CPU is stored in in-memory tables in a GICv3, but their
 format is not specified by the spec. Instead software uses a command
 queue to let the ITS implementation use their own format.
 Implement handlers for the various ITS commands and let them store
 the requested relation into our own data structures.
 Error handling is very basic at this point, as we don't have a good
 way of communicating errors to the guest (usually a SError).
 
 Signed-off-by: Andre Przywara andre.przyw...@arm.com
 ---
  include/linux/irqchip/arm-gic-v3.h |   1 +
  virt/kvm/arm/its-emul.c| 422 
 -
  virt/kvm/arm/its-emul.h|  11 +
  3 files changed, 433 insertions(+), 1 deletion(-)
 
 diff --git a/include/linux/irqchip/arm-gic-v3.h 
 b/include/linux/irqchip/arm-gic-v3.h
 index 0b450c7..651aacc 100644
 --- a/include/linux/irqchip/arm-gic-v3.h
 +++ b/include/linux/irqchip/arm-gic-v3.h
 @@ -254,6 +254,7 @@
  #define GITS_CMD_MAPD0x08
  #define GITS_CMD_MAPC0x09
  #define GITS_CMD_MAPVI   0x0a
 +#define GITS_CMD_MAPI0x0b
  #define GITS_CMD_MOVI0x01
  #define GITS_CMD_DISCARD 0x0f
  #define GITS_CMD_INV 0x0c
 diff --git a/virt/kvm/arm/its-emul.c b/virt/kvm/arm/its-emul.c
 index afd440e..574cf05 100644
 --- a/virt/kvm/arm/its-emul.c
 +++ b/virt/kvm/arm/its-emul.c
 @@ -22,6 +22,7 @@
  #include linux/kvm_host.h
  #include linux/interrupt.h
  #include linux/list.h
 +#include linux/slab.h
  
  #include linux/irqchip/arm-gic-v3.h
  #include kvm/arm_vgic.h
 @@ -55,6 +56,34 @@ struct its_itte {
   unsigned long *pending;
  };
  
 +static struct its_device *find_its_device(struct kvm *kvm, u32 device_id)
 +{
 + struct vgic_its *its = kvm-arch.vgic.its;
 + struct its_device *device;
 +
 + list_for_each_entry(device, its-device_list, dev_list)
 + if (device_id == device-device_id)
 + return device;
 +
 + return NULL;
 +}
 +
 +static struct its_itte *find_itte(struct kvm *kvm, u32 device_id, u32 
 event_id)
 +{
 + struct its_device *device;
 + struct its_itte *itte;
 +
 + device = find_its_device(kvm, device_id);
 + if (device == NULL)
 + return NULL;
 +
 + list_for_each_entry(itte, device-itt, itte_list)
 + if (itte-event_id == event_id)
 + return itte;
 +
 + return NULL;
 +}
 +
  #define for_each_lpi(dev, itte, kvm) \
   list_for_each_entry(dev, (kvm)-arch.vgic.its.device_list, dev_list) \
   list_for_each_entry(itte, (dev)-itt, itte_list)
 @@ -71,6 +100,19 @@ static struct its_itte *find_itte_by_lpi(struct kvm *kvm, 
 int lpi)
   return NULL;
  }
  
 +static struct its_collection *find_collection(struct kvm *kvm, int coll_id)
 +{
 + struct its_collection *collection;
 +
 + list_for_each_entry(collection, kvm-arch.vgic.its.collection_list,
 + coll_list) {
 + if (coll_id == collection-collection_id)
 + return collection;
 + }
 +
 + return NULL;
 +}
 +
  #define LPI_PROP_ENABLE_BIT(p)   ((p)  LPI_PROP_ENABLED)
  #define LPI_PROP_PRIORITY(p) ((p)  0xfc)
  
 @@ -345,9 +387,386 @@ void vits_unqueue_lpi(struct kvm_vcpu *vcpu, int lpi)
   spin_unlock(its-lock);
  }
  
 +static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)
 +{
 + return (le64_to_cpu(its_cmd[word])  shift)  (BIT_ULL(size) - 1);
 +}
 +
 +#define its_cmd_get_command(cmd) its_cmd_mask_field(cmd, 0,  0,  8)
 +#define its_cmd_get_deviceid(cmd)its_cmd_mask_field(cmd, 0, 32, 32)
 +#define its_cmd_get_id(cmd)  its_cmd_mask_field(cmd, 1,  0, 32)
 +#define its_cmd_get_physical_id(cmd) its_cmd_mask_field(cmd, 1, 32, 32)
 +#define its_cmd_get_collection(cmd)  its_cmd_mask_field(cmd, 2,  0, 16)
 +#define its_cmd_get_target_addr(cmd) its_cmd_mask_field(cmd, 2, 16, 32)
 +#define its_cmd_get_validbit(cmd)its_cmd_mask_field(cmd, 2, 63,  1)
 +
 +/*
 + * Handles the DISCARD command, which frees an ITTE.
 + * Must be called with the ITS lock held.
 + */
 +static int vits_cmd_handle_discard(struct kvm *kvm, u64 *its_cmd)
 +{
 + u32 device_id;
 + u32 event_id;
 + struct its_itte *itte;
 +
 + device_id = its_cmd_get_deviceid(its_cmd);
 + event_id = its_cmd_get_id(its_cmd);
 +
 + itte = find_itte(kvm, device_id, event_id);
 + if (!itte || !itte-collection)
 + return E_ITS_DISCARD_UNMAPPED_INTERRUPT;
 +
 + clear_bit(itte-collection-target_addr, itte-pending);
 +
 + list_del(itte-itte_list);
 + kfree(itte);
 + return 0;
 +}
 +
 +/*
 + * Handles the MOVI command, which moves an ITTE to a different collection.
 + * Must be called with the ITS lock held.
 + 

Re: [PATCH 03/13] KVM: arm/arm64: add emulation model specific destroy function

2015-06-28 Thread Christoffer Dall
On Fri, May 29, 2015 at 10:53:19AM +0100, Andre Przywara wrote:
 Currently we destroy the VGIC emulation in one function that cares for
 all emulated models. The ITS emulation will require some
 differentiation, so introduce a per-emulation-model destroy method.

why do we need to differentiate between the destroy and the destroy
model?  This is not clear from the commit message.

-Christoffer

 Use it for a tiny GICv3 specific code already.
 
 Signed-off-by: Andre Przywara andre.przyw...@arm.com
 ---
  include/kvm/arm_vgic.h  |  1 +
  virt/kvm/arm/vgic-v3-emul.c |  9 +
  virt/kvm/arm/vgic.c | 11 ++-
  3 files changed, 20 insertions(+), 1 deletion(-)
 
 diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
 index 2ccfa9a..b18e2c5 100644
 --- a/include/kvm/arm_vgic.h
 +++ b/include/kvm/arm_vgic.h
 @@ -144,6 +144,7 @@ struct vgic_vm_ops {
   bool(*queue_sgi)(struct kvm_vcpu *, int irq);
   void(*add_sgi_source)(struct kvm_vcpu *, int irq, int source);
   int (*init_model)(struct kvm *);
 + void(*destroy_model)(struct kvm *);
   int (*map_resources)(struct kvm *, const struct vgic_params *);
  };
  
 diff --git a/virt/kvm/arm/vgic-v3-emul.c b/virt/kvm/arm/vgic-v3-emul.c
 index e9c3a7a..fbfdd6f 100644
 --- a/virt/kvm/arm/vgic-v3-emul.c
 +++ b/virt/kvm/arm/vgic-v3-emul.c
 @@ -818,6 +818,14 @@ static int vgic_v3_init_model(struct kvm *kvm)
   return 0;
  }
  
 +static void vgic_v3_destroy_model(struct kvm *kvm)
 +{
 + struct vgic_dist *dist = kvm-arch.vgic;
 +
 + kfree(dist-irq_spi_mpidr);
 + dist-irq_spi_mpidr = NULL;
 +}
 +
  /* GICv3 does not keep track of SGI sources anymore. */
  static void vgic_v3_add_sgi_source(struct kvm_vcpu *vcpu, int irq, int 
 source)
  {
 @@ -830,6 +838,7 @@ void vgic_v3_init_emulation(struct kvm *kvm)
   dist-vm_ops.queue_sgi = vgic_v3_queue_sgi;
   dist-vm_ops.add_sgi_source = vgic_v3_add_sgi_source;
   dist-vm_ops.init_model = vgic_v3_init_model;
 + dist-vm_ops.destroy_model = vgic_v3_destroy_model;
   dist-vm_ops.map_resources = vgic_v3_map_resources;
  
   kvm-arch.max_vcpus = KVM_MAX_VCPUS;
 diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
 index 037b723..6ea30e0 100644
 --- a/virt/kvm/arm/vgic.c
 +++ b/virt/kvm/arm/vgic.c
 @@ -102,6 +102,14 @@ int kvm_vgic_map_resources(struct kvm *kvm)
   return kvm-arch.vgic.vm_ops.map_resources(kvm, vgic);
  }
  
 +static void vgic_destroy_model(struct kvm *kvm)
 +{
 + struct vgic_vm_ops *vm_ops = kvm-arch.vgic.vm_ops;
 +
 + if (vm_ops-destroy_model)
 + vm_ops-destroy_model(kvm);
 +}
 +
  /*
   * struct vgic_bitmap contains a bitmap made of unsigned longs, but
   * extracts u32s out of them.
 @@ -1631,6 +1639,8 @@ void kvm_vgic_destroy(struct kvm *kvm)
   struct kvm_vcpu *vcpu;
   int i;
  
 + vgic_destroy_model(kvm);
 +
   kvm_for_each_vcpu(i, vcpu, kvm)
   kvm_vgic_vcpu_destroy(vcpu);
  
 @@ -1647,7 +1657,6 @@ void kvm_vgic_destroy(struct kvm *kvm)
   }
   kfree(dist-irq_sgi_sources);
   kfree(dist-irq_spi_cpu);
 - kfree(dist-irq_spi_mpidr);
   kfree(dist-irq_spi_target);
   kfree(dist-irq_pending_on_cpu);
   kfree(dist-irq_active_on_cpu);
 -- 
 2.3.5
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure

2015-06-28 Thread Alexey Kardashevskiy

On 06/29/2015 02:24 AM, SF Markus Elfring wrote:

From: Markus Elfring elfr...@users.sourceforge.net
Date: Sun, 28 Jun 2015 17:58:42 +0200

The kfree() function was called even if a previous memory allocation
try failed.


tcegrp will be NULL and kfree() can handle this just fine (is not it the 
whole point of this patchset - remove the check and just call kfree() even 
if the pointer is NULL?). And if you wanted another label, than the 
existing one should have been renamed to free_exit or free_unlock_exit 
and new one would be unlock_exit.





This implementation detail could be improved by the introduction
of another jump label.

Signed-off-by: Markus Elfring elfr...@users.sourceforge.net
---
  drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c 
b/drivers/vfio/vfio_iommu_spapr_tce.c
index 50ddfac..2523075 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data,
tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL);
if (!tcegrp) {
ret = -ENOMEM;
-   goto unlock_exit;
+   goto unlock_container;
}

if (!table_group-ops || !table_group-ops-take_ownership ||
@@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data,
  unlock_exit:
if (ret)
kfree(tcegrp);
-
+unlock_container:
mutex_unlock(container-lock);

return ret;




--
Alexey
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html