From patchwork Fri Aug 2 23:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 95243 X-Patchwork-Delegate: mark@klomp.org Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B18013858C78 for ; Fri, 2 Aug 2024 23:40:10 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 6E8033858D3C for ; Fri, 2 Aug 2024 23:39:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E8033858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E8033858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722641974; cv=none; b=LHQjmy9F/D3csksoQgUAzLdExcdEsYdcO6KY3GwX7hbThxxMaef1SvIjD1uTQzP/Zi+Bs+RGxDuwDqhhnagx+jvMdNdMQcthVQPBiZyV5Dcxu74ey6PLWq6MX35tFwgEov9dvNYt8Yeak/mWNany+5s+BHjQd7j0q1DB+zJ1la8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722641974; c=relaxed/simple; bh=/WeXQJO9L/04WyRHn+KNZpnk1jOmyaqEtPa3mhKX6N0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VKXMuRm8Lw7LORDQ3bdo6gEZmxLsQfH2hWWIIO0wX/SkLjC4e25gCtYV1dX8BAdsGhZbX6LcVbCFGXBiVZ/eqdRKjIXFQEbFNPWy2Ob5TqG9DxhBQIP9hRcwFEtnxAZeYrI8aN3wGOXJIfNdMoOzaTerLsa7qWJroAtnlPjT1OY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722641971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z5OdZ1fRH+IaJMMloua5cTY+1KqZSM5AH1pmEEGgtmc=; b=X+aXDpU+DRWjuvhmt88SYJuvh34OEd3q5RABSVOmnVSI9y3GkJuTZKatoNq+oeXxi1br9v xmi1V7ffxdExuU5gwwSOjFxQlxATyW+iELNm2sBtLgPTNpCTOEj8zsa1kkl2FFD6P+pvu8 DE/2yH5u/lQA5o6sSm1LykUIwxSpfQ0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-KjHkc4hMO2u4pJPERp-GZA-1; Fri, 02 Aug 2024 19:39:29 -0400 X-MC-Unique: KjHkc4hMO2u4pJPERp-GZA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DA2CA1956088; Fri, 2 Aug 2024 23:39:28 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.40]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3C99B19560AA; Fri, 2 Aug 2024 23:39:27 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: hsm2@rice.edu, johnmc@rice.edu, mark@klomp.org, Aaron Merey Subject: [PATCH 07/10 v3] libdw: Make libdw_find_split_unit thread-safe Date: Fri, 2 Aug 2024 19:38:06 -0400 Message-ID: <20240802233847.690564-7-amerey@redhat.com> In-Reply-To: <20240802233847.690564-1-amerey@redhat.com> References: <20240802233847.690564-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org From: Heather McIntyre * libdw/libdwP.h (struct Dwarf_CU): Add split_lock. * libdw/libdw_find_split_unit.c (__libdw_find_split_unit): Add locking. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v3 changes: Move Dwarf split_lock code from patch 3/9 v2 to this patch. Assign return value before releasing lock. libdw/dwarf_end.c | 1 + libdw/libdwP.h | 3 +++ libdw/libdw_find_split_unit.c | 15 +++++++++++++-- libdw/libdw_findcu.c | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c index 487d6ce7..ee3ed74e 100644 --- a/libdw/dwarf_end.c +++ b/libdw/dwarf_end.c @@ -69,6 +69,7 @@ cu_free (void *arg) { Dwarf_Abbrev_Hash_free (&p->abbrev_hash); rwlock_fini (p->abbrev_lock); + rwlock_fini (p->split_lock); /* Free split dwarf one way (from skeleton to split). */ if (p->unit_type == DW_UT_skeleton diff --git a/libdw/libdwP.h b/libdw/libdwP.h index 48c34871..8f942433 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -454,6 +454,9 @@ struct Dwarf_CU /* Synchronize Dwarf_Die abbrev access. */ rwlock_define(, abbrev_lock); + /* Synchronize split Dwarf access. */ + rwlock_define(, split_lock); + /* Memory boundaries of this CU. */ void *startp; void *endp; diff --git a/libdw/libdw_find_split_unit.c b/libdw/libdw_find_split_unit.c index 4005793b..f4f34c5d 100644 --- a/libdw/libdw_find_split_unit.c +++ b/libdw/libdw_find_split_unit.c @@ -150,9 +150,18 @@ Dwarf_CU * internal_function __libdw_find_split_unit (Dwarf_CU *cu) { + /* Set result before releasing the lock. */ + Dwarf_CU *result; + + rwlock_wrlock(cu->split_lock); + /* Only try once. */ if (cu->split != (Dwarf_CU *) -1) - return cu->split; + { + result = cu->split; + rwlock_unlock(cu->split_lock); + return result; + } /* We need a skeleton unit with a comp_dir and [GNU_]dwo_name attributes. The split unit will be the first in the dwo file and should have the @@ -207,5 +216,7 @@ __libdw_find_split_unit (Dwarf_CU *cu) if (cu->split == (Dwarf_CU *) -1) cu->split = NULL; - return cu->split; + result = cu->split; + rwlock_unlock(cu->split_lock); + return result; } diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c index 0f46d777..c74e895e 100644 --- a/libdw/libdw_findcu.c +++ b/libdw/libdw_findcu.c @@ -178,6 +178,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types) newp->endp = data->d_buf + newp->end; eu_search_tree_init (&newp->locs_tree); rwlock_init (newp->abbrev_lock); + rwlock_init (newp->split_lock); /* v4 debug type units have version == 4 and unit_type == DW_UT_type. */ if (debug_types)