LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements
@ 2018-05-23  2:56 Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 1/4] vfio: ccw: shorten kernel doc description for pfn_array_pin() Dong Jia Shi
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Dong Jia Shi @ 2018-05-23  2:56 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: cohuck, borntraeger, bjsdjshi, pasic, pmorel

Dear Reviewers,

Here is a new version for this patch series.

We didn't get agreement on patch #4 (#5 in v2) in the former cycle though,
I made it based on my understanding. We can continue discussing on it.

Changelog:
v3->v4:
 - Change mail address from @linux.vnet.ibm.com to @linux.ibm.com

v2->v3:
 - #2. Reworded comment message.
 - #4. Trace failure only, trace all error path, and a common knob for all
       failure paths.

v1->v2:
 - #1. Reworded commit message and comment, plus some typo fixes.
 - #2. New patch.
 - #3. Added the missing suggested-by Pierre.
       Fixed typos.
       Added sanity check on pa->pa_iova_pfn and updated comments accordingly.
 - #4. Removed unused idaw_nr.
 - #5. Replaced leading white spaces with TABs.
       Traced the function in anycase.

Dong Jia Shi (3):
  vfio: ccw: shorten kernel doc description for pfn_array_pin()
  vfio: ccw: refactor and improve pfn_array_alloc_pin()
  vfio: ccw: set ccw->cda to NULL defensively

Halil Pasic (1):
  vfio: ccw: add traceponits for interesting error paths

 drivers/s390/cio/Makefile         |   1 +
 drivers/s390/cio/vfio_ccw_cp.c    | 121 +++++++++++++++++++-------------------
 drivers/s390/cio/vfio_ccw_fsm.c   |  17 +++++-
 drivers/s390/cio/vfio_ccw_trace.h |  54 +++++++++++++++++
 4 files changed, 130 insertions(+), 63 deletions(-)
 create mode 100644 drivers/s390/cio/vfio_ccw_trace.h

-- 
2.16.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/4] vfio: ccw: shorten kernel doc description for pfn_array_pin()
  2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
@ 2018-05-23  2:56 ` Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 2/4] vfio: ccw: refactor and improve pfn_array_alloc_pin() Dong Jia Shi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Dong Jia Shi @ 2018-05-23  2:56 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: cohuck, borntraeger, bjsdjshi, pasic, pmorel

The kernel doc description for usage of the struct pfn_array in
pfn_array_pin() is unnecessary long. Let's shorten it by describing
the contents of the struct pfn_array fields at the struct's definition
instead.

Suggested-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.ibm.com>
---
 drivers/s390/cio/vfio_ccw_cp.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
index dce92b2a895d..b38ef387e4f0 100644
--- a/drivers/s390/cio/vfio_ccw_cp.c
+++ b/drivers/s390/cio/vfio_ccw_cp.c
@@ -23,9 +23,13 @@
 #define CCWCHAIN_LEN_MAX	256
 
 struct pfn_array {
+	/* Starting guest physical I/O address. */
 	unsigned long		pa_iova;
+	/* Array that stores PFNs of the pages need to pin. */
 	unsigned long		*pa_iova_pfn;
+	/* Array that receives PFNs of the pages pinned. */
 	unsigned long		*pa_pfn;
+	/* Number of pages to pin/pinned from @pa_iova. */
 	int			pa_nr;
 };
 
@@ -53,14 +57,8 @@ struct ccwchain {
  * Attempt to pin user pages in memory.
  *
  * Usage of pfn_array:
- * @pa->pa_iova     starting guest physical I/O address. Assigned by caller.
- * @pa->pa_iova_pfn array that stores PFNs of the pages need to pin. Allocated
- *                  by caller.
- * @pa->pa_pfn      array that receives PFNs of the pages pinned. Allocated by
- *                  caller.
- * @pa->pa_nr       number of pages from @pa->pa_iova to pin. Assigned by
- *                  caller.
- *                  number of pages pinned. Assigned by callee.
+ * Any field in this structure should be initialized by caller.
+ * We expect @pa->pa_nr > 0, and its value will be assigned by callee.
  *
  * Returns:
  *   Number of pages pinned on success.
-- 
2.16.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 2/4] vfio: ccw: refactor and improve pfn_array_alloc_pin()
  2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 1/4] vfio: ccw: shorten kernel doc description for pfn_array_pin() Dong Jia Shi
@ 2018-05-23  2:56 ` Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 3/4] vfio: ccw: set ccw->cda to NULL defensively Dong Jia Shi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Dong Jia Shi @ 2018-05-23  2:56 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: cohuck, borntraeger, bjsdjshi, pasic, pmorel

