From: Oliver Upton <oliver.upton@linux.dev>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: maz@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com,
yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org,
kvmarm@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org
Subject: Re: [PATCH v2 2/2] KVM: arm64: VHE: Save and restore host MDCR_EL2 value correctly
Date: Wed, 3 Sep 2025 23:55:46 -0700 [thread overview]
Message-ID: <aLk38kyxyoe0CYq-@linux.dev> (raw)
In-Reply-To: <20250902130833.338216-3-alexandru.elisei@arm.com>
On Tue, Sep 02, 2025 at 02:08:33PM +0100, Alexandru Elisei wrote:
> Prior to commit 75a5fbaf6623 ("KVM: arm64: Compute MDCR_EL2 at
> vcpu_load()"), host MDCR_EL2 was saved correctly:
>
> kvm_arch_vcpu_load()
> kvm_vcpu_load_debug() /* Doesn't touch hardware MDCR_EL2. */
> kvm_vcpu_load_vhe()
> __activate_traps_common()
> /* Saves host MDCR_EL2. */
> *host_data_ptr(host_debug_state.mdcr_el2) = read_sysreg(mdcr_el2)
> /* Writes VCPU MDCR_EL2. */
> write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2)
>
> The MDCR_EL2 value saved previously was restored in
> kvm_arch_vcpu_put() -> kvm_vcpu_put_vhe().
>
> After the aforementioned commit, host MDCR_EL2 is never saved:
>
> kvm_arch_vcpu_load()
> kvm_vcpu_load_debug() /* Writes VCPU MDCR_EL2 */
> kvm_vcpu_load_vhe()
> __activate_traps_common()
> /* Saves **VCPU** MDCR_EL2. */
> *host_data_ptr(host_debug_state.mdcr_el2) = read_sysreg(mdcr_el2)
> /* Writes VCPU MDCR_EL2 a second time. */
> write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2)
>
> kvm_arch_vcpu_put() -> kvm_vcpu_put_vhe() then restores the VCPU MDCR_EL2
> value. Also VCPU's MDCR_EL2 value gets written to hardware twice now.
>
> Fix this by saving the host MDCR_EL2 in kvm_arch_vcpu_load() before it gets
> overwritten by the VCPU's MDCR_EL2 value, and restore it on VCPU put.
>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Thanks,
Oliver
next prev parent reply other threads:[~2025-09-04 8:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 13:08 [PATCH v2 0/2] KVM: arm64: VHE: Debug fixes Alexandru Elisei
2025-09-02 13:08 ` [PATCH v2 1/2] KVM: arm64: VHE: Initialize PMSCR_EL1 Alexandru Elisei
2025-09-04 6:55 ` Oliver Upton
2025-09-04 9:30 ` Alexandru Elisei
2025-09-02 13:08 ` [PATCH v2 2/2] KVM: arm64: VHE: Save and restore host MDCR_EL2 value correctly Alexandru Elisei
2025-09-04 6:55 ` Oliver Upton [this message]
2025-09-05 9:41 ` [PATCH v2 0/2] KVM: arm64: VHE: Debug fixes Oliver Upton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aLk38kyxyoe0CYq-@linux.dev \
--to=oliver.upton@linux.dev \
--cc=alexandru.elisei@arm.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox