* [kvm-unit-tests PATCH] x86: Initialize segment selectors
@ 2020-06-23 8:41 Nadav Amit
2020-06-23 18:28 ` Jim Mattson
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Nadav Amit @ 2020-06-23 8:41 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm, Nadav Amit
Currently, the BSP's segment selectors are not initialized in 32-bit
(cstart.S). As a result the tests implicitly rely on the segment
selector values that are set by the BIOS. If this assumption is not
kept, the task-switch test fails.
Fix it by initializing them.
Signed-off-by: Nadav Amit <namit@vmware.com>
---
x86/cstart.S | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/x86/cstart.S b/x86/cstart.S
index fa62e09..5ad70b5 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -94,6 +94,15 @@ MSR_GS_BASE = 0xc0000101
wrmsr
.endm
+.macro setup_segments
+ mov $0x10, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %fs
+ mov %ax, %gs
+ mov %ax, %ss
+.endm
+
.globl start
start:
mov $stacktop, %esp
@@ -109,6 +118,7 @@ start:
prepare_32:
lgdtl gdt32_descr
+ setup_segments
mov %cr4, %eax
bts $4, %eax // pse
@@ -133,12 +143,7 @@ save_id:
retl
ap_start32:
- mov $0x10, %ax
- mov %ax, %ds
- mov %ax, %es
- mov %ax, %fs
- mov %ax, %gs
- mov %ax, %ss
+ setup_segments
mov $-4096, %esp
lock/xaddl %esp, smp_stacktop
setup_percpu_area
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-23 8:41 [kvm-unit-tests PATCH] x86: Initialize segment selectors Nadav Amit
@ 2020-06-23 18:28 ` Jim Mattson
2020-06-24 6:42 ` Paolo Bonzini
2020-06-24 12:52 ` Thomas Huth
2 siblings, 0 replies; 7+ messages in thread
From: Jim Mattson @ 2020-06-23 18:28 UTC (permalink / raw)
To: Nadav Amit; +Cc: Paolo Bonzini, kvm list
On Tue, Jun 23, 2020 at 1:44 AM Nadav Amit <namit@vmware.com> wrote:
>
> Currently, the BSP's segment selectors are not initialized in 32-bit
> (cstart.S). As a result the tests implicitly rely on the segment
> selector values that are set by the BIOS. If this assumption is not
> kept, the task-switch test fails.
>
> Fix it by initializing them.
>
> Signed-off-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-23 8:41 [kvm-unit-tests PATCH] x86: Initialize segment selectors Nadav Amit
2020-06-23 18:28 ` Jim Mattson
@ 2020-06-24 6:42 ` Paolo Bonzini
2020-06-24 12:52 ` Thomas Huth
2 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2020-06-24 6:42 UTC (permalink / raw)
To: Nadav Amit; +Cc: kvm
On 23/06/20 10:41, Nadav Amit wrote:
> Currently, the BSP's segment selectors are not initialized in 32-bit
> (cstart.S). As a result the tests implicitly rely on the segment
> selector values that are set by the BIOS. If this assumption is not
> kept, the task-switch test fails.
>
> Fix it by initializing them.
>
> Signed-off-by: Nadav Amit <namit@vmware.com>
> ---
> x86/cstart.S | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/x86/cstart.S b/x86/cstart.S
> index fa62e09..5ad70b5 100644
> --- a/x86/cstart.S
> +++ b/x86/cstart.S
> @@ -94,6 +94,15 @@ MSR_GS_BASE = 0xc0000101
> wrmsr
> .endm
>
> +.macro setup_segments
> + mov $0x10, %ax
> + mov %ax, %ds
> + mov %ax, %es
> + mov %ax, %fs
> + mov %ax, %gs
> + mov %ax, %ss
> +.endm
> +
> .globl start
> start:
> mov $stacktop, %esp
> @@ -109,6 +118,7 @@ start:
>
> prepare_32:
> lgdtl gdt32_descr
> + setup_segments
>
> mov %cr4, %eax
> bts $4, %eax // pse
> @@ -133,12 +143,7 @@ save_id:
> retl
>
> ap_start32:
> - mov $0x10, %ax
> - mov %ax, %ds
> - mov %ax, %es
> - mov %ax, %fs
> - mov %ax, %gs
> - mov %ax, %ss
> + setup_segments
> mov $-4096, %esp
> lock/xaddl %esp, smp_stacktop
> setup_percpu_area
>
Applied, thanks.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-23 8:41 [kvm-unit-tests PATCH] x86: Initialize segment selectors Nadav Amit
2020-06-23 18:28 ` Jim Mattson
2020-06-24 6:42 ` Paolo Bonzini
@ 2020-06-24 12:52 ` Thomas Huth
2020-06-24 14:10 ` Paolo Bonzini
2 siblings, 1 reply; 7+ messages in thread
From: Thomas Huth @ 2020-06-24 12:52 UTC (permalink / raw)
To: Nadav Amit, Paolo Bonzini; +Cc: kvm
On 23/06/2020 10.41, Nadav Amit wrote:
> Currently, the BSP's segment selectors are not initialized in 32-bit
> (cstart.S). As a result the tests implicitly rely on the segment
> selector values that are set by the BIOS. If this assumption is not
> kept, the task-switch test fails.
>
> Fix it by initializing them.
>
> Signed-off-by: Nadav Amit <namit@vmware.com>
> ---
> x86/cstart.S | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
I'm sorry to be the bearer of bad news again, but this commit broke
another set of tests in the Travis CI:
https://travis-ci.com/github/huth/kvm-unit-tests/jobs/353103187#L796
smptest, smptest3, kvmclock_test, hyperv_synic and hyperv_stimer are
failing now in the 32-bit kvm-unit-tests :-(
Thomas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-24 12:52 ` Thomas Huth
@ 2020-06-24 14:10 ` Paolo Bonzini
2020-06-24 17:28 ` Nadav Amit
0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2020-06-24 14:10 UTC (permalink / raw)
To: Thomas Huth, Nadav Amit; +Cc: kvm
On 24/06/20 14:52, Thomas Huth wrote:
> On 23/06/2020 10.41, Nadav Amit wrote:
>> Currently, the BSP's segment selectors are not initialized in 32-bit
>> (cstart.S). As a result the tests implicitly rely on the segment
>> selector values that are set by the BIOS. If this assumption is not
>> kept, the task-switch test fails.
>>
>> Fix it by initializing them.
>>
>> Signed-off-by: Nadav Amit <namit@vmware.com>
>> ---
>> x86/cstart.S | 17 +++++++++++------
>> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> I'm sorry to be the bearer of bad news again, but this commit broke
> another set of tests in the Travis CI:
>
> https://travis-ci.com/github/huth/kvm-unit-tests/jobs/353103187#L796
>
> smptest, smptest3, kvmclock_test, hyperv_synic and hyperv_stimer are
> failing now in the 32-bit kvm-unit-tests :-(
And that's just bad testing (both Nadav's and mine). Writing to %gs
clobbers the PERCPU area. The fix is as simple as this:
diff --git a/x86/cstart.S b/x86/cstart.S
index 5ad70b5..77dc34d 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -106,6 +106,7 @@ MSR_GS_BASE = 0xc0000101
.globl start
start:
mov $stacktop, %esp
+ setup_segments
push %ebx
call setup_multiboot
call setup_libcflat
@@ -118,7 +119,6 @@ start:
prepare_32:
lgdtl gdt32_descr
- setup_segments
mov %cr4, %eax
bts $4, %eax // pse
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-24 14:10 ` Paolo Bonzini
@ 2020-06-24 17:28 ` Nadav Amit
2020-06-25 7:53 ` Paolo Bonzini
0 siblings, 1 reply; 7+ messages in thread
From: Nadav Amit @ 2020-06-24 17:28 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Thomas Huth, kvm
> On Jun 24, 2020, at 7:10 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 24/06/20 14:52, Thomas Huth wrote:
>> On 23/06/2020 10.41, Nadav Amit wrote:
>>> Currently, the BSP's segment selectors are not initialized in 32-bit
>>> (cstart.S). As a result the tests implicitly rely on the segment
>>> selector values that are set by the BIOS. If this assumption is not
>>> kept, the task-switch test fails.
>>>
>>> Fix it by initializing them.
>>>
>>> Signed-off-by: Nadav Amit <namit@vmware.com>
>>> ---
>>> x86/cstart.S | 17 +++++++++++------
>>> 1 file changed, 11 insertions(+), 6 deletions(-)
>>
>> I'm sorry to be the bearer of bad news again, but this commit broke
>> another set of tests in the Travis CI:
>>
>> https://travis-ci.com/github/huth/kvm-unit-tests/jobs/353103187#L796
>>
>> smptest, smptest3, kvmclock_test, hyperv_synic and hyperv_stimer are
>> failing now in the 32-bit kvm-unit-tests :-(
>
> And that's just bad testing (both Nadav's and mine). Writing to %gs
> clobbers the PERCPU area. The fix is as simple as this:
>
> diff --git a/x86/cstart.S b/x86/cstart.S
> index 5ad70b5..77dc34d 100644
> --- a/x86/cstart.S
> +++ b/x86/cstart.S
> @@ -106,6 +106,7 @@ MSR_GS_BASE = 0xc0000101
> .globl start
> start:
> mov $stacktop, %esp
> + setup_segments
> push %ebx
> call setup_multiboot
> call setup_libcflat
> @@ -118,7 +119,6 @@ start:
>
> prepare_32:
> lgdtl gdt32_descr
> - setup_segments
>
> mov %cr4, %eax
> bts $4, %eax // pse
Unfortunately this change does not work for me (i.e., it breaks the
task-switch test on my setup). Admittedly, my patch was wrong.
I actually did not notice this scheme of having the GS descriptor and
GS-base out of sync. It seems very fragile, specifically when you have a
task-switch that reloads the GS and overwrites the original value.
I will try to investigate it further later.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [kvm-unit-tests PATCH] x86: Initialize segment selectors
2020-06-24 17:28 ` Nadav Amit
@ 2020-06-25 7:53 ` Paolo Bonzini
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2020-06-25 7:53 UTC (permalink / raw)
To: Nadav Amit; +Cc: Thomas Huth, kvm
On 24/06/20 19:28, Nadav Amit wrote:
> Unfortunately this change does not work for me (i.e., it breaks the
> task-switch test on my setup). Admittedly, my patch was wrong.
>
> I actually did not notice this scheme of having the GS descriptor and
> GS-base out of sync. It seems very fragile, specifically when you have a
> task-switch that reloads the GS and overwrites the original value.
>
> I will try to investigate it further later.
Yeah, it's fragile but it's limited to the task switch tests; and it's
the only way to do it without having a separate selector or LDT for each
CPU.
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-06-25 7:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 8:41 [kvm-unit-tests PATCH] x86: Initialize segment selectors Nadav Amit
2020-06-23 18:28 ` Jim Mattson
2020-06-24 6:42 ` Paolo Bonzini
2020-06-24 12:52 ` Thomas Huth
2020-06-24 14:10 ` Paolo Bonzini
2020-06-24 17:28 ` Nadav Amit
2020-06-25 7:53 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.