From patchwork Tue Mar 29 15:49:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610703 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=Xcd8UqJ8; 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 4KSYtY4DSvz9sFk for ; Wed, 30 Mar 2022 02:50:29 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtY38Vxz2xYG for ; Wed, 30 Mar 2022 02:50:29 +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=Xcd8UqJ8; 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=Xcd8UqJ8; 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 4KSYtW0DRJz2xt7 for ; Wed, 30 Mar 2022 02:50:26 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so2253077pjb.3 for ; Tue, 29 Mar 2022 08:50:26 -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=TZa7tBfB6PQSoqJPKL7ERqHT9SJ+2kyqJnETyyxcFCw=; b=Xcd8UqJ8CjJhfTRFoooAANwjvIkC5gy/o0hGe7ENDZXz4smZorMf3eOPUIM6OvzMIY 2oKWZvc2PGC1GmD1ORHC6S2UZtT1pqDTN/IubiBpZbHWgA2L3JIGOlu7j1JsvFUC6L2A yyYem3G5qkKjFpuOiK6ROUQmeeZtM2Dv1m3SdGYlisI7X2pgtfA/GWiwZIBn+lhfXoVj 6R4Uvr9497Rjnk5UhLwxyC+7eanvMQXL/IRBkMBvCZnxG3U75r7018SZLSghbIB1L6Td Gy5JTxMIHVRbe5VvfupfoU2V+FgjCAsMFXulHCpl5lSaXvFwGIHgs3F6OnemQgJz17uI MpTA== 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=TZa7tBfB6PQSoqJPKL7ERqHT9SJ+2kyqJnETyyxcFCw=; b=7BZ1tBElXb4DNvOarb29KjsLhP23QyJ77EKHtU9PK1MrPCNBXUl+eM1ZOj8hY9x7Wh kfMbdzJAl3YyTvvnohn5ldpi1j70f5N0htgD/9Wr3tBwYur0GeAXikMPJ9v+Zl4WsxlU wbFXp87VhQ1LnUC5EJCwubG3dnmF9/QTZ/rdNY1WAAHCUE2wkV+jHkljoHhTEOCx6PSZ O0ylctHfny+JlMfqMn3aHVDxhrgrpR59CepomEf4GAP8568EG75qgtZyaTTsZwpoUh3M YcVurX/q5+/2Ru8e0QOEoUhpK05fN24FVtSUuU4ZzpCc+p4A1LjokkpJ3I0VTdGLqHiQ riuQ== X-Gm-Message-State: AOAM532IRtPApVNJGKC6s8eyozHr48pwu/Y7Z3nPSIseAHQKzK6yRk/6 l6qAzbYnzQUXrkg69wydmRCNuAXzXY0= X-Google-Smtp-Source: ABdhPJwPqqJ3bCF639vCcE++tseXABEygNx3qc+kh0QJhv8dTMEaLc1h68sj3Oqjg6N3pciuU3z0lQ== X-Received: by 2002:a17:903:3051:b0:156:2d03:3434 with SMTP id u17-20020a170903305100b001562d033434mr3829941pla.101.1648569024959; Tue, 29 Mar 2022 08:50:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:24 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:14 +1000 Message-Id: <20220329154931.493851-22-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 21/38] 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 instruction and quiesce the thread. This bit can be checked to confirm the thread hit an attn instruction, rather than assuming based on the thread being quiesced. This also clears the SPATTN bit which clears the exception condition that seems to be involved with the IPOLL interrupt storm and lock up (although this does not fix POWER9). Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 79 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index eddf813..1843517 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; }