Netdev List
 help / color / mirror / Atom feed
* [RESEND PATCH 4/7] mm/gup: Add FOLL_LONGTERM capability to GUP fast
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel
In-Reply-To: <20190220053040.10831-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

DAX pages were previously unprotected from longterm pins when users
called get_user_pages_fast().

Use the new FOLL_LONGTERM flag to check for DEVMAP pages and fall
back to regular GUP processing if a DEVMAP page is encountered.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 mm/gup.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 6f32d36b3c5b..f7e759c523bb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1439,6 +1439,9 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
 			goto pte_unmap;
 
 		if (pte_devmap(pte)) {
+			if (unlikely(flags & FOLL_LONGTERM))
+				goto pte_unmap;
+
 			pgmap = get_dev_pagemap(pte_pfn(pte), pgmap);
 			if (unlikely(!pgmap)) {
 				undo_dev_pagemap(nr, nr_start, pages);
@@ -1578,8 +1581,11 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
 	if (!pmd_access_permitted(orig, flags & FOLL_WRITE))
 		return 0;
 
-	if (pmd_devmap(orig))
+	if (pmd_devmap(orig)) {
+		if (unlikely(flags & FOLL_LONGTERM))
+			return 0;
 		return __gup_device_huge_pmd(orig, pmdp, addr, end, pages, nr);
+	}
 
 	refs = 0;
 	page = pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
@@ -1904,8 +1910,20 @@ int get_user_pages_fast(unsigned long start, int nr_pages,
 		start += nr << PAGE_SHIFT;
 		pages += nr;
 
-		ret = get_user_pages_unlocked(start, nr_pages - nr, pages,
-					      gup_flags);
+		if (gup_flags & FOLL_LONGTERM) {
+			down_read(&current->mm->mmap_sem);
+			ret = __gup_longterm_locked(current, current->mm,
+						    start, nr_pages - nr,
+						    pages, NULL, gup_flags);
+			up_read(&current->mm->mmap_sem);
+		} else {
+			/*
+			 * retain FAULT_FOLL_ALLOW_RETRY optimization if
+			 * possible
+			 */
+			ret = get_user_pages_unlocked(start, nr_pages - nr,
+						      pages, gup_flags);
+		}
 
 		/* Have to be a bit careful with return values */
 		if (nr > 0) {
-- 
2.20.1


^ permalink raw reply related

* [RESEND PATCH 7/7] IB/mthca: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel
In-Reply-To: <20190220053040.10831-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

Use the new FOLL_LONGTERM to get_user_pages_fast() to protect against
FS DAX pages being mapped.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 112d2f38e0de..8ff0e90d7564 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -472,7 +472,8 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
 		goto out;
 	}
 
-	ret = get_user_pages_fast(uaddr & PAGE_MASK, 1, FOLL_WRITE, pages);
+	ret = get_user_pages_fast(uaddr & PAGE_MASK, 1,
+				  FOLL_WRITE | FOLL_LONGTERM, pages);
 	if (ret < 0)
 		goto out;
 
-- 
2.20.1


^ permalink raw reply related

* [RESEND PATCH 0/7] Add FOLL_LONGTERM to GUP fast and use it
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel

From: Ira Weiny <ira.weiny@intel.com>

Resending these as I had only 1 minor comment which I believe we have covered
in this series.  I was anticipating these going through the mm tree as they
depend on a cleanup patch there and the IB changes are very minor.  But they
could just as well go through the IB tree.

NOTE: This series depends on my clean up patch to remove the write parameter
from gup_fast_permitted()[1]

HFI1, qib, and mthca, use get_user_pages_fast() due to it performance
advantages.  These pages can be held for a significant time.  But
get_user_pages_fast() does not protect against mapping of FS DAX pages.

Introduce FOLL_LONGTERM and use this flag in get_user_pages_fast() which
retains the performance while also adding the FS DAX checks.  XDP has also
shown interest in using this functionality.[2]

In addition we change get_user_pages() to use the new FOLL_LONGTERM flag and
remove the specialized get_user_pages_longterm call.

[1] https://lkml.org/lkml/2019/2/11/237
[2] https://lkml.org/lkml/2019/2/11/1789

Ira Weiny (7):
  mm/gup: Replace get_user_pages_longterm() with FOLL_LONGTERM
  mm/gup: Change write parameter to flags in fast walk
  mm/gup: Change GUP fast to use flags rather than a write 'bool'
  mm/gup: Add FOLL_LONGTERM capability to GUP fast
  IB/hfi1: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
  IB/qib: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
  IB/mthca: Use the new FOLL_LONGTERM flag to get_user_pages_fast()

 arch/mips/mm/gup.c                          |  11 +-
 arch/powerpc/kvm/book3s_64_mmu_hv.c         |   4 +-
 arch/powerpc/kvm/e500_mmu.c                 |   2 +-
 arch/powerpc/mm/mmu_context_iommu.c         |   4 +-
 arch/s390/kvm/interrupt.c                   |   2 +-
 arch/s390/mm/gup.c                          |  12 +-
 arch/sh/mm/gup.c                            |  11 +-
 arch/sparc/mm/gup.c                         |   9 +-
 arch/x86/kvm/paging_tmpl.h                  |   2 +-
 arch/x86/kvm/svm.c                          |   2 +-
 drivers/fpga/dfl-afu-dma-region.c           |   2 +-
 drivers/gpu/drm/via/via_dmablit.c           |   3 +-
 drivers/infiniband/core/umem.c              |   5 +-
 drivers/infiniband/hw/hfi1/user_pages.c     |   5 +-
 drivers/infiniband/hw/mthca/mthca_memfree.c |   3 +-
 drivers/infiniband/hw/qib/qib_user_pages.c  |   8 +-
 drivers/infiniband/hw/qib/qib_user_sdma.c   |   2 +-
 drivers/infiniband/hw/usnic/usnic_uiom.c    |   9 +-
 drivers/media/v4l2-core/videobuf-dma-sg.c   |   6 +-
 drivers/misc/genwqe/card_utils.c            |   2 +-
 drivers/misc/vmw_vmci/vmci_host.c           |   2 +-
 drivers/misc/vmw_vmci/vmci_queue_pair.c     |   6 +-
 drivers/platform/goldfish/goldfish_pipe.c   |   3 +-
 drivers/rapidio/devices/rio_mport_cdev.c    |   4 +-
 drivers/sbus/char/oradax.c                  |   2 +-
 drivers/scsi/st.c                           |   3 +-
 drivers/staging/gasket/gasket_page_table.c  |   4 +-
 drivers/tee/tee_shm.c                       |   2 +-
 drivers/vfio/vfio_iommu_spapr_tce.c         |   3 +-
 drivers/vfio/vfio_iommu_type1.c             |   3 +-
 drivers/vhost/vhost.c                       |   2 +-
 drivers/video/fbdev/pvr2fb.c                |   2 +-
 drivers/virt/fsl_hypervisor.c               |   2 +-
 drivers/xen/gntdev.c                        |   2 +-
 fs/orangefs/orangefs-bufmap.c               |   2 +-
 include/linux/mm.h                          |  17 +-
 kernel/futex.c                              |   2 +-
 lib/iov_iter.c                              |   7 +-
 mm/gup.c                                    | 220 ++++++++++++--------
 mm/gup_benchmark.c                          |   5 +-
 mm/util.c                                   |   8 +-
 net/ceph/pagevec.c                          |   2 +-
 net/rds/info.c                              |   2 +-
 net/rds/rdma.c                              |   3 +-
 44 files changed, 232 insertions(+), 180 deletions(-)

-- 
2.20.1


^ permalink raw reply

* [RESEND PATCH 1/7] mm/gup: Replace get_user_pages_longterm() with FOLL_LONGTERM
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel
In-Reply-To: <20190220053040.10831-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

Rather than have a separate get_user_pages_longterm() call,
introduce FOLL_LONGTERM and change the longterm callers to use
it.

This patch does not change any functionality.

FOLL_LONGTERM can only be supported with get_user_pages() as it
requires vmas to determine if DAX is in use.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 drivers/infiniband/core/umem.c             |   5 +-
 drivers/infiniband/hw/qib/qib_user_pages.c |   8 +-
 drivers/infiniband/hw/usnic/usnic_uiom.c   |   9 +-
 drivers/media/v4l2-core/videobuf-dma-sg.c  |   6 +-
 drivers/vfio/vfio_iommu_type1.c            |   3 +-
 include/linux/mm.h                         |  13 +-
 mm/gup.c                                   | 138 ++++++++++++---------
 mm/gup_benchmark.c                         |   5 +-
 8 files changed, 101 insertions(+), 86 deletions(-)

diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index b69d3efa8712..120a40df91b4 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -185,10 +185,11 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
 
 	while (npages) {
 		down_read(&mm->mmap_sem);
-		ret = get_user_pages_longterm(cur_base,
+		ret = get_user_pages(cur_base,
 				     min_t(unsigned long, npages,
 					   PAGE_SIZE / sizeof (struct page *)),
-				     gup_flags, page_list, vma_list);
+				     gup_flags | FOLL_LONGTERM,
+				     page_list, vma_list);
 		if (ret < 0) {
 			up_read(&mm->mmap_sem);
 			goto umem_release;
diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c
index ef8bcf366ddc..1b9368261035 100644
--- a/drivers/infiniband/hw/qib/qib_user_pages.c
+++ b/drivers/infiniband/hw/qib/qib_user_pages.c
@@ -114,10 +114,10 @@ int qib_get_user_pages(unsigned long start_page, size_t num_pages,
 
 	down_read(&current->mm->mmap_sem);
 	for (got = 0; got < num_pages; got += ret) {
-		ret = get_user_pages_longterm(start_page + got * PAGE_SIZE,
-					      num_pages - got,
-					      FOLL_WRITE | FOLL_FORCE,
-					      p + got, NULL);
+		ret = get_user_pages(start_page + got * PAGE_SIZE,
+				     num_pages - got,
+				     FOLL_LONGTERM | FOLL_WRITE | FOLL_FORCE,
+				     p + got, NULL);
 		if (ret < 0) {
 			up_read(&current->mm->mmap_sem);
 			goto bail_release;
diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c
index 06862a6af185..1d9a182ac163 100644
--- a/drivers/infiniband/hw/usnic/usnic_uiom.c
+++ b/drivers/infiniband/hw/usnic/usnic_uiom.c
@@ -143,10 +143,11 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
 	ret = 0;
 
 	while (npages) {
-		ret = get_user_pages_longterm(cur_base,
-					min_t(unsigned long, npages,
-					PAGE_SIZE / sizeof(struct page *)),
-					gup_flags, page_list, NULL);
+		ret = get_user_pages(cur_base,
+				     min_t(unsigned long, npages,
+				     PAGE_SIZE / sizeof(struct page *)),
+				     gup_flags | FOLL_LONGTERM,
+				     page_list, NULL);
 
 		if (ret < 0)
 			goto out;
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index 08929c087e27..870a2a526e0b 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -186,12 +186,12 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
 	dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
 		data, size, dma->nr_pages);
 
-	err = get_user_pages_longterm(data & PAGE_MASK, dma->nr_pages,
-			     flags, dma->pages, NULL);
+	err = get_user_pages(data & PAGE_MASK, dma->nr_pages,
+			     flags | FOLL_LONGTERM, dma->pages, NULL);
 
 	if (err != dma->nr_pages) {
 		dma->nr_pages = (err >= 0) ? err : 0;
-		dprintk(1, "get_user_pages_longterm: err=%d [%d]\n", err,
+		dprintk(1, "get_user_pages: err=%d [%d]\n", err,
 			dma->nr_pages);
 		return err < 0 ? err : -EINVAL;
 	}
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 73652e21efec..1500bd0bb6da 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -351,7 +351,8 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
 
 	down_read(&mm->mmap_sem);
 	if (mm == current->mm) {
-		ret = get_user_pages_longterm(vaddr, 1, flags, page, vmas);
+		ret = get_user_pages(vaddr, 1, flags | FOLL_LONGTERM, page,
+				     vmas);
 	} else {
 		ret = get_user_pages_remote(NULL, mm, vaddr, 1, flags, page,
 					    vmas, NULL);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 80bb6408fe73..05a105d9d4c3 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1536,18 +1536,6 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
 		    unsigned int gup_flags, struct page **pages, int *locked);
 long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
 		    struct page **pages, unsigned int gup_flags);
-#ifdef CONFIG_FS_DAX
-long get_user_pages_longterm(unsigned long start, unsigned long nr_pages,
-			    unsigned int gup_flags, struct page **pages,
-			    struct vm_area_struct **vmas);
-#else
-static inline long get_user_pages_longterm(unsigned long start,
-		unsigned long nr_pages, unsigned int gup_flags,
-		struct page **pages, struct vm_area_struct **vmas)
-{
-	return get_user_pages(start, nr_pages, gup_flags, pages, vmas);
-}
-#endif /* CONFIG_FS_DAX */
 
 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 			struct page **pages);
@@ -2615,6 +2603,7 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
 #define FOLL_REMOTE	0x2000	/* we are working on non-current tsk/mm */
 #define FOLL_COW	0x4000	/* internal GUP flag */
 #define FOLL_ANON	0x8000	/* don't do file mappings */
+#define FOLL_LONGTERM	0x10000	/* mapping is intended for a long term pin */
 
 static inline int vm_fault_to_errno(vm_fault_t vm_fault, int foll_flags)
 {
diff --git a/mm/gup.c b/mm/gup.c
index b63e88eca31b..ee96eaff118c 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1109,87 +1109,109 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
 }
 EXPORT_SYMBOL(get_user_pages_remote);
 
-/*
- * This is the same as get_user_pages_remote(), just with a
- * less-flexible calling convention where we assume that the task
- * and mm being operated on are the current task's and don't allow
- * passing of a locked parameter.  We also obviously don't pass
- * FOLL_REMOTE in here.
- */
-long get_user_pages(unsigned long start, unsigned long nr_pages,
-		unsigned int gup_flags, struct page **pages,
-		struct vm_area_struct **vmas)
-{
-	return __get_user_pages_locked(current, current->mm, start, nr_pages,
-				       pages, vmas, NULL,
-				       gup_flags | FOLL_TOUCH);
-}
-EXPORT_SYMBOL(get_user_pages);
-
 #ifdef CONFIG_FS_DAX
 /*
- * This is the same as get_user_pages() in that it assumes we are
- * operating on the current task's mm, but it goes further to validate
- * that the vmas associated with the address range are suitable for
- * longterm elevated page reference counts. For example, filesystem-dax
- * mappings are subject to the lifetime enforced by the filesystem and
- * we need guarantees that longterm users like RDMA and V4L2 only
- * establish mappings that have a kernel enforced revocation mechanism.
+ * __gup_longterm_locked() is a wrapper for __get_uer_pages_locked which
+ * allows us to process the FOLL_LONGTERM flag if present.
+ *
+ * __gup_longterm_locked() validates that the vmas associated with the address
+ * range are suitable for longterm elevated page reference counts. For example,
+ * filesystem-dax mappings are subject to the lifetime enforced by the
+ * filesystem and we need guarantees that longterm users like RDMA and V4L2
+ * only establish mappings that have a kernel enforced revocation mechanism.
  *
  * "longterm" == userspace controlled elevated page count lifetime.
  * Contrast this to iov_iter_get_pages() usages which are transient.
  */
-long get_user_pages_longterm(unsigned long start, unsigned long nr_pages,
-		unsigned int gup_flags, struct page **pages,
-		struct vm_area_struct **vmas_arg)
+static __always_inline long __gup_longterm_locked(struct task_struct *tsk,
+						  struct mm_struct *mm,
+						  unsigned long start,
+						  unsigned long nr_pages,
+						  struct page **pages,
+						  struct vm_area_struct **vmas,
+						  unsigned int flags)
 {
-	struct vm_area_struct **vmas = vmas_arg;
+	struct vm_area_struct **vmas_tmp = vmas;
 	struct vm_area_struct *vma_prev = NULL;
 	long rc, i;
 
-	if (!pages)
-		return -EINVAL;
-
-	if (!vmas) {
-		vmas = kcalloc(nr_pages, sizeof(struct vm_area_struct *),
-			       GFP_KERNEL);
-		if (!vmas)
-			return -ENOMEM;
+	if (flags & FOLL_LONGTERM) {
+		if (!pages)
+			return -EINVAL;
+
+		if (!vmas_tmp) {
+			vmas_tmp = kcalloc(nr_pages,
+					   sizeof(struct vm_area_struct *),
+					   GFP_KERNEL);
+			if (!vmas_tmp)
+				return -ENOMEM;
+		}
 	}
 
-	rc = get_user_pages(start, nr_pages, gup_flags, pages, vmas);
+	rc = __get_user_pages_locked(tsk, mm, start, nr_pages, pages,
+				     vmas_tmp, NULL, flags);
 
-	for (i = 0; i < rc; i++) {
-		struct vm_area_struct *vma = vmas[i];
+	if (flags & FOLL_LONGTERM) {
+		for (i = 0; i < rc; i++) {
+			struct vm_area_struct *vma = vmas_tmp[i];
 
-		if (vma == vma_prev)
-			continue;
+			if (vma == vma_prev)
+				continue;
 
-		vma_prev = vma;
+			vma_prev = vma;
 
-		if (vma_is_fsdax(vma))
-			break;
-	}
+			if (vma_is_fsdax(vma))
+				break;
+		}
 
-	/*
-	 * Either get_user_pages() failed, or the vma validation
-	 * succeeded, in either case we don't need to put_page() before
-	 * returning.
-	 */
-	if (i >= rc)
-		goto out;
+		/*
+		 * Either get_user_pages() failed, or the vma validation
+		 * succeeded, in either case we don't need to put_page() before
+		 * returning.
+		 */
+		if (i >= rc)
+			goto out;
 
-	for (i = 0; i < rc; i++)
-		put_page(pages[i]);
-	rc = -EOPNOTSUPP;
+		for (i = 0; i < rc; i++)
+			put_page(pages[i]);
+		rc = -EOPNOTSUPP;
 out:
-	if (vmas != vmas_arg)
-		kfree(vmas);
+		if (vmas_tmp != vmas)
+			kfree(vmas_tmp);
+	}
+
 	return rc;
 }
-EXPORT_SYMBOL(get_user_pages_longterm);
+#else /* !CONFIG_FS_DAX */
+static __always_inline long __gup_longterm_locked(struct task_struct *tsk,
+						  struct mm_struct *mm,
+						  unsigned long start,
+						  unsigned long nr_pages,
+						  struct page **pages,
+						  struct vm_area_struct **vmas,
+						  unsigned int flags)
+{
+	return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas,
+				       NULL, flags);
+}
 #endif /* CONFIG_FS_DAX */
 
+/*
+ * This is the same as get_user_pages_remote(), just with a
+ * less-flexible calling convention where we assume that the task
+ * and mm being operated on are the current task's and don't allow
+ * passing of a locked parameter.  We also obviously don't pass
+ * FOLL_REMOTE in here.
+ */
+long get_user_pages(unsigned long start, unsigned long nr_pages,
+		unsigned int gup_flags, struct page **pages,
+		struct vm_area_struct **vmas)
+{
+	return __gup_longterm_locked(current, current->mm, start, nr_pages,
+				     pages, vmas, gup_flags | FOLL_TOUCH);
+}
+EXPORT_SYMBOL(get_user_pages);
+
 /**
  * populate_vma_page_range() -  populate a range of pages in the vma.
  * @vma:   target vma
diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
index 5b42d3d4b60a..c898e2e0d1e4 100644
--- a/mm/gup_benchmark.c
+++ b/mm/gup_benchmark.c
@@ -54,8 +54,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
 						 pages + i);
 			break;
 		case GUP_LONGTERM_BENCHMARK:
-			nr = get_user_pages_longterm(addr, nr, gup->flags & 1,
-						     pages + i, NULL);
+			nr = get_user_pages(addr, nr,
+					    (gup->flags & 1) | FOLL_LONGTERM,
+					    pages + i, NULL);
 			break;
 		case GUP_BENCHMARK:
 			nr = get_user_pages(addr, nr, gup->flags & 1, pages + i,
-- 
2.20.1


^ permalink raw reply related

* [RESEND PATCH 2/7] mm/gup: Change write parameter to flags in fast walk
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel
In-Reply-To: <20190220053040.10831-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

In order to support more options in the GUP fast walk, change
the write parameter to flags throughout the call stack.

This patch does not change functionality and passes FOLL_WRITE
where write was previously used.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 mm/gup.c | 52 ++++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index ee96eaff118c..681388236106 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1417,7 +1417,7 @@ static void undo_dev_pagemap(int *nr, int nr_start, struct page **pages)
 
 #ifdef CONFIG_ARCH_HAS_PTE_SPECIAL
 static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
-			 int write, struct page **pages, int *nr)
+			 unsigned int flags, struct page **pages, int *nr)
 {
 	struct dev_pagemap *pgmap = NULL;
 	int nr_start = *nr, ret = 0;
@@ -1435,7 +1435,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
 		if (pte_protnone(pte))
 			goto pte_unmap;
 
-		if (!pte_access_permitted(pte, write))
+		if (!pte_access_permitted(pte, flags & FOLL_WRITE))
 			goto pte_unmap;
 
 		if (pte_devmap(pte)) {
@@ -1487,7 +1487,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
  * useful to have gup_huge_pmd even if we can't operate on ptes.
  */
 static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
-			 int write, struct page **pages, int *nr)
+			 unsigned int flags, struct page **pages, int *nr)
 {
 	return 0;
 }
@@ -1570,12 +1570,12 @@ static int __gup_device_huge_pud(pud_t pud, pud_t *pudp, unsigned long addr,
 #endif
 
 static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
-		unsigned long end, int write, struct page **pages, int *nr)
+		unsigned long end, unsigned int flags, struct page **pages, int *nr)
 {
 	struct page *head, *page;
 	int refs;
 
-	if (!pmd_access_permitted(orig, write))
+	if (!pmd_access_permitted(orig, flags & FOLL_WRITE))
 		return 0;
 
 	if (pmd_devmap(orig))
@@ -1608,12 +1608,12 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
 }
 
 static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,
-		unsigned long end, int write, struct page **pages, int *nr)
+		unsigned long end, unsigned int flags, struct page **pages, int *nr)
 {
 	struct page *head, *page;
 	int refs;
 
-	if (!pud_access_permitted(orig, write))
+	if (!pud_access_permitted(orig, flags & FOLL_WRITE))
 		return 0;
 
 	if (pud_devmap(orig))
@@ -1646,13 +1646,13 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,
 }
 
 static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
-			unsigned long end, int write,
+			unsigned long end, unsigned int flags,
 			struct page **pages, int *nr)
 {
 	int refs;
 	struct page *head, *page;
 
-	if (!pgd_access_permitted(orig, write))
+	if (!pgd_access_permitted(orig, flags & FOLL_WRITE))
 		return 0;
 
 	BUILD_BUG_ON(pgd_devmap(orig));
@@ -1683,7 +1683,7 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
 }
 
 static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,
-		int write, struct page **pages, int *nr)
+		unsigned int flags, struct page **pages, int *nr)
 {
 	unsigned long next;
 	pmd_t *pmdp;
@@ -1705,7 +1705,7 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,
 			if (pmd_protnone(pmd))
 				return 0;
 
-			if (!gup_huge_pmd(pmd, pmdp, addr, next, write,
+			if (!gup_huge_pmd(pmd, pmdp, addr, next, flags,
 				pages, nr))
 				return 0;
 
@@ -1715,9 +1715,9 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,
 			 * pmd format and THP pmd format
 			 */
 			if (!gup_huge_pd(__hugepd(pmd_val(pmd)), addr,
-					 PMD_SHIFT, next, write, pages, nr))
+					 PMD_SHIFT, next, flags, pages, nr))
 				return 0;
-		} else if (!gup_pte_range(pmd, addr, next, write, pages, nr))
+		} else if (!gup_pte_range(pmd, addr, next, flags, pages, nr))
 			return 0;
 	} while (pmdp++, addr = next, addr != end);
 
