From patchwork Wed Jan 15 18:30:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940778 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 5A3191D5CD6 for ; Wed, 15 Jan 2025 18:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965860; cv=none; b=FLMrcnjR1yqlk4E+r+4kMRTQdD9gryjhXvOAqwDD6zoJLkIk9F2e3sfZ8liT8zmLsA3TM861OUrVhFCVYfOASW4s6oZsjpZy0dGDq8/7rYG38c4KcpSzA296zwgtkvAw4XaB1hL0pOs6r8yy92PaUtBwbrP5Gqd8PZ6Xkqae+VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965860; c=relaxed/simple; bh=IRi8vvVbX7RcsNkx4/mfVGVQ/4HYTvSqhjj1SdFdZyI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kZbqqpD4UWGO1cncyX2xVG/XV98yUotaySgtQlzcOTHgODVZ2vF287rY+nT58+u9xq8XmUF6e+QJlWLB6aM+vDLaT++auH8qSfQOJJ4ButSCuHID/R48jNLMtMb/mk6dOGLQJcQBd2kjYsfWsk2l5OjN7/48eIpKb+YdzyaICeM= 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=XYRyoTc2; arc=none smtp.client-ip=209.85.214.170 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="XYRyoTc2" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2167141dfa1so1960975ad.1 for ; Wed, 15 Jan 2025 10:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965856; x=1737570656; 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=R6MbfDRCc6A6mGBsw+fhL6wjTkBIFejSaI+SDSiajdA=; b=XYRyoTc2U8kV4DIQcSsbHRuVZPEJ7XTXlz4mBbp3Fe1SPyY6O0kGMB5VeLH9eKXtUT 9i5XEXFAsXkRUiEMP3p16BXz6nNmtaD/nxy4G7+5B/fmd1zR2jDj7Ni0L1k7yoOCkWwI 9hPpPwDYTLKVGxnTAM+PymX/NcU5SsPAAxWh1yCLPL8EDJUFutiWWpD4Z/4yiCDtcN63 HlDlpn3sES4CNQIEfc0KnYFPiNDGh2SY4c/EOBW1Ar3jrMDa1s0F8MSQ/rqjBsZYfpYS fV/kv1zYSL0nkEc6NlhI/WfHHTYtF+QYosqDvaL4ELWCcXq6JOr/HABfrB23SpJpryHf sFvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965856; x=1737570656; 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=R6MbfDRCc6A6mGBsw+fhL6wjTkBIFejSaI+SDSiajdA=; b=Mu4S9hWd+jLczTbnNbIX/aKRzZkzPhwWzLmfOYfUARyp90OM7Mjf5fUljlQ7/WZaDX fVgToSpQw/rIDMqfweM2SsTA49u6OpwP+5r2AEct2NNKTgNnlpa2YMtHOkV2rQQTjn0G SVpDva/O/ukKVmQTn/QUv5artXmzwwIWoZlEhSOwR2TMcWJa766IlJHPPT5q3hCfOomO 2rbAETb4kynKmfxaVaQ85A1iALBO4Dbe2MZlqspe2jkFZumab4aE387zmnY6SRsGpgx+ fcGIYtfbd+kqIi4zrTHAPafkkkfAhnmhjt20ERC1bT+qhQmoK/gmAYdL8gdmat85O8+N 0fcw== X-Forwarded-Encrypted: i=1; AJvYcCUl/SwroIZxnsnBjmcNQR+iKC7fWSdtA/roLcdPeNZKHRYKOym31xcJkiQVFcbqoLMTekg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8uOW+34oyCYtq1NEgxau35AsITfVHS9bikdbFS0jRHsbR5kNE hABY31WxFMW4ADF0EAjNdZ2oUTQoNxOuTnL302YxG5YCKYX6BZ/1pXh+meJVeNo= X-Gm-Gg: ASbGncsfgOJFF0IXBHposB0gmUZU36hQEYzDlrGfzkVDGnbqOSKrCUIHJZ8NSDIulao Hqxy+OG0lCVlSFYa8VMfb+0wTTjtCHBKi9SIc56x7+KBnWMk5YjVNaC3HXFMPOyWqV/6WoW88SA rhgPIt4V/uqTcrcPoJQhx55RAvZCKvlg2BikVhHHpOFLxA5hfi8pZpXMYmNgjPkD/bNk+Td3kg1 f+Az/GexRg6KL1YL5IBUQgUQ2E2HNOm81UQ+9COQsZgE2Hgu81VOyLRvtOVRPqE3x/sTg== X-Google-Smtp-Source: AGHT+IGH5/giAEf8Q/ecUlIbOiNlBZurjf3IoH6KsqiI1EGl06ksaFaVD7yVqQ1dvhjlbV18FEvXig== X-Received: by 2002:a17:902:c40b:b0:215:ba2b:cd55 with SMTP id d9443c01a7336-21bf0b76a12mr58588755ad.2.1736965856596; Wed, 15 Jan 2025 10:30:56 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:30:56 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:41 -0800 Subject: [PATCH v2 1/9] 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: <20250115-pmu_event_info-v2-1-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 194c153e5d71..170aa93106b9 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) @@ -1452,6 +1453,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 Wed Jan 15 18:30:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940777 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 693101D63C5 for ; Wed, 15 Jan 2025 18:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965860; cv=none; b=qSdNbqqaKcOyNdkejvnM9cR23Ke1NIEvfxxPV3sm+vny3F74QzrIRCKauCjBQuVVBO92jtLDWjv7WWRDYtzYNjNitvaof5gYycPEPHJmhjV5shmx6lxg+qVGV85KOHGjB3JWpFFuaADcI2kfVCMifcPnakMKeAbdmYABMZVwjsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965860; c=relaxed/simple; bh=C2yg3QgtuxibTBRy1VBsgb98ZP1o7dJeXGlHHQuTfM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I5YcUGzBetbYDFr5h1QFUAkhyAE1w4EEyO436HdVn1dk73S/2QnexiUZf1g5mc3ropkMj/7u3VJvFFiCjxCQCuqKIwpBjLLwmDZMNre6sWXVTCx1CcdUJNzc7sKtE/W4V1pRnykhrNDbD3u0eSmJ98hXEm4VtfkVJkJOVbyRYrk= 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=LHs7oues; arc=none smtp.client-ip=209.85.214.180 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="LHs7oues" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2167141dfa1so1961245ad.1 for ; Wed, 15 Jan 2025 10:30:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965858; x=1737570658; 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=nTd9Qo5vidtOLE+cxHwuaQqNzwk6goJIP9mJXkel4TI=; b=LHs7ouesPdcBD/sHmOaAIgtbX2sEhwhBDScp3XPSeRssl6YoRva4njcBwMEoFySyPZ lth5Ocg8Fihq6ncLEatWf+Bhf7foPy3tdSqiG1NbjB1h9+F9HGLMpNvfPgWrxqr1FQ5a ldmCOCi6yjymuzY//9GQT527aZvCE3/yIJL6PYE53FYNz0RUqXoUwA7SJG55ghpopSUk mgOPU5y9iPRm+rxQlVhVvPk0qnV8vTKzF4Jw8ENyyBIoje0m4af6SNRF8hGwLsNX2eLk UPyeCPub0grs8IfPTYm7H5PWKeR2JN0W+ityrjy2GZR8DFUDF394vwDDawzBjXCt8c6A q8KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965858; x=1737570658; 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=nTd9Qo5vidtOLE+cxHwuaQqNzwk6goJIP9mJXkel4TI=; b=moMP8YibHGrFWRl1YvAYGCayVolEGJqKZuH68vERz03zqpFqMoh3eTjKRpuVa3SIQf cYkyHKPgFtDyBlqvbBWCb06Z4yvweXskXUD7ZyjFW2gXt0iHsnjPhTwz7fKdN7ga3NQ5 e+LaXpMe5soyj8MMDjFgkhrATcrnKYWuEpETQkhqgOUn8A2uY0FYQWlRjIEoezToV2CG iQy0fery1JSoZ/M9Ht2ULSkKAyiwabzLggP5vJ/8pGcujYACy72wO0/OClLgJ7aIV5jA UGtkjzhN/gAJxkdgKRCoKOnMX7sFSxWged4uEodiq1P9pEZbp4Tsf+IzfEWSSpzPJou0 Z7Lg== X-Forwarded-Encrypted: i=1; AJvYcCVN+aokehA9+0oZtAKUVhL64nyQYZ2Q5YiyPiFxkvpHAmRi5TG+krEAEe0SG211toC5RtE=@vger.kernel.org X-Gm-Message-State: AOJu0YzukE0Q7ljcdBycjHyrxABfG3SjgKk3aZn7oItgDSaRDyO1iCPK iQlNFGWvSqCWdvRpezecGUYDQ6jSECwkCaejzGNpF4ZMFUdAVjks50zGEW5mbI4= X-Gm-Gg: ASbGncudoxdidHerRfGWsunRCqnB36eG9oonBew2SpJLx88gSnCU1+YHw/+Ql3GxcTv 8fNpyOgxGuCNwEuqxNNKm1w+P1qEGae+A5vTnW0tgf2Fq9O/2B93yhF2PbHnDolPUss4szf+tol Q1bgY8NZEKM5uEhKsTnTDsnqeDLikFBVn0S+ONzE4aYOq4vJBZUj27XZ+K28gULoD3zRhIoqdlm ckZVi375ieVfOvEZ06eH2LRg5aJdUbRyUBsMVJTFo4F7V8P+JggdQUTwugJBF04uUczIw== X-Google-Smtp-Source: AGHT+IHHO3B1HJhEuywvwBIX7b7bfSC/4ve6r1ZbOzw3ZYVhbL87vWT2YRpjRvKHUMwV10zBAIgK0g== X-Received: by 2002:a17:903:2291:b0:215:58be:334e with SMTP id d9443c01a7336-21bf0bb89cemr59154695ad.10.1736965857674; Wed, 15 Jan 2025 10:30:57 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:30:57 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:42 -0800 Subject: [PATCH v2 2/9] 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: <20250115-pmu_event_info-v2-2-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 3d250824178b..6ce385a3a7bb 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -160,7 +160,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 */ @@ -218,6 +221,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 170aa93106b9..5d5b399b3e77 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,8 +527,10 @@ 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 @@ -537,8 +539,14 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) switch (config >> 62) { case 0: + if (sbi_v3_available) { + /* Return error any bits [56-63] is set as it is not allowed by the spec */ + if (!(config & ~RISCV_PMU_RAW_EVENT_V2_MASK)) { + *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; + ret = RISCV_PMU_RAW_EVENT_V2_IDX; + } /* Return error any bits [48-63] is set as it is not allowed by the spec */ - if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { + } else if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { *econfig = config & RISCV_PMU_RAW_EVENT_MASK; ret = RISCV_PMU_RAW_EVENT_IDX; } From patchwork Wed Jan 15 18:30:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940780 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 DFAFD1D79B3 for ; Wed, 15 Jan 2025 18:31:00 +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=1736965862; cv=none; b=W4sw4NL4M9OxfwweUgd7VfAV6+/EWy68XbvpPpb0U9bQVgOhzJyfpsapxTX201xBNmgtE2LKLbPxErY6uGbLitZeUeCX43qvHF1EZuvTrgks//VlXvGtwYQKN2hg449r4UczUA7B8kCjgdYk862JhpBMmKb3APsz2CBziH8Lh74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965862; c=relaxed/simple; bh=rkpDrsA/PVcggHd7+EAEFge1PhxYTYtvQjpCCjdH2MQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f8WPEr5MLd1WYx04wjynrfOKVadtbvYSYsngAaZO52C/3U7ZSioFub5Ow+qTOE3O2NvqPmaUum+MGgHh5KPCkoCjlTzF2MKAvtfOalh/qu/z8h2cmjRuX3LmIzi5x2cYNr5dQq56/baGz19RpXN9xq/F83IYFFm6PHlDc6p8wog= 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=SafW0OEp; 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="SafW0OEp" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21634338cfdso128148795ad.2 for ; Wed, 15 Jan 2025 10:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965860; x=1737570660; 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=SafW0OEplxokJRfKhuKd8E1XPRTF0Vmf+rwKUxy7Bql4BO/Bm6g1JH9f8IM8UnOh0k fP/obteDSt2zfXPDzdxr9iQGSeOtIa1extE3vgjzWjMFZvzHutWSmU+sV7rZTsMqHpLM DxzSp4k9rcX//dgChIPPB+lqUsK0dJG5QhhtuHi1gIL8FFZ9/z5wzUoxjBYYar/qm3um VaJgf/T3iHUScBAlH+xyPiVOc0iqsI6DmlJieU+Xbk6l3RlVn/5Zg6jEByIo54MZu28S XvkqQezAF+QQieHQ5Dh8NFESYwqFdDPL3+6E0Jckyyd1l1bRT75yGmbHJYQY33q7me9+ X/qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965860; x=1737570660; 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=okZrp2BwMZlvCkq0RSYt2VXGbWcmQk8JJyoN6DdICQUdyyj/PSN8npgWhQUvs2jEBy Eyv6WarjU6JC5HFc753fItj8aN40kJZMc4r76H0K96MKPXOK+ao5FktoCZJptPf2SFLh OvqeN6oxwrfA6o0kBcDQ37bsqtd/lBOw+jwsg+DokgG2solUM5BMFz46lvb7UPfNh5pV DDeaalYovPLoOYCO+xUsxk3mxeGtgEPeqqg8rZvOO1UtFQWInPM5vbTqz7SyKD9O+6T4 +8chAJBTkHo7izaxAg7fkAuK/9onw4Njswydw+otwzkTFgHmS5AbUA7nfSAVVsJ1du1g HX1g== X-Forwarded-Encrypted: i=1; AJvYcCUTTHqMUJVmCtDUn388cvywI3Iwyu0nyWhuYVszzu+Rvd1OywYaIv3LXUEiI0/nhPuNklI=@vger.kernel.org X-Gm-Message-State: AOJu0YxhnGYFJHVbfG9pED+0sFusTxHXIkZdXJPDAz0VrusDxDQNpVpq 5uNCR1n6LgQDSZ04aBLhyUMt9o5iV4Fpdz3XgMx0OfiKWNbviKx0Su8hQbSS3fY= X-Gm-Gg: ASbGncscMCYUBbJ9F8PFICbMSXp9x+Zy8rLPqhNdLOA+w//XVmbU2Dy0cCoIjSa0AF4 DnQkqNicQXMjwzTxvMrJnndYkpvCzbXWKzfjazrazzj2QhMYUCQQfp468IeumBsq+QmTBdaIkSD J/fyBB/nHVbmgZ/dG9062I0iUd+hNNlTbLIBC7tc5BbB0lufF05L6JYzV9Fbg2NKAmFc9kpIVU9 2ArSuNNNAElUf+bUVU4z/fUBhur/XUaY4eDtsf+9KqmVxdEiwX4qDLJk4a3MhSlNVl+RA== X-Google-Smtp-Source: AGHT+IFhv3d+iNN38adFn+dH29zIS7C6pmY5MPy1fONgMvFeK1H10VHPHqcDN6p90NhFpRdpeycXlA== X-Received: by 2002:a17:902:f68b:b0:216:32c4:f807 with SMTP id d9443c01a7336-21a83fdea82mr472230285ad.45.1736965858786; Wed, 15 Jan 2025 10:30:58 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:30:58 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:43 -0800 Subject: [PATCH v2 3/9] 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: <20250115-pmu_event_info-v2-3-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 Wed Jan 15 18:30:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940779 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 7E41C1D7984 for ; Wed, 15 Jan 2025 18:31:00 +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=1736965862; cv=none; b=sb53+FwyMxyB/mK4xuoqreKtyMEKOasKMJYJzhAV1oHzZQslDdil+WN5xbg4NOmWxVdIA92pR/nGK1rc59WoITCEjw7RoU8MEglJ8iA+IQG7rWZlL2MWIpQ07+YZwTG1o94EU290S4jzN42zxI+9zOLiTTxFgZBh6yRUV6Kjgok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965862; c=relaxed/simple; bh=OfDSy2joQdVcFT7jBgw7uGk7SzYpOcCrRH83Sx1YrrY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qn+WTDWM0Eh7NI/WdRS7zJJrApeJVbDRTBBU2uxqyGbkCZEac4TaPSp59g3cDLB+grjidNwG8Y5r0K5P9L1nMJDa70SAMT4jUCx5M9Vi8xqLgLzd73+H6Ekjfz6IrYWHWZ75LYfqS/TFk6+XXYMRYqdXfOwEvw8Kw6mZ+ayl6n8= 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=QIzv/UB6; 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="QIzv/UB6" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-216395e151bso1994935ad.0 for ; Wed, 15 Jan 2025 10:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965860; x=1737570660; 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=JC3EeyOvWf7FtpVzWoJ1Ny8l+dOUVPRncQAFsx1SwlE=; b=QIzv/UB6l213YYMuhc9jNO5TWyOxr13SOu3SQN0cCWV8cx7dAyUbWpEV4V4tfDadF4 sJlC3fbc9DE6M+q/bZBd+337fmI0Ceb+uK4OZdymD0sMPA34rzkjYGIhWe4FvgElAVT6 Br/sv8nuJqosPsK4oXk2eDQmtoxvwjggcE3ZaW+i8PfYApj21z9DqU8pl5nCRyLoWrry jJ7hmhYIeHIc8ThiG6CrTBIffdNtoRN38JqOQz8E+jRsPp9dS+TtXueY1WyOuVQ70jx0 nlxo5dmf+gE1CbhS3Zwm7Wl1hXtC6JG5uv8v1MfFNOhft2cB+fLSMyhfnqFq4eItsQ5A 99+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965860; x=1737570660; 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=JC3EeyOvWf7FtpVzWoJ1Ny8l+dOUVPRncQAFsx1SwlE=; b=uIs2HW3cKWeGmO/XvlifFUmIYexdT9eDaScyoxV4uROE9co1czsmbZjWEnIhuYOZti ZhvLNQrTdrQLJZsjPeEcWztBqSrhIE6TX/3s9FWnudEe1rI6treBeZ2j3bTPGGxm7yAR CpEBMefNeyuvVVy99LrDBgPO9RXJtoU5gZzwEDmsdjc3qoc3c6Fnbeus3l1+lKs933J2 lrf0hxKf7Dtlb59QPSH3XgvzOva46SYGvfl6PC9QVGQRUUO2uUKkPmDpVHe5KpUp1spx 0UubNybHrtNFhQF4H0SvQF5bCr6nkB9iKWFDwUVbOvr5XkMPE3D8ucuXgtGsrvduYO0m QWNQ== X-Forwarded-Encrypted: i=1; AJvYcCX0LpTyxErMMpJgt3BPkQnb0Sy4S46oxzdY/uhBx24gO7uJxEDwyAxPRB0TFukwTzDe4vc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywsl6sqEFfLpz2jYRFDTzcyfCf/o6hBl0RT4Hnnyz0/jKshp7Zh WJ95AIHpqjqibxi+uec6kPJwUO/wiDr7OT8KYANfCAsVS4aD4BzgjDZXKXdMqRk= X-Gm-Gg: ASbGncvilu+cmLbbeBtVbxOKgUsvbHrZIFxSAInOcxu0g+f4Zm0Sp4WGQ5WOK7OqF2N ZTBnMN8t8MQRrbH+WycZdKzEgkAH7ORF9tZKv5ZAhUsxXEU/CqXIc6f3FaRoar5PTlrORRkGOv3 8ix6NNR+bOv5ccVs2u8ZPYKHHB0mUpdPhg13vFo9YcEpqG+L2jq0yTnDvrRZL2ex1O/PoQoxRbI E+X0x3S3uW3YTNwmz9s6mkAJJSHQM8ACDvM7/f4eFO9oWUsOm+kRe+3X4DszOBgA9QEPQ== X-Google-Smtp-Source: AGHT+IH3olozIYSo4r3r15dhiFKl3/3XHwJwjdJ6AtULTMFFycwztXRXf6ddeRVzYwbOviD3YM/ZOQ== X-Received: by 2002:a17:903:1107:b0:216:5db1:5dc1 with SMTP id d9443c01a7336-21bf0b76a05mr61009835ad.1.1736965859902; Wed, 15 Jan 2025 10:30:59 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:30:59 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:44 -0800 Subject: [PATCH v2 4/9] 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: <20250115-pmu_event_info-v2-4-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 | 9 ++++++ drivers/perf/riscv_pmu_sbi.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6ce385a3a7bb..77b6997eb6c5 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -135,6 +135,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 { @@ -158,6 +159,14 @@ struct riscv_pmu_snapshot_data { u64 reserved[447]; }; +struct riscv_pmu_event_info { + u32 event_idx; + u32 output; + u64 event_data; +}; + +#define RISCV_PMU_EVENT_INFO_OUTPUT_MASK 0x01 + #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 5d5b399b3e77..7db78c7a1524 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -299,6 +299,66 @@ 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 = kcalloc(num_events, sizeof(*event_info_shmem), GFP_KERNEL); + if (!event_info_shmem) + 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; + } + + for (i = 0; i < ARRAY_SIZE(pmu_hw_event_map); i++) { + if (!(event_info_shmem[i].output & RISCV_PMU_EVENT_INFO_OUTPUT_MASK)) + 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 & + RISCV_PMU_EVENT_INFO_OUTPUT_MASK)) + 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 +376,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 Wed Jan 15 18:30:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940781 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 EDB321D86E8 for ; Wed, 15 Jan 2025 18:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965864; cv=none; b=UpToDKzDbPA90yTCDlum/BwfpWgWgTYOazU1SV+wlY9somxRvt/zQfXbJL1I9w9euEqZledMOD3XRpSqJO12H27vSkRY4PsXjDs8GXSUPoINjvIclTnLvcmIr1EkCKmywcIhwOziwzaHL6MOI6oxKHALQFYUNInYijLHQyGzn5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965864; c=relaxed/simple; bh=Uf4BWe2Su1lIPZDq6pdPd4bMwgYHVB6D6W9CaX0xEmk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AjawV47tQiXWerEGrQaVg0ABsDoFBQydTWyp1m/RXUnHZ4iaq0S9QKyvcoB9ef/+Mni8ZjUsPAy3d2ff0tydAUtSaqsShliGGFmL19s6kOcNgRGChi3IGjnxX70PDe5GSSRFFz3H7Hr4qTIs6JkGb1eCRG/x3023VQdlm3JubIs= 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=yNOfiTrR; arc=none smtp.client-ip=209.85.214.174 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="yNOfiTrR" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21661be2c2dso127639265ad.1 for ; Wed, 15 Jan 2025 10:31:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965861; x=1737570661; 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=tgS461j5peg/wBSc44BcdgWOlZZ4NL2WfdCTDE0Whhk=; b=yNOfiTrRvwmwGMEZLTTZC6DbsW0lNA0L6cAfU2g81MFjTKau1TteK5wcXBJsTVfiCS ch35NA26nXXzDZt1oMoGh4ivSLlb6/mFNgLPzluHWA6kXRfiWdRtyQpksBbplECzcERW pTpBXx/KrIb5SSDER//wytUXtFridb7f4XHEM0hLUYp+kskQjUj25/hfSr2E5WvmkF/H T8V8Y5hgta9YfE3xBUlQuCj62KUZCtHl0exj+JpL6QnOzflxCnt4uGNsC55s1JAa6jOH pcYIofoWukGDB9sLCcMZMfzKq3HUv8F55GoSJLFmP6KejN8ABXEPpoMyIANBFqhYe1ne AIhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965861; x=1737570661; 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=tgS461j5peg/wBSc44BcdgWOlZZ4NL2WfdCTDE0Whhk=; b=MjyHYBvorA0oxY3F9zR4afCNBB9kLUebbO5wU8irBII53KcRTcJMc4JVcHroNaP/in 1p5nO2/jcouGUmPNg36vR+wk0Si0uiAW1Ux70diVHPQE0OL4vaXEN7RXazbzter/iOis lQkza1oelP9AUq6cy5iPTu5nAnstNNUcpOhtGktKyueZkN4Wc/DnkO//cxxpwW6EuV4y KWM7dizkKu5kqIwyfgjJFRK6GjxFyhkoTFUBM4P5VE8IHOp/+XHGGuzMjWu1SHPxQeIq FYMzFKQmUTyavkXpaK6b2xXX9Yv86tXewzQpScU8aYRrI23fPK+RbdJh0JIEa0/IJnF7 TgWg== X-Forwarded-Encrypted: i=1; AJvYcCU7s+rjhoPk2KHlBsrT0yK6No/gDZdO7RuvggUkKifW31yKbFrWJQWptwK6d5ausInJ/V4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3XCcoNggDBdDL+CsToHWAe3a3RQB1VrhKq1AC1/ewY7WKT8k2 AaAYXQMbmxzTPXZJE5f23D36vLXBG6xs7FN0H83rnocWeNzxnjQNtcKWWNlgolA= X-Gm-Gg: ASbGnctSY+N2g8QdLmv/eFpHd2/whd6BbGztXk1CIkkQPvxAXLSyQW6dKyq/1ZqtonN 0BXLZZ896ZI4ZqrlDeaOOvG5KmKlOMEBbiGtIMb6R1qQwEpU1Cfjl9ait7HFQ5xjECX1Gg6FlsJ pE8i5TZBZ+UpYK7pQKHy20iC1mIFDH4c51SSDYaTGBiwXCxXvbjusIYAYc7ikbCmQli6gN9mzWp t2e8gGuLzaKihNTvUCmDgA1BiLXKbH/VplKXWOLXhzpO1xiH8zEougQW1Ix8RVkk8Lpzw== X-Google-Smtp-Source: AGHT+IG8TkzyWt94SBOJrOOqLMztl8kBVgG7Yj3MJPUrXXsfaCQL4prK7YB1Ze37aKg7tg/myTnREg== X-Received: by 2002:a17:903:2348:b0:215:5a53:edee with SMTP id d9443c01a7336-21a83f36f56mr441100595ad.9.1736965861248; Wed, 15 Jan 2025 10:31:01 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:31:00 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:45 -0800 Subject: [PATCH v2 5/9] 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: <20250115-pmu_event_info-v2-5-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 | 124 ++++++++++++++++++++++------------------- include/linux/perf/riscv_pmu.h | 2 + 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 7db78c7a1524..f311daf63ece 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 { @@ -411,6 +412,71 @@ 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) { + /* Return error any bits [56-63] is set as it is not allowed by the spec */ + if (!(config & ~RISCV_PMU_RAW_EVENT_V2_MASK)) { + if (econfig) + *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; + ret = RISCV_PMU_RAW_EVENT_V2_IDX; + } + /* Return error any bits [48-63] is set as it is not allowed by the spec */ + } else if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { + 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; + default: + 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 @@ -576,7 +642,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 = -ENOENT; /* * Ensure we are finished checking standard hardware events for @@ -584,62 +649,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) { - /* Return error any bits [56-63] is set as it is not allowed by the spec */ - if (!(config & ~RISCV_PMU_RAW_EVENT_V2_MASK)) { - *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK; - ret = RISCV_PMU_RAW_EVENT_V2_IDX; - } - /* Return error any bits [48-63] is set as it is not allowed by the spec */ - } else if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { - *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; - default: - break; - } - break; - default: - 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 Wed Jan 15 18:30:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940782 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 8C5581D90BC for ; Wed, 15 Jan 2025 18:31:04 +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=1736965866; cv=none; b=hpN+/RF7HB5z//AVIQ0a/xIVvzjKRw1ZfOAnPEbWBW+yf9wq7ADpXMnPfRaAySNTkBtm1OlI+SzILGLefbUymYYtSVOYfNmtBeMn8irgPaG3sfDcapeQwQdqxj+UPhzMvxcOwBRR8cSTR11kDQUfGiWZi3C5B9K8lH7MIOBDmYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965866; c=relaxed/simple; bh=2VZE7ahRiWFyeef1RfOaScKQMn6RmpORm+fo0poup2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LxMCYDlDwvlsAppIoFgYVxM2aPiTs44n0fILYKyKfU+ftIGp35lpsx9i2vy5qtPMgijBvZ6GiwGKYiDG1v8WWYW+ETKP6NRwo+m95RB05f+dZv1ddLR/oMNOEZ+mV5sA9inl/MP0MGvtC2/QhJhU3SUJhln8AQ16dQi1Y7FKbpw= 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=nkWp8jfH; 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="nkWp8jfH" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21619108a6bso126527325ad.3 for ; Wed, 15 Jan 2025 10:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965864; x=1737570664; 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=eGsO74qlfZsPi9kGTe6Mf3rItgKav5O5SJKk6N7d7+Y=; b=nkWp8jfHWt38tCi3A89AHaGElaPgfNyRMPfRv4RhE9DWQIIIeR1W4OmpSHrz4EbW6y Bqh7GxEOYJ8l7iKj9oVom+0EqYn6XaJ8/+gQfXiEaXuQ4uM7FHu1CP9RTolrfYDjj5AY VSDKg9JSdqeB6stLmPAMMvft+eHpBIObRSzVJC2PLMPYABIOQ06R5Zv9iKD/pt2C3jLW 1zUgcs7HG1j78dLCh/adaE1LF9ZJ1tsXKNCOwL5U9XaECPxxlPyTnpS6Vs3LLCFEECgx wJxEsGZNnILHRGsLPP3nO6X1m6+i8ZVxFj75POG0gDH4cfxNt0tc69Q4bxV2QdqpGZgW 5X0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965864; x=1737570664; 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=eGsO74qlfZsPi9kGTe6Mf3rItgKav5O5SJKk6N7d7+Y=; b=Ve9Yw7BX+f1JeZdRab5wlPIazwgt2ojshI43RU52beiWSB3VsAS7qmCio7O06ilU3v GwuvUWT0Qy6lOB/4TMcsyGVS6ijBVeJt5u2weeBRx/IBlZ20K5ETYem1W8d4Www6oM2h BR7P5T7DXMfmc0pW4xvcD6vK36BoN6/RUsGW3pSkUYVxlAXm14YBJFYRWJIZhLpHEkbm RSgTsr/0BWa9D61En2ED3gkoM6Nt5zdLch+lb/HhXThrkTR/WbMKxnxZCILk6bpqrPnm u8KvO8Pe//eVskYEUnOLMrfcP9E4+2UylaiL+8Ug7aYaidS/Tex/j/xyuiuZeVj9nHrJ GqQQ== X-Forwarded-Encrypted: i=1; AJvYcCXPKLBT6Rt0HnpXDRteH4xDduX4Uke+1rFMaw+AHsQbMAnsC2Vig+WeQAEINfdgnO0cWB4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0oVMGEtLCPvFM+Vk8Pau3sROYJXpS/e8oEekR5lGrcw+MaPf5 9gS1Le8e7D4V2+Z041RKUiK8ioavhgbNRLFhvb4TQHPVquxjqUlNYbHBdYPg25I= X-Gm-Gg: ASbGnctTli12xYg3TAKvMia/8n+PwVUAmMG38HLholLRxW+7rd1eBl7EQpbve1XgPvf XwLTLI3U9Y56m8rRIpq7/OLQ4Ds9ypSYJhHPNi0xcrmOwOTKAcf+2XFo3cbEDkzE7Hbg8f+0MxX +WZ1pxnOYKzBEp9Yo5mwdohRZ8954l2GKEijpACK6VIYWzgSHvf5hciisb9PiuCOXsk5RJH65ou BmdJFWoWE4llO3p1bw4idIOYV3W4TG1rZ05RGmCppoKCUfS5jCQR6e9TbOiX8q/vMZbjA== X-Google-Smtp-Source: AGHT+IEVuy0zAtOEk7axH9BqkY46Q1CUJK/CsgMJYOIS0qmHtHOLlyWCGQnQHM7bf0KJ01YfA5xjlQ== X-Received: by 2002:a17:902:cccb:b0:216:6769:9eca with SMTP id d9443c01a7336-21a83fd35bdmr452990815ad.37.1736965862343; Wed, 15 Jan 2025 10:31:02 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:31:02 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:46 -0800 Subject: [PATCH v2 6/9] KVM: Add a helper function to validate vcpu gpa range Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-pmu_event_info-v2-6-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 arch specific code may need to validate a gpa range if it is a shared memory between the host and the guest. Currently, there are few places where it is used in RISC-V implementation. Given the nature of the function it may be used for other architectures. Hence, a common helper function is added. Signed-off-by: Atish Patra --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 401439bb21e3..d999f80c7148 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1363,6 +1363,8 @@ static inline int kvm_vcpu_map_readonly(struct kvm_vcpu *vcpu, gpa_t gpa, unsigned long kvm_vcpu_gfn_to_hva(struct kvm_vcpu *vcpu, gfn_t gfn); unsigned long kvm_vcpu_gfn_to_hva_prot(struct kvm_vcpu *vcpu, gfn_t gfn, bool *writable); +int kvm_vcpu_validate_gpa_range(struct kvm_vcpu *vcpu, gpa_t gpa, unsigned long len, + bool write_access); int kvm_vcpu_read_guest_page(struct kvm_vcpu *vcpu, gfn_t gfn, void *data, int offset, int len); int kvm_vcpu_read_guest_atomic(struct kvm_vcpu *vcpu, gpa_t gpa, void *data, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index de2c11dae231..b81522add27e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3283,6 +3283,27 @@ int kvm_vcpu_write_guest(struct kvm_vcpu *vcpu, gpa_t gpa, const void *data, } EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest); +int kvm_vcpu_validate_gpa_range(struct kvm_vcpu *vcpu, gpa_t gpa, unsigned long len, + bool write_access) +{ + gfn_t gfn = gpa >> PAGE_SHIFT; + int seg; + int offset = offset_in_page(gpa); + bool writable = false; + unsigned long hva; + + while ((seg = next_segment(len, offset)) != 0) { + hva = kvm_vcpu_gfn_to_hva_prot(vcpu, gfn, &writable); + if (kvm_is_error_hva(hva) || (writable ^ write_access)) + return -EPERM; + offset = 0; + len -= seg; + ++gfn; + } + return 0; +} +EXPORT_SYMBOL_GPL(kvm_vcpu_validate_gpa_range); + static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots, struct gfn_to_hva_cache *ghc, gpa_t gpa, unsigned long len) From patchwork Wed Jan 15 18:30:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940783 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 25F371D90A9 for ; Wed, 15 Jan 2025 18:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965867; cv=none; b=AJwCxrQng9oBRa0jfuDH0fYwxSHYyfsozdDWogr5qAkAv+jbCgG8arhTpq8OQ9xEvrmHTwzSLjGdfRA7osyZrScXrr6eg0vQbTHVIxMMyFFnG16xJK4ZfWt40NDXJEgxvZ9t8eV2mPPHxD3NoJoy0+Ga1yvpWv4zzrKc+MYajNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965867; c=relaxed/simple; bh=efs3Hd7cOdrjOpmhmL2LomzcbRptdMckK8U3wRsh0lA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZlmYBSayW6Kj/1vOxeuf7Yf9zuOdrjaJLuI/+FtWu3Sf56esXDyS5N8badB8xbjWrL8JqxVTzlLXuJtzmnmTM/GMh+sDlzJD2FN3FrvSisb82KDKuzOTli45WjfKQAbzpZtrMi3yPSb+q2jcoU+NjZ+NO4yFEvAx+6pbfZHsxFY= 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=KEHRw4cn; arc=none smtp.client-ip=209.85.214.176 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="KEHRw4cn" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2166022c5caso113093875ad.2 for ; Wed, 15 Jan 2025 10:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965863; x=1737570663; 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=YPQonIfRWz8q533cgyWsgSdgY3t/tGTd1rJqUG9L59Y=; b=KEHRw4cnfFpUI7D6MXDVGVtsAH3RvTeFmlIhybyHBU53/bA6aDHAJrKgVoMYnPvy6v vekvAag4iuafrV7O+i1+kUUSqqbOcJJVL2d9G+Iq59WTHmpDn3AzLOglYI/+FmyzxVji 2maknp3CcZU2QY27KPSlEOJKDeM+xzJ0LHWSWgXRWZYg9lCkiViE7vMJY4ANqepE51vp wJOZC9pc8uvRlEmcFwnukYHuXoYAxrdk9+FeNAXSKawj2DNo4JpDoXzUP+Wh+hkBEInk OwO2vjVV0MDVYPcaH8QpeJvJkwAsmcMMEkXkdhI3dUZw2tOftdJ8HT+JbwONHWpcBp2K xElg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965863; x=1737570663; 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=YPQonIfRWz8q533cgyWsgSdgY3t/tGTd1rJqUG9L59Y=; b=lHfMtQTJy7ewZiq4v4vvsZ65a0eZlXDzgX/I+a/DWlLyKnXE5mB+/RjSDurA+/Ha8V SAs1az+DVOo5A3cISUTkQ3pUSqzaGoegW2ZvzqRQtkAF4X78xk911ZivJgzzBFWO1ACi PHIjOxz0aLrKbAQ92Ky6vAmkS/VKBrHGi5uRwnw+ar1jWiM8ro79nlQ2QpKEoZGzZqmh M0CgkkEBSsJ7P6PxpRTN+2/G0NL8wRCjmaHZnOpLFLxCD7vvLNlE94MCnl1yKmtzNnuJ SF/HtWQwVyyJFXsLA5Wb+wQzMLcYc8DvqC2tta2RIa7LGcaEdsxywxa/Cj5pWBhXaP64 Et2w== X-Forwarded-Encrypted: i=1; AJvYcCXWFjO9vfC14cXpE599I5wsZFj+qLNwYgPjwZYa1HxU74jq7kcDg2ANE4zxSx28DFgCdSs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw50WL7tWoIzDU1xUg7tFxt8A8TeXcJ2DJLrtDhy7zh3QdRNJyk e26ttfNim4kimbVrF+sKSt90eyZRxQDu6HBz434JEZyAU1Xj+ZaYnfMbqO60blc= X-Gm-Gg: ASbGncvOlQK8+DDgOzAb400AEwgr/XP9mbUoODohpwThquHwood4LDMGhSTYGG6T0Ia nINx4tElCS5PEaMWjQFvu2TNJZ3/7fxRTYAgtg6eozIn8P1mFIer2WasnKISbmrTAECxw1clr18 izSXdT1pc4+H9s0SV16gotrSGFUq947FlKYKMOpRXwZDNBSgCtweeu3Hw9spuhizl24+sXNjfeB PwmjeHlKZhOKBStqKB7AovmJue8V4c5AdHN6/sJI446yJ9yRRJ4kbHp5TCJ+Dr+Tc1Pkg== X-Google-Smtp-Source: AGHT+IHrlKrKdeucl7zMxkF/5l3NHVR4wNF51oJC9P55Fo2f9FtCoIn3BV0XWsDAU93AJPqz/FttjQ== X-Received: by 2002:a17:902:ebc4:b0:21b:d105:26b9 with SMTP id d9443c01a7336-21bd10529e9mr125689755ad.16.1736965863474; Wed, 15 Jan 2025 10:31:03 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:31:03 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:47 -0800 Subject: [PATCH v2 7/9] RISC-V: KVM: Use the new gpa range validate helper function Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-pmu_event_info-v2-7-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 Remove the duplicate code and use the new helper function to validate the shared memory gpa address. Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 5 +---- arch/riscv/kvm/vcpu_sbi_sta.c | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index efd66835c2b8..ca23427edfaa 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -409,8 +409,6 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s int snapshot_area_size = sizeof(struct riscv_pmu_snapshot_data); int sbiret = 0; gpa_t saddr; - unsigned long hva; - bool writable; if (!kvpmu || flags) { sbiret = SBI_ERR_INVALID_PARAM; @@ -432,8 +430,7 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s goto out; } - hva = kvm_vcpu_gfn_to_hva_prot(vcpu, saddr >> PAGE_SHIFT, &writable); - if (kvm_is_error_hva(hva) || !writable) { + if (kvm_vcpu_validate_gpa_range(vcpu, saddr, PAGE_SIZE, true)) { sbiret = SBI_ERR_INVALID_ADDRESS; goto out; } diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index 5f35427114c1..67dfb613df6a 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -85,8 +85,6 @@ static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) unsigned long shmem_phys_hi = cp->a1; u32 flags = cp->a2; struct sbi_sta_struct zero_sta = {0}; - unsigned long hva; - bool writable; gpa_t shmem; int ret; @@ -111,8 +109,8 @@ static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu) return SBI_ERR_INVALID_ADDRESS; } - hva = kvm_vcpu_gfn_to_hva_prot(vcpu, shmem >> PAGE_SHIFT, &writable); - if (kvm_is_error_hva(hva) || !writable) + /* The spec requires the shmem to be 64-byte aligned. */ + if (kvm_vcpu_validate_gpa_range(vcpu, shmem, 64, true)) return SBI_ERR_INVALID_ADDRESS; ret = kvm_vcpu_write_guest(vcpu, shmem, &zero_sta, sizeof(zero_sta)); From patchwork Wed Jan 15 18:30:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940784 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 65D171D9337 for ; Wed, 15 Jan 2025 18:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965867; cv=none; b=C29ZF2ROlpaafwbOfwoAxmlFOI/tY2wduBUVMgUxcLs1cU0sHM5PGX5BI4gLt8o2isaosTgb0rinqPSiXjKYHYUbUwUESVGP9ri8vEkwLOh9b7kYDXZW/ViepnPjV+apZRxVxUj8M3S+oayUTOCwHqI2T3yTzkuqOQK2IXDya28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965867; c=relaxed/simple; bh=sczug/d3NLCUmVYBCwmtejNxbBiOhgpwE4/Zl4Ffiz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R7r7t8sPlyymFDtGXmNNbRhS2ylHzGBJxQq/uVCyKcXF2Rb1MbvzrfTa8D3KwoY9YMuBF4JpXy3jka1WDQGYej2hhVH0D2jQKhUBPQnQX5IpviaMW6P6b/EhhfYsBJsbQ1m7EYRENGYX/8Zu7Sc72LvIRchybHGhUY7J0Yqc4tg= 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=2V5KCYPN; arc=none smtp.client-ip=209.85.214.169 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="2V5KCYPN" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21680814d42so107278145ad.2 for ; Wed, 15 Jan 2025 10:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965864; x=1737570664; 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=BvcM8pFAUo8mVZOX2xDK8xE/vCf4z0GzB3iMLovGRHA=; b=2V5KCYPNp0U76KG2PIoShHSbNJPU9mEHsu81zC9a0t8P2xOrdUTFmWnZbyimrji4i9 I6BYXR0nwb/xN9BfQ/SVQyMICn1SHWn3+/Pj5o0Q5Zmc0XOv5V6fnsmkSRqV/TciErPl ghrwHKm7RNFJVcEEYMfWGKiypIawwl5EhfprDN2NsExbghPh2o+/6rtNLkWLJBKLzNn6 n0b4ruDqzuapGpAuhEcwas6a7Ue4XqDD/p2nhB5jUmJ8ej0ck25GD+PIvdCZddU2zysi blwZsDqKSH/OZMtWCW4h/IsGmpiGFvaEV5UzckN5WkSEFV7jQD2tajjZYlOrhdRpq8ub wJOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965864; x=1737570664; 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=BvcM8pFAUo8mVZOX2xDK8xE/vCf4z0GzB3iMLovGRHA=; b=Jue9guJt4oI1NptKY+ltdRpGvRXt5Ac7WhJOVS+vQSB5NCF/TucrxYP/kVlZCQRN7z nWpxLFSX0EyIAUDVciJxNlDRxWZJe1TX/RRVL9cQL0U4bMSQE4sx/+COqyF0VE8Etvb0 cudgb202ENgD3HBWYPnSQJ4U2TxDYe928Amcd1ccg2SFpe6j93q+SJmD9KBVmGXX3Gq6 81YFFOjC79qwbieY++ODGrMXANoFRgEXTs7MDOmA+lF+Tc1N3zzfG9k/etiYLtlcSi2c OG/3CVmFQRyD5NglkuY5LrH2OBzQVbw5hPErD31keC8KSXpivfqe84ZQMoczxFXJmWe3 Oj1A== X-Forwarded-Encrypted: i=1; AJvYcCXHxDVQvxyFF/9bHPREYuo4yIImLy8SEh/C3pBUTupDEJMLXdRm/etM8FqhEF8TbLQCb4k=@vger.kernel.org X-Gm-Message-State: AOJu0YxBqk93ZJ56TCvuNsRnMDFj/2ouypHc3uuj6LBCm05yVZN0LuqR Tf0b0lPgYlPDMwwZuNObc2TraLW4f/JzQwe3HCc2rwge3kAY3xEk0fSglqgQHuQ= X-Gm-Gg: ASbGncv6/GRmMwIzgaL2DjBumFzzO4oXc/0JIl7Oq+M2BlVmzeh8jwSmUnBLqVs03XL pL3AMkI7FFmsgQn0dHxClSHrKLh+u0sQZZ8Hy7M42uGkw84ywofnJAoiHZxHsdG0JzJIuXkP230 O2jIogcRfDsdfiRKp3z8O7sxMiMoVPzmAWdQpvU0c7a/AqfT7jWs8FhbT01q5wBXk5YpaAmLvE6 cLMt5bhbFDPnCIWxB4vfzie1NzXLwMklxKOzNlOVIlmbrr0enEnAeUz/lOXUkR5oDC4BA== X-Google-Smtp-Source: AGHT+IGGezhqE5JLeDYHWhClhyZY1cGsFLOXrLsdEJgU2ElrVE/deMFlurFTVr/XKSOcI7Wz9ZYvgg== X-Received: by 2002:a17:902:e5ce:b0:216:386e:dd8 with SMTP id d9443c01a7336-21a83f54a51mr373139315ad.17.1736965864561; Wed, 15 Jan 2025 10:31:04 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:31:04 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:48 -0800 Subject: [PATCH v2 8/9] 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: <20250115-pmu_event_info-v2-8-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 | 66 +++++++++++++++++++++++++++++++++++ arch/riscv/kvm/vcpu_sbi_pmu.c | 3 ++ 3 files changed, 72 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 ca23427edfaa..23dedf4c9313 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -453,6 +453,72 @@ 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) +{ + struct riscv_pmu_event_info *einfo; + int shmem_size = num_events * sizeof(*einfo); + 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; + } + } + + if (kvm_vcpu_validate_gpa_range(vcpu, shmem, shmem_size, true)) { + 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; + else + einfo[i].output = 0; + } + + 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 Wed Jan 15 18:30:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13940785 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 4FBA21D9A6D for ; Wed, 15 Jan 2025 18:31:06 +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=1736965868; cv=none; b=msoLAHM71jjbHOR0bLZ8gfl0Mg1j74u27Lc+/vevHeCJZ4CoCjmGMxeH6+GwoXMb6wxh8uGAVhV3UfWBn/ro3ZmcAKrDOguGMEA2+THfphMtzHQsz3urTEnoJHTf55NxrLlfzCt9yOPDVcqRDruVjy4JeJl7RW3H6nRSjnSVHwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736965868; c=relaxed/simple; bh=I61ANzW3mMGNw+TsEklnF5HMFHS9Ft60jqTehlaG7hM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Iimlr04l7lyqhrTv2S2awmDnjFW0YLpcM6bomB/0MuOO/WNxqgjY4YhVpmLxN9HLmALH31M2C4PN08EfH0gv1+K9Fs6I/ahNEs72toAo+0l8OccAMY79fqRpRzIceuY3/CjrOIcbMjA9AP+rhjsZqPRtbMYFl3McH+eFXKzX5rA= 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=jGKDLbGz; 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="jGKDLbGz" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21619108a6bso126527795ad.3 for ; Wed, 15 Jan 2025 10:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736965866; x=1737570666; 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=jGKDLbGzpt+hAXvSI7EJJsBDiNY+gcB6fdufauX8OC66i9m2xfN/6fD4f35YpNon2W 1nPfAClCYuczg6HPMJMiNbai2enhvYVmDTwbDBc4/v+Lx6B+xKJzq6GlTkvtCPyAqGmY d3OpwsSQNo6gx671qQ9yropgpwksWpRUHk0zuWlFcy+VEK0fF10yb6BqWd0hxnnD4cCf Kj/6CrvhoIEPl4OhjifC4o8k9SK8kIbCM61J7TV9iNIk+dN8LlT1POsiEwMxbuZ5arXv 0cBf731ZnRvJOX3u+VpG1o3KsMuUuFHWToQWVJ19m6j42gwwk3YNBnNXaSEkYdeafJ1J MGdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736965866; x=1737570666; 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=rz/TWprUcvJn3BFkja/E0uXhrjhkbh91i0aTPwvL/+KFpA373TQ95rlFj7hXi5wR7O N1g3HvXbg8959Dyh4q5/K3/eObOGLkMB9ruNjxI4HrI3xj548B7GgSRjYQGqaCtgH+ZE Nk+eqEf5Rxv1P8Tpy1UmclOE8yFJckoU9gcbxJTHsZ+hrZK38ZMqgi4uhEcY+Wtviwfx OYoX9pb/1a2EykHwze24+hBX61EvBRvyH8aj0E0/FeCmUGNz52UNgI9LfJvm+mMRf7/2 7RlpHSM7ODtp3CKrQMsUGQB9gPr44bYOTpst4Jz58JwJ0XvEPxLaGQJWVId6gDQS7MV7 tV/Q== X-Forwarded-Encrypted: i=1; AJvYcCUffm1zWzhGy6Abdhy+81OblBA4zScTUNvq3tJKD5cKjvl2DuuHpTEAuBStqlHexH4dWos=@vger.kernel.org X-Gm-Message-State: AOJu0Yzq2wbCwmbX3O43auaZtX39aoxbUpzZY61PL7A7ZQaSW9lCL+NK zku6LNSNn1en+ika5xG7yIxxbdmGwU12CsMqr32hjp9rOoRmV/1aNY9kfYz5YgI= X-Gm-Gg: ASbGncsxV+t35SJERDrfLYEqHVYHi9q7RHUUUUwrwEDEZSfFAN6BN+DBTX60ZzRBiTy v+VfhnJ78EDVvAXVQd2Z2mWw5fGBtv8qAS/qhYdH+RqwcJQteV1IJYmrYTa7qdwyPGi6wmjq0AB IvsJOAI65R1FQocpZTaXH5MCwnQgUsdPKs0G8z8wFajUeY/GEMi955emKJGJhywxs2ALvS4tTfE LLKgAzgx0jjgRRPsQ6txWOUO1oeZ2X1VpGoyljtpxy3tmKaNw2dJLneNrbToB7eF0w2Aw== X-Google-Smtp-Source: AGHT+IGUgwpGj/plYJTZ8pJ5gD95k5t13F6GWcCCeHibqJhYXgtv9S5eRA0RKAcOGIqFSWIv1IyJjA== X-Received: by 2002:a17:902:fc8f:b0:215:787a:f91a with SMTP id d9443c01a7336-21a83fd1e96mr525986085ad.44.1736965865659; Wed, 15 Jan 2025 10:31:05 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f219f0dsm85333195ad.139.2025.01.15.10.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:31:05 -0800 (PST) From: Atish Patra Date: Wed, 15 Jan 2025 10:30:49 -0800 Subject: [PATCH v2 9/9] 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: <20250115-pmu_event_info-v2-9-84815b70383b@rivosinc.com> References: <20250115-pmu_event_info-v2-0-84815b70383b@rivosinc.com> In-Reply-To: <20250115-pmu_event_info-v2-0-84815b70383b@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 {