From: Mathias Krause <minipli@grsecurity.net>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: x86: Open code all direct reads to guest DR6 and DR7
Date: Fri, 9 Feb 2024 23:30:26 +0100 [thread overview]
Message-ID: <19824d6d-28f9-4aa0-8b10-bacefc49adfd@grsecurity.net> (raw)
In-Reply-To: <20240209220752.388160-3-seanjc@google.com>
On 09.02.24 23:07, Sean Christopherson wrote:
> Bite the bullet, and open code all direct reads of DR6 and DR7. KVM
> currently has a mix of open coded accesses and calls to kvm_get_dr(),
> which is confusing and ugly because there's no rhyme or reason as to why
> any particular chunk of code uses kvm_get_dr().
>
> The obvious alternative is to force all accesses through kvm_get_dr(),
> but it's not at all clear that doing so would be a net positive, e.g. even
> if KVM ends up wanting/needing to force all reads through a common helper,
> e.g. to play caching games, the cost of reverting this change is likely
> lower than the ongoing cost of maintaining weird, arbitrary code.
>
> No functional change intended.
>
> Cc: Mathias Krause <minipli@grsecurity.net>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/smm.c | 8 ++++----
> arch/x86/kvm/vmx/nested.c | 2 +-
> arch/x86/kvm/x86.c | 2 +-
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c
> index 19a7a0a31953..d06d43d8d2aa 100644
> --- a/arch/x86/kvm/smm.c
> +++ b/arch/x86/kvm/smm.c
> @@ -194,8 +194,8 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
> for (i = 0; i < 8; i++)
> smram->gprs[i] = kvm_register_read_raw(vcpu, i);
>
> - smram->dr6 = (u32)kvm_get_dr(vcpu, 6);
> - smram->dr7 = (u32)kvm_get_dr(vcpu, 7);
> + smram->dr6 = (u32)vcpu->arch.dr6;
> + smram->dr7 = (u32)vcpu->arch.dr7;
>
> enter_smm_save_seg_32(vcpu, &smram->tr, &smram->tr_sel, VCPU_SREG_TR);
> enter_smm_save_seg_32(vcpu, &smram->ldtr, &smram->ldtr_sel, VCPU_SREG_LDTR);
> @@ -236,8 +236,8 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
> smram->rip = kvm_rip_read(vcpu);
> smram->rflags = kvm_get_rflags(vcpu);
>
> - smram->dr6 = kvm_get_dr(vcpu, 6);
> - smram->dr7 = kvm_get_dr(vcpu, 7);
> + smram->dr6 = vcpu->arch.dr6;
> + smram->dr7 = vcpu->arch.dr7;
>
> smram->cr0 = kvm_read_cr0(vcpu);
> smram->cr3 = kvm_read_cr3(vcpu);
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 28d1088a1770..d05ddf751491 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -4433,7 +4433,7 @@ static void sync_vmcs02_to_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
> (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE);
>
> if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_DEBUG_CONTROLS)
> - vmcs12->guest_dr7 = kvm_get_dr(vcpu, 7);
> + vmcs12->guest_dr7 = vcpu->arch.dr7;
>
> if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_EFER)
> vmcs12->guest_ia32_efer = vcpu->arch.efer;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index bfffc13f91e6..5a08d895bde6 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5510,7 +5510,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
> for (i = 0; i < ARRAY_SIZE(vcpu->arch.db); i++)
> dbgregs->db[i] = vcpu->arch.db[i];
>
> - dbgregs->dr6 = kvm_get_dr(vcpu, 6);
> + dbgregs->dr6 = vcpu->arch.dr6;
> dbgregs->dr7 = vcpu->arch.dr7;
> }
>
Reviewed-by: Mathias Krause <minipli@grsecurity.net>
Nice cleanup. Thanks a lot, Sean!
next prev parent reply other threads:[~2024-02-09 22:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 22:07 [PATCH 0/2] KVM: x86: Cleanup kvm_get_dr() usage Sean Christopherson
2024-02-09 22:07 ` [PATCH 1/2] KVM: x86: Make kvm_get_dr() return a value, not use an out parameter Sean Christopherson
2024-02-09 22:29 ` Mathias Krause
2024-02-09 22:07 ` [PATCH 2/2] KVM: x86: Open code all direct reads to guest DR6 and DR7 Sean Christopherson
2024-02-09 22:30 ` Mathias Krause [this message]
2024-02-23 1:35 ` [PATCH 0/2] KVM: x86: Cleanup kvm_get_dr() usage Sean Christopherson
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=19824d6d-28f9-4aa0-8b10-bacefc49adfd@grsecurity.net \
--to=minipli@grsecurity.net \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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
all inboxes | Powered by JetHome®