Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp759547pxu; Thu, 15 Oct 2020 16:12:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeXGmedbQt8ehBqvFdCCdmTxH3suwVZLyCpkwetfJsGT7qd4jvAxcsCt93d/7BNdKafilQ X-Received: by 2002:a50:cdd1:: with SMTP id h17mr898435edj.94.1602803529947; Thu, 15 Oct 2020 16:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602803529; cv=none; d=google.com; s=arc-20160816; b=rg4o6O16Ngkcx/scdmoDS0Cn+gCL54HE6ni3N98cT3gZZW2E3nc7iibRjsDsACpVgR kV6gp9TkrdGc1Y47b/bgPgxi6OVZCmyxgoSTDoKp94UGe+WEheW2WAZmdDAN7wYkuPlD iPlKfnrqg2e+MW42MOTet6rZjr/pXTZM5git3fSFrBvsIYjTg3rpETjYd4DZSr6TcOqk jP3xxEcHkckCWRGnaMB5kFpPsKdNkLSNd+R8ruaMZ3GZiJIMF9SnE+G6V7zNX2GGF9Wx /EHsmVkysin5qAVsevG/AEppREOYnTij9/q8vQMDXf4r6tM0FnR9vZb4hX6I9a1Fm4UZ jnmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/RIqn6irkqKDAEEWrlzQtXEDsj4m2zjqp4+RABIoG1Y=; b=Zo8UMIX+z18QRcXLxXT1CS8nZdipNcbBtEljwjFMp5oycRQiXICxDINr28OJFV/8c5 dBpFVqvEQd2vY69vlmKVUUol2+Hq/jvXTP9fzYKoR+E0bKDsxDW2hxkDGCR+kLmuGt2K e4tytvI3309UUsgyDAvMTQewLDQ9U4Z3tJfjvFNxe+Rfry2+qnlciPLJtK3Q65LU037p 5U0FlMsfw+V5aoKDSgXYg5f881bQ02a57oUrA7ptASRcSysUgd0iGcjfMCil2q2OtMMh qQRgmnFzPkkvK3byzoyTYfSiw/tAr5fKYon9qZ9ROpUCXfH7s7gBlVJzkV/wkCKIWWE7 dFXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q7Gy3AiI; 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 l12si299564edk.163.2020.10.15.16.11.47; Thu, 15 Oct 2020 16:12:09 -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=q7Gy3AiI; 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 S1726459AbgJOSZS (ORCPT + 99 others); Thu, 15 Oct 2020 14:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbgJOSZS (ORCPT ); Thu, 15 Oct 2020 14:25:18 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DED3FC061755 for ; Thu, 15 Oct 2020 11:25:17 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id j18so2546209pfa.0 for ; Thu, 15 Oct 2020 11:25:17 -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=/RIqn6irkqKDAEEWrlzQtXEDsj4m2zjqp4+RABIoG1Y=; b=q7Gy3AiIP8tpjKySqh2jkBTHCO4bBXRCAl2e9B9yP9ygmxLfu3woG5/3GWx4pczdez evqKQrknYNpvGxM3i0bRqZfAk8vxH1/sAOindvOXUvRPbBO+W387Q3w2ExfW6N4RoWCR ahSM78Q0k22aC9DFV3rF2rCRCr+BvC5h3k8thewJfGY/CBwuJd2OT8CeVIKptRHHjRmP o3i2xs4vCz/scFBi8keH3Q9GZWhSPAqwKFcG98CIzN4CnxEwy1pXRzeUel5QAkxgEbLT 2ZbWFRVZBfacKfgtK0Z5S4Td2tD9lZIRHeiZYEa3hdNqR6/iUigESA/V/WGeCOmUKhN9 td9Q== 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=/RIqn6irkqKDAEEWrlzQtXEDsj4m2zjqp4+RABIoG1Y=; b=Cx4wSnjqwzeLFmpKKAEG5Ofl4C+lYDukdO/u3jNH27+sKK93L1kWEBdRNHuqpn7aXx o65IzPm7wXuRRA4ooTOMlk907VDREbUi7LmqC5njZw1NJ3b5pxDWxIeBDxzmGTgbeo3s 8ZKIGEo8Vrdna5PoegIdRFRJ1/Leq1pknN7J5fOSXNUfisqtjI1eteTH7yhRNfN1p9Nr CcovwhgUjgMbNMhCBABiZk6MVVfSIAYdhzCuFBMhH09g+JIha5LrdALIooJzSHCkYASL hwft+lekewMQlF4vcNDetsOfn3fvsiBLACMeocpiVUf+6r2CY2K+29WAf/rsUEAGgVJl mZRw== X-Gm-Message-State: AOAM532Wd2IN30gfNqBg43QvYBCxLcClwOl40aZJxLGO/IbKKkApP2Ck CxXzOSjK+32ee9mIdtiip0JRn0by0sTsTSzYp2xnGA== X-Received: by 2002:a65:6858:: with SMTP id q24mr143307pgt.10.1602786316973; Thu, 15 Oct 2020 11:25:16 -0700 (PDT) MIME-Version: 1.0 References: <20201015181340.653004-1-nivedita@alum.mit.edu> In-Reply-To: <20201015181340.653004-1-nivedita@alum.mit.edu> From: Nick Desaulniers Date: Thu, 15 Oct 2020 11:25:05 -0700 Message-ID: Subject: Re: [PATCH] compiler.h: Clarify comment about the need for barrier_data() To: Arvind Sankar Cc: Andrew Morton , Kees Cook , David Laight , Nathan Chancellor , "clang-built-linux@googlegroups.com" , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 11:13 AM Arvind Sankar wrote: > > Be clear about @ptr vs the variable that @ptr points to, and add some > more details as to why the special barrier_data() macro is required. > > Signed-off-by: Arvind Sankar Thanks for this distinct cleanup. Acked-by: Nick Desaulniers > --- > include/linux/compiler.h | 33 ++++++++++++++++++++++----------- > 1 file changed, 22 insertions(+), 11 deletions(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 93035d7fee0d..d8cee7c8968d 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -86,17 +86,28 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > > #ifndef barrier_data > /* > - * This version is i.e. to prevent dead stores elimination on @ptr > - * where gcc and llvm may behave differently when otherwise using > - * normal barrier(): while gcc behavior gets along with a normal > - * barrier(), llvm needs an explicit input variable to be assumed > - * clobbered. The issue is as follows: while the inline asm might > - * access any memory it wants, the compiler could have fit all of > - * @ptr into memory registers instead, and since @ptr never escaped > - * from that, it proved that the inline asm wasn't touching any of > - * it. This version works well with both compilers, i.e. we're telling > - * the compiler that the inline asm absolutely may see the contents > - * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495 > + * This version is to prevent dead stores elimination on @ptr where gcc and > + * llvm may behave differently when otherwise using normal barrier(): while gcc > + * behavior gets along with a normal barrier(), llvm needs an explicit input > + * variable to be assumed clobbered. > + * > + * Its primary use is in implementing memzero_explicit(), which is used for > + * clearing temporary data that may contain secrets. > + * > + * The issue is as follows: while the inline asm might access any memory it > + * wants, the compiler could have fit all of the variable that @ptr points to > + * into registers instead, and if @ptr never escaped from the function, it > + * proved that the inline asm wasn't touching any of it. gcc only eliminates > + * dead stores if the variable was actually allocated in registers, but llvm > + * reasons that the variable _could_ have been in registers, so the inline asm > + * can't reliably access it anyway, and eliminates dead stores even if the > + * variable is actually in memory. > + * > + * This version works well with both compilers, i.e. we're telling the compiler > + * that the inline asm absolutely may see the contents of the variable pointed > + * to by @ptr. > + * > + * See also: https://llvm.org/bugs/show_bug.cgi?id=15495#c5 > */ > # define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") > #endif > -- > 2.26.2 > -- Thanks, ~Nick Desaulniers