Index: openib/src/userspace/libibverbs/examples/rc_pingpong.c
===================================================================
--- openib/src/userspace/libibverbs/examples/rc_pingpong.c	(revision 92)
+++ openib/src/userspace/libibverbs/examples/rc_pingpong.c	(working copy)
@@ -281,7 +281,7 @@
 
 static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
 					    int rx_depth, int port,
-					    int use_event)
+					    int use_event, int pkey_idx)
 {
 	struct pingpong_context *ctx;
 
@@ -359,7 +359,7 @@
 		struct ibv_qp_attr attr;
 
 		attr.qp_state        = IBV_QPS_INIT;
-		attr.pkey_index      = 0;
+		attr.pkey_index      = pkey_idx;
 		attr.port_num        = port;
 		attr.qp_access_flags = 0;
 
@@ -432,6 +432,7 @@
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges (default 1000)\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
+	printf("  -k, --pkey_idx=<index> change the pkey index to use (default 0)\n");
 }
 
 int main(int argc, char *argv[])
@@ -453,6 +454,7 @@
 	int                      use_event = 0;
 	int                      routs;
 	int                      rcnt, scnt;
+	int                      pkey_idx = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -468,10 +470,11 @@
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
+			{ .name = "pkey_idx", .has_arg = 1, .val = 'k' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:ek:", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -519,6 +522,10 @@
 			++use_event;
 			break;
 
+		case 'k':
+			pkey_idx = strtol(optarg, NULL, 0);
+			break;
+
 		default:
 			usage(argv[0]);
 			return 1;
@@ -556,7 +563,7 @@
 		}
 	}
 
-	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event);
+	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event, pkey_idx);
 	if (!ctx)
 		return 1;
 
Index: openib/src/userspace/libibverbs/examples/srq_pingpong.c
===================================================================
--- openib/src/userspace/libibverbs/examples/srq_pingpong.c	(revision 92)
+++ openib/src/userspace/libibverbs/examples/srq_pingpong.c	(working copy)
@@ -315,7 +315,7 @@
 
 static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
 					    int num_qp, int rx_depth, int port,
-					    int use_event)
+					    int use_event, int pkey_idx)
 {
 	struct pingpong_context *ctx;
 	int i;
@@ -409,7 +409,7 @@
 		struct ibv_qp_attr attr;
 
 		attr.qp_state        = IBV_QPS_INIT;
-		attr.pkey_index      = 0;
+		attr.pkey_index      = pkey_idx;
 		attr.port_num        = port;
 		attr.qp_access_flags = 0;
 
@@ -494,6 +494,7 @@
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges per QP(default 1000)\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
+	printf("  -k, --pkey_idx=<index> change the pkey index to use (default 0)\n");
 }
 
 int main(int argc, char *argv[])
@@ -519,6 +520,7 @@
 	int                      rcnt, scnt;
 	int			 num_wc;
 	int                      i;
+	int                      pkey_idx = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -535,10 +537,11 @@
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
+			{ .name = "pkey_idx", .has_arg = 1, .val = 'k' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:q:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:q:r:n:ek:", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -590,6 +593,10 @@
 			++use_event;
 			break;
 
+		case 'k':
+			pkey_idx = strtol(optarg, NULL, 0);
+			break;
+
 		default:
 			usage(argv[0]);
 			return 1;
@@ -637,7 +644,7 @@
 		}
 	}
 
-	ctx = pp_init_ctx(ib_dev, size, num_qp, rx_depth, ib_port, use_event);
+	ctx = pp_init_ctx(ib_dev, size, num_qp, rx_depth, ib_port, use_event, pkey_idx);
 	if (!ctx)
 		return 1;
 
Index: openib/src/userspace/libibverbs/examples/uc_pingpong.c
===================================================================
--- openib/src/userspace/libibverbs/examples/uc_pingpong.c	(revision 92)
+++ openib/src/userspace/libibverbs/examples/uc_pingpong.c	(working copy)
@@ -269,7 +269,7 @@
 
 static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
 					    int rx_depth, int port,
