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=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 2CCACC07E95 for ; Tue, 20 Jul 2021 14:55:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EAA93600D4 for ; Tue, 20 Jul 2021 14:55:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAA93600D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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=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=zOYuR02i6cwZtJN3K6XwfcctnHDDe5cKShTN46y16Dk=; b=h1OMaJq63Rkpr0 NnVrr1wdeeQbigwz1ZrbGiWR8oFhzoTvn24in8fpe+q0P/6i11Xqvc9sTu4MJHEGj5ORmTokmXa2T YmzCwjqpAr4jTlVdXKLE/otv+/j8+84k+GfQPaMMW380Ek7XWou7Sy35nw350/kEKeByBYjXiDj+l ppk8Lfv7Ltb3BVqMf1buA0GN4dC28l7Dd8pV330Tpr5O5NX1pFsG1P8qwfxBc2E8XYUPAzhbwpEf6 EVkAb2bZsxjpGj1pRa0Q3xsiTRLi//ICvBwXPMM8JIwyuEEuFnfULFFzPq0kpSaS0xZvlUMSAhzsZ UPcjdJHyxHRsKe93tdhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5r7N-00DHSr-9k; Tue, 20 Jul 2021 14:53:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5r7I-00DHRE-Ll for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 14:53:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626792783; 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=AJ3a+l7HYygfc5k+wq8ZfjE4bAmzGHq+jXXRV2Bhjoc=; b=GKM5ssceMpY5ORPJal14VzP2TvLVWco+TCdm9SZ7UIFMiR5Nnc9fnCtci+lcXIzioI8rRO oHGuFZ73g7f58vVX9tPt8kL5qLkzzCOnocjtuG4qhd9lPUsTAYKgH9IGeOPrBkOQ4MeOH8 gscumfu12II+4L5G5o91qhqfcqrAYxQ= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-CRUGXGSjNTqTtwRqmS0CsA-1; Tue, 20 Jul 2021 10:53:01 -0400 X-MC-Unique: CRUGXGSjNTqTtwRqmS0CsA-1 Received: by mail-io1-f69.google.com with SMTP id d9-20020a0566023289b02904f58bb90366so15517775ioz.14 for ; Tue, 20 Jul 2021 07:53:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AJ3a+l7HYygfc5k+wq8ZfjE4bAmzGHq+jXXRV2Bhjoc=; b=ORSLCY8uPB9kRfwwpMITJqo4QU4cZgROTxfJanlj1hD+YEmazncJMWNDpLcTxFGOhz 2DfJ7FgTu/Z/qW3z2QbyGgXzhDKhvDKiAUbj/4syHKfDKXjTX3z6x4JPVy3YbqT1MbEo 80BMY3K8Umj5vOXYEiVwbFIUhA+VhTcCdR4uBH4odPifoXSHUCbSsb6heblI27T6Wqno xggAMlK/uMosFc1nFgHiibsnyLu+YIbZ6Ell4bpqVpXCIe9v6u3Ij4b/I7Da7GuNsJAD sxk8Vta7LdykGGUh3ZPtoA/DKrtIBwkmD4a8yWffmw/6+4nFmrLpun4fzpczVIoGCYsx AUjA== X-Gm-Message-State: AOAM532E8CH6m8RhOb88O+ZOYKJkGB/QSefZ/v3LhyX7I1/D0hnglW4N MYeJJVw5k+GkD+uZKbXCRxHMjtQIN1wI4xepEdCGw9IGAjHxIzrIChU3v4xxPts7/jbhj6XZtr7 N/nnB9xqUdKpq7CUWipy4p3sfoOfiWsCDcvg= X-Received: by 2002:a92:ab0a:: with SMTP id v10mr6070841ilh.17.1626792781053; Tue, 20 Jul 2021 07:53:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytAJej/L/uU7XclEttOrrPj1uCh7eLW+Gj07JbLiTweYRkQoA4op5Sy4dx4Bzh1ky2IX4HwQ== X-Received: by 2002:a92:ab0a:: with SMTP id v10mr6070822ilh.17.1626792780811; Tue, 20 Jul 2021 07:53:00 -0700 (PDT) Received: from gator ([140.82.166.162]) by smtp.gmail.com with ESMTPSA id g26sm10093279ioh.48.2021.07.20.07.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 07:53:00 -0700 (PDT) Date: Tue, 20 Jul 2021 16:52:58 +0200 From: Andrew Jones To: Fuad Tabba Cc: kvmarm@lists.cs.columbia.edu, maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, pbonzini@redhat.com, qperret@google.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com Subject: Re: [PATCH v3 06/15] KVM: arm64: Restore mdcr_el2 from vcpu Message-ID: <20210720145258.axhqog3abdvtpqhw@gator> References: <20210719160346.609914-1-tabba@google.com> <20210719160346.609914-7-tabba@google.com> MIME-Version: 1.0 In-Reply-To: <20210719160346.609914-7-tabba@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_075304_840036_07279595 X-CRM114-Status: GOOD ( 27.33 ) 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, Jul 19, 2021 at 05:03:37PM +0100, Fuad Tabba wrote: > On deactivating traps, restore the value of mdcr_el2 from the > newly created and preserved host value vcpu context, rather than > directly reading the hardware register. > > Up until and including this patch the two values are the same, > i.e., the hardware register and the vcpu one. A future patch will > be changing the value of mdcr_el2 on activating traps, and this > ensures that its value will be restored. > > No functional change intended. I'm probably missing something, but I can't convince myself that the host will end up with the same mdcr_el2 value after deactivating traps after this patch as before. We clearly now restore whatever we had when activating traps (presumably whatever we configured at init_el2_state time), but is that equivalent to what we had before with the masking and ORing that this patch drops? Thanks, drew > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_host.h | 5 ++++- > arch/arm64/include/asm/kvm_hyp.h | 2 +- > arch/arm64/kvm/hyp/include/hyp/switch.h | 6 +++++- > arch/arm64/kvm/hyp/nvhe/switch.c | 11 ++--------- > arch/arm64/kvm/hyp/vhe/switch.c | 12 ++---------- > arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 2 +- > 6 files changed, 15 insertions(+), 23 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 4d2d974c1522..76462c6a91ee 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -287,10 +287,13 @@ struct kvm_vcpu_arch { > /* Stage 2 paging state used by the hardware on next switch */ > struct kvm_s2_mmu *hw_mmu; > > - /* HYP configuration */ > + /* Values of trap registers for the guest. */ > u64 hcr_el2; > u64 mdcr_el2; > > + /* Values of trap registers for the host before guest entry. */ > + u64 mdcr_el2_host; > + > /* Exception Information */ > struct kvm_vcpu_fault_info fault; > > diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h > index 9d60b3006efc..657d0c94cf82 100644 > --- a/arch/arm64/include/asm/kvm_hyp.h > +++ b/arch/arm64/include/asm/kvm_hyp.h > @@ -95,7 +95,7 @@ void __sve_restore_state(void *sve_pffr, u32 *fpsr); > > #ifndef __KVM_NVHE_HYPERVISOR__ > void activate_traps_vhe_load(struct kvm_vcpu *vcpu); > -void deactivate_traps_vhe_put(void); > +void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu); > #endif > > u64 __guest_enter(struct kvm_vcpu *vcpu); > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index e4a2f295a394..a0e78a6027be 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -92,11 +92,15 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu) > write_sysreg(0, pmselr_el0); > write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0); > } > + > + vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2); > write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); > } > > -static inline void __deactivate_traps_common(void) > +static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu) > { > + write_sysreg(vcpu->arch.mdcr_el2_host, mdcr_el2); > + > write_sysreg(0, hstr_el2); > if (kvm_arm_support_pmu_v3()) > write_sysreg(0, pmuserenr_el0); > diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c > index f7af9688c1f7..1778593a08a9 100644 > --- a/arch/arm64/kvm/hyp/nvhe/switch.c > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c > @@ -69,12 +69,10 @@ static void __activate_traps(struct kvm_vcpu *vcpu) > static void __deactivate_traps(struct kvm_vcpu *vcpu) > { > extern char __kvm_hyp_host_vector[]; > - u64 mdcr_el2, cptr; > + u64 cptr; > > ___deactivate_traps(vcpu); > > - mdcr_el2 = read_sysreg(mdcr_el2); > - > if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) { > u64 val; > > @@ -92,13 +90,8 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) > isb(); > } > > - __deactivate_traps_common(); > - > - mdcr_el2 &= MDCR_EL2_HPMN_MASK; > - mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; > - mdcr_el2 |= MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT; > + __deactivate_traps_common(vcpu); > > - write_sysreg(mdcr_el2, mdcr_el2); > write_sysreg(this_cpu_ptr(&kvm_init_params)->hcr_el2, hcr_el2); > > cptr = CPTR_EL2_DEFAULT; > diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c > index b3229924d243..0d0c9550fb08 100644 > --- a/arch/arm64/kvm/hyp/vhe/switch.c > +++ b/arch/arm64/kvm/hyp/vhe/switch.c > @@ -91,17 +91,9 @@ void activate_traps_vhe_load(struct kvm_vcpu *vcpu) > __activate_traps_common(vcpu); > } > > -void deactivate_traps_vhe_put(void) > +void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu) > { > - u64 mdcr_el2 = read_sysreg(mdcr_el2); > - > - mdcr_el2 &= MDCR_EL2_HPMN_MASK | > - MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT | > - MDCR_EL2_TPMS; > - > - write_sysreg(mdcr_el2, mdcr_el2); > - > - __deactivate_traps_common(); > + __deactivate_traps_common(vcpu); > } > > /* Switch to the guest for VHE systems running in EL2 */ > diff --git a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > index 2a0b8c88d74f..007a12dd4351 100644 > --- a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > +++ b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > @@ -101,7 +101,7 @@ void kvm_vcpu_put_sysregs_vhe(struct kvm_vcpu *vcpu) > struct kvm_cpu_context *host_ctxt; > > host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt; > - deactivate_traps_vhe_put(); > + deactivate_traps_vhe_put(vcpu); > > __sysreg_save_el1_state(guest_ctxt); > __sysreg_save_user_state(guest_ctxt); > -- > 2.32.0.402.g57bb445576-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel