Skip to content

Commit 63adb4c

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Ioctl to put device to error state
Implement the ioctl to put the virtual compute device to the error state (LX_DXMARKDEVICEASERROR). This ioctl is used by the user mode driver when it detects an unrecoverable error condition. When a compute device is put to the error state, all subsequent ioctl calls to the device will fail. 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 dc66c10 commit 63adb4c

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,9 @@ int dxgvmb_send_update_alloc_property(struct dxgprocess *process,
856856
struct d3dddi_updateallocproperty *args,
857857
struct d3dddi_updateallocproperty *__user
858858
inargs);
859+
int dxgvmb_send_mark_device_as_error(struct dxgprocess *process,
860+
struct dxgadapter *adapter,
861+
struct d3dkmt_markdeviceaserror *args);
859862
int dxgvmb_send_set_allocation_priority(struct dxgprocess *process,
860863
struct dxgadapter *adapter,
861864
struct d3dkmt_setallocationpriority *a);

drivers/hv/dxgkrnl/dxgvmbus.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,31 @@ int dxgvmb_send_update_alloc_property(struct dxgprocess *process,
27302730
return ret;
27312731
}
27322732

2733+
int dxgvmb_send_mark_device_as_error(struct dxgprocess *process,
2734+
struct dxgadapter *adapter,
2735+
struct d3dkmt_markdeviceaserror *args)
2736+
{
2737+
struct dxgkvmb_command_markdeviceaserror *command;
2738+
int ret;
2739+
struct dxgvmbusmsg msg = {.hdr = NULL};
2740+
2741+
ret = init_message(&msg, adapter, process, sizeof(*command));
2742+
if (ret)
2743+
goto cleanup;
2744+
command = (void *)msg.msg;
2745+
2746+
command_vgpu_to_host_init2(&command->hdr,
2747+
DXGK_VMBCOMMAND_MARKDEVICEASERROR,
2748+
process->host_handle);
2749+
command->args = *args;
2750+
ret = dxgvmb_send_sync_msg_ntstatus(msg.channel, msg.hdr, msg.size);
2751+
cleanup:
2752+
free_message(&msg, process);
2753+
if (ret)
2754+
DXG_TRACE("err: %d", ret);
2755+
return ret;
2756+
}
2757+
27332758
int dxgvmb_send_set_allocation_priority(struct dxgprocess *process,
27342759
struct dxgadapter *adapter,
27352760
struct d3dkmt_setallocationpriority *args)

drivers/hv/dxgkrnl/dxgvmbus.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ struct dxgkvmb_command_updateallocationproperty_return {
627627
struct ntstatus status;
628628
};
629629

630+
struct dxgkvmb_command_markdeviceaserror {
631+
struct dxgkvmb_command_vgpu_to_host hdr;
632+
struct d3dkmt_markdeviceaserror args;
633+
};
634+
630635
/* Returns ntstatus */
631636
struct dxgkvmb_command_changevideomemoryreservation {
632637
struct dxgkvmb_command_vgpu_to_host hdr;

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,42 @@ dxgkio_update_alloc_property(struct dxgprocess *process, void *__user inargs)
33413341
return ret;
33423342
}
33433343

3344+
static int
3345+
dxgkio_mark_device_as_error(struct dxgprocess *process, void *__user inargs)
3346+
{
3347+
struct d3dkmt_markdeviceaserror args;
3348+
struct dxgadapter *adapter = NULL;
3349+
struct dxgdevice *device = NULL;
3350+
int ret;
3351+
3352+
ret = copy_from_user(&args, inargs, sizeof(args));
3353+
if (ret) {
3354+
DXG_ERR("failed to copy input args");
3355+
ret = -EINVAL;
3356+
goto cleanup;
3357+
}
3358+
device = dxgprocess_device_by_handle(process, args.device);
3359+
if (device == NULL) {
3360+
ret = -EINVAL;
3361+
goto cleanup;
3362+
}
3363+
adapter = device->adapter;
3364+
ret = dxgadapter_acquire_lock_shared(adapter);
3365+
if (ret < 0) {
3366+
adapter = NULL;
3367+
goto cleanup;
3368+
}
3369+
device->execution_state = _D3DKMT_DEVICEEXECUTION_RESET;
3370+
ret = dxgvmb_send_mark_device_as_error(process, adapter, &args);
3371+
cleanup:
3372+
if (adapter)
3373+
dxgadapter_release_lock_shared(adapter);
3374+
if (device)
3375+
kref_put(&device->device_kref, dxgdevice_release);
3376+
DXG_TRACE("ioctl:%s %d", errorstr(ret), ret);
3377+
return ret;
3378+
}
3379+
33443380
static int
33453381
dxgkio_query_alloc_residency(struct dxgprocess *process, void *__user inargs)
33463382
{
@@ -4404,7 +4440,7 @@ static struct ioctl_desc ioctls[] = {
44044440
/* 0x23 */ {},
44054441
/* 0x24 */ {},
44064442
/* 0x25 */ {dxgkio_lock2, LX_DXLOCK2},
4407-
/* 0x26 */ {},
4443+
/* 0x26 */ {dxgkio_mark_device_as_error, LX_DXMARKDEVICEASERROR},
44084444
/* 0x27 */ {},
44094445
/* 0x28 */ {},
44104446
/* 0x29 */ {},

include/uapi/misc/d3dkmthk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,16 @@ struct d3dkmt_unlock2 {
790790
struct d3dkmthandle allocation;
791791
};
792792

793+
enum d3dkmt_device_error_reason {
794+
_D3DKMT_DEVICE_ERROR_REASON_GENERIC = 0x80000000,
795+
_D3DKMT_DEVICE_ERROR_REASON_DRIVER_ERROR = 0x80000006,
796+
};
797+
798+
struct d3dkmt_markdeviceaserror {
799+
struct d3dkmthandle device;
800+
enum d3dkmt_device_error_reason reason;
801+
};
802+
793803
enum d3dkmt_standardallocationtype {
794804
_D3DKMT_STANDARDALLOCATIONTYPE_EXISTINGHEAP = 1,
795805
_D3DKMT_STANDARDALLOCATIONTYPE_CROSSADAPTER = 2,
@@ -1290,6 +1300,8 @@ struct d3dkmt_shareobjectwithhost {
12901300
_IOWR(0x47, 0x1f, struct d3dkmt_flushheaptransitions)
12911301
#define LX_DXLOCK2 \
12921302
_IOWR(0x47, 0x25, struct d3dkmt_lock2)
1303+
#define LX_DXMARKDEVICEASERROR \
1304+
_IOWR(0x47, 0x26, struct d3dkmt_markdeviceaserror)
12931305
#define LX_DXQUERYALLOCATIONRESIDENCY \
12941306
_IOWR(0x47, 0x2a, struct d3dkmt_queryallocationresidency)
12951307
#define LX_DXSETALLOCATIONPRIORITY \

0 commit comments

Comments
 (0)