Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7451880rwb; Wed, 23 Nov 2022 06:45:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ly8PahlEUCNzWr1RuAJyCIIBjLeo7Jc1Dx7qfDKodpRa6UqpE6HRVW81MJTwy1p/PsR8s X-Received: by 2002:a05:6402:5299:b0:461:7291:79c1 with SMTP id en25-20020a056402529900b00461729179c1mr16365067edb.68.1669214717418; Wed, 23 Nov 2022 06:45:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669214717; cv=none; d=google.com; s=arc-20160816; b=PukT78Cx2ijVAG6HiV8bWdP+09RN239aO9kjwbjZ+9rKpCXINoh89jYJhXTct/3wNP g+c03HZ8rQLoUOlQrxgaN48g8bWI/ZHNe1MAQq4S3iKRLEpJej2/dMq0Z0SyOUiNQCLT aqCeCRUUkj4Dnswy3Di5wodrj/dn6w0+fCeqOL39LorFP/fS1BybMbLMheLd8O9qjAgS yFFYN6wVwZbcPUO4ax4G0vnybPO54Ot1h+TRPRxgSNd57kJYD5wk/uUkKr9lu/b4mHr/ JWF12D+q2SGH/fxCziKXZ8VzujB7hEwKPhPoR4p//TMHpMsKfJW2b3Rei/vrq6MPtNJH P31g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=b1Quh2S4Mqiz+mnmyB9nbm+e1ppPa6f3UhLHFNBAwqA=; b=IdeW05iQl3/2LhWjfvW6Zg2nyIXJiifj68HeTWcDwOBNrNNDRGeKnApNzTfFTkB2Wx zBchHHGMRnWSjNIfIB/jyDyc8B4lroUYQrvMrbGafaQxryctMr8eemofTO8fWW1unqwF qD+I832sJJVl6/ltTfykgO4EGRsafE3kT4gSE1qtB6/3XOzTTLjhyikWyk5Hi5eGDHKd e+DwaxONY/CcbyupZbjCE+numqagkyVf1M/xnB9WC0yTL8JQdGoZjkYYkNK+mMorecee zzXTd4Rg4TB29N9qI/OrKTdHDsskdxyraPeMmJ+odAgB4dwUH9Jgj5r+K8YVOpOX79dq 9sNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RtArgD6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170906825100b007a1e33462c1si11124022ejx.268.2022.11.23.06.44.54; Wed, 23 Nov 2022 06:45:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RtArgD6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238394AbiKWOD4 (ORCPT + 89 others); Wed, 23 Nov 2022 09:03:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238351AbiKWODi (ORCPT ); Wed, 23 Nov 2022 09:03:38 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21DA6E5E for ; Wed, 23 Nov 2022 05:58:45 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id a11-20020a05600c2d4b00b003cf6f5fd9f1so1350174wmg.2 for ; Wed, 23 Nov 2022 05:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=b1Quh2S4Mqiz+mnmyB9nbm+e1ppPa6f3UhLHFNBAwqA=; b=RtArgD6+Z8rmyrUSFbh8yCVa5eEuQ0iy1z/3lv/Pmpd0w0tSDdpujqmsSNJX0x4mmd WIqT4YBwZWrDyaCzY1bdpaGY+t7jMv9Pmu8HJe4Ndtz5E587A2I0rUl3lg5TwjHg/xPH yYn/G0QQkQ52ZgshAgQCyG0Ebv3wSa1WZWYBwjQJxwIssdAKD9kSMNAAuet4myzGnmBB RIfNzvIIMxrxOIKnK6F0MMkFixiH8KV09xVtHfISjKrgPaerVMMXn6TFlMfNteX48vha Ly17fqLt5ylR2IGFfF3VVsfXofaivmpU9lSqRo2pxgwVH54gPAxL/HT55x90YlejspCV GZUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=b1Quh2S4Mqiz+mnmyB9nbm+e1ppPa6f3UhLHFNBAwqA=; b=2FpjvDGHF2UaYgARNBYXJnn9DV+hhzav67oOAGbpJVCAxm+h3PLl7ITW/3O+bAYlZ9 YXWrb4fj99maQeofZWnCYLsMLnyuWPdCxWLALSo4o3r5hMkgItS5O2KWpkYMBjRri2dq 1PJSXgq8Ae7n7jOw22nm6P7sVQaRmOfb4lwRU/H7iU+B1bXl0dYusvXtOhanlqon8l8v HlJiODGJ8xK8iGJm+JKHxcpuCGLxYnejtWdAMjjzwIAkTm6FAHL71WVFiCaG1M1fT4lU zEQbABJEU1sLMi4a3lrTK/HQfvq+4Vt7k1E8nfVFo/XB3x47v3uymHSPG7M7/0QAi68s Psiw== X-Gm-Message-State: ANoB5pnt044t7ElvSI4+E6YZTHX4voPh6RCp03SLiADHkwr3Jcpe6H2o CQlST1ctb+HFyRHX/5+3zt1b9g== X-Received: by 2002:a05:600c:4f55:b0:3cf:729b:d4b4 with SMTP id m21-20020a05600c4f5500b003cf729bd4b4mr14142344wmq.48.1669211923651; Wed, 23 Nov 2022 05:58:43 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-748-2a9a-a2a6-1362.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:748:2a9a:a2a6:1362]) by smtp.gmail.com with ESMTPSA id y10-20020a5d620a000000b002366dd0e030sm16751799wru.68.2022.11.23.05.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 05:58:43 -0800 (PST) Date: Wed, 23 Nov 2022 14:58:42 +0100 From: Andrew Jones To: Atish Patra Cc: Atish Patra , linux-kernel@vger.kernel.org, Albert Ou , Anup Patel , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: Re: [RFC 6/9] RISC-V: KVM: Add SBI PMU extension support Message-ID: <20221123135842.uyw46kbybgb7unm2@kamzik> References: <20220718170205.2972215-1-atishp@rivosinc.com> <20220718170205.2972215-7-atishp@rivosinc.com> <20221101142631.du54p4kyhlgf54cr@kamzik> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 22, 2022 at 03:08:34PM -0800, Atish Patra wrote: > On Tue, Nov 1, 2022 at 7:26 AM Andrew Jones wrote: > > > > On Mon, Jul 18, 2022 at 10:02:02AM -0700, Atish Patra wrote: ... > > > +static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, > > > + unsigned long *out_val, > > > + struct kvm_cpu_trap *utrap, > > > + bool *exit) > > > +{ > > > + int ret = -EOPNOTSUPP; > > > + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; > > > + unsigned long funcid = cp->a6; > > > + uint64_t temp; > > > > I think we need something like > > > > if (!vcpu_to_pmu(vcpu)->enabled) > > return -EOPNOTSUPP; > > > > here. Where 'enabled' is only true when we successfully initialize > > the pmu. And, successful initialization depends on > > Yes. I have added the flag. But should we do the check here or > respective function > as a paranoia sanity check ? I think something like above that returns a not-supported error should be in all the entry points, like the top level SBI call handler. Functions that should never be called unless the PMU is active could have WARNs added for sanity checks. > > > IS_ENABLED(CONFIG_RISCV_PMU_SBI) and > > Why do we need to guard under CONFIG_RISCV_PMU_SBI ? > vcpu_sbi_pmu.c is only compiled under CONFIG_RISCV_PMU_SBI > > If CONFIG_RISCV_PMU_SBI is not enabled, probe function will return failure. You're right. We don't need explicit config checks for things that can't exist without the config. > > In fact, I think we should also add the pmu enabled check in the probe function > itself. Probe function(kvm_sbi_ext_pmu_probe) should only true when > both vcpu_to_pmu(vcpu)->enabled and > riscv_isa_extension_available(NULL, SSCOFPMF) are true. > > Thoughts? Agreed. > > > riscv_isa_extension_available(NULL, SSCOFPMF) as well as not > > failing other things. And, KVM userspace should be able to > > disable the pmu, which keep enabled from being set as well. > > > We already have provisions for disabling sscofpmf from guests via ISA > one reg interface. > Do you mean disable the entire PMU from userspace ? Yes. We may need to configure a VM without a PMU to increase its migratability, workaround errata, or just for testing/debugging purposes. > > Currently, ARM64 enables pmu from user space using device control APIs > on vcpu fd. > Are you suggesting we should do something like that ? Yes. Although choosing which KVM API should be used could probably be thought-out again. x86 uses VM ioctls. > > If PMU needs to have device control APIs (either via vcpu fd or its > own), we can retrieve > the hpmcounter width and count from there as well. Right. We need to decide how the VM/VCPU + PMU user interface should look. A separate PMU device, like arm64 has, sounds good, but the ioctl sequences for initialization may get more tricky. Thanks, drew