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 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 52FDDC433FE for ; Thu, 10 Dec 2020 11:18:08 +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 E58ED23B85 for ; Thu, 10 Dec 2020 11:18:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E58ED23B85 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=XdnVtMdPqRfkdLvrChskr+KHDG171b/j5d0O904v1HU=; b=wRMnIdZXU6JhQ/rpRPrF7Z3wM pli1e4v/CSbOeqDj+AIFhtpn6/9pncEoJCsWSwW+9TMnBDoUO5xEGUxsFieXbGjMEFFm+etD7mvdk xVGsDixyx2IQ0kB5+Pq/HO3WRUh7RDeVjPd0u2ADOK1PPGegGuMvTQP6LlD7AZqzWHJh7NOcU2VGX e2GCn5Ug04c7YnyC/3Un8aWP+GYGUifjZlQbrFu9kOcey/kPyN7A9IfXFAxFIkugo2U3wDV/ogGrU KLGuAvJq2q9/hZQXtfTnZLjrvGXREPmI8z0DLKViki5OcSmKm2A28Ie5R98DiOvOWf/M0u8hI3/SL 9tO6bsJYg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knJwF-0000sP-Na; Thu, 10 Dec 2020 11:16:47 +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 1knJwE-0000rv-8G for linux-arm-kernel@lists.infradead.org; Thu, 10 Dec 2020 11:16:47 +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 1823C23B85; Thu, 10 Dec 2020 11:16:45 +0000 (UTC) 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 1knJwA-0003gm-VZ; Thu, 10 Dec 2020 11:16:43 +0000 MIME-Version: 1.0 Date: Thu, 10 Dec 2020 11:16:42 +0000 From: Marc Zyngier To: Alexandru Elisei Subject: Re: [PATCH] KVM: arm64: Don't access PMCR_EL0 when no PMU is available In-Reply-To: <41fab19e-1e6d-f39b-c0a8-d4a1e54fc9b9@arm.com> References: <20201210083059.1277162-1-maz@kernel.org> <41fab19e-1e6d-f39b-c0a8-d4a1e54fc9b9@arm.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: 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, kernel-team@android.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.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-20201210_061646_497015_DF515D67 X-CRM114-Status: GOOD ( 22.49 ) 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: Suzuki K Poulose , 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, Thanks for looking at this. On 2020-12-10 10:12, Alexandru Elisei wrote: > Hi Marc, > > On 12/10/20 8:30 AM, Marc Zyngier wrote: >> We reset the guest's view of PMCR_EL0 unconditionally, based on >> the host's view of this register. It is however legal for an >> imnplementation not to provide any PMU, resulting in an UNDEF. >> >> The obvious fix is to skip the reset of this shadow register >> when no PMU is available, sidestepping the issue entirely. >> If no PMU is available, the guest is not able to request >> a virtual PMU anyway, so not doing nothing is the right thing >> to do! >> >> It is unlikely that this bug can hit any HW implementation >> though, as they all provide a PMU. It has been found using nested >> virt with the host KVM not implementing the PMU itself. >> >> Fixes: ab9468340d2bc ("arm64: KVM: Add access handler for PMCR >> register") >> Signed-off-by: Marc Zyngier >> --- >> arch/arm64/kvm/sys_regs.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index bc15246775d0..6c64d010102b 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -923,6 +923,10 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, >> const struct sys_reg_desc *r) >> { >> u64 pmcr, val; >> >> + /* No PMU available, PMCR_EL0 may UNDEF... */ >> + if (!kvm_arm_support_pmu_v3()) >> + return; >> + > > reset_pmcr() is called from kvm_reset_vcpu()->kvm_reset_sys_regs(). > Before calling kvm_reset_sys_regs(), kvm_reset_vcpu() returns -EINVAL > if the VCPU has the PMUv3 feature but the host doesn't have a PMU. > > It looks to me like the undef can happen only when the VCPU feature > isn't set and the hardware doesn't have a PMU. Which is exactly what I describe in the commit message (NV without PMU). > How about we change > the test to check for kvm_vcpu_has_pmu() to avoid executing the extra > instructions, which are not needed because the VM won't have a PMU? I went down that road initially, and then realised that we need to backport this as far back as 4.9 (the code was merged in 4.6). I don't fancy backporting kvm_vcpu_has_pmu() and co... 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