From patchwork Tue Apr 16 18:44:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1924335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1SFbWmHy; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=jVPY7LGM; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=0+MJyCFm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VJtKf6GG0z1yZC for ; Wed, 17 Apr 2024 04:46:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=svEneMBzUnlsgqlxPJIh8zRQLdP3fLK5vNhnf41oFI4=; b=1SFbWmHyj2AnPy WMRZZPBIuiqlqvPP9NZY+KGfkoSqDwSAp2UtckMA3QldIhdM4ZJi61hzpswYilOxaVjU9BRTkijgF K6FWRWmnOcHf+GjBi66yJpZrWIvFKsSJbNJNJoNOmJ1YRgLaYR3yzz0CJiTcn0O6pvUC79ahVFP9S 9jrWdM5XAHi/UvGpUM5D9GcRh+I+WBjiGT9jFXW1V03ftWdUYrGK51veraU75uYprkxlBcionaGa0 bqedi6lWsELRxK4rUSRs++CTBq0bmO5hj5YbrqkE9bdp9r17FASmiVsHiHXDhqbCL91ZxTsH5fvi0 csqiw84vsT0Io03Sz/mg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwnor-0000000DNKf-1Ph6; Tue, 16 Apr 2024 18:46:13 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwnnq-0000000DMVc-2NMH for kvm-riscv@bombadil.infradead.org; Tue, 16 Apr 2024 18:45:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=qvJukw934GuSrXeFuup9ak7dnmqxN0Lb+FQnvb7sFPo=; b=jVPY7LGMbGiCTxsXqvw2HCmFiT dq1alqb+xdaJBk9uLTEc0hBWa8yOP/pSLLEs38gwN9PbRmIl9dGZO9FAjXuqqEKz6GhU+vBWJjwNi QVzsYb30iQ93AZej83stpGc/ARolZrAGFKv02f8PCWHwQ7J6lrwUYO15BSKL+p3RNg4oT55cmBBdf OmLVAztTsNGvAXuYxYA6fKjbjez2QNM+exxkxyEY0oHwOsDYMUvM3H/Ftae5JkdHS7nGkJzvlQDm/ BK/wvO6pI/FJ88wVKzmLGyYgARM/tW9swCZNNcsCcvpRpOsIvimWOC0JxysRsZxy8Y8cnBUMByJC1 2PutpumQ==; Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwnnm-0000000BCJs-1Sp1 for kvm-riscv@lists.infradead.org; Tue, 16 Apr 2024 18:45:08 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6ead4093f85so3960477b3a.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=lists.infradead.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=0+MJyCFmaQ0augpRLdVlLZA92c45kbxM8mgkMNV9m2wJsZ+3HGBarA51tttXv7Cfri 2t6HwIEFcDU/Vz19+ZMHybOPF1LPg9Iv+qRgOGv8D1xu7qD8d4KpzaOXkk7kUdZ7/kHf h+nzFSCgEceYkA4fznoOApPFZkNbfKAXBQ62qStcbJ6eWZ1ymHTDIVRvwmwmr13sacSa ScHk2zTHga0fT3RwSfUnaXknv1Og6jkDb6C9O6y+cIdiQF/cMO/UTyam77Dr99ujYbCt GnVns23c8UVl6HWY3JlUAI2kpRs3Ms4H8teJ0cLEkve1gbnFW3pnD5tHGUNDgq2OWhKQ KeXw== 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=abUrfiwFIPn6m7aOAiK21vYglWUjOK0wqVpQ7+aCB5LX41EtzM6PeG7gv4IkWQ4rX7 1djdwbzYSLc6+4JmkqGPE1kFYClKLqMfjI+sqwrE6rEKHpChgg7F+cHsaRIs01b8rQkm K0YnmlqyWHBNNaZW+YDvWHuTiyYxu49u+il7KmNwsg0PZ/MPCh7iXGgG3fVxMmZv7naU SbELDDlAoZRb4Wxk40UW9l90hanuWbipj7O2JlQ4LmuGIhE75RHGu45vXQd4i33yD+xT w1xhLfXIyVGnZ5Gn3KwB5LQqhMFnE7oZi7MGnmbImKTN0s47Ek6cua2HIqBGgz0KggYf 06gA== X-Forwarded-Encrypted: i=1; AJvYcCUqbp9cGY4rCRgzWltIj0EnwbX6f6F5oPrL2gZaORWhPfU4ZC/ym8xK+EwHlmF5AExXueb0ub5C53lu3hkALZVyET9VEoCjE6MqmBqHTA== X-Gm-Message-State: AOJu0YyHtZixfENRsIAWsq+6s+lMjPQoxCX3JOUJQIH86S+OtdcXnvRk +l5Wvq8PL5lWKKEWK7Was51LI56M2xZ+6xw/qrYenwrHzoG9CPkuyi75YyXvjUg= X-Google-Smtp-Source: AGHT+IEzkuVs13Wd8oWq41fr6Cm4Cf2ZRXqAps1equR8HRaWNn24PI2u5SFf2jAeIUGzEw8b8iUdrw== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240416_194506_568723_589A2CFF X-CRM114-Status: GOOD ( 12.09 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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/k [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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))