From patchwork Tue Mar 29 15:49:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DG94UFgd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KSYtl4YbCz9sFk for ; Wed, 30 Mar 2022 02:50:39 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtl3j90z2xfP for ; Wed, 30 Mar 2022 02:50:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DG94UFgd; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DG94UFgd; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4KSYth60yzz2yPT for ; Wed, 30 Mar 2022 02:50:36 +1100 (AEDT) Received: by mail-pj1-x102b.google.com with SMTP id jx9so17891193pjb.5 for ; Tue, 29 Mar 2022 08:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nVOLJb6QTwcEgAHI72cbLlI/IOugjAl6OzcnLkjMjAI=; b=DG94UFgdMfMPsSHV9HtRsqqZMdDGElfUvRwnpGP9AFlmIBEKr8SCT4kMT4vvNOZfYd 2TTjbjKs90DWuxKwF71SdKWq9yUV+qxo9I3w/66I+7I7rdAl625+yZy3CHY3s2/XRMfp lYOr2B8PDRVaArfYPUU77RuRGBRZeS/l8SQ4hGEGRvt49zRUTRjsUfeo+dwpb/9/64yu o4Xz7mg93Ad2J5W+nhK31a9qJHgwb5dyyj5zMxwqIIksQ0tKZUZNhdvPvmoXT9c+wBeV CQwkeQ2P06PKFo/PQLj6ccspSPNhx7LJYkXY7N6YNV8jQQON6CvOCDdWxhDJ0qyULUwT VHSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nVOLJb6QTwcEgAHI72cbLlI/IOugjAl6OzcnLkjMjAI=; b=0EVeCkgddgvtt/7ewoy9Lvq3EpAbrsyXzFuEVcGkh+hJPwbtSiYTyX6MJG5bp59nQk OifTprgQCj10JIaOhbAOw9zFP7XtsZ9ensF5IeUs1v11wpP8xknWP1UuO1f8RYE4R1uq lOybSm45Smd1Vfw/V3YR814KYsaqIZT6YavzBSLpnEJcx5No2NhvfgXx5wkJON+pQMMz 8r5PbpTdmuuOWW05pWkT4O16SnkNEx05cFb6rxvUxV8/HBV6HQxwtOyQv2ysSeIeysvn S3ooUYhWEoGGo1SM2tzpdB/Yevs8fzl6771qNREMunKLSVWvrWInA2CJ+Z7UzFeUK0qF OR6Q== X-Gm-Message-State: AOAM530RJBWj0RAKpdW5HAweBBpp9MiGpuHrNGE9adMmVRI8rSi4+A/q l2BFJPhPKXzgru832q04ybYT1ENQXjA= X-Google-Smtp-Source: ABdhPJxMnbhCZDPzm1enudRXVMXOdcTcbb0yGeGtlLvi94QbPux73awOe/SZepKLjalLf4Dc5/A5Ig== X-Received: by 2002:a17:90b:38d2:b0:1c7:1326:ec98 with SMTP id nn18-20020a17090b38d200b001c71326ec98mr252665pjb.18.1648569034547; Tue, 29 Mar 2022 08:50:34 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:34 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:19 +1000 Message-Id: <20220329154931.493851-27-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 26/38] gdbserver: track attn enablement by breakpoints X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" attn-enabled is a per-core property that host software (e.g., skiboot) may change. gdbserver should not disable attn if it was found to be enabled. There are still unavoidable races where the host could change between gdbserver wanting it enabled and disabled. This also moves set_attn to iterate all targets in preparation for multi-threaded debugging. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c5e439d..756feb5 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -54,6 +54,7 @@ static enum client_state state = IDLE; /* Attached to thread->gdbserver_priv */ struct gdb_thread { uint64_t pir; + bool attn_set; }; static void destroy_client(int dead_fd); @@ -116,39 +117,49 @@ static void detach(uint64_t *stack, void *priv) #define POWER10_HID_ENABLE_ATTN PPC_BIT(3) #define POWER10_HID_FLUSH_ICACHE PPC_BIT(2) -static int set_attn(bool enable) +static int thread_set_attn(struct pdbg_target *target, bool enable) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; uint64_t hid; - if (thread_getspr(thread_target, SPR_HID, &hid)) + if (!enable && !gdb_thread->attn_set) { + /* Don't clear attn if we didn't enable it */ + return 0; + } + + if (thread_getspr(target, SPR_HID, &hid)) return -1; - if (pdbg_target_compatible(thread_target, "ibm,power8-thread")) { + if (pdbg_target_compatible(target, "ibm,power8-thread")) { if (enable) { if (hid & POWER8_HID_ENABLE_ATTN) return 0; hid |= POWER8_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER8_HID_ENABLE_ATTN)) return 0; hid &= ~POWER8_HID_ENABLE_ATTN; } - } else if (pdbg_target_compatible(thread_target, "ibm,power9-thread")) { + } else if (pdbg_target_compatible(target, "ibm,power9-thread")) { if (enable) { if (hid & POWER9_HID_ENABLE_ATTN) return 0; hid |= POWER9_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER9_HID_ENABLE_ATTN)) return 0; hid &= ~POWER9_HID_ENABLE_ATTN; } hid |= POWER9_HID_FLUSH_ICACHE; - } else if (pdbg_target_compatible(thread_target, "ibm,power10-thread")) { + } else if (pdbg_target_compatible(target, "ibm,power10-thread")) { if (enable) { if (hid & POWER10_HID_ENABLE_ATTN) return 0; hid |= POWER10_HID_ENABLE_ATTN; + gdb_thread->attn_set = true; } else { if (!(hid & POWER10_HID_ENABLE_ATTN)) return 0; @@ -159,12 +170,29 @@ static int set_attn(bool enable) return -1; } - if (thread_putspr(thread_target, SPR_HID, hid)) + if (thread_putspr(target, SPR_HID, hid)) return -1; return 0; } +static int set_attn(bool enable) +{ + struct pdbg_target *target; + int err = 0; + + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + err = thread_set_attn(target, enable); + if (err) + break; + } + + return err; +} + /* 32 registers represented as 16 char hex numbers with null-termination */ #define REG_DATA_SIZE (32*16+1) static void get_gprs(uint64_t *stack, void *priv)