From patchwork Tue Nov 19 20:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880509 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 174901D2716 for ; Tue, 19 Nov 2024 20:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048252; cv=none; b=iPMsI7ysD5ELZwLTY9Ua4ZUr0iE7J3+xyP3o6hw7bRd4H4GN8BlFIeZWfqstOG7DPXUVhvSdptGojSz3Ft8olx2gPD5vpNaVlfnHLvmGeUv2NkDMe+Q2YuzKM57UiHUh6npOD4W0Y8CSFBNSioRCR88PmPuCbfA4EEBrc+DEk6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048252; c=relaxed/simple; bh=9a3a2dykXm+Z1VuOIzXUUFPIUB4KYnT3BbloIfBYDqg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WEUtAcDEu1jhwmW4Iu0fDwfR0XJ0gciGmDb3T8dZ/KPz7Mk4n7wdCOtuOfO8zxcZ55n8ZOv9tW768t9vL0o9W0tHvz61BIhcNm+G3REeFBtnPSIRaN3w36Ux6c5Cmze1PpqZbVWdiXcRAPE1eyR9KRiAHNPieUsGxilGrOERAC4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=o0xsLxbk; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="o0xsLxbk" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2ea49a1b4c8so2332712a91.2 for ; Tue, 19 Nov 2024 12:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048250; x=1732653050; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2qPwdXgi93D1Fj1M3CTUmRPQX23R+cN6bIgDXtW8EzY=; b=o0xsLxbkhLJ21l87Ve0dLhopPiU/2eKj5rUKGEmqAsKjm7Mklrfr3qPEAJ8B7zjOl5 f3t0oJdnWna2iun7jK8a+iVMfFzLROCO+Gpq2c1aFOEWtf6xIMViwMoYystcsNSy3B7w 5OVyohRwrKCXkAcSjCeEmFw/TNuAWGzZ5bJ6fz88salWfutHIM6GwYIoC8cN32WtVYr6 B+FyKLIHS0cmylE1ND4Ruso8YkixxR0SP4GAwl2XUpEjyofzmqrVlzx7A2CK8KNtxjw0 7AKuQMLuC/VpDm3gWz23i5llqaA3wngwXusqimS5KDHnQIDzWaSWDbQqK4WbDPTZtvu3 PTAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048250; x=1732653050; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2qPwdXgi93D1Fj1M3CTUmRPQX23R+cN6bIgDXtW8EzY=; b=iOEIF/3YOHb0o6oWXQd92oIVaqnl2mYiP3J8g+lDTtVpt65335scLBCp5sc8GwzP4g 3+Ushbz/lrc82bA2twpL9OsJ4RH6FAPrfIDl4ABAh005tTbJFSZXMUV7smRy4GOLdeeQ e5yl7Rw+YgcHjML+UuFomgKVJITSgUAfbQk6LLn6Xlf7WaQinaNH57YehwtOJtltpv9r d7swZ4b5VFtVI3SeQjuop1BKn5rNZ6fZ3S1oSf3A/1p8Lb/vtC+MZSWtlQBZ9RwIgEwE nglMm3qnOrph+QXrx1z51gQaQkjrf7bxSvnxPZC16sq6zosJcYsvZXmPV7J+ydpRh94J BZjg== X-Forwarded-Encrypted: i=1; AJvYcCWcr8sg57qPVmwpHYBhyJGkQDFStwOLotXzcFctQsCNJthF7ROqJW0eSZOSFxSfG8KXCHU=@vger.kernel.org X-Gm-Message-State: AOJu0YwTD5RjdTH2g4aHxVGRsIJr9ucJQX100Mn0NGZCrylxVB316/yJ 64tH4pwiXgsB/dhG0JYo9NxhnFqMGl8InUdPYO9vMrk2usPedzL+dFo+RdMA/TU= X-Google-Smtp-Source: AGHT+IHGbLa6SegMg+6UWCLGuDz+AC9C3f5G3GHUQKuYncIbocwbfU1Y52MRciljHs7ffGD0KEce3w== X-Received: by 2002:a17:90b:288e:b0:2ea:37b4:5373 with SMTP id 98e67ed59e1d1-2eaca70abedmr135913a91.10.1732048250306; Tue, 19 Nov 2024 12:30:50 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:50 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:49 -0800 Subject: [PATCH 1/8] drivers/perf: riscv: Add SBI v3.0 flag Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-1-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 There are new PMU related features introduced in SBI v3.0. 1. Raw Event v2 which allows mhpmeventX value to be 56 bit wide. 2. Get Event info function to do a bulk query at one shot. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 391ca1422cae..cb98efa9b106 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -63,6 +63,7 @@ PMU_FORMAT_ATTR(event, "config:0-47"); PMU_FORMAT_ATTR(firmware, "config:62-63"); static bool sbi_v2_available; +static bool sbi_v3_available; static DEFINE_STATIC_KEY_FALSE(sbi_pmu_snapshot_available); #define sbi_pmu_snapshot_available() \ static_branch_unlikely(&sbi_pmu_snapshot_available) @@ -1450,6 +1451,9 @@ static int __init pmu_sbi_devinit(void) if (sbi_spec_version >= sbi_mk_version(2, 0)) sbi_v2_available = true; + if (sbi_spec_version >= sbi_mk_version(3, 0)) + sbi_v3_available = true; + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, "perf/riscv/pmu:starting", pmu_sbi_starting_cpu, pmu_sbi_dying_cpu); From patchwork Tue Nov 19 20:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880511 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 87B051D318A for ; Tue, 19 Nov 2024 20:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048255; cv=none; b=lumPKB5lvzbjxtOZjQr66X9lbTEVhCd42qBIfguCINIPWrCCyZA29keJ84F4Qyx2UBQixFIJOPQO+RLNbRbwmrqTSTZD9uDcZQPl3ZHA11948l1syzXMY5SOr+bqXCRFNq5jrA7oebaJmCk9TsI3CuFzeIBu/F/jsDfYVbZZTJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048255; c=relaxed/simple; bh=d2OWDcgMWNTgpuTUqhaseMx00dJ1C9AXSYm/wfcfCPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pjFBd8K/jusU5u0J2OXNnjHv+FRwmG8fD/nQz8vwi5ugPAhbYlRRVPDvYttnbpvRg+r2Bfwx+XqOR1gcy/M9zE3Nk2kJw07LyWlII+fHC9ZeiTIrD9gGenlW5QYYDgcZ8OEB93ciKINlbvQKvnsMhuLxToVt7tCbHwDGyx816WA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=szgdI7d1; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="szgdI7d1" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ee020ec76dso1086633a12.3 for ; Tue, 19 Nov 2024 12:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048253; x=1732653053; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FB/tddqfX+5D+NwPYtCZBvpcbtznximYassXddDySaI=; b=szgdI7d1MF+HBQFcrcrbz1J3B3biwR9HJnw0k2Y6oV3Uj+pIDW6AYkRyZdHFm3hGAY W/WfQ5obz8cYmJ5U3k/1axsYPvXa61VOyp633kj0xGDpA03cuvP4XO48jkH0Wl4bk3O3 KPq8dohzNoWE/cYQDwizzAPXqAEbraOWUKkbObY8KNapPu+7Wa5d0bcAnHP0LdWh3FG4 /fDgNBQ593gcBVsvloQW6oBU2HORVocS+EVoj9L60xX/yplQZ2gZhthZZtgOD9vuKowM TrpiE2aGQlPVuXwu3Stjg9X+9y0mnLj1Ei6SbdS1AJJgSeZ196xBk+Z8gnBpJQF6/wai 43cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048253; x=1732653053; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FB/tddqfX+5D+NwPYtCZBvpcbtznximYassXddDySaI=; b=F3cDv2YIMWVLBFdJllpUHxQFt52wIlvxaDdnIrohWB2DUx3Knjfib65Xy1miV2Eza0 g37aAiF3QhAYUpoFUh3iodC+rv7cvho2fYls1/i1iZhLpdbUa/r+ow0zHLBaWtZXL6CD u4qIsLQ1HwndjRL9ucDnJ3GFzmvZtOzN4br/n7cjfwTid7ZPX4MPH8sRwigKadgTMI97 hb42iKoqVFnFuq7WkEJfIWcGnGKZmuH9mCkJYFHH3WIqoC3cepVCDtb/0CDd0DH8IaKx i7TFF78NqG3Chk0jjd+ZLbJ3rAO3Hwz7Q+sKKpHpsVt/nC0hfLr9RGkSb8jdsO5lG4Uj h36A== X-Forwarded-Encrypted: i=1; AJvYcCVAcamv/JfhXmA0S7FdeDSDSfbKgCGyD9LMi19JRPDm3GlHFc63ftfo8N38U+3zPrT1rak=@vger.kernel.org X-Gm-Message-State: AOJu0YzNiE6Y7HVZBtD6qaHifJczt+mR7o7qGH35c1Flstfk9Zwh1A74 iSLnF+bJgbvYAkCWOqZCHNOiLTD+pSpvL6Zw2dXUsHRUQ92OkknCr9zocU7LJow= X-Google-Smtp-Source: AGHT+IGG3BOEKBQHByHPNxLGRscpaUzNEj7RMHYMCOiguADUgT/ZA6zCcmpHgOYphyvS5L29CLFFRQ== X-Received: by 2002:a05:6a21:3287:b0:1d8:a29b:8f6f with SMTP id adf61e73a8af0-1ddae4e24bbmr613518637.16.1732048251371; Tue, 19 Nov 2024 12:30:51 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:51 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:50 -0800 Subject: [PATCH 2/8] drivers/perf: riscv: Fix Platform firmware event data Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-2-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 Platform firmware event data field is allowed to be 62 bits for Linux as uppper most two bits are reserved to indicate SBI fw or platform specific firmware events. However, the event data field is masked as per the hardware raw event mask which is not correct. Fix the platform firmware event data field with proper mask. Fixes: f0c9363db2dd ("perf/riscv-sbi: Add platform specific firmware event handling") Signed-off-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 1 + drivers/perf/riscv_pmu_sbi.c | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 98f631b051db..9be38b05f4ad 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -158,6 +158,7 @@ struct riscv_pmu_snapshot_data { }; #define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0) +#define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0) #define RISCV_PMU_RAW_EVENT_IDX 0x20000 #define RISCV_PLAT_FW_EVENT 0xFFFF diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index cb98efa9b106..50cbdbf66bb7 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -508,7 +508,6 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) { u32 type = event->attr.type; u64 config = event->attr.config; - u64 raw_config_val; int ret; /* @@ -529,21 +528,20 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) case PERF_TYPE_RAW: /* * As per SBI specification, the upper 16 bits must be unused - * for a raw event. + * for a hardware raw event. * Bits 63:62 are used to distinguish between raw events * 00 - Hardware raw event * 10 - SBI firmware events * 11 - Risc-V platform specific firmware event */ - raw_config_val = config & RISCV_PMU_RAW_EVENT_MASK; + switch (config >> 62) { case 0: ret = RISCV_PMU_RAW_EVENT_IDX; - *econfig = raw_config_val; + *econfig = config & RISCV_PMU_RAW_EVENT_MASK; break; case 2: - ret = (raw_config_val & 0xFFFF) | - (SBI_PMU_EVENT_TYPE_FW << 16); + ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); break; case 3: /* @@ -552,7 +550,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) * Event data - raw event encoding */ ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT; - *econfig = raw_config_val; + *econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK; break; } break; From patchwork Tue Nov 19 20:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880510 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 013321D363D for ; Tue, 19 Nov 2024 20:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048254; cv=none; b=ceIIPHLeBla826tbdHcH7BYfusbRiC7/QDW/upq6OM0NmJlTbNNQAbxThAgdXNGUxhKejGT/X+/AP30YE89YvTeRooQIhqUhi95jwf9V4q/MRnv/Ea5S9/on2fLV0vZlTvPnXwcLs6PIx+M47JMchlWqx4lcMU3BLmRGsnC6QUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048254; c=relaxed/simple; bh=SADvMhA7/Ukb2OMwQcY0BoWNEsNhkhKslaT1ZVi9WWw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jPwV7+ew5LIy6xwhhxhl//8aq+3wHi6B+BeS9o/f9NtBt+iZl+nxhzZnUYAiaHG/kGMxKy9uto7SrbckXPzwLDlyoB5AX/b4jtsDl66HOyuBGq3x315xapwGYIVYf1mkK5z4Qz8CdvTgKoict7tIWiN7LaBoQnV5SkCrPPhSpXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=yVB661SF; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="yVB661SF" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2ea711a76a5so2120374a91.0 for ; Tue, 19 Nov 2024 12:30:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048252; x=1732653052; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vRmKVkktJnfpekqs0vaEt2UdODXxii8BcnwHInLLVOw=; b=yVB661SF1mYVKlk0W8aEtptxaOukJtg5bcwEqgL/ka+MiQCvXkURjPs2PxEn0pCGrP scIOtROYNSzEQ3vEBqf2wFbXarl/ej/rr30JfN9mRYQcYL/oIFU5fzpjgeScypMbUtPI Mjfko/JwhcDKoXRDRTk//I0IcN9y/7WVTGeHemw8qEdx8OACeEdRaEle3191byr/EjL+ ncBYwqMjX3g89S3sc3iqzxdnUoqUlXcse2VvesXMFFPn56UuujbBmr6sXCpxBjAcZ5Gz WPGqWP99okCARr+sH97y6Nr8YXQypqyAXtWZ+qd9XIsIalYs/1wXguTaI9Psfc1UIBDt i9Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048252; x=1732653052; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vRmKVkktJnfpekqs0vaEt2UdODXxii8BcnwHInLLVOw=; b=VFK8t35ugEYnVTfoZixbCUOLdRy04iKls00yG6mJx/GHx/dSy2AmGdAED+xu1OYTri Qn00B6k/E8WUmoKpimJ+oahbTvi2pBL/9QMZU4Udrxi7eKINb5XeekHvxjt7eJRZG4pc AKDFLbv7b2J3ObFDxh2ClLMe3CNDL/H4zcrmzhfwUh9C+Z4iuhDn0A3qvtE+OTy1rai2 1UpErwgZ2SZTkGoXi0drqm9kPVpQAzHtTyt/5FXP1dKy6Cf9kJEJVOnzoLhhMNiwyOcP mQ0i8wji8CDniHNQTCfQgmgNzgSwJ78rs3OiQwcFf1ui+Q1BZE/giPr8r9a8MYubnMQ9 aJaA== X-Forwarded-Encrypted: i=1; AJvYcCUkr+q6aak92Z35qtlD4Pe5mWq0AnhZCT5Vkp7IJZuG9poEN0u2xPZj6uRbmQ8kxYASqJ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyePE4EkB1uz3Aqn18x3iAPq1kmigAgAU3vp4Cm//J3K7nuDoSq hMwXLRwCGt/2iMBQIY5eg0go2vdCNUfkqzGfvHI4qhnwUqUugrP0FV237OuMFV8= X-Google-Smtp-Source: AGHT+IH6B0MvWBP/cFrV+iSzChrNQ92fntZ29A1EV2WF6+w0INOIuuldt7jmoJ2f0P0WCEdUpH78Ag== X-Received: by 2002:a17:90b:3c8e:b0:2ea:61de:38ed with SMTP id 98e67ed59e1d1-2eaca7c9f36mr107313a91.26.1732048252407; Tue, 19 Nov 2024 12:30:52 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:52 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:51 -0800 Subject: [PATCH 3/8] drivers/perf: riscv: Add raw event v2 support Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-3-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 SBI v3.0 introduced a new raw event type that allows wider mhpmeventX width to be programmed via CFG_MATCH. Use the raw event v2 if SBI v3.0 is available. Signed-off-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 4 ++++ drivers/perf/riscv_pmu_sbi.c | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 9be38b05f4ad..3ee9bfa5e77c 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -159,7 +159,10 @@ struct riscv_pmu_snapshot_data { #define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0) #define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0) +/* SBI v3.0 allows extended hpmeventX width value */ +#define RISCV_PMU_RAW_EVENT_V2_MASK GENMASK_ULL(55, 0) #define RISCV_PMU_RAW_EVENT_IDX 0x20000 +#define RISCV_PMU_RAW_EVENT_V2_IDX 0x30000 #define RISCV_PLAT_FW_EVENT 0xFFFF /** General pmu event codes specified in SBI PMU extension */ @@ -217,6 +220,7 @@ enum sbi_pmu_event_type { SBI_PMU_EVENT_TYPE_HW = 0x0, SBI_PMU_EVENT_TYPE_CACHE = 0x1, SBI_PMU_EVENT_TYPE_RAW = 0x2, + SBI_PMU_EVENT_TYPE_RAW_V2 = 0x3, SBI_PMU_EVENT_TYPE_FW = 0xf, }; diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 50cbdbf66bb7..f0e845ff6b79 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -59,7 +59,7 @@ asm volatile(ALTERNATIVE( \ #define PERF_EVENT_FLAG_USER_ACCESS BIT(SYSCTL_USER_ACCESS) #define PERF_EVENT_FLAG_LEGACY BIT(SYSCTL_LEGACY) -PMU_FORMAT_ATTR(event, "config:0-47"); +PMU_FORMAT_ATTR(event, "config:0-55"); PMU_FORMAT_ATTR(firmware, "config:62-63"); static bool sbi_v2_available; @@ -527,18 +527,24 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) break; case PERF_TYPE_RAW: /* - * As per SBI specification, the upper 16 bits must be unused - * for a hardware raw event. + * As per SBI v0.3 specification, + * -- the upper 16 bits must be unused for a hardware raw event. + * As per SBI v3.0 specification, + * -- the upper 8 bits must be unused for a hardware raw event. * Bits 63:62 are used to distinguish between raw events * 00 - Hardware raw event * 10 - SBI firmware events * 11 - Risc-V platform specific firmware event */ - switch (config >> 62) { case 0: - ret = RISCV_PMU_RAW_EVENT_IDX; - *econfig = config & RISCV_PMU_RAW_EVENT_MASK; + if (sbi_v3_available) { + *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; + ret = RISCV_PMU_RAW_EVENT_V2_IDX; + } else { + *econfig = config & RISCV_PMU_RAW_EVENT_MASK; + ret = RISCV_PMU_RAW_EVENT_IDX; + } break; case 2: ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); From patchwork Tue Nov 19 20:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880512 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 321271D4171 for ; Tue, 19 Nov 2024 20:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048256; cv=none; b=l548w5ObTzh3+HSDGDD1Y0zDThfSFfGLSRdMXLezNJV/ozXwLcANH2GFlVijutoqH1U3+7z+64IPzXp4CZvaqFCTJmb58/PHAkVB+GfxN6K3stOXYvn4ulF1YkRi3773K0qBC/wxNZfULhV8SeUU3lw/BacAVmyGSP7kpen8iAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048256; c=relaxed/simple; bh=rkpDrsA/PVcggHd7+EAEFge1PhxYTYtvQjpCCjdH2MQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FfgvLowwG7zehHJxJ+CdG6xiBWDVMPlPHCP0LY6OM10PRTZ3Oo133EMXAGKBNOf+BvBIqI8LSpP31AwvhqM3/aHtX3RmOR0t8TB8bAahEyvxZbn0ad5bNgGl+jUhjkaaLPBye+CTfpwXZXkWfy08p5Ce3IyEg4RhwIfqD22DY2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=b4KgB1ok; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="b4KgB1ok" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20cb47387ceso14344635ad.1 for ; Tue, 19 Nov 2024 12:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048253; x=1732653053; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hCeV16Tw9Ue2BbFuxP2Jm0elvtAXwe5u9EmpHjH7wzE=; b=b4KgB1oklVUhjKk1dZMrSuSg+6IsBMa/TBmqo+HzHkgZ9Q4CqdC/d0/LFLNaNyED/x A2igfBBLHuVmVS5PVg9dxqdrYCirnHwoFSnfOFMQbwFrgVuCssHYvJ7rzxO92cpzxtxS tsbCnwcb0V/eQkXb8/XSWeXBmRvPwFqyiMlJRmWGAzeomfsKEzGKylBm77/fo4ilpQpr yViY2ChqgD8nXEIK1xkvu+HmV16jypC2JIY6jhQJLJD0/VmKh60HxGInbqhl49VTVCuh 9z3p3cHrgXzqDP+Szu3kBNrWrpzoDmG4xgDX/1gc9ZNRIx7PbaCxs25iUrsKycCe6ukk jg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048253; x=1732653053; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hCeV16Tw9Ue2BbFuxP2Jm0elvtAXwe5u9EmpHjH7wzE=; b=TYl8aWsp71WxR63WWJlphfRW+W7zE99Yzr+Q9oJQxcl/lfdjxvzniDDHIg4rGNNDOU ahxZCESudiw0GyLApnbB3pRB5ztMM27Ut3E1u/iSN6rC6gfihriE5AF9hA64x4+NprRt 5JqrdViVGiaVjV+xSjtUj5mLbIVaBgWeC9llkOVo689+SrVkbGYKz/S1alwJAI3kS3Af kbXLCyJlK5mWnwhrtjgZ08v0QB9/+f+ofMKjDUpozbvcRck3X54mnIUtnn0iL7//NLyN hkU+uERKqkk4MpY7SVeJvXE1oNxULUw5o10SNBQJbPMHYxqXsvDP7Lx8nzE8VnfcncOs qWvA== X-Forwarded-Encrypted: i=1; AJvYcCWE/RAB5S2UtvCsJV4cfkRDB+tthe9ahfJiHQWLnWBSvaHPbGYsotXMamFO62F6jedmH2o=@vger.kernel.org X-Gm-Message-State: AOJu0YwziNdkG4k11OrCBGfItdSxIYYHX+g+cKh3jmmqX2/L+xDWstu+ 2MoZHMovV98j2chBWXh35hhbFbmG+JLD+WZ6Jj9VS+ON/aBpixNKC7k54kzfDxQ= X-Google-Smtp-Source: AGHT+IEafgQoRfTXfxDGUyFBcxI9JgtU3iA1K006RwHi5mhUuXe4EdyQsqlE+qS4Y+FQs5c25dBVLA== X-Received: by 2002:a17:902:dac8:b0:211:e812:3948 with SMTP id d9443c01a7336-2126a259979mr4712555ad.0.1732048253488; Tue, 19 Nov 2024 12:30:53 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:53 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:52 -0800 Subject: [PATCH 4/8] RISC-V: KVM: Add support for Raw event v2 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-4-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 SBI v3.0 introuced a new raw event type v2 for wider mhpmeventX programming. Add the support in kvm for that. Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index 2707a51b082c..efd66835c2b8 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -60,6 +60,7 @@ static u32 kvm_pmu_get_perf_event_type(unsigned long eidx) type = PERF_TYPE_HW_CACHE; break; case SBI_PMU_EVENT_TYPE_RAW: + case SBI_PMU_EVENT_TYPE_RAW_V2: case SBI_PMU_EVENT_TYPE_FW: type = PERF_TYPE_RAW; break; @@ -128,6 +129,9 @@ static u64 kvm_pmu_get_perf_event_config(unsigned long eidx, uint64_t evt_data) case SBI_PMU_EVENT_TYPE_RAW: config = evt_data & RISCV_PMU_RAW_EVENT_MASK; break; + case SBI_PMU_EVENT_TYPE_RAW_V2: + config = evt_data & RISCV_PMU_RAW_EVENT_V2_MASK; + break; case SBI_PMU_EVENT_TYPE_FW: if (ecode < SBI_PMU_FW_MAX) config = (1ULL << 63) | ecode; From patchwork Tue Nov 19 20:29:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880513 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 4A9821D3585 for ; Tue, 19 Nov 2024 20:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048257; cv=none; b=VGYqx5TuGkpH/7wvjI4QEUghAL/1ix/TfCKoxGJRV2GnIhW7EJx4V8avaxP2S7B2SiwTmhdY+G9G9DvWIIeJ2J709fjxsoSoLFgYkfFDl26j5js8UpSm2/3sFcixbqUWLpHJRuipDBUXi91gXY0GlNHh97Xx6lD30k5WlNMd83o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048257; c=relaxed/simple; bh=5onDZuiSnkP2aXc6vh2wdwjeSxZ8XhBViklh3y0fpJo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WqNCMGbTNJwjGaPNRJVfoezmWuQyKlPkCPlNENnmmsZFJRH5/qhALtl0ZgeSQK+ASbDGXNz4pde4f7gUO8TGs0NMcRBe9uK6Yd9aB7zkOsbheoONxoD2S7O9yljE4ACGCJ3UBhseL4M6jcUtP1Db5of899d5qSqQxCI7HOqL4jA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=OIXZdX4r; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="OIXZdX4r" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-211fb27cc6bso33283825ad.0 for ; Tue, 19 Nov 2024 12:30:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048254; x=1732653054; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=40lt9LB/BTg/O24BZtpczZbDrdTkukX/GA7UpRzp0pg=; b=OIXZdX4rg/67XB2uYoxo+BdiMcIIImmGS3IqXzVpnA02peEDqOaUF4RBSOEXmlkp04 LDZ+uIVlmu0OOf8EaxvdReIksX2jT4014V4Etk4ZCh2L6FM7dwV6HYD2k9LTB/lajm7A wn2IC3BFMqUAMSENK/Y/4m3DL6hlMqrPQ0L8TuOLdaEnwNMYUQhAC85JjNjzTcK+5ioD EZkZrZuNAsNOxLEMrNyXtjyHwZrSbbC5EoYjeAwsCDSKtZOWYw/Btm9cYa9SHzMpPJjg ufRrd3Ctnlb2xcFXu0McPjTFbdlQgenEI9sBAI2sVqKMS65XdxUyAIoOFfH2PYtagJUu yI3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048254; x=1732653054; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=40lt9LB/BTg/O24BZtpczZbDrdTkukX/GA7UpRzp0pg=; b=Ijftg0D1CHhjeT1dkNxhktRG+XuN792bkgbGolulu195pBsGlkmoU3WOol+rxQxNC1 jNUeFu81AR6U47cyeXazWiXAT5x7YQbGCIrWtx5LPdjHw9ZAxxmqL8EHNaycpU0Zkt7A zH7VKz+lcCpe72DjCfN07KJpULJWm1/nMBy8f1SAEXGQmAncKbWOyHM6j4nuJc0CMle3 gjgXMUtX96MxjmWB6JgcPDbAnYSvtyk+vJBD0aR/aBFGNLXQVJMgLKJLZkiyh7x9qi0C pk0ouurZDVocFNTpVqHRJCqeDLfPZoaXxyu2+gsXrb15ENSn+9rvtFohVOVMycWihP8J k5TQ== X-Forwarded-Encrypted: i=1; AJvYcCXDEmRwRHUG3z3OL5SvGh2coQ0MGIbLIPV1yNaXGPS5rBWkAF9qMSXMhtv43eo9C0Z7EUA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywh2bwJ1/kfiahPrHuI/wnyME92+tXfIv0MN2NdE1rcc/BLqNTA NxFIKFHPje8ggTwmYHHGqpjTys3jPERi1zitOPij6wxzluJS6qx4nmWS3owM41mev/MNEmXTxGA 0 X-Google-Smtp-Source: AGHT+IHsJO0hcJESjwh6eQu7qwaEvcwUlwaSmtArcLLxZHqVuVRuaI9OsGKiZZ86BxWZYDPkCaGZqQ== X-Received: by 2002:a17:902:d2d2:b0:20c:5533:36da with SMTP id d9443c01a7336-2126b381b65mr257415ad.42.1732048254555; Tue, 19 Nov 2024 12:30:54 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:54 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:53 -0800 Subject: [PATCH 5/8] drivers/perf: riscv: Implement PMU event info function Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-5-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 With the new SBI PMU event info function, we can query the availability of the all standard SBI PMU events at boot time with a single ecall. This improves the bootime by avoiding making an SBI call for each standard PMU event. Since this function is defined only in SBI v3.0, invoke this only if the underlying SBI implementation is v3.0 or higher. Signed-off-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 7 +++++ drivers/perf/riscv_pmu_sbi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 3ee9bfa5e77c..c04f64fbc01d 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -134,6 +134,7 @@ enum sbi_ext_pmu_fid { SBI_EXT_PMU_COUNTER_FW_READ, SBI_EXT_PMU_COUNTER_FW_READ_HI, SBI_EXT_PMU_SNAPSHOT_SET_SHMEM, + SBI_EXT_PMU_EVENT_GET_INFO, }; union sbi_pmu_ctr_info { @@ -157,6 +158,12 @@ struct riscv_pmu_snapshot_data { u64 reserved[447]; }; +struct riscv_pmu_event_info { + u32 event_idx; + u32 output; + u64 event_data; +}; + #define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0) #define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0) /* SBI v3.0 allows extended hpmeventX width value */ diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index f0e845ff6b79..2a6527cc9d97 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -100,6 +100,7 @@ static unsigned int riscv_pmu_irq; /* Cache the available counters in a bitmask */ static unsigned long cmask; +static int pmu_event_find_cache(u64 config); struct sbi_pmu_event_data { union { union { @@ -299,6 +300,68 @@ static struct sbi_pmu_event_data pmu_cache_event_map[PERF_COUNT_HW_CACHE_MAX] }, }; +static int pmu_sbi_check_event_info(void) +{ + int num_events = ARRAY_SIZE(pmu_hw_event_map) + PERF_COUNT_HW_CACHE_MAX * + PERF_COUNT_HW_CACHE_OP_MAX * PERF_COUNT_HW_CACHE_RESULT_MAX; + struct riscv_pmu_event_info *event_info_shmem; + phys_addr_t base_addr; + int i, j, k, result = 0, count = 0; + struct sbiret ret; + + event_info_shmem = (struct riscv_pmu_event_info *) + kcalloc(num_events, sizeof(*event_info_shmem), GFP_KERNEL); + if (!event_info_shmem) { + pr_err("Can not allocate memory for event info query\n"); + return -ENOMEM; + } + + for (i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) + event_info_shmem[count++].event_idx = pmu_hw_event_map[i].event_idx; + + for (i = 0; i < ARRAY_SIZE(pmu_cache_event_map); i++) { + for (int j = 0; j < ARRAY_SIZE(pmu_cache_event_map[i]); j++) { + for (int k = 0; k < ARRAY_SIZE(pmu_cache_event_map[i][j]); k++) + event_info_shmem[count++].event_idx = + pmu_cache_event_map[i][j][k].event_idx; + } + } + + base_addr = __pa(event_info_shmem); + if (IS_ENABLED(CONFIG_32BIT)) + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_EVENT_GET_INFO, lower_32_bits(base_addr), + upper_32_bits(base_addr), count, 0, 0, 0); + else + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_EVENT_GET_INFO, base_addr, 0, + count, 0, 0, 0); + if (ret.error) { + result = -EOPNOTSUPP; + goto free_mem; + } + /* Do we need some barriers here or priv mode transition will ensure that */ + for (i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) { + if (!(event_info_shmem[i].output & 0x01)) + pmu_hw_event_map[i].event_idx = -ENOENT; + } + + count = ARRAY_SIZE(pmu_hw_event_map); + + for (i = 0; i < ARRAY_SIZE(pmu_cache_event_map); i++) { + for (j = 0; j < ARRAY_SIZE(pmu_cache_event_map[i]); j++) { + for (k = 0; k < ARRAY_SIZE(pmu_cache_event_map[i][j]); k++) { + if (!(event_info_shmem[count].output & 0x01)) + pmu_cache_event_map[i][j][k].event_idx = -ENOENT; + count++; + } + } + } + +free_mem: + kfree(event_info_shmem); + + return result; +} + static void pmu_sbi_check_event(struct sbi_pmu_event_data *edata) { struct sbiret ret; @@ -316,6 +379,14 @@ static void pmu_sbi_check_event(struct sbi_pmu_event_data *edata) static void pmu_sbi_check_std_events(struct work_struct *work) { + int ret; + + if (sbi_v3_available) { + ret = pmu_sbi_check_event_info(); + if (!ret) + return; + } + for (int i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) pmu_sbi_check_event(&pmu_hw_event_map[i]); From patchwork Tue Nov 19 20:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880514 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 46E331D5CDB for ; Tue, 19 Nov 2024 20:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048258; cv=none; b=qWiBCia3MGXAS1+DK3+8+ZAgbAeUIULoDAcOnvbapmWEd+NwBdAjR2d+GGgP3YjszRS1e7Pq7ny5ii5vSyOjycqFqTxVkLhbgR6A9E22DzFQTsmzLKDtazlme8ILG7CTxD7RnF7j9fBhWNvMUk8IU2uAAv48j5evUZ6gGYaL/tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048258; c=relaxed/simple; bh=d19CQgPNvBcsQ2Thiefa99k9qqPTIyWGn7bjCj3eHBA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JYLUXSaUwq83QyGnc2bkOE9kZiTyq1kUxCFTSbpySVf7YD66LWykaSzgN4e08NwXCHTpC88jIOksLr+v2hNa4jxq4uKESjeOu2dVRokMHP1fNZo/l0y4JIt0o3+y4kdL4521e/5bKlYtQhZYGMwouRLFdnik1QC/Y+xmX+t/CD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=MqBkJpn5; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="MqBkJpn5" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-211fd6a0a9cso12460015ad.3 for ; Tue, 19 Nov 2024 12:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048255; x=1732653055; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EvI6ELyRBC+Fyndrrci/LAt1a0lV7o2VMX1QjdFEcW8=; b=MqBkJpn5QNDHy+wljOqirYIG88ONCqUBdaWFNubLra3+LX9NGJ3BFxDhCLNBHYiYNC dKCxhzr6K8ZPP27rg4Zp+ufOqjZ1GspmJZpBbXAeH/8Vm8CVB8KZ/W2h9MZF0fwPEtBt wn5jQ2h8U83akh4LbkKVLmXgmG3A5cP8M+UdO12HOH0+vws8Q/2FiO4LqefcOfL3l4mw kprpnuutUb3ZHdzxRt3utuyjvpsAU7jrYfH4VWp5EFfHQpPG/E2GWpHTqDulqoLiKLDc DrtMOmL+KEo0xvVdJteoGLGoTSsM5b1z2dtoYtGGjZDs3SBooH6bfQSp6ABVBwcdbSwv 0E5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048255; x=1732653055; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvI6ELyRBC+Fyndrrci/LAt1a0lV7o2VMX1QjdFEcW8=; b=Ok10I5+2hUTBnqkJWO54TsrJcoXQ5dr9RQVmq5zNYJtZ/wVRFYAI34q+Em1gfB5FSF 9LDwQBzcWtxlY6MQqJJnuYWwn7WpefPLpd9CbeUIVZNFXogkGwL+qxThgGKObYWSNjcK qnRPOI2sz92bC0+dv/WeD3BIfjNGMzPTiOOMz69efvPYT11HRR72gD3kDvrzVIfaYmTM DSZ5K/3CUbXIzJ7k6bTlctfVHleXRHcEB8sWM1BHM2Uvv9CVat8RE6sOcqLJpw6rcVPe 3J8WYYwo1iTKZV3YH2nMmXsOR2sxZUncFvk9TXBQ3o+zhFtHptCGPx9/Q3nEx6llMULV +VmQ== X-Forwarded-Encrypted: i=1; AJvYcCVklE2luo3c8W+w28Iko10E8+8ajsPTNHJKQcnjmhCSkpe8nB4HJSw+Xbd+LP5e5OohPBY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/qcfyUdUzrBeA0l5VOJqcTYIxrGFXLB7yU00MZxkPjQKqpA1C zUAzGZuGuSXFcyskkOzwBNbH59VAV7wKeyctl2lLD9bjYx7Z7yxnV+/eHPc5rak= X-Google-Smtp-Source: AGHT+IE8OiqtfXItkGe53z5hjcs0b0CjneyIZkfN6utXnoNwtgLN2RoemxkaTVHNqe744fxPZ0nP9g== X-Received: by 2002:a17:902:d509:b0:212:40e0:9562 with SMTP id d9443c01a7336-2126a3b4478mr2002835ad.25.1732048255602; Tue, 19 Nov 2024 12:30:55 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:55 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:54 -0800 Subject: [PATCH 6/8] drivers/perf: riscv: Export PMU event info function Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-6-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 The event mapping function can be used in event info function to find out the corresponding SBI PMU event encoding during the get_event_info function as well. Refactor and export it so that it can be invoked from kvm and internal driver. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 111 ++++++++++++++++++++++------------------- include/linux/perf/riscv_pmu.h | 2 + 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 2a6527cc9d97..8ddd094c82ad 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -414,6 +414,65 @@ static bool pmu_sbi_ctr_is_fw(int cidx) return (info->type == SBI_PMU_CTR_TYPE_FW) ? true : false; } +int riscv_pmu_get_event_info(u32 type, u64 config, u64 *econfig) +{ + int ret = -ENOENT; + + switch (type) { + case PERF_TYPE_HARDWARE: + if (config >= PERF_COUNT_HW_MAX) + return -EINVAL; + ret = pmu_hw_event_map[config].event_idx; + break; + case PERF_TYPE_HW_CACHE: + ret = pmu_event_find_cache(config); + break; + case PERF_TYPE_RAW: + /* + * As per SBI v0.3 specification, + * -- the upper 16 bits must be unused for a hardware raw event. + * As per SBI v3.0 specification, + * -- the upper 8 bits must be unused for a hardware raw event. + * Bits 63:62 are used to distinguish between raw events + * 00 - Hardware raw event + * 10 - SBI firmware events + * 11 - Risc-V platform specific firmware event + */ + switch (config >> 62) { + case 0: + if (sbi_v3_available) { + if (econfig) + *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; + ret = RISCV_PMU_RAW_EVENT_V2_IDX; + } else { + if (econfig) + *econfig = config & RISCV_PMU_RAW_EVENT_MASK; + ret = RISCV_PMU_RAW_EVENT_IDX; + } + break; + case 2: + ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); + break; + case 3: + /* + * For Risc-V platform specific firmware events + * Event code - 0xFFFF + * Event data - raw event encoding + */ + ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT; + if (econfig) + *econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK; + break; + } + break; + default: + break; + } + + return ret; +} +EXPORT_SYMBOL(riscv_pmu_get_event_info); + /* * Returns the counter width of a programmable counter and number of hardware * counters. As we don't support heterogeneous CPUs yet, it is okay to just @@ -579,7 +638,6 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) { u32 type = event->attr.type; u64 config = event->attr.config; - int ret; /* * Ensure we are finished checking standard hardware events for @@ -587,56 +645,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) */ flush_work(&check_std_events_work); - switch (type) { - case PERF_TYPE_HARDWARE: - if (config >= PERF_COUNT_HW_MAX) - return -EINVAL; - ret = pmu_hw_event_map[event->attr.config].event_idx; - break; - case PERF_TYPE_HW_CACHE: - ret = pmu_event_find_cache(config); - break; - case PERF_TYPE_RAW: - /* - * As per SBI v0.3 specification, - * -- the upper 16 bits must be unused for a hardware raw event. - * As per SBI v3.0 specification, - * -- the upper 8 bits must be unused for a hardware raw event. - * Bits 63:62 are used to distinguish between raw events - * 00 - Hardware raw event - * 10 - SBI firmware events - * 11 - Risc-V platform specific firmware event - */ - switch (config >> 62) { - case 0: - if (sbi_v3_available) { - *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; - ret = RISCV_PMU_RAW_EVENT_V2_IDX; - } else { - *econfig = config & RISCV_PMU_RAW_EVENT_MASK; - ret = RISCV_PMU_RAW_EVENT_IDX; - } - break; - case 2: - ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); - break; - case 3: - /* - * For Risc-V platform specific firmware events - * Event code - 0xFFFF - * Event data - raw event encoding - */ - ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT; - *econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK; - break; - } - break; - default: - ret = -ENOENT; - break; - } - - return ret; + return riscv_pmu_get_event_info(type, config, econfig); } static void pmu_sbi_snapshot_free(struct riscv_pmu *pmu) diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h index 701974639ff2..4a5e3209c473 100644 --- a/include/linux/perf/riscv_pmu.h +++ b/include/linux/perf/riscv_pmu.h @@ -91,6 +91,8 @@ struct riscv_pmu *riscv_pmu_alloc(void); int riscv_pmu_get_hpm_info(u32 *hw_ctr_width, u32 *num_hw_ctr); #endif +int riscv_pmu_get_event_info(u32 type, u64 config, u64 *econfig); + #endif /* CONFIG_RISCV_PMU */ #endif /* _RISCV_PMU_H */ From patchwork Tue Nov 19 20:29:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880516 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 AECC61D359E for ; Tue, 19 Nov 2024 20:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048261; cv=none; b=ECmlL7kRTdhUROsUZuAhgk5zYsQvwLJqucJx9MaT0jUIPNDSof7caSrnBFOIH9kVQAOUj0VgI3Pxob9+V5oKkh45EjcTGyTqlOeCxRGDhPuJ4IKmFngk5TsISTBcD1pxGt3QrN+Nr/WTQvmoCZrQrISShzdRZtuauCsRW7xQ/2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048261; c=relaxed/simple; bh=G5yi3iNf9DP3MtmXZ7tHjmD2q1hrql1veCYCyXy2ahA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DObDTNYGpoCyeak+6ahuWl1milV2fBLUZD4/5ItQrptez9Gihv4ax+yT2tCwluBt5GJUKbjkTeFx3gmUQjjwGlB/yf+PKNn096HtpRF/CWH2EuO0ImuZ0UXsx8S68KTN0cZjj1BHOEW7KJyiJkIPiT/D2LlVelZT9jnWnL5s680= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=G2r91jeA; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="G2r91jeA" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21269c8df64so1899265ad.2 for ; Tue, 19 Nov 2024 12:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048257; x=1732653057; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bs99zjzT6d12gvM6MWyIJ6XWCfETAhHft1AvWE2UFvk=; b=G2r91jeA/OQC4RS6mdOaVl+FkMzCE7fuHinMYOjECeEFdAA/Slrc1w2HTsBwxnEx/f 7oCSCbXZNdCkAxUw74tpzD797/7mToCg1MR7XyucGFUtJSbdlV35FE551Dr291pBWFdO hKyIFq7woZ87Cf6uBDWgwCgKuBX1n5tuE7AwuvBuxxx36QeGPDQ1BDY44TFxvl+gSgq2 2V5raGVquJNsNyGDfU/Es8DtUMUtnk/zf30gA5kzM8pLi1vLzSTgzY4EnYtbsrYpi3C3 OrssxWFN/YQS3GrXnUkiAcynEDz4Yx3xX4H3s7WysJoL2Rw7JNEVgQfs6qOTm7+yS9D9 IKQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048257; x=1732653057; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bs99zjzT6d12gvM6MWyIJ6XWCfETAhHft1AvWE2UFvk=; b=ha78atGi/tbDmErQeO6gypH9xB3qrPG4ZfwnII2VKfBbZIp+gBGYX3KOpVrGjeuQ4a CHby3utjihbrvmEilIyXkEi5GmcaCKa1nMP54bu43T1FTzTGfKcti54uwUZyPXsnHThq aYjS/N3GgMkj2RVDrjuAV4eqZ3V451dkEVeT/NtbX5+/rTdJpXvOQNJLw475vxRit71j LTL1hBe19nIlMKtf+Ts3sDhH9YQFGG3PlgPXpLfrVxarZXW+lgiF5PEoMYVBJpkdKg3i qeMUR2cievrZ7AhwsR0b8CA9SvW8QYAXF0Mp0ulK18OZF1o83FUJuz2GG629YEJV3+wX /gOw== X-Forwarded-Encrypted: i=1; AJvYcCXGJI/losssfDxjBmLSxtSAq/PoWGIAPq80dHFVvCxI/VFuUQS+OBucnEhjNNi2Ti7nQD4=@vger.kernel.org X-Gm-Message-State: AOJu0Yykk3Se/5eI1KenUbxI+83NRbpdmrK5LS0AchiQoi/HET9abxKt 51cmVrLw2h3mLDR98F5OcIv/YShz6EbMey7fcgi/YKX+/Q2NwIHo1eO6DwTnNVU= X-Google-Smtp-Source: AGHT+IESHBYfIB+Rw/ycY/laHoMRI9Uw6Iu8jOPbVMITks5jvKXyAK0AlmSBcZiVndbkDkPBOO2Y/A== X-Received: by 2002:a17:903:230d:b0:211:ee35:830c with SMTP id d9443c01a7336-2126a34d311mr3124645ad.15.1732048256798; Tue, 19 Nov 2024 12:30:56 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:56 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:55 -0800 Subject: [PATCH 7/8] RISC-V: KVM: Implement get event info function Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-7-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 The new get_event_info funciton allows the guest to query the presence of multiple events with single SBI call. Currently, the perf driver in linux guest invokes it for all the standard SBI PMU events. Support the SBI function implementation in KVM as well. Signed-off-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_pmu.h | 3 ++ arch/riscv/kvm/vcpu_pmu.c | 67 +++++++++++++++++++++++++++++++++++ arch/riscv/kvm/vcpu_sbi_pmu.c | 3 ++ 3 files changed, 73 insertions(+) diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h index 1d85b6617508..9a930afc8f57 100644 --- a/arch/riscv/include/asm/kvm_vcpu_pmu.h +++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h @@ -98,6 +98,9 @@ void kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu); int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long saddr_low, unsigned long saddr_high, unsigned long flags, struct kvm_vcpu_sbi_return *retdata); +int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low, + unsigned long saddr_high, unsigned long num_events, + unsigned long flags, struct kvm_vcpu_sbi_return *retdata); void kvm_riscv_vcpu_pmu_deinit(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_pmu_reset(struct kvm_vcpu *vcpu); diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index efd66835c2b8..a30f7ec31479 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -456,6 +456,73 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s return 0; } +int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low, + unsigned long saddr_high, unsigned long num_events, + unsigned long flags, struct kvm_vcpu_sbi_return *retdata) +{ + unsigned long hva; + struct riscv_pmu_event_info *einfo; + int shmem_size = num_events * sizeof(*einfo); + bool writable; + gpa_t shmem; + u32 eidx, etype; + u64 econfig; + int ret; + + if (flags != 0 || (saddr_low & (SZ_16 - 1))) { + ret = SBI_ERR_INVALID_PARAM; + goto out; + } + + shmem = saddr_low; + if (saddr_high != 0) { + if (IS_ENABLED(CONFIG_32BIT)) { + shmem |= ((gpa_t)saddr_high << 32); + } else { + ret = SBI_ERR_INVALID_ADDRESS; + goto out; + } + } + + hva = kvm_vcpu_gfn_to_hva_prot(vcpu, shmem >> PAGE_SHIFT, &writable); + if (kvm_is_error_hva(hva) || !writable) { + ret = SBI_ERR_INVALID_ADDRESS; + goto out; + } + + einfo = kzalloc(shmem_size, GFP_KERNEL); + if (!einfo) + return -ENOMEM; + + ret = kvm_vcpu_read_guest(vcpu, shmem, einfo, shmem_size); + if (ret) { + ret = SBI_ERR_FAILURE; + goto free_mem; + } + + for (int i = 0; i < num_events; i++) { + eidx = einfo[i].event_idx; + etype = kvm_pmu_get_perf_event_type(eidx); + econfig = kvm_pmu_get_perf_event_config(eidx, einfo[i].event_data); + ret = riscv_pmu_get_event_info(etype, econfig, NULL); + if (ret > 0) + einfo[i].output = 1; + } + + kvm_vcpu_write_guest(vcpu, shmem, einfo, shmem_size); + if (ret) { + ret = SBI_ERR_FAILURE; + goto free_mem; + } + +free_mem: + kfree(einfo); +out: + retdata->err_val = ret; + + return 0; +} + int kvm_riscv_vcpu_pmu_num_ctrs(struct kvm_vcpu *vcpu, struct kvm_vcpu_sbi_return *retdata) { diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index e4be34e03e83..a020d979d179 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -73,6 +73,9 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM: ret = kvm_riscv_vcpu_pmu_snapshot_set_shmem(vcpu, cp->a0, cp->a1, cp->a2, retdata); break; + case SBI_EXT_PMU_EVENT_GET_INFO: + ret = kvm_riscv_vcpu_pmu_event_info(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, retdata); + break; default: retdata->err_val = SBI_ERR_NOT_SUPPORTED; } From patchwork Tue Nov 19 20:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13880515 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 ABF351D86C4 for ; Tue, 19 Nov 2024 20:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048260; cv=none; b=OvnukXanoTYlxq8rTsi5s1RwsBoP7QNXExvTXP2dHjxJJt7LYa4mcofwKPw9snP46EYn4yQgCCRGg5UGXGMLclxt74vadxpwfdE+z7EXFnWztGSSvJN6FPpP93zX0e9YWtmsXBz+kZSBwhFDiRac6NWizibFknaQws0rkk0aUtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732048260; c=relaxed/simple; bh=I61ANzW3mMGNw+TsEklnF5HMFHS9Ft60jqTehlaG7hM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pq43GY1NmFRY9KGKdTjNzyy0MM8BGLnRqrbuiBA6qgWHs7LPSbMwnTbpID6CIXey/UoyHiBWvrbSL5UMFOnvbDpYeSGG2fP3+5DErHrKgJXyXBtS8w/gSXKlGPLkIOFEskcAu4mvxO0YqXRytJ/mIzafAV24PLI75tAxz5arddg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=Ayez7NoG; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="Ayez7NoG" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21200c749bfso32889975ad.1 for ; Tue, 19 Nov 2024 12:30:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048258; x=1732653058; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oS1moOcp9ct9rXCWQSjf/GhpQtGR0rWY3wjXVfG0zao=; b=Ayez7NoGQMC9UcHgiyewYOdCCbHkBpWpfNnPlD4oJkCVCqo6aySmmHdCUC+kj0dNYv IT/9SpjthbtWdrsPnBv1kpHKQeEO1GlcUJlTUY0mRFcLJjE6btuC2l7iQ5F/QxMKAlKv o/APu6wZLBpE2CcFYmkWxJ1EIUKEfTV0Dpmx8j5RI+TfkV0Ppd2ff8JdVxnLTAg52pGG BThnI/HKmh7yfhWwZdp80HJa5GomB1DcdtWtrhop40ItRulHCA/PMh7rfhq9k/Y4l9CX PdcxIX2SgwN1c+wjEgGlqXMKbfX1hyik0ZyBqu/rE51dgQeHOIECbN1dVeMnp/woa7DF 5aFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048258; x=1732653058; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oS1moOcp9ct9rXCWQSjf/GhpQtGR0rWY3wjXVfG0zao=; b=ZFVXEbvPEqFvyhgCAyqJRjJvAbdpHSJP8sL1Ie+/wz4qxH0BJ6waMWF6lSlxaB3oHu 0NSEO4pOtX0LT7av5XvG5qOnSFgOI0FVCiCVP6qyCS0UxwfkLJ6aHSDqa3P2vjcUX2/t eHAgtoSI9GnSrPr0nx3l3bXcD3VxHI8DN82Zx6pk+3ZN8vAcwt8/ei7NjEBu9iCPnen7 zJencyuPEu5Ria0H+kSf7xymugwTmLCs6VSxO5v1PUlFP00rnxk19GhCkXXYZeQWjUXl AOHUYx1/gMUXD/6HUUnrg2YurGTKxOd4/il99T8iINAVSBrZmGrgm5w/MXaoOYGnEsDP C3Pw== X-Forwarded-Encrypted: i=1; AJvYcCVER39PxAxF7bTjE8icHX3nQPqRUxs/AaOUyoPaeweOLc3UUySw8HDFZoCSJwp5m3v282w=@vger.kernel.org X-Gm-Message-State: AOJu0YylbgJVEWhEV7OurHAHqRcfd2Z85CGnyQ+tLtAzooE5mVoW8EIC X46BMuciDaC0yMy+UDZVNqTA2db1uUUNVwJznFx606QVBk2N2TnFtrtPujKBTzc= X-Google-Smtp-Source: AGHT+IHJJKUj/G9a1vcUatY4x43+GcKI1AsZDcQ+KjFbu3ubgI0Q6fpviZE7gWtG38yqh7oUq4m8sw== X-Received: by 2002:a17:902:dad0:b0:20b:7210:5859 with SMTP id d9443c01a7336-2126b07a574mr1668385ad.38.1732048257883; Tue, 19 Nov 2024 12:30:57 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:57 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:56 -0800 Subject: [PATCH 8/8] RISC-V: KVM: Upgrade the supported SBI version to 3.0 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-8-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 Upgrade the SBI version to v3.0 so that corresponding features can be enabled in the guest. Signed-off-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index b96705258cf9..239457b864d7 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -11,7 +11,7 @@ #define KVM_SBI_IMPID 3 -#define KVM_SBI_VERSION_MAJOR 2 +#define KVM_SBI_VERSION_MAJOR 3 #define KVM_SBI_VERSION_MINOR 0 enum kvm_riscv_sbi_ext_status {