Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp21556ybt; Tue, 30 Jun 2020 13:59:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk5x6kNXp3uYZc7hsFAWiaRb2QqHbfoQo6GYIeemYxlCZzbqEc2gvxI0YCx9EgBZ7dVme3 X-Received: by 2002:a50:e604:: with SMTP id y4mr24320457edm.373.1593550382958; Tue, 30 Jun 2020 13:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593550382; cv=none; d=google.com; s=arc-20160816; b=olbCdGhHWOW21mAp5BffIIVsgCH2eXT21hS0Ph9bq5DSulVZo1ddCuN9jPQmUEVtl0 ycSikF5uUZdpm3idrM5+yHlUPxOmQlJZalS1OUp0Iw2AW0jNI7U9imGyzuRI4/a6xQXb Mw9aW9OVNVB2WAE0qMlSDHSfX3JWt7Y1soNcbVjLy2bJoUF7wAC3kvDr254oJHKKHKHF rI4nhpHvj+k64JgKPLiFR+M8dN7LVy8H3hnwdegFBDbGH+8RV9DBJcI758yUYW9zXBWp 4rYxORr+85oW0r6FlIqiTzkO3VNc4CHXWVhTpiFBigatv7zmojnW9fjCcigbOHkv+3z6 z47A== 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=9UKxlIJOTY2zx2nzmpDV6yMhwVzomovdk4iBLHXz+to=; b=uvZdMfXxN01DCJ7gDpdu5BACxMUCISlSIrzMC2ksA9GNdc79jmjAdwxd48F9Ba8nts DGTxGjQcKt07ce1R6ZDTc5pot2UJgkSvkAuyqTeitCx8dL4hTkw4XcrHjpHYlgPpf+CT Myu3uZXMEv2Z/2zy51zGCaIXSNkCqxgotxaH3WPH5HAr1+QsxYduqIfoTHXAkiRfp+Tt gXBBFxYA4xDfSZH2qY7FOaFXbZfWtvXAupdgD0lM+D9DYRsqyShPwwkYl6cdo/nFFipV BJ3UwrMVkEn+z1/uxpCF/s+7tWSjsVNb3O183gp9nxdxWfPPOcw54cIv2Lmw4UmcU83+ qpVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=b5QTXRyr; 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 g22si2612926edr.336.2020.06.30.13.52.40; Tue, 30 Jun 2020 13:53:02 -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=b5QTXRyr; 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 S1728397AbgF3Trn (ORCPT + 99 others); Tue, 30 Jun 2020 15:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728045AbgF3Trn (ORCPT ); Tue, 30 Jun 2020 15:47:43 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA37C03E979 for ; Tue, 30 Jun 2020 12:47:43 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id w17so17796114oie.6 for ; Tue, 30 Jun 2020 12:47:43 -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=9UKxlIJOTY2zx2nzmpDV6yMhwVzomovdk4iBLHXz+to=; b=b5QTXRyrtvJIel7TqOAPE7QxmKK0A0Kk/L9Y88ohrYuISTLLPdp5HH9fUHPSEDqcTq etgp/5shPJOkJzg9Azw7IAVltGons+60NY0zqsd3wibTXJCm7bDqpHR4MPEfSKZzdKFY RaVLrZFIUpykTrxj5+s/RbG50eBIV8k/bAMIsgo/F2IPeaMwuK8gvy97eT9jx28c4BLJ n+G1HzxZvlmPyqoBCikNS2FAk3hiUfcugrxlaT9FJD/xkpXz+luMfWgNw9gAEJLh0JfU sbJELKGA/NjGmfY/jqBwt2FR3nBPIvf0eHx8gW0vJwhwxCXQXRWsrnRGHLL8vwBPP+iw v1sA== 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=9UKxlIJOTY2zx2nzmpDV6yMhwVzomovdk4iBLHXz+to=; b=kR1DjWvSttyKzL8zjzufA598W0CI0/D9uknAvlv8FAQZEr2p6Fc1GVQPlLmfJNRuF4 OkWdtnDGQsebAdfKfI1NzsPuc2zaEDF9lP/X3Oat78TZy/JQWtKHj1UN8vmbIpHKXKyO xi6TLBrv4oYc1QZp0uNYDne9jfidmOJagC36pPfGfJx7RgugaEqXBrwAxPYNla9QATsc xkPll+UXtr1A6OWAPi9k80MAUn2u5H87r9kqWyKeExmp3nYz7KPWZVFQmghy6hlSLKly oj7ORhqNAyScfhpZXer+HWvOaoeyFKEKE/oERZ+eieyM5AJIwPpvTKLCMSzW/+55142M R0ng== X-Gm-Message-State: AOAM5318a2OgobRTZf1Qa7zJKOp8AQ/36+nm5MN2aeZiQeN1w2noOBB3 Pkv0VRsOraaQH6BFaNZWSVXC7xriaDPp/pTy04E5Hg== X-Received: by 2002:a05:6808:3ab:: with SMTP id n11mr12490827oie.121.1593546462237; Tue, 30 Jun 2020 12:47:42 -0700 (PDT) MIME-Version: 1.0 References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> In-Reply-To: <20200630173734.14057-19-will@kernel.org> From: Marco Elver Date: Tue, 30 Jun 2020 21:47:30 +0200 Message-ID: Subject: Re: [PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y To: Will Deacon Cc: LKML , Sami Tolvanen , 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@lists.infradead.org, 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, 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. Thanks, -- Marco