Skip to content

Commit ccd9169

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Add support for locking a shared allocation by not the owner
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 <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 77d5e27 commit ccd9169

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

drivers/hv/dxgkrnl/dxgadapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ void dxgsharedresource_destroy(struct kref *refcount)
559559
vfree(resource->runtime_private_data);
560560
if (resource->resource_private_data)
561561
vfree(resource->resource_private_data);
562-
if (resource->alloc_private_data_sizes)
563-
vfree(resource->alloc_private_data_sizes);
562+
if (resource->alloc_info)
563+
vfree(resource->alloc_info);
564564
if (resource->alloc_private_data)
565565
vfree(resource->alloc_private_data);
566566
kfree(resource);

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ struct dxghwqueue *dxghwqueue_create(struct dxgcontext *ctx);
613613
void dxghwqueue_destroy(struct dxgprocess *pr, struct dxghwqueue *hq);
614614
void dxghwqueue_release(struct kref *refcount);
615615

616+
/*
617+
* When a shared resource is created this structure provides information
618+
* about every allocation in the resource. It is used when someone opens the
619+
* resource and locks its allocation.
620+
*/
621+
struct dxgsharedallocdata {
622+
u32 private_data_size; /* Size of private data */
623+
u32 num_pages; /* Allocation size in pages */
624+
bool cached; /* True is the alloc memory is cached */
625+
};
626+
616627
/*
617628
* A shared resource object is created to track the list of dxgresource objects,
618629
* which are opened for the same underlying shared resource.
@@ -658,7 +669,7 @@ struct dxgsharedresource {
658669
};
659670
long flags;
660671
};
661-
u32 *alloc_private_data_sizes;
672+
struct dxgsharedallocdata *alloc_info;
662673
u8 *alloc_private_data;
663674
u8 *runtime_private_data;
664675
u8 *resource_private_data;

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource)
369369
u32 data_size;
370370
struct dxgresource *resource;
371371
struct dxgallocation *alloc;
372+
struct dxgsharedallocdata *alloc_info;
372373

373374
DXG_TRACE("Sealing resource: %p", shared_resource);
374375

@@ -409,9 +410,10 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource)
409410
ret = -EINVAL;
410411
goto cleanup1;
411412
}
412-
shared_resource->alloc_private_data_sizes =
413-
vzalloc(sizeof(u32)*shared_resource->allocation_count);
414-
if (shared_resource->alloc_private_data_sizes == NULL) {
413+
shared_resource->alloc_info =
414+
vzalloc(sizeof(struct dxgsharedallocdata) *
415+
shared_resource->allocation_count);
416+
if (shared_resource->alloc_info == NULL) {
415417
ret = -EINVAL;
416418
goto cleanup1;
417419
}
@@ -429,8 +431,10 @@ static int dxgsharedresource_seal(struct dxgsharedresource *shared_resource)
429431
ret = -EINVAL;
430432
goto cleanup1;
431433
}
432-
shared_resource->alloc_private_data_sizes[i] =
433-
alloc_data_size;
434+
alloc_info = &shared_resource->alloc_info[i];
435+
alloc_info->private_data_size = alloc_data_size;
436+
alloc_info->num_pages = alloc->num_pages;
437+
alloc_info->cached = alloc->cached;
434438
memcpy(private_data,
435439
alloc->priv_drv_data->data,
436440
alloc_data_size);
@@ -5031,6 +5035,7 @@ assign_resource_handles(struct dxgprocess *process,
50315035
u8 *cur_priv_data;
50325036
u32 total_priv_data_size = 0;
50335037
struct d3dddi_openallocationinfo2 open_alloc_info = { };
5038+
struct dxgsharedallocdata *alloc_info;
50345039

50355040
hmgrtable_lock(&process->handle_table, DXGLOCK_EXCL);
50365041
ret = hmgrtable_assign_handle(&process->handle_table, resource,
@@ -5050,11 +5055,15 @@ assign_resource_handles(struct dxgprocess *process,
50505055
allocs[i]->alloc_handle = handles[i];
50515056
allocs[i]->handle_valid = 1;
50525057
open_alloc_info.allocation = handles[i];
5053-
if (shared_resource->alloc_private_data_sizes)
5058+
if (shared_resource->alloc_info) {
5059+
alloc_info = &shared_resource->alloc_info[i];
50545060
open_alloc_info.priv_drv_data_size =
5055-
shared_resource->alloc_private_data_sizes[i];
5056-
else
5061+
alloc_info->private_data_size;
5062+
allocs[i]->num_pages = alloc_info->num_pages;
5063+
allocs[i]->cached = alloc_info->cached;
5064+
} else {
50575065
open_alloc_info.priv_drv_data_size = 0;
5066+
}
50585067

50595068
total_priv_data_size += open_alloc_info.priv_drv_data_size;
50605069
open_alloc_info.priv_drv_data = cur_priv_data;

0 commit comments

Comments
 (0)