[openib-general] [PATCH] dont create physical mr for user context

Michael S. Tsirkin mst at mellanox.co.il
Tue May 24 05:49:54 PDT 2005


It seems that mthca creates a physical MR for each PD, which would grant
a userspace process access to all physical memory if it can guess the key.
Fix this by adding a "privileged" flag, set only for kernel-level
consumers.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: mthca_main.c
===================================================================
--- mthca_main.c	(revision 2437)
+++ mthca_main.c	(working copy)
@@ -664,6 +664,8 @@ static int __devinit mthca_setup_hca(str
 		goto err_pd_table_free;
 	}
 
+	dev->driver_pd.privileged = 1;
+
 	err = mthca_pd_alloc(dev, &dev->driver_pd);
 	if (err) {
 		mthca_err(dev, "Failed to create driver PD, "
Index: mthca_provider.c
===================================================================
--- mthca_provider.c	(revision 2437)
+++ mthca_provider.c	(working copy)
@@ -379,6 +379,8 @@ static struct ib_pd *mthca_alloc_pd(stru
 	if (!pd)
 		return ERR_PTR(-ENOMEM);
 
+	pd->privileged = !context;
+
 	err = mthca_pd_alloc(to_mdev(ibdev), pd);
 	if (err) {
 		kfree(pd);
Index: mthca_provider.h
===================================================================
--- mthca_provider.h	(revision 2437)
+++ mthca_provider.h	(working copy)
@@ -91,6 +91,7 @@ struct mthca_pd {
 	u32             pd_num;
 	atomic_t        sqp_count;
 	struct mthca_mr ntmr;
+	int             privileged;
 };
 
 struct mthca_eq {
Index: mthca_pd.c
===================================================================
--- mthca_pd.c	(revision 2437)
+++ mthca_pd.c	(working copy)
@@ -48,6 +48,9 @@ int mthca_pd_alloc(struct mthca_dev *dev
 	if (pd->pd_num == -1)
 		return -ENOMEM;
 
+	if (!pd->privileged)
+		return 0;
+
 	err = mthca_mr_alloc_notrans(dev, pd->pd_num,
 				     MTHCA_MPT_FLAG_LOCAL_READ |
 				     MTHCA_MPT_FLAG_LOCAL_WRITE,
@@ -61,7 +64,8 @@ int mthca_pd_alloc(struct mthca_dev *dev
 void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd)
 {
 	might_sleep();
-	mthca_free_mr(dev, &pd->ntmr);
+	if (pd->privileged)
+		mthca_free_mr(dev, &pd->ntmr);
 	mthca_free(&dev->pd_table.alloc, pd->pd_num);
 }
 

-- 
MST - Michael S. Tsirkin



More information about the general mailing list