Skip to content

Commit 023f9d3

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Added implementation for D3DKMTInvalidateCache
D3DKMTInvalidateCache is called by user mode drivers when the device doesn't support cache coherent access to compute device allocations. It needs to be called after an allocation was accessed by CPU and now needs to be accessed by the device. And vice versa. 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 4f29ac0 commit 023f9d3

5 files changed

Lines changed: 97 additions & 2 deletions

File tree

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,9 @@ int dxgvmb_send_async_msg(struct dxgvmbuschannel *channel,
989989
u32 cmd_size);
990990
int dxgvmb_send_share_object_with_host(struct dxgprocess *process,
991991
struct d3dkmt_shareobjectwithhost *args);
992+
int dxgvmb_send_invalidate_cache(struct dxgprocess *process,
993+
struct dxgadapter *adapter,
994+
struct d3dkmt_invalidatecache *args);
992995

993996
void signal_host_cpu_event(struct dxghostevent *eventhdr);
994997
int ntstatus2int(struct ntstatus status);

drivers/hv/dxgkrnl/dxgvmbus.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,33 @@ int dxgvmb_send_flush_heap_transitions(struct dxgprocess *process,
20212021
return ret;
20222022
}
20232023

2024+
int dxgvmb_send_invalidate_cache(struct dxgprocess *process,
2025+
struct dxgadapter *adapter,
2026+
struct d3dkmt_invalidatecache *args)
2027+
{
2028+
struct dxgkvmb_command_invalidatecache *command;
2029+
int ret;
2030+
struct dxgvmbusmsg msg = {.hdr = NULL};
2031+
2032+
ret = init_message(&msg, adapter, process, sizeof(*command));
2033+
if (ret)
2034+
goto cleanup;
2035+
command = (void *)msg.msg;
2036+
command_vgpu_to_host_init2(&command->hdr,
2037+
DXGK_VMBCOMMAND_INVALIDATECACHE,
2038+
process->host_handle);
2039+
command->device = args->device;
2040+
command->allocation = args->allocation;
2041+
command->offset = args->offset;
2042+
command->length = args->length;
2043+
ret = dxgvmb_send_sync_msg_ntstatus(msg.channel, msg.hdr, msg.size);
2044+
cleanup:
2045+
free_message(&msg, process);
2046+
if (ret)
2047+
DXG_TRACE("err: %d", ret);
2048+
return ret;
2049+
}
2050+
20242051
int dxgvmb_send_query_alloc_residency(struct dxgprocess *process,
20252052
struct dxgadapter *adapter,
20262053
struct d3dkmt_queryallocationresidency

drivers/hv/dxgkrnl/dxgvmbus.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ enum dxgkvmb_commandtype {
125125
DXGK_VMBCOMMAND_QUERYRESOURCEINFO = 64,
126126
DXGK_VMBCOMMAND_LOGEVENT = 65,
127127
DXGK_VMBCOMMAND_SETEXISTINGSYSMEMPAGES = 66,
128+
DXGK_VMBCOMMAND_INVALIDATECACHE = 67,
128129
DXGK_VMBCOMMAND_INVALID
129130
};
130131

@@ -428,6 +429,16 @@ struct dxgkvmb_command_flushheaptransitions {
428429
struct dxgkvmb_command_vgpu_to_host hdr;
429430
};
430431

432+
/* Returns ntstatus */
433+
struct dxgkvmb_command_invalidatecache {
434+
struct dxgkvmb_command_vgpu_to_host hdr;
435+
struct d3dkmthandle device;
436+
struct d3dkmthandle allocation;
437+
u64 offset;
438+
u64 length;
439+
u64 reserved;
440+
};
441+
431442
struct dxgkvmb_command_freegpuvirtualaddress {
432443
struct dxgkvmb_command_vgpu_to_host hdr;
433444
struct d3dkmt_freegpuvirtualaddress args;

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,6 +4286,8 @@ dxgkio_query_clock_calibration(struct dxgprocess *process, void *__user inargs)
42864286
dxgadapter_release_lock_shared(adapter);
42874287
if (adapter)
42884288
kref_put(&adapter->adapter_kref, dxgadapter_release);
4289+
4290+
DXG_TRACE_IOCTL_END(ret);
42894291
return ret;
42904292
}
42914293

@@ -4333,6 +4335,49 @@ dxgkio_flush_heap_transitions(struct dxgprocess *process, void *__user inargs)
43334335
dxgadapter_release_lock_shared(adapter);
43344336
if (adapter)
43354337
kref_put(&adapter->adapter_kref, dxgadapter_release);
4338+
4339+
DXG_TRACE_IOCTL_END(ret);
4340+
return ret;
4341+
}
4342+
4343+
static int
4344+
dxgkio_invalidate_cache(struct dxgprocess *process, void *__user inargs)
4345+
{
4346+
struct d3dkmt_invalidatecache args;
4347+
int ret;
4348+
struct dxgdevice *device = NULL;
4349+
4350+
ret = copy_from_user(&args, inargs, sizeof(args));
4351+
if (ret) {
4352+
DXG_ERR("failed to copy input args");
4353+
ret = -EFAULT;
4354+
goto cleanup;
4355+
}
4356+
4357+
device = dxgprocess_device_by_handle(process, args.device);
4358+
if (device == NULL) {
4359+
ret = -EINVAL;
4360+
goto cleanup;
4361+
}
4362+
4363+
ret = dxgdevice_acquire_lock_shared(device);
4364+
if (ret < 0) {
4365+
kref_put(&device->device_kref, dxgdevice_release);
4366+
device = NULL;
4367+
goto cleanup;
4368+
}
4369+
4370+
ret = dxgvmb_send_invalidate_cache(process, device->adapter,
4371+
&args);
4372+
4373+
cleanup:
4374+
4375+
if (device) {
4376+
dxgdevice_release_lock_shared(device);
4377+
kref_put(&device->device_kref, dxgdevice_release);
4378+
}
4379+
4380+
DXG_TRACE_IOCTL_END(ret);
43364381
return ret;
43374382
}
43384383

