Skip to content

libibverbs: Zero-initialize buffer in default alloc_buf() op - #1827

Draft
eagleidirect wants to merge 1 commit into
linux-rdma:masterfrom
eagleidirect:dummy-ops-zero-buf
Draft

eagleidirect wants to merge 1 commit into
linux-rdma:masterfrom
eagleidirect:dummy-ops-zero-buf

Conversation

@eagleidirect

Copy link
Copy Markdown
Contributor

Zero-initialize memory allocated by the fallback alloc_buf() implementation in libibverbs/dummy_ops.c (memset(ptr, 0, size) after posix_memalign()) so callers migrating from calloc() / forksafe_alloc() to ibv_alloc_buf() do not read uninitialized control structures on providers using the default fallback.

cc: @jakemoroni @10000TB

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>
Comment thread libibverbs/dummy_ops.c
return NULL;
}

memset(ptr, 0, size);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants