From bfbb2f9de78a98c51071c8987c7500f00d6e4f22 Mon Sep 17 00:00:00 2001 From: adapryor Date: Thu, 24 Oct 2024 08:13:18 -0500 Subject: [PATCH] [SWDEV-412505] Handle mclk permission errors as not supported Change-Id: Idb3eeed76ff55c507f28b5e692f8704704c3e46e Signed-off-by: adapryor [ROCm/amdsmi commit: 02cbffb42a7bf3fb8654d5a0e30b0b2b6e394bcc] --- .../rocm_smi/include/rocm_smi/rocm_smi_utils.h | 1 + projects/amdsmi/rocm_smi/src/rocm_smi.cc | 17 ++++++++++++++--- projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h b/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h index 6dc4588cd7..901eb96954 100644 --- a/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h +++ b/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h @@ -82,6 +82,7 @@ int SameFile(const std::string fileA, const std::string fileB); bool FileExists(char const *filename); std::vector globFilesExist(const std::string& filePattern); int isRegularFile(std::string fname, bool *is_reg); +int isReadOnlyForAll(const std::string& fname, bool *is_read_only); int ReadSysfsStr(std::string path, std::string *retStr); int WriteSysfsStr(std::string path, std::string val); bool IsInteger(const std::string & n_str); diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi.cc b/projects/amdsmi/rocm_smi/src/rocm_smi.cc index 90593b0523..b0c3ea1ead 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi.cc @@ -2054,7 +2054,7 @@ rsmi_dev_gpu_clk_freq_set(uint32_t dv_ind, return ret; } - int ret_i; + rsmi_status_t status; amd::smi::DevInfoTypes dev_type; const auto & clk_type_it = kClkTypeMap.find(clk_type); @@ -2064,9 +2064,20 @@ rsmi_dev_gpu_clk_freq_set(uint32_t dv_ind, return RSMI_STATUS_INVALID_ARGS; } - ret_i = dev->writeDevInfo(dev_type, freq_enable_str); - return amd::smi::ErrnoToRsmiStatus(ret_i); + status = amd::smi::ErrnoToRsmiStatus(dev->writeDevInfo(dev_type, freq_enable_str)); + // If an operation is not supported, the dev file, ie /sys/class/drm/card1/device/pp_dpm_pcie + // will have read-only perms, and the OS will deny access, before the request hits the driver level + if (status == RSMI_STATUS_PERMISSION){ + bool read_only = false; + int perms = amd::smi::isReadOnlyForAll(dev->path(), &read_only); + if(read_only){ + return RSMI_STATUS_NOT_SUPPORTED; + } + } + + return status; + CATCH } diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc index 7c9ece9be1..332228baf1 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc @@ -173,6 +173,24 @@ int isRegularFile(std::string fname, bool *is_reg) { return 0; } +int isReadOnlyForAll(const std::string& fname, bool *is_read_only){ + struct stat file_stat; + int ret; + + ret = stat(fname.c_str(), &file_stat); + if (ret) { + return errno; + } + + if (is_read_only != nullptr) { + *is_read_only = (file_stat.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) && !(file_stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)); + } else { + ret = 1; + } + + return ret; +} + int WriteSysfsStr(std::string path, std::string val) { // On success, zero is returned. On error, -1 is returned, and // errno is set to indicate the error.