Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp374498rdb; Fri, 6 Oct 2023 06:16:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0H2cMDNlAUxWW6FapU9d7tJp+AeYiNHGmE7DOWdtsJmDSIsp/g7vbnOk2ITi3mhNdZmCG X-Received: by 2002:a6b:4403:0:b0:790:fc73:6e3c with SMTP id r3-20020a6b4403000000b00790fc736e3cmr8121749ioa.8.1696598212270; Fri, 06 Oct 2023 06:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696598212; cv=none; d=google.com; s=arc-20160816; b=xwr77dryzQ8BDx341+/aRz7qTUEzjXDvAj/PkYLFT9WxSHte25pmFQKB2Vj0o5FDC+ NBpDJaNTPp7qxPQRDYLMx0rvQs05ypIrmBF2PfAWUK5mKspCi2DfzuDdafGxI0pz38pv dNCYSu78R719pSnb8S5C1FuXCWly4EMjZzsuzH8vshJPW97dTVyfczhoFzJoYrTaquF4 QLSspYAdx7RquAgyhzVG3KOgxp7v2Mx1MR0Wyz//KzdE22FAdK/hvT45lU+eMoZdGJ0d HukOTI4YtwohdGaI2RrrAm6uOLdiFtrV4pokgLOM6mtM596gdkUctNOjOdQM1xT8Fa1b ik/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uXtzZtxgo28S1fLP8EaHGVjBByMpJbxTP1IQrzS3j2w=; fh=4+OZBTxssDa7xFX2bq/xgarF3cRi6RymsyQexOHF9Bs=; b=oa8H59n4Jdjtkq+FqjtzcSIlbOH2S7deAJIR2a9/qoQDOq5SAv5v4rV4cxshGuDEHD D7OPevMhVcfKICh93OJHD77s0ERCiB9RFO55uDts+QZQ7xrrxil1dMAu8GhiwchMuRLq up2HFf+9EteCgN9W2rNYK2nwGr4k9z/6vhpiF1vAl5PyArpQPHoh6fX13E/SzgknYYlX v22Z0+5Q4oTaCKtvOLmWM5Z3EVAp5whz+MJbP3FXcpA6+YDo9XLg/fg+/cHiOl9PuxXz 3zJ/cYmWT92zHtm5abltiIyDDNywCbl/dbZMxd6xy5Z5M3lMzLhh+7NRBsOry2KHESzU Zo1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i188-20020a639dc5000000b0058a09ed5ca2si620906pgd.313.2023.10.06.06.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 370F58233671; Fri, 6 Oct 2023 06:16:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjJFNPp (ORCPT + 99 others); Fri, 6 Oct 2023 09:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbjJFNPn (ORCPT ); Fri, 6 Oct 2023 09:15:43 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3AE5A9E for ; Fri, 6 Oct 2023 06:15:42 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 26F10C15; Fri, 6 Oct 2023 06:16:21 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 95A053F641; Fri, 6 Oct 2023 06:15:40 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, hejunhao3@huawei.com, suzuki.poulose@arm.com Cc: James Clark , Mike Leach , Leo Yan , Alexander Shishkin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] coresight: Fix crash when Perf and sysfs modes are used concurrently Date: Fri, 6 Oct 2023 14:14:52 +0100 Message-Id: <20231006131452.646721-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 06 Oct 2023 06:16:28 -0700 (PDT) X-Spam-Level: ** Partially revert the change in commit 6148652807ba ("coresight: Enable and disable helper devices adjacent to the path") which changed the bare call from source_ops(csdev)->enable() to coresight_enable_source() for Perf sessions. It was missed that coresight_enable_source() is specifically for the sysfs interface, rather than being a generic call. This interferes with the sysfs reference counting to cause the following crash: $ perf record -e cs_etm/@tmc_etr0/ -C 0 & $ echo 1 > /sys/bus/coresight/devices/tmc_etr0/enable_sink $ echo 1 > /sys/bus/coresight/devices/etm0/enable_source $ echo 0 > /sys/bus/coresight/devices/etm0/enable_source Unable to handle kernel NULL pointer dereference at virtual address 00000000000001d0 Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP ... Call trace: etm4_disable+0x54/0x150 [coresight_etm4x] coresight_disable_source+0x6c/0x98 [coresight] coresight_disable+0x74/0x1c0 [coresight] enable_source_store+0x88/0xa0 [coresight] dev_attr_store+0x20/0x40 sysfs_kf_write+0x4c/0x68 kernfs_fop_write_iter+0x120/0x1b8 vfs_write+0x2dc/0x3b0 ksys_write+0x70/0x108 __arm64_sys_write+0x24/0x38 invoke_syscall+0x50/0x128 el0_svc_common.constprop.0+0x104/0x130 do_el0_svc+0x40/0xb8 el0_svc+0x2c/0xb8 el0t_64_sync_handler+0xc0/0xc8 el0t_64_sync+0x1a4/0x1a8 Code: d53cd042 91002000 b9402a81 b8626800 (f940ead5) ---[ end trace 0000000000000000 ]--- This commit linked below also fixes the issue, but has unlocked updates to the mode which could potentially race. So until we come up with a more complete solution that takes all locking and interaction between both modes into account, just revert back to the old behavior for Perf. Reported-by: Junhao He Closes: https://lore.kernel.org/linux-arm-kernel/20230921132904.60996-1-hejunhao3@huawei.com/ Fixes: 6148652807ba ("coresight: Enable and disable helper devices adjacent to the path") Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 5ca6278baff4..89e8ed214ea4 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -493,7 +493,7 @@ static void etm_event_start(struct perf_event *event, int flags) goto fail_end_stop; /* Finally enable the tracer */ - if (coresight_enable_source(csdev, CS_MODE_PERF, event)) + if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF)) goto fail_disable_path; /* @@ -587,7 +587,7 @@ static void etm_event_stop(struct perf_event *event, int mode) return; /* stop tracer */ - coresight_disable_source(csdev, event); + source_ops(csdev)->disable(csdev, event); /* tell the core */ event->hw.state = PERF_HES_STOPPED; -- 2.34.1