From 4844a70d945e23416888eae4b900c3b25578cd25 Mon Sep 17 00:00:00 2001 From: Lang Yu Date: Wed, 17 Apr 2024 09:19:23 +0800 Subject: [PATCH] libhsakmt: Prevent hsaKmtRegisterMemory* from registering non-userptr hsaKmtRegisterMemory* can only register OS allocated userptr. v2: Apply changes to all hsaKmtRegisterMemory* stuff.(Philip) v3: Unlock aperture->fmm_mutex to aviod deadlock. Suggested-by: Felix Kuehling Change-Id: I1045af7edb4da8206cb878f64c0176ba4fc59f60 Signed-off-by: Lang Yu Signed-off-by: Chris Freehill --- libhsakmt/src/fmm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libhsakmt/src/fmm.c b/libhsakmt/src/fmm.c index ef9e3f628c..b99c138345 100644 --- a/libhsakmt/src/fmm.c +++ b/libhsakmt/src/fmm.c @@ -3533,6 +3533,10 @@ HSAKMT_STATUS fmm_register_memory(void *address, uint64_t size_in_bytes, } else if (object->userptr) { /* Update an existing userptr */ ++object->registration_count; + } else { + /* Not a userptr when we are expecting one */ + pthread_mutex_unlock(&aperture->fmm_mutex); + return HSAKMT_STATUS_INVALID_HANDLE; } /* Successful vm_find_object returns with aperture locked */