From mboxrd@z Thu Jan 1 00:00:00 1970 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 E4CD6C05027 for ; Sun, 29 Jan 2023 12:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234618AbjA2MgL (ORCPT ); Sun, 29 Jan 2023 07:36:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231796AbjA2MgK (ORCPT ); Sun, 29 Jan 2023 07:36:10 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA5C622017 for ; Sun, 29 Jan 2023 04:36:07 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id mc11so2319748ejb.10 for ; Sun, 29 Jan 2023 04:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pon3MbPPW13P0zNvYCd1smE05PP2P+jwr/geqehNzwE=; b=NhkuOfB0ra/AVj6j2EVFceBuFWItZkPYikE2pzqJ6Zb0E9Y5TN/8qH2vVwbALlL/n2 XnWF7FqbsQrX8yG6z7gdiye1PfgdSRbBOUuzr5zYIXG5/HLudCCRaqut3pJOsPZXJc+G G6QsqPS7Q4QvSuaKK5Pf4FwwPL91+uJPw7r26FceO4Dfpxk1tHvfHbpq+mVeMqDpheWb CdC46mTCMan0NFCDEKcAEdxs5CKmqc3Q1YpUgg72vgO/6DCsywnKpDauA13yA6Vx/rhw 4p22AxAKKP6EhmJ5jwk/XP1c3SUu1ewaQjqmzwhC8UX3SX2hBNfaZPSqJf+oz8FmU5fB /cww== 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=pon3MbPPW13P0zNvYCd1smE05PP2P+jwr/geqehNzwE=; b=clhRcwtS1b0vHQp2TTEACTeYjWVd6hpzgB8kPfo7emCMIdjeDftSWHo2ZalREj6UCP 4EU9M+JnhjpR4bAPxFtT8Xp6yOPnacksdvTun2YAM1quoYcitxbtgfssCYE7QC6/moZg W7f0pJeBn4ps3vaZBKehbpx/u7E5N2UAIlYmFif4DNB7KE8WrGDJKoxXHhIVvVTFftC1 ovspq5U1jvBW8YMM2LMRu7kZEuERYJ42k8hmTvePzbnNCiVcEz1XR1tSTfVv2sh6qjUp e0bSIa6hkzXVYqb+ctlN/nKloK9utzRODugxA4He4TsFtlS9u5DXuxO46exq6m+Wty8O Libg== X-Gm-Message-State: AFqh2kr6ugIOcMfkVX4wlkpv8ohMspuiS29rWwDUuJXf5jO9Wfk3w02b fvHev4NYLU5TTf+qmrUlrEcV2sL7Pkc+zVOGQhwlOg== X-Google-Smtp-Source: AMrXdXvB3OmLcvEfxFlWKF6yDJduujeg3HFdqoO8lqh4sAOeyWvSijhDyFKCWrJUJ1Xhhmu2uSm7mtH1XcFgoyIBMcg= X-Received: by 2002:a17:906:6a8e:b0:86e:3764:4f80 with SMTP id p14-20020a1709066a8e00b0086e37644f80mr5739206ejr.239.1674995766162; Sun, 29 Jan 2023 04:36:06 -0800 (PST) MIME-Version: 1.0 References: <20230127182558.2416400-1-atishp@rivosinc.com> <20230127182558.2416400-10-atishp@rivosinc.com> In-Reply-To: <20230127182558.2416400-10-atishp@rivosinc.com> From: Anup Patel Date: Sun, 29 Jan 2023 18:05:55 +0530 Message-ID: Subject: Re: [PATCH v3 09/14] RISC-V: KVM: Make PMU functionality depend on Sscofpmf To: Atish Patra Cc: linux-kernel@vger.kernel.org, Andrew Jones , Atish Patra , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Sergey Matyukevich , Will Deacon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 27, 2023 at 11:56 PM Atish Patra wrote: > > The privilege mode filtering feature must be available in the host so > that the host can inhibit the counters while the execution is in HS mode. > Otherwise, the guests may have access to critical guest information. > > Signed-off-by: Atish Patra Looks good to me. Reviewed-by: Anup Patel Regards, Anup > --- > arch/riscv/kvm/vcpu_pmu.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c > index d3fd551..7713927 100644 > --- a/arch/riscv/kvm/vcpu_pmu.c > +++ b/arch/riscv/kvm/vcpu_pmu.c > @@ -79,6 +79,14 @@ int kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu) > struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu); > struct kvm_pmc *pmc; > > + /* > + * PMU functionality should be only available to guests if privilege mode > + * filtering is available in the host. Otherwise, guest will always count > + * events while the execution is in hypervisor mode. > + */ > + if (!riscv_isa_extension_available(NULL, SSCOFPMF)) > + return 0; > + > ret = riscv_pmu_get_hpm_info(&hpm_width, &num_hw_ctrs); > if (ret < 0) > return ret; > -- > 2.25.1 > From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D1AAC61D97 for ; Sun, 29 Jan 2023 12:36:22 +0000 (UTC) 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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NqQnVem3aFpbNCwUJyig2apjq4JhTI8leLmiW3PO4Ds=; b=dnSOC/+vtuJ5/O HXG6UW4AXhSLuSjgtG/XJ69VowreKaZUDoUQ+kiXM2cOkbodC0bt9hxJgSgTFuxefr0Tsq16K855b ibC7TG5ix6D+dUB2PI98PqEwgXRTceQOUXnIY8WfqVV5lBftNGS6Mck7GdmROxTUpu9jqr8MFtvxl TgD+vs0rIrDvJaro59NN3VDlLbeo8fBCTnaxgGrVT29urSUEAZ3Q2dJ+RoWXd2+th7BJ/kVd5RhPt hTTI5EoRetVUcUuBr3F8s+gVkpCCLUUx01UTDwq1JKqNnOANw6lkl5CNooKmu9SkQlaKLbTImAtOE BRq3ae9L3tZl7MDRW+Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pM6ur-001Qvb-R9; Sun, 29 Jan 2023 12:36:13 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pM6um-001Qu2-Bo for linux-riscv@lists.infradead.org; Sun, 29 Jan 2023 12:36:12 +0000 Received: by mail-ej1-x636.google.com with SMTP id qw12so8893251ejc.2 for ; Sun, 29 Jan 2023 04:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pon3MbPPW13P0zNvYCd1smE05PP2P+jwr/geqehNzwE=; b=NhkuOfB0ra/AVj6j2EVFceBuFWItZkPYikE2pzqJ6Zb0E9Y5TN/8qH2vVwbALlL/n2 XnWF7FqbsQrX8yG6z7gdiye1PfgdSRbBOUuzr5zYIXG5/HLudCCRaqut3pJOsPZXJc+G G6QsqPS7Q4QvSuaKK5Pf4FwwPL91+uJPw7r26FceO4Dfpxk1tHvfHbpq+mVeMqDpheWb CdC46mTCMan0NFCDEKcAEdxs5CKmqc3Q1YpUgg72vgO/6DCsywnKpDauA13yA6Vx/rhw 4p22AxAKKP6EhmJ5jwk/XP1c3SUu1ewaQjqmzwhC8UX3SX2hBNfaZPSqJf+oz8FmU5fB /cww== 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=pon3MbPPW13P0zNvYCd1smE05PP2P+jwr/geqehNzwE=; b=wACe7nwR7NlsPR9vhyQgNwOkq/3ajdqCDmVMblNGCpo4B7fDgWtG1ZgrNFWQ6FIWIo P2IYOzJTWZCSBjSOjsLZ4/9EvFV83QOw/9bv4TwBnnmvf81gYRftef8C0ZqfJTTtN6+p 6TPUuqTyy4fQo2p1VSWCBP7v82QmVde1jCIgg3Bd9IfYfk/guVCZ00cOHVb+hoCU/Vw0 At4e5S/mZXEh2E8PmSiY2ZoB8iQkoLE0Nxi1tApnYfnJEx5xDG32nU+CoPatSW03fJKi S7mWbJXNrrqMZYStwOt7tYwFvojp7CDSTV2kJYG214iH1NivV8k5rJOMGa+FHLc+KcNd Hclg== X-Gm-Message-State: AFqh2kqpiyxIG3CNWdxf1yCS6dFgBqYgAijStNInit45P8hmd3jClVBf 2ZB4APC9UuTI1D0w7koHKN6xIDpnRcr0IHuvjwKMOg== X-Google-Smtp-Source: AMrXdXvB3OmLcvEfxFlWKF6yDJduujeg3HFdqoO8lqh4sAOeyWvSijhDyFKCWrJUJ1Xhhmu2uSm7mtH1XcFgoyIBMcg= X-Received: by 2002:a17:906:6a8e:b0:86e:3764:4f80 with SMTP id p14-20020a1709066a8e00b0086e37644f80mr5739206ejr.239.1674995766162; Sun, 29 Jan 2023 04:36:06 -0800 (PST) MIME-Version: 1.0 References: <20230127182558.2416400-1-atishp@rivosinc.com> <20230127182558.2416400-10-atishp@rivosinc.com> In-Reply-To: <20230127182558.2416400-10-atishp@rivosinc.com> From: Anup Patel Date: Sun, 29 Jan 2023 18:05:55 +0530 Message-ID: Subject: Re: [PATCH v3 09/14] RISC-V: KVM: Make PMU functionality depend on Sscofpmf To: Atish Patra Cc: linux-kernel@vger.kernel.org, Andrew Jones , Atish Patra , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Sergey Matyukevich , Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230129_043608_422155_8D184F83 X-CRM114-Status: GOOD ( 17.73 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, Jan 27, 2023 at 11:56 PM Atish Patra wrote: > > The privilege mode filtering feature must be available in the host so > that the host can inhibit the counters while the execution is in HS mode. > Otherwise, the guests may have access to critical guest information. > > Signed-off-by: Atish Patra Looks good to me. Reviewed-by: Anup Patel Regards, Anup > --- > arch/riscv/kvm/vcpu_pmu.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c > index d3fd551..7713927 100644 > --- a/arch/riscv/kvm/vcpu_pmu.c > +++ b/arch/riscv/kvm/vcpu_pmu.c > @@ -79,6 +79,14 @@ int kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu) > struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu); > struct kvm_pmc *pmc; > > + /* > + * PMU functionality should be only available to guests if privilege mode > + * filtering is available in the host. Otherwise, guest will always count > + * events while the execution is in hypervisor mode. > + */ > + if (!riscv_isa_extension_available(NULL, SSCOFPMF)) > + return 0; > + > ret = riscv_pmu_get_hpm_info(&hpm_width, &num_hw_ctrs); > if (ret < 0) > return ret; > -- > 2.25.1 > _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv