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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DEC0C00140 for ; Wed, 10 Aug 2022 07:08:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 769104D593; Wed, 10 Aug 2022 03:08:16 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@linux.dev Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wThFZFLG4sZR; Wed, 10 Aug 2022 03:08:15 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 3E0984D595; Wed, 10 Aug 2022 03:08:15 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id B38CA4D590 for ; Wed, 10 Aug 2022 03:08:14 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dOYkr-zsZ-BZ for ; Wed, 10 Aug 2022 03:08:13 -0400 (EDT) Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 8639F4D58F for ; Wed, 10 Aug 2022 03:08:13 -0400 (EDT) Date: Wed, 10 Aug 2022 02:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660115292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=16kqUglr1ishQgrJKlQFjUeIG4svmPIXYRWssIj916w=; b=kmhhSxS7uIccs/nrYdSWL3WpY7iLLfb086IQ2OPHv80z6GP87fiwDAqu5MhMZPTcJEhJFn IKWWEQTe2cyuaZo3J7bEjF7I+lJDWX/zwfntne4Qxoox02rZ2x4/mnYnYTdq7PegQzGnGB ylFovYXelsIAn9sU0BqHBUbbCHl/j4M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Subject: Re: [PATCH 7/9] KVM: arm64: PMU: Allow ID_AA64DFR0_EL1.PMUver to be set from userspace Message-ID: References: <20220805135813.2102034-1-maz@kernel.org> <20220805135813.2102034-8-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220805135813.2102034-8-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Cc: kvm@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Marc, On Fri, Aug 05, 2022 at 02:58:11PM +0100, Marc Zyngier wrote: > Allow userspace to write ID_AA64DFR0_EL1, on the condition that only > the PMUver field can be altered and be at most the one that was > initially computed for the guest. As DFR0_EL1 is exposed to userspace, isn't a ->set_user() hook required for it as well? > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/sys_regs.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 55451f49017c..c0595f31dab8 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1236,6 +1236,38 @@ static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, > return 0; > } > > +static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *rd, > + u64 val) > +{ > + u8 pmuver, host_pmuver; > + > + host_pmuver = kvm_arm_pmu_get_host_pmuver(); > + > + /* > + * Allow AA64DFR0_EL1.PMUver to be set from userspace as long > + * as it doesn't promise more than what the HW gives us. We > + * don't allow an IMPDEF PMU though. > + */ > + pmuver = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER), val); > + if (pmuver == ID_AA64DFR0_PMUVER_IMP_DEF || pmuver > host_pmuver) > + return -EINVAL; > + > + /* We already have a PMU, don't try to disable it... */ > + if (kvm_vcpu_has_pmu(vcpu) && pmuver == 0) > + return -EINVAL; > + > + /* We can only differ with PMUver, and anything else is an error */ > + val ^= read_id_reg(vcpu, rd, false); > + val &= ~(0xFUL << ID_AA64DFR0_PMUVER_SHIFT); nit: ~ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER) -- Thanks, Oliver _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 12D2BC00140 for ; Wed, 10 Aug 2022 07:09:51 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UbiDd25uaAdA3jNE0dif+ZCrXFE4xuCg1hSZTOZAZcE=; b=lY+P5yrmqxrN0u lc6LT0toMItAMnH8PxEES1DOytpsGNf204rCGNA+6y5NJIkKR4pdsDZhAki3B52XYQZ+lFOlPy3sZ CJJPwHd519lK1d4quB7EpRSjXZsejFPNRkGk3WByZDfoR6040ZtC53n7sxAozdBIMAx0gVAAhr195 i7PbjQcfnd942D2FXeGPap9/b3A/QdhwO98+NUEN287OwEqvtz30osCCo59fwURij5vfQYyktzMnp ysZspIaV9rS3k9hgwl03evNPZVAFIjG2DHmS5C8ApDEwteudFJ6+CicgXZUbl5XvhT46R933kwifS GW7s8C3K4kG3xWQOkuyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oLfpI-00AFeQ-2C; Wed, 10 Aug 2022 07:08:24 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oLfpC-00AFb4-Rh for linux-arm-kernel@lists.infradead.org; Wed, 10 Aug 2022 07:08:20 +0000 Date: Wed, 10 Aug 2022 02:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660115292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=16kqUglr1ishQgrJKlQFjUeIG4svmPIXYRWssIj916w=; b=kmhhSxS7uIccs/nrYdSWL3WpY7iLLfb086IQ2OPHv80z6GP87fiwDAqu5MhMZPTcJEhJFn IKWWEQTe2cyuaZo3J7bEjF7I+lJDWX/zwfntne4Qxoox02rZ2x4/mnYnYTdq7PegQzGnGB ylFovYXelsIAn9sU0BqHBUbbCHl/j4M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Alexandru Elisei , Ricardo Koller , kernel-team@android.com Subject: Re: [PATCH 7/9] KVM: arm64: PMU: Allow ID_AA64DFR0_EL1.PMUver to be set from userspace Message-ID: References: <20220805135813.2102034-1-maz@kernel.org> <20220805135813.2102034-8-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220805135813.2102034-8-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220810_000819_091568_AA72899D X-CRM114-Status: GOOD ( 21.10 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Marc, On Fri, Aug 05, 2022 at 02:58:11PM +0100, Marc Zyngier wrote: > Allow userspace to write ID_AA64DFR0_EL1, on the condition that only > the PMUver field can be altered and be at most the one that was > initially computed for the guest. As DFR0_EL1 is exposed to userspace, isn't a ->set_user() hook required for it as well? > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/sys_regs.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 55451f49017c..c0595f31dab8 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1236,6 +1236,38 @@ static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, > return 0; > } > > +static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *rd, > + u64 val) > +{ > + u8 pmuver, host_pmuver; > + > + host_pmuver = kvm_arm_pmu_get_host_pmuver(); > + > + /* > + * Allow AA64DFR0_EL1.PMUver to be set from userspace as long > + * as it doesn't promise more than what the HW gives us. We > + * don't allow an IMPDEF PMU though. > + */ > + pmuver = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER), val); > + if (pmuver == ID_AA64DFR0_PMUVER_IMP_DEF || pmuver > host_pmuver) > + return -EINVAL; > + > + /* We already have a PMU, don't try to disable it... */ > + if (kvm_vcpu_has_pmu(vcpu) && pmuver == 0) > + return -EINVAL; > + > + /* We can only differ with PMUver, and anything else is an error */ > + val ^= read_id_reg(vcpu, rd, false); > + val &= ~(0xFUL << ID_AA64DFR0_PMUVER_SHIFT); nit: ~ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER) -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 8158AC25B08 for ; Wed, 10 Aug 2022 07:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231434AbiHJHIQ (ORCPT ); Wed, 10 Aug 2022 03:08:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbiHJHIP (ORCPT ); Wed, 10 Aug 2022 03:08:15 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C60F874CFA for ; Wed, 10 Aug 2022 00:08:13 -0700 (PDT) Date: Wed, 10 Aug 2022 02:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660115292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=16kqUglr1ishQgrJKlQFjUeIG4svmPIXYRWssIj916w=; b=kmhhSxS7uIccs/nrYdSWL3WpY7iLLfb086IQ2OPHv80z6GP87fiwDAqu5MhMZPTcJEhJFn IKWWEQTe2cyuaZo3J7bEjF7I+lJDWX/zwfntne4Qxoox02rZ2x4/mnYnYTdq7PegQzGnGB ylFovYXelsIAn9sU0BqHBUbbCHl/j4M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Alexandru Elisei , Ricardo Koller , kernel-team@android.com Subject: Re: [PATCH 7/9] KVM: arm64: PMU: Allow ID_AA64DFR0_EL1.PMUver to be set from userspace Message-ID: References: <20220805135813.2102034-1-maz@kernel.org> <20220805135813.2102034-8-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220805135813.2102034-8-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Marc, On Fri, Aug 05, 2022 at 02:58:11PM +0100, Marc Zyngier wrote: > Allow userspace to write ID_AA64DFR0_EL1, on the condition that only > the PMUver field can be altered and be at most the one that was > initially computed for the guest. As DFR0_EL1 is exposed to userspace, isn't a ->set_user() hook required for it as well? > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/sys_regs.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 55451f49017c..c0595f31dab8 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1236,6 +1236,38 @@ static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, > return 0; > } > > +static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *rd, > + u64 val) > +{ > + u8 pmuver, host_pmuver; > + > + host_pmuver = kvm_arm_pmu_get_host_pmuver(); > + > + /* > + * Allow AA64DFR0_EL1.PMUver to be set from userspace as long > + * as it doesn't promise more than what the HW gives us. We > + * don't allow an IMPDEF PMU though. > + */ > + pmuver = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER), val); > + if (pmuver == ID_AA64DFR0_PMUVER_IMP_DEF || pmuver > host_pmuver) > + return -EINVAL; > + > + /* We already have a PMU, don't try to disable it... */ > + if (kvm_vcpu_has_pmu(vcpu) && pmuver == 0) > + return -EINVAL; > + > + /* We can only differ with PMUver, and anything else is an error */ > + val ^= read_id_reg(vcpu, rd, false); > + val &= ~(0xFUL << ID_AA64DFR0_PMUVER_SHIFT); nit: ~ARM64_FEATURE_MASK(ID_AA64DFR0_PMUVER) -- Thanks, Oliver