From patchwork Wed Jul 17 22:34: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: 94101 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 223BA386100B for ; Wed, 17 Jul 2024 22:35:33 +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 ESMTPS id 632C93860778 for ; Wed, 17 Jul 2024 22:35:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 632C93860778 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 632C93860778 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=1721255706; cv=none; b=FYlXr4YysA3Rvu68+d+gU8W9EoS0SpxWhMmxNCppn444gBIeP8S0t4OjjJOJMXa2mFUcBHt/jHXBMjAqQt3eiQERvmyVbEFXMiqrq3PsNkWUC/gfRVbUtkrRjOGDQjoRBW5br1jmcL+9ZcAMkGiZjLpMFfWo/7VgjlH5VYTZLaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721255706; c=relaxed/simple; bh=H/M1K0L+aMzTXB0l7ASLlCZZFRtwgV1YmHGsi8iLkh8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LKh4+C30gugsXMJReRuRIA8GwBoZLFdG6OYaO/+o5a6UlpeWG6Mp1+fb+AUgdFAQSr/4+xMv3cUIz353adsEremoKeexozeizpTGQOIiQOQUodrgTrJo/A8b4YhhgOK8HufAHmQ/0aad/zaXxlqEeOQD5ANI5+6d9QxaPjXu484= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721255703; 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=R0xSpSmlFS/uPKEeAlTogd91j8/e6ERmEdZa02uM2Ew=; b=QauLJ8WtpgYQudplBZLWjueVUmgF/2RQzVJum+KPke3psG3E+pSkpcB2hgSW8VpVlQFYWS NpJBiPUM9FAS2y8BsXROWcaWwc8z9/ndTSkL/XM4VaDJ/ye2OKUoNaRgZrLCLPYCTxqpVi Rb/D+19eUIgWOq0XI/tMXtDqGWzJK/Q= Received: from mx-prod-mc-05.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-433-CAbOorrZPJW-o1cdilhymg-1; Wed, 17 Jul 2024 18:34:58 -0400 X-MC-Unique: CAbOorrZPJW-o1cdilhymg-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82F0E1956095; Wed, 17 Jul 2024 22:34:57 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.16.62]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BDFB1955D48; Wed, 17 Jul 2024 22:34:55 +0000 (UTC) From: Aaron Merey To: elfutils-devel@sourceware.org Cc: hsm2@rice.edu, johnmc@rice.edu, Aaron Merey , Mark Wielaard Subject: [PATCH 7/9 v2] libdw: Make libdw_findcu thread-safe Date: Wed, 17 Jul 2024 18:34:06 -0400 Message-ID: <20240717223409.1788719-8-amerey@redhat.com> In-Reply-To: <20240717223409.1788719-1-amerey@redhat.com> References: <20240717223409.1788719-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=-10.2 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, RCVD_IN_SBL_CSS, 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/libdw_findcu.c (__libdw_findcu): Use eu_tfind and dwarf_lock (__libdw_intern_next_unit): Use per-Dwarf_CU locks. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- v2 changes: Use per-Dwarf_CU lock instead of a global lock. libdw/libdw_findcu.c | 47 ++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c index 72cf261c..8acff448 100644 --- a/libdw/libdw_findcu.c +++ b/libdw/libdw_findcu.c @@ -177,6 +177,8 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types) newp->startp = data->d_buf + newp->start; 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) @@ -243,27 +245,38 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types) /* Maybe we already know that CU. */ struct Dwarf_CU fake = { .start = start, .end = 0 }; struct Dwarf_CU **found = eu_tfind (&fake, tree, findcu_cb); + struct Dwarf_CU *result = NULL; if (found != NULL) return *found; - if (start < *next_offset) - { - __libdw_seterrno (DWARF_E_INVALID_DWARF); - return NULL; - } + rwlock_wrlock (dbg->dwarf_lock); - /* No. Then read more CUs. */ - while (1) - { - struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, v4_debug_types); - if (newp == NULL) - return NULL; - - /* Is this the one we are looking for? */ - if (start < *next_offset || start == newp->start) - return newp; - } - /* NOTREACHED */ + if (start < *next_offset) + __libdw_seterrno (DWARF_E_INVALID_DWARF); + else + { + /* No. Then read more CUs. */ + while (1) + { + struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, + v4_debug_types); + if (newp == NULL) + { + result = NULL; + break; + } + + /* Is this the one we are looking for? */ + if (start < *next_offset || start == newp->start) + { + result = newp; + break; + } + } + } + + rwlock_unlock (dbg->dwarf_lock); + return result; } struct Dwarf_CU *