Skip to contentSkip to conversation

Retry infinitely for hypercall

PATCH In review Long Li 4 participants 5 messages Jan 4, 2017 Hyper-V/Azure core and drivers

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH 1/1 Retry infinitely for hypercall

From: Long Li <[email protected]>

Hyper-v host guarantees that a hypercall will succeed. Retry infinitely to avoid returning transient failures to upper layer.

---
 drivers/hv/connection.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hv/connection.c +8 -9
index 6ce8b87..4bcb099 100644
@@ -439,7 +439,6 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 {
 	union hv_connection_id conn_id;
 	int ret = 0;
-	int retries = 0;
 	u32 usec = 1;
 
 	conn_id.asu32 = 0;
@@ -447,10 +446,10 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 
 	/*
 	 * hv_post_message() can have transient failures because of
-	 * insufficient resources. Retry the operation a couple of
-	 * times before giving up.
+	 * insufficient resources. We retry infinitely on these failures
+	 * because host guarantees hypercall will eventually succeed.
 	 */
-	while (retries < 20) {
+	while (1) {
 		ret = hv_post_message(conn_id, 1, buffer, buflen);
 
 		switch (ret) {
@@ -459,11 +458,11 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			 * We could get this if we send messages too
 			 * frequently.
 			 */
-			ret = -EAGAIN;
-			break;
 		case HV_STATUS_INSUFFICIENT_MEMORY:
 		case HV_STATUS_INSUFFICIENT_BUFFERS:
-			ret = -ENOMEM;
+			/*
+			 * Temporary failure out of resources
+			 */
 			break;
 		case HV_STATUS_SUCCESS:
 			return ret;
@@ -472,12 +471,12 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			return -EINVAL;
 		}
 
-		retries++;
 		udelay(usec);
 		if (usec < 2048)
 			usec *= 2;
 	}
-	return ret;
+	/* Impossible to get here */
+	BUG_ON(1);
 }
 
 /*
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Long Li

From: Long Li <[email protected]>

Hyper-v host guarantees that a hypercall will succeed. Retry infinitely to avoid returning transient failures to upper layer.

Please wrap your changelog at the proper column.

And what happens when the hypercall does not succeed? How is the kernel going to recover from that?

Quoted 33 lines
---
 drivers/hv/connection.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hv/connection.c +3 -4
index 6ce8b87..4bcb099 100644
@@ -439,7 +439,6 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 {
 	union hv_connection_id conn_id;
 	int ret = 0;
-	int retries = 0;
 	u32 usec = 1;
 
 	conn_id.asu32 = 0;
@@ -447,10 +446,10 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 
 	/*
 	 * hv_post_message() can have transient failures because of
-	 * insufficient resources. Retry the operation a couple of
-	 * times before giving up.
+	 * insufficient resources. We retry infinitely on these failures
+	 * because host guarantees hypercall will eventually succeed.
 	 */
-	while (retries < 20) {
+	while (1) {
 		ret = hv_post_message(conn_id, 1, buffer, buflen);
 
 		switch (ret) {

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 463

Quoted 5 lines
drivers/hv/connection.c +0 -2
@@ -459,11 +458,11 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			 * We could get this if we send messages too
 			 * frequently.
 			 */
-			ret = -EAGAIN;
-			break;

Document you are falling through please, otherwise someone will "fix" this later.

Quoted 11 lines
drivers/hv/connection.c +3 -1
 		case HV_STATUS_INSUFFICIENT_MEMORY:
 		case HV_STATUS_INSUFFICIENT_BUFFERS:
-			ret = -ENOMEM;
+			/*
+			 * Temporary failure out of resources
+			 */
 			break;
 		case HV_STATUS_SUCCESS:
 			return ret;
@@ -472,12 +471,12 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			return -EINVAL;

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 479

Quoted 10 lines
drivers/hv/connection.c +2 -2
 		}
 
-		retries++;
 		udelay(usec);
 		if (usec < 2048)
 			usec *= 2;
 	}
-	return ret;
+	/* Impossible to get here */
+	BUG_ON(1);

If it is impossible, why do you have this line at all?

What is this trying to solve? Do you need to increase the time spent waiting? We all know things break, please allow the kernel to stay alive if at all possible.

thanks,

greg k-h

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Wednesday, January 4, 2017 12:51 PM
To: Long Li <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH] Retry infinitely for hypercall

Quoted 7 lines
Quoted 3 lines · Long Li

From: Long Li <[email protected]>

Hyper-v host guarantees that a hypercall will succeed. Retry infinitely to

avoid returning transient failures to upper layer.

Please wrap your changelog at the proper column.

Will do in V2.

Quoted 3 lines

And what happens when the hypercall does not succeed? How is the kernel going to recover from that?

Sorry I should have used better wording in the patch. It should be "Retry infinitely on transient failures for hypercall". The host guarantees that it will return something other than transient failures in a reasonable small time frame. I will fix the comment in V2.

Quoted 31 lines
Quoted 31 lines
---
 drivers/hv/connection.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hv/connection.c index renamed from drivers/hv/connection.c +0 -0

6ce8b87..4bcb099 100644

drivers/hv/connection.c +3 -4
@@ -439,7 +439,6 @@ int vmbus_post_msg(void *buffer, size_t buflen)  {
 	union hv_connection_id conn_id;
 	int ret = 0;
-	int retries = 0;
 	u32 usec = 1;
 
 	conn_id.asu32 = 0;
@@ -447,10 +446,10 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 
 	/*
 	 * hv_post_message() can have transient failures because of
-	 * insufficient resources. Retry the operation a couple of
-	 * times before giving up.
+	 * insufficient resources. We retry infinitely on these failures
+	 * because host guarantees hypercall will eventually succeed.
 	 */
-	while (retries < 20) {
+	while (1) {
 		ret = hv_post_message(conn_id, 1, buffer, buflen);
 
Quoted 10 lines

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 463

Quoted 7 lines
drivers/hv/connection.c +0 -2
 		switch (ret) {
@@ -459,11 +458,11 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			 * We could get this if we send messages too
 			 * frequently.
 			 */
-			ret = -EAGAIN;
-			break;

Document you are falling through please, otherwise someone will "fix" this later.

Will add comment in V2.

Quoted 14 lines
Quoted 14 lines
drivers/hv/connection.c +3 -1
 		case HV_STATUS_INSUFFICIENT_MEMORY:
 		case HV_STATUS_INSUFFICIENT_BUFFERS:
-			ret = -ENOMEM;
+			/*
+			 * Temporary failure out of resources
+			 */
 			break;
 		case HV_STATUS_SUCCESS:
 			return ret;
@@ -472,12 +471,12 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			return -EINVAL;
 		}
 
Quoted 10 lines

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 479

Quoted 8 lines
drivers/hv/connection.c +2 -2
-		retries++;
 		udelay(usec);
 		if (usec < 2048)
 			usec *= 2;
 	}
-	return ret;
+	/* Impossible to get here */
+	BUG_ON(1);

If it is impossible, why do you have this line at all?

I will remove this line. There is no way for the code to get here.

Quoted 4 lines

What is this trying to solve? Do you need to increase the time spent waiting? We all know things break, please allow the kernel to stay alive if at all possible.

The purpose is to wait until the host returns a non-transient status code for a hypercall. However, we don't know how many transient failures we are getting before the host returns a final status code. So use the infinite loop to wait until the host returns the final status code.

Thanks for reviewing. I will send V2 to address the comment.

Long

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
In reply to Long Li

Fix the subsystem prefix in the subject.

Quoted 14 lines · Long Li

From: Long Li <[email protected]>

Hyper-v host guarantees that a hypercall will succeed. Retry infinitely to avoid returning transient failures to upper layer.

---
 drivers/hv/connection.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hv/connection.c +0 -0
index 6ce8b87..4bcb099 100644

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 441

Quoted 3 lines
drivers/hv/connection.c +0 -0
@@ -439,7 +439,6 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 {
 	union hv_connection_id conn_id;
 	int ret = 0;

Btw, when you disable GCC's uninitialized variable checking by storing bogus values in "ret", it's eventually going to bite you in the bum. Eventually you're going to get a bug that should have been detected through static analysis if only you hadn't disabled it.

Quoted 19 lines
drivers/hv/connection.c +3 -4
-	int retries = 0;
 	u32 usec = 1;
 
 	conn_id.asu32 = 0;
@@ -447,10 +446,10 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 
 	/*
 	 * hv_post_message() can have transient failures because of
-	 * insufficient resources. Retry the operation a couple of
-	 * times before giving up.
+	 * insufficient resources. We retry infinitely on these failures
+	 * because host guarantees hypercall will eventually succeed.
 	 */
-	while (retries < 20) {
+	while (1) {
 		ret = hv_post_message(conn_id, 1, buffer, buflen);
 
 		switch (ret) {

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 460

Quoted 3 lines
drivers/hv/connection.c +0 -0
@@ -459,11 +458,11 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			 * We could get this if we send messages too
 			 * frequently.
 			 */

Move the comment above the code it's commenting about.

		/* 
		 * We could get INVALID_CONNECTION_ID if we flood the
		 * host with too many messages.
		 */
		case HV_STATUS_INVALID_CONNECTION_ID:
		case HV_STATUS_INSUFFICIENT_MEMORY:
		case HV_STATUS_INSUFFICIENT_BUFFERS:
			break;

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 468

Quoted 11 lines
drivers/hv/connection.c +3 -3
-			ret = -EAGAIN;
-			break;
 		case HV_STATUS_INSUFFICIENT_MEMORY:
 		case HV_STATUS_INSUFFICIENT_BUFFERS:
-			ret = -ENOMEM;
+			/*
+			 * Temporary failure out of resources
+			 */
 			break;
 		case HV_STATUS_SUCCESS:
 			return ret;
			return 0;

Better to be more explicit. When I looked at this I got briefly confused if this function was supposed to return HV_ statuses or standard kernel error codes. It turns out that HV_STATUS_SUCCESS is zero the success returns map directly to linux kernel code for success but it's clearer to be explicit.

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 479

Quoted 12 lines
drivers/hv/connection.c +2 -2
@@ -472,12 +471,12 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			return -EINVAL;
 		}
 
-		retries++;
 		udelay(usec);
 		if (usec < 2048)
 			usec *= 2;
 	}
-	return ret;
+	/* Impossible to get here */
+	BUG_ON(1);

Remove the comment and the BUG_ON().

regards,
dan carpenter

#4 lore raw
Quoted 107 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday, January 4, 2017 1:48 PM
To: Long Li <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH] Retry infinitely for hypercall

Fix the subsystem prefix in the subject.

Quoted 3 lines · Long Li

From: Long Li <[email protected]>

Hyper-v host guarantees that a hypercall will succeed. Retry infinitely to

avoid returning transient failures to upper layer.

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) { · line 440

Quoted 13 lines
---
 drivers/hv/connection.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/hv/connection.c index renamed from drivers/hv/connection.c +0 -0

6ce8b87..4bcb099 100644

drivers/hv/connection.c +0 -0
@@ -439,7 +439,6 @@ int vmbus_post_msg(void *buffer, size_t buflen)  {
 	union hv_connection_id conn_id;
 	int ret = 0;

Btw, when you disable GCC's uninitialized variable checking by storing bogus values in "ret", it's eventually going to bite you in the bum. Eventually you're going to get a bug that should have been detected through static analysis if only you hadn't disabled it.

Quoted 19 lines
drivers/hv/connection.c +3 -4
-	int retries = 0;
 	u32 usec = 1;
 
 	conn_id.asu32 = 0;
@@ -447,10 +446,10 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 
 	/*
 	 * hv_post_message() can have transient failures because of
-	 * insufficient resources. Retry the operation a couple of
-	 * times before giving up.
+	 * insufficient resources. We retry infinitely on these failures
+	 * because host guarantees hypercall will eventually succeed.
 	 */
-	while (retries < 20) {
+	while (1) {
 		ret = hv_post_message(conn_id, 1, buffer, buflen);
 
 		switch (ret) {

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 460

Quoted 3 lines
drivers/hv/connection.c +0 -0
@@ -459,11 +458,11 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			 * We could get this if we send messages too
 			 * frequently.
 			 */

Move the comment above the code it's commenting about.

		/*
		 * We could get INVALID_CONNECTION_ID if we flood the
		 * host with too many messages.
		 */
		case HV_STATUS_INVALID_CONNECTION_ID:
		case HV_STATUS_INSUFFICIENT_MEMORY:
		case HV_STATUS_INSUFFICIENT_BUFFERS:
			break;

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 468

Quoted 11 lines
drivers/hv/connection.c +3 -3
-			ret = -EAGAIN;
-			break;
 		case HV_STATUS_INSUFFICIENT_MEMORY:
 		case HV_STATUS_INSUFFICIENT_BUFFERS:
-			ret = -ENOMEM;
+			/*
+			 * Temporary failure out of resources
+			 */
 			break;
 		case HV_STATUS_SUCCESS:
 			return ret;
			return 0;

Better to be more explicit. When I looked at this I got briefly confused if this function was supposed to return HV_ statuses or standard kernel error codes. It turns out that HV_STATUS_SUCCESS is zero the success returns map directly to linux kernel code for success but it's clearer to be explicit.

drivers/hv/connection.c int vmbus_post_msg(void *buffer, size_t buflen) · line 479

Quoted 12 lines
drivers/hv/connection.c +2 -2
@@ -472,12 +471,12 @@ int vmbus_post_msg(void *buffer, size_t buflen)
 			return -EINVAL;
 		}
 
-		retries++;
 		udelay(usec);
 		if (usec < 2048)
 			usec *= 2;
 	}
-	return ret;
+	/* Impossible to get here */
+	BUG_ON(1);

Remove the comment and the BUG_ON().

Quoted 2 lines

regards,
dan carpenter

Thanks, I will fix those in V2.

Long