From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2AB9C43603 for ; Fri, 13 Dec 2019 21:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D9D724671 for ; Fri, 13 Dec 2019 21:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="k23J/zLd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726916AbfLMVGz (ORCPT ); Fri, 13 Dec 2019 16:06:55 -0500 Received: from ozlabs.org ([203.11.71.1]:53267 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725937AbfLMVGz (ORCPT ); Fri, 13 Dec 2019 16:06:55 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 47ZNWw2BJjz9sP6; Sat, 14 Dec 2019 08:06:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1576271213; bh=MGInI7+F0s7HGbUV0Xqx0TPozxlo/Am/To6UDohXxq4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=k23J/zLdvtKqBunmy1ixSs+42bGbHDuGSQCB6Ke7L4Uq+z+ldveUzevFgLwdpKq0d mkr6DDnR7H0smvCQcN+BM6T37JbnmqHD4/L9a/NkSKrjRcYPT2yHYyhdPyiEXPyrMB Efjh7qR7zHjSZA5mgVn0XUYlFLdEhavQXa026DnFJi45/5Ez7taLlBYjyOaBMxyE/b 7GJ80E1SaCmTKU2aBFLDMNx1yGZX4v2RQz2d9xbDgYEA2gziROONKrvnz6W/pFOCgL jX4iWoccqf6+gYa3ICv0po4aLuXfa8qENKOix+W7EG9numuE+zbXEzjMmrCD9q6b2x GpuH9UJg8ssSA== From: Michael Ellerman To: Segher Boessenkool Cc: Peter Zijlstra , Will Deacon , Linus Torvalds , dja@axtens.net, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, christophe.leroy@c-s.fr, linux-arch@vger.kernel.org, Mark Rutland , Arnd Bergmann , Christian Borntraeger Subject: Re: READ_ONCE() + STACKPROTECTOR_STRONG == :/ (was Re: [GIT PULL] Please pull powerpc/linux.git powerpc-5.5-2 tag (topic/kasan-bitops)) In-Reply-To: <20191213135353.GN3152@gate.crashing.org> References: <87blslei5o.fsf@mpe.ellerman.id.au> <20191206131650.GM2827@hirez.programming.kicks-ass.net> <875zimp0ay.fsf@mpe.ellerman.id.au> <20191212080105.GV2844@hirez.programming.kicks-ass.net> <20191212100756.GA11317@willie-the-truck> <20191212104610.GW2827@hirez.programming.kicks-ass.net> <87pngso2ck.fsf@mpe.ellerman.id.au> <20191213135353.GN3152@gate.crashing.org> Date: Sat, 14 Dec 2019 08:06:49 +1100 Message-ID: <87mubwndee.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Segher Boessenkool writes: > Hi! > > On Fri, Dec 13, 2019 at 11:07:55PM +1100, Michael Ellerman wrote: >> I tried this: >> >> > @@ -295,6 +296,23 @@ void __write_once_size(volatile void *p, void *res, int size) >> > */ >> > #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) >> > >> > +#else /* GCC_VERSION < 40800 */ >> > + >> > +#define READ_ONCE_NOCHECK(x) \ >> > +({ \ >> > + typeof(x) __x = *(volatile typeof(x))&(x); \ >> >> Didn't compile, needed: >> >> typeof(x) __x = *(volatile typeof(&x))&(x); \ >> >> >> > + smp_read_barrier_depends(); \ >> > + __x; >> > +}) >> >> >> And that works for me. No extra stack check stuff. >> >> I guess the question is does that version of READ_ONCE() implement the >> read once semantics. Do we have a good way to test that? >> >> The only differences are because of the early return in the generic >> test_and_set_bit_lock(): > > No, there is another difference: > >> 30 ld r10,560(r9) >> 31 std r10,104(r1) >> 32 ld r10,104(r1) >> 33 andi. r10,r10,1 >> 34 bne 29 bne > > The stack var is volatile, so it is read back immediately after writing > it, here. This is a bad idea for performance, in general. Argh, yuck. Thanks, I shouldn't try to read asm listings at 11pm. So that just confirms what Will was saying further up the thread about the volatile pointer, rather than READ_ONCE() per se. cheers