All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm <qemu-arm@nongnu.org>, QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 03/28] semihosting: implement a semihosting console
Date: Fri, 24 May 2019 12:25:23 +0100	[thread overview]
Message-ID: <875zq014d8.fsf@zen.linaroharston> (raw)
In-Reply-To: <CAFEAcA_Fu3Ep10NooU5-XcAqQVjJQE5o1L2JTdYTatjcOptPUg@mail.gmail.com>


Peter Maydell <peter.maydell@linaro.org> writes:

> On Fri, 24 May 2019 at 11:46, Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>>
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>> > On Thu, 23 May 2019 at 11:39, Alex Bennée <alex.bennee@linaro.org> wrote:
>> > I'm not sure about the "no callback" part of this API. The operation
>> > here is genuinely asynchronous and providing no mechanism for the
>> > caller to be able to say "ok, now wait til it completes" doesn't
>> > seem like a good plan.
>>
>> Well the caller doesn't really get a choice. At least in system mode
>> gdbstub does a vm_stop(RUN_STATE_DEBUG) and brings everything to a halt
>> anyway. All we've removed is the ability to tack on a callback (which
>> can get run in all sorts of contexts) when we restart.
>
> gdb_do_syscall() is asynchronous -- it arranges for the syscall
> to happen, but makes no guarantee about when it will finish.
> At the moment the gdb_do_syscall() API allows the caller
> to cope with this asynchronousness, because when the callback
> is called the syscall has definitely finished. As it happens
> the callers are buggy in that they don't actually do the
> sync that they need to do, but we could fix that bug (ie post
> a semaphore in the callback function, and wait on it after
> the gdb_do_syscall() call). The API for this new function
> doesn't allow us to do that.

So for the ARM semi side the console writes are treated as always
successful so the return value is correct (it doesn't matter for writec)
and no syncing to the guest is required. However I ran into a problem
because in gdbstub we have:

    /* Is there a GDB syscall waiting to be sent?  */
    if (s->current_syscall_cb) {
        put_packet(s, s->syscall_buf);
        return;
    }

which means it can't accept NULL for the callback. So I've removed the
gdb_console_out and done:

  static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong err)
  {
      if (ret == (target_ulong) -1) {
          qemu_log("%s: gdb console output failed (%s)", __func__, strerror(-err));
      }
  }

  int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr, int len)
  {
      GString *s = copy_user_string(env, addr, len);
      int out = s->len;

      if (use_gdb_syscalls()) {
          gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, s->len);
      } else {
          out = qemu_semihosting_log_out(s->str, s->len);
      }

      g_string_free(s, true);
      return out;
  }

for now.

>> I could just drop the API here and allow the semihosting API to call
>> gdb_do_syscallv directly?
>
> I think we should either make the implementation of the function
> properly synchronous (ie do the post-semaphore-in-callback,
> wait-on-it-after-gdb_do_syscallv thing in the implementation,
> or have an API that lets callers do it.
>
> Perhaps we should just make gdb_do_syscall really be
> synchronous (ie have it do the semaphore stuff)? We
> only actually use it in semihosting, and I think all
> those cases require that the operation completes before
> we can resume execution of the guest CPU. So doing the
> synchronization in one place in the gdb code would be
> simpler than doing it separately in all the callers...

Maybe.. this seems like a bigger clean-up to do that properly. Maybe
that would be worth tackling after the gdbstub refactor stuff goes in?

--
Alex Bennée


  reply	other threads:[~2019-05-24 11:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 10:25 [Qemu-devel] [PATCH v2 00/28] current testing/next queue Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 01/28] semihosting: move semihosting configuration into its own directory Alex Bennée
2019-05-23 15:12   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 02/28] semihosting: introduce CONFIG_SEMIHOSTING Alex Bennée
2019-05-23 15:12   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 03/28] semihosting: implement a semihosting console Alex Bennée
2019-05-23 13:13   ` Peter Maydell
2019-05-24 10:46     ` Alex Bennée
2019-05-24 10:56       ` Peter Maydell
2019-05-24 11:25         ` Alex Bennée [this message]
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 04/28] semihosting: enable chardev backed output for console Alex Bennée
2019-05-23 15:16   ` Richard Henderson
2019-05-28  9:36     ` Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 05/28] target/arm: fixup some of the commentary for arm-semi Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 06/28] target/arm: use the common interface for WRITE0/WRITEC in arm-semi Alex Bennée
2019-05-23 15:12   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 07/28] target/arm: add LOG_UNIMP messages to arm-semi Alex Bennée
2019-05-23 15:18   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 08/28] target/arm: correct return values for WRITE/READ in arm-semi Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 09/28] target/mips: only build mips-semi for softmmu Alex Bennée
2019-05-23 19:52   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 10/28] target/mips: convert UHI_plog to use common semihosting code Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 11/28] MAINTAINERS: update for semihostings new home Alex Bennée
2019-05-23 19:55   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 12/28] tests/docker: add ubuntu 18.04 Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 13/28] tests/docker: Test more components on the Fedora default image Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 14/28] tests/tcg/multiarch: add support for multiarch system tests Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 15/28] tests/tcg/multiarch: add hello world system test Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 16/28] editorconfig: add settings for .s/.S files Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 17/28] tests/tcg/aarch64: add system boot.S Alex Bennée
2019-05-23 20:10   ` Richard Henderson
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 18/28] tests/tcg/multiarch: move the system memory test Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 19/28] tests/tcg/minilib: support %c format char Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 20/28] tests/tcg/multiarch: expand system memory test to cover more Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 21/28] tests/tcg/alpha: add system boot.S Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 22/28] .travis.yml: enable aarch64-softmmu and alpha-softmmu tcg tests Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 23/28] Makefile: fix coverage-report reference to BUILD_DIR Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 24/28] Makefile: include per-target build directories in coverage report Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 25/28] Makefile.target: support per-target coverage reports Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 26/28] tests/qemu-iotests/group: Re-use the "auto" group for tests that can always run Alex Bennée
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 27/28] tests/qemu-iotests: re-format output to for make check-block Alex Bennée
2019-05-27 13:43   ` Max Reitz
2019-05-27 16:20     ` Alex Bennée
2019-05-27 16:53       ` Max Reitz
2019-05-23 10:25 ` [Qemu-devel] [PATCH v2 28/28] tests: Run the iotests during "make check" again Alex Bennée

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=875zq014d8.fsf@zen.linaroharston \
    --to=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.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.