From 3f2a16fed6815e6031c247f49b79ef40f0bc35a1 Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Feb 11 2022 14:58:50 +0000 Subject: Allow manual reservation of additional hp threads bind-dyndb-ldap started crashing after memory optimization made in 9.16.25 release. It attempts to use now uninitialized memory part. Work around this problem by extra command line parameters, which would request additional threads. Those threads then would be safely used by bind-dyndb-ldap. Requires change to bind-dyndb-ldap and freeipa packages. Needs freeipa to add OPTIONS+="-H 200" to /etc/sysconfig/named Related: rhbz#2048235 --- diff --git a/bind-9.16-hp-workers-rh2048235-dyndb.patch b/bind-9.16-hp-workers-rh2048235-dyndb.patch new file mode 100644 index 0000000..12ae5ad --- /dev/null +++ b/bind-9.16-hp-workers-rh2048235-dyndb.patch @@ -0,0 +1,116 @@ +From b6320643194a3b435f2a6ae4569ace19db6ac795 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= +Date: Fri, 11 Feb 2022 14:19:10 +0100 +Subject: [PATCH] Propagate extra hp threads to dyndb plugins + +Plugin may require extra threads for processing its own source data. If +that plugin needs to call isc_task_send() from those threads, it needs +extra hp threads initialized. Allow plugin to read how many such threads +it can use. Allows plugin to fail initialization if not enough workers +were initialized. +--- + bin/named/server.c | 9 +++++---- + lib/dns/dyndb.c | 4 +++- + lib/dns/include/dns/dyndb.h | 22 +++++++++++++--------- + 3 files changed, 21 insertions(+), 14 deletions(-) + +diff --git a/bin/named/server.c b/bin/named/server.c +index 721464db8e..27e23fd52e 100644 +--- a/bin/named/server.c ++++ b/bin/named/server.c +@@ -5581,10 +5581,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, + + if (dctx == NULL) { + const void *hashinit = isc_hash_get_initializer(); +- CHECK(dns_dyndb_createctx(mctx, hashinit, named_g_lctx, +- view, named_g_server->zonemgr, +- named_g_server->task, +- named_g_timermgr, &dctx)); ++ CHECK(dns_dyndb_createctx( ++ mctx, hashinit, named_g_lctx, view, ++ named_g_server->zonemgr, named_g_server->task, ++ named_g_timermgr, named_g_hp_extra_workers, ++ &dctx)); + } + + CHECK(configure_dyndb(dyndb, mctx, dctx)); +diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c +index 1caf90bab7..7d2784c5fa 100644 +--- a/lib/dns/dyndb.c ++++ b/lib/dns/dyndb.c +@@ -408,7 +408,8 @@ dns_dyndb_cleanup(bool exiting) { + isc_result_t + dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, + dns_view_t *view, dns_zonemgr_t *zmgr, isc_task_t *task, +- isc_timermgr_t *tmgr, dns_dyndbctx_t **dctxp) { ++ isc_timermgr_t *tmgr, unsigned int extra_workers, ++ dns_dyndbctx_t **dctxp) { + dns_dyndbctx_t *dctx; + + REQUIRE(dctxp != NULL && *dctxp == NULL); +@@ -429,6 +430,7 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, + dctx->hashinit = hashinit; + dctx->lctx = lctx; + dctx->memdebug = &isc_mem_debugging; ++ dctx->extra_workers = extra_workers; + + isc_mem_attach(mctx, &dctx->mctx); + dctx->magic = DNS_DYNDBCTX_MAGIC; +diff --git a/lib/dns/include/dns/dyndb.h b/lib/dns/include/dns/dyndb.h +index bda744a8d9..a93947d340 100644 +--- a/lib/dns/include/dns/dyndb.h ++++ b/lib/dns/include/dns/dyndb.h +@@ -35,14 +35,15 @@ ISC_LANG_BEGINDECLS + */ + struct dns_dyndbctx { + unsigned int magic; +- const void *hashinit; +- isc_mem_t *mctx; +- isc_log_t *lctx; +- dns_view_t *view; +- dns_zonemgr_t *zmgr; +- isc_task_t *task; ++ const void * hashinit; ++ isc_mem_t * mctx; ++ isc_log_t * lctx; ++ dns_view_t * view; ++ dns_zonemgr_t * zmgr; ++ isc_task_t * task; + isc_timermgr_t *timermgr; +- unsigned int *memdebug; ++ unsigned int * memdebug; ++ unsigned int extra_workers; + }; + + #define DNS_DYNDBCTX_MAGIC ISC_MAGIC('D', 'd', 'b', 'c') +@@ -58,7 +59,7 @@ struct dns_dyndbctx { + */ + #ifndef DNS_DYNDB_VERSION + #define DNS_DYNDB_VERSION 1 +-#define DNS_DYNDB_AGE 0 ++#define DNS_DYNDB_AGE 1 + #endif /* ifndef DNS_DYNDB_VERSION */ + + typedef isc_result_t +@@ -135,7 +136,8 @@ dns_dyndb_cleanup(bool exiting); + isc_result_t + dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, + dns_view_t *view, dns_zonemgr_t *zmgr, isc_task_t *task, +- isc_timermgr_t *tmgr, dns_dyndbctx_t **dctxp); ++ isc_timermgr_t *tmgr, unsigned int extra_workers, ++ dns_dyndbctx_t **dctxp); + /*% + * Create a dyndb initialization context structure, with + * pointers to structures in the server that the dyndb module will +@@ -143,6 +145,8 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, + * etc). This structure is expected to last only until all dyndb + * modules have been loaded and initialized; after that it will be + * destroyed with dns_dyndb_destroyctx(). ++ * extra workers specifies how many extra worker threads can plugin ++ * use to send tasks to named threads by isc_task_send() + * + * Returns: + *\li #ISC_R_SUCCESS +-- +2.34.1 + diff --git a/bind-9.16-hp-workers-rh2048235.patch b/bind-9.16-hp-workers-rh2048235.patch new file mode 100644 index 0000000..019274b --- /dev/null +++ b/bind-9.16-hp-workers-rh2048235.patch @@ -0,0 +1,180 @@ +From 140ae14a4d6374530c9ab19a29c246abbf6d60b8 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= +Date: Fri, 11 Feb 2022 13:29:03 +0100 +Subject: [PATCH] Add extra hp workers parameter + +May be needed by dyndb plugins to prepare extra worker threads. If they +use isc_task_send, their threads need to have initialized enough thread +identifiers in isc_hp_init. New parameters allow that. + +Allows specification of both relative and absolute number of extra +workers. + +Adds new function isc_managers_create2() with extra parameter, call +original function from many tests and tools unchanged. +--- + bin/named/include/named/globals.h | 2 ++ + bin/named/include/named/main.h | 2 +- + bin/named/main.c | 29 +++++++++++++++++++++++++---- + bin/named/named.rst | 9 +++++++++ + lib/isc/include/isc/managers.h | 5 +++++ + lib/isc/managers.c | 11 ++++++++++- + 6 files changed, 52 insertions(+), 6 deletions(-) + +diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h +index 82b632ef04..d46e62b94d 100644 +--- a/bin/named/include/named/globals.h ++++ b/bin/named/include/named/globals.h +@@ -53,6 +53,8 @@ EXTERN unsigned int named_g_udpdisp INIT(0); + EXTERN isc_taskmgr_t *named_g_taskmgr INIT(NULL); + EXTERN dns_dispatchmgr_t *named_g_dispatchmgr INIT(NULL); + EXTERN unsigned int named_g_cpus_detected INIT(1); ++EXTERN unsigned int named_g_hp_extra_workers INIT(0); ++EXTERN unsigned int named_g_hp_extra_percent INIT(100); + + #ifdef ENABLE_AFL + EXTERN bool named_g_run_done INIT(false); +diff --git a/bin/named/include/named/main.h b/bin/named/include/named/main.h +index 816aeae7a0..9618251f4d 100644 +--- a/bin/named/include/named/main.h ++++ b/bin/named/include/named/main.h +@@ -23,7 +23,7 @@ + /* + * Commandline arguments for named; also referenced in win32/ntservice.c + */ +-#define NAMED_MAIN_ARGS "46A:c:d:D:E:fFgL:M:m:n:N:p:sS:t:T:U:u:vVx:X:" ++#define NAMED_MAIN_ARGS "46A:c:d:D:E:fFgh:H:L:M:m:n:N:p:sS:t:T:U:u:vVx:X:" + + ISC_PLATFORM_NORETURN_PRE void + named_main_earlyfatal(const char *format, ...) +diff --git a/bin/named/main.c b/bin/named/main.c +index 9ad2d0e277..fbe4c8d011 100644 +--- a/bin/named/main.c ++++ b/bin/named/main.c +@@ -351,7 +351,8 @@ usage(void) { + "username] [-U listeners]\n" + " [-X lockfile] [-m " + "{usage|trace|record|size|mctx}]\n" +- " [-M fill|nofill]\n" ++ " [-M fill|nofill] [-h extra_workers] " ++ "[-H extra_percent]\n" + "usage: named [-v|-V]\n"); + } + +@@ -792,6 +793,21 @@ parse_command_line(int argc, char *argv[]) { + named_g_foreground = true; + named_g_logstderr = true; + break; ++ case 'h': ++ named_g_hp_extra_workers = ++ parse_int(isc_commandline_argument, ++ "number of extra workers"); ++ break; ++ case 'H': ++ named_g_hp_extra_percent = ++ parse_int(isc_commandline_argument, ++ "percent of extra workers"); ++ if (named_g_hp_extra_percent < 100) { ++ named_main_earlyfatal( ++ "percent of extra workers " ++ "cannot be less than 100"); ++ } ++ break; + case 'L': + named_g_logfile = isc_commandline_argument; + break; +@@ -904,6 +920,10 @@ create_managers(void) { + if (named_g_cpus == 0) { + named_g_cpus = named_g_cpus_detected; + } ++ if (named_g_hp_extra_percent > 100) { ++ named_g_hp_extra_workers += ++ named_g_cpus * (named_g_hp_extra_percent - 100) / 100; ++ } + isc_log_write( + named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, + ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s", +@@ -924,11 +944,12 @@ create_managers(void) { + "using %u UDP listener%s per interface", named_g_udpdisp, + named_g_udpdisp == 1 ? "" : "s"); + +- result = isc_managers_create(named_g_mctx, named_g_cpus, 0, &named_g_nm, +- &named_g_taskmgr); ++ result = isc_managers_create2(named_g_mctx, named_g_cpus, 0, ++ named_g_hp_extra_workers, &named_g_nm, ++ &named_g_taskmgr); + if (result != ISC_R_SUCCESS) { + UNEXPECTED_ERROR(__FILE__, __LINE__, +- "isc_managers_create() failed: %s", ++ "isc_managers_create2() failed: %s", + isc_result_totext(result)); + return (ISC_R_UNEXPECTED); + } +diff --git a/bin/named/named.rst b/bin/named/named.rst +index 39c445f5f9..b5bf95398c 100644 +--- a/bin/named/named.rst ++++ b/bin/named/named.rst +@@ -75,6 +75,15 @@ Options + ``-g`` + This option runs the server in the foreground and forces all logging to ``stderr``. + ++``-h #workers`` ++ This option requests extra worker threads initialized by hazard pointers. Used only for ++ dyndb plugins. ++ ++``-H workers%`` ++ This option requests extra worker threads initialized by hazard pointers. Value is ++ computed as percent of number of cpus set by ``-n`` parameter. Minimal value is 100%. ++ Used only for dyndb plugins. ++ + ``-L logfile`` + This option sets the log to the file ``logfile`` by default, instead of the system log. + +diff --git a/lib/isc/include/isc/managers.h b/lib/isc/include/isc/managers.h +index 0ed17ff31d..712ea3e3ed 100644 +--- a/lib/isc/include/isc/managers.h ++++ b/lib/isc/include/isc/managers.h +@@ -25,5 +25,10 @@ isc_result_t + isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, + isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp); + ++isc_result_t ++isc_managers_create2(isc_mem_t *mctx, size_t workers, size_t quantum, ++ size_t hp_extra, isc_nm_t **netmgrp, ++ isc_taskmgr_t **taskmgrp); ++ + void + isc_managers_destroy(isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp); +diff --git a/lib/isc/managers.c b/lib/isc/managers.c +index a285e80d8a..daf19c5596 100644 +--- a/lib/isc/managers.c ++++ b/lib/isc/managers.c +@@ -21,15 +21,24 @@ + isc_result_t + isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, + isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp) { ++ return isc_managers_create2(mctx, workers, quantum, 0, netmgrp, ++ taskmgrp); ++} ++ ++isc_result_t ++isc_managers_create2(isc_mem_t *mctx, size_t workers, size_t quantum, ++ size_t hp_extra, isc_nm_t **netmgrp, ++ isc_taskmgr_t **taskmgrp) { + isc_result_t result; + isc_taskmgr_t *taskmgr = NULL; + isc_nm_t *netmgr = NULL; ++ size_t hp_workers = 4 * (workers + hp_extra); + + /* + * We have ncpus network threads, ncpus old network threads - make + * it 4x just to be on the safe side. + */ +- isc_hp_init(4 * workers); ++ isc_hp_init(hp_workers); + + REQUIRE(netmgrp != NULL && *netmgrp == NULL); + isc__netmgr_create(mctx, workers, &netmgr); +-- +2.34.1 + diff --git a/bind.spec b/bind.spec index 2627b6f..574b0fe 100644 --- a/bind.spec +++ b/bind.spec @@ -53,7 +53,7 @@ Summary: The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) serv Name: bind License: MPLv2.0 Version: 9.16.25 -Release: 2%{?dist} +Release: 3%{?dist} Epoch: 32 Url: https://www.isc.org/downloads/bind/ # @@ -104,6 +104,9 @@ Patch157:bind-9.11-fips-tests.patch Patch164:bind-9.11-rh1666814.patch # https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/5757 Patch165:bind-9.16-pthread-dlz.patch +# https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/5795 +Patch167:bind-9.16-hp-workers-rh2048235.patch +Patch168:bind-9.16-hp-workers-rh2048235-dyndb.patch %{?systemd_ordering} Requires: coreutils @@ -403,6 +406,8 @@ in HTML and PDF format. %patch157 -p1 -b .fips-tests %patch164 -p1 -b .rh1666814 %patch165 -p1 -b .pthread-dlz +%patch167 -p1 -b .rh2048235 +%patch168 -p1 -b .rh2048235-dyndb %if %{with PKCS11} %patch135 -p1 -b .config-pkcs11 @@ -1125,6 +1130,9 @@ fi; %endif %changelog +* Fri Feb 11 2022 Petr Menšík - 32:9.16.25-3 +- Allow reservation of extra hp threads (#2048235) + * Tue Jan 25 2022 Petr Menšík - 32:9.16.25-2 - Replace master with primary in configuration