From patchwork Wed Apr 20 06:49:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619349 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=peUIapYf; 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 4KjrtK0BnHz9sG0 for ; Wed, 20 Apr 2022 16:51:21 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtJ68fQz30BN for ; Wed, 20 Apr 2022 16:51:20 +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=peUIapYf; 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::434; helo=mail-pf1-x434.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=peUIapYf; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 4KjrtG5qhxz2yjS for ; Wed, 20 Apr 2022 16:51:18 +1000 (AEST) Received: by mail-pf1-x434.google.com with SMTP id a15so1075487pfv.11 for ; Tue, 19 Apr 2022 23:51:18 -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=U7rAf3Li/Y/CSPmM29+PsAgSOnr5cCqKx+EL6tAbx2o=; b=peUIapYf9H0GKEAIVfkqm1u8A4Tv0bxEw2OALvHIqKA8MVjSjI1y6v6qJnMllzseqX 0CucwZ3Ett6njCW5qh7+tTcTuiwBTKlq3zY17ygTeuo2U03+G3o25MSyTB8Y9DJ4bf3H IlK0nEx1tL558IBUH8pUQMijyyZQU8Ag03269tnO4lfSz4aaBYPC6cSwucspvu0HMr8j OxH3BeuiEWb0PB/Rwcy8VWy033G1Dsn0HKwNZHv1FeyokeQLlXsdZvGraTaD7c2t+8WO CDLOvYxMshLJhc40jcT2LadP9kn2/tc3cu60KUKhDxWpXvgAIc2v2aF56iavS+X/Em9k ezpQ== 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=U7rAf3Li/Y/CSPmM29+PsAgSOnr5cCqKx+EL6tAbx2o=; b=bQyv5xzpegaiCqdQzac9b0xC9SkAUsExDrm32U+avSV3AMnoqP6BIgv4Hzj7xX7pXM xLQYB6gJJlmd0zNv3fhS7eWrlII3WowYwmdKZVRXbNdcOvpo9pU72Cdlm/n43ltZD65J jCXTaG/rPLjynMKaKwSoMw7wDkCfsKdmzm1TSSPB0PiGWqR5uRSZFgyH5Xyr2fSg/AAD /HqQit6QZ3V1/iXRUyKGinc8XOjuMKZy+K6n4mMAuKEO9ySbm9+KC62DIJroKofQeZ+S 7A40TeLkWJTccNgpDF8AdJJeeSAd5cHwLKTIA3MrqMzRDf8hwiGgu1fiVe5wFWMFWd7k o7SQ== X-Gm-Message-State: AOAM531hwxsKgGPOpik5fd4RDKB+Zx+5FNe0C5ftsYjmR5Fpushrxx+p 2GyR3dYaeqPudtqU1kCdZcfKmpfHezhaAw== X-Google-Smtp-Source: ABdhPJzp6M9DEgaOaWr8/W5N+Q9QbNzxG1LykFcJRD1sLrQJURxLXF5A9AVVaDd/vTgnZyZG+YUHYg== X-Received: by 2002:a62:fb0f:0:b0:4f2:6d3f:5ffb with SMTP id x15-20020a62fb0f000000b004f26d3f5ffbmr21524240pfm.55.1650437476434; Tue, 19 Apr 2022 23:51:16 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:16 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:56 +1000 Message-Id: <20220420065013.222816-23-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 22/39] gdbserver: check for attn using the SPATTN register 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" When POWER9/10 execute an attn instruction, they set a bit in the SPATTN register and quiesce the thread. This bit can be checked to confirm the thread hit an attn instruction, rather than assuming a thread was quiesced because of attn. This makes the gdb breakpoint code more robust in the presence of other direct controls (e.g., host-based direct controls from OPAL). This change also clears the SPATTN bit which clears the exception condition that raises the IPOLL global interrupt. That interrupt seems to be involved with the IPOLL interrupt storm and lock-up on POWER9 (although this does not fix it). Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 79 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 23971c25..d7ceac8d 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -457,6 +457,59 @@ static void v_contc(uint64_t *stack, void *priv) poll_interval = 1; } +#define P9_SPATTN_AND 0x20010A98 +#define P9_SPATTN 0x20010A99 + +#define P10_SPATTN_AND 0x20028498 +#define P10_SPATTN 0x20028499 + +static bool thread_check_attn(struct pdbg_target *target) +{ + struct thread *thread = target_to_thread(target); + struct pdbg_target *core; + uint64_t spattn; + + if (pdbg_target_compatible(target, "ibm,power8-thread")) { + return true; /* XXX */ + } else if (pdbg_target_compatible(target, "ibm,power9-thread")) { + core = pdbg_target_require_parent("core", target); + if (pib_read(core, P9_SPATTN, &spattn)) { + PR_ERROR("SPATTN read failed\n"); + return false; + } + + if (spattn & PPC_BIT(1 + 4*thread->id)) { + uint64_t mask = ~PPC_BIT(1 + 4*thread->id); + + if (pib_write(core, P9_SPATTN_AND, mask)) { + PR_ERROR("SPATTN clear failed\n"); + return false; + } + + return true; + } + } else if (pdbg_target_compatible(target, "ibm,power10-thread")) { + core = pdbg_target_require_parent("core", target); + if (pib_read(core, P10_SPATTN, &spattn)) { + PR_ERROR("SPATTN read failed\n"); + return false; + } + + if (spattn & PPC_BIT(1 + 4*thread->id)) { + uint64_t mask = ~PPC_BIT(1 + 4*thread->id); + + if (pib_write(core, P10_SPATTN_AND, mask)) { + PR_ERROR("SPATTN clear failed\n"); + return false; + } + + return true; + } + } + + return false; +} + static void interrupt(uint64_t *stack, void *priv) { struct thread_state status; @@ -477,7 +530,6 @@ static void interrupt(uint64_t *stack, void *priv) static void poll(void) { - uint64_t nia; struct thread_state status; thread_target->probe(thread_target); @@ -495,17 +547,22 @@ static void poll(void) state = IDLE; poll_interval = VCONT_POLL_DELAY; - if (!(status.active)) { - PR_ERROR("Thread inactive after trap\n"); - send_response(fd, ERROR(EPERM)); - return; - } - /* Restore NIA */ - if (thread_getnia(thread_target, &nia)) - PR_ERROR("Error during getnia\n"); - if (thread_putnia(thread_target, nia - 4)) - PR_ERROR("Error during putnia\n"); + if (thread_check_attn(thread_target)) { + uint64_t nia; + + if (!(status.active)) { + PR_ERROR("Thread inactive after trap\n"); + send_response(fd, ERROR(EPERM)); + return; + } + + /* Restore NIA */ + if (thread_getnia(thread_target, &nia)) + PR_ERROR("Error during getnia\n"); + if (thread_putnia(thread_target, nia - 4)) + PR_ERROR("Error during putnia\n"); + } send_response(fd, TRAP); break; }