[Qemu-devel] [PATCH 0/9] Assembly coroutine backend and x86 CET support

Paolo Bonzini posted 9 patches 4 years, 11 months ago
Test docker-mingw@fedora passed
Test docker-clang@ubuntu failed
Test asan passed
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190504120528.6389-1-pbonzini@redhat.com
Maintainers: Claudio Fontana <claudio.fontana@huawei.com>, Aurelien Jarno <aurelien@aurel32.net>, Aleksandar Rikalo <arikalo@wavecomp.com>, Palmer Dabbelt <palmer@sifive.com>, Kevin Wolf <kwolf@redhat.com>, Alistair Francis <Alistair.Francis@wdc.com>, Andrzej Zaborowski <balrogg@gmail.com>, Riku Voipio <riku.voipio@iki.fi>, Stefan Hajnoczi <stefanha@redhat.com>, Stefan Weil <sw@weilnetz.de>, Laurent Vivier <laurent@vivier.eu>, Richard Henderson <rth@twiddle.net>
Makefile.target                           |   5 +
configure                                 |  62 ++++
include/qemu/cpuid.h                      |   5 +
linux-user/host/i386/safe-syscall.inc.S   |  19 ++
linux-user/host/x86_64/safe-syscall.inc.S |  19 ++
scripts/qemugdb/coroutine.py              | 107 ++----
scripts/qemugdb/coroutine_asm.py          |  24 ++
scripts/qemugdb/coroutine_ucontext.py     |  69 ++++
tcg/aarch64/tcg-target.inc.c              |   4 +
tcg/arm/tcg-target.inc.c                  |   4 +
tcg/i386/tcg-target.inc.c                 |  23 ++
tcg/mips/tcg-target.inc.c                 |   4 +
tcg/ppc/tcg-target.inc.c                  |   4 +
tcg/riscv/tcg-target.inc.c                |   4 +
tcg/s390/tcg-target.inc.c                 |   4 +
tcg/sparc/tcg-target.inc.c                |   4 +
tcg/tcg.c                                 |   2 +
tcg/tci/tcg-target.inc.c                  |   4 +
util/Makefile.objs                        |  10 +
util/coroutine-asm.c                      | 387 ++++++++++++++++++++++
20 files changed, 689 insertions(+), 75 deletions(-)
create mode 100644 scripts/qemugdb/coroutine_asm.py
create mode 100644 scripts/qemugdb/coroutine_ucontext.py
create mode 100644 util/coroutine-asm.c
[Qemu-devel] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Paolo Bonzini 4 years, 11 months ago
*** BLURB HERE ***

Paolo Bonzini (10):
  qemugdb: allow adding support for other coroutine backends
  qemugdb: allow adding support for other architectures
  coroutine: add host specific coroutine backend for 64-bit x86
  coroutine: add host specific coroutine backend for 64-bit ARM
  coroutine: add host specific coroutine backend for 64-bit s390
  configure: add control-flow protection support
  tcg: add tcg_out_start
  tcg/i386: add support for IBT
  linux-user: add IBT support to x86 safe-syscall.S
  coroutine-asm: add x86 CET shadow stack support

 Makefile.target                           |   5 +
 configure                                 |  62 ++++
 include/qemu/cpuid.h                      |   5 +
 linux-user/host/i386/safe-syscall.inc.S   |  19 ++
 linux-user/host/x86_64/safe-syscall.inc.S |  19 ++
 scripts/qemugdb/coroutine.py              | 107 ++----
 scripts/qemugdb/coroutine_asm.py          |  24 ++
 scripts/qemugdb/coroutine_ucontext.py     |  69 ++++
 tcg/aarch64/tcg-target.inc.c              |   4 +
 tcg/arm/tcg-target.inc.c                  |   4 +
 tcg/i386/tcg-target.inc.c                 |  23 ++
 tcg/mips/tcg-target.inc.c                 |   4 +
 tcg/ppc/tcg-target.inc.c                  |   4 +
 tcg/riscv/tcg-target.inc.c                |   4 +
 tcg/s390/tcg-target.inc.c                 |   4 +
 tcg/sparc/tcg-target.inc.c                |   4 +
 tcg/tcg.c                                 |   2 +
 tcg/tci/tcg-target.inc.c                  |   4 +
 util/Makefile.objs                        |  10 +
 util/coroutine-asm.c                      | 387 ++++++++++++++++++++++
 20 files changed, 689 insertions(+), 75 deletions(-)
 create mode 100644 scripts/qemugdb/coroutine_asm.py
 create mode 100644 scripts/qemugdb/coroutine_ucontext.py
 create mode 100644 util/coroutine-asm.c

-- 
2.21.0


Re: [Qemu-devel] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Stefan Hajnoczi 4 years, 11 months ago
On Sat, May 04, 2019 at 06:05:18AM -0600, Paolo Bonzini wrote:
> *** BLURB HERE ***
> 
> Paolo Bonzini (10):
>   qemugdb: allow adding support for other coroutine backends
>   qemugdb: allow adding support for other architectures
>   coroutine: add host specific coroutine backend for 64-bit x86
>   coroutine: add host specific coroutine backend for 64-bit ARM
>   coroutine: add host specific coroutine backend for 64-bit s390
>   configure: add control-flow protection support
>   tcg: add tcg_out_start
>   tcg/i386: add support for IBT
>   linux-user: add IBT support to x86 safe-syscall.S
>   coroutine-asm: add x86 CET shadow stack support
> 
>  Makefile.target                           |   5 +
>  configure                                 |  62 ++++
>  include/qemu/cpuid.h                      |   5 +
>  linux-user/host/i386/safe-syscall.inc.S   |  19 ++
>  linux-user/host/x86_64/safe-syscall.inc.S |  19 ++
>  scripts/qemugdb/coroutine.py              | 107 ++----
>  scripts/qemugdb/coroutine_asm.py          |  24 ++
>  scripts/qemugdb/coroutine_ucontext.py     |  69 ++++
>  tcg/aarch64/tcg-target.inc.c              |   4 +
>  tcg/arm/tcg-target.inc.c                  |   4 +
>  tcg/i386/tcg-target.inc.c                 |  23 ++
>  tcg/mips/tcg-target.inc.c                 |   4 +
>  tcg/ppc/tcg-target.inc.c                  |   4 +
>  tcg/riscv/tcg-target.inc.c                |   4 +
>  tcg/s390/tcg-target.inc.c                 |   4 +
>  tcg/sparc/tcg-target.inc.c                |   4 +
>  tcg/tcg.c                                 |   2 +
>  tcg/tci/tcg-target.inc.c                  |   4 +
>  util/Makefile.objs                        |  10 +
>  util/coroutine-asm.c                      | 387 ++++++++++++++++++++++
>  20 files changed, 689 insertions(+), 75 deletions(-)
>  create mode 100644 scripts/qemugdb/coroutine_asm.py
>  create mode 100644 scripts/qemugdb/coroutine_ucontext.py
>  create mode 100644 util/coroutine-asm.c
> 
> -- 
> 2.21.0
> 
> 

Aside from the comments I posted:
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Re: [Qemu-devel] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Alex Bennée 4 years, 11 months ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> *** BLURB HERE ***

I assume there was going to be a bit more background here?

--
Alex Bennée

Re: [Qemu-devel] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Peter Maydell 4 years, 11 months ago
On Sun, 5 May 2019 at 16:41, Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
> > *** BLURB HERE ***
>
> I assume there was going to be a bit more background here?

Mmm, could we have the rationale, please ?

thanks
-- PMM

Re: [Qemu-devel] [Qemu-block] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Stefan Hajnoczi 4 years, 11 months ago
On Thu, May 09, 2019 at 02:44:39PM +0100, Peter Maydell wrote:
> On Sun, 5 May 2019 at 16:41, Alex Bennée <alex.bennee@linaro.org> wrote:
> >
> >
> > Paolo Bonzini <pbonzini@redhat.com> writes:
> >
> > > *** BLURB HERE ***
> >
> > I assume there was going to be a bit more background here?
> 
> Mmm, could we have the rationale, please ?

Paolo can add more if necessary, but my understanding is:

1. It's required for Intel Control-flow Enforcement Technology (CET).
   The existing ucontext backend doesn't work with CET.
2. It's faster than the existing ucontext implementation.
Re: [Qemu-devel] [Qemu-block] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Peter Maydell 4 years, 11 months ago
On Wed, 15 May 2019 at 10:48, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Thu, May 09, 2019 at 02:44:39PM +0100, Peter Maydell wrote:
> > On Sun, 5 May 2019 at 16:41, Alex Bennée <alex.bennee@linaro.org> wrote:
> > >
> > >
> > > Paolo Bonzini <pbonzini@redhat.com> writes:
> > >
> > > > *** BLURB HERE ***
> > >
> > > I assume there was going to be a bit more background here?
> >
> > Mmm, could we have the rationale, please ?
>
> Paolo can add more if necessary, but my understanding is:
>
> 1. It's required for Intel Control-flow Enforcement Technology (CET).
>    The existing ucontext backend doesn't work with CET.
> 2. It's faster than the existing ucontext implementation.

Mmm, I think we've talked about 1 before, but I think it would
be useful to clearly state why we need to do things here.
It's also useful for identifying whether we need an asm
backend for every host, or only some hosts (and if so which).

I'm unconvinced by 2 as a rationale for adding more host asm.
Coroutines were already bad enough when they were at least
vaguely portable C code.

thanks
-- PMM

Re: [Qemu-devel] [Qemu-block] [PATCH 0/9] Assembly coroutine backend and x86 CET support
Posted by Paolo Bonzini 4 years, 11 months ago
On 16/05/19 14:50, Peter Maydell wrote:
> On Wed, 15 May 2019 at 10:48, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> 1. It's required for Intel Control-flow Enforcement Technology (CET).
>>    The existing ucontext backend doesn't work with CET.
>> 2. It's faster than the existing ucontext implementation.
> 
> Mmm, I think we've talked about 1 before, but I think it would
> be useful to clearly state why we need to do things here.

The reason is that, with CET enabled, setjmp and longjmp assume that
they are used only to unwind the stack and not to switch to a completely
different one.  You are supposed to use swapcontext for that, but it
doesn't work for QEMU coroutines because it saves/restores the signal
mask; that is not only slower, it's incorrect we want the signal mask to
be a property of the thread, not the coroutine.

> It's also useful for identifying whether we need an asm
> backend for every host, or only some hosts (and if so which).

It's not needed for _any_ host (except x86 if you want CET support).  I
wrote these three backends to ensure that it could be ported without
much effort on any host.  If you prefer not having an aarch64 backend,
for example, I can leave it out.

Paolo