linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page
@ 2023-04-08 21:34 Dexuan Cui
  2023-04-10  4:28 ` Jinank Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dexuan Cui @ 2023-04-08 21:34 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, linux-hyperv, linux-kernel,
	mikelley

The post_msg_page was introduced in 2014 in
commit b29ef3546aec ("Drivers: hv: vmbus: Cleanup hv_post_message()")

Commit 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") introduced
the hyperv_pcpu_input_arg in 2018, which can be used in hv_post_message().

Remove post_msg_page to simplify the code a little bit.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/hv.c           | 20 +++++---------------
 drivers/hv/hyperv_vmbus.h |  4 ----
 2 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 8b0dd8e5244d7..30bf122a502ae 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -84,14 +84,15 @@ int hv_post_message(union hv_connection_id connection_id,
 		  void *payload, size_t payload_size)
 {
 	struct hv_input_post_message *aligned_msg;
-	struct hv_per_cpu_context *hv_cpu;
+	unsigned long flags;
 	u64 status;
 
 	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
 		return -EMSGSIZE;
 
-	hv_cpu = get_cpu_ptr(hv_context.cpu_context);
-	aligned_msg = hv_cpu->post_msg_page;
+	local_irq_save(flags);
+
+	aligned_msg = *this_cpu_ptr(hyperv_pcpu_input_arg);
 	aligned_msg->connectionid = connection_id;
 	aligned_msg->reserved = 0;
 	aligned_msg->message_type = message_type;
@@ -106,11 +107,7 @@ int hv_post_message(union hv_connection_id connection_id,
 		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
 				aligned_msg, NULL);
 
-	/* Preemption must remain disabled until after the hypercall
-	 * so some other thread can't get scheduled onto this cpu and
-	 * corrupt the per-cpu post_msg_page
-	 */
-	put_cpu_ptr(hv_cpu);
+	local_irq_restore(flags);
 
 	return hv_result(status);
 }
@@ -162,12 +159,6 @@ int hv_synic_alloc(void)
 				goto err;
 			}
 		}
-
-		hv_cpu->post_msg_page = (void *)get_zeroed_page(GFP_ATOMIC);
-		if (hv_cpu->post_msg_page == NULL) {
-			pr_err("Unable to allocate post msg page\n");
-			goto err;
-		}
 	}
 
 	return 0;
@@ -190,7 +181,6 @@ void hv_synic_free(void)
 
 		free_page((unsigned long)hv_cpu->synic_event_page);
 		free_page((unsigned long)hv_cpu->synic_message_page);
-		free_page((unsigned long)hv_cpu->post_msg_page);
 	}
 
 	kfree(hv_context.hv_numa_map);
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index dc673edf053c3..d8322049ecd08 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -122,10 +122,6 @@ enum {
 struct hv_per_cpu_context {
 	void *synic_message_page;
 	void *synic_event_page;
-	/*
-	 * buffer to post messages to the host.
-	 */
-	void *post_msg_page;
 
 	/*
 	 * Starting with win8, we can take channel interrupts on any CPU;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page
  2023-04-08 21:34 [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page Dexuan Cui
@ 2023-04-10  4:28 ` Jinank Jain
  2023-04-11 17:24 ` Michael Kelley (LINUX)
  2023-04-13  1:19 ` Wei Liu
  2 siblings, 0 replies; 5+ messages in thread
From: Jinank Jain @ 2023-04-10  4:28 UTC (permalink / raw)
  To: Dexuan Cui, kys, haiyangz, wei.liu, linux-hyperv, linux-kernel,
	mikelley

Reviewed-by: Jinank Jain <jinankjain@linux.microsoft.com>

