linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Christoph Hellwig <hch@lst.de>,
	Russell King <rmk@arm.linux.org.uk>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	"linux-kernel@vger.kernel.org" <kernel@vger.kernel.org>,
	linux-arch <linux-arch@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Russell King <linux@armlinux.org.uk>,
	Oleg Nesterov <oleg@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/9] ARM: syscall: always store thread_info->syscall
Date: Mon, 28 Sep 2020 14:42:43 +0200	[thread overview]
Message-ID: <CAK8P3a0BZ-zdk+RB5ODcVs2z-Y6xmLCp57uzivUGWRcoeH2fQQ@mail.gmail.com> (raw)
In-Reply-To: <CACRpkdYkL2=gkBvbHO514rnppLdHgsXwi0==6Ovq43kSZqEvUQ@mail.gmail.com>

On Mon, Sep 28, 2020 at 11:41 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> Hi Arnd,
>
> help me out here because I feel vaguely stupid...
>
> On Mon, Sep 7, 2020 at 5:38 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> >  {
> > +       if (IS_ENABLED(CONFIG_OABI_COMPAT))
> > +               return task_thread_info(task)->syscall & ~__NR_OABI_SYSCALL_BASE;
>
> Where __NR_OABI_SYSCALL_BASE is
> #define __NR_OABI_SYSCALL_BASE       0x900000
>
> So you will end up with sycall number & FF6FFFFF
> masking off bits 20 and 23.

Right. I fixed a bug in here since I sent this, the correct version also
needs to mask away the __NR_OABI_SYSCALL_BASE for a native
oabi kernel, not just for an eabi kernel with oabi-compat mode.

> I suppose this is based on this:
>
> >         bics    r10, r10, #0xff000000
> > +       str     r10, [tsk, #TI_SYSCALL]
>
> OK we mask off bits 24-31 before we store this.
>
> >         bic     scno, scno, #0xff000000         @ mask off SWI op-code
> > +       str     scno, [tsk, #TI_SYSCALL]
>
> And here too.
>
> >         eor     scno, scno, #__NR_SYSCALL_BASE  @ check OS number
>
> And then happens that which will ... I don't know really.
> Exclusive or with 0x9000000 is not immediately intuitive
> evident to me, I suppose it is for everyone else... :/

This is how the SWI/SVC immediate argument gets turned into
a system call number that is used as an offset into the sys_call_table.

OABI syscalls are called with '__NR_OABI_SYSCALL_BASE | scno'
in the immediate argument of the instruction, so using an
'eor ... , #__NR_SYSCALL_BASE' means that any valid
argument afterwards is a number between zero and
__NR_syscalls, and any invalid argument is a number outside
of that range

EABI syscalls are just 'SVC 0' with the syscall number in register 7
and no offset.

See also
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3f2829a31573e3e502b874c8d69a765f7a778793

> I need some idea how this numberspace is managed in order to
> understand the code so I can review it, I guess it all makes perfect
> sense but I need some background here.

I also had never understood this part before, and I'm still not
sure where the 0x900000 actually comes from, though my best
guess is that this was intended as a an OS specific number space,
with '9' being assigned to Linux (similar to the way Itanium and
MIPS do with their respective offsets). By the time EABI got added,
this was apparently no longer considered helpful.

        Arnd

  reply	other threads:[~2020-09-28 12:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07 15:36 [PATCH 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann
2020-09-07 15:36 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-09-08  6:11   ` Christoph Hellwig
2020-09-27  9:25   ` Linus Walleij
2020-09-07 15:36 ` [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Arnd Bergmann
2020-09-08  6:15   ` Christoph Hellwig
2020-09-17 17:29     ` Arnd Bergmann
2020-09-18  7:42       ` Russell King - ARM Linux admin
2020-09-18 12:36         ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 3/9] ARM: oabi-compat: add epoll_pwait handler Arnd Bergmann
2020-09-08  6:16   ` Christoph Hellwig
2020-09-07 15:36 ` [PATCH 4/9] ARM: syscall: always store thread_info->syscall Arnd Bergmann
2020-09-28  9:41   ` Linus Walleij
2020-09-28 12:42     ` Arnd Bergmann [this message]
2020-09-28 15:08       ` Russell King - ARM Linux admin
2020-09-07 15:36 ` [PATCH 5/9] ARM: oabi-compat: rework epoll_wait/epoll_pwait emulation Arnd Bergmann
2020-09-08  6:20   ` Christoph Hellwig
2020-09-08 20:56     ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 6/9] ARM: oabi-compat: rework sys_semtimedop emulation Arnd Bergmann
2020-09-07 15:36 ` [PATCH 7/9] ARM: oabi-compat: rework fcntl64() emulation Arnd Bergmann
2020-09-07 15:36 ` [PATCH 8/9] ARM: uaccess: add __{get,put}_kernel_nofault Arnd Bergmann
2020-09-07 15:36 ` [PATCH 9/9] ARM: uaccess: remove set_fs() implementation Arnd Bergmann
2020-10-30 15:45 [PATCH v4 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann
2020-10-30 15:49 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-10-30 15:49   ` [PATCH 4/9] ARM: syscall: always store thread_info->syscall Arnd Bergmann
2020-10-30 16:53     ` Russell King - ARM Linux admin
2020-10-30 21:28       ` Arnd Bergmann

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=CAK8P3a0BZ-zdk+RB5ODcVs2z-Y6xmLCp57uzivUGWRcoeH2fQQ@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=hch@lst.de \
    --cc=kernel@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=oleg@redhat.com \
    --cc=rmk@arm.linux.org.uk \
    --cc=viro@zeniv.linux.org.uk \
    /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).