Closed operezmuena closed 2 years ago
Ah, I think there's an issue with using resp.reserve()
here:
https://github.com/openbmc/dbus-sensors/blob/master/src/NVMeBasicContext.cpp#L80
The size of the response is returned but the size of the vector is never changed. It's not invalid from a memory-safety standpoint, just the vector never changes to a size that's appropriate to fetch the values out (I've run it under valgrind and poked around but haven't caused any issues). Further, just adding a resize() before the return will overwrite the values just written by the call to i2c_smbus_read_block_data()
so we'll have to do something more. It's odd that I'm not seeing it fail but you are, because it seems there's definitely a bug there.
I'd prefer we stick with a vector rather than use a templated array as this allows execBasicQuery()
to abstract the response sizes away for the caller. @operezmuena can you try this patch?
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index 08333c591081..5708ad843c00 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -77,7 +77,7 @@ static ssize_t execBasicQuery(int bus, uint8_t addr, uint8_t cmd,
return -errno;
}
- resp.reserve(UINT8_MAX + 1);
+ resp.resize(UINT8_MAX + 1);
/* Issue the NVMe MI basic command */
size = i2c_smbus_read_block_data(fileHandle.handle(), cmd, resp.data());
@@ -96,6 +96,8 @@ static ssize_t execBasicQuery(int bus, uint8_t addr, uint8_t cmd,
return -EBADMSG;
}
+ resp.resize(size);
+
return size;
}
@amboar I just tested your patch and it does solve my issues. Thank you for the prompt response.
@operezmuena Do you mind marking it as verified here: https://gerrit.openbmc-project.xyz/c/openbmc/dbus-sensors/+/52531
Actually, this was broken by 73030639a5ba8 at https://github.com/openbmc/dbus-sensors/commit/73030639a5ba8#diff-5abbed76e66786eec2a94b186f608b090c253722a2b37635b278e0740e3a5e4aL185-L187 where we switch from accessing the backing buffer directly to using an iterator over the vector.
I've recently begun testing NVMe sensors and I've been having temperature reading issues with my Intel SSD P4510 devices. Debugging the NVMe code, I noticed that the "i2c_smbus_read_block_data()" function is returning a size of 6 but, no sensor data is found in the "resp" vector.
size = i2c_smbus_read_block_data(fileHandle.handle(), cmd, resp.data());
Only after I changed 'resp' from being a std::vector type to a std::array type, I began seeing valid temperature readings from my SSD drives. Here is my patch for your reference: