From: Iouri Tarassov <[email protected]> WDDM has a restriction that an allocation of a shared resource can be locked for CPU access only by the resource creator (the owner). This restriction is removed for system memory only allocations. This change adds support for this feature.
Signed-off-by: Iouri Tarassov <[email protected]> [kms: forward port to 6.6 from 6.1. No code changes made.] Signed-off-by: Kelsey Steele <[email protected]> --- drivers/hv/dxgkrnl/dxgadapter.c | 4 ++-- drivers/hv/dxgkrnl/dxgkrnl.h | 13 ++++++++++++- drivers/hv/dxgkrnl/ioctl.c | 25 +++++++++++++++++-------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/drivers/hv/dxgkrnl/dxgadapter.c b/drivers/hv/dxgkrnl/dxgadapter.c index b8ae8099847b..cf946e476411 100644 --- a/drivers/hv/dxgkrnl/dxgadapter.c +++ b/drivers/hv/dxgkrnl/dxgadapter.c @@ -559,8 +559,8 @@ void dxgsharedresource_destroy(struct kref *refcount) vfree(resource->runtime_private_data); if (resource->resource_private_data) vfree(resource->resource_private_data); - if (resource->alloc_private_data_sizes) - vfree(resource->alloc_private_data_sizes); + if (resource->alloc_info) + vfree(resource->alloc_info); if (resource->alloc_private_data) vfree(resource->alloc_private_data); kfree(resource); diff --git a/drivers/hv/dxgkrnl/dxgkrnl.h b/drivers/hv/dxgkrnl/dxgkrnl.h index a4d0c504668b..d816a875d5ab 100644 --- a/drivers/hv/dxgkrnl/dxgkrnl.h +++ b/drivers/hv/dxgkrnl/dxgkrnl.h @@ -613,6 +613,17 @@ struct dxghwqueue *dxghwqueue_create(struct dxgcontext *ctx); void dxghwqueue_destroy(struct dxgprocess *pr, struct dxghwqueue *hq); void dxghwqueue_release(struct kref *refcount); +/* + * When a shared resource is created this structure provides information + * about every allocation in the resource. It is used when someone opens the + * resource and locks its allocation. + */ +struct dxgsharedallocdata { + u32 private_data_size; /* Size of private data */ + u32 num_pages; /* Allocation size in pages */ + bool cached; /* True is the alloc memory is cached */ +}; + /* * A shared resource object is created to track the list of dxgresource objects, * which are opened for the same underlying shared resource. @@ -658,7 +669,7 @@ struct dxgsharedresource { }; long flags; }; - u32 *alloc_private_data_sizes; + struct dxgsharedallocdata *alloc_info; u8 *alloc_private_data; u8 *runtime_private_data; u8 *resource_private_data; diff --git a/drivers/hv/dxgkrnl/ioctl.c b/drivers/hv/dxgkrnl/ioctl.c index d91af2e176e9..f8f116a7f87f 100644 --- a/drivers/hv/dxgkrnl/ioctl.c +++ b/drivers/hv/dxgkrnl/ioctl.c @@ -369,6 +369,7 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource) u32 data_size; struct dxgresource *resource; struct dxgallocation *alloc; + struct dxgsharedallocdata *alloc_info; DXG_TRACE("Sealing resource: %p", shared_resource); @@ -409,9 +410,10 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource) ret = -EINVAL; goto cleanup1; } - shared_resource->alloc_private_data_sizes = - vzalloc(sizeof(u32)*shared_resource->allocation_count); - if (shared_resource->alloc_private_data_sizes == NULL) { + shared_resource->alloc_info = + vzalloc(sizeof(struct dxgsharedallocdata) * + shared_resource->allocation_count); + if (shared_resource->alloc_info == NULL) { ret = -EINVAL; goto cleanup1; } @@ -429,8 +431,10 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource) ret = -EINVAL; goto cleanup1; } - shared_resource->alloc_private_data_sizes[i] = - alloc_data_size; + alloc_info = &shared_resource->alloc_info[i]; + alloc_info->private_data_size = alloc_data_size; + alloc_info->num_pages = alloc->num_pages; + alloc_info->cached = alloc->cached; memcpy(private_data, alloc->priv_drv_data->data, alloc_data_size); @@ -5031,6 +5035,7 @@ assign_resource_handles(struct dxgprocess *process, u8 *cur_priv_data; u32 total_priv_data_size = 0; struct d3dddi_openallocationinfo2 open_alloc_info = { }; + struct dxgsharedallocdata *alloc_info; hmgrtable_lock(&process->handle_table, DXGLOCK_EXCL); ret = hmgrtable_assign_handle(&process->handle_table, resource, @@ -5050,11 +5055,15 @@ assign_resource_handles(struct dxgprocess *process, allocs[i]->alloc_handle = handles[i]; allocs[i]->handle_valid = 1; open_alloc_info.allocation = handles[i]; - if (shared_resource->alloc_private_data_sizes) + if (shared_resource->alloc_info) { + alloc_info = &shared_resource->alloc_info[i]; open_alloc_info.priv_drv_data_size = - shared_resource->alloc_private_data_sizes[i]; - else + alloc_info->private_data_size; + allocs[i]->num_pages = alloc_info->num_pages; + allocs[i]->cached = alloc_info->cached; + } else { open_alloc_info.priv_drv_data_size = 0; + } total_priv_data_size += open_alloc_info.priv_drv_data_size; open_alloc_info.priv_drv_data = cur_priv_data;

