Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Apr 2026 22:42:38 +0000
From:      Vladimir Druzenko <vvd@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Cc:        Generic Rikka <rikka.goering@outlook.de>
Subject:   git: 601e614318cd - main - net/ucx: Fix FreeBSD runtime portability issues
Message-ID:  <69d6d9de.22c35.655bacbd@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by vvd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=601e614318cdfbb381bcb7a9841353720feb53a9

commit 601e614318cdfbb381bcb7a9841353720feb53a9
Author:     Generic Rikka <rikka.goering@outlook.de>
AuthorDate: 2026-04-08 22:07:05 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2026-04-08 22:42:18 +0000

    net/ucx: Fix FreeBSD runtime portability issues
    
    Adjust several Linux-specific runtime assumptions in UCX for FreeBSD:
    - use FreeBSD-specific network interface handling where Linux sysfs logic
      is not available
    - avoid Linux-only IPOIB and bridge detection paths
    - improve pthread_create() error reporting
    - provide FreeBSD fallbacks for memory remapping and affinity helpers
    
    This fixes multiple runtime failures and device discovery issues on FreeBSD.
    
    PR:             293867
    Sponsored by:   UNIS Labs
    MFH:            2026Q2
---
 net/ucx/files/patch-src_ucs_sys_sys.c        |  39 +++---
 net/ucx/files/patch-src_uct_tcp_tcp__iface.c | 173 +++++++++++++++++++++++++++
 2 files changed, 198 insertions(+), 14 deletions(-)

diff --git a/net/ucx/files/patch-src_ucs_sys_sys.c b/net/ucx/files/patch-src_ucs_sys_sys.c
index 1f70cc8b329f..39d00cd926db 100644
--- a/net/ucx/files/patch-src_ucs_sys_sys.c
+++ b/net/ucx/files/patch-src_ucs_sys_sys.c
@@ -1,6 +1,6 @@
 --- src/ucs/sys/sys.c.orig	2026-02-05 12:41:56 UTC
 +++ src/ucs/sys/sys.c
-@@ -23,16 +23,26 @@
+@@ -23,16 +23,27 @@
  #include <ucm/util/sys.h>
  
  #include <unistd.h>
@@ -13,6 +13,7 @@
  #include <sys/resource.h>
 +#include <netinet/in.h>
  #include <net/if.h>
++#include <pthread.h>
  #include <dirent.h>
  #include <sched.h>
  #include <ctype.h>
@@ -27,7 +28,7 @@
  #ifdef HAVE_SYS_THR_H
  #include <sys/thr.h>
  #endif
-@@ -94,7 +104,7 @@ const char *ucs_get_host_name()
+@@ -94,7 +105,7 @@ const char *ucs_get_host_name()
  
  const char *ucs_get_host_name()
  {
@@ -36,7 +37,7 @@
  
      if (*hostname == 0) {
          gethostname(hostname, sizeof(hostname));
-@@ -180,6 +190,41 @@ int ucs_netif_is_ipoib(const char *if_name)
+@@ -180,6 +191,41 @@ int ucs_netif_is_ipoib(const char *if_name)
  
  int ucs_netif_is_ipoib(const char *if_name)
  {
@@ -78,7 +79,7 @@
      struct ifreq ifr;
      ucs_status_t status;
  
-@@ -191,11 +236,56 @@ int ucs_netif_is_ipoib(const char *if_name)
+@@ -191,11 +237,56 @@ int ucs_netif_is_ipoib(const char *if_name)
      }
  
      return ifr.ifr_hwaddr.sa_family == ARPHRD_INFINIBAND;
@@ -135,7 +136,7 @@
      struct ifreq ifr, *it, *end;
      struct ifconf ifc;
      char buf[1024];
-@@ -243,6 +333,7 @@ static uint64_t ucs_get_mac_address()
+@@ -243,6 +334,7 @@ static uint64_t ucs_get_mac_address()
      }
  
      return mac_address;
@@ -143,7 +144,7 @@
  }
  
  static uint64_t __sumup_host_name(unsigned prime_index)
