From patchwork Sat May 8 10:14:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1475833 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org 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=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VETU5Pmg; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Fcjt46lNZz9sX1 for ; Sat, 8 May 2021 20:17:16 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Fcjt46Pjyz3cCc for ; Sat, 8 May 2021 20:17:16 +1000 (AEST) 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=20161025 header.b=VETU5Pmg; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1032; helo=mail-pj1-x1032.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=20161025 header.b=VETU5Pmg; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 4Fcjqn5zKJz2yxn for ; Sat, 8 May 2021 20:15:17 +1000 (AEST) Received: by mail-pj1-x1032.google.com with SMTP id l10-20020a17090a850ab0290155b06f6267so6812481pjn.5 for ; Sat, 08 May 2021 03:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ptlMcBDWcssXFzxYZbffEn+kF4lLgbECIyuV9dbqyUE=; b=VETU5PmgWqPT9wkHQwd2cTDCqWo/komATP7v841czInCv+jgXK0cxYzc1EmPQaDAmU M5uFfIdTq2p4oMqoTl6nsMpcFWsBrnqgA8vWEJvRKGMS+WS4UgUtwGbzLaqLVBwmOBxn dSMcb+bSuDUJSbNOzHADwXa6wn0pRzC/sWKaBjPz3cg8HseEwoPzMV501BL4n7EG8eVR xYUNq0s+bMJTZrdp6eyEVgq0s2a/oXEIUduB5pxRNbIglEfHGAo6gRaptrxNp4DyYv1n 331uk4ps6cnXJ4QuGtoBa07VydHdz+3xzbcPTU+6OGLj7jZuXP4npKIx+thQL1S3jlIt tbtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ptlMcBDWcssXFzxYZbffEn+kF4lLgbECIyuV9dbqyUE=; b=RPbr7+J8YKQv5VuLt+wYhZSxkhFwGdsVa1n3zDi0Pg78eHrA2V+oKWz/8pYw3sIMk6 72BPyYeX/BUcQoDs+y/br7qq/J4VMS1CRk+6CSm7f33K0bImNFB9pH0VXBGvB++1U6Vl yuaiY8DdnNpBPxZz4jNipo5NtWV/aDIOyWuWOXLbM6I+G6OWvqU/MzU4OLffaX5Qj6wk F7ri+HhNomq3JztyIoysBVNTdkywf+vy3zKfWaCBMU8HR7Z5CjVLD7Fj4V56iCk67Kqc cGsNI4spqW2BpH3Sb5qQwYdL6YflPVU4A0/gsAFOwwRvJl6QBxD4J/Y0Xlw8D774oTdJ hSuw== X-Gm-Message-State: AOAM532GJqwsA2PTZ8WZQZHG5qpvxSdObwJ+2j9svBejZsxgUNdRdird qhxa4iXQmV4CaBtw3gIBkQPtKfe7FRABTQ== X-Google-Smtp-Source: ABdhPJxBxbxD102H8yGDvvJLFY48fiTDQmiaSWB9TXOBd+4NEVv8dQlQH946DbbDkGEmjJiGVC2c0w== X-Received: by 2002:a17:902:b487:b029:ee:d04b:741e with SMTP id y7-20020a170902b487b02900eed04b741emr14293651plr.45.1620468915047; Sat, 08 May 2021 03:15:15 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (60-241-47-46.tpgi.com.au. [60.241.47.46]) by smtp.gmail.com with ESMTPSA id c13sm6608465pfl.212.2021.05.08.03.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 May 2021 03:15:14 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 4/4] powerpc/pseries: warn if recursing into the hcall tracing code Date: Sat, 8 May 2021 20:14:55 +1000 Message-Id: <20210508101455.1578318-5-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210508101455.1578318-1-npiggin@gmail.com> References: <20210508101455.1578318-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The hcall tracing code has a recursion check built in, which skips tracing if we are already tracing an hcall. However if the tracing code has problems with recursion, this check may not catch all cases because the tracing code could be invoked from a different tracepoint first, then make an hcall that gets traced, then recurse. Add an explicit warning if recursion is detected here, which might help to notice tracing code making hcalls. Really the core trace code should have its own recursion checking and warnings though. Signed-off-by: Nicholas Piggin --- arch/powerpc/platforms/pseries/lpar.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c index ad1cec80019b..dab356e3ff87 100644 --- a/arch/powerpc/platforms/pseries/lpar.c +++ b/arch/powerpc/platforms/pseries/lpar.c @@ -1829,8 +1829,14 @@ void hcall_tracepoint_unregfunc(void) #endif /* - * Since the tracing code might execute hcalls we need to guard against - * recursion. + * Keep track of hcall tracing depth and prevent recursion. Warn if any is + * detected because it may indicate a problem. This will not catch all + * problems with tracing code making hcalls, because the tracing might have + * been invoked from a non-hcall, so the first hcall could recurse into it + * without warning here, but this better than nothing. + * + * Hcalls with specific problems being traced should use the _notrace + * plpar_hcall variants. */ static DEFINE_PER_CPU(unsigned int, hcall_trace_depth); @@ -1844,7 +1850,7 @@ notrace void __trace_hcall_entry(unsigned long opcode, unsigned long *args) depth = this_cpu_ptr(&hcall_trace_depth); - if (*depth) + if (WARN_ON_ONCE(*depth)) goto out; (*depth)++; @@ -1865,7 +1871,7 @@ notrace void __trace_hcall_exit(long opcode, long retval, unsigned long *retbuf) depth = this_cpu_ptr(&hcall_trace_depth); - if (*depth) + if (*depth) /* Don't warn again on the way out */ goto out; (*depth)++;