Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2556882lqz; Wed, 3 Apr 2024 01:14:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5hEpNpBpw7lszZh5ZodVikZjMlkH5G/WICExy488eQzPaj9Mg+6PmlNjkTOo7nVQic6AEDRdAxBWykWkXm+uaoqXIdPDGCATx1QBGNA== X-Google-Smtp-Source: AGHT+IHYaX0qLJO7RrTDwzoqcs4MZuyZkNCcMI8sJjk++c4f7llVbSOmn4xhymJBPNIbIOvlNVju X-Received: by 2002:a17:902:f789:b0:1e0:972f:de7d with SMTP id q9-20020a170902f78900b001e0972fde7dmr1876073pln.5.1712132076566; Wed, 03 Apr 2024 01:14:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712132076; cv=pass; d=google.com; s=arc-20160816; b=vIGzk1vlK60jau3aRvrwl4MX61vqIpL+jN6XpNqi1VScl9ZlVWM2cb266NntDexkeG 5d2EFAk+A+p+aOC0QiljOCgkvBC5UPUv779lCEenk8Y2h121lVsHE0bvX+ncKUZckHwD YRjI7isu3eHgwLWRDyAM6EzzhPrSpAyF9p5cTwKmKQBpwJK8m5MoUiM7Mym0NHeo9mpe ZS58dtbtGtO6fXR5cq1PPTO63iGz5GtpbiOXNOC9DaEaV7db8EWwEkbTSnBJfQ7gr49R AC42PgQ94AbzWOAVGewLRivvNj8gak3LeB5srOaOl1uTV2ALz/ARIFQpQSVEV70FLeBD eCvQ== 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=qwALXHKqCD9Iy5mIzImMbfILjpXmZkM44DIWXWIBe7w=; fh=iEgamv6dbODmscQv2wzZN1BSfdyVgGmpVc4xUNBH9RU=; b=C6Pa80mwwAn1nRgMnmFVzS4qBrQq0HEtw+2oBnlBXIGD5y9MlCebzDProK7YcWEjlS ilrtGID8EizdlM/yUtpjo1mBLG6DhCjVGRwFU59/0Dyk4DhEafcrhsN4klo1L1KT6zT3 lheGih6CLscvrWb1j14V5NWMyutqEegnN4GomDko9uEKgs4W9gYxoMCftJaeff4Z3X22 0Gq7h9HdBYPB/niTIlUK5udvNjAPuFhyz9RPPByvEswayaDadmH2X/0k4qXi+jRWcgaP ZbrEzFGto+T2NPMH6wyNtTDNqEZvWOUGPwGguWw8pgUF2Jxo/VUhFaQ2Ud6cRlBJLXlf HWAA==; 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=FG6TLL8M; 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-129255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129255-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 m1-20020a170902f20100b001e2866a914dsi1687720plc.562.2024.04.03.01.14.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129255-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=FG6TLL8M; 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-129255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129255-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 E961328A21C for ; Wed, 3 Apr 2024 08:09:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D1FB129A9C; Wed, 3 Apr 2024 08:05:46 +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="FG6TLL8M" 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 01A2F127B45 for ; Wed, 3 Apr 2024 08:05:43 +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=1712131545; cv=none; b=sy7/UPT5Tl/6m+A2FOQW0sdK7pIRbB/+AKPHfH8Tl39tgxVWJ7fO8dDbM74FpHycLY+1cDatYYZN+rz2yriNCSN5llBSltZbs1UUdFvOPJ/auuXS2VCNMyJbWeu2K8o7ICHpPVNQQ8ywcCOZNdaVvRp0WMLKb+EgA1ZzjpFycPI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131545; c=relaxed/simple; bh=bM8YEfWLGTqv0xxOOBxSCTgoJM3x8dV7ewXvwA2n16I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gsyfui+Kx9oGf4sYWaCYlUird9U4DyUoCvEq86PXM4+C31ORvLwfkF1LkeTX/z9LfcWwChOu9yIgGQLDQ9opOnYOmuUpDBg8H+GoMjacBBzlnA/1Bxq3+NAuwh/GiraJZpWyOnhUN6QVurZ2hj6kyVOhJ/k72dbwiX3my0bAVzk= 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=FG6TLL8M; 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 Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1e0fa980d55so49276705ad.3 for ; Wed, 03 Apr 2024 01:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712131543; x=1712736343; 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=qwALXHKqCD9Iy5mIzImMbfILjpXmZkM44DIWXWIBe7w=; b=FG6TLL8M8EddF7b09NZAX4sghUKreVKn+OQPBt7iN4Urg/HX4tg7ZfI3vS1yCepBfh 1VMwqZ1OmCtwoW8b4W7mS7bPbpRKXQ/c6Z34MRqmhhyHGh1cmZSzc0k0OQZ3U3t7vaui SKc5CjnFciPh5SMKULT1b2KTH8BJ1SM8JCG1BYTv3hv04416kzHVzwoMlNciH0Ku36M+ dNdHBG2945liMqBBaxxSYhdItRZekvRekwPA4vdlKDQyoBUfKn+HjvliTjvsXSeQh5ka LkbfgJPMLXchVezjz5n5hHrW5XNaXkdjznqFKXhJ4+kUWi3fuN76+kwpXnIcHvbd6qf3 Po6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712131543; x=1712736343; 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=qwALXHKqCD9Iy5mIzImMbfILjpXmZkM44DIWXWIBe7w=; b=IwayJ1GZEsQu4lsgfqlUrgKF/OW0wC5sWtva7boul1QLwRI/Ex/fXHL7R7icMsssDy R5Ijyo7FFOuPCdFtFtqMK+qsoqdCMFAlgPF/zjOsr9FgzPEoV17ZhuLB3Yh2X6G+NA8/ kTvIVTzdL4xp7AysxtVrGBnPoSIInKZuGVfGDoRA/t93gN4JdZACdmZWSFUmC7CuSG5D jZq4UgQ6Vby0LJA16vQUAoACn7QgTCxPqwVtv7eu+fB23cC60ykRzlURpkeJEDs52u1J 2maVVaGaGaCVzZDeayo9NIcseD7d6P0oCgOjL1mw31HACzGQUA+BqRWtnGEqs8aS8AXo Qsrw== X-Gm-Message-State: AOJu0YwjMLRwQIGAADdDdIj2XWS+cDiqHNKk3DhtTkd10sURBQT/WVIq 2McW4wm/JCdI1v572pnT2SuFwy4Txb+BJyoIFqCfRwQT5Zq6AtVIAREm8Urx1el51l+AjwJdp2s E X-Received: by 2002:a17:903:2283:b0:1e0:b60e:1a33 with SMTP id b3-20020a170903228300b001e0b60e1a33mr2264737plh.31.1712131543069; Wed, 03 Apr 2024 01:05:43 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c12-20020a170902d48c00b001e0b5d49fc7sm12557229plg.161.2024.04.03.01.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:05:42 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Andrew Jones , 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, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org Subject: [PATCH v5 15/22] RISC-V: KVM: Improve firmware counter read function Date: Wed, 3 Apr 2024 01:04:44 -0700 Message-Id: <20240403080452.1007601-16-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403080452.1007601-1-atishp@rivosinc.com> References: <20240403080452.1007601-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. 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 ff326152eeff..94efa88d054d 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