@@ -1725,7 +1725,7 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,
 }
 
 static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end,
-			 int write, struct page **pages, int *nr)
+			 unsigned int flags, struct page **pages, int *nr)
 {
 	unsigned long next;
 	pud_t *pudp;
@@ -1738,14 +1738,14 @@ static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end,
 		if (pud_none(pud))
 			return 0;
 		if (unlikely(pud_huge(pud))) {
-			if (!gup_huge_pud(pud, pudp, addr, next, write,
+			if (!gup_huge_pud(pud, pudp, addr, next, flags,
 					  pages, nr))
 				return 0;
 		} else if (unlikely(is_hugepd(__hugepd(pud_val(pud))))) {
 			if (!gup_huge_pd(__hugepd(pud_val(pud)), addr,
-					 PUD_SHIFT, next, write, pages, nr))
+					 PUD_SHIFT, next, flags, pages, nr))
 				return 0;
-		} else if (!gup_pmd_range(pud, addr, next, write, pages, nr))
+		} else if (!gup_pmd_range(pud, addr, next, flags, pages, nr))
 			return 0;
 	} while (pudp++, addr = next, addr != end);
 
@@ -1753,7 +1753,7 @@ static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end,
 }
 
 static int gup_p4d_range(pgd_t pgd, unsigned long addr, unsigned long end,
-			 int write, struct page **pages, int *nr)
+			 unsigned int flags, struct page **pages, int *nr)
 {
 	unsigned long next;
 	p4d_t *p4dp;
@@ -1768,9 +1768,9 @@ static int gup_p4d_range(pgd_t pgd, unsigned long addr, unsigned long end,
 		BUILD_BUG_ON(p4d_huge(p4d));
 		if (unlikely(is_hugepd(__hugepd(p4d_val(p4d))))) {
 			if (!gup_huge_pd(__hugepd(p4d_val(p4d)), addr,
-					 P4D_SHIFT, next, write, pages, nr))
+					 P4D_SHIFT, next, flags, pages, nr))
 				return 0;
-		} else if (!gup_pud_range(p4d, addr, next, write, pages, nr))
+		} else if (!gup_pud_range(p4d, addr, next, flags, pages, nr))
 			return 0;
 	} while (p4dp++, addr = next, addr != end);
 
@@ -1778,7 +1778,7 @@ static int gup_p4d_range(pgd_t pgd, unsigned long addr, unsigned long end,
 }
 
 static void gup_pgd_range(unsigned long addr, unsigned long end,
-		int write, struct page **pages, int *nr)
+		unsigned int flags, struct page **pages, int *nr)
 {
 	unsigned long next;
 	pgd_t *pgdp;
@@ -1791,14 +1791,14 @@ static void gup_pgd_range(unsigned long addr, unsigned long end,
 		if (pgd_none(pgd))
 			return;
 		if (unlikely(pgd_huge(pgd))) {
-			if (!gup_huge_pgd(pgd, pgdp, addr, next, write,
+			if (!gup_huge_pgd(pgd, pgdp, addr, next, flags,
 					  pages, nr))
 				return;
 		} else if (unlikely(is_hugepd(__hugepd(pgd_val(pgd))))) {
 			if (!gup_huge_pd(__hugepd(pgd_val(pgd)), addr,
-					 PGDIR_SHIFT, next, write, pages, nr))
+					 PGDIR_SHIFT, next, flags, pages, nr))
 				return;
-		} else if (!gup_p4d_range(pgd, addr, next, write, pages, nr))
+		} else if (!gup_p4d_range(pgd, addr, next, flags, pages, nr))
 			return;
 	} while (pgdp++, addr = next, addr != end);
 }
@@ -1852,7 +1852,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
 
 	if (gup_fast_permitted(start, nr_pages)) {
 		local_irq_save(flags);
-		gup_pgd_range(start, end, write, pages, &nr);
+		gup_pgd_range(start, end, write ? FOLL_WRITE : 0, pages, &nr);
 		local_irq_restore(flags);
 	}
 
@@ -1894,7 +1894,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 
 	if (gup_fast_permitted(start, nr_pages)) {
 		local_irq_disable();
-		gup_pgd_range(addr, end, write, pages, &nr);
+		gup_pgd_range(addr, end, write ? FOLL_WRITE : 0, pages, &nr);
 		local_irq_enable();
 		ret = nr;
 	}
-- 
2.20.1


^ permalink raw reply related

* [RESEND PATCH 6/7] IB/qib: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
From: ira.weiny @ 2019-02-20  5:30 UTC (permalink / raw)
  To: John Hubbard, Andrew Morton, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, Paul Burton,
	James Hogan
  Cc: Ira Weiny, linux-kernel, linux-mm, linux-mips, linuxppc-dev,
	linux-s390, linux-sh, sparclinux, kvm-ppc, kvm, linux-fpga,
	dri-devel, linux-rdma, linux-media, linux-scsi, devel,
	virtualization, netdev, linux-fbdev, xen-devel, devel, ceph-devel,
	rds-devel
In-Reply-To: <20190220053040.10831-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

Use the new FOLL_LONGTERM to get_user_pages_fast() to protect against
FS DAX pages being mapped.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 drivers/infiniband/hw/qib/qib_user_sdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/qib/qib_user_sdma.c b/drivers/infiniband/hw/qib/qib_user_sdma.c
index 31c523b2a9f5..b53cc0240e02 100644
--- a/drivers/infiniband/hw/qib/qib_user_sdma.c
+++ b/drivers/infiniband/hw/qib/qib_user_sdma.c
@@ -673,7 +673,7 @@ static int qib_user_sdma_pin_pages(const struct qib_devdata *dd,
 		else
 			j = npages;
 
-		ret = get_user_pages_fast(addr, j, 0, pages);
+		ret = get_user_pages_fast(addr, j, FOLL_LONGTERM, pages);
 		if (ret != j) {
 			i = 0;
 			j = ret;
-- 
2.20.1


^ permalink raw reply related

* Re: linux-next: Fixes tag needs some work in the net-next tree
From: Stephen Rothwell @ 2019-02-20  5:38 UTC (permalink / raw)
  To: Vinod Koul
  Cc: David Miller, Networking, Linux Next Mailing List,
	Linux Kernel Mailing List, Andrew Lunn
In-Reply-To: <20190220044055.GD21884@vkoul-mobl>

[-- Attachment #1: Type: text/plain, Size: 313 bytes --]

Hi Vinod,

On Wed, 20 Feb 2019 10:10:55 +0530 Vinod Koul <vkoul@kernel.org> wrote:
>
> Dave would you like to drop this and me sending updated patch or
> something else..

Dave doesn't rebase/reset net-next, so we will just have to use this as
a learning experience :-)

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* [PATCH] r8152: Fix an error on RTL8153-BD MAC Address Passthrough support
From: David Chen @ 2019-02-20  5:47 UTC (permalink / raw)
  To: linux-usb, netdev, linux-kernel
  Cc: davem, hayeswang, mario.limonciello, bigeasy, edumazet, jslaby,
	f.fainelli, david.chen7, kai.heng.feng, zhongjiang

From: David Chen <david.chen7@dell.com>

RTL8153-BD is used in Dell DA300 type-C dongle.
Added RTL8153-BD support to activate MAC address pass through on DA300.
Apply correction on previously submitted patch in net.git tree.

Signed-off-by: David Chen <david.chen7@dell.com>
---
 drivers/net/usb/r8152.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index ada6baf8847a..86c8c64fbb0f 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1179,7 +1179,7 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
 	} else {
 		/* test for RTL8153-BND and RTL8153-BD */
 		ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
-		if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK)) {
+		if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {
 			netif_dbg(tp, probe, tp->netdev,
 				  "Invalid variant for MAC pass through\n");
 			return -ENODEV;
-- 
2.19.1


^ permalink raw reply related

* [PATCH net-next] tls: Return type of non-data records retrieved using MSG_PEEK in recvmsg
From: Vakul Garg @ 2019-02-20  6:15 UTC (permalink / raw)
  To: netdev@vger.kernel.org
  Cc: borisp@mellanox.com, aviadye@mellanox.com, davejwatson@fb.com,
	davem@davemloft.net, doronrk@fb.com, Vakul Garg

The patch enables returning 'type' in msghdr for records that are
retrieved with MSG_PEEK in recvmsg. Further it prevents records peeked
from socket from getting clubbed with any other record of different
type when records are subsequently dequeued from strparser.

For each record, we now retain its type in sk_buff's control buffer
cb[]. Inside control buffer, record's full length and offset are already
stored by strparser in 'struct strp_msg'. We store record type after
'struct strp_msg' inside 'struct tls_msg'. For tls1.2, the type is
stored just after record dequeue. For tls1.3, the type is stored after
record has been decrypted.

Inside process_rx_list(), before processing a non-data record, we check
that we must be able to return back the record type to the user
application. If not, the decrypted records in tls context's rx_list is
left there without consuming any data.

Fixes: 692d7b5d1f912 ("tls: Fix recvmsg() to be able to peek across...)
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
---
 include/net/tls.h | 10 +++++++
 net/tls/tls_sw.c  | 78 +++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/include/net/tls.h b/include/net/tls.h
index a8b37226a287..9f4117ae2297 100644
--- a/include/net/tls.h
+++ b/include/net/tls.h
@@ -129,6 +129,11 @@ struct tls_rec {
 	u8 aead_req_ctx[];
 };
 
+struct tls_msg {
+	struct strp_msg rxm;
+	u8 control;
+};
+
 struct tx_work {
 	struct delayed_work work;
 	struct sock *sk;
@@ -333,6 +338,11 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
 int tls_push_pending_closed_record(struct sock *sk, struct tls_context *ctx,
 				   int flags, long *timeo);
 
+static inline struct tls_msg *tls_msg(struct sk_buff *skb)
+{
+	return (struct tls_msg *)strp_msg(skb);
+}
+
 static inline bool tls_is_pending_closed_record(struct tls_context *ctx)
 {
 	return test_bit(TLS_PENDING_CLOSED_RECORD, &ctx->flags);
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 71be8acfbc9b..1cc830582fa8 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1530,22 +1530,38 @@ static bool tls_sw_advance_skb(struct sock *sk, struct sk_buff *skb,
 }
 
 /* This function traverses the rx_list in tls receive context to copies the
- * decrypted data records into the buffer provided by caller zero copy is not
+ * decrypted records into the buffer provided by caller zero copy is not
  * true. Further, the records are removed from the rx_list if it is not a peek
  * case and the record has been consumed completely.
  */
 static int process_rx_list(struct tls_sw_context_rx *ctx,
 			   struct msghdr *msg,
+			   u8 *control,
+			   bool *cmsg,
 			   size_t skip,
 			   size_t len,
 			   bool zc,
 			   bool is_peek)
 {
 	struct sk_buff *skb = skb_peek(&ctx->rx_list);
+	u8 ctrl = *control;
+	u8 msgc = *cmsg;
+	struct tls_msg *tlm;
 	ssize_t copied = 0;
 
+	/* Set the record type in 'control' if caller didn't pass it */
+	if (!ctrl && skb) {
+		tlm = tls_msg(skb);
+		ctrl = tlm->control;
+	}
+
 	while (skip && skb) {
 		struct strp_msg *rxm = strp_msg(skb);
+		tlm = tls_msg(skb);
+
+		/* Cannot process a record of different type */
+		if (ctrl != tlm->control)
+			return 0;
 
 		if (skip < rxm->full_len)
 			break;
@@ -1559,6 +1575,27 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
 		struct strp_msg *rxm = strp_msg(skb);
 		int chunk = min_t(unsigned int, rxm->full_len - skip, len);
 
+		tlm = tls_msg(skb);
+
+		/* Cannot process a record of different type */
+		if (ctrl != tlm->control)
+			return 0;
+
+		/* Set record type if not already done. For a non-data record,
+		 * do not proceed if record type could not be copied.
+		 */
+		if (!msgc) {
+			int cerr = put_cmsg(msg, SOL_TLS, TLS_GET_RECORD_TYPE,
+					    sizeof(ctrl), &ctrl);
+			msgc = true;
+			if (ctrl != TLS_RECORD_TYPE_DATA) {
+				if (cerr || msg->msg_flags & MSG_CTRUNC)
+					return -EIO;
+
+				*cmsg = msgc;
+			}
+		}
+
 		if (!zc || (rxm->full_len - skip) > len) {
 			int err = skb_copy_datagram_msg(skb, rxm->offset + skip,
 						    msg, chunk);
@@ -1597,6 +1634,7 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
 		skb = next_skb;
 	}
 
+	*control = ctrl;
 	return copied;
 }
 
@@ -1614,6 +1652,7 @@ int tls_sw_recvmsg(struct sock *sk,
 	unsigned char control = 0;
 	ssize_t decrypted = 0;
 	struct strp_msg *rxm;
+	struct tls_msg *tlm;
 	struct sk_buff *skb;
 	ssize_t copied = 0;
 	bool cmsg = false;
@@ -1632,7 +1671,8 @@ int tls_sw_recvmsg(struct sock *sk,
 	lock_sock(sk);
 
 	/* Process pending decrypted records. It must be non-zero-copy */
-	err = process_rx_list(ctx, msg, 0, len, false, is_peek);
+	err = process_rx_list(ctx, msg, &control, &cmsg, 0, len, false,
+			      is_peek);
 	if (err < 0) {
 		tls_err_abort(sk, err);
 		goto end;
@@ -1668,6 +1708,12 @@ int tls_sw_recvmsg(struct sock *sk,
 				}
 			}
 			goto recv_end;
+		} else {
+			tlm = tls_msg(skb);
+			if (prot->version == TLS_1_3_VERSION)
+				tlm->control = 0;
+			else
+				tlm->control = ctx->control;
 		}
 
 		rxm = strp_msg(skb);
@@ -1694,22 +1740,34 @@ int tls_sw_recvmsg(struct sock *sk,
 
 		if (err == -EINPROGRESS)
 			num_async++;
+		else if (prot->version == TLS_1_3_VERSION)
+			tlm->control = ctx->control;
+
+		/* If the type of records being processed is not known yet,
+		 * set it to record type just dequeued. If it is already known,
+		 * but does not match the record type just dequeued, go to end.
+		 * We always get record type here since for tls1.2, record type
+		 * is known just after record is dequeued from stream parser.
+		 * For tls1.3, we disable async.
+		 */
+
+		if (!control)
+			control = tlm->control;
+		else if (control != tlm->control)
+			goto recv_end;
 
 		if (!cmsg) {
 			int cerr;
 
 			cerr = put_cmsg(msg, SOL_TLS, TLS_GET_RECORD_TYPE,
-					sizeof(ctx->control), &ctx->control);
+					sizeof(control), &control);
 			cmsg = true;
-			control = ctx->control;
-			if (ctx->control != TLS_RECORD_TYPE_DATA) {
+			if (control != TLS_RECORD_TYPE_DATA) {
 				if (cerr || msg->msg_flags & MSG_CTRUNC) {
 					err = -EIO;
 					goto recv_end;
 				}
 			}
-		} else if (control != ctx->control) {
-			goto recv_end;
 		}
 
 		if (async)
@@ -1784,18 +1842,16 @@ int tls_sw_recvmsg(struct sock *sk,
 
 		/* Drain records from the rx_list & copy if required */
 		if (is_peek || is_kvec)
-			err = process_rx_list(ctx, msg, copied,
+			err = process_rx_list(ctx, msg, &control, &cmsg, copied,
 					      decrypted, false, is_peek);
 		else
-			err = process_rx_list(ctx, msg, 0,
+			err = process_rx_list(ctx, msg, &control, &cmsg, 0,
 					      decrypted, true, is_peek);
 		if (err < 0) {
 			tls_err_abort(sk, err);
 			copied = 0;
 			goto end;
 		}
-
-		WARN_ON(decrypted != err);
 	}
 
 	copied += decrypted;
-- 
2.13.6


^ permalink raw reply related

* mlx5 stable backport help
From: David Miller @ 2019-02-20  6:36 UTC (permalink / raw)
  To: saeedm; +Cc: ogerlitz, netdev


Saeed and Or,

I need help backporting two changes for -stable.  Namely:

6707f74be8621ae067d2cf1c4485900e2742c20f ("net/mlx5e: Update hw flows when encap source mac changed")
218d05ce326f9e1b40a56085431fa1068b43d5d9 ("net/mlx5e: Don't overwrite pedit action when multiple pedit used")

For example, with the first one, not only has the code moved into
tc_tun.c but also we require the addition of get_route_and_out_devs(),
the passing in of the &route_dev, and also all of the new
dst_is_lag_dev logic.  That's like 4 or 5 commits worth.

Thanks.

^ permalink raw reply

* [PATCH net-next] net: phy: aquantia: Use get_features for the PHYs abilities
From: Heiner Kallweit @ 2019-02-20  6:46 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev@vger.kernel.org

From: Andrew Lunn <andrew@lunn.ch>
Use the new PHY driver call to get the PHYs supported features.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
[hkallweit1@gmail.com: removed new config_init callback from patch]
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/aquantia.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c
index 5f3782d4b..b86cfee3b 100644
--- a/drivers/net/phy/aquantia.c
+++ b/drivers/net/phy/aquantia.c
@@ -190,8 +190,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQ1202),
 	.name		= "Aquantia AQ1202",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -200,8 +200,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQ2104),
 	.name		= "Aquantia AQ2104",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -210,8 +210,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQR105),
 	.name		= "Aquantia AQR105",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -220,8 +220,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQR106),
 	.name		= "Aquantia AQR106",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -230,8 +230,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQR107),
 	.name		= "Aquantia AQR107",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -240,8 +240,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQCS109),
 	.name		= "Aquantia AQCS109",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
@@ -250,8 +250,8 @@ static struct phy_driver aqr_driver[] = {
 {
 	PHY_ID_MATCH_MODEL(PHY_ID_AQR405),
 	.name		= "Aquantia AQR405",
-	.features	= PHY_10GBIT_FULL_FEATURES,
 	.aneg_done	= genphy_c45_aneg_done,
+	.get_features	= genphy_c45_pma_read_abilities,
 	.config_aneg    = aqr_config_aneg,
 	.config_intr	= aqr_config_intr,
 	.ack_interrupt	= aqr_ack_interrupt,
-- 
2.20.1


^ permalink raw reply related

* Re: linux-next: Fixes tag needs some work in the net-next tree
From: David Miller @ 2019-02-20  6:48 UTC (permalink / raw)
  To: vkoul; +Cc: sfr, netdev, linux-next, linux-kernel, andrew
In-Reply-To: <20190220044055.GD21884@vkoul-mobl>

From: Vinod Koul <vkoul@kernel.org>
Date: Wed, 20 Feb 2019 10:10:55 +0530

> On 20-02-19, 09:31, Stephen Rothwell wrote:
>> Hi all,
>> 
>> In commit
>> 
>>   a968b5e9d587 ("net: dsa: qca8k: Enable delay for RGMII_ID mode")
>> 
>> Fixes tag
>> 
>>   Fixes: 40269aa9f40a ("net: dsa: qca8k: disable delay for RGMII mode")
>> 
>> has these problem(s):
>> 
>>   - Target SHA1 does not exist
>> 
>> Did you mean:
>> 
>>   Fixes: 5ecdd77c61c8 ("net: dsa: qca8k: disable delay for RGMII mode")
> 
> Yes looks like I messed up the commit id.. Not sure why :(
> 
> Dave would you like to drop this and me sending updated patch or
> something else..
> 
> Sorry about the miss

Doesn't work that way, something in my tree is there forever.

^ permalink raw reply

* Re: [PATCH RESEND net] net: phy: xgmiitorgmii: Support generic PHY status read
From: Michal Simek @ 2019-02-20  6:58 UTC (permalink / raw)
  To: Andrew Lunn, Paul Kocialkowski
  Cc: Florian Fainelli, netdev, linux-arm-kernel, linux-kernel,
	Michal Simek, David S . Miller, Thomas Petazzoni, Heiner Kallweit
In-Reply-To: <20190219172515.GC13075@lunn.ch>

Hi,

On 19. 02. 19 18:25, Andrew Lunn wrote:
>> Thanks for the suggestion! So I had a closer look at that driver to try
>> and see what could go wrong and it looks like I found a few things
>> there.
> 
> Hi Paul
> 
> Yes, this driver has issues. If i remember correctly, it got merged
> while i was on vacation. I pointed out a few issues, but the authors
> never responded. Feel free to fix it up.

Will be good to know who was that person.

I can't do much this week with this because responsible person for this
driver is out of office this week. That's why please give us some time
to get back to this.

Thanks,
Michal




^ permalink raw reply

* [PATCH iproute2-next v1 00/19] Export object IDs to users
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger

From: Leon Romanovsky <leonro@mellanox.com>

Changelog:
v0->v1:
 * Rebased to latest iproute2-next
 * Added latest rdma_netlink.h and updated commit message to point
   to kernel SHA commit.

This series adds ability to present and query all known to rdmatool
object by their respective, unique IDs (e.g. pdn. mrn, cqn e.t.c).
All objects which have "parent" object has this information too.

Thanks

Leon Romanovsky (19):
  rdma: update uapi headers
  rdma: Remove duplicated print code
  rdma: Provide unique indexes for all visible objects
  rdma: Provide parent context index for all objects except CM_ID
  rdma: Move resource PD logic to separate file
  rdma: Refactor out resource MR logic to separate file
  rdma: Move out resource CQ logic to separate file
  rdma: Move out resource CM-ID logic to separate file
  rdma: Move resource PD logic to separate file
  rdma: Properly mark RDMAtool license
  rdma: Simplify code to reuse existing functions
  rdma: Simplify CM_ID print code
  rdma: Refactor CQ prints
  rdma: Separate MR code
  rdma: Separate PD code
  rdma: Move QP code to separate function
  rdma: Unify netlink attribute checks prior to prints
  rdma: Perform single .doit call to query specific objects
  rdma: Provide and reuse filter functions

 rdma/Makefile                         |   5 +-
 rdma/dev.c                            |   7 +-
 rdma/include/uapi/rdma/rdma_netlink.h |  64 +-
 rdma/link.c                           |   7 +-
 rdma/rdma.c                           |   7 +-
 rdma/rdma.h                           |  24 +-
 rdma/res-cmid.c                       | 275 ++++++++
 rdma/res-cq.c                         | 160 +++++
 rdma/res-mr.c                         | 133 ++++
 rdma/res-pd.c                         | 136 ++++
 rdma/res-qp.c                         | 240 +++++++
 rdma/res.c                            | 932 ++------------------------
 rdma/res.h                            | 148 ++++
 rdma/utils.c                          |  53 +-
 14 files changed, 1257 insertions(+), 934 deletions(-)
 create mode 100644 rdma/res-cmid.c
 create mode 100644 rdma/res-cq.c
 create mode 100644 rdma/res-mr.c
 create mode 100644 rdma/res-pd.c
 create mode 100644 rdma/res-qp.c
 create mode 100644 rdma/res.h

--
2.19.1


^ permalink raw reply

* [PATCH iproute2-next v1 01/19] rdma: update uapi headers
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Update rdma_netlink,h file upto kernel commit
f2a0e45f36b0 RDMA/nldev: Don't expose number of not-visible entries

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/include/uapi/rdma/rdma_netlink.h | 64 +++++++++++++++++++++------
 1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/rdma/include/uapi/rdma/rdma_netlink.h b/rdma/include/uapi/rdma/rdma_netlink.h
index 04c80ceb..5027c627 100644
--- a/rdma/include/uapi/rdma/rdma_netlink.h
+++ b/rdma/include/uapi/rdma/rdma_netlink.h
@@ -5,8 +5,7 @@
 #include <linux/types.h>
 
 enum {
-	RDMA_NL_RDMA_CM = 1,
-	RDMA_NL_IWCM,
+	RDMA_NL_IWCM = 2,
 	RDMA_NL_RSVD,
 	RDMA_NL_LS,	/* RDMA Local Services */
 	RDMA_NL_NLDEV,	/* RDMA device interface */
@@ -14,8 +13,7 @@ enum {
 };
 
 enum {
-	RDMA_NL_GROUP_CM = 1,
-	RDMA_NL_GROUP_IWPM,
+	RDMA_NL_GROUP_IWPM = 2,
 	RDMA_NL_GROUP_LS,
 	RDMA_NL_NUM_GROUPS
 };
@@ -24,15 +22,17 @@ enum {
 #define RDMA_NL_GET_OP(type) (type & ((1 << 10) - 1))
 #define RDMA_NL_GET_TYPE(client, op) ((client << 10) + op)
 
-enum {
-	RDMA_NL_RDMA_CM_ID_STATS = 0,
-	RDMA_NL_RDMA_CM_NUM_OPS
-};
+/* The minimum version that the iwpm kernel supports */
+#define IWPM_UABI_VERSION_MIN	3
 
+/* The latest version that the iwpm kernel supports */
+#define IWPM_UABI_VERSION	4
+
+/* iwarp port mapper message flags */
 enum {
-	RDMA_NL_RDMA_CM_ATTR_SRC_ADDR = 1,
-	RDMA_NL_RDMA_CM_ATTR_DST_ADDR,
-	RDMA_NL_RDMA_CM_NUM_ATTR,
+
+	/* Do not map the port for this IWPM request */
+	IWPM_FLAGS_NO_PORT_MAP = (1 << 0),
 };
 
 /* iwarp port mapper op-codes */
@@ -45,6 +45,7 @@ enum {
 	RDMA_NL_IWPM_HANDLE_ERR,
 	RDMA_NL_IWPM_MAPINFO,
 	RDMA_NL_IWPM_MAPINFO_NUM,
+	RDMA_NL_IWPM_HELLO,
 	RDMA_NL_IWPM_NUM_OPS
 };
 
@@ -83,20 +84,38 @@ enum {
 	IWPM_NLA_MANAGE_MAPPING_UNSPEC = 0,
 	IWPM_NLA_MANAGE_MAPPING_SEQ,
 	IWPM_NLA_MANAGE_ADDR,
-	IWPM_NLA_MANAGE_MAPPED_LOC_ADDR,
+	IWPM_NLA_MANAGE_FLAGS,
+	IWPM_NLA_MANAGE_MAPPING_MAX
+};
+
+enum {
+	IWPM_NLA_RMANAGE_MAPPING_UNSPEC = 0,
+	IWPM_NLA_RMANAGE_MAPPING_SEQ,
+	IWPM_NLA_RMANAGE_ADDR,
+	IWPM_NLA_RMANAGE_MAPPED_LOC_ADDR,
+	/* The following maintains bisectability of rdma-core */
+	IWPM_NLA_MANAGE_MAPPED_LOC_ADDR = IWPM_NLA_RMANAGE_MAPPED_LOC_ADDR,
 	IWPM_NLA_RMANAGE_MAPPING_ERR,
 	IWPM_NLA_RMANAGE_MAPPING_MAX
 };
 
-#define IWPM_NLA_MANAGE_MAPPING_MAX 3
-#define IWPM_NLA_QUERY_MAPPING_MAX  4
 #define IWPM_NLA_MAPINFO_SEND_MAX   3
+#define IWPM_NLA_REMOVE_MAPPING_MAX 3
 
 enum {
 	IWPM_NLA_QUERY_MAPPING_UNSPEC = 0,
 	IWPM_NLA_QUERY_MAPPING_SEQ,
 	IWPM_NLA_QUERY_LOCAL_ADDR,
 	IWPM_NLA_QUERY_REMOTE_ADDR,
+	IWPM_NLA_QUERY_FLAGS,
+	IWPM_NLA_QUERY_MAPPING_MAX,
+};
+
+enum {
+	IWPM_NLA_RQUERY_MAPPING_UNSPEC = 0,
+	IWPM_NLA_RQUERY_MAPPING_SEQ,
+	IWPM_NLA_RQUERY_LOCAL_ADDR,
+	IWPM_NLA_RQUERY_REMOTE_ADDR,
 	IWPM_NLA_RQUERY_MAPPED_LOC_ADDR,
 	IWPM_NLA_RQUERY_MAPPED_REM_ADDR,
 	IWPM_NLA_RQUERY_MAPPING_ERR,
@@ -114,6 +133,7 @@ enum {
 	IWPM_NLA_MAPINFO_UNSPEC = 0,
 	IWPM_NLA_MAPINFO_LOCAL_ADDR,
 	IWPM_NLA_MAPINFO_MAPPED_ADDR,
+	IWPM_NLA_MAPINFO_FLAGS,
 	IWPM_NLA_MAPINFO_MAX
 };
 
@@ -132,6 +152,12 @@ enum {
 	IWPM_NLA_ERR_MAX
 };
 
+enum {
+	IWPM_NLA_HELLO_UNSPEC = 0,
+	IWPM_NLA_HELLO_ABI_VERSION,
+	IWPM_NLA_HELLO_MAX
+};
+
 /*
  * Local service operations:
  *   RESOLVE - The client requests the local service to resolve a path.
@@ -430,6 +456,16 @@ enum rdma_nldev_attr {
 	RDMA_NLDEV_ATTR_DRIVER_S64,		/* s64 */
 	RDMA_NLDEV_ATTR_DRIVER_U64,		/* u64 */
 
+	/*
+	 * Indexes to get/set secific entry,
+	 * for QP use RDMA_NLDEV_ATTR_RES_LQPN
+	 */
+	RDMA_NLDEV_ATTR_RES_PDN,               /* u32 */
+	RDMA_NLDEV_ATTR_RES_CQN,               /* u32 */
+	RDMA_NLDEV_ATTR_RES_MRN,               /* u32 */
+	RDMA_NLDEV_ATTR_RES_CM_IDN,            /* u32 */
+	RDMA_NLDEV_ATTR_RES_CTXN,	       /* u32 */
+
 	/*
 	 * Always the end
 	 */
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 03/19] rdma: Provide unique indexes for all visible objects
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/res.c | 83 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 63 insertions(+), 20 deletions(-)

diff --git a/rdma/res.c b/rdma/res.c
index 87865ec8..f941de5c 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -549,6 +549,22 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)
 	return 0;
 }
 
+static void print_key(struct rd *rd, const char *name, uint64_t val)
+{
+	if (rd->json_output)
+		jsonw_xint_field(rd->jw, name, val);
+	else
+		pr_out("%s 0x%" PRIx64 " ", name, val);
+}
+
+static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
+{
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, name, val);
+	else
+		pr_out("%s %" PRIu64 " ", name, val);
+}
+
 static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 {
 	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
@@ -574,6 +590,7 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 		uint32_t port = 0, pid = 0;
 		uint8_t type = 0, state;
 		uint32_t lqpn = 0, ps;
+		uint32_t cm_idn = 0;
 		char *comm = NULL;
 		int err;
 
@@ -651,6 +668,12 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 			continue;
 		}
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
+			cm_idn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
+		if (rd_check_is_filtered(rd, "cm-idn", cm_idn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -669,6 +692,8 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_ps(rd, ps);
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
+			res_print_uint(rd, "cm-idn", cm_idn);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
 			print_ipaddr(rd, "src-addr", src_addr_str, src_port);
@@ -743,6 +768,7 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 		char *comm = NULL;
 		uint32_t pid = 0;
 		uint8_t poll_ctx = 0;
+		uint32_t cqn = 0;
 		uint64_t users;
 		uint32_t cqe;
 		int err;
@@ -783,6 +809,12 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 			continue;
 		}
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
+			cqn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
+		if (rd_check_is_filtered(rd, "cqn", cqn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -799,6 +831,9 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
+			res_print_uint(rd, "cqn", cqn);
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
 			free(comm);
 
@@ -808,22 +843,6 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static void print_key(struct rd *rd, const char *name, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_xint_field(rd->jw, name, val);
-	else
-		pr_out("%s 0x%" PRIx64 " ", name, val);
-}
-
-static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, name, val);
-	else
-		pr_out("%s %" PRIu64 " ", name, val);
-}
-
 static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 {
 	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
@@ -847,6 +866,7 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		uint32_t rkey = 0, lkey = 0;
 		uint64_t iova = 0, mrlen;
 		char *comm = NULL;
+		uint32_t mrn = 0;
 		uint32_t pid = 0;
 		int err;
 
@@ -885,6 +905,12 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 			continue;
 		}
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
+			mrn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
+		if (rd_check_is_filtered(rd, "mrn", mrn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -904,6 +930,9 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
+			res_print_uint(rd, "mrn", mrn);
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
 			free(comm);
 
@@ -936,6 +965,7 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
 		char *comm = NULL;
 		uint32_t pid = 0;
+		uint32_t pdn = 0;
 		uint64_t users;
 		int err;
 
@@ -970,6 +1000,12 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (rd_check_is_filtered(rd, "pid", pid))
 			continue;
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -987,6 +1023,9 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
 			free(comm);
 
@@ -1033,7 +1072,8 @@ struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "src-addr", .is_number = false },
 	{ .name = "src-port", .is_number = true },
 	{ .name = "dst-addr", .is_number = false },
-	{ .name = "dst-port", .is_number = true }
+	{ .name = "dst-port", .is_number = true },
+	{ .name = "cm-idn", .is_number = true }
 };
 
 RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false);
@@ -1043,7 +1083,8 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "dev", .is_number = false },
 	{ .name = "users", .is_number = true },
 	{ .name = "poll-ctx", .is_number = false },
-	{ .name = "pid", .is_number = true }
+	{ .name = "pid", .is_number = true },
+	{ .name = "cqn", .is_number = true }
 };
 
 RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true);
@@ -1054,7 +1095,8 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "rkey", .is_number = true },
 	{ .name = "lkey", .is_number = true },
 	{ .name = "mrlen", .is_number = true },
-	{ .name = "pid", .is_number = true }
+	{ .name = "pid", .is_number = true },
+	{ .name = "mrn", .is_number = true }
 };
 
 RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
@@ -1063,7 +1105,8 @@ static const
 struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "dev", .is_number = false },
 	{ .name = "users", .is_number = true },
-	{ .name = "pid", .is_number = true }
+	{ .name = "pid", .is_number = true },
+	{ .name = "pdn", .is_number = true }
 };
 
 RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 04/19] rdma: Provide parent context index for all objects except CM_ID
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Allow users to correlate allocated object with relevant parent

[leonro@server ~]$ rdma res show pd
dev mlx5_0 users 5 pid 0 comm [ib_core] pdn 1
dev mlx5_0 users 7 pid 0 comm [ib_ipoib] pdn 2
dev mlx5_0 users 0 pid 0 comm [mlx5_ib] pdn 3
dev mlx5_0 users 2 pid 548 comm ibv_rc_pingpong ctxn 0 pdn 4

[leonro@server ~]$ rdma res show cq cqn 0-100
dev mlx5_0 cqe 2047 users 6 poll-ctx UNBOUND_WORKQUEUE pid 0 comm [ib_core] cqn 2
dev mlx5_0 cqe 255 users 2 poll-ctx SOFTIRQ pid 0 comm [mlx5_ib] cqn 3
dev mlx5_0 cqe 511 users 1 poll-ctx DIRECT pid 0 comm [ib_ipoib] cqn 4
dev mlx5_0 cqe 255 users 1 poll-ctx DIRECT pid 0 comm [ib_ipoib] cqn 5
dev mlx5_0 cqe 255 users 0 poll-ctx SOFTIRQ pid 0 comm [mlx5_ib] cqn 6
dev mlx5_0 cqe 511 users 2 pid 548 comm ibv_rc_pingpong cqn 7 ctxn 0

[leonro@server ~]$ rdma res show mr
dev mlx5_0 mrlen 4096 pid 548 comm ibv_rc_pingpong mrn 4 pdn 0

[leonro@nps-server-14-015 ~]$ /images/leonro/src/iproute2/rdma/rdma res show qp
link mlx5_0/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 8 type UD state RTS sq-psn 0 pid 0 comm [ib_ipoib]
link mlx5_0/1 lqpn 9 pdn 4 rqpn 0 type RC state INIT rq-psn 0 sq-psn 0 path-mig-state MIGRATED pid 548 comm ibv_rc_pingpong

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/res.c | 110 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 72 insertions(+), 38 deletions(-)

diff --git a/rdma/res.c b/rdma/res.c
index f941de5c..308f66c0 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -320,6 +320,22 @@ static char *get_task_name(uint32_t pid)
 	return comm;
 }
 
+static void print_key(struct rd *rd, const char *name, uint64_t val)
+{
+	if (rd->json_output)
+		jsonw_xint_field(rd->jw, name, val);
+	else
+		pr_out("%s 0x%" PRIx64 " ", name, val);
+}
+
+static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
+{
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, name, val);
+	else
+		pr_out("%s %" PRIu64 " ", name, val);
+}
+
 static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 {
 	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
@@ -343,6 +359,7 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 		uint32_t lqpn, rqpn = 0, rq_psn = 0, sq_psn;
 		uint8_t type, state, path_mig_state = 0;
 		uint32_t port = 0, pid = 0;
+		uint32_t pdn = 0;
 		char *comm = NULL;
 		int err;
 
@@ -369,6 +386,11 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (rd_check_is_filtered(rd, "lqpn", lqpn))
 			continue;
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) {
 			rqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQPN]);
 			if (rd_check_is_filtered(rd, "rqpn", rqpn))
@@ -428,6 +450,8 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_link(rd, idx, name, port, nla_line);
 
 		print_lqpn(rd, lqpn);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
 		print_rqpn(rd, rqpn, nla_line);
 
 		print_type(rd, type);
@@ -549,22 +573,6 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)
 	return 0;
 }
 
