From 41522f665fd2365bd03d5e146d7cbf74b82bb114 Mon Sep 17 00:00:00 2001 From: "Narlo, Joseph" Date: Wed, 28 May 2025 18:31:30 -0500 Subject: [PATCH] [SWDEV-532131] Update String Lengths (#383) Signed-off-by: Narlo, Joseph [ROCm/amdsmi commit: 7c29b4eab8da1ea7e57dad703ab1a6a149c9860f] --- projects/amdsmi/CHANGELOG.md | 5 +++++ projects/amdsmi/include/amd_smi/amdsmi.h | 18 ++++++------------ .../amdsmi/py-interface/amdsmi_interface.py | 3 +-- projects/amdsmi/py-interface/amdsmi_wrapper.py | 6 +++--- .../rust-interface/src/amdsmi_wrapper.rs | 10 +++++----- projects/amdsmi/src/amd_smi/amd_smi.cc | 6 ++++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index abd9e577bd..2d4cb0d0a6 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -98,6 +98,11 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr ### Changed +- **The char arrays in the following structures have been changed**. + - `amdsmi_vbios_info_t` member `build_date` changed from AMDSMI_MAX_DATE_LENGTH to AMDSMI_MAX_STRING_LENGTH. + - `amdsmi_dpm_policy_entry_t` member `policy_description` changed from AMDSMI_MAX_NAME to AMDSMI_MAX_STRING_LENGTH. + - `amdsmi_name_value_t` member `name` changed from AMDSMI_MAX_NAME to AMDSMI_MAX_STRING_LENGTH. + - **The `amd-smi topology` command has been enabled for Guest environments**. - `amd-smi topology` is now available in Guest environments. This includes full functionality so users can use the command just as they would in Bare Metal environments. diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index 94b363d42e..cc5b382ec6 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -753,7 +753,7 @@ typedef struct { */ typedef struct { char name[AMDSMI_MAX_STRING_LENGTH]; - char build_date[AMDSMI_MAX_DATE_LENGTH]; + char build_date[AMDSMI_MAX_STRING_LENGTH]; char part_number[AMDSMI_MAX_STRING_LENGTH]; char version[AMDSMI_MAX_STRING_LENGTH]; uint64_t reserved[32]; @@ -1252,21 +1252,15 @@ typedef enum { */ #define AMDSMI_EVENT_MASK_FROM_INDEX(i) (1ULL << ((i) - 1)) -/** - * @brief Maximum number of characters an event notification message will be - * matches kfd message max size - */ -#define MAX_EVENT_NOTIFICATION_MSG_SIZE 256 - /** * @brief Event notification data returned from event notification API * * @cond @tag{gpu_bm_linux} @endcond */ typedef struct { - amdsmi_processor_handle processor_handle; //!< Handler of device that corresponds to the event - amdsmi_evt_notification_type_t event; //!< Event type - char message[MAX_EVENT_NOTIFICATION_MSG_SIZE]; //!< Event message + amdsmi_processor_handle processor_handle; //!< Handler of device that corresponds to the event + amdsmi_evt_notification_type_t event; //!< Event type + char message[AMDSMI_MAX_STRING_LENGTH]; //!< Event message } amdsmi_evt_notification_data_t; /** @@ -1614,7 +1608,7 @@ typedef struct { */ typedef struct { uint32_t policy_id; - char policy_description[AMDSMI_MAX_NAME]; + char policy_description[AMDSMI_MAX_STRING_LENGTH]; } amdsmi_dpm_policy_entry_t; #define AMDSMI_MAX_NUM_PM_POLICIES 32 @@ -1982,7 +1976,7 @@ typedef struct { * @cond @tag{gpu_bm_linux} @endcond */ typedef struct { - char name[MAX_AMDSMI_NAME_LENGTH]; //!< Name + char name[AMDSMI_MAX_STRING_LENGTH]; //!< Name uint64_t value; //!< Use uint64_t to make it universal } amdsmi_name_value_t; diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 207ca2e3dd..50ad5fbb19 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -78,7 +78,7 @@ AMDSMI_NUM_VOLTAGE_CURVE_POINTS = 3 # Max size definitions AMDSMI_MAX_MM_IP_COUNT = 8 AMDSMI_MAX_DATE_LENGTH = 32 -AMDSMI_MAX_STRING_LENGTH = 64 +AMDSMI_MAX_STRING_LENGTH = 256 AMDSMI_MAX_DEVICES = 32 AMDSMI_MAX_NAME = 32 AMDSMI_MAX_DRIVER_VERSION_LENGTH = 80 @@ -88,7 +88,6 @@ AMDSMI_MAX_CACHE_TYPES = 10 AMDSMI_MAX_NUM_XGMI_PHYSICAL_LINK = 64 AMDSMI_GPU_UUID_SIZE = 38 MAX_AMDSMI_NAME_LENGTH = 64 -MAX_EVENT_NOTIFICATION_MSG_SIZE = 256 _AMDSMI_STRING_LENGTH = 80 diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 1fa4238d72..a89cabe36f 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -908,7 +908,7 @@ class struct_amdsmi_vbios_info_t(Structure): struct_amdsmi_vbios_info_t._pack_ = 1 # source:False struct_amdsmi_vbios_info_t._fields_ = [ ('name', ctypes.c_char * 256), - ('build_date', ctypes.c_char * 32), + ('build_date', ctypes.c_char * 256), ('part_number', ctypes.c_char * 256), ('version', ctypes.c_char * 256), ('reserved', ctypes.c_uint64 * 32), @@ -1804,7 +1804,7 @@ class struct_amdsmi_dpm_policy_entry_t(Structure): struct_amdsmi_dpm_policy_entry_t._pack_ = 1 # source:False struct_amdsmi_dpm_policy_entry_t._fields_ = [ ('policy_id', ctypes.c_uint32), - ('policy_description', ctypes.c_char * 32), + ('policy_description', ctypes.c_char * 256), ] amdsmi_dpm_policy_entry_t = struct_amdsmi_dpm_policy_entry_t @@ -2022,7 +2022,7 @@ class struct_amdsmi_name_value_t(Structure): struct_amdsmi_name_value_t._pack_ = 1 # source:False struct_amdsmi_name_value_t._fields_ = [ - ('name', ctypes.c_char * 64), + ('name', ctypes.c_char * 256), ('value', ctypes.c_uint64), ] diff --git a/projects/amdsmi/rust-interface/src/amdsmi_wrapper.rs b/projects/amdsmi/rust-interface/src/amdsmi_wrapper.rs index 64ad2f4b5f..719e45164f 100644 --- a/projects/amdsmi/rust-interface/src/amdsmi_wrapper.rs +++ b/projects/amdsmi/rust-interface/src/amdsmi_wrapper.rs @@ -793,7 +793,7 @@ const _: () = { #[derive(Debug, Copy, Clone)] pub struct AmdsmiVbiosInfoT { pub name: [::std::os::raw::c_char; 256usize], - pub build_date: [::std::os::raw::c_char; 32usize], + pub build_date: [::std::os::raw::c_char; 256usize], pub part_number: [::std::os::raw::c_char; 256usize], pub version: [::std::os::raw::c_char; 256usize], pub reserved: [u64; 32usize], @@ -807,11 +807,11 @@ const _: () = { ["Offset of field: AmdsmiVbiosInfoT::build_date"] [::std::mem::offset_of!(AmdsmiVbiosInfoT, build_date) - 256usize]; ["Offset of field: AmdsmiVbiosInfoT::part_number"] - [::std::mem::offset_of!(AmdsmiVbiosInfoT, part_number) - 288usize]; + [::std::mem::offset_of!(AmdsmiVbiosInfoT, part_number) - 512usize]; ["Offset of field: AmdsmiVbiosInfoT::version"] - [::std::mem::offset_of!(AmdsmiVbiosInfoT, version) - 544usize]; + [::std::mem::offset_of!(AmdsmiVbiosInfoT, version) - 768usize]; ["Offset of field: AmdsmiVbiosInfoT::reserved"] - [::std::mem::offset_of!(AmdsmiVbiosInfoT, reserved) - 800usize]; + [::std::mem::offset_of!(AmdsmiVbiosInfoT, reserved) - 1024usize]; }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1833,7 +1833,7 @@ const _: () = { #[derive(Debug, Copy, Clone)] pub struct AmdsmiDpmPolicyEntryT { pub policy_id: u32, - pub policy_description: [::std::os::raw::c_char; 32usize], + pub policy_description: [::std::os::raw::c_char; 256usize], } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index f70d06a6ff..c4e1f72015 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -1914,8 +1914,9 @@ amdsmi_get_gpu_event_notification(int timeout_ms, rsmi_evt_notification_data_t rsmi_data = r_data[i]; data[i].event = static_cast( rsmi_data.event); + // Size is tied max event notification size snprintf(data[i].message, - MAX_EVENT_NOTIFICATION_MSG_SIZE, + AMDSMI_MAX_STRING_LENGTH, "%s", rsmi_data.message); amdsmi_status_t r = amd::smi::AMDSmiSystem::getInstance() @@ -3637,7 +3638,8 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios if (drm_write == 0) { strncpy(info->name, reinterpret_cast(vbios.name), AMDSMI_MAX_STRING_LENGTH); - strncpy(info->build_date, reinterpret_cast(vbios.date), AMDSMI_MAX_DATE_LENGTH); + strncpy(info->build_date, reinterpret_cast(vbios.date), AMDSMI_MAX_STRING_LENGTH - 1); + info->build_date[AMDSMI_MAX_STRING_LENGTH - 1] = '\0'; strncpy(info->part_number, reinterpret_cast(vbios.vbios_pn), AMDSMI_MAX_STRING_LENGTH); strncpy(info->version, reinterpret_cast(vbios.vbios_ver_str),