From: Sean Christopherson <seanjc@google.com>
To: Mathias Krause <minipli@grsecurity.net>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: x86: Simplify kvm_vcpu_ioctl_x86_get_debugregs()
Date: Tue, 6 Feb 2024 10:24:34 -0800 [thread overview]
Message-ID: <ZcJ5YqJhSOrt-GMk@google.com> (raw)
In-Reply-To: <86024ab8-0483-42a2-ab71-56c720b01b9e@grsecurity.net>
On Tue, Feb 06, 2024, Mathias Krause wrote:
> On 05.02.24 20:53, Sean Christopherson wrote:
> > On Sat, Feb 03, 2024, Mathias Krause wrote:
> >> Take 'dr6' from the arch part directly as already done for 'dr7'.
> >> There's no need to take the clunky route via kvm_get_dr().
> >>
> >> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> >> ---
> >> arch/x86/kvm/x86.c | 5 +----
> >> 1 file changed, 1 insertion(+), 4 deletions(-)
> >>
> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> >> index 13ec948f3241..0f958dcf8458 100644
> >> --- a/arch/x86/kvm/x86.c
> >> +++ b/arch/x86/kvm/x86.c
> >> @@ -5504,12 +5504,9 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
> >> static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
> >> struct kvm_debugregs *dbgregs)
> >> {
> >> - unsigned long val;
> >> -
> >> memset(dbgregs, 0, sizeof(*dbgregs));
> >> memcpy(dbgregs->db, vcpu->arch.db, sizeof(vcpu->arch.db));
> >> - kvm_get_dr(vcpu, 6, &val);
> >> - dbgregs->dr6 = val;
> >> + dbgregs->dr6 = vcpu->arch.dr6;
> >
> > Blech, kvm_get_dr() is so dumb, it takes an out parameter despite have a void
> > return.
>
> Jepp, that's why I tried to get rid of it.
>
> > I would rather fix that wart and go the other direction, i.e. make dr7
> > go through kvm_get_dr(). This obviously isn't a fast path, so the extra CALL+RET
> > is a non-issue.
>
> Okay. I thought, as this is an indirect call which is slightly more
> expensive under RETPOLINE, I'd go the other way and simply open-code the
> access, as done a few lines below in kvm_vcpu_ioctl_x86_set_debugregs().
It's not an indirect call. It's not even strictly guaranteed to be a function
call, e.g. within x86.c, kvm_get_dr() is in scope of kvm_vcpu_ioctl_x86_get_debugregs()
and so a very smart compiler could fully inline and optimize it to just
"xxx = vcpu->arch.dr6" through dead code elimination (I doubt gcc or clang actually
does this, but it's possible).
next prev parent reply other threads:[~2024-02-06 18:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-03 12:45 [PATCH 0/3] KVM: x86 - misc fixes Mathias Krause
2024-02-03 12:45 ` [PATCH 1/3] KVM: x86: Fix KVM_GET_MSRS stack info leak Mathias Krause
2024-02-04 1:28 ` Xiaoyao Li
2024-02-05 18:42 ` Sean Christopherson
2024-02-06 17:52 ` Mathias Krause
2024-02-03 12:45 ` [PATCH 2/3] KVM: x86: Simplify kvm_vcpu_ioctl_x86_get_debugregs() Mathias Krause
2024-02-04 1:05 ` Xiaoyao Li
2024-02-05 19:53 ` Sean Christopherson
2024-02-06 18:15 ` Mathias Krause
2024-02-06 18:24 ` Sean Christopherson [this message]
2024-02-06 18:30 ` Mathias Krause
2024-02-06 18:32 ` Mathias Krause
2024-02-03 12:45 ` [PATCH 3/3] KVM: x86: Fix broken debugregs ABI for 32 bit kernels Mathias Krause
2024-02-05 18:46 ` Sean Christopherson
2024-02-06 18:23 ` Mathias Krause
2024-02-05 19:56 ` [PATCH 0/3] KVM: x86 - misc fixes Sean Christopherson
2024-02-06 18:24 ` Mathias Krause
2024-02-06 18:52 ` 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=ZcJ5YqJhSOrt-GMk@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=minipli@grsecurity.net \
--cc=pbonzini@redhat.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