From patchwork Thu Jun 6 16:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 165990 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp8996646ili; Thu, 6 Jun 2019 09:17:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqywQ2Gu6m3L6lvDcdWQyBsUTkGF3fmF1Ox91j+c+DYyizvRmCgnzxgBPbuYO3lXattHWFbr X-Received: by 2002:a17:902:683:: with SMTP id 3mr47273681plh.209.1559837831920; Thu, 06 Jun 2019 09:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559837831; cv=none; d=google.com; s=arc-20160816; b=gf7SaFr55G8nS/4Ty1NAJYA85TZzThHvMMv4VJgiSyuALFdDXbApC6TThLtfrklB1o VpDGfYtAtMCJhOHMFapy3og+I1xKcf6Iv5EOPV8sC3DJXOOJzbueBXVJs8feZl/TsB/f Kzztp3s7wjgAwj/N4KmxPxycdbGn98zSgVbiZVl2VVxt6jNboczb95wYdLYMtrVo+X6u FsE+BhtGfeTU1aydgHijZomrKdvdzuRcgHDM1NBeY/Ui+DmWGYfT3PGq9MsYEdQGS4XE GMP7Mkr20lhfc0bVVUnf2lmBBAdb31teYhf4sUoeU6glfgzT+wzVQd8KuasqkIVuFNBA P1lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=W3p6RjEG4T7iSJaKvzxBU/iw9Jcv6YhV0XwlGYcoRMA=; b=RVv+2hEMkAQ+jtS/UzmtfWdc3bmJpZy82JduqBYni88Buc6qkUx4X2CIEX9OTk7LJD 1Afb+Oe9AJgEYZLQS3PnuLTM0PtjeqWC6ZAPvDdXgyy/r0vXCkF1M0oIR7Wn0oNJLqX2 luIjB41YJwkmZtTblZ7ll7rzbChGJloY3Eg3vb/M9C0btk+PZc2lx3NSwfXooEtp4CQv mu3cZdtdldaanykeWaFa6CI3UPPqzFlpz3J/UqOEqaRu1BYbHQytiEQojBJ3pZZAmHyc lb+LGMZhvwdEoVEQzO666xn1DuAgUs1Jeo6gHPG7551VC76inx8Nqn41lyOJ2YHNvmxE MjWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10si2382097pfj.93.2019.06.06.09.17.11; Thu, 06 Jun 2019 09:17:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729717AbfFFQRK (ORCPT + 30 others); Thu, 6 Jun 2019 12:17:10 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:49834 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729681AbfFFQRD (ORCPT ); Thu, 6 Jun 2019 12:17:03 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6373F15BF; Thu, 6 Jun 2019 09:17:03 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.196.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 776EA3F690; Thu, 6 Jun 2019 09:17:02 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, Suzuki K Poulose Subject: [PATCH v4 3/4] coresight: tmc-etf: Do not call smp_processor_id from preemptible Date: Thu, 6 Jun 2019 17:16:46 +0100 Message-Id: <1559837807-15447-4-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559837807-15447-1-git-send-email-suzuki.poulose@arm.com> References: <1559837807-15447-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During a perf session we try to allocate buffers on the "node" associated with the CPU the event is bound to. If it is not bound to a CPU, we use the current CPU node, using smp_processor_id(). However this is unsafe in a pre-emptible context and could generate the splats as below : BUG: using smp_processor_id() in preemptible [00000000] code: perf/2544 caller is tmc_alloc_etf_buffer+0x5c/0x60 CPU: 2 PID: 2544 Comm: perf Not tainted 5.1.0-rc6-147786-g116841e #344 Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform, BIOS EDK II Feb 1 2019 Call trace: dump_backtrace+0x0/0x150 show_stack+0x14/0x20 dump_stack+0x9c/0xc4 debug_smp_processor_id+0x10c/0x110 tmc_alloc_etf_buffer+0x5c/0x60 etm_setup_aux+0x1c4/0x230 rb_alloc_aux+0x1b8/0x2b8 perf_mmap+0x35c/0x478 mmap_region+0x34c/0x4f0 do_mmap+0x2d8/0x418 vm_mmap_pgoff+0xd0/0xf8 ksys_mmap_pgoff+0x88/0xf8 __arm64_sys_mmap+0x28/0x38 el0_svc_handler+0xd8/0x138 el0_svc+0x8/0xc Use NUMA_NO_NODE hint instead of using the current node for events not bound to CPUs. Fixes: 2e499bbc1a929ac ("coresight: tmc: implementing TMC-ETF AUX space API") Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-tmc-etf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index b89e29c..23b7ff0 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -377,12 +377,10 @@ static void *tmc_alloc_etf_buffer(struct coresight_device *csdev, struct perf_event *event, void **pages, int nr_pages, bool overwrite) { - int node, cpu = event->cpu; + int node; struct cs_buffers *buf; - if (cpu == -1) - cpu = smp_processor_id(); - node = cpu_to_node(cpu); + node = (event->cpu == -1) ? NUMA_NO_NODE : cpu_to_node(event->cpu); /* Allocate memory structure for interaction with Perf */ buf = kzalloc_node(sizeof(struct cs_buffers), GFP_KERNEL, node);