From: David Laight <David.Laight@ACULAB.COM>
To: 'Paolo Bonzini' <pbonzini@redhat.com>,
'Jim Mattson' <jmattson@google.com>
Cc: 'LKML' <linux-kernel@vger.kernel.org>,
'kvm list' <kvm@vger.kernel.org>,
'Sean Christopherson' <sean.j.christopherson@intel.com>,
'Joerg Roedel' <joro@8bytes.org>,
"'everdox@gmail.com'" <everdox@gmail.com>
Subject: RE: [PATCH] KVM: x86: handle wrap around 32-bit address space
Date: Thu, 30 Apr 2020 13:18:10 +0000 [thread overview]
Message-ID: <47a766451de248718d2a9bec47dda86e@AcuMS.aculab.com> (raw)
In-Reply-To: <2f471fbc-99fb-1a85-8f9f-c276c897f518@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
> Sent: 30 April 2020 13:45
> On 29/04/20 10:56, David Laight wrote:
> >>>> + if (unlikely(((rip ^ orig_rip) >> 31) == 3) && !is_64_bit_mode(vcpu))
> >> Isn't the more obvious:
> >> if (((rip ^ orig_rip) & 1ull << 32) ...
> >> equivalent?
>
> This one would not (it would also detect carry on high memory addresses,
> not just 0x7fffffff to 0x80000000)...
So will the proposed one half the time.
If (orig_rip & 1 << 32) is zero the high bits are all unchanged
and cancel out.
> > Actually not even being clever, how about:
> > if (orig_rip < (1ull << 32) && unlikely(rip >= (1ull << 32)) && ...
>
> ... but yes this one would be equivalent.
If sub 4G addresses are likely on 64bit you may want to do:
if (unlikely((rip ^ orig_rip) & (1ull << 32)) && orig_rip < (1ull << 32)) && ...
or unlikely((rip ^ orig_rip) >> 32)
I think you always want unlikely(a) && b rather than unlikely(a && b).
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2020-04-30 13:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 16:59 Paolo Bonzini
2020-04-28 0:28 ` Jim Mattson
2020-04-28 0:33 ` Sean Christopherson
2020-04-29 8:50 ` David Laight
2020-04-29 8:56 ` David Laight
2020-04-30 12:45 ` Paolo Bonzini
2020-04-30 13:18 ` David Laight [this message]
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=47a766451de248718d2a9bec47dda86e@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=everdox@gmail.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.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
Powered by JetHome