Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp488558lql; Mon, 11 Mar 2024 08:28:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkQ1gQ/DLLXAvJTGHEN4aon5XDQ+/VRHBJLwkGQCaIyyOaqMT+AI2QkZvuElpy7AA0N9CzrKisn4skdBmq7tk4a2YqtXsX65zy57hQHA== X-Google-Smtp-Source: AGHT+IHUJoEXWvx/3QXAxc7n3kOzYa7Uhkl27bpGX7W1f7KhzC6VQXYUmBcRoQ8IkiC8zlaCvlhH X-Received: by 2002:a17:906:892:b0:a44:c1bf:a801 with SMTP id n18-20020a170906089200b00a44c1bfa801mr4228144eje.17.1710170937492; Mon, 11 Mar 2024 08:28:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710170937; cv=pass; d=google.com; s=arc-20160816; b=BDafDuoZ8mIEGE4NLGhTQPcTldqdvg6KsHKh5HZq+hQPq/pFo5gLs7668B0LCNCNLI 6jdw/hT2FaXc6FjjSwgBx14wieRoqEg8JCXZ+4t22lV+yFgR/syWCKMtdLiylzRvDcAL BZythibt4rMQWV5zZW307/9LY2/7DLdTCwNnfSzaPWJxd3CyyxKkrZm5yuqRXgeRcxi2 E0QLLIzf9dNRWf7A5o73cSI0UXLwJhBC6lbkwk+rJJK8SRUpluaLenTuz72WG2NEyWvi Mg8+Zo+L0Z2L8Ed+3Efycf1P6x7B5WTRlrOomXKSUFJoX00jlZ6RGNXrWq7A5P0aQajI DhGw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ANbZ4MEfJDxMTtdshudp5qwOEUlb4mfOdbH+eIGJyhE=; fh=vUl3RSDFG7ciie3OI3PtND/VXeGE2nExGgDJ5Q4wLfU=; b=aF1OHlW7hNor/yr5j6IUnk+mnIZAgi1bzuALpCx4xspbeZVzVJjJ/u9nJOU/2qFZIr hjqCmsZU3NNVV5axnjp5wmshppvU/uPLlP0bN1u/BQEBvNcY1WcmA/1/FtNfbGtA6FO9 NIAWGp9aoituXP4RszBKlyVw7KS88zbBd04GiAbO6esrNKWHTWOyRWNsE6o16OWaVlJs EWRE1gHeHnKAiteksG9oY8ZhdMIJmY+gjKktLMgAo3dU3Llakxlf5weRUELEWaO8ySeh YbEDvtz2wuV/L9ycYbKIIY1sshI1CmVJ4Y/xfYLTOQkY8ULnfUz4XlVO0J95vtG5YHut Pyjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FH7qCz5I; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99072-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lc16-20020a170906f91000b00a45b3fe84b9si2513459ejb.186.2024.03.11.08.28.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 08:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FH7qCz5I; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99072-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3C6D41F259C6 for ; Mon, 11 Mar 2024 15:19:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1630F58ACE; Mon, 11 Mar 2024 15:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FH7qCz5I" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 335E058AAC; Mon, 11 Mar 2024 15:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710169988; cv=none; b=CsbPYHjcUelZ4qN/sC+LX7LAFkhgtW96J7lHFjjtqbg8KG27lD81+EdE4OkyHXK5NT0UOI9VlMT7yLJDmH0y4vbdBBAFwehuBpySCMCodQ7R0Y9OaByMQCPsO6oYpVtXfIMePEB2/ke0JzF5BEX/16xcc1iijkLDxM+dQ/KwT1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710169988; c=relaxed/simple; bh=oMx6zHeOTkEXDKbjq76qlbY+QDGbPJEZZs3fhZ3D9bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QUx9pw5vEkR/JNPocSASWr9KKoPkicO7zpKFN+V/rJZYYheiH5lxfxhuQ9XRXH8SppdesuJHVBKY2MKichQheQCGevAbpRZ6BQjANhtJ3wQqwp4syGg5un5P2nN2eaT6thpTPBTW1Li4byWXUXVIQ3svpMsFnIwKQFoQlL53mBs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FH7qCz5I; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFC3CC43390; Mon, 11 Mar 2024 15:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710169987; bh=oMx6zHeOTkEXDKbjq76qlbY+QDGbPJEZZs3fhZ3D9bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FH7qCz5I9D+5TG6yKE2OxT0QvT8KWAlC4La6EWzYw4zl9NDjchwcvyfv9HT4wxcuD kaGdZxBKVjM9aTXyzjcYDYFwFgFsOyd1YoeeDJYzGlJLKL5G6FtKQMLcbzJnN9kmxZ TSBIxNSGEImNrGIbarnVqZJ3DPfRacOOc6pm21MR3V1M7Dm4TNsRF1Kic6K915h7JS t5tM7psXtBrRSu+nTbqMNV2R2NxLm0+MBqLknklW+A2K6Ev9AdWg1S4LS72tXLQzFZ I9VIClDo+ac4eYXdg5/G8bA9RetUKzx5S9LoPOc8VCyhlXP7yBcnK2lBSUKpIP0nsS cXhUrFRUj5laA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Fei Wu , Alexandre Ghiti , Atish Patra , Palmer Dabbelt , Sasha Levin , atishp@atishpatra.org, will@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 6.7 23/23] perf: RISCV: Fix panic on pmu overflow handler Date: Mon, 11 Mar 2024 11:12:03 -0400 Message-ID: <20240311151217.317068-23-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311151217.317068-1-sashal@kernel.org> References: <20240311151217.317068-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.9 Content-Transfer-Encoding: 8bit From: Fei Wu [ Upstream commit 34b567868777e9fd39ec5333969728a7f0cf179c ] (1 << idx) of int is not desired when setting bits in unsigned long overflowed_ctrs, use BIT() instead. This panic happens when running 'perf record -e branches' on sophgo sg2042. [ 273.311852] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000098 [ 273.320851] Oops [#1] [ 273.323179] Modules linked in: [ 273.326303] CPU: 0 PID: 1475 Comm: perf Not tainted 6.6.0-rc3+ #9 [ 273.332521] Hardware name: Sophgo Mango (DT) [ 273.336878] epc : riscv_pmu_ctr_get_width_mask+0x8/0x62 [ 273.342291] ra : pmu_sbi_ovf_handler+0x2e0/0x34e [ 273.347091] epc : ffffffff80aecd98 ra : ffffffff80aee056 sp : fffffff6e36928b0 [ 273.354454] gp : ffffffff821f82d0 tp : ffffffd90c353200 t0 : 0000002ade4f9978 [ 273.361815] t1 : 0000000000504d55 t2 : ffffffff8016cd8c s0 : fffffff6e3692a70 [ 273.369180] s1 : 0000000000000020 a0 : 0000000000000000 a1 : 00001a8e81800000 [ 273.376540] a2 : 0000003c00070198 a3 : 0000003c00db75a4 a4 : 0000000000000015 [ 273.383901] a5 : ffffffd7ff8804b0 a6 : 0000000000000015 a7 : 000000000000002a [ 273.391327] s2 : 000000000000ffff s3 : 0000000000000000 s4 : ffffffd7ff8803b0 [ 273.398773] s5 : 0000000000504d55 s6 : ffffffd905069800 s7 : ffffffff821fe210 [ 273.406139] s8 : 000000007fffffff s9 : ffffffd7ff8803b0 s10: ffffffd903f29098 [ 273.413660] s11: 0000000080000000 t3 : 0000000000000003 t4 : ffffffff8017a0ca [ 273.421022] t5 : ffffffff8023cfc2 t6 : ffffffd9040780e8 [ 273.426437] status: 0000000200000100 badaddr: 0000000000000098 cause: 000000000000000d [ 273.434512] [] riscv_pmu_ctr_get_width_mask+0x8/0x62 [ 273.441169] [] handle_percpu_devid_irq+0x98/0x1ee [ 273.447562] [] generic_handle_domain_irq+0x28/0x36 [ 273.454151] [] riscv_intc_irq+0x36/0x4e [ 273.459659] [] handle_riscv_irq+0x4a/0x74 [ 273.465442] [] do_irq+0x62/0x92 [ 273.470360] Code: 0420 60a2 6402 5529 0141 8082 0013 0000 0013 0000 (6d5c) b783 [ 273.477921] ---[ end trace 0000000000000000 ]--- [ 273.482630] Kernel panic - not syncing: Fatal exception in interrupt Reviewed-by: Alexandre Ghiti Reviewed-by: Atish Patra Signed-off-by: Fei Wu Link: https://lore.kernel.org/r/20240228115425.2613856-1-fei2.wu@intel.com Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- drivers/perf/riscv_pmu_sbi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 16acd4dcdb96c..452aab49db1e8 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -512,7 +512,7 @@ static void pmu_sbi_set_scounteren(void *arg) if (event->hw.idx != -1) csr_write(CSR_SCOUNTEREN, - csr_read(CSR_SCOUNTEREN) | (1 << pmu_sbi_csr_index(event))); + csr_read(CSR_SCOUNTEREN) | BIT(pmu_sbi_csr_index(event))); } static void pmu_sbi_reset_scounteren(void *arg) @@ -521,7 +521,7 @@ static void pmu_sbi_reset_scounteren(void *arg) if (event->hw.idx != -1) csr_write(CSR_SCOUNTEREN, - csr_read(CSR_SCOUNTEREN) & ~(1 << pmu_sbi_csr_index(event))); + csr_read(CSR_SCOUNTEREN) & ~BIT(pmu_sbi_csr_index(event))); } static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival) @@ -731,14 +731,14 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) /* compute hardware counter index */ hidx = info->csr - CSR_CYCLE; /* check if the corresponding bit is set in sscountovf */ - if (!(overflow & (1 << hidx))) + if (!(overflow & BIT(hidx))) continue; /* * Keep a track of overflowed counters so that they can be started * with updated initial value. */ - overflowed_ctrs |= 1 << lidx; + overflowed_ctrs |= BIT(lidx); hw_evt = &event->hw; riscv_pmu_event_update(event); perf_sample_data_init(&data, 0, hw_evt->last_period); -- 2.43.0