-static void print_key(struct rd *rd, const char *name, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_xint_field(rd->jw, name, val);
-	else
-		pr_out("%s 0x%" PRIx64 " ", name, val);
-}
-
-static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, name, val);
-	else
-		pr_out("%s %" PRIu64 " ", name, val);
-}
-
 static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 {
 	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
@@ -768,6 +776,7 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 		char *comm = NULL;
 		uint32_t pid = 0;
 		uint8_t poll_ctx = 0;
+		uint32_t ctxn = 0;
 		uint32_t cqn = 0;
 		uint64_t users;
 		uint32_t cqe;
@@ -815,6 +824,12 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (rd_check_is_filtered(rd, "cqn", cqn))
 			continue;
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			ctxn = mnl_attr_get_u32(
+				 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
+		if (rd_check_is_filtered(rd, "ctxn", ctxn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -833,6 +848,8 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
 			res_print_uint(rd, "cqn", cqn);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			res_print_uint(rd, "ctxn", ctxn);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
 			free(comm);
@@ -866,6 +883,7 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		uint32_t rkey = 0, lkey = 0;
 		uint64_t iova = 0, mrlen;
 		char *comm = NULL;
+		uint32_t pdn = 0;
 		uint32_t mrn = 0;
 		uint32_t pid = 0;
 		int err;
@@ -911,6 +929,12 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (rd_check_is_filtered(rd, "mrn", mrn))
 			continue;
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
 			/* discard const from mnl_attr_get_str */
 			comm = (char *)mnl_attr_get_str(
@@ -933,6 +957,9 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
 			res_print_uint(rd, "mrn", mrn);
 
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
+
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
 			free(comm);
 
@@ -964,6 +991,7 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 		uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0;
 		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
 		char *comm = NULL;
+		uint32_t ctxn = 0;
 		uint32_t pid = 0;
 		uint32_t pdn = 0;
 		uint64_t users;
@@ -997,7 +1025,13 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 			comm = get_task_name(pid);
 		}
 
-		if (rd_check_is_filtered(rd, "pid", pid))
+                if (rd_check_is_filtered(rd, "pid", pid))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
+
+		if (rd_check_is_filtered(rd, "ctxn", ctxn))
 			continue;
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
@@ -1022,6 +1056,8 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 			print_key(rd, "unsafe_global_rkey", unsafe_global_rkey);
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			res_print_uint(rd, "ctxn", ctxn);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
 			res_print_uint(rd, "pdn", pdn);
@@ -1038,24 +1074,18 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static const struct
-filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {{ .name = "link",
-						   .is_number = false },
-						   { .name = "lqpn",
-						   .is_number = true },
-						   { .name = "rqpn",
-						   .is_number = true },
-						   { .name = "pid",
-						   .is_number = true },
-						   { .name = "sq-psn",
-						   .is_number = true },
-						   { .name = "rq-psn",
-						   .is_number = true },
-						   { .name = "type",
-						   .is_number = false },
-						   { .name = "path-mig-state",
-						   .is_number = false },
-						   { .name = "state",
-						   .is_number = false } };
+filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
+	{ .name = "link", .is_number = false },
+	{ .name = "lqpn", .is_number = true },
+	{ .name = "rqpn", .is_number = true },
+	{ .name = "pid",  .is_number = true },
+	{ .name = "sq-psn", .is_number = true },
+	{ .name = "rq-psn", .is_number = true },
+	{ .name = "type", .is_number = false },
+	{ .name = "path-mig-state", .is_number = false },
+	{ .name = "state", .is_number = false },
+	{ .name = "pdn", .is_number = true },
+};
 
 RES_FUNC(res_qp,	RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false);
 
@@ -1084,7 +1114,8 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "users", .is_number = true },
 	{ .name = "poll-ctx", .is_number = false },
 	{ .name = "pid", .is_number = true },
-	{ .name = "cqn", .is_number = true }
+	{ .name = "cqn", .is_number = true },
+	{ .name = "ctxn", .is_number = true }
 };
 
 RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true);
@@ -1096,7 +1127,8 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "lkey", .is_number = true },
 	{ .name = "mrlen", .is_number = true },
 	{ .name = "pid", .is_number = true },
-	{ .name = "mrn", .is_number = true }
+	{ .name = "mrn", .is_number = true },
+	{ .name = "pdn", .is_number = true }
 };
 
 RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
@@ -1106,7 +1138,9 @@ struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 	{ .name = "dev", .is_number = false },
 	{ .name = "users", .is_number = true },
 	{ .name = "pid", .is_number = true },
-	{ .name = "pdn", .is_number = true }
+	{ .name = "ctxn", .is_number = true },
+	{ .name = "pdn", .is_number = true },
+	{ .name = "ctxn", .is_number = true }
 };
 
 RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 05/19] rdma: Move resource PD logic to separate file
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Logically separate resource PD logic to separate file,
in order to make PD specific logic self-contained.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/Makefile |   2 +-
 rdma/res-pd.c | 110 ++++++++++++++++++++++++++++++++++++
 rdma/res.c    | 154 +++-----------------------------------------------
 rdma/res.h    |  55 ++++++++++++++++++
 4 files changed, 175 insertions(+), 146 deletions(-)
 create mode 100644 rdma/res-pd.c
 create mode 100644 rdma/res.h

diff --git a/rdma/Makefile b/rdma/Makefile
index 0498994f..9c2fb203 100644
--- a/rdma/Makefile
+++ b/rdma/Makefile
@@ -6,7 +6,7 @@ TARGETS :=
 ifeq ($(HAVE_MNL),y)
 CFLAGS += -I./include/uapi/
 
-RDMA_OBJ = rdma.o utils.o dev.o link.o res.o
+RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o
 
 TARGETS += rdma
 endif
diff --git a/rdma/res-pd.c b/rdma/res-pd.c
new file mode 100644
index 00000000..d879a21a
--- /dev/null
+++ b/rdma/res-pd.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * res-pd.c	RDMA tool
+ * Authors:     Leon Romanovsky <leonro@mellanox.com>
+ */
+
+#include "res.h"
+#include <inttypes.h>
+
+int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+	struct nlattr *nla_table, *nla_entry;
+	struct rd *rd = data;
+	const char *name;
+	uint32_t idx;
+
+	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+	    !tb[RDMA_NLDEV_ATTR_RES_PD])
+		return MNL_CB_ERROR;
+
+	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	nla_table = tb[RDMA_NLDEV_ATTR_RES_PD];
+
+	mnl_attr_for_each_nested(nla_entry, nla_table) {
+		uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0;
+		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+		char *comm = NULL;
+		uint32_t ctxn = 0;
+		uint32_t pid = 0;
+		uint32_t pdn = 0;
+		uint64_t users;
+		int err;
+
+		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+		if (err != MNL_CB_OK)
+			return MNL_CB_ERROR;
+
+		if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
+		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+			return MNL_CB_ERROR;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
+			local_dma_lkey = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
+
+		users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
+		if (rd_check_is_filtered(rd, "users", users))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
+			unsafe_global_rkey = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+			pid = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+			comm = get_task_name(pid);
+		}
+
+		if (rd_check_is_filtered(rd, "pid", pid))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			ctxn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
+
+		if (rd_check_is_filtered(rd, "ctxn", ctxn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
+			/* discard const from mnl_attr_get_str */
+			comm = (char *)mnl_attr_get_str(
+				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+
+		if (rd->json_output)
+			jsonw_start_array(rd->jw);
+
+		print_dev(rd, idx, name);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
+			print_key(rd, "local_dma_lkey", local_dma_lkey);
+		print_users(rd, users);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
+			print_key(rd, "unsafe_global_rkey", unsafe_global_rkey);
+		print_pid(rd, pid);
+		print_comm(rd, comm, nla_line);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			res_print_uint(rd, "ctxn", ctxn);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+			free(comm);
+
+		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
+		newline(rd);
+	}
+	return MNL_CB_OK;
+}
diff --git a/rdma/res.c b/rdma/res.c
index 308f66c0..494a82e4 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -9,7 +9,7 @@
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
-#include "rdma.h"
+#include "res.h"
 #include <inttypes.h>
 
 static int res_help(struct rd *rd)
@@ -92,7 +92,7 @@ static int res_no_args_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback)
+int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback)
 {
 	uint32_t flags = NLM_F_REQUEST | NLM_F_ACK;
 	uint32_t seq;
@@ -119,27 +119,6 @@ static int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback)
 	return ret;
 }
 
