* [PATCH] mask out clflush
@ 2008-07-08 18:29 Glauber Costa
2008-07-08 19:34 ` Anthony Liguori
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Glauber Costa @ 2008-07-08 18:29 UTC (permalink / raw)
To: kvm; +Cc: glommer, avi
clflush is a non-privileged instruction that flushes the cacheline
given by its parameter, in terms of linear address. As it is non-privileged,
it is quite tricky, because a guest doing clflush will actually be trying to
flush a host kernel address.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
qemu/qemu-kvm-x86.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
index 5daedd1..7f90fc2 100644
--- a/qemu/qemu-kvm-x86.c
+++ b/qemu/qemu-kvm-x86.c
@@ -505,13 +505,17 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
e->ecx = bcd[1];
e->edx = bcd[2];
}
- // "Hypervisor present" bit for Microsoft guests
- if (function == 1)
- e->ecx |= (1u << 31);
+
+ if (function == 1) {
+ // "Hypervisor present" bit for Microsoft guests
+ e->ecx |= (1u << 31);
+ e->edx &= ~(1u << 19);
+ }
// 3dnow isn't properly emulated yet
if (function == 0x80000001)
- e->edx &= ~0xc0000000;
+ e->edx &= ~0xc0000000;
+
}
struct kvm_para_features {
--
1.5.5.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-08 18:29 [PATCH] mask out clflush Glauber Costa
@ 2008-07-08 19:34 ` Anthony Liguori
2008-07-08 20:01 ` Glauber Costa
2008-07-10 10:43 ` Yang, Sheng
2008-07-10 14:16 ` Avi Kivity
2 siblings, 1 reply; 16+ messages in thread
From: Anthony Liguori @ 2008-07-08 19:34 UTC (permalink / raw)
To: Glauber Costa; +Cc: kvm, glommer, avi
Glauber Costa wrote:
> clflush is a non-privileged instruction that flushes the cacheline
> given by its parameter, in terms of linear address. As it is non-privileged,
> it is quite tricky, because a guest doing clflush will actually be trying to
> flush a host kernel address.
>
Is this the case still with NPT/EPT?
Regards,
Anthony Liguori
> Signed-off-by: Glauber Costa <gcosta@redhat.com>
> ---
> qemu/qemu-kvm-x86.c | 12 ++++++++----
> 1 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
> index 5daedd1..7f90fc2 100644
> --- a/qemu/qemu-kvm-x86.c
> +++ b/qemu/qemu-kvm-x86.c
> @@ -505,13 +505,17 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
> e->ecx = bcd[1];
> e->edx = bcd[2];
> }
> - // "Hypervisor present" bit for Microsoft guests
> - if (function == 1)
> - e->ecx |= (1u << 31);
> +
> + if (function == 1) {
> + // "Hypervisor present" bit for Microsoft guests
> + e->ecx |= (1u << 31);
> + e->edx &= ~(1u << 19);
> + }
>
> // 3dnow isn't properly emulated yet
> if (function == 0x80000001)
> - e->edx &= ~0xc0000000;
> + e->edx &= ~0xc0000000;
> +
> }
>
> struct kvm_para_features {
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-08 19:34 ` Anthony Liguori
@ 2008-07-08 20:01 ` Glauber Costa
0 siblings, 0 replies; 16+ messages in thread
From: Glauber Costa @ 2008-07-08 20:01 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Glauber Costa, kvm, avi
On Tue, Jul 8, 2008 at 4:34 PM, Anthony Liguori <anthony@codemonkey.ws> wrote:
> Glauber Costa wrote:
>>
>> clflush is a non-privileged instruction that flushes the cacheline
>> given by its parameter, in terms of linear address. As it is
>> non-privileged,
>> it is quite tricky, because a guest doing clflush will actually be trying
>> to
>> flush a host kernel address.
>>
>
> Is this the case still with NPT/EPT?
Honestly don't know, and don't have the hardware to test. I don't know
exactly how NPT works. But probably isn't an issue. Do we have any
kind of mechanism to test for npt from userspace? A quick grep didn't
show me.
> Regards,
>
> Anthony Liguori
>
>> Signed-off-by: Glauber Costa <gcosta@redhat.com>
>> ---
>> qemu/qemu-kvm-x86.c | 12 ++++++++----
>> 1 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
>> index 5daedd1..7f90fc2 100644
>> --- a/qemu/qemu-kvm-x86.c
>> +++ b/qemu/qemu-kvm-x86.c
>> @@ -505,13 +505,17 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e,
>> uint32_t function,
>> e->ecx = bcd[1];
>> e->edx = bcd[2];
>> }
>> - // "Hypervisor present" bit for Microsoft guests
>> - if (function == 1)
>> - e->ecx |= (1u << 31);
>> +
>> + if (function == 1) {
>> + // "Hypervisor present" bit for Microsoft guests
>> + e->ecx |= (1u << 31);
>> + e->edx &= ~(1u << 19);
>> + }
>> // 3dnow isn't properly emulated yet
>> if (function == 0x80000001)
>> - e->edx &= ~0xc0000000;
>> + e->edx &= ~0xc0000000;
>> +
>> }
>> struct kvm_para_features {
>>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-08 18:29 [PATCH] mask out clflush Glauber Costa
2008-07-08 19:34 ` Anthony Liguori
@ 2008-07-10 10:43 ` Yang, Sheng
2008-07-10 13:30 ` Anthony Liguori
2008-07-10 14:16 ` Avi Kivity
2 siblings, 1 reply; 16+ messages in thread
From: Yang, Sheng @ 2008-07-10 10:43 UTC (permalink / raw)
To: kvm; +Cc: Glauber Costa, glommer, avi
On Wednesday 09 July 2008 02:29:44 Glauber Costa wrote:
> clflush is a non-privileged instruction that flushes the cacheline
> given by its parameter, in terms of linear address. As it is
> non-privileged, it is quite tricky, because a guest doing clflush
> will actually be trying to flush a host kernel address.
The linear address was convert to host physical address, then cache
line was flushed. Of course the host physical address was used by
guest at the time. I don't understand why we need to prevent guest
from flushing cache line related to itself...
--
Thanks
Yang, Sheng
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 10:43 ` Yang, Sheng
@ 2008-07-10 13:30 ` Anthony Liguori
2008-07-10 13:34 ` Avi Kivity
0 siblings, 1 reply; 16+ messages in thread
From: Anthony Liguori @ 2008-07-10 13:30 UTC (permalink / raw)
To: Yang, Sheng; +Cc: kvm, Glauber Costa, glommer, avi
Yang, Sheng wrote:
> On Wednesday 09 July 2008 02:29:44 Glauber Costa wrote:
>
>> clflush is a non-privileged instruction that flushes the cacheline
>> given by its parameter, in terms of linear address. As it is
>> non-privileged, it is quite tricky, because a guest doing clflush
>> will actually be trying to flush a host kernel address.
>>
>
> The linear address was convert to host physical address, then cache
> line was flushed. Of course the host physical address was used by
> guest at the time. I don't understand why we need to prevent guest
> from flushing cache line related to itself...
>
The problem turned out to be that we aren't emulating clflush in
x86_emulate.
Regards,
Anthony Liguori
> --
> Thanks
> Yang, Sheng
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 13:30 ` Anthony Liguori
@ 2008-07-10 13:34 ` Avi Kivity
2008-07-10 13:37 ` Anthony Liguori
0 siblings, 1 reply; 16+ messages in thread
From: Avi Kivity @ 2008-07-10 13:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Yang, Sheng, kvm, Glauber Costa, glommer
Anthony Liguori wrote:
> Yang, Sheng wrote:
>> On Wednesday 09 July 2008 02:29:44 Glauber Costa wrote:
>>
>>> clflush is a non-privileged instruction that flushes the cacheline
>>> given by its parameter, in terms of linear address. As it is
>>> non-privileged, it is quite tricky, because a guest doing clflush
>>> will actually be trying to flush a host kernel address.
>>>
>>
>> The linear address was convert to host physical address, then cache
>> line was flushed. Of course the host physical address was used by
>> guest at the time. I don't understand why we need to prevent guest
>> from flushing cache line related to itself...
>>
>
> The problem turned out to be that we aren't emulating clflush in
> x86_emulate.
>
Why would clflush trap? Is it called from real mode?
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 13:34 ` Avi Kivity
@ 2008-07-10 13:37 ` Anthony Liguori
2008-07-10 14:10 ` Avi Kivity
0 siblings, 1 reply; 16+ messages in thread
From: Anthony Liguori @ 2008-07-10 13:37 UTC (permalink / raw)
To: Avi Kivity; +Cc: Yang, Sheng, kvm, Glauber Costa, glommer
Avi Kivity wrote:
> Anthony Liguori wrote:
>> Yang, Sheng wrote:
>>> On Wednesday 09 July 2008 02:29:44 Glauber Costa wrote:
>>>
>>>> clflush is a non-privileged instruction that flushes the cacheline
>>>> given by its parameter, in terms of linear address. As it is
>>>> non-privileged, it is quite tricky, because a guest doing clflush
>>>> will actually be trying to flush a host kernel address.
>>>>
>>>
>>> The linear address was convert to host physical address, then cache
>>> line was flushed. Of course the host physical address was used by
>>> guest at the time. I don't understand why we need to prevent guest
>>> from flushing cache line related to itself...
>>>
>>
>> The problem turned out to be that we aren't emulating clflush in
>> x86_emulate.
>>
>
> Why would clflush trap? Is it called from real mode?
It's equivalent to a read from a VT perspective so if the read would
trap, the clflush instruction will trap.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 13:37 ` Anthony Liguori
@ 2008-07-10 14:10 ` Avi Kivity
2008-07-10 14:20 ` Anthony Liguori
0 siblings, 1 reply; 16+ messages in thread
From: Avi Kivity @ 2008-07-10 14:10 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Yang, Sheng, kvm, Glauber Costa, glommer
Anthony Liguori wrote:
>
> It's equivalent to a read from a VT perspective so if the read would
> trap, the clflush instruction will trap.
>
Reads don't normally go through the emulator. Is the guest clflush()ing
mmio addresses? Strange as these are not normally cached.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-08 18:29 [PATCH] mask out clflush Glauber Costa
2008-07-08 19:34 ` Anthony Liguori
2008-07-10 10:43 ` Yang, Sheng
@ 2008-07-10 14:16 ` Avi Kivity
2 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2008-07-10 14:16 UTC (permalink / raw)
To: Glauber Costa; +Cc: kvm, glommer
Glauber Costa wrote:
> clflush is a non-privileged instruction that flushes the cacheline
> given by its parameter, in terms of linear address. As it is non-privileged,
> it is quite tricky, because a guest doing clflush will actually be trying to
> flush a host kernel address.
>
We need to allow clflush for pci device assignment.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 14:10 ` Avi Kivity
@ 2008-07-10 14:20 ` Anthony Liguori
2008-07-10 14:45 ` Glauber Costa
0 siblings, 1 reply; 16+ messages in thread
From: Anthony Liguori @ 2008-07-10 14:20 UTC (permalink / raw)
To: Avi Kivity; +Cc: Yang, Sheng, kvm, Glauber Costa, glommer
Avi Kivity wrote:
> Anthony Liguori wrote:
>>
>> It's equivalent to a read from a VT perspective so if the read would
>> trap, the clflush instruction will trap.
>>
>
> Reads don't normally go through the emulator. Is the guest
> clflush()ing mmio addresses? Strange as these are not normally cached.
It seems so, Glauber mentioned that the address was an MMIO address.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 14:20 ` Anthony Liguori
@ 2008-07-10 14:45 ` Glauber Costa
2008-07-10 14:47 ` Avi Kivity
0 siblings, 1 reply; 16+ messages in thread
From: Glauber Costa @ 2008-07-10 14:45 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Avi Kivity, Yang, Sheng, kvm, Glauber Costa
On Thu, Jul 10, 2008 at 11:20 AM, Anthony Liguori <anthony@codemonkey.ws> wrote:
> Avi Kivity wrote:
>>
>> Anthony Liguori wrote:
>>>
>>> It's equivalent to a read from a VT perspective so if the read would
>>> trap, the clflush instruction will trap.
>>>
>>
>> Reads don't normally go through the emulator. Is the guest clflush()ing
>> mmio addresses? Strange as these are not normally cached.
>
> It seems so, Glauber mentioned that the address was an MMIO address.
yes. It is address 0xc8821000, apparently part of a pci controller
initialization.
> Regards,
>
> Anthony Liguori
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 14:45 ` Glauber Costa
@ 2008-07-10 14:47 ` Avi Kivity
2008-07-10 15:37 ` Anthony Liguori
0 siblings, 1 reply; 16+ messages in thread
From: Avi Kivity @ 2008-07-10 14:47 UTC (permalink / raw)
To: Glauber Costa; +Cc: Anthony Liguori, Yang, Sheng, kvm, Glauber Costa
Glauber Costa wrote:
> On Thu, Jul 10, 2008 at 11:20 AM, Anthony Liguori <anthony@codemonkey.ws> wrote:
>
>> Avi Kivity wrote:
>>
>>> Anthony Liguori wrote:
>>>
>>>> It's equivalent to a read from a VT perspective so if the read would
>>>> trap, the clflush instruction will trap.
>>>>
>>>>
>>> Reads don't normally go through the emulator. Is the guest clflush()ing
>>> mmio addresses? Strange as these are not normally cached.
>>>
>> It seems so, Glauber mentioned that the address was an MMIO address.
>>
>
> yes. It is address 0xc8821000, apparently part of a pci controller
> initialization.
>
qemu pci starts at 0xe0000000 IIRC. So maybe the guest is flushing
random addresses just to be annoying.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 14:47 ` Avi Kivity
@ 2008-07-10 15:37 ` Anthony Liguori
2008-07-10 15:39 ` Avi Kivity
0 siblings, 1 reply; 16+ messages in thread
From: Anthony Liguori @ 2008-07-10 15:37 UTC (permalink / raw)
To: Avi Kivity; +Cc: Glauber Costa, Yang, Sheng, kvm, Glauber Costa
Avi Kivity wrote:
> Glauber Costa wrote:
>> On Thu, Jul 10, 2008 at 11:20 AM, Anthony Liguori
>> <anthony@codemonkey.ws> wrote:
>>
>>> Avi Kivity wrote:
>>>
>>>> Anthony Liguori wrote:
>>>>
>>>>> It's equivalent to a read from a VT perspective so if the read would
>>>>> trap, the clflush instruction will trap.
>>>>>
>>>>>
>>>> Reads don't normally go through the emulator. Is the guest
>>>> clflush()ing
>>>> mmio addresses? Strange as these are not normally cached.
>>>>
>>> It seems so, Glauber mentioned that the address was an MMIO address.
>>>
>>
>> yes. It is address 0xc8821000, apparently part of a pci controller
>> initialization.
>>
>
> qemu pci starts at 0xe0000000 IIRC. So maybe the guest is flushing
> random addresses just to be annoying.
That's a virtual address, not a physical address IIUC.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 15:37 ` Anthony Liguori
@ 2008-07-10 15:39 ` Avi Kivity
2008-07-10 20:18 ` Glauber Costa
0 siblings, 1 reply; 16+ messages in thread
From: Avi Kivity @ 2008-07-10 15:39 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Glauber Costa, Yang, Sheng, kvm, Glauber Costa
Anthony Liguori wrote:
>>>
>>> yes. It is address 0xc8821000, apparently part of a pci controller
>>> initialization.
>>>
>>
>> qemu pci starts at 0xe0000000 IIRC. So maybe the guest is flushing
>> random addresses just to be annoying.
>
> That's a virtual address, not a physical address IIUC.
>
Ah, of course.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 15:39 ` Avi Kivity
@ 2008-07-10 20:18 ` Glauber Costa
2008-07-13 7:58 ` Avi Kivity
0 siblings, 1 reply; 16+ messages in thread
From: Glauber Costa @ 2008-07-10 20:18 UTC (permalink / raw)
To: Avi Kivity; +Cc: Anthony Liguori, Yang, Sheng, kvm, Glauber Costa
[-- Attachment #1: Type: text/plain, Size: 618 bytes --]
On Thu, Jul 10, 2008 at 12:39 PM, Avi Kivity <avi@qumranet.com> wrote:
> Anthony Liguori wrote:
>>>>
>>>> yes. It is address 0xc8821000, apparently part of a pci controller
>>>> initialization.
>>>>
>>>
>>> qemu pci starts at 0xe0000000 IIRC. So maybe the guest is flushing
>>> random addresses just to be annoying.
>>
>> That's a virtual address, not a physical address IIUC.
>>
>
> Ah, of course.
How's that one ?
>
> --
> error compiling committee.c: too many arguments to function
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
[-- Attachment #2: 0001-properly-decode-clflush.patch --]
[-- Type: application/octet-stream, Size: 1155 bytes --]
From 7f60c9c828c7907625f634baf740376bdee7726b Mon Sep 17 00:00:00 2001
From: Glauber Costa <gcosta@redhat.com>
Date: Thu, 10 Jul 2008 17:08:15 -0300
Subject: [PATCH] properly decode clflush
If the guest issues a clflush in a mmio address, the instruction
can trap into the hypervisor. Currently, we do not decode clflush
properly, causing the guest to hang. This patch fixes this by
adding the "ModRM" flag into position 0xAE of twobyte_table.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
arch/x86/kvm/x86_emulate.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index 932f216..ee4cebf 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -215,7 +215,7 @@ static u16 twobyte_table[256] = {
/* 0xA0 - 0xA7 */
0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
/* 0xA8 - 0xAF */
- 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
+ 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, ModRM, 0,
/* 0xB0 - 0xB7 */
ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0,
DstMem | SrcReg | ModRM | BitOp,
--
1.5.5.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] mask out clflush
2008-07-10 20:18 ` Glauber Costa
@ 2008-07-13 7:58 ` Avi Kivity
0 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2008-07-13 7:58 UTC (permalink / raw)
To: Glauber Costa; +Cc: Anthony Liguori, Yang, Sheng, kvm, Glauber Costa
Glauber Costa wrote:
> On Thu, Jul 10, 2008 at 12:39 PM, Avi Kivity <avi@qumranet.com> wrote:
>
>> Anthony Liguori wrote:
>>
>>>>> yes. It is address 0xc8821000, apparently part of a pci controller
>>>>> initialization.
>>>>>
>>>>>
>>>> qemu pci starts at 0xe0000000 IIRC. So maybe the guest is flushing
>>>> random addresses just to be annoying.
>>>>
>>> That's a virtual address, not a physical address IIUC.
>>>
>>>
>> Ah, of course.
>>
>
> How's that one ?
>
It abuses the lack of a 'default:' statement in the switch. I fixed
that up and applied.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2008-07-13 7:58 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-08 18:29 [PATCH] mask out clflush Glauber Costa
2008-07-08 19:34 ` Anthony Liguori
2008-07-08 20:01 ` Glauber Costa
2008-07-10 10:43 ` Yang, Sheng
2008-07-10 13:30 ` Anthony Liguori
2008-07-10 13:34 ` Avi Kivity
2008-07-10 13:37 ` Anthony Liguori
2008-07-10 14:10 ` Avi Kivity
2008-07-10 14:20 ` Anthony Liguori
2008-07-10 14:45 ` Glauber Costa
2008-07-10 14:47 ` Avi Kivity
2008-07-10 15:37 ` Anthony Liguori
2008-07-10 15:39 ` Avi Kivity
2008-07-10 20:18 ` Glauber Costa
2008-07-13 7:58 ` Avi Kivity
2008-07-10 14:16 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox