summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJieqiang Wang <jieqiang.wang@arm.com>2020-01-13 17:15:13 +0800
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-08-13 10:39:40 +0000
commitc81ba3d6a611e08b8eb0e5097b01c01c4356b5ff (patch)
tree45b5a8403447e46085ac52fc86940f283abf6764 /src
parent7c8260196a8a54f8e66c65269fd8a00b86c7a854 (diff)
vlib: fix error when creating avf interface on SMP system
On SMP architecture, '/sys/bus/pci/devices/<devices id>/numa_node' file will return -1 as a valid value if it does not have any NUMA node information. Using -1 as a valid node id to access data structures will cause memory issue. Fix the error by setting the value of numa_node to 0 if '/sys/bus/pci/devices/ <devices id>/numa_node' returns -1 and it is a SMP system. Type: fix Change-Id: Ib60e79c3656fe5b17e08fd9011122683e8b08b6f Signed-off-by: Jieqiang Wang <jieqiang.wang@arm.com> (cherry picked from commit 76c6159d83c2dfe29f84dc4b05d399cdbbdf2878)
Diffstat (limited to 'src')
-rw-r--r--src/vlib/linux/pci.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index d8cbf7a4163..8af1cdab0d4 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -208,6 +208,7 @@ vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
u32 tmp;
int fd;
u8 *tmpstr;
+ clib_bitmap_t *bmp = 0;
di = clib_mem_alloc (sizeof (vlib_pci_device_info_t));
clib_memset (di, 0, sizeof (vlib_pci_device_info_t));
@@ -260,12 +261,22 @@ vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
di->numa_node = -1;
vec_reset_length (f);
f = format (f, "%v/numa_node%c", dev_dir_name, 0);
- err = clib_sysfs_read ((char *) f, "%u", &di->numa_node);
+ err = clib_sysfs_read ((char *) f, "%d", &di->numa_node);
if (err)
{
di->numa_node = -1;
clib_error_free (err);
}
+ if (di->numa_node == -1)
+ {
+ /* if '/sys/bus/pci/devices/<device id>/numa_node' returns -1 and
+ it is a SMP system, set numa_node to 0. */
+ if ((err = clib_sysfs_read ("/sys/devices/system/node/online", "%U",
+ unformat_bitmap_list, &bmp)))
+ clib_error_free (err);
+ if (clib_bitmap_count_set_bits (bmp) == 1)
+ di->numa_node = 0;
+ }
vec_reset_length (f);
f = format (f, "%v/class%c", dev_dir_name, 0);
@@ -362,6 +373,7 @@ error:
di = 0;
done:
+ vec_free (bmp);
vec_free (f);
vec_free (dev_dir_name);
if (error)