Skip to content

[Offload] Fix segfault when looking for host device name #141632

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

Merged
merged 1 commit into from
May 27, 2025

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented May 27, 2025

Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.

Fixes: #141434

Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.

Fixes: llvm#141434
@jhuber6 jhuber6 requested review from jdoerfert and shiltian May 27, 2025 16:57
@jhuber6
Copy link
Contributor Author

jhuber6 commented May 27, 2025

@callumfare Don't think I can add you as a reviewer the normal way yet.

@llvmbot
Copy link
Member

llvmbot commented May 27, 2025

@llvm/pr-subscribers-offload

Author: Joseph Huber (jhuber6)

Changes

Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.

Fixes: #141434


Full diff: https://github.com/llvm/llvm-project/pull/141632.diff

2 Files Affected:

  • (modified) offload/liboffload/src/OffloadImpl.cpp (+6)
  • (modified) offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp (+10)
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index ea65282e3ba52..ac2ca20601cae 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -230,6 +230,12 @@ ol_impl_result_t olGetDeviceInfoImplDetail(ol_device_handle_t Device,
   // Find the info if it exists under any of the given names
   auto GetInfo = [&](std::vector<std::string> Names) {
     InfoQueueTy DevInfo;
+    if (Device == HostDevice())
+      return std::string("Host");
+
+    if (!Device->Device)
+      return std::string("");
+
     if (auto Err = Device->Device->obtainInfoImpl(DevInfo))
       return std::string("");
 
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index 46ed622fa8b81..1240f219813e2 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -37,6 +37,16 @@ TEST_P(olGetDeviceInfoTest, SuccessName) {
   ASSERT_EQ(std::strlen(Name.data()), Size - 1);
 }
 
+TEST_P(olGetDeviceInfoTest, HostName) {
+  size_t Size = 0;
+  ASSERT_SUCCESS(olGetDeviceInfoSize(Host, OL_DEVICE_INFO_NAME, &Size));
+  ASSERT_GT(Size, 0ul);
+  std::vector<char> Name;
+  Name.resize(Size);
+  ASSERT_SUCCESS(olGetDeviceInfo(Host, OL_DEVICE_INFO_NAME, Size, Name.data()));
+  ASSERT_EQ(std::strlen(Name.data()), Size - 1);
+}
+
 TEST_P(olGetDeviceInfoTest, SuccessVendor) {
   size_t Size = 0;
   ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_VENDOR, &Size));

@jhuber6 jhuber6 merged commit a9b64bb into llvm:main May 27, 2025
11 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.

Fixes: llvm#141434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Offload] Segmentation fault when calling olGetDeviceInfoSize for host device name
3 participants