This refactors pfn_array_alloc_pin() and also improves it by adding
defensive code in error handling so that calling pfn_array_unpin_free()
after error return won't lead to problem. This mainly does:
1. Merge pfn_array_pin() into pfn_array_alloc_pin(), since there is no
   other user of pfn_array_pin(). As a result, also remove kernel-doc
   for pfn_array_pin() and add/update kernel-doc for pfn_array_alloc_pin()
   and struct pfn_array.
2. For a vfio_pin_pages() failure, set pa->pa_nr to zero to indicate
   zero pages were pinned.
3. Set pa->pa_iova_pfn to NULL right after it was freed.

Suggested-by: Pierre Morel <pmorel@linux.ibm.com>,
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.ibm.com>
---
 drivers/s390/cio/vfio_ccw_cp.c | 82 +++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 46 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
index b38ef387e4f0..262f969b3b33 100644
--- a/drivers/s390/cio/vfio_ccw_cp.c
+++ b/drivers/s390/cio/vfio_ccw_cp.c
@@ -29,7 +29,7 @@ struct pfn_array {
 	unsigned long		*pa_iova_pfn;
 	/* Array that receives PFNs of the pages pinned. */
 	unsigned long		*pa_pfn;
-	/* Number of pages to pin/pinned from @pa_iova. */
+	/* Number of pages pinned from @pa_iova. */
 	int			pa_nr;
 };
 
@@ -50,64 +50,33 @@ struct ccwchain {
 };
 
 /*
- * pfn_array_pin() - pin user pages in memory
+ * pfn_array_alloc_pin() - alloc memory for PFNs, then pin user pages in memory
  * @pa: pfn_array on which to perform the operation
  * @mdev: the mediated device to perform pin/unpin operations
+ * @iova: target guest physical address
+ * @len: number of bytes that should be pinned from @iova
  *
- * Attempt to pin user pages in memory.
+ * Attempt to allocate memory for PFNs, and pin user pages in memory.
  *
  * Usage of pfn_array:
- * Any field in this structure should be initialized by caller.
- * We expect @pa->pa_nr > 0, and its value will be assigned by callee.
+ * We expect (pa_nr == 0) and (pa_iova_pfn == NULL), any field in
+ * this structure will be filled in by this function.
  *
  * Returns:
  *   Number of pages pinned on success.
- *   If @pa->pa_nr is 0 or negative, returns 0.
+ *   If @pa->pa_nr is not 0, or @pa->pa_iova_pfn is not NULL initially,
+ *   returns -EINVAL.
  *   If no pages were pinned, returns -errno.
  */
-static int pfn_array_pin(struct pfn_array *pa, struct device *mdev)
-{
-	int i, ret;
-
-	if (pa->pa_nr <= 0) {
-		pa->pa_nr = 0;
-		return 0;
-	}
-
-	pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT;
-	for (i = 1; i < pa->pa_nr; i++)
-		pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1;
-
-	ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr,
-			     IOMMU_READ | IOMMU_WRITE, pa->pa_pfn);
-
-	if (ret > 0 && ret != pa->pa_nr) {
-		vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret);
-		pa->pa_nr = 0;
-		return 0;
-	}
-
-	return ret;
-}
-
-/* Unpin the pages before releasing the memory. */
-static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev)
-{
-	vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr);
-	pa->pa_nr = 0;
-	kfree(pa->pa_iova_pfn);
-}
-
-/* Alloc memory for PFNs, then pin pages with them. */
 static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev,
 			       u64 iova, unsigned int len)
 {
-	int ret = 0;
+	int i, ret = 0;
 
 	if (!len)
 		return 0;
 
-	if (pa->pa_nr)
+	if (pa->pa_nr || pa->pa_iova_pfn)
 		return -EINVAL;
 
 	pa->pa_iova = iova;
@@ -124,18 +93,39 @@ static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev,
 		return -ENOMEM;
 	pa->pa_pfn = pa->pa_iova_pfn + pa->pa_nr;
 
-	ret = pfn_array_pin(pa, mdev);
+	pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT;
+	for (i = 1; i < pa->pa_nr; i++)
+		pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1;
+
+	ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr,
+			     IOMMU_READ | IOMMU_WRITE, pa->pa_pfn);
 
