From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B24E01F54E; Mon, 15 Aug 2022 21:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1660598537; bh=3YJ13/mdrTL05Z7VuHElbj27/8LAXtaE4Jva77OHqfU=; h=Date:From:To:Cc:Subject:From; b=WJTe1m59ov6L9A64Nyxgh0gCY6rkf999vUJpD9tmor1kHyC9CMcHnZrz+t+kTgfIi f/GA8r61eR9jWw9uyNfYNeNVvXV/+HWH4wtT8+IPj31koKnbCBNtOOoaMnfHIyJ8TK 0GQzkrcVZab5NZxJBnVBiNY7v+AU2UZQGlKeUvhQ= Date: Mon, 15 Aug 2022 21:22:17 +0000 From: Eric Wong To: mwrap-public@80x24.org Cc: Sam Saffron Subject: [RFC/PATCH] workaround breakage from urcu v0.11.4 Message-ID: <20220815212217.GA11237@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: urcu v0.11.4+ introduced commit 7ca7fe9c03 (Make temporary variable in _rcu_dereference non-const, 2021-07-29) which conflicts with our use of _LGPL_SOURCE. In retrospect, CMM_LOAD_SHARED and CMM_STORE_SHARED seem sufficient for our use of the `totals' cds_lfht pointer since the constructur should always fire before any threads are running. Link: https://lore.kernel.org/lttng-dev/20220809181927.GA3718@dcvr/ --- I'm nearly certain this change is correct and prior use of rcu_dereference was overkill; but confirmation from a URCU hacker would be nice. ext/mwrap/mwrap.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index 4575e34..477b1cb 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -139,8 +139,8 @@ __attribute__((constructor)) static void resolve_malloc(void) _exit(1); } #endif /* !FreeBSD */ - totals = lfht_new(); - if (!totals) + CMM_STORE_SHARED(totals, lfht_new()); + if (!CMM_LOAD_SHARED(totals)) fprintf(stderr, "failed to allocate totals table\n"); err = pthread_atfork(call_rcu_before_fork, @@ -375,7 +375,7 @@ static struct src_loc *totals_add_rcu(struct src_loc *k) struct cds_lfht *t; again: - t = rcu_dereference(totals); + t = CMM_LOAD_SHARED(totals); if (!t) goto out_unlock; cds_lfht_lookup(t, k->hval, loc_eq, k, &iter); cur = cds_lfht_iter_get_node(&iter); @@ -417,7 +417,7 @@ static struct src_loc *update_stats_rcu_lock(size_t size, uintptr_t caller) static const size_t xlen = sizeof(caller); char *dst; - if (caa_unlikely(!totals)) return 0; + if (caa_unlikely(!CMM_LOAD_SHARED(totals))) return 0; if (locating++) goto out; /* do not recurse into another *alloc */ uatomic_add(&total_bytes_inc, size); @@ -808,7 +808,7 @@ static void *dump_to_file(void *x) ++locating; rcu_read_lock(); - t = rcu_dereference(totals); + t = CMM_LOAD_SHARED(totals); if (!t) goto out_unlock; cds_lfht_for_each_entry(t, &iter, l, hnode) { @@ -877,7 +877,7 @@ static void *totals_reset(void *ign) uatomic_set(&total_bytes_dec, 0); rcu_read_lock(); - t = rcu_dereference(totals); + t = CMM_LOAD_SHARED(totals); cds_lfht_for_each_entry(t, &iter, l, hnode) { uatomic_set(&l->total, 0); uatomic_set(&l->allocations, 0); @@ -945,7 +945,7 @@ static VALUE dump_each_rcu(VALUE x) struct cds_lfht_iter iter; struct src_loc *l; - t = rcu_dereference(totals); + t = CMM_LOAD_SHARED(totals); cds_lfht_for_each_entry(t, &iter, l, hnode) { VALUE v[6]; if (l->total <= a->min) continue; @@ -1049,9 +1049,9 @@ static VALUE mwrap_aref(VALUE mod, VALUE loc) if (!k) return val; + t = CMM_LOAD_SHARED(totals); + if (!t) return val; rcu_read_lock(); - t = rcu_dereference(totals); - if (!t) goto out_unlock; cds_lfht_lookup(t, k->hval, loc_eq, k, &iter); cur = cds_lfht_iter_get_node(&iter); @@ -1059,7 +1059,6 @@ static VALUE mwrap_aref(VALUE mod, VALUE loc) l = caa_container_of(cur, struct src_loc, hnode); val = TypedData_Wrap_Struct(cSrcLoc, &src_loc_type, l); } -out_unlock: rcu_read_unlock(); return val; }