Skip to main content

monarch_rdma/backend/ibverbs/
efa_domain.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! EFA domain strategy for [`IbvDomainImpl`].
10
11use super::domain::IbvDomainImpl;
12use super::efa_queue_pair::EfaQueuePair;
13use super::primitives::IbvConfig;
14use super::primitives::IbvContext;
15use super::primitives::IbvDeviceInfo;
16
17/// EFA [`IbvDomainImpl`]. Uses the default host/dmabuf MR registration;
18/// EFA has no device-specific memory-key binding to add.
19#[derive(Debug)]
20pub struct EfaDomain;
21
22impl IbvDomainImpl for EfaDomain {
23    type QueuePair = EfaQueuePair;
24
25    unsafe fn new(
26        _context: &IbvContext,
27        _device_info: &IbvDeviceInfo,
28        _config: &IbvConfig,
29    ) -> Self {
30        EfaDomain
31    }
32
33    fn access_flags(&self) -> i32 {
34        // EFA does not support `IBV_ACCESS_REMOTE_ATOMIC`.
35        (rdmaxcel_sys::ibv_access_flags::IBV_ACCESS_LOCAL_WRITE
36            | rdmaxcel_sys::ibv_access_flags::IBV_ACCESS_REMOTE_WRITE
37            | rdmaxcel_sys::ibv_access_flags::IBV_ACCESS_REMOTE_READ)
38            .0 as i32
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use std::sync::Arc;
45
46    use super::*;
47    use crate::backend::ibverbs::domain::IbvDomain;
48    use crate::backend::ibverbs::primitives::IbvCq;
49    use crate::backend::ibverbs::primitives::IbvPd;
50
51    // A domain with no protection domain cannot build a queue pair, and says so
52    // rather than reaching the driver with a null handle.
53    #[test]
54    fn create_queue_pair_rejects_null_pd() {
55        // SAFETY: `IbvPd::null()` holds a null PD (and, through it, a null
56        // context) whose `Drop`s are no-ops.
57        let domain = unsafe {
58            IbvDomain::for_test(
59                Arc::new(IbvPd::null()),
60                IbvDeviceInfo::for_test_named("efa0"),
61                EfaDomain,
62            )
63        };
64        let err = domain
65            .create_queue_pair(&IbvConfig::default(), Arc::new(IbvCq::null()))
66            .expect_err("a null protection domain cannot back a queue pair");
67        assert!(
68            err.to_string().contains("null protection domain"),
69            "unexpected error: {err}"
70        );
71    }
72}