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: <164706701.45822.1633008519556.JavaMail.zimbra@efficios.com>
Date:   Thu, 30 Sep 2021 09:28:39 -0400 (EDT)
From:   Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:     Florian Weimer <fweimer@...hat.com>
Cc:     Will Deacon <will@...nel.org>, paulmck <paulmck@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Segher Boessenkool <segher@...nel.crashing.org>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Alan Stern <stern@...land.harvard.edu>,
        Andrea Parri <parri.andrea@...il.com>,
        Boqun Feng <boqun.feng@...il.com>,
        Nicholas Piggin <npiggin@...il.com>,
        David Howells <dhowells@...hat.com>,
        j alglave <j.alglave@....ac.uk>,
        luc maranget <luc.maranget@...ia.fr>,
        akiyks <akiyks@...il.com>,
        linux-toolchains <linux-toolchains@...r.kernel.org>,
        linux-arch <linux-arch@...r.kernel.org>
Subject: Re: [RFC PATCH] LKMM: Add ctrl_dep() macro for control dependency

----- On Sep 29, 2021, at 8:28 AM, Florian Weimer fweimer@...hat.com wrote:

> * Mathieu Desnoyers:
> 
>> + * will ensure that the STORE to B happens after the LOAD of A. Normally a
>> + * control dependency relies on a conditional branch having a data dependency
>> + * on the LOAD and an architecture's inability to speculate STOREs. IOW, this
>> + * provides a LOAD->STORE order.
>> + *
>> + * Due to optimizing compilers, extra care is needed; as per the example above
>> + * the LOAD must be 'volatile' qualified in order to ensure the compiler
>> + * actually emits the load, such that the data-dependency to the conditional
>> + * branch can be formed.
>> + *
>> + * Secondly, the compiler must be prohibited from lifting anything out of the
>> + * selection statement, as this would obviously also break the ordering.
>> + *
>> + * Thirdly, architectures that allow the LOAD->STORE reorder must ensure
>> + * the compiler actually emits the conditional branch instruction.
> 
> If you need a specific instruction emitted, you need a compiler
> intrinsic or inline assembly.
> 
> So something like this:
> 
> #define control_dep(x)                          \
>  ({                                            \
>    __typeof(x) x__ = (x);                      \
>    __asm__("test $0, %0\n\t"                   \
>            "jnz 1f\n\t"                        \
>            "1:"                                \
>            :: "r"(x__) : "cc");                \
>  })
> 
> with an appropriate instruction sequence for each architecture.
> 
> I don't think it's possible to piggy-back this on something else.

The previous patch set from Peter Zijlstra proposed using asm goto to achieve this,
but it was turned down in part because it prevented the compiler from choosing the
most appropriate instruction for the conditional branch:

https://lore.kernel.org/lkml/YLn8dzbNwvqrqqp5@hirez.programming.kicks-ass.net/

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