lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230725054414.15055-1-falcon@tinylab.org>
Date:   Tue, 25 Jul 2023 13:44:14 +0800
From:   Zhangjin Wu <falcon@...ylab.org>
To:     w@....eu
Cc:     arnd@...db.de, falcon@...ylab.org, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org, thomas@...ch.de
Subject: Re: [PATCH v1 1/8] tools/nolibc: add support for powerpc

Hi, Thomas, Willy

> On Sun, Jul 23, 2023 at 09:32:37AM +0200, Thomas Weißschuh wrote:
> > On 2023-07-19 05:10:48+0800, Zhangjin Wu wrote:
> > > diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arch-powerpc.h
> > > new file mode 100644
> > > index 000000000000..100ec0f412dc
> > > --- /dev/null
> > > +++ b/tools/include/nolibc/arch-powerpc.h
> > > @@ -0,0 +1,156 @@
> > > +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> > > +/*
> > > + * PowerPC specific definitions for NOLIBC
> > > + * Copyright (C) 2023 Zhangjin Wu <falcon@...ylab.org>
> > 
> > If it is taken from musl, shouldn't there also be a musl copyright?
> 
> In fact it depends. If code was taken there, not only the copyright is
> needed, but the license' compatibility must be verified. If, however,
> the code was only disassembled to be understood and reimplemented (as
> it seems to me), then no code was taken there and it's not needed.
>

This discussion does inspire me a lot to shrink the whole architecture
specific nolibc my_syscall<N>() macros, like crt.h, a common syscall.h
is added to do so. I have finished most of them except the ones passing
arguments via stack, still trying to merge these ones.

With this new syscall.h, to support my_syscall<N>, the arch-<ARCH>.h
will only require to add ~10 lines to define their own syscall
instructions, registers and clobberlist, which looks like this (for
powerpc):

    #define _NOLIBC_SYSCALL_CALL "sc; bns+ 1f; neg  %0, %0; 1:"

    /* PowerPC doesn't always restore r3-r12 for us */
    #define _NOLIBC_SYSCALL_CLOBBERLIST 
    	"memory", "cr0", "r12", "r11", "r10", "r9", "r8", "r7", "r6", "r5", "r4"

    /* PowerPC write GPRS in kernel side but not restore them */
    #define _NOLIBC_GPRS_AS_OUTPUT_OPERANDS
    
    #define _NOLIBC_REG_NUM  "r0"
    #define _NOLIBC_REG_RET  "r3"
    #define _NOLIBC_REG_arg1 "r3"
    #define _NOLIBC_REG_arg2 "r4"
    #define _NOLIBC_REG_arg3 "r5"
    #define _NOLIBC_REG_arg4 "r6"
    #define _NOLIBC_REG_arg5 "r7"
    #define _NOLIBC_REG_arg6 "r8"

Before:

    $ ls tools/include/nolibc/arch-*.h | while read f; do git show dfef4fc45d5713eb23d87f0863aff9c33bd4bfaf:$f 2>/dev/null | wc -l | tr -d '\n'; echo " $f"; done
    157 tools/include/nolibc/arch-aarch64.h
    199 tools/include/nolibc/arch-arm.h
    178 tools/include/nolibc/arch-i386.h
    164 tools/include/nolibc/arch-loongarch.h
    195 tools/include/nolibc/arch-mips.h
    0 tools/include/nolibc/arch-powerpc.h
    160 tools/include/nolibc/arch-riscv.h
    186 tools/include/nolibc/arch-s390.h
    176 tools/include/nolibc/arch-x86_64.h

After:

    $ wc -l tools/include/nolibc/arch-*.h
       54 tools/include/nolibc/arch-aarch64.h
       84 tools/include/nolibc/arch-arm.h
       90 tools/include/nolibc/arch-i386.h                        /* the last one use stack to pass arguments, reserve as-is */
       59 tools/include/nolibc/arch-loongarch.h
      120 tools/include/nolibc/arch-mips.h                        /* the last two use stack to pass arguments, reserve as-is */
       73 tools/include/nolibc/arch-powerpc.h
       58 tools/include/nolibc/arch-riscv.h
       87 tools/include/nolibc/arch-s390.h
       67 tools/include/nolibc/arch-x86_64.h

syscall.h itself:

    $ wc -l tools/include/nolibc/syscall.h
    112 tools/include/nolibc/syscall.h 

Willy, do we need to rename my_syscall<N> to _nolibc_syscall<N> to limit
these macros nolibc internally? I plan to rename all of the new adding
macros with _nolibc_ (for funcs) or _NOLIBC_ (for variables).

Thomas, do we need to merge the syscall macros from unistd.h to this new
syscall.h? we do reuse the macros between them, like the _syscall_narg* ones.

Since this new syscall.h does help a lot to shrink the arch-powerpc.h, I plan
to send this syscall.h at first and then renew our powerpc patchset, what's
your idea? 

Thanks,
Zhangjin

> Thanks,
> Willy

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