-@@ -766,6 +857,10 @@ static void ucs_sysv_shmget_error_check_ENOSPC(size_t 
+@@ -766,6 +858,10 @@ static void ucs_sysv_shmget_error_check_ENOSPC(size_t 
                                                 const struct shminfo *ipc_info,
                                                 char *buf, size_t max)
  {
@@ -154,7 +155,7 @@
      unsigned long new_used_ids;
      unsigned long new_shm_tot;
      struct shm_info shm_info;
-@@ -797,6 +892,7 @@ static void ucs_sysv_shmget_error_check_ENOSPC(size_t 
+@@ -797,6 +893,7 @@ static void ucs_sysv_shmget_error_check_ENOSPC(size_t 
                   " limit in /proc/sys/kernel/shmall (=%lu)",
                   new_shm_tot, ipc_info->shmall);
      }
@@ -162,7 +163,7 @@
  }
  
  ucs_status_t ucs_sys_get_proc_cap(uint32_t *effective)
-@@ -857,6 +953,14 @@ static void ucs_sysv_shmget_format_error(size_t alloc_
+@@ -857,6 +954,14 @@ static void ucs_sysv_shmget_format_error(size_t alloc_
                                           const char *alloc_name, int sys_errno,
                                           char *buf, size_t max)
  {
@@ -177,7 +178,7 @@
      struct shminfo ipc_info;
      char *p, *endp, *errp;
      int ret;
-@@ -894,6 +998,7 @@ static void ucs_sysv_shmget_format_error(size_t alloc_
+@@ -894,6 +999,7 @@ static void ucs_sysv_shmget_format_error(size_t alloc_
      if (p == errp) {
          snprintf(p, endp - p, ", please check shared memory limits by 'ipcs -l'");
      }
@@ -185,7 +186,7 @@
  }
  
  ucs_status_t ucs_sysv_alloc(size_t *size, size_t max_size, void **address_p,
-@@ -1287,11 +1392,44 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
+@@ -1287,11 +1393,44 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
  {
      void *ptr;
  
@@ -231,7 +232,7 @@
                               MAP_PRIVATE|MAP_ANONYMOUS, -1, 0ul);
          if (ptr == MAP_FAILED) {
              ucs_log_fatal_error("mmap(NULL, %zu, READ|WRITE, PRIVATE|ANON) failed: %m",
-@@ -1300,7 +1438,7 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
+@@ -1300,7 +1439,7 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
          }
      } else {
          old_length = ucs_align_up_pow2(old_length, ucs_get_page_size());
@@ -240,7 +241,7 @@
                               MREMAP_MAYMOVE);
          if (ptr == MAP_FAILED) {
              ucs_log_fatal_error("mremap(%p, %zu, %zu, MAYMOVE) failed: %m",
-@@ -1310,6 +1448,13 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
+@@ -1310,6 +1449,13 @@ void *ucs_sys_realloc(void *old_ptr, size_t old_length
      }
  
      return ptr;
@@ -254,7 +255,7 @@
  }
  
  void ucs_sys_free(void *ptr, size_t length)
-@@ -1317,11 +1462,19 @@ void ucs_sys_free(void *ptr, size_t length)
+@@ -1317,11 +1463,19 @@ void ucs_sys_free(void *ptr, size_t length)
      int ret;
  
      if (ptr != NULL) {
@@ -275,7 +276,7 @@
      }
  }
  
-@@ -1391,12 +1544,32 @@ ucs_status_t ucs_sys_pthread_getaffinity(ucs_sys_cpuse
+@@ -1391,12 +1545,32 @@ ucs_status_t ucs_sys_pthread_getaffinity(ucs_sys_cpuse
  
  ucs_status_t ucs_sys_pthread_getaffinity(ucs_sys_cpuset_t *cpuset)
  {
@@ -308,3 +309,13 @@
  }
  
  void ucs_sys_cpuset_copy(ucs_cpu_set_t *dst, const ucs_sys_cpuset_t *src)
+@@ -1557,7 +1731,8 @@ ucs_status_t ucs_pthread_create(pthread_t *thread_id_p
+ 
+     ret = pthread_create(&thread_id, NULL, start_routine, arg);
+     if (ret != 0) {
+-        ucs_error("pthread_create() failed: %m");
++        ucs_error("pthread_create(start_routine=%p arg=%p) failed: %s (%d)",
++                  start_routine, arg, strerror(ret), ret);
+         return UCS_ERR_IO_ERROR;
+     }
+ 
diff --git a/net/ucx/files/patch-src_uct_tcp_tcp__iface.c b/net/ucx/files/patch-src_uct_tcp_tcp__iface.c
new file mode 100644
index 000000000000..6049d4462248
--- /dev/null
+++ b/net/ucx/files/patch-src_uct_tcp_tcp__iface.c
@@ -0,0 +1,173 @@
+--- src/uct/tcp/tcp_iface.c.orig	2026-03-14 01:11:54 UTC
++++ src/uct/tcp/tcp_iface.c
+@@ -20,6 +20,10 @@
+ #include <netinet/tcp.h>
+ #include <dirent.h>
+ #include <float.h>
++#if defined(__FreeBSD__)
++#include <net/if.h>
++#include <net/if_types.h>
++#endif
+ 
+ #define UCT_TCP_IFACE_NETDEV_DIR "/sys/class/net"
+ 
+@@ -289,6 +293,11 @@ uct_tcp_iface_get_sysfs_path(const char *dev_name, cha
+ static const char *
+ uct_tcp_iface_get_sysfs_path(const char *dev_name, char *path_buffer)
+ {
++#if defined(__FreeBSD__)
++    (void)dev_name;
++    (void)path_buffer;
++    return NULL;
++#else
+     const char *sysfs_path = NULL;
+     ucs_status_t status;
+     char *lowest_path_buf;
+@@ -315,6 +324,7 @@ out:
+     ucs_free(lowest_path_buf);
+ out:
+     return sysfs_path;
++#endif
+ }
+ 
+ static ucs_status_t uct_tcp_iface_query(uct_iface_h tl_iface,
+@@ -948,6 +958,10 @@ static int uct_tcp_is_bridge(const char *if_name)
+ 
+ static int uct_tcp_is_bridge(const char *if_name)
+ {
++#if defined(__FreeBSD__)
++    (void)if_name;
++    return 0;
++#else
+     char *path;
+     int ret;
+     struct stat st;
+@@ -967,6 +981,7 @@ out:
+     ucs_free(path);
+ out:
+     return ret;
++#endif
+ }
+ 
+ ucs_status_t uct_tcp_query_devices(uct_md_h md,
+@@ -976,7 +991,11 @@ ucs_status_t uct_tcp_query_devices(uct_md_h md,
+     uct_tcp_md_t *tcp_md               = ucs_derived_of(md, uct_tcp_md_t);
+     const unsigned sys_device_priority = 10;
+     uct_tl_device_resource_t *devices, *tmp;
+-    struct dirent **entries, **entry;
++#if defined(__FreeBSD__)
++    struct if_nameindex *ifn, *it;
++#else
++     struct dirent **entries, **entry;
++#endif
+     unsigned num_devices;
+     int is_active, i, n;
+     ucs_status_t status;
+@@ -984,21 +1003,77 @@ ucs_status_t uct_tcp_query_devices(uct_md_h md,
+     char *path_buffer;
+     ucs_sys_device_t sys_dev;
+ 
++#if defined(__FreeBSD__)
++    ifn = if_nameindex();
++    if (ifn == NULL) {
++        ucs_error("if_nameindex() failed: %m");
++        status = UCS_ERR_IO_ERROR;
++        goto out;
++    }
++#else
+     n = scandir(UCT_TCP_IFACE_NETDEV_DIR, &entries, NULL, alphasort);
+     if (n == -1) {
+         ucs_error("scandir(%s) failed: %m", UCT_TCP_IFACE_NETDEV_DIR);
+         status = UCS_ERR_IO_ERROR;
+         goto out;
+     }
++#endif
+ 
+     devices     = NULL;
+     num_devices = 0;
+ 
++#if defined(__FreeBSD__)
++    path_buffer = NULL;
++    status      = UCS_OK;
++#else
+     status = ucs_string_alloc_path_buffer(&path_buffer, "path_buffer");
+     if (status != UCS_OK) {
+-        goto out;
++        goto out_release;
+     }
++#endif
+ 
++#if defined(__FreeBSD__)
++    for (it = ifn; it->if_name != NULL; ++it) {
++        is_active = 0;
++        for (i = 0; i < tcp_md->config.af_prio_count; i++) {
++            if (ucs_netif_is_active(it->if_name,
++                                    tcp_md->config.af_prio_list[i])) {
++                is_active = 1;
++                break;
++            }
++        }
++
++        if (!is_active) {
++            continue;
++        }
++
++        if (!tcp_md->config.bridge_enable &&
++            uct_tcp_is_bridge(it->if_name)) {
++            ucs_debug("filtered out bridge device %s", it->if_name);
++            continue;
++        }
++
++        tmp = ucs_realloc(devices, sizeof(*devices) * (num_devices + 1),
++                          "tcp devices");
++        if (tmp == NULL) {
++            ucs_free(devices);
++            status = UCS_ERR_NO_MEMORY;
++            goto out_release;
++        }
++        devices = tmp;
++
++        sysfs_path = uct_tcp_iface_get_sysfs_path(it->if_name, path_buffer);
++        sys_dev    = ucs_topo_get_sysfs_dev(it->if_name, sysfs_path,
++                                            sys_device_priority);
++
++        ucs_snprintf_zero(devices[num_devices].name,
++                          sizeof(devices[num_devices].name), "%s",
++                          it->if_name);
++        devices[num_devices].type       = UCT_DEVICE_TYPE_NET;
++        devices[num_devices].sys_device = sys_dev;
++        ++num_devices;
++    }
++#else
+     ucs_carray_for_each(entry, entries, n) {
+         /* According to the sysfs(5) manual page, all of entries
+          * has to be a symbolic link representing one of the real
+@@ -1050,18 +1125,28 @@ ucs_status_t uct_tcp_query_devices(uct_md_h md,
+         devices[num_devices].sys_device = sys_dev;
+         ++num_devices;
+     }
++#endif
+ 
+     *num_devices_p = num_devices;
+     *devices_p     = devices;
+     status         = UCS_OK;
+ 
+ out_release:
++#if defined(__FreeBSD__)
++    if (ifn != NULL) {
++        if_freenameindex(ifn);
++    }
++    if (path_buffer != NULL) {
++        ucs_free(path_buffer);
++    }
++#else
+     ucs_carray_for_each(entry, entries, n) {
+         free(*entry);
+     }
+ 
+     free(entries);
+     ucs_free(path_buffer);
++#endif
+ out:
+     return status;
+ }


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69d6d9de.22c35.655bacbd>