On 4/9/2023 3:04 AM, Dexuan Cui wrote:
> The post_msg_page was introduced in 2014 in
> commit b29ef3546aec ("Drivers: hv: vmbus: Cleanup hv_post_message()")
>
> Commit 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") introduced
> the hyperv_pcpu_input_arg in 2018, which can be used in hv_post_message().
>
> Remove post_msg_page to simplify the code a little bit.
>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
>   drivers/hv/hv.c           | 20 +++++---------------
>   drivers/hv/hyperv_vmbus.h |  4 ----
>   2 files changed, 5 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index 8b0dd8e5244d7..30bf122a502ae 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -84,14 +84,15 @@ int hv_post_message(union hv_connection_id connection_id,
>   		  void *payload, size_t payload_size)
>   {
>   	struct hv_input_post_message *aligned_msg;
> -	struct hv_per_cpu_context *hv_cpu;
> +	unsigned long flags;
>   	u64 status;
>   
>   	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
>   		return -EMSGSIZE;
>   
> -	hv_cpu = get_cpu_ptr(hv_context.cpu_context);
> -	aligned_msg = hv_cpu->post_msg_page;
> +	local_irq_save(flags);
> +
> +	aligned_msg = *this_cpu_ptr(hyperv_pcpu_input_arg);
>   	aligned_msg->connectionid = connection_id;
>   	aligned_msg->reserved = 0;
>   	aligned_msg->message_type = message_type;
> @@ -106,11 +107,7 @@ int hv_post_message(union hv_connection_id connection_id,
>   		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
>   				aligned_msg, NULL);
>   
> -	/* Preemption must remain disabled until after the hypercall
> -	 * so some other thread can't get scheduled onto this cpu and
> -	 * corrupt the per-cpu post_msg_page
> -	 */
> -	put_cpu_ptr(hv_cpu);
> +	local_irq_restore(flags);
>   
>   	return hv_result(status);
>   }
> @@ -162,12 +159,6 @@ int hv_synic_alloc(void)
>   				goto err;
>   			}
>   		}
> -
> -		hv_cpu->post_msg_page = (void *)get_zeroed_page(GFP_ATOMIC);
> -		if (hv_cpu->post_msg_page == NULL) {
> -			pr_err("Unable to allocate post msg page\n");
> -			goto err;
> -		}
>   	}
>   
>   	return 0;
> @@ -190,7 +181,6 @@ void hv_synic_free(void)
>   
>   		free_page((unsigned long)hv_cpu->synic_event_page);
>   		free_page((unsigned long)hv_cpu->synic_message_page);
> -		free_page((unsigned long)hv_cpu->post_msg_page);
>   	}
>   
>   	kfree(hv_context.hv_numa_map);
> diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
> index dc673edf053c3..d8322049ecd08 100644
> --- a/drivers/hv/hyperv_vmbus.h
> +++ b/drivers/hv/hyperv_vmbus.h
> @@ -122,10 +122,6 @@ enum {
>   struct hv_per_cpu_context {
>   	void *synic_message_page;
>   	void *synic_event_page;
> -	/*
> -	 * buffer to post messages to the host.
> -	 */
> -	void *post_msg_page;
>   
>   	/*
>   	 * Starting with win8, we can take channel interrupts on any CPU;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page
  2023-04-08 21:34 [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page Dexuan Cui
  2023-04-10  4:28 ` Jinank Jain
@ 2023-04-11 17:24 ` Michael Kelley (LINUX)
  2023-04-13  1:20   ` Wei Liu
  2023-04-13  1:19 ` Wei Liu
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Kelley (LINUX) @ 2023-04-11 17:24 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org

From: Dexuan Cui <decui@microsoft.com> Sent: Saturday, April 8, 2023 2:35 PM
> 
> The post_msg_page was introduced in 2014 in
> commit b29ef3546aec ("Drivers: hv: vmbus: Cleanup hv_post_message()")
> 
> Commit 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") introduced
> the hyperv_pcpu_input_arg in 2018, which can be used in hv_post_message().
> 
> Remove post_msg_page to simplify the code a little bit.
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
>  drivers/hv/hv.c           | 20 +++++---------------
>  drivers/hv/hyperv_vmbus.h |  4 ----
>  2 files changed, 5 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index 8b0dd8e5244d7..30bf122a502ae 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -84,14 +84,15 @@ int hv_post_message(union hv_connection_id connection_id,
>  		  void *payload, size_t payload_size)
>  {
>  	struct hv_input_post_message *aligned_msg;
> -	struct hv_per_cpu_context *hv_cpu;
> +	unsigned long flags;
>  	u64 status;
> 
>  	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
>  		return -EMSGSIZE;
> 
> -	hv_cpu = get_cpu_ptr(hv_context.cpu_context);
> -	aligned_msg = hv_cpu->post_msg_page;
> +	local_irq_save(flags);
> +
> +	aligned_msg = *this_cpu_ptr(hyperv_pcpu_input_arg);
>  	aligned_msg->connectionid = connection_id;
>  	aligned_msg->reserved = 0;
>  	aligned_msg->message_type = message_type;
> @@ -106,11 +107,7 @@ int hv_post_message(union hv_connection_id connection_id,
>  		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
>  				aligned_msg, NULL);
> 
> -	/* Preemption must remain disabled until after the hypercall
> -	 * so some other thread can't get scheduled onto this cpu and
> -	 * corrupt the per-cpu post_msg_page
> -	 */
> -	put_cpu_ptr(hv_cpu);
> +	local_irq_restore(flags);
> 
>  	return hv_result(status);
>  }
> @@ -162,12 +159,6 @@ int hv_synic_alloc(void)
>  				goto err;
>  			}
>  		}
> -
> -		hv_cpu->post_msg_page = (void *)get_zeroed_page(GFP_ATOMIC);
> -		if (hv_cpu->post_msg_page == NULL) {
> -			pr_err("Unable to allocate post msg page\n");
> -			goto err;
> -		}
>  	}
> 
>  	return 0;
> @@ -190,7 +181,6 @@ void hv_synic_free(void)
> 
>  		free_page((unsigned long)hv_cpu->synic_event_page);
>  		free_page((unsigned long)hv_cpu->synic_message_page);
> -		free_page((unsigned long)hv_cpu->post_msg_page);
>  	}
> 
>  	kfree(hv_context.hv_numa_map);
> diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
> index dc673edf053c3..d8322049ecd08 100644
> --- a/drivers/hv/hyperv_vmbus.h
> +++ b/drivers/hv/hyperv_vmbus.h
> @@ -122,10 +122,6 @@ enum {
>  struct hv_per_cpu_context {
>  	void *synic_message_page;
>  	void *synic_event_page;
> -	/*
> -	 * buffer to post messages to the host.
> -	 */
> -	void *post_msg_page;
> 
>  	/*
>  	 * Starting with win8, we can take channel interrupts on any CPU;
> --
> 2.25.1

This looks good.  Glad to have this simplification done!

FWIW, this patch will cause conflicts with your TDX patch series.  If this
patch goes first, then you'll have merge errors with the TDX patches.
If the TDX series goes first, then this patch will have merge errors.  And
per my comments on Patch 5 of your TDX series, eliminating the
post_msg_page will simplify the error cleanup code in hv_synic_alloc().
It seems like making this patch part of the TDX series would be helpful
all around.

Reviewed-by: Michael Kelley

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page
  2023-04-08 21:34 [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page Dexuan Cui
  2023-04-10  4:28 ` Jinank Jain
  2023-04-11 17:24 ` Michael Kelley (LINUX)
@ 2023-04-13  1:19 ` Wei Liu
  2 siblings, 0 replies; 5+ messages in thread
From: Wei Liu @ 2023-04-13  1:19 UTC (permalink / raw)
  To: Dexuan Cui; +Cc: kys, haiyangz, wei.liu, linux-hyperv, linux-kernel, mikelley

On Sat, Apr 08, 2023 at 02:34:41PM -0700, Dexuan Cui wrote:
> The post_msg_page was introduced in 2014 in
> commit b29ef3546aec ("Drivers: hv: vmbus: Cleanup hv_post_message()")
> 
> Commit 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") introduced
> the hyperv_pcpu_input_arg in 2018, which can be used in hv_post_message().
> 
> Remove post_msg_page to simplify the code a little bit.
> 
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Applied to hyperv-next.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page
  2023-04-11 17:24 ` Michael Kelley (LINUX)
@ 2023-04-13  1:20   ` Wei Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Wei Liu @ 2023-04-13  1:20 UTC (permalink / raw)
  To: Michael Kelley (LINUX)
  Cc: Dexuan Cui, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org

On Tue, Apr 11, 2023 at 05:24:31PM +0000, Michael Kelley (LINUX) wrote:
> > --
> > 2.25.1
> 
> This looks good.  Glad to have this simplification done!
> 
> FWIW, this patch will cause conflicts with your TDX patch series.  If this
> patch goes first, then you'll have merge errors with the TDX patches.
> If the TDX series goes first, then this patch will have merge errors.  And
> per my comments on Patch 5 of your TDX series, eliminating the
> post_msg_page will simplify the error cleanup code in hv_synic_alloc().
> It seems like making this patch part of the TDX series would be helpful
> all around.

Seeing that there are pending comments in the TDX series, I've applied
this patch. TDX series can be rebased.

Thanks,
Wei.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-13  1:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-08 21:34 [PATCH] Drivers: hv: vmbus: Remove the per-CPU post_msg_page Dexuan Cui
2023-04-10  4:28 ` Jinank Jain
2023-04-11 17:24 ` Michael Kelley (LINUX)
2023-04-13  1:20   ` Wei Liu
2023-04-13  1:19 ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).