From patchwork Mon Mar 3 22:53:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 869975 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 CBE26239594 for ; Mon, 3 Mar 2025 22:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741042395; cv=none; b=oLzuUlXnG3bQt1zEjTgyk9nRgKDDPD4dq793rd6Ph0KLbpzZEUnskn4eucqkslzQUj91GX7LjhrUZQPAMr4g4DZ2c0Q50urjR3dQ76un1A1Ii+3tXe2ufiTGEZXQSo3nCq0h/mmrOknVZd3PDSsWg7vIBzsWdPs88x9mQdNQIsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741042395; c=relaxed/simple; bh=DxQuXHMlgc7H5Iz7LRmGc2M8YCqPk4tOjdxPmN2FNfI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ry0dQW4qkVxNDgAleRy3TcG11T+WgaNvl8up5Qauc5zTbvzYb1A19JKG6OikfHm5lE+NFEQ5yZpRMAs4NyhZFSlf93J4q/6FPasLag5mIJniXDf7cbDGMljI1HCQQdZxRcaTVMQv9BklX2/O6xgdDBUCXhuh0+9qPgF1qTMgq/Q= 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=WdJuMiIk; arc=none smtp.client-ip=209.85.214.181 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="WdJuMiIk" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2234e4b079cso90571265ad.1 for ; Mon, 03 Mar 2025 14:53:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741042393; x=1741647193; 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=mugBhowmjHeOZ8voD78niLPk8kFDSWBL6lZCl8cn1Qg=; b=WdJuMiIkIs3pUQXpxz7Z9HmUtPvCC79mJk/occ7KYGG/aZdiOmBHRmCNJhdTOf3/ef ovpBWaFkZU/v2DMGUw9V6pXveZmqaYiGBC56j7XIAZad2ocyzUG4D6T6+hEk5gaP94Fw VsXkGx+7uzLOu6QNKgxQZDi4HxBscik0se8xvAPweYri0I7hRmHEPx0d0wqW2CcqCN/h N4o+RyBR5xgif1GKI770sWlsnhnzzyufnWMaoEritGhZ29py8V5tvja0pu0oehAjlZy+ 7I/spmdEj4WD2ny8Xc1m55EZRBYIwT6a33H+8dc1T906V1Jmn7Qk8d7bPbSMbFd/dkTJ xihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741042393; x=1741647193; 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=mugBhowmjHeOZ8voD78niLPk8kFDSWBL6lZCl8cn1Qg=; b=rhFZ4FX8693d7Ns5Aywdt4peBuDl10Km/hf9sAjJlbts9424prqTofG0d2xQLTnT62 qJ350zsN/aNd4XWjHsUNWgLIgKHu6Xkm2dO9FRcNK0cGi4zpgan8QIMMrnln5+gVlJX7 FUjEtTf88LIJsT06HKvX/Xz0aS9BWvQXvQWUe68Bdu8M2mtOGcYXk2eoyRD1qBbCsGGB iPKozbTbIH8E0mlIN+7S1lc7rkmgq3OI60lz0nEADv4VePVWrw1/SEBBXL9y2gXXD0Rs r4HPurZKtkteqdqxtab+mluH/41n3nKvC/4TzjqBo9KC7mQQqoKGX2BU6HAhvlZkhszF yS2w== X-Forwarded-Encrypted: i=1; AJvYcCU0jlK8yMu8s0DDt9ikmnzqVRGuHDcOAmEKQ1GKT9cA1lSRwqFMpWVE+IePfSRiR1lA+7oB7ySV6bALQs1zXiI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz02TObtsYO8SUxVx+c65MXyKxZ5+QW3mOckNvDdtepMna9134U Oc/eBwXu0j7ZcL5Ot9wkOKyGSbPNHNDiip1x7xmqZSIFc8NlynPJPn3lml91sX4= X-Gm-Gg: ASbGncsTIRSEZt7uAwh/hpXVevkY9WCLwcdQg9NAkS+7mVeYMDW2ypbooAfNeLFc8H1 PxddqRx16IDnjZfCGdPordPUTu7KuVB8xCfeYk9ZwQBVNpUsWUtbKeaqmtQuJKNSzv72vplG4jy q+SQ8LqLlCzh2K3AYVUZ1NrUx0TEAOkn+lo+xB3Rf1VkdivOHlTJTtxD0sF3kicASit851NXBsr YjO169MBuBdJ+HRCFaLGZ+/u60Xb2pQfqaNchC2pUxzRs+qwq2FXF8We4ZUsPMn4effX7PnlqxR eoHQocdd8yZ+RJCTNi5zOwiFIKx63Tcg4YmGIsftO7bxS83t0pIDDVsOuw== X-Google-Smtp-Source: AGHT+IGcN7KmSzWUc3x2Q9hIKcCxmrhzor1ESo6ey42ZNpnLuX0uKU0+qCp3SXFy7hHj8nlBIEN6rA== X-Received: by 2002:a05:6a00:240c:b0:732:2170:b68b with SMTP id d2e1a72fcca58-734abee4a68mr22681643b3a.0.1741042393072; Mon, 03 Mar 2025 14:53:13 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-734a003eb4fsm9440601b3a.129.2025.03.03.14.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 14:53:12 -0800 (PST) From: Atish Patra Date: Mon, 03 Mar 2025 14:53:06 -0800 Subject: [PATCH v2 1/4] RISC-V: KVM: Disable the kernel perf counter during configure Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250303-kvm_pmu_improve-v2-1-41d177e45929@rivosinc.com> References: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> In-Reply-To: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-42535 The perf event should be marked disabled during the creation as it is not ready to be scheduled until there is SBI PMU start call or config matching is called with auto start. Otherwise, event add/start gets called during perf_event_create_kernel_counter function. It will be enabled and scheduled to run via perf_event_enable during either the above mentioned scenario. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index 2707a51b082c..78ac3216a54d 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -666,6 +666,7 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba .type = etype, .size = sizeof(struct perf_event_attr), .pinned = true, + .disabled = true, /* * It should never reach here if the platform doesn't support the sscofpmf * extension as mode filtering won't work without it. From patchwork Mon Mar 3 22:53:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 869974 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 F24FE23ED52 for ; Mon, 3 Mar 2025 22:53:14 +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=1741042396; cv=none; b=KQiwoV3NEl/Ebj/zBzbhPBn0DzTCIm20Dyf8zCgz8mVm0IhxoI6fN3S3oj3diqwCW8VDJ0OWGD75R238YUqReJI40yHGZ5QyJ/PIGJSjsRx9PhA3SzGQ0jAdT6bfkGpxnrvjQaxJldcrnfbwmfiIFd7YiU1xJeBIFdFQwGBcluo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741042396; c=relaxed/simple; bh=gBJ6uGpDPU8VQvhfth2yUutlzUR6uu8KN/4t8mgGmWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CtnEZ6yaqpdPSvel071eH7zvyb7qUvQIckGp3DEpvwRCFEiyk0FrAJUxfLXyaaCf8KeqVAGv/ZqX3Qye53G6G+jjWAdGeu2S4SqMFz3j+GcnOPXJ56zyVBEZFz/4d7Pm+Ns4HJG6cNu9vhVh/a+bQSLlU/ZFWnNGDlRPRKBcmYw= 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=rw2Ic0j3; 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="rw2Ic0j3" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2233622fdffso95039265ad.2 for ; Mon, 03 Mar 2025 14:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741042394; x=1741647194; 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=b5xoxucipI3r87CV5kbgeUb/z0QLUAJbC0b2XlScuLU=; b=rw2Ic0j3xtkPH5LOGEOzDrhI//tfDv7NUln4/ovKnCAWLlp2odyXKMBNCkL8tmQr1b BijZYi3maGEJae5FyLgl0p7zTT/VBS9tlibysY0nINZf1GjUlGQEyyEyI2VrffrghxUZ GofPyfjlVVQ4qC4i0R7VqLCPPX1Bs+k3MqU2aCLrZIjmvWkouO6OqlOzNVAz6wQHkwN1 Vqu6ZyAZscDwpOjgSrteRa7FMx5x0hWKPKXS8upLHgacv7qgCiD4HWMWtIEJ/yWBENSR g4gpcvrLIvL5ZRzP8QlyK1JnvIHPrvK9V2o/aws0n1uNK625KzRv+eUkKEJHyZudS2bK GOAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741042394; x=1741647194; 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=b5xoxucipI3r87CV5kbgeUb/z0QLUAJbC0b2XlScuLU=; b=oh7CaJA8ty0GSP2alQQkwcdETKS8p7wtl4kESoW2P8721PDrIj+5Jqy+bU7finuYus YMatnDSC9Ow7EPmRwv9UiYm0zwNip3/7kAiQkaAlrYLqmVrTORYJMDiS3L9U71hfNLt1 ZgGprtzoL4dRLQGaTAgKe6YVAGrtc2a8dhqd36yE5mkBfn0uCTL90nxkSzfCJ+Hhc/9W +sM4447gJ84yjcOpobxtygGAt7zdO1DxwvUE/usbe1zbciYKizRBLvJvIUMAx6qlyGBX UAbt7otdj3kZxuUdg93KhhIjtYvFeoTFYTWJ+n+ULH2ZvbEWfpUajHYiB1TR9g6BU1iL Izww== X-Forwarded-Encrypted: i=1; AJvYcCV7nylSahq/Lc633o/LtH+zQhNe8vY5oyiXqaXxoYfCedIxsasCui6vBG8dSFUvfMplt9bAUndxYgD65aNXQkk=@vger.kernel.org X-Gm-Message-State: AOJu0YwUak6Ow4Sbs7b+Ymgajsl3eLL07EOTVKRUZsFzoIQz3zFa5UXB Nsyb2k7otQ9CA5+wXrDyMXbgnDqgnZnZDRsl/a/RParQEooBmN04JZUzmEO8hduXVtFdYqUFuig t X-Gm-Gg: ASbGncvNnOvpFVPAk6asSGPigsIjMpQgj9qv06HP7qr0ps5aBH5inXm1kdaiiwQFRNL oasOomYZmoUnWc4fbHEr6Ek8Gza6dFDbnpQON1utj+Ko6MqYVyy8Nyp5jvURfHkNayjgiNycv2a ry16B3Aw7WcvSwGoQRff/fVl4ScB0P/f6YJgLdSgieYfgSRs8lcRmvVWyWPc3wTrtMknCJEXyF/ nV9AD/Q3ngEJEcC9m3cUU9oXqV/1Qw+ihIe9OLxTmd+0WcnYc4Rq/GJUjJyMnnIvViMYOGyjavT S4SbEDKXDkjsyV0yLR8pqCJTbrTB/Vh6nMEjc1Xn7bzxkm+LM0WfJY6qaw== X-Google-Smtp-Source: AGHT+IGy8hMH+W8RZy5SJOGyzi1MeiJvJku2zV+j7M0txVehkixRDHS/MmEvMDbU3gziq5b3wIbZEQ== X-Received: by 2002:a17:903:230c:b0:21f:78f:c178 with SMTP id d9443c01a7336-22368fa5425mr202955235ad.3.1741042394242; Mon, 03 Mar 2025 14:53:14 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-734a003eb4fsm9440601b3a.129.2025.03.03.14.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 14:53:13 -0800 (PST) From: Atish Patra Date: Mon, 03 Mar 2025 14:53:07 -0800 Subject: [PATCH v2 2/4] KVM: riscv: selftests: Do not start the counter in the overflow handler Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250303-kvm_pmu_improve-v2-2-41d177e45929@rivosinc.com> References: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> In-Reply-To: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-42535 There is no need to start the counter in the overflow handler as we intend to trigger precise number of LCOFI interrupts through these tests. The overflow irq handler has already stopped the counter. As a result, the stop call from the test function may return already stopped error which is fine as well. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- tools/testing/selftests/kvm/riscv/sbi_pmu_test.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c index f45c0ecc902d..284bc80193bd 100644 --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c @@ -118,8 +118,8 @@ static void stop_counter(unsigned long counter, unsigned long stop_flags) ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, counter, 1, stop_flags, 0, 0, 0); - __GUEST_ASSERT(ret.error == 0, "Unable to stop counter %ld error %ld\n", - counter, ret.error); + __GUEST_ASSERT(ret.error == 0 || ret.error == SBI_ERR_ALREADY_STOPPED, + "Unable to stop counter %ld error %ld\n", counter, ret.error); } static void guest_illegal_exception_handler(struct ex_regs *regs) @@ -137,7 +137,6 @@ static void guest_irq_handler(struct ex_regs *regs) unsigned int irq_num = regs->cause & ~CAUSE_IRQ_FLAG; struct riscv_pmu_snapshot_data *snapshot_data = snapshot_gva; unsigned long overflown_mask; - unsigned long counter_val = 0; /* Validate that we are in the correct irq handler */ GUEST_ASSERT_EQ(irq_num, IRQ_PMU_OVF); @@ -151,10 +150,6 @@ static void guest_irq_handler(struct ex_regs *regs) GUEST_ASSERT(overflown_mask & 0x01); WRITE_ONCE(vcpu_shared_irq_count, vcpu_shared_irq_count+1); - - counter_val = READ_ONCE(snapshot_data->ctr_values[0]); - /* Now start the counter to mimick the real driver behavior */ - start_counter(counter_in_use, SBI_PMU_START_FLAG_SET_INIT_VALUE, counter_val); } static unsigned long get_counter_index(unsigned long cbase, unsigned long cmask, From patchwork Mon Mar 3 22:53:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 869973 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 71FBE23FC75 for ; Mon, 3 Mar 2025 22:53:16 +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=1741042399; cv=none; b=q9mNc9W78hGPuQEo8BE+2R3ze3s5qdRPnt7pkWaRmcZp/YM1gN053U94JRmsm7ELW9J2kxgolTykXYWnsJP1thzux6TsFVLEj5YSmLOXA/UiRrQDXH1wmfDbhSeXBA8k3+WKtYMaQ+RuHzxi1BnUvHuvAYO0FY66huF+LEeCf9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741042399; c=relaxed/simple; bh=nT1SZDmhRpluE6T0UXqXL8ivt7r+ikBYyrkgQ9kcFWM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GpsWWENarWYXeuVqb5VC6b1YXNq7FBZUZ2jElXQnIFoc+afSdqWs+F3YR8Jsv2rcYEiIIXP5Txs1TfKMZl+euYLzw3bOX8YHPw9IWkeDMuGjSl0YSPjJi33/YJVmRm7uVGGhYdfYRvPOI+3/T4Xp/eS+APCpPtz1c7SY7zbInrI= 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=jifWr2nx; 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="jifWr2nx" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-219f8263ae0so92314355ad.0 for ; Mon, 03 Mar 2025 14:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741042396; x=1741647196; 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=ZCtM/lSFNLHVQ6KX2EDg2QNHrviALMnTGfDgB4f3TXM=; b=jifWr2nx4e35qYZjqR6eXb8khK+zuhylyXa25mW3z0ZH4ij1JG0qWGVhxOdHF+Sgy9 wukzH02Bb5J1DpS8p0esZEhFF/Kh9//vKDoMhAO1MfgK2/DtIR9i/ThlSo5XDiwtDTG1 TsPpTZW9Y2+ZbjzJrLNHni7BhU+lxelqzeJD8kOO6uTCksLY8Iatmnvj+0bPUbrtvmmf yx9+JEMt4jOF7DJ2KLnZKbEeheVPsLMlvFYSdLb5yANVm2x1+ry2hEGgCtSJqUmzxMpc mbnZubhuU57YEdRdIIGVBLQ6d3SIi7Pt/k0Jpb/VR2YCLYtJ/ivNdeijVS8+qn8OWl6C vq1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741042396; x=1741647196; 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=ZCtM/lSFNLHVQ6KX2EDg2QNHrviALMnTGfDgB4f3TXM=; b=QQe4SR4iJLL7xp9Fr08u6r5fOttIeUF372j4KCSx0VDBmDUjFHl9puJp1+Ky9XiY2Y rOqOjt4T0gWu8B/vzOYQw5XmKYC1PqI8IbNVktt4rg4cKmCFbbwu4EoEJHRBxWH9YcUU KXPWZ/ycpmW7RZ9OJkHhLYUXxeHylyiTdpV68u5Hyzi+ZYuUfB6vq6Kv8qBb96g2WTSD fk/qcR1hPz2SKzpHJcc1wxOqPRa8RlhZJUCRgaO1CDpR/EJ1boeV7feE5Aa7zcLyKfev 5yHjW/+lgim2PjDFECSfi5+MI6V07NxSapECUHOk7sihRvvn5EUwqTm9fouJu6D0sweh ZPdg== X-Forwarded-Encrypted: i=1; AJvYcCXN6ULtlb5I8sE69mvP2K7S+JDmIwQuDuvq+pJwVq9F1PsnmFfWRc2WT7ehmIbv9w76P1Kq4yuHKvlgOLFE544=@vger.kernel.org X-Gm-Message-State: AOJu0YyJGfAcsMWMJfnPnQHkG92Gr6S7J5OPvcttaGsVFHnPC8a0fzf8 67VBx6cujTSw4x/Cc/dq4eFjqBGOxNcCUh+MtYXFd53ckptr+E6uL6TLF5DJlZA= X-Gm-Gg: ASbGnctD7HbAUs9ltMptpPbre+I085J9Swi7WsZQkatZIXgDkiJZVTl+GXMPPxpa1Hd QSFd+42rHY00eaAoKxOzp3Lio93+/kMZ9VBYPFWOVZ4qs/ZpxPNb5hanxlD+HxszRbn18a0oARK khSaateqUri/4BPcT2LvxzrndvnOKsNAqF6ufR5dG66fBDFPdl9zX2RyfXXeZgevQZ6+4x9fI0C FIJRaU/6fO7yXJ5Sv7kQfkoX0CxD3GdJl0JyIuuQRLmysS9Vpb68Zlq84CqRiIpiLfgjbfuD4nZ aS/4D8NVN+lHGeZd4NyJ8dyv7rS/U6IqCwOwyATssQDIysVfcsfL1M3tgQ== X-Google-Smtp-Source: AGHT+IGXirVkG7YmM+e3F/UoJqVCuA4YUPHtWRuh1VU5G5YFfQvPrt0/VrZAaOMzGSWX8Cr6YTAmAg== X-Received: by 2002:a05:6a00:92a1:b0:736:3ed1:e842 with SMTP id d2e1a72fcca58-7363ed1ec20mr10954047b3a.20.1741042396365; Mon, 03 Mar 2025 14:53:16 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-734a003eb4fsm9440601b3a.129.2025.03.03.14.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 14:53:16 -0800 (PST) From: Atish Patra Date: Mon, 03 Mar 2025 14:53:09 -0800 Subject: [PATCH v2 4/4] KVM: riscv: selftests: Allow number of interrupts to be configurable Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250303-kvm_pmu_improve-v2-4-41d177e45929@rivosinc.com> References: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> In-Reply-To: <20250303-kvm_pmu_improve-v2-0-41d177e45929@rivosinc.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-42535 It is helpful to vary the number of the LCOFI interrupts generated by the overflow test. Allow additional argument for overflow test to accommodate that. It can be easily cross-validated with /proc/interrupts output in the host. Signed-off-by: Atish Patra --- tools/testing/selftests/kvm/riscv/sbi_pmu_test.c | 38 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c index de66099235d9..03406de4989d 100644 --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c @@ -39,8 +39,10 @@ static bool illegal_handler_invoked; #define SBI_PMU_TEST_SNAPSHOT BIT(2) #define SBI_PMU_TEST_OVERFLOW BIT(3) +#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5 struct test_args { int disabled_tests; + int overflow_irqnum; }; static struct test_args targs; @@ -478,7 +480,7 @@ static void test_pmu_events_snaphost(void) static void test_pmu_events_overflow(void) { - int num_counters = 0; + int num_counters = 0, i = 0; /* Verify presence of SBI PMU and minimum requrired SBI version */ verify_sbi_requirement_assert(); @@ -495,11 +497,15 @@ static void test_pmu_events_overflow(void) * Qemu supports overflow for cycle/instruction. * This test may fail on any platform that do not support overflow for these two events. */ - test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES); - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1); + for (i = 0; i < targs.overflow_irqnum; i++) + test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES); + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum); + + vcpu_shared_irq_count = 0; - test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS); - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2); + for (i = 0; i < targs.overflow_irqnum; i++) + test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS); + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum); GUEST_DONE(); } @@ -621,8 +627,11 @@ static void test_vm_events_overflow(void *guest_code) static void test_print_help(char *name) { - pr_info("Usage: %s [-h] [-t ]\n", name); + pr_info("Usage: %s [-h] [-t ] [-n ]\n", + name); pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n"); + pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n", + SBI_PMU_OVERFLOW_IRQNUM_DEFAULT); pr_info("\t-h: print this help screen\n"); } @@ -631,7 +640,9 @@ static bool parse_args(int argc, char *argv[]) int opt; int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT | SBI_PMU_TEST_OVERFLOW; - while ((opt = getopt(argc, argv, "ht:")) != -1) { + int overflow_interrupts = 0; + + while ((opt = getopt(argc, argv, "ht:n:")) != -1) { switch (opt) { case 't': if (!strncmp("basic", optarg, 5)) @@ -646,12 +657,24 @@ static bool parse_args(int argc, char *argv[]) goto done; targs.disabled_tests = temp_disabled_tests; break; + case 'n': + overflow_interrupts = atoi_positive("Number of LCOFI", optarg); + break; case 'h': default: goto done; } } + if (overflow_interrupts > 0) { + if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) { + pr_info("-n option is only available for overflow test\n"); + goto done; + } else { + targs.overflow_irqnum = overflow_interrupts; + } + } + return true; done: test_print_help(argv[0]); @@ -661,6 +684,7 @@ static bool parse_args(int argc, char *argv[]) int main(int argc, char *argv[]) { targs.disabled_tests = 0; + targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT; if (!parse_args(argc, argv)) exit(KSFT_SKIP);