-#define RES_FUNC(name, command, valid_filters, strict_port) \
-	static int _##name(struct rd *rd)\
-	{ \
-		return _res_send_msg(rd, command, name##_parse_cb); \
-	} \
-	static int name(struct rd *rd) \
-	{\
-		int ret = rd_build_filter(rd, valid_filters); \
-		if (ret) \
-			return ret; \
-		if ((uintptr_t)valid_filters != (uintptr_t)NULL) { \
-			ret = rd_set_arg_to_devname(rd); \
-			if (ret) \
-				return ret;\
-		} \
-		if (strict_port) \
-			return rd_exec_dev(rd, _##name); \
-		else \
-			return rd_exec_link(rd, _##name, strict_port); \
-	}
-
 static const char *path_mig_to_str(uint8_t idx)
 {
 	static const char * const path_mig_str[] = { "MIGRATED",
@@ -244,7 +223,7 @@ static void print_pathmig(struct rd *rd, uint32_t val,
 		pr_out("path-mig-state %s ", path_mig_to_str(val));
 }
 
-static void print_pid(struct rd *rd, uint32_t val)
+void print_pid(struct rd *rd, uint32_t val)
 {
 	if (rd->json_output)
 		jsonw_uint_field(rd->jw, "pid", val);
@@ -252,8 +231,7 @@ static void print_pid(struct rd *rd, uint32_t val)
 		pr_out("pid %u ", val);
 }
 
-static void print_comm(struct rd *rd, const char *str,
-		       struct nlattr **nla_line)
+void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line)
 {
 	char tmp[18];
 
@@ -271,7 +249,7 @@ static void print_comm(struct rd *rd, const char *str,
 	pr_out("comm %s ", tmp);
 }
 
-static void print_dev(struct rd *rd, uint32_t idx, const char *name)
+void print_dev(struct rd *rd, uint32_t idx, const char *name)
 {
 	if (rd->json_output) {
 		jsonw_uint_field(rd->jw, "ifindex", idx);
@@ -299,7 +277,7 @@ static void print_link(struct rd *rd, uint32_t idx, const char *name,
 	}
 }
 
-static char *get_task_name(uint32_t pid)
+char *get_task_name(uint32_t pid)
 {
 	char *comm;
 	FILE *f;
@@ -320,7 +298,7 @@ static char *get_task_name(uint32_t pid)
 	return comm;
 }
 
-static void print_key(struct rd *rd, const char *name, uint64_t val)
+void print_key(struct rd *rd, const char *name, uint64_t val)
 {
 	if (rd->json_output)
 		jsonw_xint_field(rd->jw, name, val);
@@ -328,7 +306,7 @@ static void print_key(struct rd *rd, const char *name, uint64_t val)
 		pr_out("%s 0x%" PRIx64 " ", name, val);
 }
 
-static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
+void res_print_uint(struct rd *rd, const char *name, uint64_t val)
 {
 	if (rd->json_output)
 		jsonw_uint_field(rd->jw, name, val);
@@ -725,7 +703,7 @@ static void print_cqe(struct rd *rd, uint32_t val)
 		pr_out("cqe %u ", val);
 }
 
-static void print_users(struct rd *rd, uint64_t val)
+void print_users(struct rd *rd, uint64_t val)
 {
 	if (rd->json_output)
 		jsonw_uint_field(rd->jw, "users", val);
@@ -969,108 +947,6 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_PD])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_PD];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0;
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		char *comm = NULL;
-		uint32_t ctxn = 0;
-		uint32_t pid = 0;
-		uint32_t pdn = 0;
-		uint64_t users;
-		int err;
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
-		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-			return MNL_CB_ERROR;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
-			local_dma_lkey = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
-
-		users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-		if (rd_check_is_filtered(rd, "users", users))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
-			unsafe_global_rkey = mnl_attr_get_u32(
-			      nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-			pid = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-			comm = get_task_name(pid);
-		}
-
-                if (rd_check_is_filtered(rd, "pid", pid))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-			ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-
-		if (rd_check_is_filtered(rd, "ctxn", ctxn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			pdn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-		if (rd_check_is_filtered(rd, "pdn", pdn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-			/* discard const from mnl_attr_get_str */
-			comm = (char *)mnl_attr_get_str(
-				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-		if (rd->json_output)
-			jsonw_start_array(rd->jw);
-
-		print_dev(rd, idx, name);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
-			print_key(rd, "local_dma_lkey", local_dma_lkey);
-		print_users(rd, users);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
-			print_key(rd, "unsafe_global_rkey", unsafe_global_rkey);
-		print_pid(rd, pid);
-		print_comm(rd, comm, nla_line);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-			res_print_uint(rd, "ctxn", ctxn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			res_print_uint(rd, "pdn", pdn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-			free(comm);
-
-		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-		newline(rd);
-	}
-	return MNL_CB_OK;
-}
-
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static const struct
@@ -1133,18 +1009,6 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
 
-static const
-struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "users", .is_number = true },
-	{ .name = "pid", .is_number = true },
-	{ .name = "ctxn", .is_number = true },
-	{ .name = "pdn", .is_number = true },
-	{ .name = "ctxn", .is_number = true }
-};
-
-RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
-
 static int res_show(struct rd *rd)
 {
 	const struct rd_cmd cmds[] = {
diff --git a/rdma/res.h b/rdma/res.h
new file mode 100644
index 00000000..dd01b803
--- /dev/null
+++ b/rdma/res.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/*
+ * res.h	RDMA tool
+ * Authors:     Leon Romanovsky <leonro@mellanox.com>
+ */
+#ifndef _RDMA_TOOL_RES_H_
+#define _RDMA_TOOL_RES_H_
+
+#include "rdma.h"
+
+int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
+int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
+
+#define RES_FUNC(name, command, valid_filters, strict_port) \
+	static inline int _##name(struct rd *rd)\
+	{ \
+		return _res_send_msg(rd, command, name##_parse_cb); \
+	} \
+	static inline int name(struct rd *rd) \
+	{\
+		int ret = rd_build_filter(rd, valid_filters); \
+		if (ret) \
+			return ret; \
+		if ((uintptr_t)valid_filters != (uintptr_t)NULL) { \
+			ret = rd_set_arg_to_devname(rd); \
+			if (ret) \
+				return ret;\
+		} \
+		if (strict_port) \
+			return rd_exec_dev(rd, _##name); \
+		else \
+			return rd_exec_link(rd, _##name, strict_port); \
+	}
+
+static const
+struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
+	{ .name = "dev", .is_number = false },
+	{ .name = "users", .is_number = true },
+	{ .name = "pid", .is_number = true },
+	{ .name = "ctxn", .is_number = true },
+	{ .name = "pdn", .is_number = true },
+	{ .name = "ctxn", .is_number = true }
+};
+
+RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
+
+char *get_task_name(uint32_t pid);
+void print_dev(struct rd *rd, uint32_t idx, const char *name);
+void print_users(struct rd *rd, uint64_t val);
+void print_key(struct rd *rd, const char *name, uint64_t val);
+void res_print_uint(struct rd *rd, const char *name, uint64_t val);
+void print_pid(struct rd *rd, uint32_t val);
+void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line);
+
+#endif /* _RDMA_TOOL_RES_H_ */
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 06/19] rdma: Refactor out resource MR logic to separate file
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Logically separate resource MR logic to separate file,
in order to make MR specific logic self-contained.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/Makefile |   2 +-
 rdma/res-mr.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++
 rdma/res.c    | 122 --------------------------------------------------
 rdma/res.h    |  14 ++++++
 4 files changed, 132 insertions(+), 123 deletions(-)
 create mode 100644 rdma/res-mr.c

diff --git a/rdma/Makefile b/rdma/Makefile
index 9c2fb203..0b4e1eef 100644
--- a/rdma/Makefile
+++ b/rdma/Makefile
@@ -6,7 +6,7 @@ TARGETS :=
 ifeq ($(HAVE_MNL),y)
 CFLAGS += -I./include/uapi/
 
-RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o
+RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o
 
 TARGETS += rdma
 endif
diff --git a/rdma/res-mr.c b/rdma/res-mr.c
new file mode 100644
index 00000000..dae5def2
--- /dev/null
+++ b/rdma/res-mr.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * res-mr.c	RDMA tool
+ * Authors:     Leon Romanovsky <leonro@mellanox.com>
+ */
+
+#include "res.h"
+#include <inttypes.h>
+
+int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+	struct nlattr *nla_table, *nla_entry;
+	struct rd *rd = data;
+	const char *name;
+	uint32_t idx;
+
+	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+	    !tb[RDMA_NLDEV_ATTR_RES_MR])
+		return MNL_CB_ERROR;
+
+	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
+
+	mnl_attr_for_each_nested(nla_entry, nla_table) {
+		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+		uint32_t rkey = 0, lkey = 0;
+		uint64_t iova = 0, mrlen;
+		char *comm = NULL;
+		uint32_t pdn = 0;
+		uint32_t mrn = 0;
+		uint32_t pid = 0;
+		int err;
+
+		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+		if (err != MNL_CB_OK)
+			return MNL_CB_ERROR;
+
+		if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] ||
+		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+			return MNL_CB_ERROR;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
+			rkey = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
+			lkey = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
+			iova = mnl_attr_get_u64(
+				nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
+
+		mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
+		if (rd_check_is_filtered(rd, "mrlen", mrlen))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+			pid = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+			comm = get_task_name(pid);
+		}
+
+		if (rd_check_is_filtered(rd, "pid", pid)) {
+			free(comm);
+			continue;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
+			mrn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
+		if (rd_check_is_filtered(rd, "mrn", mrn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
+			/* discard const from mnl_attr_get_str */
+			comm = (char *)mnl_attr_get_str(
+				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+
+		if (rd->json_output)
+			jsonw_start_array(rd->jw);
+
+		print_dev(rd, idx, name);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
+			print_key(rd, "rkey", rkey);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
+			print_key(rd, "lkey", lkey);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
+			print_key(rd, "iova", iova);
+		res_print_uint(rd, "mrlen", mrlen);
+		print_pid(rd, pid);
+		print_comm(rd, comm, nla_line);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
+			res_print_uint(rd, "mrn", mrn);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+			free(comm);
+
+		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
+		newline(rd);
+	}
+	return MNL_CB_OK;
+}
+
diff --git a/rdma/res.c b/rdma/res.c
index 494a82e4..1de8c797 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -838,115 +838,6 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_MR])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		uint32_t rkey = 0, lkey = 0;
-		uint64_t iova = 0, mrlen;
-		char *comm = NULL;
-		uint32_t pdn = 0;
-		uint32_t mrn = 0;
-		uint32_t pid = 0;
-		int err;
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] ||
-		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-			return MNL_CB_ERROR;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
-			rkey = mnl_attr_get_u32(
-					nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
-			lkey = mnl_attr_get_u32(
-					nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
-			iova = mnl_attr_get_u64(
-					nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
-
-		mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
-		if (rd_check_is_filtered(rd, "mrlen", mrlen))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-			pid = mnl_attr_get_u32(
-					nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-			comm = get_task_name(pid);
-		}
-
-		if (rd_check_is_filtered(rd, "pid", pid)) {
-			free(comm);
-			continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
-			mrn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
-		if (rd_check_is_filtered(rd, "mrn", mrn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			pdn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-		if (rd_check_is_filtered(rd, "pdn", pdn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-			/* discard const from mnl_attr_get_str */
-			comm = (char *)mnl_attr_get_str(
-				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-		if (rd->json_output)
-			jsonw_start_array(rd->jw);
-
-		print_dev(rd, idx, name);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
-			print_key(rd, "rkey", rkey);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
-			print_key(rd, "lkey", lkey);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
-			print_key(rd, "iova", iova);
-		res_print_uint(rd, "mrlen", mrlen);
-		print_pid(rd, pid);
-		print_comm(rd, comm, nla_line);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
-			res_print_uint(rd, "mrn", mrn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			res_print_uint(rd, "pdn", pdn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-			free(comm);
-
-		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-		newline(rd);
-	}
-	return MNL_CB_OK;
-}
-
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static const struct
@@ -996,19 +887,6 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true);
 
-static const
-struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "rkey", .is_number = true },
-	{ .name = "lkey", .is_number = true },
-	{ .name = "mrlen", .is_number = true },
-	{ .name = "pid", .is_number = true },
-	{ .name = "mrn", .is_number = true },
-	{ .name = "pdn", .is_number = true }
-};
-
-RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
-
 static int res_show(struct rd *rd)
 {
 	const struct rd_cmd cmds[] = {
diff --git a/rdma/res.h b/rdma/res.h
index dd01b803..e3619773 100644
--- a/rdma/res.h
+++ b/rdma/res.h
@@ -10,6 +10,7 @@
 
 int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
 int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
+int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
 
 #define RES_FUNC(name, command, valid_filters, strict_port) \
 	static inline int _##name(struct rd *rd)\
@@ -44,6 +45,19 @@ struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
 
+static const
+struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
+	{ .name = "dev", .is_number = false },
+	{ .name = "rkey", .is_number = true },
+	{ .name = "lkey", .is_number = true },
+	{ .name = "mrlen", .is_number = true },
+	{ .name = "pid", .is_number = true },
+	{ .name = "mrn", .is_number = true },
+	{ .name = "pdn", .is_number = true }
+};
+
+RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
+
 char *get_task_name(uint32_t pid);
 void print_dev(struct rd *rd, uint32_t idx, const char *name);
 void print_users(struct rd *rd, uint64_t val);
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 07/19] rdma: Move out resource CQ logic to separate file
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Logically separate resource CQ logic to separate file,
in order to make CQ specific logic self-contained.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/Makefile |   2 +-
 rdma/res-cq.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++
 rdma/res.c    | 147 --------------------------------------------------
 rdma/res.h    |  13 +++++
 4 files changed, 157 insertions(+), 148 deletions(-)
 create mode 100644 rdma/res-cq.c

diff --git a/rdma/Makefile b/rdma/Makefile
index 0b4e1eef..e32ccd18 100644
--- a/rdma/Makefile
+++ b/rdma/Makefile
@@ -6,7 +6,7 @@ TARGETS :=
 ifeq ($(HAVE_MNL),y)
 CFLAGS += -I./include/uapi/
 
-RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o
+RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o
 
 TARGETS += rdma
 endif
diff --git a/rdma/res-cq.c b/rdma/res-cq.c
new file mode 100644
index 00000000..fbfe593b
--- /dev/null
+++ b/rdma/res-cq.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * res-cq.c	RDMA tool
+ * Authors:     Leon Romanovsky <leonro@mellanox.com>
+ */
+
+#include "res.h"
+#include <inttypes.h>
+
+static void print_cqe(struct rd *rd, uint32_t val)
+{
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, "cqe", val);
+	else
+		pr_out("cqe %u ", val);
+}
+
+static const char *poll_ctx_to_str(uint8_t idx)
+{
+	static const char * const cm_id_states_str[] = {
+		"DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
+
+	if (idx < ARRAY_SIZE(cm_id_states_str))
+		return cm_id_states_str[idx];
+	return "UNKNOWN";
+}
+
+static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx)
+{
+	if (rd->json_output) {
+		jsonw_string_field(rd->jw, "poll-ctx",
+				   poll_ctx_to_str(poll_ctx));
+		return;
+	}
+	pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx));
+}
+
+int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+	struct nlattr *nla_table, *nla_entry;
+	struct rd *rd = data;
+	const char *name;
+	uint32_t idx;
+
+	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+	    !tb[RDMA_NLDEV_ATTR_RES_CQ])
+		return MNL_CB_ERROR;
+
+	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
+
+	mnl_attr_for_each_nested(nla_entry, nla_table) {
+		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+		char *comm = NULL;
+		uint32_t pid = 0;
+		uint8_t poll_ctx = 0;
+		uint32_t ctxn = 0;
+		uint32_t cqn = 0;
+		uint64_t users;
+		uint32_t cqe;
+		int err;
+
+		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+		if (err != MNL_CB_OK)
+			return MNL_CB_ERROR;
+
+		if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
+		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+			return MNL_CB_ERROR;
+		}
+
+		cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
+
+		users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
+		if (rd_check_is_filtered(rd, "users", users))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) {
+			poll_ctx = mnl_attr_get_u8(
+				nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
+			if (rd_check_is_string_filtered(
+				    rd, "poll-ctx", poll_ctx_to_str(poll_ctx)))
+				continue;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+			pid = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+			comm = get_task_name(pid);
+		}
+
+		if (rd_check_is_filtered(rd, "pid", pid)) {
+			free(comm);
+			continue;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
+			cqn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
+		if (rd_check_is_filtered(rd, "cqn", cqn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			ctxn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
+		if (rd_check_is_filtered(rd, "ctxn", ctxn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
+			/* discard const from mnl_attr_get_str */
+			comm = (char *)mnl_attr_get_str(
+				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+
+		if (rd->json_output)
+			jsonw_start_array(rd->jw);
+
+		print_dev(rd, idx, name);
+		print_cqe(rd, cqe);
+		print_users(rd, users);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
+			print_poll_ctx(rd, poll_ctx);
+		print_pid(rd, pid);
+		print_comm(rd, comm, nla_line);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
+			res_print_uint(rd, "cqn", cqn);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
+			res_print_uint(rd, "ctxn", ctxn);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+			free(comm);
+
+		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
+		newline(rd);
+	}
+	return MNL_CB_OK;
+}
+
diff --git a/rdma/res.c b/rdma/res.c
index 1de8c797..7956882e 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -695,14 +695,6 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static void print_cqe(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "cqe", val);
-	else
-		pr_out("cqe %u ", val);
-}
-
 void print_users(struct rd *rd, uint64_t val)
 {
 	if (rd->json_output)
@@ -711,133 +703,6 @@ void print_users(struct rd *rd, uint64_t val)
 		pr_out("users %" PRIu64 " ", val);
 }
 
-static const char *poll_ctx_to_str(uint8_t idx)
-{
-	static const char * const cm_id_states_str[] = {
-		"DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
-
-	if (idx < ARRAY_SIZE(cm_id_states_str))
-		return cm_id_states_str[idx];
-	return "UNKNOWN";
-}
-
-static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx)
-{
-	if (rd->json_output) {
-		jsonw_string_field(rd->jw, "poll-ctx",
-				   poll_ctx_to_str(poll_ctx));
-		return;
-	}
-	pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx));
-}
-
-static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_CQ])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		char *comm = NULL;
-		uint32_t pid = 0;
-		uint8_t poll_ctx = 0;
-		uint32_t ctxn = 0;
-		uint32_t cqn = 0;
-		uint64_t users;
-		uint32_t cqe;
-		int err;
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
-		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-			return MNL_CB_ERROR;
-		}
-
-		cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
-
-		users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-		if (rd_check_is_filtered(rd, "users", users))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) {
-			poll_ctx = mnl_attr_get_u8(
-					nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
-			if (rd_check_is_string_filtered(rd, "poll-ctx",
-						poll_ctx_to_str(poll_ctx)))
-				continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-			pid = mnl_attr_get_u32(
-					nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-			comm = get_task_name(pid);
-		}
-
-		if (rd_check_is_filtered(rd, "pid", pid)) {
-			free(comm);
-			continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
-			cqn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
-		if (rd_check_is_filtered(rd, "cqn", cqn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-			ctxn = mnl_attr_get_u32(
-				 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-		if (rd_check_is_filtered(rd, "ctxn", ctxn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-			/* discard const from mnl_attr_get_str */
-			comm = (char *)mnl_attr_get_str(
-				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-		if (rd->json_output)
-			jsonw_start_array(rd->jw);
-
-		print_dev(rd, idx, name);
-		print_cqe(rd, cqe);
-		print_users(rd, users);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
-			print_poll_ctx(rd, poll_ctx);
-		print_pid(rd, pid);
-		print_comm(rd, comm, nla_line);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
-			res_print_uint(rd, "cqn", cqn);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
-			res_print_uint(rd, "ctxn", ctxn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-			free(comm);
-
-		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-		newline(rd);
-	}
-	return MNL_CB_OK;
-}
-
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static const struct
@@ -875,18 +740,6 @@ struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false);
 
-static const
-struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "dev", .is_number = false },
-	{ .name = "users", .is_number = true },
-	{ .name = "poll-ctx", .is_number = false },
-	{ .name = "pid", .is_number = true },
-	{ .name = "cqn", .is_number = true },
-	{ .name = "ctxn", .is_number = true }
-};
-
-RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true);
-
 static int res_show(struct rd *rd)
 {
 	const struct rd_cmd cmds[] = {
diff --git a/rdma/res.h b/rdma/res.h
index e3619773..19f0d420 100644
--- a/rdma/res.h
+++ b/rdma/res.h
@@ -11,6 +11,7 @@
 int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
 int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
 int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
+int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data);
 
 #define RES_FUNC(name, command, valid_filters, strict_port) \
 	static inline int _##name(struct rd *rd)\
@@ -58,6 +59,18 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
 
+static const
+struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
+	{ .name = "dev", .is_number = false },
+	{ .name = "users", .is_number = true },
+	{ .name = "poll-ctx", .is_number = false },
+	{ .name = "pid", .is_number = true },
+	{ .name = "cqn", .is_number = true },
+	{ .name = "ctxn", .is_number = true }
+};
+
+RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true);
+
 char *get_task_name(uint32_t pid);
 void print_dev(struct rd *rd, uint32_t idx, const char *name);
 void print_users(struct rd *rd, uint64_t val);
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 02/19] rdma: Remove duplicated print code
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

There is no need to keep same print functions for
uint32_t and uint64_t, unify them into one function.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/res.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/rdma/res.c b/rdma/res.c
index 6b0f5fe3..87865ec8 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -808,28 +808,20 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
-static void print_key(struct rd *rd, const char *name, uint32_t val)
+static void print_key(struct rd *rd, const char *name, uint64_t val)
 {
 	if (rd->json_output)
 		jsonw_xint_field(rd->jw, name, val);
 	else
-		pr_out("%s 0x%x ", name, val);
+		pr_out("%s 0x%" PRIx64 " ", name, val);
 }
 
-static void print_iova(struct rd *rd, uint64_t val)
+static void res_print_uint(struct rd *rd, const char *name, uint64_t val)
 {
 	if (rd->json_output)
-		jsonw_xint_field(rd->jw, "iova", val);
+		jsonw_uint_field(rd->jw, name, val);
 	else
-		pr_out("iova 0x%" PRIx64 " ", val);
-}
-
-static void print_mrlen(struct rd *rd, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "mrlen", val);
-	else
-		pr_out("mrlen %" PRIu64 " ", val);
+		pr_out("%s %" PRIu64 " ", name, val);
 }
 
 static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
@@ -907,8 +899,8 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
 			print_key(rd, "lkey", lkey);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
-			print_iova(rd, iova);
-		print_mrlen(rd, mrlen);
+			print_key(rd, "iova", iova);
+		res_print_uint(rd, "mrlen", mrlen);
 		print_pid(rd, pid);
 		print_comm(rd, comm, nla_line);
 
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 09/19] rdma: Move resource PD logic to separate file
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Logically separate resource PD logic to separate file,
in order to make PD specific logic self-contained.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/Makefile |   2 +-
 rdma/res-qp.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++
 rdma/res.c    | 236 --------------------------------------------------
 rdma/res.h    |  17 ++++
 4 files changed, 252 insertions(+), 237 deletions(-)
 create mode 100644 rdma/res-qp.c

diff --git a/rdma/Makefile b/rdma/Makefile
index ef240404..ad7f4177 100644
--- a/rdma/Makefile
+++ b/rdma/Makefile
@@ -7,7 +7,7 @@ ifeq ($(HAVE_MNL),y)
 CFLAGS += -I./include/uapi/
 
 RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o \
-	   res-cmid.o
+	   res-cmid.o res-qp.o
 
 TARGETS += rdma
 endif
diff --git a/rdma/res-qp.c b/rdma/res-qp.c
new file mode 100644
index 00000000..85725fea
--- /dev/null
+++ b/rdma/res-qp.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * res-qp.c	RDMA tool
+ * Authors:     Leon Romanovsky <leonro@mellanox.com>
+ */
+
+#include "res.h"
+#include <inttypes.h>
+
+static const char *path_mig_to_str(uint8_t idx)
+{
+	static const char *const path_mig_str[] = { "MIGRATED", "REARM",
+						    "ARMED" };
+
+	if (idx < ARRAY_SIZE(path_mig_str))
+		return path_mig_str[idx];
+	return "UNKNOWN";
+}
+
+static const char *qp_states_to_str(uint8_t idx)
+{
+	static const char *const qp_states_str[] = { "RESET", "INIT", "RTR",
+						     "RTS",   "SQD",  "SQE",
+						     "ERR" };
+
+	if (idx < ARRAY_SIZE(qp_states_str))
+		return qp_states_str[idx];
+	return "UNKNOWN";
+}
+
+static void print_rqpn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
+{
+	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQPN])
+		return;
+
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, "rqpn", val);
+	else
+		pr_out("rqpn %u ", val);
+}
+
+static void print_type(struct rd *rd, uint32_t val)
+{
+	if (rd->json_output)
+		jsonw_string_field(rd->jw, "type", qp_types_to_str(val));
+	else
+		pr_out("type %s ", qp_types_to_str(val));
+}
+
+static void print_state(struct rd *rd, uint32_t val)
+{
+	if (rd->json_output)
+		jsonw_string_field(rd->jw, "state", qp_states_to_str(val));
+	else
+		pr_out("state %s ", qp_states_to_str(val));
+}
+
+static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
+{
+	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
+		return;
+
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, "rq-psn", val);
+	else
+		pr_out("rq-psn %u ", val);
+}
+
+static void print_sqpsn(struct rd *rd, uint32_t val)
+{
+	if (rd->json_output)
+		jsonw_uint_field(rd->jw, "sq-psn", val);
+	else
+		pr_out("sq-psn %u ", val);
+}
+
+static void print_pathmig(struct rd *rd, uint32_t val, struct nlattr **nla_line)
+{
+	if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
+		return;
+
+	if (rd->json_output)
+		jsonw_string_field(rd->jw, "path-mig-state",
+				   path_mig_to_str(val));
+	else
+		pr_out("path-mig-state %s ", path_mig_to_str(val));
+}
+
+int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+	struct nlattr *nla_table, *nla_entry;
+	struct rd *rd = data;
+	const char *name;
+	uint32_t idx;
+
+	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+	    !tb[RDMA_NLDEV_ATTR_RES_QP])
+		return MNL_CB_ERROR;
+
+	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	nla_table = tb[RDMA_NLDEV_ATTR_RES_QP];
+
+	mnl_attr_for_each_nested(nla_entry, nla_table) {
+		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+		uint32_t lqpn, rqpn = 0, rq_psn = 0, sq_psn;
+		uint8_t type, state, path_mig_state = 0;
+		uint32_t port = 0, pid = 0;
+		uint32_t pdn = 0;
+		char *comm = NULL;
+		int err;
+
+		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+		if (err != MNL_CB_OK)
+			return MNL_CB_ERROR;
+
+		if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_TYPE] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
+		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+			return MNL_CB_ERROR;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
+			port = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
+
+		if (port != rd->port_idx)
+			continue;
+
+		lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
+		if (rd_check_is_filtered(rd, "lqpn", lqpn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			pdn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
+		if (rd_check_is_filtered(rd, "pdn", pdn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) {
+			rqpn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_RQPN]);
+			if (rd_check_is_filtered(rd, "rqpn", rqpn))
+				continue;
+		} else {
+			if (rd_check_is_key_exist(rd, "rqpn"))
+				continue;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]) {
+			rq_psn = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]);
+			if (rd_check_is_filtered(rd, "rq-psn", rq_psn))
+				continue;
+		} else {
+			if (rd_check_is_key_exist(rd, "rq-psn"))
+				continue;
+		}
+
+		sq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]);
+		if (rd_check_is_filtered(rd, "sq-psn", sq_psn))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]) {
+			path_mig_state = mnl_attr_get_u8(
+				nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]);
+			if (rd_check_is_string_filtered(
+				    rd, "path-mig-state",
+				    path_mig_to_str(path_mig_state)))
+				continue;
+		} else {
+			if (rd_check_is_key_exist(rd, "path-mig-state"))
+				continue;
+		}
+
+		type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
+		if (rd_check_is_string_filtered(rd, "type",
+						qp_types_to_str(type)))
+			continue;
+
+		state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
+		if (rd_check_is_string_filtered(rd, "state",
+						qp_states_to_str(state)))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+			pid = mnl_attr_get_u32(
+				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+			comm = get_task_name(pid);
+		}
+
+		if (rd_check_is_filtered(rd, "pid", pid)) {
+			free(comm);
+			continue;
+		}
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
+			/* discard const from mnl_attr_get_str */
+			comm = (char *)mnl_attr_get_str(
+				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+
+		if (rd->json_output)
+			jsonw_start_array(rd->jw);
+
+		print_link(rd, idx, name, port, nla_line);
+
+		print_lqpn(rd, lqpn);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
+			res_print_uint(rd, "pdn", pdn);
+		print_rqpn(rd, rqpn, nla_line);
+
+		print_type(rd, type);
+		print_state(rd, state);
+
+		print_rqpsn(rd, rq_psn, nla_line);
+		print_sqpsn(rd, sq_psn);
+
+		print_pathmig(rd, path_mig_state, nla_line);
+		print_pid(rd, pid);
+		print_comm(rd, comm, nla_line);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+			free(comm);
+
+		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
+		newline(rd);
+	}
+	return MNL_CB_OK;
+}
diff --git a/rdma/res.c b/rdma/res.c
index d5ae60e1..6d4da38c 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -119,27 +119,6 @@ int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback)
 	return ret;
 }
 
