Skip to content

Commit 65fdb5a

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Flush heap transitions
Implement the ioctl to flush heap transitions (LX_DXFLUSHHEAPTRANSITIONS). The ioctl is used to ensure that the video memory manager on the host flushes all internal operations. Signed-off-by: Iouri Tarassov <iourit@linux.microsoft.com> [kms: forward port to 6.6 from 6.1. No code changes made.] Signed-off-by: Kelsey Steele <kelseysteele@microsoft.com>
1 parent 8f81198 commit 65fdb5a

6 files changed

Lines changed: 86 additions & 2 deletions

File tree

drivers/hv/dxgkrnl/dxgadapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ else
942942
if (alloc->priv_drv_data)
943943
vfree(alloc->priv_drv_data);
944944
if (alloc->cpu_address_mapped)
945-
pr_err("Alloc IO space is mapped: %p", alloc);
945+
DXG_ERR("Alloc IO space is mapped: %p", alloc);
946946
kfree(alloc);
947947
}
948948

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ int dxgvmb_send_query_adapter_info(struct dxgprocess *process,
882882
int dxgvmb_send_submit_command_hwqueue(struct dxgprocess *process,
883883
struct dxgadapter *adapter,
884884
struct d3dkmt_submitcommandtohwqueue *a);
885+
int dxgvmb_send_flush_heap_transitions(struct dxgprocess *process,
886+
struct dxgadapter *adapter,
887+
struct d3dkmt_flushheaptransitions *arg);
885888
int dxgvmb_send_open_sync_object_nt(struct dxgprocess *process,
886889
struct dxgvmbuschannel *channel,
887890
struct d3dkmt_opensyncobjectfromnthandle2

drivers/hv/dxgkrnl/dxgvmbus.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,29 @@ int dxgvmb_send_destroy_allocation(struct dxgprocess *process,
18291829
return ret;
18301830
}
18311831

1832+
int dxgvmb_send_flush_heap_transitions(struct dxgprocess *process,
1833+
struct dxgadapter *adapter,
1834+
struct d3dkmt_flushheaptransitions *args)
1835+
{
1836+
struct dxgkvmb_command_flushheaptransitions *command;
1837+
int ret;
1838+
struct dxgvmbusmsg msg = {.hdr = NULL};
1839+
1840+
ret = init_message(&msg, adapter, process, sizeof(*command));
1841+
if (ret)
1842+
goto cleanup;
1843+
command = (void *)msg.msg;
1844+
command_vgpu_to_host_init2(&command->hdr,
1845+
DXGK_VMBCOMMAND_FLUSHHEAPTRANSITIONS,
1846+
process->host_handle);
1847+
ret = dxgvmb_send_sync_msg_ntstatus(msg.channel, msg.hdr, msg.size);
1848+
cleanup:
1849+
free_message(&msg, process);
1850+
if (ret)
1851+
DXG_TRACE("err: %d", ret);
1852+
return ret;
1853+
}
1854+
18321855
int dxgvmb_send_query_alloc_residency(struct dxgprocess *process,
18331856
struct dxgadapter *adapter,
18341857
struct d3dkmt_queryallocationresidency

drivers/hv/dxgkrnl/dxgvmbus.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ struct dxgkvmb_command_submitcommandtohwqueue {
367367
/* PrivateDriverData */
368368
};
369369

370+
/* Returns ntstatus */
371+
struct dxgkvmb_command_flushheaptransitions {
372+
struct dxgkvmb_command_vgpu_to_host hdr;
373+
};
374+
370375
struct dxgkvmb_command_createallocation_allocinfo {
371376
u32 flags;
372377
u32 priv_drv_data_size;

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,53 @@ dxgkio_change_vidmem_reservation(struct dxgprocess *process, void *__user inargs
35003500
return ret;
35013501
}
35023502

3503+
static int
3504+
dxgkio_flush_heap_transitions(struct dxgprocess *process, void *__user inargs)
3505+
{
3506+
struct d3dkmt_flushheaptransitions args;
3507+
int ret;
3508+
struct dxgadapter *adapter = NULL;
3509+
bool adapter_locked = false;
3510+
3511+
ret = copy_from_user(&args, inargs, sizeof(args));
3512+
if (ret) {
3513+
DXG_ERR("failed to copy input args");
3514+
ret = -EINVAL;
3515+
goto cleanup;
3516+
}
3517+
3518+
adapter = dxgprocess_adapter_by_handle(process, args.adapter);
3519+
if (adapter == NULL) {
3520+
ret = -EINVAL;
3521+
goto cleanup;
3522+
}
3523+
3524+
ret = dxgadapter_acquire_lock_shared(adapter);
3525+
if (ret < 0) {
3526+
adapter = NULL;
3527+
goto cleanup;
3528+
}
3529+
adapter_locked = true;
3530+
3531+
args.adapter = adapter->host_handle;
3532+
ret = dxgvmb_send_flush_heap_transitions(process, adapter, &args);
3533+
if (ret < 0)
3534+
goto cleanup;
3535+
ret = copy_to_user(inargs, &args, sizeof(args));
3536+
if (ret) {
3537+
DXG_ERR("failed to copy output args");
3538+
ret = -EINVAL;
3539+
}
3540+
3541+
cleanup:
3542+
3543+
if (adapter_locked)
3544+
dxgadapter_release_lock_shared(adapter);
3545+
if (adapter)
3546+
kref_put(&adapter->adapter_kref, dxgadapter_release);
3547+
return ret;
3548+
}
3549+
35033550
static int
35043551
dxgkio_get_device_state(struct dxgprocess *process, void *__user inargs)
35053552
{
@@ -4262,7 +4309,7 @@ static struct ioctl_desc ioctls[] = {
42624309
/* 0x1c */ {dxgkio_destroy_paging_queue, LX_DXDESTROYPAGINGQUEUE},
42634310
/* 0x1d */ {dxgkio_destroy_sync_object, LX_DXDESTROYSYNCHRONIZATIONOBJECT},
42644311
/* 0x1e */ {},
4265-
/* 0x1f */ {},
4312+
/* 0x1f */ {dxgkio_flush_heap_transitions, LX_DXFLUSHHEAPTRANSITIONS},
42664313
/* 0x20 */ {},
42674314
/* 0x21 */ {},
42684315
/* 0x22 */ {},

include/uapi/misc/d3dkmthk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ struct d3dkmt_queryadapterinfo {
936936
__u32 private_data_size;
937937
};
938938

939+
struct d3dkmt_flushheaptransitions {
940+
struct d3dkmthandle adapter;
941+
};
942+
939943
struct d3dddi_openallocationinfo2 {
940944
struct d3dkmthandle allocation;
941945
#ifdef __KERNEL__
@@ -1228,6 +1232,8 @@ struct d3dkmt_shareobjectwithhost {
12281232
_IOWR(0x47, 0x19, struct d3dkmt_destroydevice)
12291233
#define LX_DXDESTROYSYNCHRONIZATIONOBJECT \
12301234
_IOWR(0x47, 0x1d, struct d3dkmt_destroysynchronizationobject)
1235+
#define LX_DXFLUSHHEAPTRANSITIONS \
1236+
_IOWR(0x47, 0x1f, struct d3dkmt_flushheaptransitions)
12311237
#define LX_DXLOCK2 \
12321238
_IOWR(0x47, 0x25, struct d3dkmt_lock2)
12331239
#define LX_DXQUERYALLOCATIONRESIDENCY \

0 commit comments

Comments
 (0)