Repository navigation
librdmacm: Add Confidential Computing (CoCo) support for rsocket - #1826
eagleidirect wants to merge 5 commits into
Conversation
| free(rs->rmsg); | ||
|
|
||
| if (rs->index >= 0) | ||
| rs_remove(rs); |
There was a problem hiding this comment.
This also seems a net positive change, to prevent new accesses after buf freeed, and before rs_remove. Was this done as a general improvement together as part of CoCo support, or is there a CoCo specific reason for this ordering change ?
There was a problem hiding this comment.
Both: in general, calling rs_remove() and rdma_destroy_qp() before deregistering MRs and freeing sbuf/rbuf prevents hardware or concurrent fd lookups from touching unmapped buffers. For CoCo specifically (commit 4), cm_id->pd becomes the CoCo parent PD backing both the QP/CQ and the ibv_buf allocations (sbuf_ibv/rbuf_ibv), so destroying the QP/CQ first, then freeing the MRs/ibv_bufs, and finally calling ibv_dealloc_pd(cm_id->pd) before rdma_destroy_id() ensures all child objects are released before the parent PD and its dmabuf_heap are torn down.
|
FWIW, there is a patch series that I believe will effectively prevent RDMA CM from working with untrusted NICs in a CVM, which I think would break rsocket. Can you take a look and see what the impact would be? |
|
Thanks for flagging this, @jakemoroni! I looked through Yishai's V2 kernel series and companion PR #1844. For cc_dma_bounce devices that leave ib_device::adversarial_mode = 0 (like irdma in #1766 today), kverbs_provider stays true, so rdma_cm and rsocket (SOCK_STREAM and SOCK_DGRAM) continue working as-is. For devices that set adversarial_mode = 1 (mlx5 in a CC guest), you're right: RDMA core clears kverbs_provider so kernel ULPs (MAD, IB CM, rdma_cm) don't bind to the untrusted device, which makes librdmacm device/address resolution fail with ENODEV and breaks rsocket on mlx5 in a CVM. PR #1844 also rejects IBV_QPT_UD and ibv_create_ah(), ruling out SOCK_DGRAM at the verbs layer. All of RoCE/IB rsocket SOCK_STREAM's RC data-path verbs (IBV_QPT_RC, RDMA_WRITE, RDMA_WRITE_WITH_IMM, IBV_SEND_INLINE, 0-SGE ibv_post_recv, and ibv_poll_cq) are still supported by #1844, though. So if we want SOCK_STREAM to work on adversarial_mode devices in a follow-up, rsocket could fall back to an out-of-band TCP handshake to transition the RC QP via uverbs (plus bounds-checking wc.imm_data and target_sgl in shared memory). |
shefty
left a comment
There was a problem hiding this comment.
I only reviewed 2 of the patches. My main concern is that this series tries to add CoCo support only to rsockets without the rdma_cm itself being CoCo aware. Yet, it's the rdma_cm which is calling through to CoCo verbs.
I don't think the rdma_cm needs full support (so pieces of the implementation can be deferred), but it should have enough to support rsocket's needs.
I haven't thought through all the pieces, but my general idea is to store the parent_domain with the ucma_device. For the cm_id, an opt-in model is preferrable. For example, use rdma_set_option() to change the cm_id->pd to the parent_domain. This should be set prior to using the cm_id->pd.
The CoCo requirement could be stored as a flag on the ucma_device. We may need to expose a new private ucma_ function for rsockets to use.
|
|
||
| if (qp->cm_id) { | ||
| if (qp->dest.ah) | ||
| ibv_destroy_ah(qp->dest.ah); |
There was a problem hiding this comment.
This looks like it solves a real leak
| rdma_destroy_qp(qp->cm_id); | ||
| } else if (qp->cm_id->recv_cq) { | ||
| ibv_destroy_cq(qp->cm_id->recv_cq); | ||
| ibv_destroy_comp_channel(qp->cm_id->recv_cq_channel); |
There was a problem hiding this comment.
I don't believe this path can be taken, but I'm okay keeping it.
| rdma_destroy_qp(rs->cm_id); | ||
| } else if (rs->cm_id->recv_cq) { | ||
| ibv_destroy_cq(rs->cm_id->recv_cq); | ||
| ibv_destroy_comp_channel(rs->cm_id->recv_cq_channel); |
There was a problem hiding this comment.
As above, I don't think this path can be taken, but I'm okay with it.
| ibv_destroy_comp_channel(rs->cm_id->recv_cq_channel); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
The reordering of the destroy path is fine. But it shouldn't have an impact on security. Deregistering a MR should invalidate the lkey/rkey, resulting in any access to the MR failing.
There was a problem hiding this comment.
Good point. Updated the commit message in v2 to drop the security rationale and focus on keeping cm_id->pd alive until after ibv_free_buf().
| if (!coco_parent_pd) | ||
| goto err1; | ||
| cq_attr.parent_domain = coco_parent_pd; | ||
| cm_id->recv_cq = ibv_cq_ex_to_cq(ibv_create_cq_ex(cm_id->verbs, &cq_attr)); |
There was a problem hiding this comment.
I have a couple concerns about this flow. First, this queries the device for CC_DMA_BOUNCE for every rsocket. Second, it allocates a parent domain for each rsocket.
The coco_parent_pd would be better paired next to the actual pd. That means relocating it to umca_device, which would fix both concerns.
And that raises the issue whether the approach shouldn't start with adding CoCo support to the rdma_cm itself.
There was a problem hiding this comment.
Updated in v2: moved cc_dma_bounce and a single lazily allocated coco_pd onto struct cma_device alongside cma_dev->pd (commit 1), so the device is queried once and one shared parent domain is reused across rsockets.
| if (coco_parent_pd) { | ||
| cm_id->pd = coco_parent_pd; | ||
| rs->opts |= RS_OPT_COCO_PD; | ||
| } |
There was a problem hiding this comment.
For example, changes like this where the PD is swapped out, so that rdma_create_qp works builds in a hidden and possibly fragile dependency.
The rdma_cm 'core' needs to use the parent_domain, but it's unaware that it's actually occuring.
There was a problem hiding this comment.
Updated in v2: removed the direct cm_id->pd swap from rsocket.c. rsocket now opts in via private ucma_set_coco_pd() and ucma_create_cq() helpers in cma.c, so librdmacm owns the coco_pd lifecycle and propagates the opt-in to accepted child IDs.
In Confidential Computing (CoCo) guests whose RDMA device reports IBV_DEVICE_CC_DMA_BOUNCE, hardware queues and data buffers must be allocated from an unprotected parent domain created with IBV_PARENT_DOMAIN_INIT_ATTR_ALLOW_CC_UNPROTECTED_ALLOC. Having internal consumers such as rsocket query the device and allocate a parent domain per connection adds repeated device queries, duplicates parent domains, and leaves librdmacm unaware of the substituted cm_id->pd. Cache IBV_DEVICE_CC_DMA_BOUNCE and a single lazily allocated coco_pd on struct cma_device alongside cma_dev->pd, releasing coco_pd before pd when the device refcount drops to zero or the device is removed. If a provider does not support ALLOW_CC_UNPROTECTED_ALLOC (EOPNOTSUPP or EINVAL), clear the cached flag and fall back to cma_dev->pd. Add private helpers ucma_set_coco_pd() and ucma_create_cq() so callers can opt an rdma_cm_id into the shared CoCo parent domain (propagated to accepted child IDs) and create extended CQs bound to coco_pd while leaving non-CoCo and regular rdma_cm paths unchanged. Signed-off-by: Ying Xiao <eagleshaw@google.com>
Upcoming ibv_free_buf() buffer teardown requires the buffer's allocation PD (cm_id->pd) to remain valid until all buffers are released, and rs_free()/ds_free_qp() currently deregister MRs and free buffers before destroying QPs/CQs and removing the rsocket from lookup tables. In addition, ds_free_qp() leaks qp->dest.ah and clobbers errno when unwinding ds_create_qp() failures, ds_create_qp() initializes buffers before creating the CQ, and rs_create_cq() dereferences cm_id->verbs without checking for a non-RDMA rdma_bind_addr(). Reorder rs_free() and ds_free_qp() to destroy the QP (or standalone CQ and completion channel) and qp->dest.ah before deregistering MRs and freeing buffers, move rs_remove() and rs_free_iomappings() ahead of buffer teardown, and call rdma_destroy_id() last. Preserve errno across ds_free_qp() on ds_create_qp() error paths, create the CQ before ds_init_bufs() in ds_create_qp() to match rs_create_ep(), and return ENODEV from rs_create_cq() when cm_id->verbs or cm_id->pd is NULL. Fixes: e6e93ed ("rsocket: Add datagram support") Signed-off-by: Ying Xiao <eagleshaw@google.com>
A single SOCK_DGRAM rsocket can create multiple ds_qp instances across different local source addresses or RDMA devices (rs->qp_list), each with its own qp->cm_id->pd. Unlike qp->rbuf, which is allocated per ds_qp, sbuf was previously allocated once on struct rsocket and registered across every ds_qp. Because ibv_reg_buf_mr() requires the registration PD to match the allocation PD (pd == buf->pd), a single shared send buffer cannot be registered across multiple ds_qp instances with distinct PDs. Move sbuf into the SOCK_STREAM union of struct rsocket and allocate qp->sbuf per struct ds_qp in ds_init_bufs(), matching qp->rbuf. Keep the send slot freelist (qp->smsg_free) in a private uint16_t index stack instead of an intrusive pointer list inside qp->sbuf so raw guest pointers are never stored in DMA-accessible/unencrypted send buffers, synchronize slot pop/push under rs->cq_lock, bounds-check completion slot indices, and return the slot if ds_post_send() fails. Signed-off-by: Ying Xiao <eagleshaw@google.com>
In Confidential Computing (CoCo) guests, private memory allocated via forksafe_alloc() is encrypted and cannot be DMA-accessed by the RDMA device; buffers must instead be allocated through the protection domain's buffer allocator (such as an unprotected DMA-buf heap on a CoCo parent domain). Replace forksafe_alloc() and rdma_reg_msgs()/rdma_reg_write() with ibv_alloc_buf(), ibv_reg_buf_mr(), and ibv_free_buf() for stream and datagram rsocket buffers. Keep page-size length rounding in rs_alloc_buf() (while registering the logical length with ibv_reg_buf_mr()) so MADV_DONTFORK fork-safety from commit b2fedc4 ("rsocket: Make sure that the allocated memory is aligned") is preserved on providers using libibverbs' default alloc_buf(). Zero rs->target_buffer_list explicitly, reject zero-length allocations, guard page rounding against overflow, and preserve errno on allocation failure. Signed-off-by: Ying Xiao <eagleshaw@google.com>
In Confidential Computing (CoCo) guests whose RDMA device reports IBV_DEVICE_CC_DMA_BOUNCE, opt rsocket cm_ids into librdmacm's shared per-device CoCo parent domain via ucma_set_coco_pd() in rsocket() (SOCK_STREAM) and ds_create_qp() (SOCK_DGRAM), and create CQs via ucma_create_cq() in rs_create_cq(). Because cma_device caches both the CC_DMA_BOUNCE capability and the shared coco_pd, rsocket does not need to query the device or allocate a parent domain per socket, and cm_id->pd is managed directly by librdmacm across active connections, accepted child sockets, and datagram QPs. Signed-off-by: Ying Xiao <eagleshaw@google.com>
9483a63 to
3ce2328
Compare
|
Thanks for the review, @shefty. I reworked the series to make librdmacm CoCo-aware as you suggested:
Re-tested on both CoCo ( |
Enable
librdmacmandrsocket(SOCK_STREAMandSOCK_DGRAM) to operate in Confidential Computing (CoCo) guests using theibv_alloc_buf(),ibv_reg_buf_mr(), and parent domain APIs from #1748:IBV_DEVICE_CC_DMA_BOUNCEand a single lazily allocatedcoco_pdonstruct cma_devicealongsidecma_dev->pd, and expose private opt-in helpersucma_set_coco_pd()anducma_create_cq().cm_id->pdalive until buffers are freed, fixqp->dest.ahleak anderrnopreservation, orderrs_create_cq()beforeds_init_bufs(), and guardrs_create_cq()againstNULLcm_id->verbs/cm_id->pd.qp->sbufperds_qpso registration PD matches allocation PD, and movesmsg_freeinto a private index stack synchronized underrs->cq_lock.ibv_alloc_buf()/ibv_reg_buf_mr()/ibv_free_buf(), keeping page-size rounding forMADV_DONTFORK.cm_ids intolibrdmacm's sharedcoco_pdviaucma_set_coco_pd()anducma_create_cq().cc: @shefty @jpirko @jakemoroni @10000TB