From patchwork Wed Apr 20 06:50:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619354 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=O5VxDD5J; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 4KjrtY48Nnz9sG0 for ; Wed, 20 Apr 2022 16:51:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtY327Xz2yn2 for ; Wed, 20 Apr 2022 16:51:33 +1000 (AEST) 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=O5VxDD5J; 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::1029; helo=mail-pj1-x1029.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=O5VxDD5J; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 4KjrtV5wvpz2xrv for ; Wed, 20 Apr 2022 16:51:30 +1000 (AEST) Received: by mail-pj1-x1029.google.com with SMTP id j8-20020a17090a060800b001cd4fb60dccso1159501pjj.2 for ; Tue, 19 Apr 2022 23:51:30 -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=OpNGnNkesvWC7X6J3CQoHsEQ77BKvlbvuMXrjHXhdc0=; b=O5VxDD5JgGlrV1XfLt8ihYnD2X8EUG30eYTh+oOUUr+Q2shKM2CFN0EW4VGPDVYIq3 BGiosSw38tgxrGNs9hLqrCRUeUsg4Z9VGZMnYewXpzQplkM+w17Ng43I26hZYqPzr8SF BLMHi2BydjY3LWgK1tZ5YR+Tg4fE2/rV2hKwC5iWErbL5W5Gjx55VpxTNwTNVFzCLTLB d8hRrXbQM/vBGHXw6igtnpkFRNu1LWUb6fD+6aJ3qEqQ2vCqRKF4NBQhyNIKZbQu6Qk6 ZUPsdkos0G+sxg2jUZwuLS1G2gL7rgu2MsL4OcWb5nLnWXqkYArV+n6vLocNAKSg0RCS IRnQ== 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=OpNGnNkesvWC7X6J3CQoHsEQ77BKvlbvuMXrjHXhdc0=; b=ybJyep/Nk5FDvOQUAn0lTLzTr61AtPh2JeFXQ2It2xVKRs07r0zEmu3luLzpxIr2Sb 1f/ZKbFjdYWbXlbL2PQbOOL/SVBCjy/RqSk96f6ZtoxjnXdkmrdRb9efxoenhqVifD/J OTCiAxo9UZSpQhWJaAh1tSCdM1Vow9d3d2hR3hIYWusX4Hd14kKToF+/F5nLxY5J9/hO DPT32FWSb5E6+fPQnC55dX2mKOPGDqLXL5h0v15Dts/5a+YetflT2l+xabR2GX1i+a5P o9QKTRM6u0KULGU5dPvafrqal8uSqE4DregOhSETFtILBIk2ILEsqWf5AP7NRlcyWAwl XV1w== X-Gm-Message-State: AOAM533IELEO+Gx2XAvUPRMoFvfIU43ct2S0y/vx5Vmp6w6yV0rqodle h4ja/JfOqdziAXZoJwYegXDCYk067fgT3Q== X-Google-Smtp-Source: ABdhPJxf0ZqZvnS+ekKO3i09lnsa2t75RPYni2cRn9VCu30Yd8c/JhXurFhj+X3pZaGvrLjkiD2TyA== X-Received: by 2002:a17:902:cacb:b0:158:694f:23ff with SMTP id y11-20020a170902cacb00b00158694f23ffmr19418574pld.119.1650437487656; Tue, 19 Apr 2022 23:51:27 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:27 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:01 +1000 Message-Id: <20220420065013.222816-28-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 27/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index b8ee2a06..d0da1f37 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)