linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lang Yu <Lang.Yu@amd.com>
To: Iouri Tarassov <iourit@linux.microsoft.com>
Cc: <linux-hyperv@vger.kernel.org>, Lang Yu <Lang.Yu@amd.com>
Subject: [PATCH] drivers: hv: dxgkrnl: Allow user to specify CPU VA for device allocation
Date: Wed, 27 Dec 2023 11:49:50 +0800	[thread overview]
Message-ID: <20231227034950.1975922-1-Lang.Yu@amd.com> (raw)

The movtivation is we want to unify CPU VA and GPU VA.

Signed-off-by: Lang Yu <Lang.Yu@amd.com>
---
 drivers/hv/dxgkrnl/dxgvmbus.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/hv/dxgkrnl/dxgvmbus.c b/drivers/hv/dxgkrnl/dxgvmbus.c
index 9320bede3a0a..a4bca27a7cc8 100644
--- a/drivers/hv/dxgkrnl/dxgvmbus.c
+++ b/drivers/hv/dxgkrnl/dxgvmbus.c
@@ -580,7 +580,7 @@ int dxg_unmap_iospace(void *va, u32 size)
 	return 0;
 }
 
-static u8 *dxg_map_iospace(u64 iospace_address, u32 size,
+static u8 *dxg_map_iospace(u64 iospace_address, u64 user_va, u32 size,
 			   unsigned long protection, bool cached)
 {
 	struct vm_area_struct *vma;
@@ -594,7 +594,12 @@ static u8 *dxg_map_iospace(u64 iospace_address, u32 size,
 		return NULL;
 	}
 
-	va = vm_mmap(NULL, 0, size, protection, MAP_SHARED | MAP_ANONYMOUS, 0);
+	if (user_va)
+		va = vm_mmap(untagged_addr(user_va), 0, size, protection,
+			     MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, 0);
+	else
+		va = vm_mmap(NULL, 0, size, protection,
+			     MAP_SHARED | MAP_ANONYMOUS, 0);
 	if ((long)va <= 0) {
 		DXG_ERR("vm_mmap failed %lx %d", va, size);
 		return NULL;
@@ -789,9 +794,8 @@ int dxgvmb_send_open_sync_object_nt(struct dxgprocess *process,
 
 	args->sync_object = result.sync_object;
 	if (syncobj->monitored_fence) {
-		void *va = dxg_map_iospace(result.guest_cpu_physical_address,
-					   PAGE_SIZE, PROT_READ | PROT_WRITE,
-					   true);
+		void *va = dxg_map_iospace(result.guest_cpu_physical_address, 0,
+					   PAGE_SIZE, PROT_READ | PROT_WRITE, true);
 		if (va == NULL) {
 			ret = -ENOMEM;
 			goto cleanup;
@@ -1315,8 +1319,8 @@ int dxgvmb_send_create_paging_queue(struct dxgprocess *process,
 	args->paging_queue = result.paging_queue;
 	args->sync_object = result.sync_object;
 	args->fence_cpu_virtual_address =
-	    dxg_map_iospace(result.fence_storage_physical_address, PAGE_SIZE,
-			    PROT_READ | PROT_WRITE, true);
+	    dxg_map_iospace(result.fence_storage_physical_address, 0,
+			    PAGE_SIZE, PROT_READ | PROT_WRITE, true);
 	if (args->fence_cpu_virtual_address == NULL) {
 		ret = -ENOMEM;
 		goto cleanup;
@@ -2867,7 +2871,7 @@ dxgvmb_send_create_sync_object(struct dxgprocess *process,
 	}
 
 	if (syncobj->monitored_fence) {
-		va = dxg_map_iospace(result.fence_storage_address, PAGE_SIZE,
+		va = dxg_map_iospace(result.fence_storage_address, 0, PAGE_SIZE,
 				     PROT_READ | PROT_WRITE, true);
 		if (va == NULL) {
 			ret = -ENOMEM;
@@ -3156,7 +3160,7 @@ int dxgvmb_send_lock2(struct dxgprocess *process,
 		} else {
 			u64 offset = (u64)result.cpu_visible_buffer_offset;
 
-			args->data = dxg_map_iospace(offset,
+			args->data = dxg_map_iospace(offset, args->data,
 					alloc->num_pages << PAGE_SHIFT,
 					PROT_READ | PROT_WRITE, alloc->cached);
 			if (args->data) {
@@ -3712,7 +3716,7 @@ int dxgvmb_send_create_hwqueue(struct dxgprocess *process,
 	}
 
 	hwqueue->progress_fence_mapped_address =
-		dxg_map_iospace((u64)command->hwqueue_progress_fence_cpuva,
+		dxg_map_iospace((u64)command->hwqueue_progress_fence_cpuva, 0,
 				PAGE_SIZE, PROT_READ | PROT_WRITE, true);
 	if (hwqueue->progress_fence_mapped_address == NULL) {
 		ret = -ENOMEM;
-- 
2.25.1


             reply	other threads:[~2023-12-27  3:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-27  3:49 Lang Yu [this message]
2024-01-16 13:58 ` [PATCH] drivers: hv: dxgkrnl: Allow user to specify CPU VA for device allocation Yu, Lang
2024-01-17  2:53   ` Wei Liu
2024-01-17  2:59     ` Yu, Lang
2024-01-17  3:02       ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231227034950.1975922-1-Lang.Yu@amd.com \
    --to=lang.yu@amd.com \
    --cc=iourit@linux.microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).