-static const char *path_mig_to_str(uint8_t idx)
-{
-	static const char * const path_mig_str[] = { "MIGRATED",
-						     "REARM", "ARMED" };
-
-	if (idx < ARRAY_SIZE(path_mig_str))
-		return path_mig_str[idx];
-	return "UNKNOWN";
-}
-
-static const char *qp_states_to_str(uint8_t idx)
-{
-	static const char * const qp_states_str[] = { "RESET", "INIT",
-						      "RTR", "RTS", "SQD",
-						      "SQE", "ERR" };
-
-	if (idx < ARRAY_SIZE(qp_states_str))
-		return qp_states_str[idx];
-	return "UNKNOWN";
-}
-
 const char *qp_types_to_str(uint8_t idx)
 {
 	static const char * const qp_types_str[] = { "SMI", "GSI", "RC",
@@ -161,68 +140,6 @@ void print_lqpn(struct rd *rd, uint32_t val)
 		pr_out("lqpn %u ", val);
 }
 
-static void print_rqpn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQPN])
-		return;
-
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "rqpn", val);
-	else
-		pr_out("rqpn %u ", val);
-}
-
-static void print_type(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "type",
-				   qp_types_to_str(val));
-	else
-		pr_out("type %s ", qp_types_to_str(val));
-}
-
-static void print_state(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_string_field(rd->jw, "state",
-				   qp_states_to_str(val));
-	else
-		pr_out("state %s ", qp_states_to_str(val));
-}
-
-static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
-		return;
-
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "rq-psn", val);
-	else
-		pr_out("rq-psn %u ", val);
-}
-
-static void print_sqpsn(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "sq-psn", val);
-	else
-		pr_out("sq-psn %u ", val);
-}
-
-static void print_pathmig(struct rd *rd, uint32_t val,
-			  struct nlattr **nla_line)
-{
-	if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
-		return;
-
-	if (rd->json_output)
-		jsonw_string_field(rd->jw,
-				   "path-mig-state",
-				   path_mig_to_str(val));
-	else
-		pr_out("path-mig-state %s ", path_mig_to_str(val));
-}
-
 void print_pid(struct rd *rd, uint32_t val)
 {
 	if (rd->json_output)
@@ -314,143 +231,6 @@ void res_print_uint(struct rd *rd, const char *name, uint64_t val)
 		pr_out("%s %" PRIu64 " ", name, val);
 }
 
-static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
-{
-	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
-	struct nlattr *nla_table, *nla_entry;
-	struct rd *rd = data;
-	const char *name;
-	uint32_t idx;
-
-	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
-	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
-	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
-	    !tb[RDMA_NLDEV_ATTR_RES_QP])
-		return MNL_CB_ERROR;
-
-	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
-	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
-	nla_table = tb[RDMA_NLDEV_ATTR_RES_QP];
-
-	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		uint32_t lqpn, rqpn = 0, rq_psn = 0, sq_psn;
-		uint8_t type, state, path_mig_state = 0;
-		uint32_t port = 0, pid = 0;
-		uint32_t pdn = 0;
-		char *comm = NULL;
-		int err;
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return MNL_CB_ERROR;
-
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_TYPE] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
-		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-			return MNL_CB_ERROR;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-			port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
-
-		if (port != rd->port_idx)
-			continue;
-
-		lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-		if (rd_check_is_filtered(rd, "lqpn", lqpn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-		if (rd_check_is_filtered(rd, "pdn", pdn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) {
-			rqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQPN]);
-			if (rd_check_is_filtered(rd, "rqpn", rqpn))
-				continue;
-		} else {
-			if (rd_check_is_key_exist(rd, "rqpn"))
-				continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]) {
-			rq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]);
-			if (rd_check_is_filtered(rd, "rq-psn", rq_psn))
-				continue;
-		} else {
-			if (rd_check_is_key_exist(rd, "rq-psn"))
-				continue;
-		}
-
-		sq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]);
-		if (rd_check_is_filtered(rd, "sq-psn", sq_psn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]) {
-			path_mig_state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]);
-			if (rd_check_is_string_filtered(rd, "path-mig-state", path_mig_to_str(path_mig_state)))
-				continue;
-		} else {
-			if (rd_check_is_key_exist(rd, "path-mig-state"))
-				continue;
-		}
-
-		type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-		if (rd_check_is_string_filtered(rd, "type", qp_types_to_str(type)))
-			continue;
-
-		state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-		if (rd_check_is_string_filtered(rd, "state", qp_states_to_str(state)))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-			pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-			comm = get_task_name(pid);
-		}
-
-		if (rd_check_is_filtered(rd, "pid", pid)) {
-			free(comm);
-			continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
-			/* discard const from mnl_attr_get_str */
-			comm = (char *)mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
-		if (rd->json_output)
-			jsonw_start_array(rd->jw);
-
-		print_link(rd, idx, name, port, nla_line);
-
-		print_lqpn(rd, lqpn);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
-			res_print_uint(rd, "pdn", pdn);
-		print_rqpn(rd, rqpn, nla_line);
-
-		print_type(rd, type);
-		print_state(rd, state);
-
-		print_rqpsn(rd, rq_psn, nla_line);
-		print_sqpsn(rd, sq_psn);
-
-		print_pathmig(rd, path_mig_state, nla_line);
-		print_pid(rd, pid);
-		print_comm(rd, comm, nla_line);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-			free(comm);
-
-		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-		newline(rd);
-	}
-	return MNL_CB_OK;
-}
-
 void print_users(struct rd *rd, uint64_t val)
 {
 	if (rd->json_output)
@@ -461,22 +241,6 @@ void print_users(struct rd *rd, uint64_t val)
 
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
-static const struct
-filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
-	{ .name = "link", .is_number = false },
-	{ .name = "lqpn", .is_number = true },
-	{ .name = "rqpn", .is_number = true },
-	{ .name = "pid",  .is_number = true },
-	{ .name = "sq-psn", .is_number = true },
-	{ .name = "rq-psn", .is_number = true },
-	{ .name = "type", .is_number = false },
-	{ .name = "path-mig-state", .is_number = false },
-	{ .name = "state", .is_number = false },
-	{ .name = "pdn", .is_number = true },
-};
-
-RES_FUNC(res_qp,	RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false);
-
 static int res_show(struct rd *rd)
 {
 	const struct rd_cmd cmds[] = {
diff --git a/rdma/res.h b/rdma/res.h
index e9d0d12e..95d88a3a 100644
--- a/rdma/res.h
+++ b/rdma/res.h
@@ -13,6 +13,7 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
 int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
 int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data);
 int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data);
+int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data);
 
 #define RES_FUNC(name, command, valid_filters, strict_port) \
 	static inline int _##name(struct rd *rd)\
@@ -91,6 +92,22 @@ struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
 
 RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false);
 
+static const struct
+filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
+	{ .name = "link", .is_number = false },
+	{ .name = "lqpn", .is_number = true },
+	{ .name = "rqpn", .is_number = true },
+	{ .name = "pid",  .is_number = true },
+	{ .name = "sq-psn", .is_number = true },
+	{ .name = "rq-psn", .is_number = true },
+	{ .name = "type", .is_number = false },
+	{ .name = "path-mig-state", .is_number = false },
+	{ .name = "state", .is_number = false },
+	{ .name = "pdn", .is_number = true },
+};
+
+RES_FUNC(res_qp,	RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false);
+
 char *get_task_name(uint32_t pid);
 void print_dev(struct rd *rd, uint32_t idx, const char *name);
 void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 10/19] rdma: Properly mark RDMAtool license
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

RDMA subsystem is dual-licensed with "GPL-2.0 OR Linux-OpenIB" proper
license and Mellanox submission are supposed to have this type of license.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/Makefile | 2 +-
 rdma/dev.c    | 7 +------
 rdma/link.c   | 7 +------
 rdma/rdma.c   | 7 +------
 rdma/rdma.h   | 7 +------
 rdma/res.c    | 7 +------
 rdma/utils.c  | 7 +------
 7 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/rdma/Makefile b/rdma/Makefile
index ad7f4177..6a424234 100644
--- a/rdma/Makefile
+++ b/rdma/Makefile
@@ -1,4 +1,4 @@
-# SPDX-License-Identifier: GPL-2.0
+# SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 include ../config.mk
 
 TARGETS :=
