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 X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D9A9C56202 for ; Thu, 26 Nov 2020 15:27:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A90A2087C for ; Thu, 26 Nov 2020 15:27:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="beT2/2Sc"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="VLV1daix" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A90A2087C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6pSJ1D9Zg8yFTG7mVenGgSpiEpI5QbJjLfUZbyN5yLo=; b=beT2/2Scwyd+oYwN1dtZxg+ZT XiLvKULyREpGRI+6Mmduj7eZXyz30oU5Sp3QSWwwPU6uEgGGjy2hzAmeit5MG/9srQhhWvEVcmo4h bBQgELN9msSEFyoMX5/PlHJbdr1OJHaYmL2upbc7b/AHpYRNMyLxaHVNHBvOwDfnjxiKDgyKvROdo hqm1MHQlBy0GELSiHaw54CidqG6iV0oaSxz8SWPXWE2S3f/L9SqN/z6Gg4WP3t34MgYGpBJa9xR5C wEPLxT0rkCQ+S5ulGjGTL39NvVS3w8zpeuIEOAr3W63MiUn1o9n3/EH67hC+3EwpgW2q65V7JCd6e LZ3YRR4Kw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiJ9H-0003mV-W8; Thu, 26 Nov 2020 15:25:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiJ9F-0003lw-2o for linux-arm-kernel@lists.infradead.org; Thu, 26 Nov 2020 15:25:30 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 44BE12087C; Thu, 26 Nov 2020 15:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606404326; bh=ex8zM01Qf4GRjPCLPiCrNyiXTx9goms244wEAdEL7NQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VLV1daix0z8iPONDOP+71WX/IOApqNx+Rx+fdXn3AF7cp9vVuvZmKZcWhlOFavXqy 9dWw3lUQnequckWPtHnUH9Nt+0KKSOYtcKaeAzXAK5EK5swiKpvwHIbfwHW//M17hh JgCY9Z/i9HxHfVpMe9oKfq1CGBbfvZb19LNy3QB0= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kiJ9A-00Dq9p-9S; Thu, 26 Nov 2020 15:25:24 +0000 MIME-Version: 1.0 Date: Thu, 26 Nov 2020 15:25:24 +0000 From: Marc Zyngier To: Alexandru Elisei Subject: Re: [PATCH 3/8] KVM: arm64: Refuse illegal KVM_ARM_VCPU_PMU_V3 at reset time In-Reply-To: <27c74186-d9d6-4021-c561-54ae4475bf88@arm.com> References: <20201113182602.471776-1-maz@kernel.org> <20201113182602.471776-4-maz@kernel.org> <27c74186-d9d6-4021-c561-54ae4475bf88@arm.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: <7abf75c1d1248a9c0e3fcb7737a101c0@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, eric.auger@redhat.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201126_102529_301900_5F0E6D78 X-CRM114-Status: GOOD ( 24.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Suzuki K Poulose , Eric Auger , James Morse , linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, Julien Thierry Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Alex, On 2020-11-26 14:59, Alexandru Elisei wrote: > Hi Marc, > > On 11/13/20 6:25 PM, Marc Zyngier wrote: >> We accept to configure a PMU when a vcpu is created, even if the >> HW (or the host) doesn't support it. This results in failures >> when attributes get set, which is a bit odd as we should have >> failed the vcpu creation the first place. >> >> Move the check to the point where we check the vcpu feature set, >> and fail early if we cannot support a PMU. This further simplifies >> the attribute handling. >> >> Signed-off-by: Marc Zyngier >> --- >> arch/arm64/kvm/pmu-emul.c | 4 ++-- >> arch/arm64/kvm/reset.c | 4 ++++ >> 2 files changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c >> index e7e3b4629864..200f2a0d8d17 100644 >> --- a/arch/arm64/kvm/pmu-emul.c >> +++ b/arch/arm64/kvm/pmu-emul.c >> @@ -913,7 +913,7 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int >> irq) >> >> int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct >> kvm_device_attr *attr) >> { >> - if (!kvm_arm_support_pmu_v3() || !kvm_vcpu_has_pmu(vcpu)) >> + if (!kvm_vcpu_has_pmu(vcpu)) >> return -ENODEV; >> >> if (vcpu->arch.pmu.created) >> @@ -1034,7 +1034,7 @@ int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu >> *vcpu, struct kvm_device_attr *attr) >> case KVM_ARM_VCPU_PMU_V3_IRQ: >> case KVM_ARM_VCPU_PMU_V3_INIT: >> case KVM_ARM_VCPU_PMU_V3_FILTER: >> - if (kvm_arm_support_pmu_v3() && kvm_vcpu_has_pmu(vcpu)) >> + if (kvm_vcpu_has_pmu(vcpu)) >> return 0; >> } >> >> diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c >> index 74ce92a4988c..3e772ea4e066 100644 >> --- a/arch/arm64/kvm/reset.c >> +++ b/arch/arm64/kvm/reset.c >> @@ -285,6 +285,10 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) >> pstate = VCPU_RESET_PSTATE_EL1; >> } >> >> + if (kvm_vcpu_has_pmu(vcpu) && !kvm_arm_support_pmu_v3()) { >> + ret = -EINVAL; >> + goto out; >> + } > > This looks correct, but right at the beginning of the function, before > this > non-preemptible section, we do kvm_pmu_vcpu_reset(), which is wrong for > several > reasons: > > - we don't check if the feature flag is set > - we don't check if the hardware supports a PMU > - kvm_pmu_vcpu_reset() relies on __vcpu_sys_reg(vcpu, PMCR_EL0), which > is set in > kvm_reset_sys_regs() below when the VCPU is initialized. I'm not sure it actually matters. Here's my rational: - PMU support not compiled in: no problem! - PMU support compiled in, but no HW PMU: we just reset some state to 0, no harm done - HW PMU, but no KVM PMU for this vcpu: same thing - HW PMU, and KVM PMU: we do the right thing! Am I missing anything? Thanks, M. -- Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel