From 392ac795ce6a63840ccd341463a00288c9d4a86e Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Sep 18 2020 12:49:47 +0000 Subject: Add fix of rbtdb.c from upstream ARM and s390x cannot compile, because they lack atomic implementation in lib/isc. Include upstream fix after 9.11.23 release. Signed-off-by: Petr Menšík --- diff --git a/bind-9.11.23-atomic.patch b/bind-9.11.23-atomic.patch new file mode 100644 index 0000000..b5c37ec --- /dev/null +++ b/bind-9.11.23-atomic.patch @@ -0,0 +1,178 @@ +From 1528f231b559670445cfc427937174535981917d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= +Date: Fri, 18 Sep 2020 14:46:02 +0200 +Subject: [PATCH] Fix isc_atomic_xadd symbol missing + +Squashed commit of the following: + +commit d8afe85342f05d8fec8ee0255451568e936b7eb2 +Author: Mark Andrews +Date: Mon Sep 7 16:12:31 2020 +1000 + + Update 'init_count' atomically to silence tsan errors. + + (cherry picked from commit 90185b225f4c7acde2fbb04697d857fe496725a2) + +commit f166c7fb7cc262a688ed511e40c9b0d551d5992d +Author: Mark Andrews +Date: Thu Sep 3 12:53:53 2020 +1000 + + The node lock was released too early. + + NEGATIVE needs to be call with the node lock held. + + WARNING: ThreadSanitizer: data race + Write of size 2 at 0x000000000001 by thread T1 (mutexes: write M1): + #0 mark_stale_header lib/dns/rbtdb.c:1802:21 + #1 add32 lib/dns/rbtdb.c:6559:5 + #2 addrdataset lib/dns/rbtdb.c:6975:12 + #3 dns_db_addrdataset lib/dns/db.c:783:10 + #4 cache_name lib/dns/resolver.c:5829:13 + #5 cache_message lib/dns/resolver.c:5926:14 + #6 resquery_response lib/dns/resolver.c:8618:12 + #7 dispatch lib/isc/task.c:1157:7 + #8 run lib/isc/task.c:1331:2 + + Previous read of size 2 at 0x000000000001 by thread T2: + #0 cache_findrdataset lib/dns/rbtdb.c:5932:6 + #1 dns_db_findrdataset lib/dns/db.c:739:10 + #2 query_addadditional2 bin/named/query.c:2196:11 + #3 additionaldata_ns lib/dns/./rdata/generic/ns_2.c:198:10 + #4 dns_rdata_additionaldata lib/dns/rdata.c:1246:2 + #5 dns_rdataset_additionaldata lib/dns/rdataset.c:629:12 + #6 query_addrdataset bin/named/query.c:2411:8 + #7 query_addrrset bin/named/query.c:2802:2 + #8 query_addbestns bin/named/query.c:3501:2 + #9 query_find bin/named/query.c:9165:4 + #10 query_resume bin/named/query.c:4164:12 + #11 dispatch lib/isc/task.c:1157:7 + #12 run lib/isc/task.c:1331:2 + + (cherry picked from commit a1dcb73f677969d99df3ccff2acf4737e18a72b1) + +commit 591a80fa95b8f3f3e716c45ceb9c5e4ccfa551c8 +Author: Mark Andrews +Date: Mon Aug 24 17:34:58 2020 +1000 + + increment header->count atomically + + (cherry picked from commit 121837aa75ced489e28f8ce1dd20315487d199fa) +--- + lib/dns/rbtdb.c | 43 +++++++++++++++++++++++++++++++++++-------- + 1 file changed, 35 insertions(+), 8 deletions(-) + +diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c +index 88c39bf714..31ced8e73a 100644 +--- a/lib/dns/rbtdb.c ++++ b/lib/dns/rbtdb.c +@@ -399,6 +399,23 @@ typedef isc_mutex_t nodelock_t; + #define NODE_WEAKDOWNGRADE(l) ((void)0) + #endif + ++#if defined(ISC_PLATFORM_HAVESTDATOMIC) ++#if defined(__cplusplus) ++#include ++#else ++#include ++#endif ++#define DNS_RBTDB_STDATOMIC 1 ++#define DNS_RBTDB_INC(x) atomic_fetch_add(&(x), (1)) ++#define DNS_RBTDB_LOAD(x) atomic_load(&(x)) ++#elif defined(ISC_PLATFORM_HAVEXADD) ++#define DNS_RBTDB_INC(x) isc_atomic_xadd((int *)&(x), 1); ++#define DNS_RBTDB_LOAD(x) isc_atomic_xadd((int *)&(x), 0); ++#else ++#define DNS_RBTDB_INC(x) ((x)++) ++#define DNS_RBTDB_LOAD(x) (x) ++#endif ++ + /*% + * Whether to rate-limit updating the LRU to avoid possible thread contention. + * Our performance measurement has shown the cost is marginal, so it's defined +@@ -457,7 +474,11 @@ typedef struct rdatasetheader { + * this rdataset. + */ + +- uint32_t count; ++#ifdef DNS_RBTDB_STDATOMIC ++ _Atomic(uint32_t) count; ++#else ++ uint32_t count; ++#endif + /*%< + * Monotonously increased every time this rdataset is bound so that + * it is used as the base of the starting point in DNS responses +@@ -952,7 +973,11 @@ static char FILE_VERSION[32] = "\0"; + * that indicates that the database does not implement cyclic + * processing. + */ ++#ifdef DNS_RBTDB_STDATOMIC ++static _Atomic(unsigned int) init_count; ++#else + static unsigned int init_count; ++#endif + + /* + * Locking +@@ -3322,7 +3347,7 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, + rdataset->private2 = node; + raw = (unsigned char *)header + sizeof(*header); + rdataset->private3 = raw; +- rdataset->count = header->count++; ++ rdataset->count = DNS_RBTDB_INC(header->count); + if (rdataset->count == UINT32_MAX) + rdataset->count = 0; + +@@ -5924,10 +5949,10 @@ cache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, + } + } + +- NODE_UNLOCK(lock, locktype); +- +- if (found == NULL) ++ if (found == NULL) { ++ NODE_UNLOCK(lock, locktype); + return (ISC_R_NOTFOUND); ++ } + + if (NEGATIVE(found)) { + /* +@@ -5939,6 +5964,8 @@ cache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, + result = DNS_R_NCACHENXRRSET; + } + ++ NODE_UNLOCK(lock, locktype); ++ + update_cachestats(rbtdb, result); + + return (result); +@@ -6839,7 +6866,7 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, + newheader->attributes |= RDATASET_ATTR_ZEROTTL; + newheader->noqname = NULL; + newheader->closest = NULL; +- newheader->count = isc_atomic_xadd((int32_t*)&init_count, 1); ++ newheader->count = DNS_RBTDB_INC(init_count); + newheader->trust = rdataset->trust; + newheader->additional_auth = NULL; + newheader->additional_glue = NULL; +@@ -7035,7 +7062,7 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, + newheader->trust = 0; + newheader->noqname = NULL; + newheader->closest = NULL; +- newheader->count = isc_atomic_xadd((int32_t*)&init_count, 1); ++ newheader->count = DNS_RBTDB_INC(init_count); + newheader->additional_auth = NULL; + newheader->additional_glue = NULL; + newheader->last_used = 0; +@@ -7481,7 +7508,7 @@ loading_addrdataset(void *arg, dns_name_t *name, dns_rdataset_t *rdataset) { + newheader->serial = 1; + newheader->noqname = NULL; + newheader->closest = NULL; +- newheader->count = isc_atomic_xadd((int32_t*)&init_count, 1); ++ newheader->count = DNS_RBTDB_INC(init_count); + newheader->additional_auth = NULL; + newheader->additional_glue = NULL; + newheader->last_used = 0; +-- +2.26.2 + diff --git a/bind.spec b/bind.spec index 3103281..1e4edfa 100644 --- a/bind.spec +++ b/bind.spec @@ -168,6 +168,8 @@ Patch177: bind-9.11-serve-stale.patch Patch178: bind-9.11-serve-stale-dbfix.patch # https://bugzilla.redhat.com/show_bug.cgi?id=1736762 Patch183: bind-9.11-rh1736762-5.patch +# https://gitlab.isc.org/isc-projects/bind9/-/issues/2167 +Patch184: bind-9.11.23-atomic.patch # SDB patches Patch11: bind-9.3.2b2-sdbsrc.patch @@ -589,6 +591,7 @@ are used for building ISC DHCP. %patch177 -p1 -b .serve-stale %patch178 -p1 -b .rh1770492 %patch183 -p1 -b .rh1736762-5 +%patch184 -p1 -b .rbtdb-atomic mkdir lib/dns/tests/testdata/dstrandom cp -a %{SOURCE50} lib/dns/tests/testdata/dstrandom/random.data