Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 May 2019 17:14:09 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r347801 - stable/11/sys/dev/mlx5/mlx5_ib
Message-ID:  <201905161714.x4GHE9AW098638@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu May 16 17:14:08 2019
New Revision: 347801
URL: https://svnweb.freebsd.org/changeset/base/347801

Log:
  MFC r347251:
  Import Linux code to implement mlx5_ib_disassociate_ucontext() in mlx5ib.
  
  Submitted by:	kib@
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c	Thu May 16 17:13:21 2019	(r347800)
+++ stable/11/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c	Thu May 16 17:14:08 2019	(r347801)
@@ -1335,6 +1335,70 @@ static int mlx5_ib_set_vma_data(struct vm_area_struct 
 	return 0;
 }
 
+static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
+{
+	int ret;
+	struct vm_area_struct *vma;
+	struct mlx5_ib_vma_private_data *vma_private, *n;
+	struct mlx5_ib_ucontext *context = to_mucontext(ibcontext);
+	struct task_struct *owning_process  = NULL;
+	struct mm_struct   *owning_mm       = NULL;
+
+	owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID);
+	if (!owning_process)
+		return;
+
+	owning_mm = get_task_mm(owning_process);
+	if (!owning_mm) {
+		pr_info("no mm, disassociate ucontext is pending task termination\n");
+		while (1) {
+			put_task_struct(owning_process);
+			usleep_range(1000, 2000);
+			owning_process = get_pid_task(ibcontext->tgid,
+						      PIDTYPE_PID);
+			if (!owning_process || owning_process->task_thread->
+			    td_proc->p_state == PRS_ZOMBIE) {
+				pr_info("disassociate ucontext done, task was terminated\n");
+				/* in case task was dead need to release the
+				 * task struct.
+				 */
+				if (owning_process)
+					put_task_struct(owning_process);
+				return;
+			}
+		}
+	}
+
+	/* need to protect from a race on closing the vma as part of
+	 * mlx5_ib_vma_close.
+	 */
+	down_write(&owning_mm->mmap_sem);
+	list_for_each_entry_safe(vma_private, n, &context->vma_private_list,
+				 list) {
+		vma = vma_private->vma;
+		ret = zap_vma_ptes(vma, vma->vm_start,
+				   PAGE_SIZE);
+		if (ret == -ENOTSUP) {
+			if (bootverbose)
+				WARN_ONCE(
+	"%s: zap_vma_ptes not implemented for unmanaged mappings", __func__);
+		} else {
+			WARN(ret, "%s: zap_vma_ptes failed, error %d",
+			    __func__, -ret);
+		}
+		/* context going to be destroyed, should
+		 * not access ops any more.
+		 */
+		/* XXXKIB vma->vm_flags &= ~(VM_SHARED | VM_MAYSHARE); */
+		vma->vm_ops = NULL;
+		list_del(&vma_private->list);
+		kfree(vma_private);
+	}
+	up_write(&owning_mm->mmap_sem);
+	mmput(owning_mm);
+	put_task_struct(owning_process);
+}
+
 static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd)
 {
 	switch (cmd) {
@@ -3084,6 +3148,8 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
 		dev->ib_dev.get_vf_stats	= mlx5_ib_get_vf_stats;
 		dev->ib_dev.set_vf_guid		= mlx5_ib_set_vf_guid;
 	}
+
+	dev->ib_dev.disassociate_ucontext = mlx5_ib_disassociate_ucontext;
 
 	mlx5_ib_internal_fill_odp_caps(dev);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905161714.x4GHE9AW098638>