-					    int use_event)
+					    int use_event, int pkey_idx)
 {
 	struct pingpong_context *ctx;
 
@@ -347,7 +347,7 @@
 		struct ibv_qp_attr attr;
 
 		attr.qp_state        = IBV_QPS_INIT;
-		attr.pkey_index      = 0;
+		attr.pkey_index      = pkey_idx;
 		attr.port_num        = port;
 		attr.qp_access_flags = 0;
 
@@ -420,6 +420,7 @@
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges (default 1000)\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
+	printf("  -k, --pkey_idx=<index> change the pkey index to use (default 0)\n");
 }
 
 int main(int argc, char *argv[])
@@ -441,6 +442,7 @@
 	int                      use_event = 0;
 	int                      routs;
 	int                      rcnt, scnt;
+	int                      pkey_idx = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -456,10 +458,11 @@
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
+			{ .name = "pkey_idx", .has_arg = 1, .val = 'k' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:m:r:n:ek:", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -507,6 +510,10 @@
 			++use_event;
 			break;
 
+		case 'k':
+			pkey_idx = strtol(optarg, NULL, 0);
+			break;
+
 		default:
 			usage(argv[0]);
 			return 1;
@@ -544,7 +551,7 @@
 		}
 	}
 
-	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event);
+	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event, pkey_idx);
 	if (!ctx)
 		return 1;
 
Index: openib/src/userspace/libibverbs/examples/ud_pingpong.c
===================================================================
--- openib/src/userspace/libibverbs/examples/ud_pingpong.c	(revision 92)
+++ openib/src/userspace/libibverbs/examples/ud_pingpong.c	(working copy)
@@ -270,7 +270,7 @@
 
 static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
 					    int rx_depth, int port,
-					    int use_event)
+					    int use_event, int pkey_idx)
 {
 	struct pingpong_context *ctx;
 
@@ -348,7 +348,7 @@
 		struct ibv_qp_attr attr;
 
 		attr.qp_state        = IBV_QPS_INIT;
-		attr.pkey_index      = 0;
+		attr.pkey_index      = pkey_idx;
 		attr.port_num        = port;
 		attr.qkey            = 0x11111111;
 
@@ -427,6 +427,7 @@
 	printf("  -r, --rx-depth=<dep>   number of receives to post at a time (default 500)\n");
 	printf("  -n, --iters=<iters>    number of exchanges (default 1000)\n");
 	printf("  -e, --events           sleep on CQ events (default poll)\n");
+	printf("  -k, --pkey_idx=<index> change the pkey index to use (default 0)\n");
 }
 
 int main(int argc, char *argv[])
@@ -447,6 +448,7 @@
 	int                      use_event = 0;
 	int                      routs;
 	int                      rcnt, scnt;
+	int                      pkey_idx = 0;
 
 	srand48(getpid() * time(NULL));
 
@@ -461,10 +463,11 @@
 			{ .name = "rx-depth", .has_arg = 1, .val = 'r' },
 			{ .name = "iters",    .has_arg = 1, .val = 'n' },
 			{ .name = "events",   .has_arg = 0, .val = 'e' },
+			{ .name = "pkey_idx", .has_arg = 1, .val = 'k' },
 			{ 0 }
 		};
 
-		c = getopt_long(argc, argv, "p:d:i:s:r:n:e", long_options, NULL);
+		c = getopt_long(argc, argv, "p:d:i:s:r:n:ek:", long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -505,6 +508,10 @@
 			++use_event;
 			break;
 
+		case 'k':
+			pkey_idx = strtol(optarg, NULL, 0);
+			break;
+
 		default:
 			usage(argv[0]);
 			return 1;
@@ -542,7 +549,7 @@
 		}
 	}
 
-	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event);
+	ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event, pkey_idx);
 	if (!ctx)
 		return 1;
 
