mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Iouri Tarassov <iourit@linux.microsoft.com>
To: kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, wei.liu@kernel.org,
	linux-hyperv@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, spronovo@microsoft.com,
	spronovo@linux.microsoft.com, gregkh@linuxfoundation.org
Subject: [PATCH v3 22/30] drivers: hv: dxgkrnl: Query video memory information
Date: Tue,  1 Mar 2022 11:46:09 -0800	[thread overview]
Message-ID: <5dadbe959f96e2764a61157eb05f0804a74afb1c.1646163379.git.iourit@linux.microsoft.com> (raw)
In-Reply-To: <719fe06b7cbe9ac12fa4a729e810e3383ab421c1.1646163378.git.iourit@linux.microsoft.com>

Implement the ioctl to query video memory information from the host
(LX_DXQUERYVIDEOMEMORYINFO).

Signed-off-by: Iouri Tarassov <iourit@linux.microsoft.com>
---
 drivers/hv/dxgkrnl/dxgkrnl.h  |  5 +++
 drivers/hv/dxgkrnl/dxgvmbus.c | 64 +++++++++++++++++++++++++++++++++++
 drivers/hv/dxgkrnl/dxgvmbus.h | 14 ++++++++
 drivers/hv/dxgkrnl/ioctl.c    | 50 +++++++++++++++++++++++++++
 include/uapi/misc/d3dkmthk.h  | 13 +++++++
 5 files changed, 146 insertions(+)

diff --git a/drivers/hv/dxgkrnl/dxgkrnl.h b/drivers/hv/dxgkrnl/dxgkrnl.h
index 7d3f2617414d..6cd6bc6d6b9a 100644
--- a/drivers/hv/dxgkrnl/dxgkrnl.h
+++ b/drivers/hv/dxgkrnl/dxgkrnl.h
@@ -874,6 +874,11 @@ int dxgvmb_send_query_alloc_residency(struct dxgprocess *process,
 				      struct dxgadapter *adapter,
 				      struct d3dkmt_queryallocationresidency
 				      *args);
