Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp167130lqb; Tue, 16 Apr 2024 11:50:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV28ZL5ItqeLk7XlquyhIHhkMv9FV7cd4AwBa7j+gUkvLihL8W0jWuh9UIPC2s1eBfRXKY0QzvFMAxqi6BC5rPS5iGhvc1cBBp0rfigig== X-Google-Smtp-Source: AGHT+IGHRGNczbRup0Bb/HtW2wb2CCgx9Z3wgxMNKzxVrSN8ALuvN3r5r0EyYZKd8Bunp3tJjZUL X-Received: by 2002:a17:90a:7284:b0:2a8:30a6:be3c with SMTP id e4-20020a17090a728400b002a830a6be3cmr6351096pjg.43.1713293426383; Tue, 16 Apr 2024 11:50:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713293426; cv=pass; d=google.com; s=arc-20160816; b=l7Qyz2p57o1qY7GOlMbQ1Iha3wxgII6W0ngA7iju/yAB+KtCNlUZwiGpjLg2nvXyQn 8XvstUcmjdxdYkdtfXfJpdabuhfszLzR7MvmxS6FzbLxBmnRm5NVf9LFCJj0vzxgOdD+ QzyFpViAM/6OAD8W6swWi/kC+octXQfwN5LYFyiMvSJ66SWshpsgaHeL9emW79URlQAN 4CbBYX5/dc++cNAt3p7Y0K1q3GnvLhUM4xz3XH8v1Uuo9CF4zpuOleERM1EaDpMI8rLM E2N3IbvKLXIJq08F9sUgWaj6tcmlowgRAEkm2IiuDKqoayK3IaFKQuZZdAay1ICJcFNQ 4/Iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qvJukw934GuSrXeFuup9ak7dnmqxN0Lb+FQnvb7sFPo=; fh=Rp1+u4PMjowggwvpRu96VEneDwGpmH5BAOjZCbMCQT4=; b=HC1bgZ21a/GAnYADyDimmdHQRgCsvBOOe+aZEdvVUG9c+7NBjRvdK7q9dfVKp9lmho wpMF8EEAVg3gmjCkUc0xRBikjvcdtQj0pFYX7/XMBIZbBZfU0cpWvgxB4zr+D9/Wxbvb MW8H3mi9uwiGi9Ykm98ado3ShpJiP+9mmtQzkIYkjhv1irgdJLw88Em+FLeMFoHCFTH6 K5+RVyPp4ce6cvE/SnyZ/zXOdeC4Y9eYVxsNeEK01UyWCy7vKgpjIBcXsnOuC0gtkZdM Cj9OBmRMwF8iop4bUNPWhqopHrQuND+pgpFZt4G2eABu4Bdv4MisWpZrA/5mh/cEi9cI G5tA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=h+XacNlf; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147415-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x8-20020a17090a8a8800b0029fff93fd91si12046164pjn.12.2024.04.16.11.50.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:50:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=h+XacNlf; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147415-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0E66F281830 for ; Tue, 16 Apr 2024 18:50:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C885713D2BA; Tue, 16 Apr 2024 18:45:07 +0000 (UTC) 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="h+XacNlf" Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 8872713C3F0 for ; Tue, 16 Apr 2024 18:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293106; cv=none; b=ikSwtNnr45IRzg2Xjy3rNVCv8hW94ncFiiwOrvncYJ4snaO6K3/TVZXOIjuyrn7z8gYQ9fWdwgE/lsgA1iYOU8hM1eILSxDVavvLRVaQq1oigTL6Cv2ni8h0vkyMmMvP076pmhpjmYVy17kh4y2lb1/FsD5OkzKQY/LUymeR7lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293106; c=relaxed/simple; bh=iSleVGmYPORH0YJ6M9GKkX0luLVW1L/lHmqsDNV+cHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ogv3IdsJVPYuxIWvfIObe8NIuPZJfTs7j+oiSbnMj2k2Rql0CrnK8tcyXi1zL/WsCF3pbjiELnAR+Sbu19zvFSSGaELr3+S2mJO5u1gcXKS1R+OHAwAopadjBechXjxNxhXLwbOjB837kWJbbhkul6e3v78rFXdbMyjJSovvK3k= 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=h+XacNlf; arc=none smtp.client-ip=209.85.215.172 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 Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5f415fd71f8so3658115a12.3 for ; Tue, 16 Apr 2024 11:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713293104; x=1713897904; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qvJukw934GuSrXeFuup9ak7dnmqxN0Lb+FQnvb7sFPo=; b=h+XacNlfbK5JGXFKKTe77kKNvOlW2y/Vpbuwxe78qoMbYEiZrwxCcqFe1Oykjpnz3p KwNhWTzg6FgSok/WC3RR+gRF0FI+wsIMqPC4YhcJPoBXnWLetg+p0q7ls43caxj42JT+ zGmIhalf1fXVkfmarpH6KiLR/BegJXEj7k0LSSPiS6eydRUOT4UXI2hzROiFuuwWHHq+ mvaXyQHfUC4QlK69cxnk66guZdWhPf7KToKuY18rm1oz8cSXggkkb8s7RB8qWsGH71H5 JC9FzUCK42tBv/1SE1aHpnABh1SLC26Cl1tYf2LxMOX4s+S/0AmViiais+lj6In7aNCT mctw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713293104; x=1713897904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qvJukw934GuSrXeFuup9ak7dnmqxN0Lb+FQnvb7sFPo=; b=KxWByTe0EWssKXphBB5IJU6k9s3LLKYAOBoOf/K303FUKCmQ/4+MQJ5hn5P7yBWJ5r am0Q+17L8qYnlWpD1PlWo2Lo/2FA9SoA9ZG4/nVA0hUaPBkQ9l3IkX7gmAES5RtKjmm+ /dvjkDbkiqHsJ2yEJdR/I0TAhWsedMCcf0osF4HjzLaZIIZjgoyp213SWQSY2Kreg+Il QIN3wps8b5knqQ1sRZYW02PxToxgVUNJMZBYQePmQp30xInsiWJbe5UqN6lEyMbNuEDW 84x0hyHXEsIrpLtU1FtmlQB6F1X5rdaxGhgSRF/ujjhIWTNY5ZJH0UV7Rsr65TUgkzmW JC2Q== X-Gm-Message-State: AOJu0Yx/jNHUofv44mHf8KbE8ninM8AdDWlA+aMfK991Aiu7ZDL3RDN1 hufcMyVowEessaPCSBnWSp2a/arXYH5ZxWtSZ8PjgJUQc+AG2dNMfwbcaS5EJ82CvJtGG0KRb5P d X-Received: by 2002:a05:6a21:2d8e:b0:1a9:dd82:a42a with SMTP id ty14-20020a056a212d8e00b001a9dd82a42amr9766403pzb.31.1713293104126; Tue, 16 Apr 2024 11:45:04 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a269828bb8sm8883645pjq.40.2024.04.16.11.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:45:03 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Anup Patel , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v7 16/24] RISC-V: KVM: Improve firmware counter read function Date: Tue, 16 Apr 2024 11:44:13 -0700 Message-Id: <20240416184421.3693802-17-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416184421.3693802-1-atishp@rivosinc.com> References: <20240416184421.3693802-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Rename the function to indicate that it is meant for firmware counter read. While at it, add a range sanity check for it as well. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_pmu.h | 2 +- arch/riscv/kvm/vcpu_pmu.c | 7 ++++++- arch/riscv/kvm/vcpu_sbi_pmu.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h index 55861b5d3382..fa0f535bbbf0 100644 --- a/arch/riscv/include/asm/kvm_vcpu_pmu.h +++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h @@ -89,7 +89,7 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba unsigned long ctr_mask, unsigned long flags, unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata); -int kvm_riscv_vcpu_pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, +int kvm_riscv_vcpu_pmu_fw_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, struct kvm_vcpu_sbi_return *retdata); int kvm_riscv_vcpu_pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx, struct kvm_vcpu_sbi_return *retdata); diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index e1409ec9afc0..04db1f993c47 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -235,6 +235,11 @@ static int pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, u64 enabled, running; int fevent_code; + if (cidx >= kvm_pmu_num_counters(kvpmu) || cidx == 1) { + pr_warn("Invalid counter id [%ld] during read\n", cidx); + return -EINVAL; + } + pmc = &kvpmu->pmc[cidx]; if (pmc->cinfo.type == SBI_PMU_CTR_TYPE_FW) { @@ -747,7 +752,7 @@ int kvm_riscv_vcpu_pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx, return 0; } -int kvm_riscv_vcpu_pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, +int kvm_riscv_vcpu_pmu_fw_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, struct kvm_vcpu_sbi_return *retdata) { int ret; diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index cf111de51bdb..e4be34e03e83 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -62,7 +62,7 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, ret = kvm_riscv_vcpu_pmu_ctr_stop(vcpu, cp->a0, cp->a1, cp->a2, retdata); break; case SBI_EXT_PMU_COUNTER_FW_READ: - ret = kvm_riscv_vcpu_pmu_ctr_read(vcpu, cp->a0, retdata); + ret = kvm_riscv_vcpu_pmu_fw_ctr_read(vcpu, cp->a0, retdata); break; case SBI_EXT_PMU_COUNTER_FW_READ_HI: if (IS_ENABLED(CONFIG_32BIT)) -- 2.34.1