Skip to content

Commit a43e2a0

Browse files
fxkamdalexdeucher
authored andcommitted
drm/amdkfd: Allow querying SVM attributes that are clear
Currently the SVM get_attr call allows querying, which flags are set in the entire address range. Add the opposite query, which flags are clear in the entire address range. Both queries can be combined in a single get_attr call, which allows answering questions such as, "is this address range coherent, non-coherent, or a mix of both"? Proposed userspace for UAPI: https://github.com/RadeonOpenCompute/ROCR-Runtime/tree/memory_model_queries Signed-off-by: Felix Kuehling <[email protected]> Reviewed-by: Philip Yand <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent ed7c28c commit a43e2a0

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_svm.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,8 @@ svm_range_get_attr(struct kfd_process *p, uint64_t start, uint64_t size,
30193019
struct svm_range *prange;
30203020
uint32_t prefetch_loc = KFD_IOCTL_SVM_LOCATION_UNDEFINED;
30213021
uint32_t location = KFD_IOCTL_SVM_LOCATION_UNDEFINED;
3022-
uint32_t flags = 0xffffffff;
3022+
uint32_t flags_and = 0xffffffff;
3023+
uint32_t flags_or = 0;
30233024
int gpuidx;
30243025
uint32_t i;
30253026

@@ -3046,12 +3047,12 @@ svm_range_get_attr(struct kfd_process *p, uint64_t start, uint64_t size,
30463047
get_accessible = true;
30473048
break;
30483049
case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
3050+
case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
30493051
get_flags = true;
30503052
break;
30513053
case KFD_IOCTL_SVM_ATTR_GRANULARITY:
30523054
get_granularity = true;
30533055
break;
3054-
case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
30553056
case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:
30563057
case KFD_IOCTL_SVM_ATTR_NO_ACCESS:
30573058
fallthrough;
@@ -3069,7 +3070,8 @@ svm_range_get_attr(struct kfd_process *p, uint64_t start, uint64_t size,
30693070
if (!node) {
30703071
pr_debug("range attrs not found return default values\n");
30713072
svm_range_set_default_attributes(&location, &prefetch_loc,
3072-
&granularity, &flags);
3073+
&granularity, &flags_and);
3074+
flags_or = flags_and;
30733075
if (p->xnack_enabled)
30743076
bitmap_copy(bitmap_access, svms->bitmap_supported,
30753077
MAX_GPU_INSTANCE);
@@ -3115,8 +3117,10 @@ svm_range_get_attr(struct kfd_process *p, uint64_t start, uint64_t size,
31153117
bitmap_and(bitmap_aip, bitmap_aip,
31163118
prange->bitmap_aip, MAX_GPU_INSTANCE);
31173119
}
3118-
if (get_flags)
3119-
flags &= prange->flags;
3120+
if (get_flags) {
3121+
flags_and &= prange->flags;
3122+
flags_or |= prange->flags;
3123+
}
31203124

31213125
if (get_granularity && prange->granularity < granularity)
31223126
granularity = prange->granularity;
@@ -3150,7 +3154,10 @@ svm_range_get_attr(struct kfd_process *p, uint64_t start, uint64_t size,
31503154
attrs[i].type = KFD_IOCTL_SVM_ATTR_NO_ACCESS;
31513155
break;
31523156
case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
3153-
attrs[i].value = flags;
3157+
attrs[i].value = flags_and;
3158+
break;
3159+
case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
3160+
attrs[i].value = ~flags_or;
31543161
break;
31553162
case KFD_IOCTL_SVM_ATTR_GRANULARITY:
31563163
attrs[i].value = (uint32_t)granularity;

include/uapi/linux/kfd_ioctl.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
* - 1.3 - Add SMI events support
3232
* - 1.4 - Indicate new SRAM EDC bit in device properties
3333
* - 1.5 - Add SVM API
34+
* - 1.6 - Query clear flags in SVM get_attr API
3435
*/
3536
#define KFD_IOCTL_MAJOR_VERSION 1
36-
#define KFD_IOCTL_MINOR_VERSION 5
37+
#define KFD_IOCTL_MINOR_VERSION 6
3738

3839
struct kfd_ioctl_get_version_args {
3940
__u32 major_version; /* from KFD */
@@ -575,18 +576,19 @@ struct kfd_ioctl_svm_attribute {
575576
* @KFD_IOCTL_SVM_ATTR_PREFERRED_LOC or
576577
* @KFD_IOCTL_SVM_ATTR_PREFETCH_LOC resepctively. For
577578
* @KFD_IOCTL_SVM_ATTR_SET_FLAGS, flags of all pages will be
578-
* aggregated by bitwise AND. The minimum migration granularity
579-
* throughout the range will be returned for
580-
* @KFD_IOCTL_SVM_ATTR_GRANULARITY.
579+
* aggregated by bitwise AND. That means, a flag will be set in the
580+
* output, if that flag is set for all pages in the range. For
581+
* @KFD_IOCTL_SVM_ATTR_CLR_FLAGS, flags of all pages will be
582+
* aggregated by bitwise NOR. That means, a flag will be set in the
583+
* output, if that flag is clear for all pages in the range.
584+
* The minimum migration granularity throughout the range will be
585+
* returned for @KFD_IOCTL_SVM_ATTR_GRANULARITY.
581586
*
582587
* Querying of accessibility attributes works by initializing the
583588
* attribute type to @KFD_IOCTL_SVM_ATTR_ACCESS and the value to the
584589
* GPUID being queried. Multiple attributes can be given to allow
585590
* querying multiple GPUIDs. The ioctl function overwrites the
586591
* attribute type to indicate the access for the specified GPU.
587-
*
588-
* @KFD_IOCTL_SVM_ATTR_CLR_FLAGS is invalid for
589-
* @KFD_IOCTL_SVM_OP_GET_ATTR.
590592
*/
591593
struct kfd_ioctl_svm_args {
592594
__u64 start_addr;

0 commit comments

Comments
 (0)