+int dxgvmb_send_query_vidmem_info(struct dxgprocess *process,
+				  struct dxgadapter *adapter,
+				  struct d3dkmt_queryvideomemoryinfo *args,
+				  struct d3dkmt_queryvideomemoryinfo
+				  *__user iargs);
 int dxgvmb_send_get_device_state(struct dxgprocess *process,
 				 struct dxgadapter *adapter,
 				 struct d3dkmt_getdevicestate *args,
diff --git a/drivers/hv/dxgkrnl/dxgvmbus.c b/drivers/hv/dxgkrnl/dxgvmbus.c
index 67b9e1b45b97..40ed2e981d73 100644
--- a/drivers/hv/dxgkrnl/dxgvmbus.c
+++ b/drivers/hv/dxgkrnl/dxgvmbus.c
@@ -1908,6 +1908,70 @@ int dxgvmb_send_query_alloc_residency(struct dxgprocess *process,
 	return ret;
 }
 
+int dxgvmb_send_query_vidmem_info(struct dxgprocess *process,
+				  struct dxgadapter *adapter,
+				  struct d3dkmt_queryvideomemoryinfo *args,
+				  struct d3dkmt_queryvideomemoryinfo *__user
+				  output)
+{
+	int ret;
+	struct dxgkvmb_command_queryvideomemoryinfo *command;
+	struct dxgkvmb_command_queryvideomemoryinfo_return result = { };
+	struct dxgvmbusmsg msg = {.hdr = NULL};
+
+	ret = init_message(&msg, adapter, process, sizeof(*command));
+	if (ret)
+		goto cleanup;
+	command = (void *)msg.msg;
+	command_vgpu_to_host_init2(&command->hdr,
+				   dxgk_vmbcommand_queryvideomemoryinfo,
+				   process->host_handle);
+	command->adapter = args->adapter;
+	command->memory_segment_group = args->memory_segment_group;
+	command->physical_adapter_index = args->physical_adapter_index;
+
+	ret = dxgvmb_send_sync_msg(msg.channel, msg.hdr, msg.size,
+				   &result, sizeof(result));
+	if (ret < 0)
+		goto cleanup;
+
+	ret = copy_to_user(&output->budget, &result.budget,
+			   sizeof(output->budget));
+	if (ret) {
+		pr_err("%s failed to copy budget", __func__);
+		ret = -EINVAL;
+		goto cleanup;
+	}
+	ret = copy_to_user(&output->current_usage, &result.current_usage,
+			   sizeof(output->current_usage));
+	if (ret) {
+		pr_err("%s failed to copy current usage", __func__);
+		ret = -EINVAL;
+		goto cleanup;
+	}
+	ret = copy_to_user(&output->current_reservation,
+			   &result.current_reservation,
+			   sizeof(output->current_reservation));
+	if (ret) {
+		pr_err("%s failed to copy reservation", __func__);
+		ret = -EINVAL;
+		goto cleanup;
+	}
+	ret = copy_to_user(&output->available_for_reservation,
+			   &result.available_for_reservation,
+			   sizeof(output->available_for_reservation));
+	if (ret) {
+		pr_err("%s failed to copy avail reservation", __func__);
+		ret = -EINVAL;
+	}
+
+cleanup:
+	free_message(&msg, process);
+	if (ret)
+		pr_debug("err: %s %d", __func__, ret);
+	return ret;
+}
+
 int dxgvmb_send_get_device_state(struct dxgprocess *process,
 				 struct dxgadapter *adapter,
 				 struct d3dkmt_getdevicestate *args,
diff --git a/drivers/hv/dxgkrnl/dxgvmbus.h b/drivers/hv/dxgkrnl/dxgvmbus.h
index 95c8b4a0cff9..8bca304fcb4b 100644
--- a/drivers/hv/dxgkrnl/dxgvmbus.h
+++ b/drivers/hv/dxgkrnl/dxgvmbus.h
@@ -664,6 +664,20 @@ struct dxgkvmb_command_queryallocationresidency_return {
 	/* d3dkmt_allocationresidencystatus[NumAllocations] */
 };
 
+struct dxgkvmb_command_queryvideomemoryinfo {
+	struct dxgkvmb_command_vgpu_to_host hdr;
+	struct d3dkmthandle		adapter;
+	enum d3dkmt_memory_segment_group memory_segment_group;
+	u32				physical_adapter_index;
+};
+
+struct dxgkvmb_command_queryvideomemoryinfo_return {
+	u64			budget;
+	u64			current_usage;
+	u64			current_reservation;
+	u64			available_for_reservation;
+};
+
 struct dxgkvmb_command_getdevicestate {
 	struct dxgkvmb_command_vgpu_to_host hdr;
 	struct d3dkmt_getdevicestate	args;
diff --git a/drivers/hv/dxgkrnl/ioctl.c b/drivers/hv/dxgkrnl/ioctl.c
index 4f2d762811ba..d7dbde41b8a2 100644
--- a/drivers/hv/dxgkrnl/ioctl.c
+++ b/drivers/hv/dxgkrnl/ioctl.c
@@ -3586,6 +3586,54 @@ dxgk_flush_heap_transitions(struct dxgprocess *process, void *__user inargs)
 	return ret;
 }
 
+static int
+dxgk_query_vidmem_info(struct dxgprocess *process, void *__user inargs)
+{
+	struct d3dkmt_queryvideomemoryinfo args;
+	int ret;
+	struct dxgadapter *adapter = NULL;
+	bool adapter_locked = false;
+
+	ret = copy_from_user(&args, inargs, sizeof(args));
+	if (ret) {
+		pr_err("%s failed to copy input args", __func__);
+		ret = -EINVAL;
+		goto cleanup;
+	}
+
+	if (args.process != 0) {
+		pr_err("query vidmem info from another process ");
+		ret = -EINVAL;
+		goto cleanup;
+	}
+
+	adapter = dxgprocess_adapter_by_handle(process, args.adapter);
+	if (adapter == NULL) {
+		ret = -EINVAL;
+		goto cleanup;
+	}
+
+	ret = dxgadapter_acquire_lock_shared(adapter);
+	if (ret < 0) {
+		adapter = NULL;
+		goto cleanup;
+	}
+	adapter_locked = true;
+
+	args.adapter = adapter->host_handle;
+	ret = dxgvmb_send_query_vidmem_info(process, adapter, &args, inargs);
+
+cleanup:
+
+	if (adapter_locked)
+		dxgadapter_release_lock_shared(adapter);
+	if (adapter)
+		kref_put(&adapter->adapter_kref, dxgadapter_release);
+	if (ret < 0)
+		pr_err("%s failed: %x", __func__, ret);
+	return ret;
+}
+
 static int
 dxgk_get_device_state(struct dxgprocess *process, void *__user inargs)
 {
@@ -4391,6 +4439,8 @@ void init_ioctls(void)
 		  LX_DXCREATEPAGINGQUEUE);
 	SET_IOCTL(/*0x9 */ dxgk_query_adapter_info,
 		  LX_DXQUERYADAPTERINFO);
+	SET_IOCTL(/*0xa */ dxgk_query_vidmem_info,
+		  LX_DXQUERYVIDEOMEMORYINFO);
 	SET_IOCTL(/*0xe */ dxgk_get_device_state,
 		  LX_DXGETDEVICESTATE);
 	SET_IOCTL(/*0xf */ dxgk_submit_command,
diff --git a/include/uapi/misc/d3dkmthk.h b/include/uapi/misc/d3dkmthk.h
index b0a2c858f122..f7f663f6e674 100644
--- a/include/uapi/misc/d3dkmthk.h
+++ b/include/uapi/misc/d3dkmthk.h
@@ -893,6 +893,17 @@ enum d3dkmt_memory_segment_group {
 	_D3DKMT_MEMORY_SEGMENT_GROUP_NON_LOCAL	= 1
 };
 
+struct d3dkmt_queryvideomemoryinfo {
+	__u64					process;
+	struct d3dkmthandle			adapter;
+	enum d3dkmt_memory_segment_group	memory_segment_group;
+	__u64					budget;
+	__u64					current_usage;
+	__u64					current_reservation;
+	__u64					available_for_reservation;
+	__u32					physical_adapter_index;
+};
+
 struct d3dkmt_adaptertype {
 	union {
 		struct {
@@ -1200,6 +1211,8 @@ struct d3dkmt_shareobjectwithhost {
 	_IOWR(0x47, 0x07, struct d3dkmt_createpagingqueue)
 #define LX_DXQUERYADAPTERINFO		\
 	_IOWR(0x47, 0x09, struct d3dkmt_queryadapterinfo)
+#define LX_DXQUERYVIDEOMEMORYINFO	\
+	_IOWR(0x47, 0x0a, struct d3dkmt_queryvideomemoryinfo)
 #define LX_DXGETDEVICESTATE		\
 	_IOWR(0x47, 0x0e, struct d3dkmt_getdevicestate)
 #define LX_DXSUBMITCOMMAND		\
-- 
2.35.1


  parent reply	other threads:[~2022-03-01 19:48 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 19:45 [PATCH v3 00/30] Driver for Hyper-v virtual compute device Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 01/30] drivers: hv: dxgkrnl: Add virtual compute device VM bus channel guids Iouri Tarassov
2022-03-01 19:45   ` [PATCH v3 02/30] drivers: hv: dxgkrnl: Driver initialization and loading Iouri Tarassov
2022-03-01 20:45     ` Greg KH
2022-03-01 22:23       ` Wei Liu
2022-03-01 22:47         ` Iouri Tarassov
2022-03-02  7:54           ` Greg KH
2022-03-02  7:53         ` Greg KH
2022-03-02 11:53           ` Wei Liu
2022-03-02 18:49             ` Iouri Tarassov
2022-03-02 20:20               ` Greg KH
2022-03-02 22:27                 ` Iouri Tarassov
2022-03-03 13:16                   ` Greg KH
2022-03-09 23:14                     ` Steve Pronovost
2022-03-10 10:13                       ` Greg KH
2022-03-10 18:31                         ` Steve Pronovost
2022-03-02 20:34               ` Wei Liu
2022-03-03  1:09           ` Iouri Tarassov
2022-03-03 13:22             ` Greg KH
2022-03-04 16:04               ` Wei Liu
2022-03-04 17:55                 ` Greg KH
2022-03-02 22:59       ` Iouri Tarassov
2022-03-03 13:29         ` Greg KH
2022-03-02 23:27       ` Iouri Tarassov
2022-03-03 13:10         ` Greg KH
2022-03-01 22:06     ` Wei Liu
2022-03-03  2:01       ` Iouri Tarassov
2022-03-01 19:45   ` [PATCH v3 03/30] drivers: hv: dxgkrnl: Add VM bus message support, initialize VM bus channels Iouri Tarassov
2022-03-01 22:57     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 04/30] drivers: hv: dxgkrnl: Creation of dxgadapter object Iouri Tarassov
2022-03-01 23:25     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 05/30] drivers: hv: dxgkrnl: Opening of /dev/dxg device and dxgprocess creation Iouri Tarassov
2022-03-01 20:46     ` Greg KH
2022-03-01 20:46     ` Greg KH
2022-03-01 23:47     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 06/30] drivers: hv: dxgkrnl: Enumerate and open dxgadapter objects Iouri Tarassov
2022-03-02 12:43     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 07/30] drivers: hv: dxgkrnl: Creation of dxgdevice objects Iouri Tarassov
2022-03-01 19:45   ` [PATCH v3 08/30] drivers: hv: dxgkrnl: Creation of dxgcontext objects Iouri Tarassov
2022-03-02 12:59     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 09/30] drivers: hv: dxgkrnl: Creation of compute device allocations and resources Iouri Tarassov
2022-03-01 19:45   ` [PATCH v3 10/30] drivers: hv: dxgkrnl: Creation of compute device sync objects Iouri Tarassov
2022-03-02 13:25     ` Wei Liu
2022-03-01 19:45   ` [PATCH v3 11/30] drivers: hv: dxgkrnl: Operations using " Iouri Tarassov
2022-03-01 19:45   ` [PATCH v3 12/30] drivers: hv: dxgkrnl: Sharing of dxgresource objects Iouri Tarassov
2022-03-02 14:13     ` Wei Liu
2022-03-02 14:15     ` Wei Liu
2022-03-01 19:46   ` [PATCH v3 13/30] drivers: hv: dxgkrnl: Sharing of sync objects Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 14/30] drivers: hv: dxgkrnl: Creation of hardware queues. Sync object operations to hw queue Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 15/30] drivers: hv: dxgkrnl: Creation of paging queue objects Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 16/30] drivers: hv: dxgkrnl: Submit execution commands to the compute device Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 17/30] drivers: hv: dxgkrnl: Share objects with the host Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 18/30] drivers: hv: dxgkrnl: Query the dxgdevice state Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 19/30] drivers: hv: dxgkrnl: Map(unmap) CPU address to device allocation Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 20/30] drivers: hv: dxgkrnl: Manage device allocation properties Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 21/30] drivers: hv: dxgkrnl: Flush heap transitions Iouri Tarassov
2022-03-01 19:46   ` Iouri Tarassov [this message]
2022-03-01 19:46   ` [PATCH v3 23/30] drivers: hv: dxgkrnl: The escape ioctl Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 24/30] drivers: hv: dxgkrnl: Ioctl to put device to error state Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 25/30] drivers: hv: dxgkrnl: Ioctls to query statistics and clock calibration Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 26/30] drivers: hv: dxgkrnl: Offer and reclaim allocations Iouri Tarassov
2022-03-02 14:25     ` Wei Liu
2022-03-02 18:13       ` Iouri Tarassov
2022-03-02 18:23         ` Wei Liu
2022-03-01 19:46   ` [PATCH v3 27/30] drivers: hv: dxgkrnl: Ioctls to manage scheduling priority Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 28/30] drivers: hv: dxgkrnl: Manage residency of allocations Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 29/30] drivers: hv: dxgkrnl: Manage compute device virtual addresses Iouri Tarassov
2022-03-01 19:46   ` [PATCH v3 30/30] drivers: hv: dxgkrnl: Add support to map guest pages by host Iouri Tarassov
2022-03-02 14:29     ` Wei Liu
2022-03-01 21:37   ` [PATCH v3 01/30] drivers: hv: dxgkrnl: Add virtual compute device VM bus channel guids Wei Liu
2022-03-02  8:51 ` [PATCH v3 00/30] Driver for Hyper-v virtual compute device Christoph Hellwig
2022-03-02 14:53 ` 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=5dadbe959f96e2764a61157eb05f0804a74afb1c.1646163379.git.iourit@linux.microsoft.com \
    --to=iourit@linux.microsoft.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spronovo@linux.microsoft.com \
    --cc=spronovo@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@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

Powered by JetHome