Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp112311ybt; Tue, 30 Jun 2020 15:59:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybZtLevdpXIxkQsZN/i3GZOpjWYKHlXfc8kisVqHg4ptBNeqygOy240G7c30jw4cEkn3FI X-Received: by 2002:a17:906:76d7:: with SMTP id q23mr19580668ejn.95.1593557962113; Tue, 30 Jun 2020 15:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593557962; cv=none; d=google.com; s=arc-20160816; b=JKgq+umJOKCUzrv4O3775/9lxjkfh7dByOrk9m9hsvEd3/r4f98AmsKzi985/+UEYZ AMtdD1V7pZopLBhwTq30vL0OUqzrzjya1F9fgOHmBUlMnel0yl5YqY79dO0XmS2LmItT GKbBJuHG6NKvw0YgVSvklgfI4oSM2GSer2V9e4mRaF2c8SqKANyPi4e8bWI9NZMeE/Wc 37NXHYEPQWHMtAzwBvYAc4MdHwmj96BbjIWz2hk0dm9hhHIGvPlhNeSoOIhFu6b3c9md o8rYaCBBcBvB6d0xAUx3st2oDg3mbEkyq+4btz/9O7QAThH0znJj9QBH+lVQsaF9pzi8 ftrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DSyr2ChJftwUjYWgZAXvEatbLcj++yS0JpUL3ndj5DU=; b=BySZNKSuaH0eq8sAkFvHx3X8uTG7SZNBVLgC2AwIyUUjOjSkhrChI4Uy5z6N2yuudb 4meVyGKsyCQGa+8UyAimu7f1WOlgumz5L88rLqGz/VdkAoO6ngf4KdCI6ER8aoery7C4 khO2oElCCT23sfNtcprbGptvRgjC6p677nhLTanzHZkdHU8OBc9myAnhfqhiGWor8NNP NRsGuiG9TIdJ8kNsRrtMSN4ugz0+SIBhL/9zvtJB+Tw/AQWNkA/keAzqisfTXmeNGN/b HYjaMgDNq6aXF+cmZWvmfcHoj/BHduNkS4iX+YSWKulpnGRp14+4dHNymsjGnNpDECH/ mSJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pWOYL6Mj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw24si2621360edb.177.2020.06.30.15.58.58; Tue, 30 Jun 2020 15:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pWOYL6Mj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbgF3W6J (ORCPT + 99 others); Tue, 30 Jun 2020 18:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726311AbgF3W6H (ORCPT ); Tue, 30 Jun 2020 18:58:07 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4590EC03E979 for ; Tue, 30 Jun 2020 15:58:07 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id dr13so22396000ejc.3 for ; Tue, 30 Jun 2020 15:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DSyr2ChJftwUjYWgZAXvEatbLcj++yS0JpUL3ndj5DU=; b=pWOYL6MjvPFUe7s+sL3ssAVAE3rJ+0I0MBPbDe/8jAsZ2gDipFCWXaJL200o2afH7G au84QSD0EygQdxbIL9VONLF7MbwZwZaFgu6ZkN21qA4RUY3BnRHodQWC7SIrlTbfNfsV HqDH+IR53dpqnNGYDlmyPKrIwiyg3NQAdJctr9t/wDs2ZMYxSZNZDkeNMq7bKzV9SpMk HmaA29N/8jKpjSnzb35OalgVh+uYKvGgzAYUzHDKm6krOCVQRSoTuGK2M+tJrvWZs/pu qaTkSYV7fYgWGgp6rSLHtNlJ8K1K+t8poHIRIQpL8gm2b9cRsfpBo+50hsIuWYEIBSKB Y/Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DSyr2ChJftwUjYWgZAXvEatbLcj++yS0JpUL3ndj5DU=; b=LVqv4iTH5YGMoCMWMrmovEYmW87oLTiweqY+GlCHd2RffzoGCkzp0gMxhox7mvY3Ri 1f+yCWJB0hG9heUclqJwnWNU7/N8vZOqEq/dVNtZcW4IRXbY71ym5OoJ+JmESJkR00eD C5/DgEfnrlnNa5Zl1si7Cknq60+cNHIV3Y3KdM/xtfF8WIJVtODJmf9uDookMEPMND2T 0lG30asRMR8tHVK5HGvQU0Jy+XeasvZbrE22jI5TjKp1e0+xKjrMBfDAknXPw3h/4WL2 MvZ9CqpInk+StSV1Iu8bnGv2/Q7TVmrPn/hbQOEMO+8/JwvE+0LGSc76fFOCsTVuR/iD q/gQ== X-Gm-Message-State: AOAM531Bb8+d4FtVk2y+un7esAjjIwfKewyxYueCPIbBCYgg9rgrVnoH fj+izx6DZEDspSH42QIhzTclMN+Dm6dwBBfXVoi5CA== X-Received: by 2002:a17:906:eb93:: with SMTP id mh19mr19706035ejb.552.1593557885578; Tue, 30 Jun 2020 15:58:05 -0700 (PDT) MIME-Version: 1.0 References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> In-Reply-To: From: Sami Tolvanen Date: Tue, 30 Jun 2020 15:57:54 -0700 Message-ID: Subject: Re: [PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y To: Marco Elver Cc: Will Deacon , LKML , Nick Desaulniers , Kees Cook , "Paul E. McKenney" , Josh Triplett , Matt Turner , Ivan Kokshaysky , Richard Henderson , Peter Zijlstra , Alan Stern , "Michael S. Tsirkin" , Jason Wang , Arnd Bergmann , Boqun Feng , Catalin Marinas , Mark Rutland , linux-arm-kernel , linux-alpha@vger.kernel.org, virtualization@lists.linux-foundation.org, Android Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 30, 2020 at 12:47 PM Marco Elver wrote: > > On Tue, 30 Jun 2020 at 19:39, Will Deacon wrote: > > > > When building with LTO, there is an increased risk of the compiler > > converting an address dependency headed by a READ_ONCE() invocation > > into a control dependency and consequently allowing for harmful > > reordering by the CPU. > > > > Ensure that such transformations are harmless by overriding the generic > > READ_ONCE() definition with one that provides acquire semantics when > > building with LTO. > > > > Signed-off-by: Will Deacon > > --- > > arch/arm64/include/asm/rwonce.h | 63 +++++++++++++++++++++++++++++++ > > arch/arm64/kernel/vdso/Makefile | 2 +- > > arch/arm64/kernel/vdso32/Makefile | 2 +- > > 3 files changed, 65 insertions(+), 2 deletions(-) > > create mode 100644 arch/arm64/include/asm/rwonce.h > > This seems reasonable, given we can't realistically tell the compiler > about dependent loads. What (if any), is the performance impact? I > guess this also heavily depends on the actual silicon. > > I do wonder, though, if there is some way to make the compiler do > something better for us. Clearly, implementing real > memory_order_consume hasn't worked out until today. But maybe the > compiler could promote dependent loads to acquires if it recognizes it > lost dependencies during optimizations. Just thinking out loud, it > probably still has some weird corner case that will break. ;-) > > The other thing is that I'd be cautious blaming LTO, as I tried to > summarize here: > https://lore.kernel.org/kernel-hardening/20200630191931.GA884155@elver.google.com/ > > The main thing is that, yes, this might be something to be worried > about, but if we are worried about it, we need to be worried about it > in *all* builds (LTO or not). My guess is that's not acceptable. Would > it be better to just guard the promotion of READ_ONCE() to acquire > behind a config option like CONFIG_ACQUIRE_READ_DEPENDENCIES, and then > make LTO select that (or maybe leave it optional?). In future, for > very aggressive non-LTO compilers even, one may then also select that > if there is substantiated worry things do actually break. I agree, a separate config option would be better here. Also Will, the LTO patches use CONFIG_LTO_CLANG instead of CLANG_LTO. Sami