diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ee7832 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/irqbalance-1.4.0.tar.gz diff --git a/.irqbalance.metadata b/.irqbalance.metadata new file mode 100644 index 0000000..678d9c9 --- /dev/null +++ b/.irqbalance.metadata @@ -0,0 +1 @@ +4eb861313d6b93b3be5d5933a7f45ee7b51c7ddb SOURCES/irqbalance-1.4.0.tar.gz diff --git a/SOURCES/irqbalance-1.0.4-env-file-path.patch b/SOURCES/irqbalance-1.0.4-env-file-path.patch new file mode 100644 index 0000000..450d755 --- /dev/null +++ b/SOURCES/irqbalance-1.0.4-env-file-path.patch @@ -0,0 +1,12 @@ +diff -up ./misc/irqbalance.service.path ./misc/irqbalance.service +--- ./misc/irqbalance.service.path 2017-11-14 13:09:56.011146473 -0500 ++++ ./misc/irqbalance.service 2017-11-14 13:10:13.480075654 -0500 +@@ -4,7 +4,7 @@ After=syslog.target + ConditionVirtualization=!container + + [Service] +-EnvironmentFile=/path/to/irqbalance.env ++EnvironmentFile=/etc/sysconfig/irqbalance + ExecStart=/usr/sbin/irqbalance --foreground $IRQBALANCE_ARGS + + [Install] diff --git a/SOURCES/irqbalance-1.4.0-Fix-an-possible-overflow-error.patch b/SOURCES/irqbalance-1.4.0-Fix-an-possible-overflow-error.patch new file mode 100644 index 0000000..26816e6 --- /dev/null +++ b/SOURCES/irqbalance-1.4.0-Fix-an-possible-overflow-error.patch @@ -0,0 +1,34 @@ +From 16cb6df56960f58df61ec35ef3be45286eb3c788 Mon Sep 17 00:00:00 2001 +From: Kairui Song +Date: Sun, 2 Sep 2018 23:40:45 +0800 +Subject: [PATCH 2/4] Fix an possible overflow error + +Got: +"specified bound 2048 exceeds the size 19 of the destination" +when -O2 is used, and a "*** buffer overflow detected ***" error output +with no backtrace. + +With -O0, it's gone, guess it's some gcc optimization problem, and the +size there is wrong anyway, this patch could fix it. +--- + irqbalance.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/irqbalance.c b/irqbalance.c +index 4b3de54..c89c3c0 100644 +--- a/irqbalance.c ++++ b/irqbalance.c +@@ -457,8 +457,8 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + } + if (!strncmp(buff, "setup", strlen("setup"))) { + char banned[512]; +- char *setup = calloc(strlen("SLEEP ") + 11 +1, 1); +- snprintf(setup, 2048, "SLEEP %d ", sleep_interval); ++ char *setup = calloc(strlen("SLEEP ") + 11 + 1, 1); ++ snprintf(setup, strlen("SLEEP ") + 11 + 1, "SLEEP %d ", sleep_interval); + if(g_list_length(cl_banned_irqs) > 0) { + for_each_irq(cl_banned_irqs, get_irq_data, setup); + } +-- +2.17.1 + diff --git a/SOURCES/irqbalance-1.4.0-Fix-several-memleak-problems-found-by-covscan.patch b/SOURCES/irqbalance-1.4.0-Fix-several-memleak-problems-found-by-covscan.patch new file mode 100644 index 0000000..bd0a844 --- /dev/null +++ b/SOURCES/irqbalance-1.4.0-Fix-several-memleak-problems-found-by-covscan.patch @@ -0,0 +1,253 @@ +From 9ed5c269bd59c95f41829aedf0520930c97b08d3 Mon Sep 17 00:00:00 2001 +From: Kairui Song +Date: Thu, 30 Aug 2018 17:45:53 +0800 +Subject: Fix several memleak problems found by covscan + +Some memleak issues is found by static analysis tools, and can confirm +irqbalance is leaking memory slowly when there are incomming connection +to socket. + +This patch could solve the memleak problem. +--- + irqbalance.c | 16 ++++++++++++---- + ui/irqbalance-ui.c | 31 +++++++++++++++++++++++++++---- + ui/ui.c | 2 ++ + 3 files changed, 41 insertions(+), 8 deletions(-) + +diff --git a/irqbalance.c b/irqbalance.c +index 6412447..4b3de54 100644 +--- a/irqbalance.c ++++ b/irqbalance.c +@@ -385,11 +385,11 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + sock = accept(fd, NULL, NULL); + if (sock < 0) { + log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n"); +- return TRUE; ++ goto out; + } + if ((recv_size = recvmsg(sock, &msg, 0)) < 0) { + log(TO_ALL, LOG_WARNING, "Error while receiving data.\n"); +- return TRUE; ++ goto out; + } + cmsg = CMSG_FIRSTHDR(&msg); + if ((cmsg->cmsg_level == SOL_SOCKET) && +@@ -401,7 +401,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + } + if (!valid_user) { + log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n"); +- return TRUE; ++ goto out; + } + + if (!strncmp(buff, "stats", strlen("stats"))) { +@@ -421,6 +421,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + if (new_iterval >= 1) { + sleep_interval = new_iterval; + } ++ free(sleep_string); + } else if (!(strncmp(buff + strlen("settings "), "ban irqs ", + strlen("ban irqs ")))) { + char *end; +@@ -432,12 +433,14 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + cl_banned_irqs = NULL; + need_rescan = 1; + if (!strncmp(irq_string, "NONE", strlen("NONE"))) { +- return TRUE; ++ free(irq_string); ++ goto out; + } + int irq = strtoul(irq_string, &end, 10); + do { + add_cl_banned_irq(irq); + } while((irq = strtoul(end, &end, 10))); ++ free(irq_string); + } else if (!(strncmp(buff + strlen("settings "), "cpus ", + strlen("cpus")))) { + char *cpu_ban_string = malloc( +@@ -449,6 +452,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + banned_cpumask_from_ui = NULL; + } + need_rescan = 1; ++ free(cpu_ban_string); + } + } + if (!strncmp(buff, "setup", strlen("setup"))) { +@@ -463,10 +467,14 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + snprintf(setup + strlen(setup), strlen(banned) + 7 + 1, + "BANNED %s", banned); + send(sock, setup, strlen(setup), 0); ++ free(setup); + } + + close(sock); + } ++ ++out: ++ free(msg.msg_control); + return TRUE; + } + +diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c +index 3fc46af..99f2ca2 100644 +--- a/ui/irqbalance-ui.c ++++ b/ui/irqbalance-ui.c +@@ -41,6 +41,7 @@ struct msghdr * create_credentials_msg() + cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred)); + memcpy(CMSG_DATA(cmsg), credentials, sizeof(struct ucred)); + ++ free(credentials); + return msg; + } + +@@ -87,6 +88,8 @@ void send_settings(char *data) + sendmsg(socket_fd, msg, 0); + + close(socket_fd); ++ free(msg->msg_control); ++ free(msg); + } + + char * get_data(char *string) +@@ -115,6 +118,8 @@ char * get_data(char *string) + int len = recv(socket_fd, data, 8192, 0); + close(socket_fd); + data[len] = '\0'; ++ free(msg->msg_control); ++ free(msg); + return data; + } + +@@ -123,6 +128,7 @@ void parse_setup(char *setup_data) + char *token, *ptr; + int i,j; + char *copy; ++ irq_t *new_irq = NULL; + if((setup_data == NULL) || (strlen(setup_data) == 0)) return; + copy = strdup(setup_data); + if (!copy) +@@ -136,7 +142,7 @@ void parse_setup(char *setup_data) + token = strtok_r(NULL, " ", &ptr); + /* Parse banned IRQ data */ + while(!strncmp(token, "IRQ", strlen("IRQ"))) { +- irq_t *new_irq = malloc(sizeof(irq_t)); ++ new_irq = malloc(sizeof(irq_t)); + new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10); + token = strtok_r(NULL, " ", &ptr); + if(strncmp(token, "LOAD", strlen("LOAD"))) goto out; +@@ -151,6 +157,7 @@ void parse_setup(char *setup_data) + new_irq->assigned_to = NULL; + setup.banned_irqs = g_list_append(setup.banned_irqs, new_irq); + token = strtok_r(NULL, " ", &ptr); ++ new_irq = NULL; + } + + if(strncmp(token, "BANNED", strlen("BANNED"))) goto out; +@@ -165,6 +172,7 @@ void parse_setup(char *setup_data) + banned_cpu); + } + } ++ free(map); + + } + free(copy); +@@ -173,6 +181,9 @@ void parse_setup(char *setup_data) + out: { + /* Invalid data presented */ + printf("Invalid data sent. Unexpected token: %s", token); ++ if (new_irq) { ++ free(new_irq); ++ } + free(copy); + g_list_free(tree); + exit(1); +@@ -240,7 +251,9 @@ void parse_into_tree(char *data) + cpu_node_t *parent = NULL; + char *copy; + tree = NULL; +- ++ irq_t *new_irq = NULL; ++ cpu_node_t *new = NULL; ++ + if (!data || strlen(data) == 0) + return; + +@@ -255,7 +268,7 @@ void parse_into_tree(char *data) + free(copy); + goto out; + } +- cpu_node_t *new = malloc(sizeof(cpu_node_t)); ++ new = malloc(sizeof(cpu_node_t)); + new->irqs = NULL; + new->children = NULL; + new->cpu_list = NULL; +@@ -279,7 +292,7 @@ void parse_into_tree(char *data) + + /* Parse assigned IRQ data */ + while((token != NULL) && (!strncmp(token, "IRQ", strlen("IRQ")))) { +- irq_t *new_irq = malloc(sizeof(irq_t)); ++ new_irq = malloc(sizeof(irq_t)); + new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10); + token = strtok_r(NULL, " ", &ptr); + if(strncmp(token, "LOAD", strlen("LOAD"))) goto out; +@@ -293,6 +306,7 @@ void parse_into_tree(char *data) + new_irq->is_banned = 0; + new->irqs = g_list_append(new->irqs, new_irq); + token = strtok_r(NULL, " ", &ptr); ++ new_irq = NULL; + } + + if((token == NULL) || (strncmp(token, "IRQ", strlen("IRQ")))) { +@@ -306,6 +320,8 @@ void parse_into_tree(char *data) + parent = new; + } + } ++ ++ new = NULL; + } + free(copy); + for_each_node(tree, assign_cpu_lists, NULL); +@@ -315,6 +331,12 @@ void parse_into_tree(char *data) + out: { + /* Invalid data presented */ + printf("Invalid data sent. Unexpected token: %s\n", token); ++ if (new_irq) { ++ free(new_irq); ++ } ++ if (new) { ++ free(new); ++ } + g_list_free(tree); + exit(1); + } +@@ -330,6 +352,7 @@ gboolean rescan_tree(gpointer data __attribute__((unused))) + display_tree(); + } + free(setup_data); ++ free(irqbalance_data); + return TRUE; + } + +diff --git a/ui/ui.c b/ui/ui.c +index 4054f0e..06ec472 100644 +--- a/ui/ui.c ++++ b/ui/ui.c +@@ -71,6 +71,7 @@ char * check_control_in_sleep_input(int max_len, int column_offest, int line_off + attrset(COLOR_PAIR(6)); + break; + case 27: ++ free(input_to); + return NULL; + default: + input_to[iteration] = new; +@@ -115,6 +116,7 @@ int get_valid_sleep_input(int column_offest) + input); + refresh(); + } ++ free(input); + } + + attrset(COLOR_PAIR(1)); +-- +2.17.1 + diff --git a/SOURCES/irqbalance-1.4.0-procinterrupts-check-xen-dyn-event-more-flexible.patch b/SOURCES/irqbalance-1.4.0-procinterrupts-check-xen-dyn-event-more-flexible.patch new file mode 100644 index 0000000..23bb4dd --- /dev/null +++ b/SOURCES/irqbalance-1.4.0-procinterrupts-check-xen-dyn-event-more-flexible.patch @@ -0,0 +1,72 @@ +From 3eae2edd136540898f8e51546eedfb56729f938d Mon Sep 17 00:00:00 2001 +From: Xiao Liang +Date: Thu, 18 Oct 2018 21:50:33 +0800 +Subject: procinterrupts: check xen-dyn-event more flexible + +In current /proc/interrupts, the 'xen-dyn-event' was split to 'xen-dyn -event'. +It causes interrupts not balanced inside xen guest. + +Below result is without this patch: + 70: 29 0 0 0 xen-dyn -event vif0-q0-tx + 71: 120 0 0 0 xen-dyn -event vif0-q0-rx + 72: 586350 0 0 0 xen-dyn -event vif0-q1-tx + 73: 44 0 0 0 xen-dyn -event vif0-q1-rx + 74: 19 0 0 0 xen-dyn -event vif0-q2-tx + 75: 179 0 0 0 xen-dyn -event vif0-q2-rx + 76: 67 0 0 0 xen-dyn -event vif0-q3-tx + 77: 299637 0 0 0 xen-dyn -event vif0-q3-rx + +Below result is with this patch: +[root@dhcp-3-194 ~]# grep vif0 /proc/interrupts + 70: 30 0 0 0 xen-dyn -event vif0-q0-tx + 71: 305 0 11 0 xen-dyn -event vif0-q0-rx + 72: 586354 0 27 0 xen-dyn -event vif0-q1-tx + 73: 49 7 5 0 xen-dyn -event vif0-q1-rx + 74: 27 0 0 509373 xen-dyn -event vif0-q2-tx + 75: 420 0 5 0 xen-dyn -event vif0-q2-rx + 76: 179 0 38 0 xen-dyn -event vif0-q3-tx + 77: 299803 281433 0 0 xen-dyn -event vif0-q3-rx + +Signed-off-by: Xiao Liang +--- + procinterrupts.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/procinterrupts.c b/procinterrupts.c +index eb84a1c..ca9533b 100644 +--- a/procinterrupts.c ++++ b/procinterrupts.c +@@ -167,6 +167,7 @@ GList* collect_full_irq_list() + + while (!feof(file)) { + int number; ++ int is_xen_dyn = 0; + struct irq_info *info; + char *c; + char savedline[1024]; +@@ -187,9 +188,13 @@ GList* collect_full_irq_list() + + strncpy(savedline, line, sizeof(savedline)); + irq_name = strtok_r(savedline, " ", &savedptr); ++ if (strstr(irq_name, "xen-dyn") != NULL) ++ is_xen_dyn = 1; + last_token = strtok_r(NULL, " ", &savedptr); + while ((p = strtok_r(NULL, " ", &savedptr))) { + irq_name = last_token; ++ if (strstr(irq_name, "xen-dyn") != NULL) ++ is_xen_dyn = 1; + last_token = p; + } + +@@ -209,7 +214,7 @@ GList* collect_full_irq_list() + info = calloc(sizeof(struct irq_info), 1); + if (info) { + info->irq = number; +- if (strstr(irq_name, "xen-dyn-event") != NULL) { ++ if (strstr(irq_name, "-event") != NULL && is_xen_dyn == 1) { + info->type = IRQ_TYPE_VIRT_EVENT; + info->class = IRQ_VIRT_EVENT; + } else { +-- +2.17.1 + diff --git a/SOURCES/irqbalance-1.5.0-Don-t-leak-socket-fd-on-connection-error.patch b/SOURCES/irqbalance-1.5.0-Don-t-leak-socket-fd-on-connection-error.patch new file mode 100644 index 0000000..225d47c --- /dev/null +++ b/SOURCES/irqbalance-1.5.0-Don-t-leak-socket-fd-on-connection-error.patch @@ -0,0 +1,65 @@ +From ce71f0cc2255aba072eabb2af26f6cb0e31f8189 Mon Sep 17 00:00:00 2001 +From: Kairui Song +Date: Tue, 6 Nov 2018 10:37:15 +0800 +Subject: Don't leak socket fd on connection error + +Signed-off-by: Kairui Song +--- + irqbalance.c | 7 ++++--- + ui/irqbalance-ui.c | 1 + + 2 files changed, 5 insertions(+), 3 deletions(-) + +diff --git a/irqbalance.c b/irqbalance.c +index c89c3c0..a77f842 100644 +--- a/irqbalance.c ++++ b/irqbalance.c +@@ -389,7 +389,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + } + if ((recv_size = recvmsg(sock, &msg, 0)) < 0) { + log(TO_ALL, LOG_WARNING, "Error while receiving data.\n"); +- goto out; ++ goto out_close; + } + cmsg = CMSG_FIRSTHDR(&msg); + if ((cmsg->cmsg_level == SOL_SOCKET) && +@@ -401,7 +401,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + } + if (!valid_user) { + log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n"); +- goto out; ++ goto out_close; + } + + if (!strncmp(buff, "stats", strlen("stats"))) { +@@ -434,7 +434,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + need_rescan = 1; + if (!strncmp(irq_string, "NONE", strlen("NONE"))) { + free(irq_string); +- goto out; ++ goto out_close; + } + int irq = strtoul(irq_string, &end, 10); + do { +@@ -470,6 +470,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri + free(setup); + } + ++out_close: + close(sock); + } + +diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c +index 99f2ca2..6d4c845 100644 +--- a/ui/irqbalance-ui.c ++++ b/ui/irqbalance-ui.c +@@ -62,6 +62,7 @@ int init_connection() + + if(connect(socket_fd, (struct sockaddr *)&addr, + sizeof(sa_family_t) + strlen(socket_name) + 1) < 0) { ++ close(socket_fd); + return 0; + } + +-- +2.17.1 + diff --git a/SOURCES/irqbalance-1.5.0-Update-document-and-remove-dead-options.patch b/SOURCES/irqbalance-1.5.0-Update-document-and-remove-dead-options.patch new file mode 100644 index 0000000..80b93ea --- /dev/null +++ b/SOURCES/irqbalance-1.5.0-Update-document-and-remove-dead-options.patch @@ -0,0 +1,109 @@ +From 5f8ed87f36381569725c67445f12226f41861d1f Mon Sep 17 00:00:00 2001 +From: Kairui Song +Date: Fri, 9 Nov 2018 11:36:12 +0800 +Subject: [PATCH] Update document and remove dead options + +This is the stash of following three commits: + +commit ea743009f69ad4800c60bf26c776ef4944c6af8b +Author: Kairui Song +Date: Mon Mar 25 19:58:58 2019 +0800 + + Remove a duplicated word in manpage + + Just noticed a warning in a manpage scan report, trivial but let's + fix it. + + Signed-off-by: Kairui Song + +commit 0b95593b19ff13e7e271d5b0b8219e7c70bf773c +Author: Kairui Song +Date: Fri Nov 9 12:26:29 2018 +0800 + + Update document for option --banmod and --deepestcache + + '--banmod' is not documented, and '--deepestcache's alias '-c' is + missing. + + Also fix an typo. + + Signed-off-by: Kairui Song + +commit 3ae01f5bd5ef3ed3080c9b06fc63bb02cc03bf1a +Author: Kairui Song +Date: Fri Nov 9 11:36:12 2018 +0800 + + Remove hintpolicy related options in help message + + hintpolicy was dropped sometime ago so related help message should be + dropped as well. + + Signed-off-by: Kairui Song + +Signed-off-by: Kairui Song +--- + irqbalance.1 | 15 ++++++++++++--- + irqbalance.c | 3 +-- + 2 files changed, 13 insertions(+), 5 deletions(-) + +diff --git a/irqbalance.1 b/irqbalance.1 +index 68e3cf8..61ae35e 100644 +--- a/irqbalance.1 ++++ b/irqbalance.1 +@@ -62,12 +62,21 @@ in an effort to prevent that CPU from waking up without need. + .B -i, --banirq= + Add the specified IRQ to the set of banned IRQs. irqbalance will not affect + the affinity of any IRQs on the banned list, allowing them to be specified +-manually. This option is addative and can be specified multiple times. For ++manually. This option is additive and can be specified multiple times. For + example to ban IRQs 43 and 44 from balancing, use the following command line: + .B irqbalance --banirq=43 --banirq=44 + + .TP +-.B --deepestcache= ++.B -m, --banmod= ++Add the specified module to the set of banned modules, similiar to --banirq. ++irqbalance will not affect the affinity of any IRQs of given modules, allowing ++them to be specified manually. This option is additive and can be specified ++multiple times. For example to ban all IRQs of module foo and module bar from ++balancing, use the following command line: ++.B irqbalance --banmod=foo --banmod=bar ++ ++.TP ++.B -c, --deepestcache= + This allows a user to specify the cache level at which irqbalance partitions + cache domains. Specifying a deeper cache may allow a greater degree of + flexibility for irqbalance to assign IRQ affinity to achieve greater performance +@@ -148,7 +157,7 @@ each assigned IRQ type, it's number, load, number of IRQs since last rebalancing + and it's class are sent. Refer to types.h file for explanation of defines. + .TP + .B setup +-Get the current value of sleep interval, mask of banned CPUs and and list of banned IRQs. ++Get the current value of sleep interval, mask of banned CPUs and list of banned IRQs. + .TP + .B settings sleep + Set new value of sleep interval, >= 1. +diff --git a/irqbalance.c b/irqbalance.c +index 6412447..7713cd0 100644 +--- a/irqbalance.c ++++ b/irqbalance.c +@@ -84,7 +84,6 @@ struct option lopts[] = { + {"oneshot", 0, NULL, 'o'}, + {"debug", 0, NULL, 'd'}, + {"foreground", 0, NULL, 'f'}, +- {"hintpolicy", 1, NULL, 'h'}, + {"powerthresh", 1, NULL, 'p'}, + {"banirq", 1 , NULL, 'i'}, + {"banscript", 1, NULL, 'b'}, +@@ -100,7 +99,7 @@ struct option lopts[] = { + + static void usage(void) + { +- log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] [--foreground | -f] [--journal | -j] [--hintpolicy= | -h [exact|subset|ignore]]\n"); ++ log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] [--foreground | -f] [--journal | -j]\n"); + log(TO_CONSOLE, LOG_INFO, " [--powerthresh= | -p | ] [--banirq= | -i ] [--banmod= | -m ] [--policyscript= | -l