From patchwork Sun Oct 22 14:42:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13431843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EED17C001DF for ; Sun, 22 Oct 2023 14:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NiLj2N9dQPbKThAOyGlEB5re4limYELBQftKgpsHx5Q=; b=gnlV3gJXVgZWQ/ 2ACKPIKp48HqWoT4xFLNXccWHKShyBNloFD165ICx5OIy/4WvJWGAj8pWwzM+ULPuA+TYJ7PfBEs9 ZQ9jKhcg0DqCOLuYRWeKMG5LAioOfuE/bbEACD97YsD1LV0g8/y5gmcBFlAS1bNxrOSMS0R5KyLdu O/yjZEfSK0hhzc5vYJLKfYNR9XNozVU7shHnVLI4xVs5RnEtKqiPabzGYvOCS9EbH3NpnmQfXH2+P WbQ7oRxtZWsTneAhFPMrkRLuzfezW7BNbjvqxBOyBS35FugBcRh0bZhyf473YHszHBmhaKzMN6Vhv 26sMyqIb+/g6dH2Es3pA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1quZf0-005ZDB-1t; Sun, 22 Oct 2023 14:42:34 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1quZex-005ZCU-1X for linux-arm-kernel@lists.infradead.org; Sun, 22 Oct 2023 14:42:33 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c50d1b9f22so32423341fa.0 for ; Sun, 22 Oct 2023 07:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697985748; x=1698590548; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=i2jxN58Rd50B5qNlzzl+HgDNo1YZPDCqE37ZPo/QrR8=; b=W2NQFze/0Ey5zUwPSiBuQyyJvNirJ0HZCWg8Hhpz35qI5MTnMllqRTPGc/tek7IY+L QzzDJvoCs53qoQV+Rm5C05osn7/s2sg4xybR8RUgs3Nr7tg/DaTVMrmbpa1TkkGfsbvK zHKusX+Ov1siicmEtQAwZ8HJKzUQB6f1DK/056pl352oX0AhZiQ9VWB60HGtlu3GnsKJ 5TxrMI5Fy+CUu7jJgdff1k+BsWSs6UlJ297eZUQF011BSnGD13Z32ApLmvoUo0GBnPmr bxwqkSO59EErB39OzPZ7byLNN2NDg1dtKVw3sdoINXDkYhHQHQHHOm/4gb9NYKEm34JB +2nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697985748; x=1698590548; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i2jxN58Rd50B5qNlzzl+HgDNo1YZPDCqE37ZPo/QrR8=; b=EPbm+TeoJVmGkgnYVnEAuTrS5HabOONOgPNWiyCCunVVyubUcxlZjdU3WAlFa5KTCT cK8A96rP/pRelnxuzbJqAmijIfDTTbVSg6tmqT7JeKyLu1GBapF3KynGlUObBvIP2aHA QoYWRdY9gvXF2G7Vj4y2ABSf3mGpBh9IPCY9fs8hgIrlWRnfFKYvPeH+V/IGju9E1e64 RaE8jQgDmSIO1lCqP49I0ysRMXtfAd2Iqy5HiQKMcM4qw7icz92fP8ZxbOEzac8TLmcm T+bnuHKWbvf2pS5143GV7TsJwkP8bUzAaq+3lC7wTniPfhnii3qVlWV9Ths8mQm1flTR gH2Q== X-Gm-Message-State: AOJu0Yz4WijdzGsDm5/dZ2P8UZIPd4ps+dRjmZDlB/vFFbcrk3uiSKLA SCFn257mwbVl3atuBHWuO855KA== X-Google-Smtp-Source: AGHT+IF4DjTi8VI5kLF6HbYNHbRd4ens1x/g/+IRCor29hYZcgSeulBALYpy478UxCsdxjTinUPj5w== X-Received: by 2002:a05:651c:1025:b0:2c0:1bf9:3c94 with SMTP id w5-20020a05651c102500b002c01bf93c94mr4262023ljm.50.1697985748380; Sun, 22 Oct 2023 07:42:28 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id iv15-20020a05600c548f00b00405c7591b09sm7115935wmb.35.2023.10.22.07.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 07:42:27 -0700 (PDT) From: Alexandre Ghiti To: Atish Patra , Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Jones , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH -fixes] drivers: perf: Do not broadcast to other cpus when starting a counter Date: Sun, 22 Oct 2023 16:42:20 +0200 Message-Id: <20231022144220.109469-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231022_074231_737459_8B0B6D61 X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This command: $ perf record -e cycles:k -e instructions:k -c 10000 -m 64M dd if=/dev/zero of=/dev/null count=1000 gives rise to this kernel warning: [ 444.364395] WARNING: CPU: 0 PID: 104 at kernel/smp.c:775 smp_call_function_many_cond+0x42c/0x436 [ 444.364515] Modules linked in: [ 444.364657] CPU: 0 PID: 104 Comm: perf-exec Not tainted 6.6.0-rc6-00051-g391df82e8ec3-dirty #73 [ 444.364771] Hardware name: riscv-virtio,qemu (DT) [ 444.364868] epc : smp_call_function_many_cond+0x42c/0x436 [ 444.364917] ra : on_each_cpu_cond_mask+0x20/0x32 [ 444.364948] epc : ffffffff8009f9e0 ra : ffffffff8009fa5a sp : ff20000000003800 [ 444.364966] gp : ffffffff81500aa0 tp : ff60000002b83000 t0 : ff200000000038c0 [ 444.364982] t1 : ffffffff815021f0 t2 : 000000000000001f s0 : ff200000000038b0 [ 444.364998] s1 : ff60000002c54d98 a0 : ff60000002a73940 a1 : 0000000000000000 [ 444.365013] a2 : 0000000000000000 a3 : 0000000000000003 a4 : 0000000000000100 [ 444.365029] a5 : 0000000000010100 a6 : 0000000000f00000 a7 : 0000000000000000 [ 444.365044] s2 : 0000000000000000 s3 : ffffffffffffffff s4 : ff60000002c54d98 [ 444.365060] s5 : ffffffff81539610 s6 : ffffffff80c20c48 s7 : 0000000000000000 [ 444.365075] s8 : 0000000000000000 s9 : 0000000000000001 s10: 0000000000000001 [ 444.365090] s11: ffffffff80099394 t3 : 0000000000000003 t4 : 00000000eac0c6e6 [ 444.365104] t5 : 0000000400000000 t6 : ff60000002e010d0 [ 444.365120] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003 [ 444.365226] [] smp_call_function_many_cond+0x42c/0x436 [ 444.365295] [] on_each_cpu_cond_mask+0x20/0x32 [ 444.365311] [] pmu_sbi_ctr_start+0x7a/0xaa [ 444.365327] [] riscv_pmu_start+0x48/0x66 [ 444.365339] [] perf_adjust_freq_unthr_context+0x196/0x1ac [ 444.365356] [] perf_event_task_tick+0x78/0x8c [ 444.365368] [] scheduler_tick+0xe6/0x25e [ 444.365383] [] update_process_times+0x80/0x96 [ 444.365398] [] tick_sched_handle+0x26/0x52 [ 444.365410] [] tick_sched_timer+0x50/0x98 [ 444.365422] [] __hrtimer_run_queues+0x126/0x18a [ 444.365433] [] hrtimer_interrupt+0xce/0x1da [ 444.365444] [] riscv_timer_interrupt+0x30/0x3a [ 444.365457] [] handle_percpu_devid_irq+0x80/0x114 [ 444.365470] [] generic_handle_domain_irq+0x1c/0x2a [ 444.365483] [] riscv_intc_irq+0x2e/0x46 [ 444.365497] [] handle_riscv_irq+0x4a/0x74 [ 444.365521] [] do_irq+0x7c/0x7e [ 444.365796] ---[ end trace 0000000000000000 ]--- That's because the fix in commit 3fec323339a4 ("drivers: perf: Fix panic in riscv SBI mmap support") was wrong since there is no need to broadcast to other cpus when starting a counter, that's only needed in mmap when the counters could have already been started on other cpus, so simply remove this broadcast. Fixes: 3fec323339a4 ("drivers: perf: Fix panic in riscv SBI mmap support") Signed-off-by: Alexandre Ghiti Tested-by: Clément Léger Tested-by: Yu Chien Peter Lin --- drivers/perf/riscv_pmu_sbi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 96c7f670c8f0..439da49dd0a9 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -543,8 +543,7 @@ static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival) if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - on_each_cpu_mask(mm_cpumask(event->owner->mm), - pmu_sbi_set_scounteren, (void *)event, 1); + pmu_sbi_set_scounteren((void *)event); } static void pmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) @@ -554,8 +553,7 @@ static void pmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - on_each_cpu_mask(mm_cpumask(event->owner->mm), - pmu_sbi_reset_scounteren, (void *)event, 1); + pmu_sbi_set_scounteren((void *)event); ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, hwc->idx, 1, flag, 0, 0, 0); if (ret.error && (ret.error != SBI_ERR_ALREADY_STOPPED) &&