From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47EFC33F8D4 for ; Tue, 11 Aug 2026 03:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786420237; cv=none; b=qCbZp3Vc55bvLqRVPShS12AqI2Eg0UdMCFXOZNg9CwBSeG0Wrp1X00gFmq5iCQcr3EFCLGY4CepIwJEMQs1AiE5utw8nyEnJvvKqQ9AvUnH6Ch9c4Fd6GuGqv2dIof1B0/dyLcBRrAKIaTIAAkwpS4/DuukdBpSKG44vLf2ERUk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786420237; c=relaxed/simple; bh=gWBYvoXvMuR+XWw4Tsmg87T8vN6PxbDkYFOQRNHGpm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=guCbG7un6CNQhIbpkxahWi2NIVmhZaoGjC6hDRTK1xBuHUv/XCchKbo5asf0y+LoHye2kOY0CkqStL4QsycYr7XCqplS0WD1do+YC46QbFpIb7dgRLeG/JcrVSjStoetccH8o956sq3aIk4zm+goTTrg3FAPWXOCa1mKXkaEyn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=O/GM3YyO; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O/GM3YyO" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2ceaf8a1265so40432115ad.2 for ; Mon, 10 Aug 2026 20:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786420235; x=1787025035; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=UzLQVcGZ5l2XVUGPdqbb3e7Oajp0X5+/MxQRIPlN0dE=; b=O/GM3YyOirhrW+Lysm1oxIeHknUS6sS+gCLYJ6xtqlW1z3eupaZ7Nwu0ORc94/wT04 9d51ml2dxk13VnFwCX1iunWpeeWYCfm0YoZ0/BSwEs1Ch2vBf54anw9hqi2Q9j9QGoXN F4XvLtn3dHXiiY9kNDRd/qH3VmvPwx2b1DiVQDIjBMGAPLkASjU1PJp+5HLLTQqjKux2 johfrs9a8mgkvklLS9VQZaNS7UEMWMitmUL2incn0pR1VMuwI/pQJdXuslvijWKN70H7 bEVL9/nzSORCBhJskRWx6refaWmUAZ7q1qMeiXAEcHhQO1HllAAzM/vhfCfWwKuMWXeV w/pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786420235; x=1787025035; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UzLQVcGZ5l2XVUGPdqbb3e7Oajp0X5+/MxQRIPlN0dE=; b=Ko9xCBQ/KkpIzF94admJtUWoDtHMVeXm4tHHWxAg804EDXLhinb7UFm4eRyyDSYpbi l3V2vMn96jGfwLMwFwqMJX9AQjg3M887JlONljxA04TP7WhjlDG7XU2wAzk4rL2D5qYe 3QIt1fW604VaFTuAYvr+ehVNL7Ku2wDJPw/BbGLvfzM8BIyzXcKwHOCdL8jToJr+AFxD P2BlhcTbN6+kOzxClAauhO+L2neRbAnkTJJtxZK3igJLBf45Bh008A7cu/Thni/1A65s J7EKy7cyjQt1TLBavgJhrYKYzrCDMIJL+BrhhfcRN3pHFfrUBPWOcoJ39tTI3ERQvxca TmUg== X-Forwarded-Encrypted: i=1; AHgh+RqzfBEHGQSt4k7Va4MMX6ciR8MJP3IDuWw6f2BTM8refo8V7pYncqsdz2Pvv829aa4tZF9bHa26Lpg2m08=@vger.kernel.org X-Gm-Message-State: AOJu0Yyaaps3P9wDbdmOXhb46E/RIm1ct96HP+1mGIjTOZkRy1lleCIQ 1oYLQPio0Wjgbiqx/IJGfG7sFVOf6T2jio0/ChWfRwv/zsVYax6xXmvh X-Gm-Gg: AR+sD10oPOr7a015Yh0uwItaN1Lyw2qnTF2P7XbUYDfKr+iXTALbbLgBzTUCKDygeHV e9FWtov4/DVOtiZNnykVl1Hf5VPZ94gbLbWAMSKzRZOzMcOIaVO4BVoqzVaotCglV0V3icXdxs1 3RNfneFGs7HVAj6KQI92jsaGU9KD3vqY60o0YXxsRbbkTHqG8dZUpARopCFCMOpLQTG4yz7y8qW af2Brw5FNZkZHG8iKwjRuFvmxrDQ7W1m9lNpkpEcpKm4z2mfmku9r6e60GIbM6yWZlS+j4ERSCy OLYKUN5V5OxCLBQE5VFXYenM5vYjVDRmT5ftu1zKNgFSxJdo48XhUjX3K7rX81spS2+yuYxbCLz qWArBN+bplCCr0KNJYKKmf57ebRaYFKuuGc9VHwQOneVusCJX29+dBRD3Yn87Ruag+i/bwuQ61P LzXXGy6/8UduMAb2apOyilpRtnb+OFCSB783/lE8SeycdTqwdWhE57Faju59TyNEnZhjqCFUh77 0wj5w5fcmMqPuS8TbHY/yCsrDd1TJSGag== X-Received: by 2002:a17:90b:2541:b0:381:a766:efcb with SMTP id 98e67ed59e1d1-392ec2fc235mr451558a91.4.1786420235511; Mon, 10 Aug 2026 20:50:35 -0700 (PDT) Received: from blinky ([67.174.242.98]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-392d4050557sm1740457a91.3.2026.08.10.20.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 20:50:34 -0700 (PDT) Date: Mon, 10 Aug 2026 20:50:31 -0700 From: Charlie Jenkins To: Atish Patra Cc: Jiri Olsa , Paul Walmsley , Mark Rutland , Rob Herring , Anup Patel , Namhyung Kim , Arnaldo Carvalho de Melo , Krzysztof Kozlowski , Ian Rogers , Will Deacon , James Clark , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-perf-users@vger.kernel.org, Conor Dooley Subject: Re: [PATCH v8 12/22] RISC-V: perf: Modify the counter discovery mechanism Message-ID: References: <20260701-counter_delegation-v8-0-7909f863a645@meta.com> <20260701-counter_delegation-v8-12-7909f863a645@meta.com> <178453211938.543975.7016109597042850635.b4-review@b4> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Aug 07, 2026 at 01:08:31AM -0700, Atish Patra wrote: > > On 7/20/26 12:21 AM, Charlie Jenkins wrote: > > On Wed, 01 Jul 2026 01:47:00 -0700, Atish Patra wrote: > > > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c > > > index 74d934238821..c20f1e33c65d 100644 > > > --- a/drivers/perf/riscv_pmu_sbi.c > > > +++ b/drivers/perf/riscv_pmu_sbi.c > > > @@ -1599,13 +1658,23 @@ static int __init rvpmu_devinit(void) > > > [ ... skip 15 lines ... ] > > > + * in S-mode via Supervisor Counter delegation. > > > + */ > > > + if (riscv_isa_extension_available(NULL, SSCCFG) && > > > + riscv_isa_extension_available(NULL, SMCDELEG) && > > > + riscv_isa_extension_available(NULL, SSCSRIND)) > > > + static_branch_enable(&riscv_pmu_cdeleg_available); > > This needs to not only check that smcdeleg is supported in linux, but > > also that it is supported in the SBI implementation correct? Trying to > > boot this on OpenSBI before 6bb6b61c27eb ("lib: sbi: Add support for smcsrind and > > smcdeleg") will fail on an illegal instruction in > > rvpmu_deleg_find_ctrs() while trying to access the scountinhibit csr in > > the patch "RISC-V: perf: Implement supervisor counter delegation > > support". The proper mstateen bits need to be set for this to work > > without crashing. > > Yeah. We can do trap/detect to identify if smcdeleg is actually available > but that is bit ugly. > The firmware should make sure that it doesn't advertises an ISA extension if > that is not avaialble > to S-mode but that model only works for newer firmware. > > if you are running very old firmware with new Qemu/platform, the default ISA > extension may have > smcdeleg while older firmware may not even know about it. > > In reality, I am hoping chances of that happening are rare as OpenSBI > patches have been available > from a long time and Linux kernel patches are yet to merge. I have not > addressed this in v9 as I am > not sure which is the best worst approach yet :) I had an old opensbi binary laying around and ran into this. This unfortunately crashes the kernel, but since there is not a good way of detecting it and newer firmware has handled it for 2 years now, I think it is acceptable to leave this as-is. - Charlie > > >