Message ID | 20240227170002.188671-1-vadim.shakirov@syntacore.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2885004dyb; Tue, 27 Feb 2024 10:25:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUeOIEllmof9khV03Fui1OL4d9Ys/uIpgjKf9xcrLQ5b49D2gO0sTmWNc4s2qZ2PMj3HhigLT7jgAhUctTvYR7F0SpAzg== X-Google-Smtp-Source: AGHT+IECwtsPDKRFc3sd2NnKGitw9D7/u4mNuXboRJqbpKKcHw7rQ09IqbJoYtaq7hXirbQQjSui X-Received: by 2002:a05:6a00:4403:b0:6e5:265:fd38 with SMTP id br3-20020a056a00440300b006e50265fd38mr12821465pfb.18.1709058335627; Tue, 27 Feb 2024 10:25:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709058335; cv=pass; d=google.com; s=arc-20160816; b=Le19MpSHLA+pnEAvEztDy/DkRqyvKU/OeXbciGQxTS6ZHJnAP6t9lCs85J8/4rP1QE kx3cnaPyrQBDtKyzRi8WI+S0Y4mAgn1CnmY2NcoLhHGsQhw9SaRMxzGqB6tc7k9V8wIx Sot09sZW8F56UJjNFAdp1adXBLFqZG+H6T0wxAkLL+YCz4I/SwigRMbJDvk15+bglEFW EebCOby74u6/UJumyalMWEp9ceo3P4hc8TIYoi81wGyYBphA1uD2jichZtazDT8N8fRr lDH2QGMe3vOpCE+wU5ushxVPTSliMBCG26d//ot2uu0xQHeRf77kQs94UxNvcGuklkf3 rhnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:dkim-filter; bh=MD+Aeir3B6NSv5VxdWchXqnIlbEpAOLGX4DiWLdrVQs=; fh=2hmqWtCcjtCMwW8nk/JH1dn0ryMGReRZogHdwCQv2XE=; b=n2vQTCCX0/FScm/73OqpXULPEkSxCv/L2jXs0xyUHSb+jO92g6AXi0ACgxgqVeq38j VbHXIhoIh7ejLSEoooEgA7fXW4TPIIM+TPhiOmTI1afk0LVH3cPCk/SBEBGFif/vvmq1 ASvMWDB6NFJ+kjzl74+gVccY5q5SraPPS9tcozh+ueGHW/IOyQNS6zEnfGQs5rVBwwH/ SjBhRyWlQRSX6d9/pij468ULcIUh35B+HEgS3Bhp2YT43E8ZwmmwX5XDyg52apY+reoU 2F1G6PhAvFcBBb7iK8zLo+1GsyPzyis6U9+BA1840e2mUCzmXqWHLf9PW0LtVKNjhGK8 N2RQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@syntacore.com header.s=mta-04 header.b=odVUulp4; dkim=pass header.i=@syntacore.com header.s=mta-03 header.b=QEUyMi2g; arc=pass (i=1 dkim=pass dkdomain=syntacore.com dkim=pass dkdomain=syntacore.com dmarc=pass fromdomain=syntacore.com); spf=pass (google.com: domain of linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=syntacore.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s8-20020aa78288000000b006e49051f25dsi5747003pfm.210.2024.02.27.10.25.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:25:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@syntacore.com header.s=mta-04 header.b=odVUulp4; dkim=pass header.i=@syntacore.com header.s=mta-03 header.b=QEUyMi2g; arc=pass (i=1 dkim=pass dkdomain=syntacore.com dkim=pass dkdomain=syntacore.com dmarc=pass fromdomain=syntacore.com); spf=pass (google.com: domain of linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=syntacore.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 337FA28A3B5 for <ouuuleilei@gmail.com>; Tue, 27 Feb 2024 17:06:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A539F4C63D; Tue, 27 Feb 2024 17:06:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=syntacore.com header.i=@syntacore.com header.b="odVUulp4"; dkim=pass (2048-bit key) header.d=syntacore.com header.i=@syntacore.com header.b="QEUyMi2g" Received: from mta-04.yadro.com (mta-04.yadro.com [89.207.88.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6170C1EB40 for <linux-kernel@vger.kernel.org>; Tue, 27 Feb 2024 17:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.207.88.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709053599; cv=none; b=WgnRCL0hwHI/SqDhftHSz225o8iixNfDto9AfWH+HoXyR3kco6soHBTDSZg9TK/1J5iNlDqYU82FuYfIhxLF3FxsMR0TyRXi1skppEBogQzk2dBzJwWH7xVICL3ly+zaP9xU2VVT/5MVTVXE8j/yjl4xB7Ub5atMTxoFxjnVgsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709053599; c=relaxed/simple; bh=MebS9n5ZiCS4+c+fVej6vKE1hD4/nz20mid32q2t1s0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZvzDSpVyGondt/EnKsgGe0FCDLfCsSCogOw5weAoFrauh05XC4UBHiyAS57SnV/dpJ4WG72y9fdyylfHRDX4n+EvMlSDnd2CymUAYEQQnz1luHrhbjtObbH0BlIjFrhJGOQEWZ1f9dlGBnN9P5lMibgoYEZ2qdUc7s++fn7P880= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=syntacore.com; spf=fail smtp.mailfrom=syntacore.com; dkim=pass (2048-bit key) header.d=syntacore.com header.i=@syntacore.com header.b=odVUulp4; dkim=pass (2048-bit key) header.d=syntacore.com header.i=@syntacore.com header.b=QEUyMi2g; arc=none smtp.client-ip=89.207.88.248 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=syntacore.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=syntacore.com DKIM-Filter: OpenDKIM Filter v2.11.0 mta-04.yadro.com 6DE4CC002E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-04; t=1709053260; bh=MD+Aeir3B6NSv5VxdWchXqnIlbEpAOLGX4DiWLdrVQs=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=odVUulp4NTJadskyMmbqTctpkueG6DuJQskXWlApGq9Of11jwpjc+jZO5lNzUvULZ 4bvfaTF5pihBqOcBZ4aR1kVPpxK3+yOftUV9Evv2ArDHGzfXGP8h5xdCEuxag8myTE WBMEn60qMbaRZ36RLeTEVg53ecVqA2XHm/qYjJXvWiiszQrlAWsqGXp1F49zjZyms7 WBneShy6r8Q7lxT6xk9iXwBjR3ULiwe7TDnEKO3cjXmxrS02y0HjSbtWsq3TqCdqJW dPEJpGGPAn6mCorXzK6eHLDuJp+0rfipZ6axfB4js2nRdXVYBK4So8wUrpdbhKvKdB I5k50oiX+0Z/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-03; t=1709053260; bh=MD+Aeir3B6NSv5VxdWchXqnIlbEpAOLGX4DiWLdrVQs=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=QEUyMi2grJRDP+vJgy1S9AD4Dh5Bl9f2gqJEX8jl10Wj0syR3GLEoi6sPoXtklDhj XD13tipkqxWH2MiC965NxNSKfSN62lyCnhxs0syGb0uRvwMlJJWQtvEra1MvVUKTuu hsFnLrLpSfxujVW8WsnZpGzdgClB5jnO1BcYFTQ5W8l8fIQkkzlIuzu1zDGLBrU2Xo hYPC3LEVZbPKM0zzDEEc43vVfzcFbxk83TkYIpdlRJkI9kG/4+nPhkQGZfYDqVkWLv vwHeE+HZK+9YUrsgeGEd9vgTEe7qQb1EE0tRlYdCZ0vMoCshElQrt3Pg4ShrDtaC74 qyXKMNMXXb/8w== From: Vadim Shakirov <vadim.shakirov@syntacore.com> To: <linux-riscv@lists.infradead.org> CC: Vadim Shakirov <vadim.shakirov@syntacore.com>, Atish Patra <atishp@atishpatra.org>, Anup Patel <anup@brainfault.org>, Will Deacon <will@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v2,RESEND 0/2] drivers: perf: fix crash with the legacy riscv driver Date: Tue, 27 Feb 2024 20:00:00 +0300 Message-ID: <20240227170002.188671-1-vadim.shakirov@syntacore.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: T-Exch-05.corp.yadro.com (172.17.10.109) To S-Exch-01.corp.yadro.com (10.78.5.241) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792077553061736916 X-GMAIL-MSGID: 1792077553061736916 |
Series |
drivers: perf: fix crash with the legacy riscv driver
|
|
Message
Vadim Shakirov
Feb. 27, 2024, 5 p.m. UTC
This series fix crash with the legacy riscv driver when configs: CONFIG_RISCV_PMU_LEGACY=y and CONFIG_RISCV_PMU_SBI=n and you try to perf record Vadim Shakirov (2): drivers: perf: added capabilities for legacy PMU drivers: perf: ctr_get_width function for legacy is not defined drivers/perf/riscv_pmu.c | 18 +++++------------- drivers/perf/riscv_pmu_legacy.c | 10 +++++++++- 2 files changed, 14 insertions(+), 14 deletions(-)
Comments
Hi Vadim, On 27/02/2024 18:00, Vadim Shakirov wrote: > With parameters CONFIG_RISCV_PMU_LEGACY=y and CONFIG_RISCV_PMU_SBI=n > linux kernel crashes when you try perf record: > > $ perf record ls > [ 46.749286] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 > [ 46.750199] Oops [#1] > [ 46.750342] Modules linked in: > [ 46.750608] CPU: 0 PID: 107 Comm: perf-exec Not tainted 6.6.0 #2 > [ 46.750906] Hardware name: riscv-virtio,qemu (DT) > [ 46.751184] epc : 0x0 > [ 46.751430] ra : arch_perf_update_userpage+0x54/0x13e > [ 46.751680] epc : 0000000000000000 ra : ffffffff8072ee52 sp : ff2000000022b8f0 > [ 46.751958] gp : ffffffff81505988 tp : ff6000000290d400 t0 : ff2000000022b9c0 > [ 46.752229] t1 : 0000000000000001 t2 : 0000000000000003 s0 : ff2000000022b930 > [ 46.752451] s1 : ff600000028fb000 a0 : 0000000000000000 a1 : ff600000028fb000 > [ 46.752673] a2 : 0000000ae2751268 a3 : 00000000004fb708 a4 : 0000000000000004 > [ 46.752895] a5 : 0000000000000000 a6 : 000000000017ffe3 a7 : 00000000000000d2 > [ 46.753117] s2 : ff600000028fb000 s3 : 0000000ae2751268 s4 : 0000000000000000 > [ 46.753338] s5 : ffffffff8153e290 s6 : ff600000863b9000 s7 : ff60000002961078 > [ 46.753562] s8 : ff60000002961048 s9 : ff60000002961058 s10: 0000000000000001 > [ 46.753783] s11: 0000000000000018 t3 : ffffffffffffffff t4 : ffffffffffffffff > [ 46.754005] t5 : ff6000000292270c t6 : ff2000000022bb30 > [ 46.754179] status: 0000000200000100 badaddr: 0000000000000000 cause: 000000000000000c > [ 46.754653] Code: Unable to access instruction at 0xffffffffffffffec. > [ 46.754939] ---[ end trace 0000000000000000 ]--- > [ 46.755131] note: perf-exec[107] exited with irqs disabled > [ 46.755546] note: perf-exec[107] exited with preempt_count 4 > > This happens because in the legacy case the ctr_get_width function was not > defined, but it is used in arch_perf_update_userpage. > > Also remove extra check in riscv_pmu_ctr_get_width_mask > > Signed-off-by: Vadim Shakirov <vadim.shakirov@syntacore.com> > Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> > Reviewed-by: Atish Patra <atishp@rivosinc.com> > --- > drivers/perf/riscv_pmu.c | 18 +++++------------- > drivers/perf/riscv_pmu_legacy.c | 8 +++++++- > 2 files changed, 12 insertions(+), 14 deletions(-) > > diff --git a/drivers/perf/riscv_pmu.c b/drivers/perf/riscv_pmu.c > index 0dda70e1ef90..c78a6fd6c57f 100644 > --- a/drivers/perf/riscv_pmu.c > +++ b/drivers/perf/riscv_pmu.c > @@ -150,19 +150,11 @@ u64 riscv_pmu_ctr_get_width_mask(struct perf_event *event) > struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu); > struct hw_perf_event *hwc = &event->hw; > > - if (!rvpmu->ctr_get_width) > - /** > - * If the pmu driver doesn't support counter width, set it to default > - * maximum allowed by the specification. > - */ > - cwidth = 63; > - else { > - if (hwc->idx == -1) > - /* Handle init case where idx is not initialized yet */ > - cwidth = rvpmu->ctr_get_width(0); > - else > - cwidth = rvpmu->ctr_get_width(hwc->idx); > - } > + if (hwc->idx == -1) > + /* Handle init case where idx is not initialized yet */ > + cwidth = rvpmu->ctr_get_width(0); > + else > + cwidth = rvpmu->ctr_get_width(hwc->idx); > > return GENMASK_ULL(cwidth, 0); > } > diff --git a/drivers/perf/riscv_pmu_legacy.c b/drivers/perf/riscv_pmu_legacy.c > index a85fc9a15f03..fa0bccf4edf2 100644 > --- a/drivers/perf/riscv_pmu_legacy.c > +++ b/drivers/perf/riscv_pmu_legacy.c > @@ -37,6 +37,12 @@ static int pmu_legacy_event_map(struct perf_event *event, u64 *config) > return pmu_legacy_ctr_get_idx(event); > } > > +/* cycle & instret are always 64 bit, one bit less according to SBI spec */ > +static int pmu_legacy_ctr_get_width(int idx) > +{ > + return 63; > +} > + > static u64 pmu_legacy_read_ctr(struct perf_event *event) > { > struct hw_perf_event *hwc = &event->hw; > @@ -111,7 +117,7 @@ static void pmu_legacy_init(struct riscv_pmu *pmu) > pmu->ctr_stop = NULL; > pmu->event_map = pmu_legacy_event_map; > pmu->ctr_get_idx = pmu_legacy_ctr_get_idx; > - pmu->ctr_get_width = NULL; > + pmu->ctr_get_width = pmu_legacy_ctr_get_width; > pmu->ctr_clear_idx = NULL; > pmu->ctr_read = pmu_legacy_read_ctr; > pmu->event_mapped = pmu_legacy_event_mapped; Thanks for the resend, this one slipped through... Let's add the fixes tag: Fixes: cc4c07c89aad ("drivers: perf: Implement perf event mmap support in the SBI backend") Thanks again, Alex
On 27/02/2024 20:26, Alexandre Ghiti wrote: > On 27/02/2024 18:00, Vadim Shakirov wrote: >> Added the PERF_PMU_CAP_NO_INTERRUPT flag because the legacy pmu driver >> does not provide sampling capabilities >> >> Added the PERF_PMU_CAP_NO_EXCLUDE flag because the legacy pmu driver >> does not provide the ability to disable counter incrementation in >> different privilege modes >> >> Suggested-by: Atish Patra <atishp@rivosinc.com> >> Signed-off-by: Vadim Shakirov <vadim.shakirov@syntacore.com> >> --- >> drivers/perf/riscv_pmu_legacy.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/perf/riscv_pmu_legacy.c >> b/drivers/perf/riscv_pmu_legacy.c >> index 79fdd667922e..a85fc9a15f03 100644 >> --- a/drivers/perf/riscv_pmu_legacy.c >> +++ b/drivers/perf/riscv_pmu_legacy.c >> @@ -117,6 +117,8 @@ static void pmu_legacy_init(struct riscv_pmu *pmu) >> pmu->event_mapped = pmu_legacy_event_mapped; >> pmu->event_unmapped = pmu_legacy_event_unmapped; >> pmu->csr_index = pmu_legacy_csr_index; >> + pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; >> + pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE; >> perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW); >> } > > > I see here that Atish added its RB: > https://lore.kernel.org/linux-riscv/CAOnJCUJ-eE+zbXH0yBX_QBK2ep779q=wNCSrc+BJfzUb+zBCaw@mail.gmail.com/ > > So I add it here (hopefully b4 won't complain, I don't know): FTR, b4 indeed complains: NOTE: some trailers ignored due to from/email mismatches: ! Trailer: Reviewed-by: Atish Patra <atishp@rivosinc.com> Msg From: Alexandre Ghiti <alex@ghiti.fr> > > Reviewed-by: Atish Patra <atishp@rivosinc.com> > > And I'd say the fixes tag for this one is: > > Fixes: 9b3e150e310e ("RISC-V: Add a simple platform driver for RISC-V > legacy perf") > > Thanks, > > Alex > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
Hello: This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <palmer@rivosinc.com>: On Tue, 27 Feb 2024 20:00:00 +0300 you wrote: > This series fix crash with the legacy riscv driver when configs: > CONFIG_RISCV_PMU_LEGACY=y and CONFIG_RISCV_PMU_SBI=n and you try > to perf record > > Vadim Shakirov (2): > drivers: perf: added capabilities for legacy PMU > drivers: perf: ctr_get_width function for legacy is not defined > > [...] Here is the summary with links: - [v2,RESEND,1/2] drivers: perf: added capabilities for legacy PMU https://git.kernel.org/riscv/c/65730fe8f4fb - [v2,RESEND,2/2] drivers: perf: ctr_get_width function for legacy is not defined https://git.kernel.org/riscv/c/682dc133f83e You are awesome, thank you!