diff --git a/prov/efa/src/rdm/efa_rdm_ep.h b/prov/efa/src/rdm/efa_rdm_ep.h index eba552d39ad..83e0a7c399a 100644 --- a/prov/efa/src/rdm/efa_rdm_ep.h +++ b/prov/efa/src/rdm/efa_rdm_ep.h @@ -56,7 +56,10 @@ struct efa_rdm_ep { struct fid_ep *shm_ep; size_t mtu_size; - size_t inject_size; + size_t max_msg_size; /**< #FI_OPT_MAX_MSG_SIZE */ + size_t max_rma_size; /**< #FI_OPT_MAX_RMA_SIZE */ + size_t inject_msg_size; /**< #FI_OPT_INJECT_MSG_SIZE */ + size_t inject_rma_size; /**< #FI_OPT_INJECT_RMA_SIZE */ /* Endpoint's capability to support zero-copy rx */ bool use_zcpy_rx; @@ -73,11 +76,6 @@ struct efa_rdm_ep { /* Resource management flag */ uint64_t rm_full; - /* Application's maximum msg size hint */ - size_t max_msg_size; - - /** Application's maximum RMA size */ - size_t max_rma_size; /* Applicaiton's message prefix size. */ size_t msg_prefix_size; diff --git a/prov/efa/src/rdm/efa_rdm_ep_fiops.c b/prov/efa/src/rdm/efa_rdm_ep_fiops.c index abc4f89c720..d59db2fb7dc 100644 --- a/prov/efa/src/rdm/efa_rdm_ep_fiops.c +++ b/prov/efa/src/rdm/efa_rdm_ep_fiops.c @@ -557,13 +557,14 @@ int efa_rdm_ep_open(struct fid_domain *domain, struct fi_info *info, EFA_INFO(FI_LOG_EP_CTRL, "efa_rdm_ep->host_id: i-%017lx\n", efa_rdm_ep->host_id); } - efa_rdm_ep->inject_size = info->tx_attr->inject_size; + efa_rdm_ep->max_msg_size = info->ep_attr->max_msg_size; + efa_rdm_ep->max_rma_size = info->ep_attr->max_msg_size; + efa_rdm_ep->inject_msg_size = info->tx_attr->inject_size; + efa_rdm_ep->inject_rma_size = info->tx_attr->inject_size; efa_rdm_ep->efa_max_outstanding_tx_ops = efa_domain->device->rdm_info->tx_attr->size; efa_rdm_ep->efa_max_outstanding_rx_ops = efa_domain->device->rdm_info->rx_attr->size; efa_rdm_ep->use_device_rdma = efa_rdm_get_use_device_rdma(info->fabric_attr->api_version); efa_rdm_ep->shm_permitted = true; - efa_rdm_ep->max_msg_size = info->ep_attr->max_msg_size; - efa_rdm_ep->max_rma_size = info->ep_attr->max_msg_size; efa_rdm_ep->msg_prefix_size = info->ep_attr->msg_prefix_size; efa_rdm_ep->mtu_size = efa_domain->device->rdm_info->ep_attr->max_msg_size; @@ -1251,7 +1252,7 @@ static int efa_rdm_ep_ctrl(struct fid *fid, int command, void *arg) * when supported */ if (ep->use_zcpy_rx) - ep->inject_size = MIN(ep->inject_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size); + ep->inject_rma_size = MIN(ep->inject_rma_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size); ret = efa_rdm_ep_create_base_ep_ibv_qp(ep); if (ret) @@ -1440,110 +1441,6 @@ static int efa_rdm_ep_set_shared_memory_permitted(struct efa_rdm_ep *ep, bool sh return 0; } -/** - * @brief Conditionally set efa_rdm_ep#max_msg_size per user's request - * - * If the requested msg size exceeds the EFA provider's default value, the - * request is rejected. - * - * @param[in,out] ep EFA RDM endpoint - * @param[in] max_msg_size Requested maximum msg size - * - * @return 0 on success, -FI_EINVAL otherwise - * - * @sa #FI_OPT_MAX_MSG_SIZE - */ -static int efa_rdm_ep_set_max_msg_size(struct efa_rdm_ep *ep, size_t max_msg_size) -{ - if (max_msg_size > ep->base_ep.info->ep_attr->max_msg_size) { - EFA_WARN(FI_LOG_EP_CTRL, - "Requested size of %zu for FI_OPT_MAX_MSG_SIZE " - "exceeds the maximum (%zu)\n", - max_msg_size, ep->base_ep.info->ep_attr->max_msg_size); - return -FI_EINVAL; - } - ep->max_msg_size = max_msg_size; - return 0; -} - -/** - * @brief Conditionally set efa_rdm_ep#max_rma_size per user's request - * - * If the requested inject size exceeds the EFA provider's default value, the - * request is rejected. - * - * @param[in,out] ep EFA RDM endpoint - * @param[in] max_rma_size Requested max RMA size - * - * @return 0 on success, -FI_EINVAL otherwise - * - * @sa #FI_OPT_MAX_RMA_SIZE - */ -static int efa_rdm_ep_set_max_rma_size(struct efa_rdm_ep *ep, size_t max_rma_size) -{ - if (max_rma_size > ep->base_ep.info->ep_attr->max_msg_size) { - EFA_WARN(FI_LOG_EP_CTRL, - "Requested size of %zu for FI_OPT_MAX_RMA_SIZE " - "exceeds the maximum (%zu)\n", - max_rma_size, ep->base_ep.info->ep_attr->max_msg_size); - return -FI_EINVAL; - } - ep->max_rma_size = max_rma_size; - return 0; -} - -/** - * @brief Conditionally set efa_rdm_ep#inject_size per user's request - * - * If the requested inject size exceeds the EFA provider's default value, the - * request is rejected. - * - * @param[in,out] ep EFA RDM endpoint - * @param[in] inject_size Requested inject size - * - * @return 0 on success, -FI_EINVAL otherwise - * - * @sa #FI_OPT_INJECT_MSG_SIZE - */ -static int efa_rdm_ep_set_inject_msg_size(struct efa_rdm_ep *ep, size_t inject_msg_size) -{ - if (inject_msg_size > ep->base_ep.info->tx_attr->inject_size) { - EFA_WARN(FI_LOG_EP_CTRL, - "Requested size of %zu for FI_OPT_INJECT_MSG_SIZE " - "exceeds the maximum (%zu)\n", - inject_msg_size, ep->base_ep.info->tx_attr->inject_size); - return -FI_EINVAL; - } - ep->inject_size = inject_msg_size; - return 0; -} - -/** - * @brief Conditionally set efa_rdm_ep#inject_size per user's request - * - * If the requested inject size exceeds the EFA provider's default value, the - * request is rejected. - * - * @param[in,out] ep EFA RDM endpoint - * @param[in] inject_size Requested inject size - * - * @return 0 on success, -FI_EINVAL otherwise - * - * @sa #FI_OPT_INJECT_RMA_SIZE - */ -static int efa_rdm_ep_set_inject_rma_size(struct efa_rdm_ep *ep, size_t inject_rma_size) -{ - if (inject_rma_size > ep->base_ep.info->tx_attr->inject_size) { - EFA_WARN(FI_LOG_EP_CTRL, - "Requested size of %zu for FI_OPT_INJECT_RMA_SIZE " - "exceeds the maximum (%zu)\n", - inject_rma_size, ep->base_ep.info->tx_attr->inject_size); - return -FI_EINVAL; - } - ep->inject_size = inject_rma_size; - return 0; -} - /** * @brief set use_device_rdma flag in efa_rdm_ep. * @@ -1662,6 +1559,23 @@ int efa_rdm_ep_check_qp_in_order_aligned_128_bytes(struct efa_rdm_ep *ep, return ret; } +/** + * Convenience macro for setopt with an enforced threshold + */ +#define EFA_RDM_EP_SETOPT_THRESHOLD(opt, field, threshold) { \ + size_t _val = *(size_t *) optval; \ + if (optlen != sizeof field) \ + return -FI_EINVAL; \ + if (_val > threshold) { \ + EFA_WARN(FI_LOG_EP_CTRL, \ + "Requested size of %zu for FI_OPT_" #opt " " \ + "exceeds the maximum (%zu)\n", \ + _val, threshold); \ + return -FI_EINVAL; \ + } \ + field = _val; \ +} + /** * @brief implement the fi_setopt() API for EFA RDM endpoint * @param[in] fid fid to endpoint @@ -1745,32 +1659,16 @@ static int efa_rdm_ep_setopt(fid_t fid, int level, int optname, return ret; break; case FI_OPT_MAX_MSG_SIZE: - if (optlen != sizeof (size_t)) - return -FI_EINVAL; - ret = efa_rdm_ep_set_max_msg_size(efa_rdm_ep, *(size_t *) optval); - if (ret) - return ret; + EFA_RDM_EP_SETOPT_THRESHOLD(MAX_MSG_SIZE, efa_rdm_ep->max_msg_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size) break; case FI_OPT_MAX_RMA_SIZE: - if (optlen != sizeof (size_t)) - return -FI_EINVAL; - ret = efa_rdm_ep_set_max_rma_size(efa_rdm_ep, *(size_t *) optval); - if (ret) - return ret; + EFA_RDM_EP_SETOPT_THRESHOLD(MAX_RMA_SIZE, efa_rdm_ep->max_rma_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size) break; case FI_OPT_INJECT_MSG_SIZE: - if (optlen != sizeof (size_t)) - return -FI_EINVAL; - ret = efa_rdm_ep_set_inject_msg_size(efa_rdm_ep, *(size_t *) optval); - if (ret) - return ret; + EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_MSG_SIZE, efa_rdm_ep->inject_msg_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size) break; case FI_OPT_INJECT_RMA_SIZE: - if (optlen != sizeof (size_t)) - return -FI_EINVAL; - ret = efa_rdm_ep_set_inject_rma_size(efa_rdm_ep, *(size_t *) optval); - if (ret) - return ret; + EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_RMA_SIZE, efa_rdm_ep->inject_rma_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size) break; case FI_OPT_EFA_USE_DEVICE_RDMA: if (optlen != sizeof(bool)) @@ -1863,13 +1761,13 @@ static int efa_rdm_ep_getopt(fid_t fid, int level, int optname, void *optval, case FI_OPT_INJECT_MSG_SIZE: if (*optlen < sizeof (size_t)) return -FI_ETOOSMALL; - *(size_t *) optval = efa_rdm_ep->inject_size; + *(size_t *) optval = efa_rdm_ep->inject_msg_size; *optlen = sizeof (size_t); break; case FI_OPT_INJECT_RMA_SIZE: if (*optlen < sizeof (size_t)) return -FI_ETOOSMALL; - *(size_t *) optval = efa_rdm_ep->inject_size; + *(size_t *) optval = efa_rdm_ep->inject_rma_size; *optlen = sizeof (size_t); break; case FI_OPT_EFA_EMULATED_READ: diff --git a/prov/efa/src/rdm/efa_rdm_msg.c b/prov/efa/src/rdm/efa_rdm_msg.c index 8185e411b4f..4b5a7439fdf 100644 --- a/prov/efa/src/rdm/efa_rdm_msg.c +++ b/prov/efa/src/rdm/efa_rdm_msg.c @@ -356,7 +356,7 @@ ssize_t efa_rdm_msg_inject(struct fid_ep *ep, const void *buf, size_t len, struct efa_rdm_peer *peer; efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); + assert(len <= efa_rdm_ep->inject_msg_size); peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr); assert(peer); @@ -384,7 +384,7 @@ ssize_t efa_rdm_msg_injectdata(struct fid_ep *ep, const void *buf, struct efa_rdm_peer *peer; efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); + assert(len <= efa_rdm_ep->inject_msg_size); peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr); assert(peer); @@ -559,7 +559,6 @@ ssize_t efa_rdm_msg_tinject(struct fid_ep *ep_fid, const void *buf, size_t len, struct efa_rdm_peer *peer; efa_rdm_ep = container_of(ep_fid, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr); assert(peer); @@ -586,7 +585,6 @@ ssize_t efa_rdm_msg_tinjectdata(struct fid_ep *ep_fid, const void *buf, size_t l struct efa_rdm_peer *peer; efa_rdm_ep = container_of(ep_fid, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr); assert(peer); diff --git a/prov/efa/src/rdm/efa_rdm_ope.c b/prov/efa/src/rdm/efa_rdm_ope.c index c232047d4c4..2f1d82821f4 100644 --- a/prov/efa/src/rdm/efa_rdm_ope.c +++ b/prov/efa/src/rdm/efa_rdm_ope.c @@ -1503,7 +1503,7 @@ int efa_rdm_ope_post_remote_write(struct efa_rdm_ope *ope) if (ope->fi_flags & FI_INJECT) { assert(ope->iov_count == 1); - assert(ope->total_len <= ep->inject_size); + assert(ope->total_len <= ep->inject_rma_size); copied = efa_rdm_pke_copy_from_hmem_iov( ope->desc[iov_idx], pkt_entry, ope, sizeof(struct efa_rdm_rma_context_pkt), 0, diff --git a/prov/efa/src/rdm/efa_rdm_rma.c b/prov/efa/src/rdm/efa_rdm_rma.c index 6a6562b2849..ae04af66e1e 100644 --- a/prov/efa/src/rdm/efa_rdm_rma.c +++ b/prov/efa/src/rdm/efa_rdm_rma.c @@ -642,7 +642,7 @@ ssize_t efa_rdm_rma_inject_write(struct fid_ep *ep, const void *buf, size_t len, int err; efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); + assert(len <= efa_rdm_ep->inject_rma_size); err = efa_rdm_ep_cap_check_rma(efa_rdm_ep); if (err) return err; @@ -679,7 +679,7 @@ ssize_t efa_rdm_rma_inject_writedata(struct fid_ep *ep, const void *buf, size_t int err; efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid); - assert(len <= efa_rdm_ep->inject_size); + assert(len <= efa_rdm_ep->inject_rma_size); err = efa_rdm_ep_cap_check_rma(efa_rdm_ep); if (err) return err; diff --git a/prov/efa/test/efa_unit_test_ep.c b/prov/efa/test/efa_unit_test_ep.c index b33e98b241d..673e82703c3 100644 --- a/prov/efa/test/efa_unit_test_ep.c +++ b/prov/efa/test/efa_unit_test_ep.c @@ -924,7 +924,7 @@ static void test_efa_rdm_ep_use_zcpy_rx_impl(struct efa_resource *resource, struct efa_domain *efa_domain; struct efa_rdm_ep *ep; size_t max_msg_size = 1000; - size_t inject_size = 0; + size_t inject_rma_size = 0; bool shm_permitted = false; efa_unit_test_resource_construct_with_hints(resource, FI_EP_RDM, FI_VERSION(1, 14), @@ -967,12 +967,12 @@ static void test_efa_rdm_ep_use_zcpy_rx_impl(struct efa_resource *resource, assert_true(ep->use_zcpy_rx == expected_use_zcpy_rx); assert_int_equal(fi_getopt(&resource->ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_RMA_SIZE, - &inject_size, &(size_t){sizeof inject_size}), 0); - assert_int_equal(ep->inject_size, inject_size); + &inject_rma_size, &(size_t){sizeof inject_rma_size}), 0); + assert_int_equal(ep->inject_rma_size, inject_rma_size); if (expected_use_zcpy_rx) - assert_int_equal(inject_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size); + assert_int_equal(inject_rma_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size); else - assert_int_equal(inject_size, resource->info->tx_attr->inject_size); + assert_int_equal(inject_rma_size, resource->info->tx_attr->inject_size); } /**