Skip to contentSkip to conversation

ppc patch queue 2013-05-02 for 3.10

GIT PULL New Alexander Graf 2 participants 8 messages May 2, 2013 – May 3, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Marcelo / Gleb,

This is my current patch queue for ppc. Please pull and apply to next, so it makes its way into 3.10. Sorry for the late request.

There is still one RCU patch outstanding that needs a respin, so expect another request to come in later in the 3.10 cycle.

Changes include:

- Book3S HV: Expose in-kernel XICS device creation, enabling in-kernel irqchip on POWER systems.
- Various MPIC and RCU bug fixes

Alex

The following changes since commit 4cee4b72f1e2600e19779a14d4d9a4f4016ce49f:

kvm: KVM_CAP_IOMMU only available with device assignment (2013-04-29 23:08:50 -0300)

are available in the git repository at:

git://github.com/agraf/linux-2.6.git kvm-ppc-next

for you to fetch changes up to 5975a2e0950291a6bfe9fd5880e7952ff87764be:

KVM: PPC: Book3S: Add API for in-kernel XICS emulation (2013-05-02 15:28:36 +0200)

----------------------------------------------------------------
Paul Mackerras (1):
KVM: PPC: Book3S: Add API for in-kernel XICS emulation

Scott Wood (4):
kvm/ppc/mpic: remove default routes from documentation kvm/ppc/mpic: fix mmio region lists when multiple guests used kvm/ppc/mpic: remove users
kvm/ppc: Hold srcu lock when calling kvm_io_bus_read/write

Wei Yongjun (1):
kvm/ppc/mpic: fix missing unlock in set_base_addr()

 Documentation/virtual/kvm/api.txt          |   8 ++
 Documentation/virtual/kvm/devices/mpic.txt |   3 -
 Documentation/virtual/kvm/devices/xics.txt |  66 ++++++++++
 arch/powerpc/include/asm/kvm_ppc.h         |   2 +
 arch/powerpc/include/uapi/asm/kvm.h        |  12 ++
 arch/powerpc/kvm/book3s_xics.c             | 190 +++++++++++++++++++++++++----
 arch/powerpc/kvm/book3s_xics.h             |   1 +
 arch/powerpc/kvm/irq.h                     |   3 +
 arch/powerpc/kvm/mpic.c                    |  56 +++++----
 arch/powerpc/kvm/powerpc.c                 |  45 ++++++-
 include/linux/kvm_host.h                   |   1 +
 include/uapi/linux/kvm.h                   |   2 +
 virt/kvm/kvm_main.c                        |   5 +
 13 files changed, 339 insertions(+), 55 deletions(-)
 create mode 100644 Documentation/virtual/kvm/devices/xics.txt
#1 lore raw

PATCH 1/6 kvm/ppc/mpic: remove default routes from documentation

From: Scott Wood <[email protected]>

The default routes were removed from the code during patchset respinning, but were not removed from the documentation.

---
 Documentation/virtual/kvm/devices/mpic.txt | 3 ---
 1 file changed, 3 deletions(-)
Documentation/virtual/kvm/devices/mpic.txt +0 -3
index ad0ac77..8257397 100644
@@ -50,7 +50,4 @@ IRQ Routing:
   regard to any subdivisions in chip documentation such as "internal"
   or "external" interrupts.
 
-  Default routes are established for these pins, with the GSI being equal
-  to the pin number.
-
   Access to non-SRC interrupts is not implemented through IRQ routing mechanisms.
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/6 kvm/ppc/mpic: fix mmio region lists when multiple guests used

In reply to Alexander Graf

From: Scott Wood <[email protected]>

Keeping a linked list of statically defined objects doesn't work very well when we have multiple guests. :-P

Switch to an array of constant objects. This fixes a hang when multiple guests are used.

[agraf: remove struct list_head from mem_reg]
---
 arch/powerpc/kvm/mpic.c | 53 +++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 21 deletions(-)
arch/powerpc/kvm/mpic.c +32 -21
index f3148f8..886ebf6 100644
@@ -184,11 +184,14 @@ struct irq_dest {
 	uint32_t outputs_active[NUM_OUTPUTS];
 };
 
+#define MAX_MMIO_REGIONS 10
+
 struct openpic {
 	struct kvm *kvm;
 	struct kvm_device *dev;
 	struct kvm_io_device mmio;
-	struct list_head mmio_regions;
+	const struct mem_reg *mmio_regions[MAX_MMIO_REGIONS];
+	int num_mmio_regions;
 	atomic_t users;
 
 	gpa_t reg_base;
@@ -1238,62 +1241,71 @@ static int openpic_cpu_read(void *opaque, gpa_t addr, u32 *ptr)
 }
 
 struct mem_reg {
-	struct list_head list;
 	int (*read)(void *opaque, gpa_t addr, u32 *ptr);
 	int (*write)(void *opaque, gpa_t addr, u32 val);
 	gpa_t start_addr;
 	int size;
 };
 
-static struct mem_reg openpic_gbl_mmio = {
+static const struct mem_reg openpic_gbl_mmio = {
 	.write = openpic_gbl_write,
 	.read = openpic_gbl_read,
 	.start_addr = OPENPIC_GLB_REG_START,
 	.size = OPENPIC_GLB_REG_SIZE,
 };
 
-static struct mem_reg openpic_tmr_mmio = {
+static const struct mem_reg openpic_tmr_mmio = {
 	.write = openpic_tmr_write,
 	.read = openpic_tmr_read,
 	.start_addr = OPENPIC_TMR_REG_START,
 	.size = OPENPIC_TMR_REG_SIZE,
 };
 
-static struct mem_reg openpic_cpu_mmio = {
+static const struct mem_reg openpic_cpu_mmio = {
 	.write = openpic_cpu_write,
 	.read = openpic_cpu_read,
 	.start_addr = OPENPIC_CPU_REG_START,
 	.size = OPENPIC_CPU_REG_SIZE,
 };
 
-static struct mem_reg openpic_src_mmio = {
+static const struct mem_reg openpic_src_mmio = {
 	.write = openpic_src_write,
 	.read = openpic_src_read,
 	.start_addr = OPENPIC_SRC_REG_START,
 	.size = OPENPIC_SRC_REG_SIZE,
 };
 
-static struct mem_reg openpic_msi_mmio = {
+static const struct mem_reg openpic_msi_mmio = {
 	.read = openpic_msi_read,
 	.write = openpic_msi_write,
 	.start_addr = OPENPIC_MSI_REG_START,
 	.size = OPENPIC_MSI_REG_SIZE,
 };
 
-static struct mem_reg openpic_summary_mmio = {
+static const struct mem_reg openpic_summary_mmio = {
 	.read = openpic_summary_read,
 	.write = openpic_summary_write,
 	.start_addr = OPENPIC_SUMMARY_REG_START,
 	.size = OPENPIC_SUMMARY_REG_SIZE,
 };
 
+static void add_mmio_region(struct openpic *opp, const struct mem_reg *mr)
+{
+	if (opp->num_mmio_regions >= MAX_MMIO_REGIONS) {
+		WARN(1, "kvm mpic: too many mmio regions\n");
+		return;
+	}
+
+	opp->mmio_regions[opp->num_mmio_regions++] = mr;
+}
+
 static void fsl_common_init(struct openpic *opp)
 {
 	int i;
 	int virq = MAX_SRC;
 
-	list_add(&openpic_msi_mmio.list, &opp->mmio_regions);
-	list_add(&openpic_summary_mmio.list, &opp->mmio_regions);
+	add_mmio_region(opp, &openpic_msi_mmio);
+	add_mmio_region(opp, &openpic_summary_mmio);
 
 	opp->vid = VID_REVISION_1_2;
 	opp->vir = VIR_GENERIC;
@@ -1330,10 +1342,10 @@ static void fsl_common_init(struct openpic *opp)
 
 static int kvm_mpic_read_internal(struct openpic *opp, gpa_t addr, u32 *ptr)
 {
-	struct list_head *node;
+	int i;
 
-	list_for_each(node, &opp->mmio_regions) {
-		struct mem_reg *mr = list_entry(node, struct mem_reg, list);
+	for (i = 0; i < opp->num_mmio_regions; i++) {
+		const struct mem_reg *mr = opp->mmio_regions[i];
 
 		if (mr->start_addr > addr || addr >= mr->start_addr + mr->size)
 			continue;
@@ -1346,10 +1358,10 @@ static int kvm_mpic_read_internal(struct openpic *opp, gpa_t addr, u32 *ptr)
 
 static int kvm_mpic_write_internal(struct openpic *opp, gpa_t addr, u32 val)
 {
-	struct list_head *node;
+	int i;
 
-	list_for_each(node, &opp->mmio_regions) {
-		struct mem_reg *mr = list_entry(node, struct mem_reg, list);
+	for (i = 0; i < opp->num_mmio_regions; i++) {
+		const struct mem_reg *mr = opp->mmio_regions[i];
 
 		if (mr->start_addr > addr || addr >= mr->start_addr + mr->size)
 			continue;
@@ -1660,11 +1672,10 @@ static int mpic_create(struct kvm_device *dev, u32 type)
 	opp->model = type;
 	spin_lock_init(&opp->lock);
 
-	INIT_LIST_HEAD(&opp->mmio_regions);
-	list_add(&openpic_gbl_mmio.list, &opp->mmio_regions);
-	list_add(&openpic_tmr_mmio.list, &opp->mmio_regions);
-	list_add(&openpic_src_mmio.list, &opp->mmio_regions);
-	list_add(&openpic_cpu_mmio.list, &opp->mmio_regions);
+	add_mmio_region(opp, &openpic_gbl_mmio);
+	add_mmio_region(opp, &openpic_tmr_mmio);
+	add_mmio_region(opp, &openpic_src_mmio);
+	add_mmio_region(opp, &openpic_cpu_mmio);
 
 	switch (opp->model) {
 	case KVM_DEV_TYPE_FSL_MPIC_20:
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/6 kvm/ppc/mpic: remove users

In reply to Alexander Graf

From: Scott Wood <[email protected]>

This is an unused (no pun intended) leftover from when this code did reference counting.

---
 arch/powerpc/kvm/mpic.c | 1 -
 1 file changed, 1 deletion(-)
arch/powerpc/kvm/mpic.c +0 -1
index 886ebf6..eaac187 100644
@@ -192,7 +192,6 @@ struct openpic {
 	struct kvm_io_device mmio;
 	const struct mem_reg *mmio_regions[MAX_MMIO_REGIONS];
 	int num_mmio_regions;
-	atomic_t users;
 
 	gpa_t reg_base;
 	spinlock_t lock;
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/6 kvm/ppc: Hold srcu lock when calling kvm_io_bus_read/write

In reply to Alexander Graf

From: Scott Wood <[email protected]>

These functions do an srcu_dereference without acquiring the srcu lock themselves.

---
 arch/powerpc/kvm/powerpc.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
arch/powerpc/kvm/powerpc.c +19 -4
index 31084c6..270773f 100644
@@ -622,6 +622,8 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,
 int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
                        unsigned int rt, unsigned int bytes, int is_bigendian)
 {
+	int idx, ret;
+
 	if (bytes > sizeof(run->mmio.data)) {
 		printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
 		       run->mmio.len);
@@ -637,8 +639,14 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	vcpu->mmio_is_write = 0;
 	vcpu->arch.mmio_sign_extend = 0;
 
-	if (!kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
-			     bytes, &run->mmio.data)) {
+	idx = srcu_read_lock(&vcpu->kvm->srcu);
+
+	ret = kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
+			      bytes, &run->mmio.data);
+
+	srcu_read_unlock(&vcpu->kvm->srcu, idx);
+
+	if (!ret) {
 		kvmppc_complete_mmio_load(vcpu, run);
 		vcpu->mmio_needed = 0;
 		return EMULATE_DONE;
@@ -663,6 +671,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
                         u64 val, unsigned int bytes, int is_bigendian)
 {
 	void *data = run->mmio.data;
+	int idx, ret;
 
 	if (bytes > sizeof(run->mmio.data)) {
 		printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
@@ -692,8 +701,14 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		}
 	}
 
-	if (!kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
-			      bytes, &run->mmio.data)) {
+	idx = srcu_read_lock(&vcpu->kvm->srcu);
+
+	ret = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
+			       bytes, &run->mmio.data);
+
+	srcu_read_unlock(&vcpu->kvm->srcu, idx);
+
+	if (!ret) {
 		vcpu->mmio_needed = 0;
 		return EMULATE_DONE;
 	}
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/6 kvm/ppc/mpic: fix missing unlock in set_base_addr()

In reply to Alexander Graf

From: Wei Yongjun <[email protected]>

Add the missing unlock before return from function set_base_addr() when disables the mapping.

Introduced by commit 5df554ad5b7522ea62b0ff9d5be35183494efc21 (kvm/ppc/mpic: in-kernel MPIC emulation)

---
 arch/powerpc/kvm/mpic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/mpic.c +1 -1
index eaac187..2861ae9 100644
@@ -1486,8 +1486,8 @@ static int set_base_addr(struct openpic *opp, struct kvm_device_attr *attr)
 
 	map_mmio(opp);
 
-	mutex_unlock(&opp->kvm->slots_lock);
 out:
+	mutex_unlock(&opp->kvm->slots_lock);
 	return 0;
 }
 
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH 6/6 KVM: PPC: Book3S: Add API for in-kernel XICS emulation

In reply to Alexander Graf

From: Paul Mackerras <[email protected]>

This adds the API for userspace to instantiate an XICS device in a VM and connect VCPUs to it. The API consists of a new device type for the KVM_CREATE_DEVICE ioctl, a new capability KVM_CAP_IRQ_XICS, which functions similarly to KVM_CAP_IRQ_MPIC, and the KVM_IRQ_LINE ioctl, which is used to assert and deassert interrupt inputs of the XICS.

The XICS device has one attribute group, KVM_DEV_XICS_GRP_SOURCES. Each attribute within this group corresponds to the state of one interrupt source. The attribute number is the same as the interrupt source number.

This does not support irq routing or irqfd yet.

---
 Documentation/virtual/kvm/api.txt          |   8 ++
 Documentation/virtual/kvm/devices/xics.txt |  66 ++++++++++
 arch/powerpc/include/asm/kvm_ppc.h         |   2 +
 arch/powerpc/include/uapi/asm/kvm.h        |  12 ++
 arch/powerpc/kvm/book3s_xics.c             | 190 +++++++++++++++++++++++++----
 arch/powerpc/kvm/book3s_xics.h             |   1 +
 arch/powerpc/kvm/irq.h                     |   3 +
 arch/powerpc/kvm/powerpc.c                 |  22 ++++
 include/linux/kvm_host.h                   |   1 +
 include/uapi/linux/kvm.h                   |   2 +
 virt/kvm/kvm_main.c                        |   5 +
 11 files changed, 287 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/virtual/kvm/devices/xics.txt
Documentation/virtual/kvm/api.txt +8 -0
index c09d183..03492f9 100644
@@ -2772,3 +2772,11 @@ Parameters: args[0] is the MPIC device fd
             args[1] is the MPIC CPU number for this vcpu
 
 This capability connects the vcpu to an in-kernel MPIC device.
+
+6.7 KVM_CAP_IRQ_XICS
+
+Architectures: ppc
+Parameters: args[0] is the XICS device fd
+            args[1] is the XICS CPU number (server ID) for this vcpu
+
+This capability connects the vcpu to an in-kernel XICS device.
Documentation/virtual/kvm/devices/xics.txt new file +66 -0

66 lines not on this page · raw message

arch/powerpc/include/asm/kvm_ppc.h +2 -0
index d7339df..a5287fe 100644
@@ -315,6 +315,8 @@ extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
 extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
 extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
 extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
+extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
+			struct kvm_vcpu *vcpu, u32 cpu);
 #else
 static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
 	{ return 0; }
arch/powerpc/include/uapi/asm/kvm.h +12 -0
index 427b9ac..0fb1a6e 100644
@@ -499,4 +499,16 @@ struct kvm_get_htab_header {
 #define KVM_REG_PPC_TLB3PS	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9a)
 #define KVM_REG_PPC_EPTCFG	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9b)
 
+/* PPC64 eXternal Interrupt Controller Specification */
+#define KVM_DEV_XICS_GRP_SOURCES	1	/* 64-bit source attributes */
+
+/* Layout of 64-bit source attribute values */
+#define  KVM_XICS_DESTINATION_SHIFT	0
+#define  KVM_XICS_DESTINATION_MASK	0xffffffffULL
+#define  KVM_XICS_PRIORITY_SHIFT	32
+#define  KVM_XICS_PRIORITY_MASK		0xff
+#define  KVM_XICS_LEVEL_SENSITIVE	(1ULL << 40)
+#define  KVM_XICS_MASKED		(1ULL << 41)
+#define  KVM_XICS_PENDING		(1ULL << 42)
+
 #endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/kvm/book3s_xics.c +165 -25

264 lines not on this page · raw message

arch/powerpc/kvm/book3s_xics.h +1 -0
index e4fdec3..dd9326c 100644
@@ -88,6 +88,7 @@ struct kvmppc_ics {
 
 struct kvmppc_xics {
 	struct kvm *kvm;
+	struct kvm_device *dev;
 	struct dentry *dentry;
 	u32 max_icsid;
 	bool real_mode;
arch/powerpc/kvm/irq.h +3 -0
index f1e27fd..5a9a10b 100644
@@ -10,6 +10,9 @@ static inline int irqchip_in_kernel(struct kvm *kvm)
 #ifdef CONFIG_KVM_MPIC
 	ret = ret || (kvm->arch.mpic != NULL);
 #endif
+#ifdef CONFIG_KVM_XICS
+	ret = ret || (kvm->arch.xics != NULL);
+#endif
 	smp_rmb();
 	return ret;
 }
arch/powerpc/kvm/powerpc.c +22 -0
index 270773f..6316ee3 100644
@@ -342,6 +342,9 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_SPAPR_TCE:
 	case KVM_CAP_PPC_ALLOC_HTAB:
 	case KVM_CAP_PPC_RTAS:
+#ifdef CONFIG_KVM_XICS
+	case KVM_CAP_IRQ_XICS:
+#endif
 		r = 1;
 		break;
 #endif /* CONFIG_PPC_BOOK3S_64 */
@@ -837,6 +840,25 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
 		break;
 	}
 #endif
+#ifdef CONFIG_KVM_XICS
+	case KVM_CAP_IRQ_XICS: {
+		struct file *filp;
+		struct kvm_device *dev;
+
+		r = -EBADF;
+		filp = fget(cap->args[0]);
+		if (!filp)
+			break;
+
+		r = -EPERM;
+		dev = kvm_device_from_filp(filp);
+		if (dev)
+			r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
+
+		fput(filp);
+		break;
+	}
+#endif /* CONFIG_KVM_XICS */
 	default:
 		r = -EINVAL;
 		break;
include/linux/kvm_host.h +1 -0
index 996661e..7823b63 100644
@@ -1086,6 +1086,7 @@ void kvm_device_put(struct kvm_device *dev);
 struct kvm_device *kvm_device_from_filp(struct file *filp);
 
 extern struct kvm_device_ops kvm_mpic_ops;
+extern struct kvm_device_ops kvm_xics_ops;
 
 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
 
include/uapi/linux/kvm.h +2 -0
index 965e5b5..a5c86fc 100644
@@ -665,6 +665,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_DEVICE_CTRL 89
 #define KVM_CAP_IRQ_MPIC 90
 #define KVM_CAP_PPC_RTAS 91
+#define KVM_CAP_IRQ_XICS 92
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -837,6 +838,7 @@ struct kvm_device_attr {
 
 #define KVM_DEV_TYPE_FSL_MPIC_20	1
 #define KVM_DEV_TYPE_FSL_MPIC_42	2
+#define KVM_DEV_TYPE_XICS		3
 
 /*
  * ioctls for VM fds
virt/kvm/kvm_main.c +5 -0
index 5da9f02..e6e7abe 100644
@@ -2247,6 +2247,11 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
 		ops = &kvm_mpic_ops;
 		break;
 #endif
+#ifdef CONFIG_KVM_XICS
+	case KVM_DEV_TYPE_XICS:
+		ops = &kvm_xics_ops;
+		break;
+#endif
 	default:
 		return -ENODEV;
 	}
Signature · 1 line
1.8.1.4
#7 lore raw
In reply to Alexander Graf
Quoted 21 lines · Alexander Graf

Hi Marcelo / Gleb,

This is my current patch queue for ppc. Please pull and apply to next, so it makes its way into 3.10. Sorry for the late request.

There is still one RCU patch outstanding that needs a respin, so expect another request to come in later in the 3.10 cycle.

Changes include:

- Book3S HV: Expose in-kernel XICS device creation, enabling in-kernel irqchip on POWER systems.
- Various MPIC and RCU bug fixes

Alex

The following changes since commit 4cee4b72f1e2600e19779a14d4d9a4f4016ce49f:

kvm: KVM_CAP_IOMMU only available with device assignment (2013-04-29 23:08:50 -0300)

Quoted 7 lines

are available in the git repository at:

git://github.com/agraf/linux-2.6.git kvm-ppc-next

for you to fetch changes up to 5975a2e0950291a6bfe9fd5880e7952ff87764be:

KVM: PPC: Book3S: Add API for in-kernel XICS emulation (2013-05-02 15:28:36 +0200)

Pulled, thanks.