-	if (ret > 0)
-		return ret;
-	else if (!ret)
+	if (ret < 0) {
+		goto err_out;
+	} else if (ret > 0 && ret != pa->pa_nr) {
+		vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret);
 		ret = -EINVAL;
+		goto err_out;
+	}
+
+	return ret;
 
+err_out:
+	pa->pa_nr = 0;
 	kfree(pa->pa_iova_pfn);
+	pa->pa_iova_pfn = NULL;
 
 	return ret;
 }
 
+/* Unpin the pages before releasing the memory. */
+static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev)
+{
+	vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr);
+	pa->pa_nr = 0;
+	kfree(pa->pa_iova_pfn);
+}
+
 static int pfn_array_table_init(struct pfn_array_table *pat, int nr)
 {
 	pat->pat_pa = kcalloc(nr, sizeof(*pat->pat_pa), GFP_KERNEL);
-- 
2.16.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 3/4] vfio: ccw: set ccw->cda to NULL defensively
  2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 1/4] vfio: ccw: shorten kernel doc description for pfn_array_pin() Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 2/4] vfio: ccw: refactor and improve pfn_array_alloc_pin() Dong Jia Shi
@ 2018-05-23  2:56 ` Dong Jia Shi
  2018-05-23  2:56 ` [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths Dong Jia Shi
  2018-05-23 10:21 ` [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Cornelia Huck
  4 siblings, 0 replies; 8+ messages in thread
From: Dong Jia Shi @ 2018-05-23  2:56 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: cohuck, borntraeger, bjsdjshi, pasic, pmorel

Let's avoid free on ccw->cda that points to a guest address
or an already freed memory area by setting it to NULL if memory
allocation didn't happen or failed.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.ibm.com>
---
 drivers/s390/cio/vfio_ccw_cp.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
index 262f969b3b33..63c3df1c2ff2 100644
--- a/drivers/s390/cio/vfio_ccw_cp.c
+++ b/drivers/s390/cio/vfio_ccw_cp.c
@@ -491,7 +491,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
 	struct ccw1 *ccw;
 	struct pfn_array_table *pat;
 	unsigned long *idaws;
-	int idaw_nr;
+	int ret;
 
 	ccw = chain->ch_ccw + idx;
 
@@ -511,18 +511,19 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
 	 * needed when translating a direct ccw to a idal ccw.
 	 */
 	pat = chain->ch_pat + idx;
-	if (pfn_array_table_init(pat, 1))
-		return -ENOMEM;
-	idaw_nr = pfn_array_alloc_pin(pat->pat_pa, cp->mdev,
-				      ccw->cda, ccw->count);
-	if (idaw_nr < 0)
-		return idaw_nr;
+	ret = pfn_array_table_init(pat, 1);
+	if (ret)
+		goto out_init;
+
+	ret = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, ccw->cda, ccw->count);
+	if (ret < 0)
+		goto out_init;
 
 	/* Translate this direct ccw to a idal ccw. */
-	idaws = kcalloc(idaw_nr, sizeof(*idaws), GFP_DMA | GFP_KERNEL);
+	idaws = kcalloc(ret, sizeof(*idaws), GFP_DMA | GFP_KERNEL);
 	if (!idaws) {
-		pfn_array_table_unpin_free(pat, cp->mdev);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_unpin;
 	}
 	ccw->cda = (__u32) virt_to_phys(idaws);
 	ccw->flags |= CCW_FLAG_IDA;
@@ -530,6 +531,12 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
 	pfn_array_table_idal_create_words(pat, idaws);
 
 	return 0;
+
+out_unpin:
+	pfn_array_table_unpin_free(pat, cp->mdev);
+out_init:
+	ccw->cda = 0;
+	return ret;
 }
 
 static int ccwchain_fetch_idal(struct ccwchain *chain,
@@ -559,7 +566,7 @@ static int ccwchain_fetch_idal(struct ccwchain *chain,
 	pat = chain->ch_pat + idx;
 	ret = pfn_array_table_init(pat, idaw_nr);
 	if (ret)
-		return ret;
+		goto out_init;
 
 	/* Translate idal ccw to use new allocated idaws. */
 	idaws = kzalloc(idaw_len, GFP_DMA | GFP_KERNEL);
@@ -591,6 +598,8 @@ static int ccwchain_fetch_idal(struct ccwchain *chain,
 	kfree(idaws);
 out_unpin:
 	pfn_array_table_unpin_free(pat, cp->mdev);
+out_init:
+	ccw->cda = 0;
 	return ret;
 }
 
-- 
2.16.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths
  2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
                   ` (2 preceding siblings ...)
  2018-05-23  2:56 ` [PATCH v4 3/4] vfio: ccw: set ccw->cda to NULL defensively Dong Jia Shi
@ 2018-05-23  2:56 ` Dong Jia Shi
  2018-05-23 10:25   ` Cornelia Huck
  2018-05-23 10:21 ` [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Cornelia Huck
  4 siblings, 1 reply; 8+ messages in thread
From: Dong Jia Shi @ 2018-05-23  2:56 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: cohuck, borntraeger, bjsdjshi, pasic, pmorel

From: Halil Pasic <pasic@linux.ibm.com>

Add some tracepoints so we can inspect what is not working as is should.

Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.ibm.com>
---
 drivers/s390/cio/Makefile         |  1 +
 drivers/s390/cio/vfio_ccw_fsm.c   | 17 +++++++++++-
 drivers/s390/cio/vfio_ccw_trace.h | 54 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 drivers/s390/cio/vfio_ccw_trace.h

diff --git a/drivers/s390/cio/Makefile b/drivers/s390/cio/Makefile
index a070ef0efe65..f230516abb96 100644
--- a/drivers/s390/cio/Makefile
+++ b/drivers/s390/cio/Makefile
@@ -5,6 +5,7 @@
 
 # The following is required for define_trace.h to find ./trace.h
 CFLAGS_trace.o := -I$(src)
+CFLAGS_vfio_ccw_fsm.o := -I$(src)
 
 obj-y += airq.o blacklist.o chsc.o cio.o css.o chp.o idset.o isc.o \
 	fcx.o itcw.o crw.o ccwreq.o trace.o ioasm.o
diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
index 3c800642134e..797a82731159 100644
--- a/drivers/s390/cio/vfio_ccw_fsm.c
+++ b/drivers/s390/cio/vfio_ccw_fsm.c
@@ -13,6 +13,9 @@
 #include "ioasm.h"
 #include "vfio_ccw_private.h"
 
+#define CREATE_TRACE_POINTS
+#include "vfio_ccw_trace.h"
+
 static int fsm_io_helper(struct vfio_ccw_private *private)
 {
 	struct subchannel *sch;
@@ -110,6 +113,10 @@ static void fsm_disabled_irq(struct vfio_ccw_private *private,
 	 */
 	cio_disable_subchannel(sch);
 }
+inline struct subchannel_id get_schid(struct vfio_ccw_private *p)
+{
+	return p->sch->schid;
+}
 
 /*
  * Deal with the ccw command request from the userspace.
@@ -121,6 +128,7 @@ static void fsm_io_request(struct vfio_ccw_private *private,
 	union scsw *scsw = &private->scsw;
 	struct ccw_io_region *io_region = &private->io_region;
 	struct mdev_device *mdev = private->mdev;
+	char *errstr = "request";
 
 	private->state = VFIO_CCW_STATE_BOXED;
 
@@ -132,15 +140,19 @@ static void fsm_io_request(struct vfio_ccw_private *private,
 		/* Don't try to build a cp if transport mode is specified. */
 		if (orb->tm.b) {
 			io_region->ret_code = -EOPNOTSUPP;
+			errstr = "transport mode";
 			goto err_out;
 		}
 		io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev),
 					      orb);
-		if (io_region->ret_code)
+		if (io_region->ret_code) {
+			errstr = "cp init";
 			goto err_out;
+		}
 
 		io_region->ret_code = cp_prefetch(&private->cp);
 		if (io_region->ret_code) {
+			errstr = "cp prefetch";
 			cp_free(&private->cp);
 			goto err_out;
 		}
@@ -148,6 +160,7 @@ static void fsm_io_request(struct vfio_ccw_private *private,
 		/* Start channel program and wait for I/O interrupt. */
 		io_region->ret_code = fsm_io_helper(private);
 		if (io_region->ret_code) {
+			errstr = "cp fsm_io_helper";
 			cp_free(&private->cp);
 			goto err_out;
 		}
@@ -164,6 +177,8 @@ static void fsm_io_request(struct vfio_ccw_private *private,
 
 err_out:
 	private->state = VFIO_CCW_STATE_IDLE;
+	trace_vfio_ccw_io_fctl(scsw->cmd.fctl, get_schid(private),
+			       io_region->ret_code, errstr);
 }
 
 /*
diff --git a/drivers/s390/cio/vfio_ccw_trace.h b/drivers/s390/cio/vfio_ccw_trace.h
new file mode 100644
index 000000000000..b1da53ddec1f
--- /dev/null
+++ b/drivers/s390/cio/vfio_ccw_trace.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Tracepoints for vfio_ccw driver
+ *
+ * Copyright IBM Corp. 2018
+ *
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Halil Pasic <pasic@linux.vnet.ibm.com>
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM vfio_ccw
+
+#if !defined(_VFIO_CCW_TRACE_) || defined(TRACE_HEADER_MULTI_READ)
+#define _VFIO_CCW_TRACE_
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(vfio_ccw_io_fctl,
+	TP_PROTO(int fctl, struct subchannel_id schid, int errno, char *errstr),
+	TP_ARGS(fctl, schid, errno, errstr),
+
+	TP_STRUCT__entry(
+		__field(int, fctl)
+		__field_struct(struct subchannel_id, schid)
+		__field(int, errno)
+		__field(char*, errstr)
+	),
+
+	TP_fast_assign(
+		__entry->fctl = fctl;
+		__entry->schid = schid;
+		__entry->errno = errno;
+		__entry->errstr = errstr;
+	),
+
+	TP_printk("schid=%x.%x.%04x fctl=%x errno=%d info=%s",
+		  __entry->schid.cssid,
+		  __entry->schid.ssid,
+		  __entry->schid.sch_no,
+		  __entry->fctl,
+		  __entry->errno,
+		  __entry->errstr)
+);
+
+#endif /* _VFIO_CCW_TRACE_ */
+
+/* This part must be outside protection */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE vfio_ccw_trace
+
+#include <trace/define_trace.h>
-- 
2.16.3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements
  2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
                   ` (3 preceding siblings ...)
  2018-05-23  2:56 ` [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths Dong Jia Shi
@ 2018-05-23 10:21 ` Cornelia Huck
  2018-05-24 14:29   ` Cornelia Huck
  4 siblings, 1 reply; 8+ messages in thread
From: Cornelia Huck @ 2018-05-23 10:21 UTC (permalink / raw)
  To: Dong Jia Shi; +Cc: linux-kernel, linux-s390, kvm, borntraeger, pasic, pmorel

On Wed, 23 May 2018 04:56:41 +0200
Dong Jia Shi <bjsdjshi@linux.ibm.com> wrote:

> Dear Reviewers,
> 
> Here is a new version for this patch series.
> 
> We didn't get agreement on patch #4 (#5 in v2) in the former cycle though,
> I made it based on my understanding. We can continue discussing on it.

I'll probably go ahead and queue 1-3 (would not mind r-bs, though) in
any case.

I hope we can queue the tracing patch as well, as any tracing beats no
tracing :)

> 
> Changelog:
> v3->v4:
>  - Change mail address from @linux.vnet.ibm.com to @linux.ibm.com
> 
> v2->v3:
>  - #2. Reworded comment message.
>  - #4. Trace failure only, trace all error path, and a common knob for all
>        failure paths.
> 
> v1->v2:
>  - #1. Reworded commit message and comment, plus some typo fixes.
>  - #2. New patch.
>  - #3. Added the missing suggested-by Pierre.
>        Fixed typos.
>        Added sanity check on pa->pa_iova_pfn and updated comments accordingly.
>  - #4. Removed unused idaw_nr.
>  - #5. Replaced leading white spaces with TABs.
>        Traced the function in anycase.
> 
> Dong Jia Shi (3):
>   vfio: ccw: shorten kernel doc description for pfn_array_pin()
>   vfio: ccw: refactor and improve pfn_array_alloc_pin()
>   vfio: ccw: set ccw->cda to NULL defensively
> 
> Halil Pasic (1):
>   vfio: ccw: add traceponits for interesting error paths
> 
>  drivers/s390/cio/Makefile         |   1 +
>  drivers/s390/cio/vfio_ccw_cp.c    | 121 +++++++++++++++++++-------------------
>  drivers/s390/cio/vfio_ccw_fsm.c   |  17 +++++-
>  drivers/s390/cio/vfio_ccw_trace.h |  54 +++++++++++++++++
>  4 files changed, 130 insertions(+), 63 deletions(-)
>  create mode 100644 drivers/s390/cio/vfio_ccw_trace.h
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths
  2018-05-23  2:56 ` [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths Dong Jia Shi
@ 2018-05-23 10:25   ` Cornelia Huck
  0 siblings, 0 replies; 8+ messages in thread
From: Cornelia Huck @ 2018-05-23 10:25 UTC (permalink / raw)
  To: Dong Jia Shi; +Cc: linux-kernel, linux-s390, kvm, borntraeger, pasic, pmorel

On Wed, 23 May 2018 04:56:45 +0200
Dong Jia Shi <bjsdjshi@linux.ibm.com> wrote:

Still s/traceponits/tracepoints/ (can fix up when applying).

> From: Halil Pasic <pasic@linux.ibm.com>
> 
> Add some tracepoints so we can inspect what is not working as is should.
> 
> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
> Signed-off-by: Dong Jia Shi <bjsdjshi@linux.ibm.com>
> ---
>  drivers/s390/cio/Makefile         |  1 +
>  drivers/s390/cio/vfio_ccw_fsm.c   | 17 +++++++++++-
>  drivers/s390/cio/vfio_ccw_trace.h | 54 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 71 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/s390/cio/vfio_ccw_trace.h
> 
> diff --git a/drivers/s390/cio/Makefile b/drivers/s390/cio/Makefile
> index a070ef0efe65..f230516abb96 100644
> --- a/drivers/s390/cio/Makefile
> +++ b/drivers/s390/cio/Makefile
> @@ -5,6 +5,7 @@
>  
>  # The following is required for define_trace.h to find ./trace.h
>  CFLAGS_trace.o := -I$(src)
> +CFLAGS_vfio_ccw_fsm.o := -I$(src)
>  
>  obj-y += airq.o blacklist.o chsc.o cio.o css.o chp.o idset.o isc.o \
>  	fcx.o itcw.o crw.o ccwreq.o trace.o ioasm.o
> diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
> index 3c800642134e..797a82731159 100644
> --- a/drivers/s390/cio/vfio_ccw_fsm.c
> +++ b/drivers/s390/cio/vfio_ccw_fsm.c
> @@ -13,6 +13,9 @@
>  #include "ioasm.h"
>  #include "vfio_ccw_private.h"
>  
> +#define CREATE_TRACE_POINTS
> +#include "vfio_ccw_trace.h"
> +
>  static int fsm_io_helper(struct vfio_ccw_private *private)
>  {
>  	struct subchannel *sch;
> @@ -110,6 +113,10 @@ static void fsm_disabled_irq(struct vfio_ccw_private *private,
>  	 */
>  	cio_disable_subchannel(sch);
>  }
> +inline struct subchannel_id get_schid(struct vfio_ccw_private *p)
> +{
> +	return p->sch->schid;
> +}
>  
>  /*
>   * Deal with the ccw command request from the userspace.
> @@ -121,6 +128,7 @@ static void fsm_io_request(struct vfio_ccw_private *private,
>  	union scsw *scsw = &private->scsw;
>  	struct ccw_io_region *io_region = &private->io_region;
>  	struct mdev_device *mdev = private->mdev;
> +	char *errstr = "request";
>  
>  	private->state = VFIO_CCW_STATE_BOXED;
>  
> @@ -132,15 +140,19 @@ static void fsm_io_request(struct vfio_ccw_private *private,
>  		/* Don't try to build a cp if transport mode is specified. */
>  		if (orb->tm.b) {
>  			io_region->ret_code = -EOPNOTSUPP;
> +			errstr = "transport mode";
>  			goto err_out;
>  		}
>  		io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev),
>  					      orb);
> -		if (io_region->ret_code)
> +		if (io_region->ret_code) {
> +			errstr = "cp init";
>  			goto err_out;
> +		}
>  
>  		io_region->ret_code = cp_prefetch(&private->cp);
>  		if (io_region->ret_code) {
> +			errstr = "cp prefetch";
>  			cp_free(&private->cp);
>  			goto err_out;
>  		}
> @@ -148,6 +160,7 @@ static void fsm_io_request(struct vfio_ccw_private *private,
>  		/* Start channel program and wait for I/O interrupt. */
>  		io_region->ret_code = fsm_io_helper(private);
>  		if (io_region->ret_code) {
> +			errstr = "cp fsm_io_helper";
>  			cp_free(&private->cp);
>  			goto err_out;
>  		}
> @@ -164,6 +177,8 @@ static void fsm_io_request(struct vfio_ccw_private *private,
>  
>  err_out:
>  	private->state = VFIO_CCW_STATE_IDLE;
> +	trace_vfio_ccw_io_fctl(scsw->cmd.fctl, get_schid(private),
> +			       io_region->ret_code, errstr);
>  }
>  
>  /*

This approach looks reasonable to me. We can still improve this later,
should we want to.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements
  2018-05-23 10:21 ` [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Cornelia Huck
@ 2018-05-24 14:29   ` Cornelia Huck
  0 siblings, 0 replies; 8+ messages in thread
From: Cornelia Huck @ 2018-05-24 14:29 UTC (permalink / raw)
  To: Dong Jia Shi; +Cc: linux-kernel, linux-s390, kvm, borntraeger, pasic, pmorel

On Wed, 23 May 2018 12:21:29 +0200
Cornelia Huck <cohuck@redhat.com> wrote:

> On Wed, 23 May 2018 04:56:41 +0200
> Dong Jia Shi <bjsdjshi@linux.ibm.com> wrote:
> 
> > Dear Reviewers,
> > 
> > Here is a new version for this patch series.
> > 
> > We didn't get agreement on patch #4 (#5 in v2) in the former cycle though,
> > I made it based on my understanding. We can continue discussing on it.  
> 
> I'll probably go ahead and queue 1-3 (would not mind r-bs, though) in
> any case.
> 
> I hope we can queue the tracing patch as well, as any tracing beats no
> tracing :)

OK, I've pushed this out to the vfio-ccw branch.

Would still be great to get some R-bs.

What about sending a pull req next week, so that we get this ready for
the 4.18 merge window?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-24 14:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-23  2:56 [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Dong Jia Shi
2018-05-23  2:56 ` [PATCH v4 1/4] vfio: ccw: shorten kernel doc description for pfn_array_pin() Dong Jia Shi
2018-05-23  2:56 ` [PATCH v4 2/4] vfio: ccw: refactor and improve pfn_array_alloc_pin() Dong Jia Shi
2018-05-23  2:56 ` [PATCH v4 3/4] vfio: ccw: set ccw->cda to NULL defensively Dong Jia Shi
2018-05-23  2:56 ` [PATCH v4 4/4] vfio: ccw: add traceponits for interesting error paths Dong Jia Shi
2018-05-23 10:25   ` Cornelia Huck
2018-05-23 10:21 ` [PATCH v4 0/4] vfio: ccw: error handling fixes and improvements Cornelia Huck
2018-05-24 14:29   ` Cornelia Huck

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).