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 6267FC433EF for ; Mon, 9 May 2022 10:32:27 +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=kSsbxmS+gpASKqBin1ua2EAh7mLdDGNDf3mkGI50Los=; b=qVDoMV6/9/rmp6 +Quo6QogZWhUpnkVHQD8GEjN2CVSMnZgggD8pjwByYyjHkozuKFh5sjTOsVZJMfH8dRGOTFGHCHNz qvF8ak/LGfzX91oPrVLQXOC1fPXhblqxsxA+eTwE+IGcQgngKG6m3tkrWBKVgqI3HdDtebeWtJ4md O5Kgrpe/clrPBwf8rh64DSGaHEFaSLW+XKOwbdGyZ4EOXrau8N0YbZJBLaKLU3alvlV346ml5KpjN BhQpFNi37ndwn+FOkEW6qmSUQCzjTrzCgA8/6nMvmiCTNvTbZHAJrj7/AnPNqgLahARNWLt8XcRye OlAZxlLqM7L4fZNwlnZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1no0fi-00DmPm-5s; Mon, 09 May 2022 10:31:22 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1no0fe-00DmOa-Tk for linux-arm-kernel@lists.infradead.org; Mon, 09 May 2022 10:31:20 +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 94A4960F7C; Mon, 9 May 2022 10:31:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F259AC385A8; Mon, 9 May 2022 10:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652092277; bh=nCB481jj88Qz5Y0reD7Efn/bS+/FLmjmh3enacfHSu0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Kpuw6y1wKMO2Vd05V2I6xAVrTjnKYJv6H8tS1Hc3SYD3XjlLSQc2Wp7qAdaMwvys5 UfDBa5qz3e118I//N8Zi/EGtvTdu5YxPHQNnxjvtHF3PoMVNQuu/8Dy3LB1seOGf+8 9NuiDF0U5cMdfV+YKPnoCT4bUP78Z6tyi14GBvr6SxAX2lQXSE7UDIDRqSNVvlCEkQ Sy/ZHpGqLywKb+JOeeLVmSHaNNHYPVLd0/jVii2JDfwneFvHGV0T0a6yO/6ZzcN9U9 TX+9qSExFgGMbVDcCL1iP/+oKHr4vTYf3+TZhV+LTlFedkCWXl2mcUxeM1/gXX0t+1 G1KL0GsV7TgAg== 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 1no0fa-009wDh-DF; Mon, 09 May 2022 11:31:14 +0100 Date: Mon, 09 May 2022 11:31:14 +0100 Message-ID: <87fslj6lql.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.cs.columbia.edu, will@kernel.org, qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, drjones@redhat.com, linux-arm-kernel@lists.infradead.org, kernel-team@android.com Subject: Re: [PATCH v2 3/4] KVM: arm64: Pass pmu events to hyp via vcpu In-Reply-To: <20220509095500.2408785-4-tabba@google.com> References: <20220509095500.2408785-1-tabba@google.com> <20220509095500.2408785-4-tabba@google.com> 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: tabba@google.com, kvmarm@lists.cs.columbia.edu, will@kernel.org, qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, drjones@redhat.com, linux-arm-kernel@lists.infradead.org, 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-20220509_033119_073226_F3B238CB X-CRM114-Status: GOOD ( 30.55 ) 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 Mon, 09 May 2022 10:54:59 +0100, Fuad Tabba wrote: > > Instead of the host accessing hyp data directly, pass the pmu > events of the current cpu to hyp via the vcpu. > > This adds 64 bits (in two fields) to the vcpu that need to be > synced before every vcpu run in nvhe and protected modes. > However, it isolates the hypervisor from the host, which allows > us to use pmu in protected mode in a subsequent patch. > > No functional change intended. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_host.h | 8 ++------ > arch/arm64/kvm/hyp/nvhe/switch.c | 20 ++++++-------------- > arch/arm64/kvm/pmu-emul.c | 3 +++ > arch/arm64/kvm/pmu.c | 12 ++++-------- > include/kvm/arm_pmu.h | 6 ++++++ > 5 files changed, 21 insertions(+), 28 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index dfd360404dd8..90476e713643 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -273,14 +273,8 @@ struct kvm_cpu_context { > struct kvm_vcpu *__hyp_running_vcpu; > }; > > -struct kvm_pmu_events { > - u32 events_host; > - u32 events_guest; > -}; > - > struct kvm_host_data { > struct kvm_cpu_context host_ctxt; > - struct kvm_pmu_events pmu_events; > }; > > struct kvm_host_psci_config { > @@ -763,6 +757,7 @@ void kvm_set_sei_esr(struct kvm_vcpu *vcpu, u64 syndrome); > struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr); > > DECLARE_KVM_HYP_PER_CPU(struct kvm_host_data, kvm_host_data); > +DECLARE_PER_CPU(struct kvm_pmu_events, kvm_pmu_events); > > static inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt) > { > @@ -821,6 +816,7 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu); > void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr); > void kvm_clr_pmu_events(u32 clr); > > +struct kvm_pmu_events *kvm_get_pmu_events(void); > void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu); > void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu); > #else > diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c > index 0716163313d6..c61120ec8d1a 100644 > --- a/arch/arm64/kvm/hyp/nvhe/switch.c > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c > @@ -153,13 +153,9 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu) > /* > * Disable host events, enable guest events > */ > -static bool __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) > +static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu) > { > - struct kvm_host_data *host; > - struct kvm_pmu_events *pmu; > - > - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); > - pmu = &host->pmu_events; > + struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events; > > if (pmu->events_host) > write_sysreg(pmu->events_host, pmcntenclr_el0); > @@ -173,13 +169,9 @@ static bool __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) > /* > * Disable guest events, enable host events > */ > -static void __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) > +static void __pmu_switch_to_host(struct kvm_vcpu *vcpu) > { > - struct kvm_host_data *host; > - struct kvm_pmu_events *pmu; > - > - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); > - pmu = &host->pmu_events; > + struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events; > > if (pmu->events_guest) > write_sysreg(pmu->events_guest, pmcntenclr_el0); > @@ -304,7 +296,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu) > host_ctxt->__hyp_running_vcpu = vcpu; > guest_ctxt = &vcpu->arch.ctxt; > > - pmu_switch_needed = __pmu_switch_to_guest(host_ctxt); > + pmu_switch_needed = __pmu_switch_to_guest(vcpu); > > __sysreg_save_state_nvhe(host_ctxt); > /* > @@ -366,7 +358,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu) > __debug_restore_host_buffers_nvhe(vcpu); > > if (pmu_switch_needed) > - __pmu_switch_to_host(host_ctxt); > + __pmu_switch_to_host(vcpu); > > /* Returning to host will clear PSR.I, remask PMR if needed */ > if (system_uses_irq_prio_masking()) > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index 3dc990ac4f44..08d0551a4e43 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -406,6 +406,9 @@ static void kvm_pmu_update_state(struct kvm_vcpu *vcpu) > if (!kvm_vcpu_has_pmu(vcpu)) > return; > > + if (!has_vhe()) > + pmu->events = *kvm_get_pmu_events(); A bit of context: preempt_disable(); /* * The VMID allocator only tracks active VMIDs per * physical CPU, and therefore the VMID allocated may not be * preserved on VMID roll-over if the task was preempted, * making a thread's VMID inactive. So we need to call * kvm_arm_vmid_update() in non-premptible context. */ kvm_arm_vmid_update(&vcpu->arch.hw_mmu->vmid); kvm_pmu_flush_hwstate(vcpu); local_irq_disable(); You *still* are in a context where an interrupt can fire and mess things up behind your back. Not good. Also, this is now synchronised *twice* per run (once on flush, once on sync). Do we really need this? Thanks, 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