--
1.9.3
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Avi, sorry, but given all this, it is no longer clear for me if the SSE part of evil memcpy would bring us
that much value. No to mention this is messing with the fpu for any memcpy size, whereas the sse problem exists
only for a short range. We have seen, I guess, that a single branch instruction is not *that* expensive for memcpy, so
maybe it is better to branch at memcpy site and only use sse if it is safe?
From: Avi Kivity <a...@cloudius-systems.com>
fpu: early save/restore in interrupt/exception context
Since we cannot guarantee that the fpu will not be used in interrupts and
exceptions, we must save it earlier rather than later.
This was discovered with an fpu-based memcpy, but can be triggered in other
ways.
Signed-off-by: Avi Kivity <a...@cloudius-systems.com>
---
diff --git a/arch/aarch64/exceptions.cc b/arch/aarch64/exceptions.cc
--- a/arch/aarch64/exceptions.cc
+++ b/arch/aarch64/exceptions.cc
@@ -82,6 +82,8 @@ extern "C" { void interrupt(exception_frame* frame); }
void interrupt(exception_frame* frame)
{
+ sched::fpu_lock fpu;
+ SCOPE_LOCK(fpu);
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, May 28, 2014 at 10:55 AM, Commit Bot <b...@cloudius-systems.com> wrote:
From: Avi Kivity <a...@cloudius-systems.com>
fpu: early save/restore in interrupt/exception context
Since we cannot guarantee that the fpu will not be used in interrupts and
exceptions, we must save it earlier rather than later.
This was discovered with an fpu-based memcpy, but can be triggered in other
ways.
Signed-off-by: Avi Kivity <a...@cloudius-systems.com>
---
diff --git a/arch/aarch64/exceptions.cc b/arch/aarch64/exceptions.cc
--- a/arch/aarch64/exceptions.cc
+++ b/arch/aarch64/exceptions.cc
@@ -82,6 +82,8 @@ extern "C" { void interrupt(exception_frame* frame); }
void interrupt(exception_frame* frame)
{
+ sched::fpu_lock fpu;
+ SCOPE_LOCK(fpu);
This uses a significant chunk of the per-thread interrupt stack, so maybe we need to grow it accordingly - or not, if it was already too big...
The good news is that this won't take more memory from before, since this patch removes the per-thread fpu state.
From: Avi Kivity <a...@cloudius-systems.com>
elf: allow elf_resolve_pltgot() to use the fpu
elf_resolve_pltgot() can be called from anywhere, including with dirty fpu
state. Ensure the fpu is not clobbered during its execution.
Signed-off-by: Avi Kivity <a...@cloudius-systems.com>
---
diff --git a/arch/x64/elf-dl.S b/arch/x64/elf-dl.S
--- a/arch/x64/elf-dl.S
+++ b/arch/x64/elf-dl.S
@@ -20,13 +20,20 @@ __elf_resolve_pltgot:
.cfi_rel_offset %rip, 16
sub $8, %rsp # make room for resolved address
.cfi_adjust_cfa_offset 8
+ pushq_cfi %rbp
+ .cfi_adjust_cfa_offset 8
+ mov %rsp, %rbp
+ .cfi_def_cfa %rbp, 16
+
+ # align stack
+ andq $-16, %rsp
+
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, May 28, 2014 at 10:55 AM, Commit Bot <b...@cloudius-systems.com> wrote:
From: Avi Kivity <a...@cloudius-systems.com>
elf: allow elf_resolve_pltgot() to use the fpu
elf_resolve_pltgot() can be called from anywhere, including with dirty fpu
state. Ensure the fpu is not clobbered during its execution.
Signed-off-by: Avi Kivity <a...@cloudius-systems.com>
---
diff --git a/arch/x64/elf-dl.S b/arch/x64/elf-dl.S
--- a/arch/x64/elf-dl.S
+++ b/arch/x64/elf-dl.S
@@ -20,13 +20,20 @@ __elf_resolve_pltgot:
.cfi_rel_offset %rip, 16
sub $8, %rsp # make room for resolved address
.cfi_adjust_cfa_offset 8
+ pushq_cfi %rbp
+ .cfi_adjust_cfa_offset 8
+ mov %rsp, %rbp
+ .cfi_def_cfa %rbp, 16
+
+ # align stack
+ andq $-16, %rsp
+
Hi Avi, is it possible that after this patch, something is wrong with the dwarf debugging data here?
I won't pretend I remember anything from this CFI stuff (once I understood it pretty well, but I no longer do), but the "andq" without a matching cfi thing is most suspicious (?). Here is an example stack trace I'm seeing from inside __elf_resolve_pltgot:
#0 elf::object::resolve_pltgot (this=<optimized out>, index=<optimized out>)
at /home/nyh/osv/core/elf.cc:574
#1 0x0000000000339050 in elf_resolve_pltgot (index=<optimized out>,
obj=<optimized out>) at /home/nyh/osv/core/elf.cc:1356
#2 0x0000000000370e82 in __elf_resolve_pltgot ()
at /home/nyh/osv/arch/x64/elf-dl.S:47
#3 0x0000000000000010 in ?? ()
#4 0x000000000033b12d in elf::program::get_library (this=<optimized out>,
name=..., extra_path=...) at /home/nyh/osv/core/elf.cc:999
Frame #3 appears crap, and I'm missing a bunch of other frames (in this case I was expecting to see a call to some static constructor, which calls one function, which then calls the function that needs to be resolved so ends up calling __elf_resolve_pltgot().
By the way, I am curious - why is special stack-alignment code actually needed in __elf_resolve_pltgot? I would have thought that this function only gets called when the caller is prepared to call a real function, so the caller would already have ensured that regular ABI guarantees are followed before making this call. Isn't it so?
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Interesting, I didn't think of that at all. However it's better to be extra safe here and assume nothing.By the way, I am curious - why is special stack-alignment code actually needed in __elf_resolve_pltgot? I would have thought that this function only gets called when the caller is prepared to call a real function, so the caller would already have ensured that regular ABI guarantees are followed before making this call. Isn't it so?
On Sun, Jun 1, 2014 at 5:22 PM, Avi Kivity <a...@cloudius-systems.com> wrote:
Interesting, I didn't think of that at all. However it's better to be extra safe here and assume nothing.By the way, I am curious - why is special stack-alignment code actually needed in __elf_resolve_pltgot? I would have thought that this function only gets called when the caller is prepared to call a real function, so the caller would already have ensured that regular ABI guarantees are followed before making this call. Isn't it so?
My question also applies to the whole FPU-saving thing too - if the caller was about to call a function, it would also save its own FPU state, and we don't need to save it in the callee...
Did you see a problem before this patch?
I wonder what it could be. Can __elf_resolve_pltgot ever be used for something other than function calls? Is it ever used to resolve variable names or something? (I didn't think so, but maybe?)
If this whole patch is not necessary I'm not sure the "extra safe" is warranted here, especially if it creates weird unwinding bugs (although those obviously can be solved).
No. If it's calling a function with floating point arguments, then these would be loaded into the fpu registers just prior to calling that function.
On 06/01/2014 05:30 PM, Nadav Har'El wrote:
On Sun, Jun 1, 2014 at 5:22 PM, Avi Kivity <a...@cloudius-systems.com> wrote:
Interesting, I didn't think of that at all. However it's better to be extra safe here and assume nothing.By the way, I am curious - why is special stack-alignment code actually needed in __elf_resolve_pltgot? I would have thought that this function only gets called when the caller is prepared to call a real function, so the caller would already have ensured that regular ABI guarantees are followed before making this call. Isn't it so?
My question also applies to the whole FPU-saving thing too - if the caller was about to call a function, it would also save its own FPU state, and we don't need to save it in the callee...
Yes, very early crashes with fpu-using memcpy.
Did you see a problem before this patch?No.
I wonder what it could be. Can __elf_resolve_pltgot ever be used for something other than function calls? Is it ever used to resolve variable names or something? (I didn't think so, but maybe?)
I'll take a stab at fixing it.
If this whole patch is not necessary I'm not sure the "extra safe" is warranted here, especially if it creates weird unwinding bugs (although those obviously can be solved).
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Sun, Jun 1, 2014 at 11:39 AM, Avi Kivity <a...@cloudius-systems.com> wrote:
No. If it's calling a function with floating point arguments, then these would be loaded into the fpu registers just prior to calling that function.
On 06/01/2014 05:30 PM, Nadav Har'El wrote:
On Sun, Jun 1, 2014 at 5:22 PM, Avi Kivity <a...@cloudius-systems.com> wrote:
Interesting, I didn't think of that at all. However it's better to be extra safe here and assume nothing.By the way, I am curious - why is special stack-alignment code actually needed in __elf_resolve_pltgot? I would have thought that this function only gets called when the caller is prepared to call a real function, so the caller would already have ensured that regular ABI guarantees are followed before making this call. Isn't it so?
My question also applies to the whole FPU-saving thing too - if the caller was about to call a function, it would also save its own FPU state, and we don't need to save it in the callee...
I think Nadav means the FPU registers respective to the current function being saved prior to calling a new function (to allow reentrancy).