Skip to content

Commit

Permalink
prov/verbs: Bug fix for matching domain name with device name
Browse files Browse the repository at this point in the history
The domain name may contain a "-<xxx>" suffix, the original code used
"strncmp(domain_name, dev_name, strlen(dev_name))" to check if the names
match. However, this scheme does not work when the device name is a
substring of the domain name (e.g. "mlx5_11-rdm" vs "mlx5_1") and would
incorrectly return match for such case.

Signed-off-by: jianxin.xiong <jianxin.xiong@intel.com>
  • Loading branch information
jianxin.xiong authored and j-xiong committed Oct 10, 2023
1 parent 00266f8 commit 4843d1a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions prov/verbs/src/verbs_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,24 @@ vrb_info_add_dev_addr(struct fi_info **info, struct verbs_dev_info *dev)
return 0;
}

/* domain name may have a "-<xxx>" suffix */
static inline int vrb_cmp_domain_and_dev_name(const char *domain_name,
const char *dev_name)
{
size_t cmp_len;
char *s = strrchr(domain_name, '-');

if (s)
cmp_len = s - domain_name;
else
cmp_len = strlen(domain_name);

if (cmp_len != strlen(dev_name))
return -1;

return strncmp(domain_name, dev_name, cmp_len);
}

static int vrb_get_srcaddr_devs(struct fi_info **info)
{
struct verbs_dev_info *dev;
Expand All @@ -1231,10 +1249,8 @@ static int vrb_get_srcaddr_devs(struct fi_info **info)
continue;
dlist_foreach_container(&verbs_devs, struct verbs_dev_info,
dev, entry) {
/* strncmp because we want to process XRC fi_info as
* well which have a "-xrc" suffix in domain name */
if (!strncmp(fi->domain_attr->name, dev->name,
strlen(dev->name))) {
if (!vrb_cmp_domain_and_dev_name(fi->domain_attr->name,
dev->name)) {
ret = vrb_info_add_dev_addr(&fi, dev);
if (ret)
return ret;
Expand Down Expand Up @@ -1607,10 +1623,10 @@ static int vrb_del_info_not_belong_to_dev(const char *dev_name, struct fi_info *
*info = NULL;

while (check_info) {
/* Use strncmp since verbs domain names would have "-<ep_type>" suffix */
if (dev_name && strncmp(dev_name, check_info->domain_attr->name,
strlen(dev_name))) {
/* This branch removing `check_info` entry from the list */
if (dev_name &&
vrb_cmp_domain_and_dev_name(check_info->domain_attr->name,
dev_name)) {
/* remove unmatched `check_info` entry from the list */
cur = check_info;
if (prev)
prev->next = check_info->next;
Expand Down

0 comments on commit 4843d1a

Please sign in to comment.