--- v4
+++ vrfc
@@ -1,36 +1,26 @@
From: Tianyu Lan <Tianyu.Lan@microsoft.com>
-The monitor pages in the CHANNELMSG_INITIATE_CONTACT msg are shared
-with host in Isolation VM and so it's necessary to use hvcall to set
-them visible to host. In Isolation VM with AMD SEV SNP, the access
-address should be in the extra space which is above shared gpa
-boundary. So remap these pages into the extra address(pa +
-shared_gpa_boundary).
+The physical address of monitor pages in the CHANNELMSG_INITIATE_CONTACT
+msg should be in the extra address space for SNP support and these
+pages also should be accessed via the extra address space inside Linux
+guest and remap the extra address by ioremap function.
Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
- drivers/hv/connection.c | 65 +++++++++++++++++++++++++++++++++++++++
+ drivers/hv/connection.c | 62 +++++++++++++++++++++++++++++++++++++++
drivers/hv/hyperv_vmbus.h | 1 +
- 2 files changed, 66 insertions(+)
+ 2 files changed, 63 insertions(+)
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
-index 186fd4c8acd4..a32bde143e4c 100644
+index 79bca653dce9..a0be9c11d737 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
-@@ -19,6 +19,7 @@
- #include <linux/vmalloc.h>
- #include <linux/hyperv.h>
- #include <linux/export.h>
-+#include <linux/io.h>
- #include <asm/mshyperv.h>
-
- #include "hyperv_vmbus.h"
-@@ -104,6 +105,12 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
+@@ -101,6 +101,12 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
+
-+ if (hv_is_isolation_supported()) {
++ if (hv_isolation_type_snp()) {
+ msg->monitor_page1 += ms_hyperv.shared_gpa_boundary;
+ msg->monitor_page2 += ms_hyperv.shared_gpa_boundary;
+ }
@@ -38,26 +28,24 @@
msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU);
/*
-@@ -148,6 +155,31 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
+@@ -145,6 +151,29 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
return -ECONNREFUSED;
}
-+ if (hv_is_isolation_supported()) {
++ if (hv_isolation_type_snp()) {
+ vmbus_connection.monitor_pages_va[0]
+ = vmbus_connection.monitor_pages[0];
+ vmbus_connection.monitor_pages[0]
-+ = memremap(msg->monitor_page1, HV_HYP_PAGE_SIZE,
-+ MEMREMAP_WB);
++ = ioremap_cache(msg->monitor_page1, HV_HYP_PAGE_SIZE);
+ if (!vmbus_connection.monitor_pages[0])
+ return -ENOMEM;
+
+ vmbus_connection.monitor_pages_va[1]
+ = vmbus_connection.monitor_pages[1];
+ vmbus_connection.monitor_pages[1]
-+ = memremap(msg->monitor_page2, HV_HYP_PAGE_SIZE,
-+ MEMREMAP_WB);
++ = ioremap_cache(msg->monitor_page2, HV_HYP_PAGE_SIZE);
+ if (!vmbus_connection.monitor_pages[1]) {
-+ memunmap(vmbus_connection.monitor_pages[0]);
++ vunmap(vmbus_connection.monitor_pages[0]);
+ return -ENOMEM;
+ }
+
@@ -70,7 +58,7 @@
return ret;
}
-@@ -159,6 +191,7 @@ int vmbus_connect(void)
+@@ -156,6 +185,7 @@ int vmbus_connect(void)
struct vmbus_channel_msginfo *msginfo = NULL;
int i, ret = 0;
__u32 version;
@@ -78,11 +66,11 @@
/* Initialize the vmbus connection */
vmbus_connection.conn_state = CONNECTING;
-@@ -216,6 +249,16 @@ int vmbus_connect(void)
+@@ -213,6 +243,16 @@ int vmbus_connect(void)
goto cleanup;
}
-+ if (hv_is_isolation_supported()) {
++ if (hv_isolation_type_snp()) {
+ pfn[0] = virt_to_hvpfn(vmbus_connection.monitor_pages[0]);
+ pfn[1] = virt_to_hvpfn(vmbus_connection.monitor_pages[1]);
+ if (hv_mark_gpa_visibility(2, pfn,
@@ -95,7 +83,7 @@
msginfo = kzalloc(sizeof(*msginfo) +
sizeof(struct vmbus_channel_initiate_contact),
GFP_KERNEL);
-@@ -282,6 +325,8 @@ int vmbus_connect(void)
+@@ -279,6 +319,8 @@ int vmbus_connect(void)
void vmbus_disconnect(void)
{
@@ -104,20 +92,20 @@
/*
* First send the unload request to the host.
*/
-@@ -301,6 +346,26 @@ void vmbus_disconnect(void)
+@@ -298,6 +340,26 @@ void vmbus_disconnect(void)
vmbus_connection.int_page = NULL;
}
-+ if (hv_is_isolation_supported()) {
++ if (hv_isolation_type_snp()) {
+ if (vmbus_connection.monitor_pages_va[0]) {
-+ memunmap(vmbus_connection.monitor_pages[0]);
++ vunmap(vmbus_connection.monitor_pages[0]);
+ vmbus_connection.monitor_pages[0]
+ = vmbus_connection.monitor_pages_va[0];
+ vmbus_connection.monitor_pages_va[0] = NULL;
+ }
+
+ if (vmbus_connection.monitor_pages_va[1]) {
-+ memunmap(vmbus_connection.monitor_pages[1]);
++ vunmap(vmbus_connection.monitor_pages[1]);
+ vmbus_connection.monitor_pages[1]
+ = vmbus_connection.monitor_pages_va[1];
+ vmbus_connection.monitor_pages_va[1] = NULL;
@@ -132,7 +120,7 @@
hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]);
vmbus_connection.monitor_pages[0] = NULL;
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
-index 42f3d9d123a1..40bc0eff6665 100644
+index 9416e09ebd58..0778add21a9c 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -240,6 +240,7 @@ struct vmbus_connection {