@@ -5198,7 +5243,7 @@ static struct ioctl_desc ioctls[] = {
51985243
/* 0x22 */ {dxgkio_get_context_scheduling_priority,
51995244
LX_DXGETCONTEXTSCHEDULINGPRIORITY},
52005245
/* 0x23 */ {},
5201-
/* 0x24 */ {},
5246+
/* 0x24 */ {dxgkio_invalidate_cache, LX_DXINVALIDATECACHE},
52025247
/* 0x25 */ {dxgkio_lock2, LX_DXLOCK2},
52035248
/* 0x26 */ {dxgkio_mark_device_as_error, LX_DXMARKDEVICEASERROR},
52045249
/* 0x27 */ {dxgkio_offer_allocations, LX_DXOFFERALLOCATIONS},
@@ -5243,7 +5288,7 @@ static struct ioctl_desc ioctls[] = {
52435288
/* 0x44 */ {dxgkio_share_object_with_host, LX_DXSHAREOBJECTWITHHOST},
52445289
/* 0x45 */ {dxgkio_create_sync_file, LX_DXCREATESYNCFILE},
52455290
/* 0x46 */ {dxgkio_wait_sync_file, LX_DXWAITSYNCFILE},
5246-
/* 0x46 */ {dxgkio_open_syncobj_from_syncfile,
5291+
/* 0x47 */ {dxgkio_open_syncobj_from_syncfile,
52475292
LX_DXOPENSYNCOBJECTFROMSYNCFILE},
52485293
};
52495294

include/uapi/misc/d3dkmthk.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,13 @@ struct d3dkmt_opensyncobjectfromsyncfile {
15801580
__u64 fence_value_gpu_va; /* out */
15811581
};
15821582

1583+
struct d3dkmt_invalidatecache {
1584+
struct d3dkmthandle device;
1585+
struct d3dkmthandle allocation;
1586+
__u64 offset;
1587+
__u64 length;
1588+
};
1589+
15831590
/*
15841591
* Dxgkrnl Graphics Port Driver ioctl definitions
15851592
*
@@ -1647,6 +1654,8 @@ struct d3dkmt_opensyncobjectfromsyncfile {
16471654
_IOWR(0x47, 0x21, struct d3dkmt_getcontextinprocessschedulingpriority)
16481655
#define LX_DXGETCONTEXTSCHEDULINGPRIORITY \
16491656
_IOWR(0x47, 0x22, struct d3dkmt_getcontextschedulingpriority)
1657+
#define LX_DXINVALIDATECACHE \
1658+
_IOWR(0x47, 0x24, struct d3dkmt_invalidatecache)
16501659
#define LX_DXLOCK2 \
16511660
_IOWR(0x47, 0x25, struct d3dkmt_lock2)
16521661
#define LX_DXMARKDEVICEASERROR \

0 commit comments

Comments
 (0)