-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Move the pointer to pin off the stack to the heap #74118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary: This may be problematic to pin a stack pointer. Allocate it via the OS allocator instead as the documentation suggests. For some reason, if you attempt to free this pointer after the memory region has been unlocked, it will return an invalid pointer.
@llvm/pr-subscribers-backend-amdgpu Author: Joseph Huber (jhuber6) ChangesSummary: For some reason, if you attempt to free this pointer after the memory Full diff: https://github.com/llvm/llvm-project/pull/74118.diff 1 Files Affected:
diff --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp
index a9a687656efcb39..d3d2c2b42080837 100644
--- a/libc/utils/gpu/loader/amdgpu/Loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp
@@ -471,7 +471,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
handle_error(err);
// Pin some memory we can use to obtain the address of the rpc client.
- void *rpc_client_storage = nullptr;
+ void **rpc_client_storage = new void *;
void *rpc_client_host = nullptr;
if (hsa_status_t err =
hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
|
@llvm/pr-subscribers-libc Author: Joseph Huber (jhuber6) ChangesSummary: For some reason, if you attempt to free this pointer after the memory Full diff: https://github.com/llvm/llvm-project/pull/74118.diff 1 Files Affected:
diff --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp
index a9a687656efcb39..d3d2c2b42080837 100644
--- a/libc/utils/gpu/loader/amdgpu/Loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp
@@ -471,7 +471,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
handle_error(err);
// Pin some memory we can use to obtain the address of the rpc client.
- void *rpc_client_storage = nullptr;
+ void **rpc_client_storage = new void *;
void *rpc_client_host = nullptr;
if (hsa_status_t err =
hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
|
@@ -471,7 +471,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size, | |||
handle_error(err); | |||
|
|||
// Pin some memory we can use to obtain the address of the rpc client. | |||
void *rpc_client_storage = nullptr; | |||
void **rpc_client_storage = new void *; | |||
void *rpc_client_host = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably wrong that it used to be a void* and is now a void**, could that be why delete was a problem?
void *rpc_client_host = nullptr; | ||
if (hsa_status_t err = | ||
hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *), | ||
/*agents=*/nullptr, 0, &rpc_client_host)) | ||
handle_error(err); | ||
free(rpc_client_storage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be right. If you allocated some memory, and then locked it, you still need to leave that memory allocated until you're finished with it. Free should be after the unlock. Nested lifetimes and all that.
Github has mangled this. If it's now a three line change - malloc, &, free - then we're good to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't land this as five separate commits
Summary:
This may be problematic to pin a stack pointer. Allocate it via the OS
allocator instead as the documentation suggests.
For some reason, if you attempt to free this pointer after the memory
region has been unlocked, it will return an invalid pointer.