Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66CFEC636D4 for ; Tue, 7 Feb 2023 09:20:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231667AbjBGJU5 (ORCPT ); Tue, 7 Feb 2023 04:20:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231567AbjBGJUa (ORCPT ); Tue, 7 Feb 2023 04:20:30 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A51624C96 for ; Tue, 7 Feb 2023 01:20:24 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id w20so10305468pfn.4 for ; Tue, 07 Feb 2023 01:20:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=616h4CPqRb9+yGgK1+zMae6bPtCXWD1O+JIiZJuuAN4=; b=POuFDmmZM+HsSNu3Ig6MrYzwr3GM4CyOQdDe7V11yiwyZPXSCPNLzrlt076FyPn9N3 Ra3OCljjkArBP9GamaRLVX37vdcbOskg+wqXX/KuFLOrm5AYkm4n/TmA6Zn3pxImfTlT OL0CV63kV1gNyVRmGC8U56R9ST6dZfBwW6N/w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=616h4CPqRb9+yGgK1+zMae6bPtCXWD1O+JIiZJuuAN4=; b=MLh8rdkkiUOp0mX8gRMfp6B9jZ1dXElHVZdcTU799Nn/Df/PZOl1XRcz+/3oGFSE6J bUfH1G7J6UvIg4WbDM/5on4hlb6FD/+c0UR4iltBkK+1QUtC3YxZsYniBTNeZISlteUX OvB9gfgyzhTb4bc+V4OldaGeVenYmS4U5yNhZMdHqL1H8Dwii7tQDDv1jwMAimox1beR KrGLSQ2nwQjGb7t5Wry3AZByCH7hAqCVyX3767aAJaa6nIG6L5D2ZBJ8n6lUKVe5H98N D29wU4wKaslFrt3vj46Tkw3dlceY538qo+w9n8EoWbrORQdJSDOEVeCSueLHns3yGjnx +rNw== X-Gm-Message-State: AO0yUKWAbdG3z55mmALq+f9eJsfpooCvmiiELbYJ2neDMhRJ2i5xmaOd yP3kLNZZEYgKCyN590Wf75fULU6ywcYL+xZtJjGI X-Google-Smtp-Source: AK7set8u2ObsZbLlP0iS0NBdphAYXHsP07SB/g80AsW6PNgCWskBsHThfsh9+Xa6vPihwEdNRDQUptXNmQK/81bFsSg= X-Received: by 2002:a63:7a56:0:b0:4c7:ef33:bbe1 with SMTP id j22-20020a637a56000000b004c7ef33bbe1mr415970pgn.73.1675761624040; Tue, 07 Feb 2023 01:20:24 -0800 (PST) MIME-Version: 1.0 References: <20230201231250.3806412-1-atishp@rivosinc.com> <20230201231250.3806412-8-atishp@rivosinc.com> <20230202170345.uwi72dauzunlzxex@orel> <20230206092204.aiyo43uxlm4xdmgn@orel> <20230206113945.vcnrokltvzgifsqu@orel> In-Reply-To: <20230206113945.vcnrokltvzgifsqu@orel> From: Atish Patra Date: Tue, 7 Feb 2023 01:20:12 -0800 Message-ID: Subject: Re: [PATCH v4 07/14] RISC-V: KVM: Add skeleton support for perf To: Andrew Jones Cc: Atish Patra , linux-kernel@vger.kernel.org, Albert Ou , Anup Patel , Eric Lin , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 6, 2023 at 3:39 AM Andrew Jones wrote: > > On Mon, Feb 06, 2023 at 10:22:04AM +0100, Andrew Jones wrote: > > On Sat, Feb 04, 2023 at 11:37:47PM -0800, Atish Patra wrote: > > > On Fri, Feb 3, 2023 at 12:47 AM Atish Patra wrote: > > > > > > > > On Thu, Feb 2, 2023 at 9:03 AM Andrew Jones wrote: > > > > > > > > > > On Wed, Feb 01, 2023 at 03:12:43PM -0800, Atish Patra wrote: > > > > > > This patch only adds barebone structure of perf implementation. Most of > > > > > > the function returns zero at this point and will be implemented > > > > > > fully in the future. > > > > > > > > > > > > Signed-off-by: Atish Patra > > > > > > --- > > > > > > arch/riscv/include/asm/kvm_host.h | 4 + > > > > > > arch/riscv/include/asm/kvm_vcpu_pmu.h | 78 +++++++++++++++ > > > > > > arch/riscv/kvm/Makefile | 1 + > > > > > > arch/riscv/kvm/vcpu.c | 7 ++ > > > > > > arch/riscv/kvm/vcpu_pmu.c | 136 ++++++++++++++++++++++++++ > > > > > > 5 files changed, 226 insertions(+) > > > > > > create mode 100644 arch/riscv/include/asm/kvm_vcpu_pmu.h > > > > > > create mode 100644 arch/riscv/kvm/vcpu_pmu.c > > > > > > > > > > > > diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h > > > > > > index 93f43a3..b90be9a 100644 > > > > > > --- a/arch/riscv/include/asm/kvm_host.h > > > > > > +++ b/arch/riscv/include/asm/kvm_host.h > > > > > > @@ -18,6 +18,7 @@ > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > +#include > > > > > > > > > > > > #define KVM_MAX_VCPUS 1024 > > > > > > > > > > > > @@ -228,6 +229,9 @@ struct kvm_vcpu_arch { > > > > > > > > > > > > /* Don't run the VCPU (blocked) */ > > > > > > bool pause; > > > > > > + > > > > > > + /* Performance monitoring context */ > > > > > > + struct kvm_pmu pmu_context; > > > > > > }; > > > > > > > > > > > > static inline void kvm_arch_hardware_unsetup(void) {} > > > > > > diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h > > > > > > new file mode 100644 > > > > > > index 0000000..e2b4038 > > > > > > --- /dev/null > > > > > > +++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h > > > > > > @@ -0,0 +1,78 @@ > > > > > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > > > > > +/* > > > > > > + * Copyright (c) 2023 Rivos Inc > > > > > > + * > > > > > > + * Authors: > > > > > > + * Atish Patra > > > > > > + */ > > > > > > + > > > > > > +#ifndef __KVM_VCPU_RISCV_PMU_H > > > > > > +#define __KVM_VCPU_RISCV_PMU_H > > > > > > + > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > + > > > > > > +#ifdef CONFIG_RISCV_PMU_SBI > > > > > > +#define RISCV_KVM_MAX_FW_CTRS 32 > > > > > > + > > > > > > +#if RISCV_KVM_MAX_FW_CTRS > 32 > > > > > > +#error "Maximum firmware counter can't exceed 32 without increasing the RISCV_MAX_COUNTERS" > > > > > > > > > > "The number of firmware counters cannot exceed 32 without increasing RISCV_MAX_COUNTERS" > > > > > > > > > > > +#endif > > > > > > + > > > > > > +#define RISCV_MAX_COUNTERS 64 > > > > > > > > > > But instead of that message, what I think we need is something like > > > > > > > > > > #define RISCV_KVM_MAX_HW_CTRS 32 > > > > > #define RISCV_KVM_MAX_FW_CTRS 32 > > > > > #define RISCV_MAX_COUNTERS (RISCV_KVM_MAX_HW_CTRS + RISCV_KVM_MAX_FW_CTRS) > > > > > > > > > > static_assert(RISCV_MAX_COUNTERS <= 64) > > > > > > > > > > And then in pmu_sbi_device_probe() should ensure > > > > > > > > > > num_counters <= RISCV_MAX_COUNTERS > > > > > > > > > > and pmu_sbi_get_ctrinfo() should ensure > > > > > > > > > > num_hw_ctr <= RISCV_KVM_MAX_HW_CTRS > > > > > num_fw_ctr <= RISCV_KVM_MAX_FW_CTRS > > > > > > > > > > which has to be done at runtime. > > > > > > > > > > > > > Sure. I will add the additional sanity checks. > > > > > > > > > > As explained above, I feel we shouldn't mix the firmware number of > > > counters that the host gets and it exposes to a guest. > > > So I have not included this suggestion in the v5. > > > I have changed the num_fw_ctrs to PMU_FW_MAX though to accurately > > > reflect the firmware counters KVM is actually using. > > > > Sounds good > > I just looked at v5. IMO, much of what I proposed above still makes > sense, since what I'm proposing is that the relationship between > RISCV_KVM_MAX_HW_CTRS, RISCV_KVM_MAX_FW_CTRS, RISCV_MAX_COUNTERS, and 64 > (our current max bitmap size) be explicitly checked. So, even if we want > RISCV_KVM_MAX_FW_CTRS to be SBI_PMU_FW_MAX, it'd be good to have > > #define RISCV_KVM_MAX_HW_CTRS 32 > > (And a runtime check confirming num_hw_ctrs + 1 <= RISCV_KVM_MAX_HW_CTRS, > and then either silently capping or issuing a warning and capping) > > And, to be sure the sum of RISCV_KVM_MAX_FW_CTRS and RISCV_KVM_MAX_HW_CTRS > doesn't exceed the size of the bitmap > > #define RISCV_KVM_MAX_FW_CTRS SBI_PMU_FW_MAX > #define RISCV_MAX_COUNTERS (RISCV_KVM_MAX_HW_CTRS + RISCV_KVM_MAX_FW_CTRS) > static_assert(RISCV_MAX_COUNTERS <= 64) > ok. I have added those changes but I have modified RISCV_MAX_COUNTERS to RISCV_KVM_MAX_COUNTERS, to avoid overlapping with the RISCV_MAX_COUNTERS defined in the host. Logically, the host and the guest can have separate counters anyways. > Thanks, > drew > > > > > > I don't know if there is any benefit of static_assert over #error. > > > Please let me know if you feel strongly about that. > > > > One "normal" line vs. three #-lines? > > Fair enough. Fixed. > > Thanks, > > drew -- Regards, Atish