From: Avi Kivity <avi@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/5] KVM: Make locked operations truly atomic
Date: Wed, 17 Mar 2010 10:05:13 +0200 [thread overview]
Message-ID: <4BA08D39.5030005@redhat.com> (raw)
In-Reply-To: <4BA088A5.6000201@web.de>
On 03/17/2010 09:45 AM, Jan Kiszka wrote:
> Avi Kivity wrote:
>
>> Once upon a time, locked operations were emulated while holding the mmu mutex.
>> Since mmu pages were write protected, it was safe to emulate the writes in
>> a non-atomic manner, since there could be no other writer, either in the
>> guest or in the kernel.
>>
>> These days emulation takes place without holding the mmu spinlock, so the
>> write could be preempted by an unshadowing event, which exposes the page
>> to writes by the guest. This may cause corruption of guest page tables.
>>
>> Fix by using an atomic cmpxchg for these operations.
>>
>> Signed-off-by: Avi Kivity<avi@redhat.com>
>> ---
>> arch/x86/kvm/x86.c | 69 ++++++++++++++++++++++++++++++++++++----------------
>> 1 files changed, 48 insertions(+), 21 deletions(-)
>>
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 9d02cc7..d724a52 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -3299,41 +3299,68 @@ int emulator_write_emulated(unsigned long addr,
>> }
>> EXPORT_SYMBOL_GPL(emulator_write_emulated);
>>
>> +#define CMPXCHG_TYPE(t, ptr, old, new) \
>> + (cmpxchg((t *)(ptr), *(t *)(old), *(t *)(new)) == *(t *)(old))
>> +
>> +#ifdef CONFIG_X86_64
>> +# define CMPXCHG64(ptr, old, new) CMPXCHG_TYPE(u64, ptr, old, new)
>> +#else
>> +# define CMPXCHG64(ptr, old, new) \
>> + (cmpxchg64((u64 *)(ptr), *(u64 *)(old), *(u *)(new)) == *(u64 *)(old))
>>
> ^^^^^^
> This should cause the 32-bit build breakage I see with the current next
> branch.
>
Also, Marcelo sees autotest breakage, so it's also broken on 64-bit somehow.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
next prev parent reply other threads:[~2010-03-17 8:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-15 11:59 [PATCH 0/5] Fix some mmu/emulator atomicity issues (v2) Avi Kivity
2010-03-15 11:59 ` [PATCH 1/5] KVM: MMU: Consolidate two guest pte reads in kvm_mmu_pte_write() Avi Kivity
2010-03-15 11:59 ` [PATCH 2/5] KVM: Make locked operations truly atomic Avi Kivity
2010-03-17 7:45 ` Jan Kiszka
2010-03-17 8:05 ` Avi Kivity [this message]
2010-03-20 9:14 ` [PATCH] KVM: x86: Fix 32-bit build breakage due to typo Jan Kiszka
2010-03-21 14:34 ` Avi Kivity
2010-03-15 11:59 ` [PATCH 3/5] KVM: Don't follow an atomic operation by a non-atomic one Avi Kivity
2010-03-15 11:59 ` [PATCH 4/5] KVM: MMU: Do not instantiate nontrapping spte on unsync page Avi Kivity
2010-03-15 11:59 ` [PATCH 5/5] KVM: MMU: Reinstate pte prefetch on invlpg Avi Kivity
2010-03-16 16:36 ` [PATCH 0/5] Fix some mmu/emulator atomicity issues (v2) Marcelo Tosatti
2010-03-16 18:22 ` Alexander Graf
2010-03-16 19:33 ` Marcelo Tosatti
2010-03-17 3:58 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2010-03-10 14:50 Avi Kivity
2010-03-10 14:50 ` [PATCH 2/5] KVM: Make locked operations truly atomic Avi Kivity
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=4BA08D39.5030005@redhat.com \
--to=avi@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@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