diff --git a/rdma/dev.c b/rdma/dev.c
index 60ff4b31..954e0015 100644
--- a/rdma/dev.c
+++ b/rdma/dev.c
@@ -1,11 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /*
  * dev.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
diff --git a/rdma/link.c b/rdma/link.c
index c064be62..89e81b84 100644
--- a/rdma/link.c
+++ b/rdma/link.c
@@ -1,11 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /*
  * link.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
diff --git a/rdma/rdma.c b/rdma/rdma.c
index 010e9837..676e03c2 100644
--- a/rdma/rdma.c
+++ b/rdma/rdma.c
@@ -1,11 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /*
  * rdma.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
diff --git a/rdma/rdma.h b/rdma/rdma.h
index 547bb574..d2559e7c 100644
--- a/rdma/rdma.h
+++ b/rdma/rdma.h
@@ -1,11 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
 /*
  * rdma.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 #ifndef _RDMA_TOOL_H_
diff --git a/rdma/res.c b/rdma/res.c
index 6d4da38c..f621afa8 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -1,11 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /*
  * res.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
diff --git a/rdma/utils.c b/rdma/utils.c
index 069d44fe..bce052d5 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -1,11 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /*
  * utils.c	RDMA tool
- *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
- *
  * Authors:     Leon Romanovsky <leonro@mellanox.com>
  */
 
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 11/19] rdma: Simplify code to reuse existing functions
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Remove duplicated functions in favour general res_print_uint() call.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/res-cmid.c |  4 ++--
 rdma/res-cq.c   | 14 +++-----------
 rdma/res-mr.c   |  2 +-
 rdma/res-pd.c   |  4 ++--
 rdma/res-qp.c   | 14 +++-----------
 rdma/res.c      | 34 ++--------------------------------
 rdma/res.h      |  3 ---
 7 files changed, 13 insertions(+), 62 deletions(-)

diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c
index b63634a3..5eea7a6b 100644
--- a/rdma/res-cmid.c
+++ b/rdma/res-cmid.c
@@ -227,12 +227,12 @@ int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 
 		print_link(rd, idx, name, port, nla_line);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
-			print_lqpn(rd, lqpn);
+			res_print_uint(rd, "lqpn", lqpn);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
 			print_qp_type(rd, type);
 		print_cm_id_state(rd, state);
 		print_ps(rd, ps);
-		print_pid(rd, pid);
+		res_print_uint(rd, "pid", pid);
 		print_comm(rd, comm, nla_line);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
 			res_print_uint(rd, "cm-idn", cm_idn);
diff --git a/rdma/res-cq.c b/rdma/res-cq.c
index fbfe593b..93c18251 100644
--- a/rdma/res-cq.c
+++ b/rdma/res-cq.c
@@ -7,14 +7,6 @@
 #include "res.h"
 #include <inttypes.h>
 
-static void print_cqe(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "cqe", val);
-	else
-		pr_out("cqe %u ", val);
-}
-
 static const char *poll_ctx_to_str(uint8_t idx)
 {
 	static const char * const cm_id_states_str[] = {
@@ -120,11 +112,11 @@ int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
 			jsonw_start_array(rd->jw);
 
 		print_dev(rd, idx, name);
-		print_cqe(rd, cqe);
-		print_users(rd, users);
+		res_print_uint(rd, "cqe", cqe);
+		res_print_uint(rd, "users", users);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
 			print_poll_ctx(rd, poll_ctx);
-		print_pid(rd, pid);
+		res_print_uint(rd, "pid", pid);
 		print_comm(rd, comm, nla_line);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
diff --git a/rdma/res-mr.c b/rdma/res-mr.c
index dae5def2..e373035a 100644
--- a/rdma/res-mr.c
+++ b/rdma/res-mr.c
@@ -97,7 +97,7 @@ int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 		if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
 			print_key(rd, "iova", iova);
 		res_print_uint(rd, "mrlen", mrlen);
-		print_pid(rd, pid);
+		res_print_uint(rd, "pid", pid);
 		print_comm(rd, comm, nla_line);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
diff --git a/rdma/res-pd.c b/rdma/res-pd.c
index d879a21a..24ac7f1b 100644
--- a/rdma/res-pd.c
+++ b/rdma/res-pd.c
@@ -89,10 +89,10 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_dev(rd, idx, name);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY])
 			print_key(rd, "local_dma_lkey", local_dma_lkey);
-		print_users(rd, users);
+		res_print_uint(rd, "users", users);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
 			print_key(rd, "unsafe_global_rkey", unsafe_global_rkey);
-		print_pid(rd, pid);
+		res_print_uint(rd, "pid", pid);
 		print_comm(rd, comm, nla_line);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
 			res_print_uint(rd, "ctxn", ctxn);
diff --git a/rdma/res-qp.c b/rdma/res-qp.c
index 85725fea..ecd2cbd6 100644
--- a/rdma/res-qp.c
+++ b/rdma/res-qp.c
@@ -66,14 +66,6 @@ static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
 		pr_out("rq-psn %u ", val);
 }
 
-static void print_sqpsn(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "sq-psn", val);
-	else
-		pr_out("sq-psn %u ", val);
-}
-
 static void print_pathmig(struct rd *rd, uint32_t val, struct nlattr **nla_line)
 {
 	if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
@@ -209,7 +201,7 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 
 		print_link(rd, idx, name, port, nla_line);
 
-		print_lqpn(rd, lqpn);
+		res_print_uint(rd, "lqpn", lqpn);
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
 			res_print_uint(rd, "pdn", pdn);
 		print_rqpn(rd, rqpn, nla_line);
@@ -218,10 +210,10 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
 		print_state(rd, state);
 
 		print_rqpsn(rd, rq_psn, nla_line);
-		print_sqpsn(rd, sq_psn);
+		res_print_uint(rd, "sq-psn", sq_psn);
 
 		print_pathmig(rd, path_mig_state, nla_line);
-		print_pid(rd, pid);
+		res_print_uint(rd, "pid", pid);
 		print_comm(rd, comm, nla_line);
 
 		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
diff --git a/rdma/res.c b/rdma/res.c
index f621afa8..140c0908 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -35,7 +35,6 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb)
 
 	mnl_attr_for_each_nested(nla_entry, nla_table) {
 		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		char json_name[32];
 
 		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
 		if (err != MNL_CB_OK)
@@ -48,12 +47,7 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb)
 
 		name = mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME]);
 		curr = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
-		if (rd->json_output) {
-			snprintf(json_name, 32, "%s", name);
-			jsonw_lluint_field(rd->jw, json_name, curr);
-		} else {
-			pr_out("%s %"PRId64 " ", name, curr);
-		}
+		res_print_uint(rd, name, curr);
 	}
 	return 0;
 }
@@ -127,22 +121,6 @@ const char *qp_types_to_str(uint8_t idx)
 	return "UNKNOWN";
 }
 
-void print_lqpn(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "lqpn", val);
-	else
-		pr_out("lqpn %u ", val);
-}
-
-void print_pid(struct rd *rd, uint32_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "pid", val);
-	else
-		pr_out("pid %u ", val);
-}
-
 void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line)
 {
 	char tmp[18];
@@ -221,19 +199,11 @@ void print_key(struct rd *rd, const char *name, uint64_t val)
 void res_print_uint(struct rd *rd, const char *name, uint64_t val)
 {
 	if (rd->json_output)
-		jsonw_uint_field(rd->jw, name, val);
+		jsonw_u64_field(rd->jw, name, val);
 	else
 		pr_out("%s %" PRIu64 " ", name, val);
 }
 
-void print_users(struct rd *rd, uint64_t val)
-{
-	if (rd->json_output)
-		jsonw_uint_field(rd->jw, "users", val);
-	else
-		pr_out("users %" PRIu64 " ", val);
-}
-
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static int res_show(struct rd *rd)
diff --git a/rdma/res.h b/rdma/res.h
index 95d88a3a..89dd818a 100644
--- a/rdma/res.h
+++ b/rdma/res.h
@@ -112,12 +112,9 @@ char *get_task_name(uint32_t pid);
 void print_dev(struct rd *rd, uint32_t idx, const char *name);
 void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
 		struct nlattr **nla_line);
-void print_users(struct rd *rd, uint64_t val);
 void print_key(struct rd *rd, const char *name, uint64_t val);
 void res_print_uint(struct rd *rd, const char *name, uint64_t val);
-void print_pid(struct rd *rd, uint32_t val);
 void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line);
 const char *qp_types_to_str(uint8_t idx);
-void print_lqpn(struct rd *rd, uint32_t val);
 
 #endif /* _RDMA_TOOL_RES_H_ */
-- 
2.19.1


^ permalink raw reply related

* [PATCH iproute2-next v1 12/19] rdma: Simplify CM_ID print code
From: Leon Romanovsky @ 2019-02-20  7:21 UTC (permalink / raw)
  To: David Ahern; +Cc: Leon Romanovsky, netdev, RDMA mailing list, Stephen Hemminger
In-Reply-To: <20190220072136.3840-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Refactor our the CM_ID print code.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/res-cmid.c | 246 ++++++++++++++++++++++++------------------------
 1 file changed, 124 insertions(+), 122 deletions(-)

diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c
index 5eea7a6b..12d1acee 100644
--- a/rdma/res-cmid.c
+++ b/rdma/res-cmid.c
@@ -108,11 +108,130 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)
 	return 0;
 }
 
+static int res_cm_id_line(struct rd *rd, const char *name, int idx,
+			  struct nlattr *nla_entry)
+{
+	struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+	char src_addr_str[INET6_ADDRSTRLEN];
+	char dst_addr_str[INET6_ADDRSTRLEN];
+	uint16_t src_port, dst_port;
+	uint32_t port = 0, pid = 0;
+	uint8_t type = 0, state;
+	uint32_t lqpn = 0, ps;
+	uint32_t cm_idn = 0;
+	char *comm = NULL;
+	int err;
+
+	err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+	if (err != MNL_CB_OK)
+		return MNL_CB_ERROR;
+
+	if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
+	    !nla_line[RDMA_NLDEV_ATTR_RES_PS] ||
+	    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+	     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+		return MNL_CB_ERROR;
+	}
+
+	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
+		port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
+
+	if (port && port != rd->port_idx)
+		goto out;
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN]) {
+		lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
+		if (rd_check_is_filtered(rd, "lqpn", lqpn))
+			goto out;
+	}
+	if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) {
+		type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
+		if (rd_check_is_string_filtered(rd, "qp-type",
+						qp_types_to_str(type)))
+			goto out;
+	}
+
+	ps = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PS]);
+	if (rd_check_is_string_filtered(rd, "ps", cm_id_ps_to_str(ps)))
+		goto out;
+
+	state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
+	if (rd_check_is_string_filtered(rd, "state", cm_id_state_to_str(state)))
+		goto out;
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]) {
+		if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR],
+			    src_addr_str, &src_port))
+			goto out;
+		if (rd_check_is_string_filtered(rd, "src-addr", src_addr_str))
+			goto out;
+		if (rd_check_is_filtered(rd, "src-port", src_port))
+			goto out;
+	}
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]) {
+		if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR],
+			    dst_addr_str, &dst_port))
+			goto out;
+		if (rd_check_is_string_filtered(rd, "dst-addr", dst_addr_str))
+			goto out;
+		if (rd_check_is_filtered(rd, "dst-port", dst_port))
+			goto out;
+	}
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+		pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+		comm = get_task_name(pid);
+	}
+
+	if (rd_check_is_filtered(rd, "pid", pid))
+		goto out;
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
+		cm_idn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
+	if (rd_check_is_filtered(rd, "cm-idn", cm_idn))
+		goto out;
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+		/* discard const from mnl_attr_get_str */
+		comm = (char *)mnl_attr_get_str(
+			nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+	}
+
+	if (rd->json_output)
+		jsonw_start_array(rd->jw);
+
+	print_link(rd, idx, name, port, nla_line);
+	if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
+		res_print_uint(rd, "lqpn", lqpn);
+	if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
+		print_qp_type(rd, type);
+	print_cm_id_state(rd, state);
+	print_ps(rd, ps);
+	res_print_uint(rd, "pid", pid);
+	print_comm(rd, comm, nla_line);
+	if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
+		res_print_uint(rd, "cm-idn", cm_idn);
+
+	if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
+		print_ipaddr(rd, "src-addr", src_addr_str, src_port);
+	if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR])
+		print_ipaddr(rd, "dst-addr", dst_addr_str, dst_port);
+
+	print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
+	newline(rd);
+
+out:	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+		free(comm);
+	return MNL_CB_OK;
+}
+
 int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 {
 	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
 	struct nlattr *nla_table, *nla_entry;
 	struct rd *rd = data;
+	int ret = MNL_CB_OK;
 	const char *name;
 	int idx;
 
@@ -124,129 +243,12 @@ int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)
 	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
 	idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
 	nla_table = tb[RDMA_NLDEV_ATTR_RES_CM_ID];
+
 	mnl_attr_for_each_nested(nla_entry, nla_table) {
-		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
-		char src_addr_str[INET6_ADDRSTRLEN];
-		char dst_addr_str[INET6_ADDRSTRLEN];
-		uint16_t src_port, dst_port;
-		uint32_t port = 0, pid = 0;
-		uint8_t type = 0, state;
-		uint32_t lqpn = 0, ps;
-		uint32_t cm_idn = 0;
-		char *comm = NULL;
-		int err;
-
-		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
-		if (err != MNL_CB_OK)
-			return -EINVAL;
+		ret = res_cm_id_line(rd, name, idx, nla_entry);
 
-		if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE] ||
-		    !nla_line[RDMA_NLDEV_ATTR_RES_PS] ||
-		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
-		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
-			return MNL_CB_ERROR;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-			port = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]);
-
-		if (port && port != rd->port_idx)
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN]) {
-			lqpn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-			if (rd_check_is_filtered(rd, "lqpn", lqpn))
-				continue;
-		}
-		if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) {
-			type = mnl_attr_get_u8(
-				nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-			if (rd_check_is_string_filtered(rd, "qp-type",
-							qp_types_to_str(type)))
-				continue;
-		}
-
-		ps = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PS]);
-		if (rd_check_is_string_filtered(rd, "ps", cm_id_ps_to_str(ps)))
-			continue;
-
-		state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-		if (rd_check_is_string_filtered(rd, "state",
-						cm_id_state_to_str(state)))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]) {
-			if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR],
-				    src_addr_str, &src_port))
-				continue;
-			if (rd_check_is_string_filtered(rd, "src-addr",
-							src_addr_str))
-				continue;
-			if (rd_check_is_filtered(rd, "src-port", src_port))
-				continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]) {
-			if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR],
-				    dst_addr_str, &dst_port))
-				continue;
-			if (rd_check_is_string_filtered(rd, "dst-addr",
-							dst_addr_str))
-				continue;
-			if (rd_check_is_filtered(rd, "dst-port", dst_port))
-				continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
-			pid = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_PID]);
-			comm = get_task_name(pid);
-		}
-
-		if (rd_check_is_filtered(rd, "pid", pid)) {
-			free(comm);
-			continue;
-		}
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
-			cm_idn = mnl_attr_get_u32(
-				nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
-		if (rd_check_is_filtered(rd, "cm-idn", cm_idn))
-			continue;
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
-			/* discard const from mnl_attr_get_str */
-			comm = (char *)mnl_attr_get_str(
-				nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-		}
-
-		if (rd->json_output)
-			jsonw_start_array(rd->jw);
-
-		print_link(rd, idx, name, port, nla_line);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
-			res_print_uint(rd, "lqpn", lqpn);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
-			print_qp_type(rd, type);
-		print_cm_id_state(rd, state);
-		print_ps(rd, ps);
-		res_print_uint(rd, "pid", pid);
-		print_comm(rd, comm, nla_line);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
-			res_print_uint(rd, "cm-idn", cm_idn);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
-			print_ipaddr(rd, "src-addr", src_addr_str, src_port);
-		if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR])
-			print_ipaddr(rd, "dst-addr", dst_addr_str, dst_port);
-
-		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
-			free(comm);
-
-		print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
-		newline(rd);
+		if (ret != MNL_CB_OK)
+			break;
 	}
-	return MNL_CB_OK;
+	return ret;
 }
-- 
2.19.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox