qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: Philippe Mathieu-Daude <f4bug@amsat.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Laurent Vivier <laurent@vivier.eu>
Subject: Re: [RFC 4/4] common-user: Allow return codes to be adjusted after sytsem call
Date: Mon, 8 Nov 2021 11:49:42 -0700	[thread overview]
Message-ID: <CANCZdfohHLKjstby1t3vA3u=MU2qdt_FXNTSpWyUPbbyd2p5aw@mail.gmail.com> (raw)
In-Reply-To: <0511aedf-1ecd-666d-034f-55d50306e115@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 3394 bytes --]

On Mon, Nov 8, 2021 at 8:10 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 11/8/21 3:37 AM, Warner Losh wrote:
> > All the *-users generally use the Linux style of negative return codes
> > for errno. However, other systems, like FreeBSD, have a different
> > convention. Allow those systems to insert code after the syscall that
> > adjusts the return value of the system call to match the native linux
> > format.
> >
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   common-user/host/aarch64/safe-syscall.inc.S | 1 +
> >   common-user/host/arm/safe-syscall.inc.S     | 1 +
> >   common-user/host/i386/safe-syscall.inc.S    | 1 +
> >   common-user/host/ppc64/safe-syscall.inc.S   | 1 +
> >   common-user/host/riscv/safe-syscall.inc.S   | 1 +
> >   common-user/host/s390x/safe-syscall.inc.S   | 1 +
> >   common-user/host/x86_64/safe-syscall.inc.S  | 1 +
> >   linux-user/safe-syscall.S                   | 1 +
> >   8 files changed, 8 insertions(+)
> >
> > diff --git a/common-user/host/aarch64/safe-syscall.inc.S
> b/common-user/host/aarch64/safe-syscall.inc.S
> > index bc1f5a9792..81d83e8e79 100644
> > --- a/common-user/host/aarch64/safe-syscall.inc.S
> > +++ b/common-user/host/aarch64/safe-syscall.inc.S
> > @@ -64,6 +64,7 @@ safe_syscall_start:
> >       svc     0x0
> >   safe_syscall_end:
> >       /* code path for having successfully executed the syscall */
> > +     ADJUST_SYSCALL_RETCODE
> >       ret
> >
> >   0:
>
> Not sure about this, really.  Is it really that much cleaner to insert
> this than create
> separate 10-line files, with the adjustment included?
>

While the meat of these files is only around 10 lines, the files themselves
are more like 70 lines with a lot of extra marking to ensure proper
integration with toolchains. Such lines have a tendency, over time, to need
adjusting as new toolchains change the requirements slightly (clang
certainly has forced that in a number of places in FreeBSD's code base, and
every new version seems to require something). The adjustments have all
been 3 lines (gmail seems to hate my formatting):

+#define        ADJUST_SYSCALL_RETCODE \
+    jnb 2f;                    \
+    neg %rax;                  \
+    2:

which is significantly easier to maintain than having to monitor these
files for changes and copying over the changes that happen. Plus, as I'm
upstreaming the arch support, it's one more file I have to include in the
review, it's one more file that may get questions and advice I'll have to
answer with 'it's a verbatim copy of the linux version with these three
lines added, why do I need to make those stylistic changes'. All of which
takes extra time. The upstreaming is going much more slowly than I'd
anticipated (but on the up-side also finding more problems than I thought
were latent in the system), and we're still at about 30k lines (after
starting at about 36k lines, though some of that is due to deleting mips).
It's been running about a month per 1000 lines to get reviewed and
upstreamed. There's about 626 lines in these 6 files, so sharing them
seemed like it would save me a few weeks of upstreaming time as well
(though I'll be the first to admit that translating LoC metrics to time has
a dubious history).

The other alternative I considered was having a #ifdef __FreeBSD__ ..
#endif in all those files, but I thought that even more intrusive.

Warner

[-- Attachment #2: Type: text/html, Size: 4225 bytes --]

  reply	other threads:[~2021-11-08 18:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08  2:37 [RFC 0/4] linux-user: simplify safe signal handling Warner Losh
2021-11-08  2:37 ` [RFC 1/4] linux-user: Add host_signal_set_pc to set pc in mcontext Warner Losh
2021-11-08 15:03   ` Richard Henderson
2021-11-10 15:43   ` Philippe Mathieu-Daudé
2021-11-08  2:37 ` [RFC 2/4] linux-user/signal.c: Create a common rewind_if_in_safe_syscall Warner Losh
2021-11-08 15:07   ` Richard Henderson
2021-11-08 16:39     ` Warner Losh
2021-11-10 16:20       ` Warner Losh
2021-11-10 16:31         ` Richard Henderson
2021-11-10 15:44   ` Philippe Mathieu-Daudé
2021-11-08  2:37 ` [RFC 3/4] linux-user/safe-syscall.inc.S: Move to common-user Warner Losh
2021-11-08  2:37 ` [RFC 4/4] common-user: Allow return codes to be adjusted after sytsem call Warner Losh
2021-11-08 15:10   ` Richard Henderson
2021-11-08 18:49     ` Warner Losh [this message]
2021-11-09  8:11       ` Richard Henderson
2021-11-10  2:10         ` Warner Losh

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='CANCZdfohHLKjstby1t3vA3u=MU2qdt_FXNTSpWyUPbbyd2p5aw@mail.gmail.com' \
    --to=imp@bsdimp.com \
    --cc=f4bug@amsat.org \
    --cc=laurent@vivier.eu \
    --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).