Repository navigation
libibverbs: Zero-initialize buffer in default alloc_buf() op - #1827
eagleidirect wants to merge 1 commit into
Conversation
Ensure the default alloc_buf() fallback in dummy_ops.c zeroes the allocated memory with memset(), matching provider implementations and callers such as rsocket that expect zero-initialized control and data buffers. Signed-off-by: Ying Xiao <eagleshaw@google.com>
| return NULL; | ||
| } | ||
|
|
||
| memset(ptr, 0, size); |
There was a problem hiding this comment.
This appears needed, thought it is not clear if we should add it here in alloc_buf. I am thinking if this allocation call would ever end up in a hot path, where memset can be costly. But this is not a new issue, and similar pattern as in alloc forksafe.
There was a problem hiding this comment.
In librdmacm/rsocket.c (https://github.com/linux-rdma/rdma-core/pull/1826/changes), memset is carried out outside ibv_alloc_buf(), so there is flexibility.
rs->target_buffer_list appears need zeroing, as it holds control structures, like rs_sge, and rs_iomap - so zero-initialized state appears important.
While later ibv_alloc_buf() calls does not require zeroing, as send / receive buffers as they will be written before check
Zero-initialize memory allocated by the fallback
alloc_buf()implementation inlibibverbs/dummy_ops.c(memset(ptr, 0, size)afterposix_memalign()) so callers migrating fromcalloc()/forksafe_alloc()toibv_alloc_buf()do not read uninitialized control structures on providers using the default fallback.cc: @jakemoroni @10000TB