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] [day] [month] [year] [list]
Message-ID: <CAAhV-H5e=fOuAngxkUpuosveCOEUcY03Our2=H-fGPCO6L51Ag@mail.gmail.com>
Date: Fri, 6 Sep 2024 14:25:46 +0800
From: Huacai Chen <chenhuacai@...nel.org>
To: Uros Bizjak <ubizjak@...il.com>
Cc: Xi Ruoyao <xry111@...111.site>, loongarch@...ts.linux.dev, 
	linux-kernel@...r.kernel.org, WANG Xuerui <kernel@...0n.name>, 
	Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH v3] LoongArch/percpu: Simplify _percpu_read() and _percpu_write()

On Thu, Sep 5, 2024 at 11:09 PM Uros Bizjak <ubizjak@...il.com> wrote:
>
> On Thu, Sep 5, 2024 at 5:04 PM Huacai Chen <chenhuacai@...nel.org> wrote:
> >
> > On Thu, Sep 5, 2024 at 8:46 PM Uros Bizjak <ubizjak@...il.com> wrote:
> > >
> > > On Thu, Sep 5, 2024 at 2:16 PM Uros Bizjak <ubizjak@...il.com> wrote:
> > > >
> > > > On Thu, Sep 5, 2024 at 2:09 PM Xi Ruoyao <xry111@...111.site> wrote:
> > > > >
> > > > > On Thu, 2024-09-05 at 14:02 +0200, Uros Bizjak wrote:
> > > > > > > If the input value is less than 0xff, then "& 0xff" is meaningless, if
> > > > > > > the input value is more than 0xff, this conversion still cannot give a
> > > > > > > correct result for the caller. So I think for all sizes it is enough
> > > > > > > to just use "((unsigned long) val)".
> > > > > >
> > > > > > This part is used to force unsigned extension, otherwise the compiler
> > > > > > will use sign-extension of the possibly signed variable.
> > > > >
> > > > > It's not relevant.  For example when size is 2 __pcpu_op_##size("stx")
> > > > > is expanded to stx.h, and stx.h only stores the lower 16 bits of a
> > > > > register into MEM[r21 + ptr], the high bits are ignored anyway.
> > > > >
> > > > > Thus we can just have
> > > > >
> > > > > +#define _percpu_write(size, _pcp, _val)                                        \
> > > > > +do {                                                                   \
> > > > > +       if (0) {                                                        \
> > > > > +               typeof(_pcp) pto_tmp__;                                 \
> > > > > +               pto_tmp__ = (_val);                                     \
> > > > > +               (void)pto_tmp__;                                        \
> > > > > +       }                                                               \
> > > > > +       __asm__ __volatile__(                                           \
> > > > > +               __pcpu_op_##size("stx") "%[val], $r21, %[ptr]   \n"     \
> > > > > +               :                                                       \
> > > > > +               : [val] "r"(_val), [ptr] "r"(&(_pcp))           \
> > > > > +               : "memory");                                            \
> > > > > +} while (0)
> > > >
> > > > Nice, the less code, the better. If it works for loongson target, then
> > > > we don't need this paranoia.
> > > >
> > > > I just played safe and took the approach that x86 took.
> > >
> > > Please note that the original code extended the value to a long type.
> > > If the simplified macro works, then the usage of macros will result in
> > > a better assembly code, where zero-extends will be omitted.
> > OK, please send a simplified V4, remember to remove the if(0)
> > checking, which is the same as V2, thanks.
>
> Are you sure we want to remove type checking on _val ? I'd rather
> leave the if(0) part, but remove forcing zero-extension.
Yes, please, the checking is not very useful.

Huacai

>
> Uros.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