From: Nadav Amit <nadav.amit@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Nadav Amit <namit@cs.technion.ac.il>,
mtosatti@redhat.com, hpa@zytor.com
Cc: gleb@kernel.org, tglx@linutronix.de, mingo@redhat.com,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] KVM: x86: Wrong register masking in 64-bit mode
Date: Thu, 08 May 2014 15:27:50 +0300 [thread overview]
Message-ID: <536B7846.7080102@gmail.com> (raw)
In-Reply-To: <536A56C3.7050907@redhat.com>
On 5/7/14, 6:52 PM, Paolo Bonzini wrote:
> Il 07/05/2014 14:32, Nadav Amit ha scritto:
>> 32-bit operations are zero extended in 64-bit mode. Currently, the
>> code does
>> not handle them correctly and keeps the high bits. In 16-bit mode, the
>> high
>> 32-bits are kept intact.
>>
>> In addition, although it is not well-documented, when address override
>> prefix
>> is used with REP-string instruction, RCX high half is zeroed even if
>> ECX was
>> zero on the first iteration (as if an assignment was performed to ECX).
>
> Is this true even for REPZ and ZF=0 or REPNZ and ZF=1?
>
> Paolo
The REPZ and REPNZ condition is checked on the end of an iteration (see
the REP instruction description on the SDM), so it does not matter. So
even REPZ/RENZ would zero RCX high half.
This "feature" is not well-documented, but can be observed. Here is a
small code you can try.
---
#include <stdio.h>
unsigned long src, dst;
int main()
{
unsigned long long rsi, rdi, rcx;
rcx = 0xffffffff00000000ull;
rsi = (unsigned long long)&src | 0xffffffff00000000ull;
rdi = (unsigned long long)&dst | 0xffffffff00000000ull;
printf("before: rsi %llx rdi %llx rcx %llx\n", rsi, rdi ,rcx);
asm volatile ( ".byte 0x67\n\t"
"repne cmpsd\n\t"
: "+S" (rsi), "+D" (rdi), "+c" (rcx)
: : "memory", "cc" );
printf("after: rsi %llx rdi %llx rcx %llx\n", rsi, rdi ,rcx);
return 0;
}
---
Nadav
next prev parent reply other threads:[~2014-05-08 12:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 12:32 [PATCH 0/5] KVM: x86: Fix exit handler and emulation bugs Nadav Amit
2014-05-07 12:32 ` [PATCH 1/5] KVM: x86: Emulator does not calculate address correctly Nadav Amit
2014-05-07 13:57 ` Paolo Bonzini
2014-05-07 15:21 ` Nadav Amit
2014-05-07 12:32 ` [PATCH 2/5] KVM: vmx: handle_dr does not handle RSP correctly Nadav Amit
2014-05-07 12:32 ` [PATCH 3/5] KVM: x86: Mark bit 7 in long-mode PDPTE according to 1GB pages support Nadav Amit
2014-05-07 12:32 ` [PATCH 4/5] KVM: x86: Wrong register masking in 64-bit mode Nadav Amit
2014-05-07 14:50 ` Bandan Das
2014-05-07 15:24 ` Paolo Bonzini
2014-05-07 16:11 ` Nadav Amit
2014-05-07 15:52 ` Paolo Bonzini
2014-05-08 12:27 ` Nadav Amit [this message]
2014-05-07 12:32 ` [PATCH 5/5] KVM: x86: Fix wrong masking on relative jump/call Nadav Amit
2014-05-07 14:43 ` Bandan Das
2014-05-07 15:57 ` Nadav Amit
2014-05-07 15:59 ` Paolo Bonzini
2014-05-07 16:00 ` [PATCH 0/5] KVM: x86: Fix exit handler and emulation bugs Paolo Bonzini
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=536B7846.7080102@gmail.com \
--to=nadav.amit@gmail.com \
--cc=gleb@kernel.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=namit@cs.technion.ac.il \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).