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 3C51CC433EF for ; Fri, 7 Jan 2022 14:38:05 +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:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vZTXbjqz4cP0Szo22KFzuo7OprOq9lNVW8V0rte8cvk=; b=yx0+z0LxhG7ouT DY338M1X/1NNWbDWOAF/QaFQlcHeEJxx0xLgVjsMeAzZEdd3k2DVopJ/mEemVj/Xz4IAOUjnGjFIe tGsD0Cdt7AnKOeQ5NCUUhVKGoZ4O8ZSCN4kSJH9Oa7M4P9VeMxF4PjqXEtzlw7HLqpU1/K2Thqbh7 yrzQAaOxgEzsb2cOhBQfapNRlda6GwuHj8t/2HVhY0bdgB5t6sqAbJrPWGN1l2VDq7ns+vSf35g6I gL5BpFvohPPxi/VVN8sOd9Qz5pb0czWwpQdCtbTWIo8PsnqeaTiVdeX84kEVB9PZ86uOAPwX7ogU3 WQp49YvUjayscj0i79gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5qMI-004EQi-PY; Fri, 07 Jan 2022 14:36:47 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5qKy-004Dba-M2 for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 14:35:26 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F06760C9B; Fri, 7 Jan 2022 14:35:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A69BAC36AE0; Fri, 7 Jan 2022 14:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641566123; bh=E5Ii6LbrkS/Ebzy5u+j9MvhVrkMFgncRBxfaTK9oY10=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eSmSjrFu48UAnu1Bjv7D1M46BDg+NnPGqE8t+L2lnaZDtXIk6wz2Kgs6IvpxFmz+b /UgQbIgRdXMWYJwZ3DI28g/UnDFcuXmFZwmw55DhSMlYqClq4W2p1YjgRVT+rnec++ fKt9GS3Jok62uoJJOkkDeISLRUGpjy0SXzdNDAAbI+Hna7ordcdimIbrHjD+sY6AD4 yk4O52sKKIW7+msFOSfXQmfXDgM3CGki5pR4r1bEjabDeCYiWI0Xb9P2nhwz7qfAZk njzwKlXFfshdg8Hcd9ZBlm5P6ZsTG3x6w5zC/xXWPSym8oeaj90rlFRZkFPFl9yujn IBkDELJuJlKWA== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n5qKu-00GaZC-Pe; Fri, 07 Jan 2022 14:35:21 +0000 Date: Fri, 07 Jan 2022 14:35:20 +0000 Message-ID: <87zgo7txzr.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: james.morse@arm.com, suzuki.poulose@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, tglx@linutronix.de, mingo@redhat.com, peter.maydell@linaro.org Subject: Re: [PATCH v3 3/4] KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_SET_PMU attribute In-Reply-To: References: <20211213152309.158462-1-alexandru.elisei@arm.com> <20211213152309.158462-4-alexandru.elisei@arm.com> <8735mvjrq8.wl-maz@kernel.org> <8735m0vifv.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, tglx@linutronix.de, mingo@redhat.com, peter.maydell@linaro.org 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-20220107_063524_846190_C2AD4661 X-CRM114-Status: GOOD ( 33.01 ) 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 On Fri, 07 Jan 2022 11:08:05 +0000, Alexandru Elisei wrote: > > Hi Marc, > > On Thu, Jan 06, 2022 at 06:16:04PM +0000, Marc Zyngier wrote: > > On Thu, 06 Jan 2022 11:54:11 +0000, > > Alexandru Elisei wrote: > > > > > > 2. What's to stop userspace to change the PMU after at least one VCPU has > > > run? That can be easily observed by the guest when reading PMCEIDx_EL0. > > > > That's a good point. We need something here. It is a bit odd as to do > > that, you need to fully enable a PMU on one CPU, but not on the other, > > then run the first while changing stuff on the other. Something along > > those lines (untested): > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index 4bf28905d438..4f53520e84fd 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -139,6 +139,7 @@ struct kvm_arch { > > > > /* Memory Tagging Extension enabled for the guest */ > > bool mte_enabled; > > + bool ran_once; > > }; > > > > struct kvm_vcpu_fault_info { > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > index 83297fa97243..3045d7f609df 100644 > > --- a/arch/arm64/kvm/arm.c > > +++ b/arch/arm64/kvm/arm.c > > @@ -606,6 +606,10 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) > > > > vcpu->arch.has_run_once = true; > > > > + mutex_lock(&kvm->lock); > > + kvm->arch.ran_once = true; > > + mutex_unlock(&kvm->lock); > > + > > kvm_arm_vcpu_init_debug(vcpu); > > > > if (likely(irqchip_in_kernel(kvm))) { > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > > index dfc0430d6418..95100c541244 100644 > > --- a/arch/arm64/kvm/pmu-emul.c > > +++ b/arch/arm64/kvm/pmu-emul.c > > @@ -959,8 +959,9 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) > > arm_pmu = entry->arm_pmu; > > if (arm_pmu->pmu.type == pmu_id) { > > /* Can't change PMU if filters are already in place */ > > - if (kvm->arch.arm_pmu != arm_pmu && > > - kvm->arch.pmu_filter) { > > + if ((kvm->arch.arm_pmu != arm_pmu && > > + kvm->arch.pmu_filter) || > > + kvm->arch.ran_once) { > > ret = -EBUSY; > > break; > > } > > @@ -1040,6 +1041,11 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) > > > > mutex_lock(&vcpu->kvm->lock); > > > > + if (vcpu->kvm->arch.ran_once) { > > + mutex_unlock(&vcpu->kvm->lock); > > + return -EBUSY; > > + } > > + > > if (!vcpu->kvm->arch.pmu_filter) { > > vcpu->kvm->arch.pmu_filter = bitmap_alloc(nr_events, GFP_KERNEL_ACCOUNT); > > if (!vcpu->kvm->arch.pmu_filter) { > > > > which should prevent both PMU or filters to be changed once a single > > vcpu as run. > > > > Thoughts? > > Haven't tested it either, but it looks good to me. If you agree, I can pick > the diff, turn it into a patch and send it for the next iteration of this > series as a fix for the PMU events filter, while keeping your authorship. Of course, please help yourself! :-) M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel