qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Keith Packard <keithp@keithp.com>
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>
Subject: Re: [PATCH] Semihost SYS_READC implementation (v4)
Date: Thu, 14 Nov 2019 18:18:01 +0000	[thread overview]
Message-ID: <CAFEAcA8CO5gcVoEq+H=WnhafOf5XoUj2hCrXasrCamMY3QpO8A@mail.gmail.com> (raw)
In-Reply-To: <87zhgytjt7.fsf@keithp.com>

On Thu, 14 Nov 2019 at 18:05, Keith Packard <keithp@keithp.com> wrote:
>
> Peter Maydell <peter.maydell@linaro.org> writes:
>
> > I had an idle glance at this implementation, and this:
> >
> >    uint32_t pre = opcode_at(&ctx->base, ctx->base.pc_next - 4);
> >    uint32_t ebreak = opcode_at(&ctx->base, ctx->base.pc_next);
> >    uint32_t post = opcode_at(&ctx->base, ctx->base.pc_next + 4);
> >
> > (where opcode_at() is a wrapper for cpu_ldl_code()) has
> > some unfortunate side effects: if the previous instruction
> > is in the previous MMU page, or the following instruction
> > is in the next MMU page, you might incorrectly trigger
> > an exception (where QEMU will just longjmp straight out of
> > the cpu_ldl_code()) if that other page isn't actually mapped
> > in the guest's page table. You need to be careful not to access
> > code outside the page you're actually on unless you're really
> > going to execute it and are OK with it faulting.
>
> I can't even find the implementation of cpu_ldl_code; the qemu source
> code is somewhat obscure in this area. But, longjmp'ing out of the
> middle of that seems like a bad idea.

It's the way QEMU works -- generally load/store operations
that work on virtual addresses are expected to only return
in the success case; on failure they longjmp out to cause
the guest exception. (Load/stores on physical addresses
generally return a memory transaction status for the caller
to check and handle.) I agree that within the translation code
it's a bit weird and it might be nicer for the translate.c
code to explicitly handle failures to load an insn, but it
would be a bit of an upheaval to try to rewrite it at this point.

cpu_ldl_code() is provided by include/exec/cpu_ldst.h, incidentally
(via preprocessor macros and repeated inclusion of some template
.h files, which is why a grep for the function name misses it).

> > Does your semihosting spec expect to have the semihosting
> > call work if the sequence crosses a page boundary, the
> > code is being executed by a userspace process, and one of
> > the two pages has been paged out by the OS ?
>
> You've seen the entirety of the RISC-V semihosting spec already.  For
> now, perhaps we should limit RISC-V semihosting support to devices
> without paging support and await a more complete spec.
>
> As you suggest, disallowing the sequence from crossing a page boundary
> would be a simple fix, but that would require wording changes to the
> spec.

Yeah, I'm implicitly suggesting that a bit more thought/revision
of the spec might not be a bad idea. Things that are
effectively supposed to be treated like a single instruction
but which can cross cacheline or page boundaries turn out
to be a fertile source of implementation bugs. (The arm
translate.c code has to be quite careful about handling
32-bit Thumb insns that cross pages. The x86 translate.c
code is less careful and may well be buggy in this area.)

thanks
-- PMM


  reply	other threads:[~2019-11-14 18:19 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23 19:26 [PATCH] Semihost SYS_READC implementation (v3) Keith Packard
2019-10-24 17:33 ` no-reply
2019-10-24 18:54   ` Paolo Bonzini
2019-10-24 22:46     ` [PATCH] Semihost SYS_READC implementation (v4) Keith Packard
2019-10-25  9:51       ` Alex Bennée
2019-10-25 16:36         ` Keith Packard
2019-10-25 16:49           ` Peter Maydell
2019-10-25 19:15             ` Keith Packard
2019-10-25 20:53               ` Peter Maydell
2019-10-25 23:18                 ` Keith Packard
2019-11-04 20:42                   ` [PATCH] Semihost SYS_READC implementation (v6) Keith Packard
2019-12-17  8:38                     ` Alex Bennée
2019-12-17  9:08                       ` Paolo Bonzini
2019-12-17  9:51                         ` Alex Bennée
2019-12-17 10:04                           ` Paolo Bonzini
2019-12-17 12:14                             ` [RFC PATCH] semihosting: suspend recieving CPU when blocked (HACK, WIP) Alex Bennée
2019-12-17 12:22                               ` Paolo Bonzini
2019-12-17 13:42                                 ` Alex Bennée
2019-12-17 13:48                                   ` Paolo Bonzini
2019-12-17 14:18                                     ` Alex Bennée
2019-12-17 14:39                                       ` Paolo Bonzini
2019-12-17 14:39                                       ` Paolo Bonzini
2019-12-18 17:36                                         ` Alex Bennée
2019-12-18 21:23                                           ` Paolo Bonzini
2019-11-05  5:10                 ` [PATCH] Semihost SYS_READC implementation (v4) Keith Packard
2019-11-11 14:51                   ` Peter Maydell
2019-11-14 15:46                     ` Alistair Francis
2019-11-14 17:43                       ` Keith Packard
2019-11-14 17:39                     ` Keith Packard
2019-11-14 17:47                       ` Peter Maydell
2019-11-14 19:20                         ` Peter Maydell
2019-11-14 16:14               ` Peter Maydell
2019-11-14 18:05                 ` Keith Packard
2019-11-14 18:18                   ` Peter Maydell [this message]
2019-11-14 19:18                 ` Richard Henderson
2019-11-14 19:29                   ` Peter Maydell
2019-11-14 20:52                     ` Richard Henderson
2019-11-14 21:04                       ` Peter Maydell
2019-11-14 22:26                   ` Keith Packard
2019-11-15 10:54                     ` Peter Maydell
2019-11-15 23:40                       ` Keith Packard
2019-10-25 17:02           ` Alex Bennée
2019-10-25 18:17       ` no-reply
2019-10-25 18:20       ` no-reply
2019-10-24 17:43 ` [PATCH] Semihost SYS_READC implementation (v3) no-reply

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='CAFEAcA8CO5gcVoEq+H=WnhafOf5XoUj2hCrXasrCamMY3QpO8A@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=keithp@keithp.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).