All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PULL 12/13] page_unprotect(): handle calls to pages that are PAGE_WRITE
Date: Thu, 22 Mar 2018 02:52:58 +0100	[thread overview]
Message-ID: <758f54da-d733-6e95-57cf-cc8b25a81dd5@vivier.eu> (raw)
In-Reply-To: <20180123144807.5618-13-laurent@vivier.eu>

Le 23/01/2018 à 15:48, Laurent Vivier a écrit :
> From: Peter Maydell <peter.maydell@linaro.org>
> 
> If multiple guest threads in user-mode emulation write to a
> page which QEMU has marked read-only because of cached TCG
> translations, the threads can race in page_unprotect:
> 
>  * threads A & B both try to do a write to a page with code in it at
>    the same time (ie which we've made non-writeable, so SEGV)
>  * they race into the signal handler with this faulting address
>  * thread A happens to get to page_unprotect() first and takes the
>    mmap lock, so thread B sits waiting for it to be done
>  * A then finds the page, marks it PAGE_WRITE and mprotect()s it writable
>  * A can then continue OK (returns from signal handler to retry the
>    memory access)
>  * ...but when B gets the mmap lock it finds that the page is already
>    PAGE_WRITE, and so it exits page_unprotect() via the "not due to
>    protected translation" code path, and wrongly delivers the signal
>    to the guest rather than just retrying the access
> 
> In particular, this meant that trying to run 'javac' in user-mode
> emulation would fail with a spurious guest SIGSEGV.
> 
> Handle this by making page_unprotect() assume that a call for a page
> which is already PAGE_WRITE is due to a race of this sort and return
> a "fault handled" indication.
> 
> Since this would cause an infinite loop if we ever called
> page_unprotect() for some other kind of fault than "write failed due
> to bad access permissions", tighten the condition in
> handle_cpu_signal() to check the signal number and si_code, and add a
> comment so that if somebody does ever find themselves debugging an
> infinite loop of faults they have some clue about why.
> 
> (The trick for identifying the correct setting for
> current_tb_invalidated for thread B (needed to handle the precise-SMC
> case) is due to Richard Henderson.  Paolo Bonzini suggested just
> relying on si_code rather than trying anything more complicated.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Message-Id: <1511879725-9576-3-git-send-email-peter.maydell@linaro.org>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  accel/tcg/translate-all.c | 50 +++++++++++++++++++++++++++++------------------
>  accel/tcg/user-exec.c     | 13 +++++++++++-
>  2 files changed, 43 insertions(+), 20 deletions(-)
> 

It seems this patch breaks something in linux-user mode emulation for
m68k (32bit BE) on ppc (32bit BE).

What I have:

  ~/chroot$ sudo QEMU_CPU=m68040 chroot m68k/sid/
  I have no name!@localhost:/# ls
  bin   debootstrap  etc	 lib   qemu-m68k  run	sys  usr
  boot  dev	   home  proc  root	  sbin	tmp  var
  qemu: uncaught target signal 11 (Segmentation fault) - core dumped
  ~/chroot$

It seems "bash" crashes on "ls" exit.

My chroot has been installed with:

  ARCH=m68k
  TARGET=sid
  CHROOT=$HOME/chroot/m68k/sid/
  REPOT=http://cdn-fastly.deb.debian.org/debian-ports/
  debootstrap --arch=$ARCH --foreign --variant=minbase \
              --no-check-gpg $TARGET $CHROOT $REPO

I didn't investigate more.

Thanks,
Laurent

  reply	other threads:[~2018-03-22  1:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 14:47 [Qemu-devel] [PULL 00/13] Linux user for 2.12 patches Laurent Vivier
2018-01-23 14:47 ` [Qemu-devel] [PULL 01/13] linux-user: Fix locking order in fork_start() Laurent Vivier
2018-01-23 14:47 ` [Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusive section Laurent Vivier
2018-01-23 14:47 ` [Qemu-devel] [PULL 03/13] linux-user: Fix length calculations in host_to_target_cmsg() Laurent Vivier
2018-01-23 14:47 ` [Qemu-devel] [PULL 04/13] linux-user: Don't use CMSG_ALIGN(sizeof struct cmsghdr) Laurent Vivier
2018-01-23 14:47 ` [Qemu-devel] [PULL 05/13] linux-user: Translate flags argument to dup3 syscall Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 06/13] linux-user/mmap.c: Avoid choosing NULL as start address Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 07/13] linux-user: Fix sched_get/setaffinity conversion Laurent Vivier
2018-01-26 18:23   ` Peter Maydell
2018-01-26 18:33     ` Samuel Thibault
2018-01-23 14:48 ` [Qemu-devel] [PULL 08/13] linux-user: Add AT_SECURE auxval Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 09/13] linux-user: Add getcpu() support Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 10/13] linux-user: remove nmi.c and fw-path-provider.c Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 11/13] linux-user: Propagate siginfo_t through to handle_cpu_signal() Laurent Vivier
2018-01-23 14:48 ` [Qemu-devel] [PULL 12/13] page_unprotect(): handle calls to pages that are PAGE_WRITE Laurent Vivier
2018-03-22  1:52   ` Laurent Vivier [this message]
2018-03-22 10:36     ` Laurent Vivier
2018-03-22 11:05       ` Peter Maydell
2018-03-22 11:07         ` Peter Maydell
2018-03-22 11:13           ` Laurent Vivier
2018-03-22 16:47             ` Laurent Vivier
2018-03-22 11:07         ` Laurent Vivier
2018-03-22 11:10           ` Peter Maydell
2018-01-23 14:48 ` [Qemu-devel] [PULL 13/13] linux-user: implement renameat2 Laurent Vivier
2018-01-23 19:13   ` Palmer Dabbelt
2018-01-23 20:13     ` Laurent Vivier
2018-01-23 20:55       ` Palmer Dabbelt
2018-01-25 11:37 ` [Qemu-devel] [PULL 00/13] Linux user for 2.12 patches Peter Maydell

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=758f54da-d733-6e95-57cf-cc8b25a81dd5@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 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.