Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp651635lqp; Fri, 5 Apr 2024 05:10:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVU1AOJzTs1e+050DbkwwWtjhyCQXYmLHOhaewRUQv/eIdQ5xCaunesZoQ3WPm0+qppElDZ9jKUWsuO5IIKbIv5OnwzollXm16cvU1lZA== X-Google-Smtp-Source: AGHT+IFkKF61AxDgItTgGQmoHrdjyLUyaI4aLAsxeXb38jgyR2Ag1ndseSzjsdHulEZ1pg82Dv2F X-Received: by 2002:a05:6359:5142:b0:183:a47e:6284 with SMTP id oc2-20020a056359514200b00183a47e6284mr1213317rwb.5.1712319048930; Fri, 05 Apr 2024 05:10:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712319048; cv=pass; d=google.com; s=arc-20160816; b=nEgzLBtnavT5DanDVTktTmToS4N2HF6M+yp08agqZrMliBZL9EIkbpNhPWurxuzV+o SW7/0/COpSlaF5QgY27uyoSDIxz74q6xquD1tsgs9xKD4W/sxLXiRnnJuhUshit0l34G esoAvK8/JL5IYaK8EuNerw0AhzcQGH98qD1VeSmCo2xImQQuzbZNikpvt4O02qQibPO9 KL7G0QM2jSDC4RdKnUWaLDhnIVh3vszi/q+mhpJLKOUsjIUUIyABiZr9Qm1vTXtK7MJ/ qYy9wI9Be+1+QxKKrS347RIw3QDAILu4cf8DHuWWHPOqsE6/HlxIJP/MDxGfEeB45At3 vugw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=en++ou90w+echMP7REhkEA6fNREBrRLo/x86xMpLdGE=; fh=gaKXNLThCBu7XqEF+OIYsPuGXO9AUGCWBxjHRzZNzhM=; b=dsUPiIs+6t4i65+O+/Lit9isbanxgOMFDEqlGZc+13J2KEkrlX9kqQT5w7eNN8h/ay vlRMQTZIgCTFp3w5GP5ONXCVCCA5XgfuG1CsZbKdAZ4sT1vH1PRZIYhSvYEtwdP/oGje dGxZJrdVUgv2brQr7yUThflmnA0gv7LXjUjAE9i9x3LeSXa38gdwIB+gbodBW+XzCseZ 8tRY8By4IxWpTkfQGqP/CHCktJUOppbN5encfnGNYLPrNAaF6Ov+n5ObDOwjG5gTNRdX UZVzbyT+6lZuURwv9wm5DLG0JAfz89T9L3HrVempyYwJyhdHeDhCHnyPPjzexMi4tOf2 Wg/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aBtPzcQ5; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-132955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132955-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s9-20020a056102370900b00479dedd3a7csi71211vst.133.2024.04.05.05.10.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 05:10:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aBtPzcQ5; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-132955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132955-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 889231C20BE5 for ; Fri, 5 Apr 2024 12:10:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33E6216C867; Fri, 5 Apr 2024 12:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="aBtPzcQ5" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.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 59CE016C84A for ; Fri, 5 Apr 2024 12:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712319038; cv=none; b=mQqd4QDPOH7SuXjS+/iP3pm0KJKPjB7WNUhF8kikXXvlaS+5dA6Ca2P/n4in7YHye+STftJfnXe7oMl9blhVMwjgOVrp73VLVYeAklPfRRtqUz/JxdNTt+OLcj6PtfjaqXR1OBhD6fHgnJslwPo0fqTkwmqnQXCyjTI9fbWtohI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712319038; c=relaxed/simple; bh=3Z9ZBDg8byD1z+Fk/GQuEQBsa+swzZyx2Lz/7j+AnmE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S7QEADB6nZmDvqURxFHrBzXFuCdAnUNz1PX+D2mam+ZmOtkU/5bTbN1dfgms3pxmEAygcqSQyBnJRRip5s33emoRUy75Y3Y5g3HJrLgByWi/tBF56UBuXmJ7XHnzXkmxaUIWiOKaOXZTdkgmFxrW2JiIjowDOTcgBbeBVgSFQ5Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=aBtPzcQ5; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d485886545so37279021fa.2 for ; Fri, 05 Apr 2024 05:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1712319034; x=1712923834; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=en++ou90w+echMP7REhkEA6fNREBrRLo/x86xMpLdGE=; b=aBtPzcQ5nDiI6mcGK4NEfJafUA4rZ/Gichz9jqKmZ7pM+gYE416N6xVjIHwTm/uflD tYXbSRgCA4b+SmB5wo6BHUqVYfA8uKhzzLKZf7yiLr4r74QVeHzmvKlMxgSHvAglTFOy VF+Tj7l5seCHU47Kp6v5NJAQShIhZV3sHvU9u1LMYbF3a39JxtRWfuBjLFEQYHOyJZtp LwWSPqzP/LUvgibt6QK1aT9xYAnnF8M8fT1/UFrcYOEZ/I744M1BRJp9/Jhi9PkgYLTo eM7iHd3LfI4p36JPr9vkp5DYddmBXsGpGra0TJN7JBMdwsXCLkMc/XcPtiJKAOexOkVW kZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712319034; x=1712923834; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=en++ou90w+echMP7REhkEA6fNREBrRLo/x86xMpLdGE=; b=DpjW+8fmrh3xVrvEc8iZX/an9kJgMUdz2qfSc/PofNhgyAs2Wr888oEyxo9WHpmzfj ImwyayaY/5tYHf334BAHFD+/wfAKIDbd27D9Xh7SjPzA3P9+iBLbPmEGaeS668JiRq5B 5Z9Nz0athOsJ/tK0ygndgegZ9deK6XvDvtYsCC4M4g9bY8yb3iztoHnksNdGvuSOamEh ap0IYw2CODR9yWtLu5zoSmJl8QOqVze5GLHevFEd29BcfXIYtRi62darpe2LP3JiTNP7 GlxYuKFhQgE+8SgklyVpmCAgGpBqC0m7OQF/5YkFfERgUGtGo8LEbfoVtaJR5B8yjBJ1 JWew== X-Gm-Message-State: AOJu0Yx91A3LO+cvK3lkv9nbtnjVRAxRfE0qJHkhHjWMPadQVomLBKm9 TK2ep6nXTOCCnFH+VxGmoASP6sP6J+DtSqDLnzikNz6ZwGbICNie9qHqWTt4Tvo= X-Received: by 2002:a05:651c:49d:b0:2d6:f793:3434 with SMTP id s29-20020a05651c049d00b002d6f7933434mr1296826ljc.2.1712319034264; Fri, 05 Apr 2024 05:10:34 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id j31-20020a5d6e5f000000b0033fc06f2d84sm1872775wrz.109.2024.04.05.05.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 05:10:33 -0700 (PDT) Date: Fri, 5 Apr 2024 14:10:32 +0200 From: Andrew Jones To: Atish Patra Cc: linux-kernel@vger.kernel.org, Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , 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: Re: [PATCH v5 14/22] RISC-V: KVM: Support 64 bit firmware counters on RV32 Message-ID: <20240405-6ef7f32d45deb5edd2d54ecb@orel> References: <20240403080452.1007601-1-atishp@rivosinc.com> <20240403080452.1007601-15-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240403080452.1007601-15-atishp@rivosinc.com> On Wed, Apr 03, 2024 at 01:04:43AM -0700, Atish Patra wrote: > The SBI v2.0 introduced a fw_read_hi function to read 64 bit firmware > counters for RV32 based systems. > > Add infrastructure to support that. > > Reviewed-by: Anup Patel > Signed-off-by: Atish Patra > --- > arch/riscv/include/asm/kvm_vcpu_pmu.h | 4 ++- > arch/riscv/kvm/vcpu_pmu.c | 44 ++++++++++++++++++++++++++- > arch/riscv/kvm/vcpu_sbi_pmu.c | 6 ++++ > 3 files changed, 52 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h > index 257f17641e00..55861b5d3382 100644 > --- a/arch/riscv/include/asm/kvm_vcpu_pmu.h > +++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h > @@ -20,7 +20,7 @@ static_assert(RISCV_KVM_MAX_COUNTERS <= 64); > > struct kvm_fw_event { > /* Current value of the event */ > - unsigned long value; > + u64 value; > > /* Event monitoring status */ > bool started; > @@ -91,6 +91,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba > struct kvm_vcpu_sbi_return *retdata); > int kvm_riscv_vcpu_pmu_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); > 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, > diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c > index 9fedf9dc498b..ff326152eeff 100644 > --- a/arch/riscv/kvm/vcpu_pmu.c > +++ b/arch/riscv/kvm/vcpu_pmu.c > @@ -197,6 +197,36 @@ static int pmu_get_pmc_index(struct kvm_pmu *pmu, unsigned long eidx, > return kvm_pmu_get_programmable_pmc_index(pmu, eidx, cbase, cmask); > } > > +static int pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx, > + unsigned long *out_val) > +{ > + struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu); > + struct kvm_pmc *pmc; > + int fevent_code; > + > + if (!IS_ENABLED(CONFIG_32BIT)) { > + pr_warn("%s: should be invoked for only RV32\n", __func__); > + return -EINVAL; > + } > + > + 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) > + return -EINVAL; > + > + fevent_code = get_event_code(pmc->event_idx); > + pmc->counter_val = kvpmu->fw_event[fevent_code].value; > + > + *out_val = pmc->counter_val >> 32; > + > + return 0; > +} > + > static int pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, > unsigned long *out_val) > { > @@ -705,6 +735,18 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba > return 0; > } > > +int kvm_riscv_vcpu_pmu_fw_ctr_read_hi(struct kvm_vcpu *vcpu, unsigned long cidx, > + struct kvm_vcpu_sbi_return *retdata) > +{ > + int ret; > + > + ret = pmu_fw_ctr_read_hi(vcpu, cidx, &retdata->out_val); > + if (ret == -EINVAL) > + retdata->err_val = SBI_ERR_INVALID_PARAM; > + > + return 0; > +} > + > int kvm_riscv_vcpu_pmu_ctr_read(struct kvm_vcpu *vcpu, unsigned long cidx, > struct kvm_vcpu_sbi_return *retdata) > { > @@ -778,7 +820,7 @@ void kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu) > pmc->cinfo.csr = CSR_CYCLE + i; > } else { > pmc->cinfo.type = SBI_PMU_CTR_TYPE_FW; > - pmc->cinfo.width = BITS_PER_LONG - 1; > + pmc->cinfo.width = 63; > } > } > > diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c > index d3e7625fb2d2..cf111de51bdb 100644 > --- a/arch/riscv/kvm/vcpu_sbi_pmu.c > +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c > @@ -64,6 +64,12 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, > case SBI_EXT_PMU_COUNTER_FW_READ: > ret = kvm_riscv_vcpu_pmu_ctr_read(vcpu, cp->a0, retdata); > break; > + case SBI_EXT_PMU_COUNTER_FW_READ_HI: > + if (IS_ENABLED(CONFIG_32BIT)) > + ret = kvm_riscv_vcpu_pmu_fw_ctr_read_hi(vcpu, cp->a0, retdata); > + else > + retdata->out_val = 0; > + break; > case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM: > ret = kvm_riscv_vcpu_pmu_snapshot_set_shmem(vcpu, cp->a0, cp->a1, cp->a2, retdata); > break; > -- > 2.34.1 > Reviewed-by: Andrew Jones