Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp758236pxu; Thu, 15 Oct 2020 16:09:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCZ62+SXNgMznGuMdYlrk4Zflle7Ka6qQkCr45h2PbgBDpSAFOHWjF/LnPp4gExXFK8eUx X-Received: by 2002:aa7:d352:: with SMTP id m18mr800575edr.287.1602803392344; Thu, 15 Oct 2020 16:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602803392; cv=none; d=google.com; s=arc-20160816; b=Bfvw5sj0iNyHjFH67DFGuMBZktnaUeF+qx674xzH6BqKxxMzpqUTyjc068MvL5ol5g XZYKsJqr79YYahKEwDgiowiJs1NbV9p/VqPgoUvBx2/xm6dPnKmkLr06r2w07F+6mo44 xP+t5oVkhN1iWW1BwKhuzXhUdwTHu5Igd4ND4UBRZmqNKASbwu4ZWatxKRMDohRA25GL +Nhj96eljtQxmeh8Dsziykc7qTgnEHVjMITNLxPDilVXCHEF5T0XzdjcC1SG83/8vGaZ Hvj4tnNVvorj/fRbbCzmGrY/ho2BWGXJI0n8cdWmDskuzA9b7PouJqeFWpizfnwSrOOg LKjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4cJuATedXYgpSJ1YqRltFNQY8ajjuWuhu8ViNrBTmls=; b=m9HPXzHq4kTLboRV48R6761XuaMTyUAIn4LIymKfGP1Z1sy3WM/ludhietAxVIg/yC JMDvUv0pj1iSVZzll/tepiqRCBpA5n7cVRhw0YRyKW2LivCrGs0Xlr90I6g/WWJPVZq/ HBJvtSU+oKj7wLvj1cuSwUSMJuSxNclE+XW3mLcqEJgKpULl9+zGFocXb2gurmXPRjr5 xEjcQAf4ID6EoVz69c3kr1Q0V10BBoIXEgUQkb9Ro3M2WR+Chv+R/2wRR1yCF8b/T16g /gYzPwXRiV40GA2nW7GfsWHI09ytIIEGg/YDJPpZZiSfoq7FDig/Nakg0UGMG2xlqLXj YCDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si320214ejd.450.2020.10.15.16.09.15; Thu, 15 Oct 2020 16:09:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732861AbgJOSNn (ORCPT + 99 others); Thu, 15 Oct 2020 14:13:43 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:34260 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbgJOSNn (ORCPT ); Thu, 15 Oct 2020 14:13:43 -0400 Received: by mail-qk1-f196.google.com with SMTP id x20so3107469qkn.1 for ; Thu, 15 Oct 2020 11:13:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4cJuATedXYgpSJ1YqRltFNQY8ajjuWuhu8ViNrBTmls=; b=WGRQ49gmvCN+ZcGnXrjAJpp3MX6JEarYrIN98zNlhXYzgyVrcFs3z9iP9M5/ak6Rlg wuagfdzRBpXIUCJxeMuzpzbaa5yMkXNEVmVoiegyBVOlhdZT/u5P0FxrCScIwbMc/G+m gY2CHkAb51OqNCmEPtSnmScI/87Ig/2CUUG28TmXJ4+t3vUhRiH7wTs7IjriNVtwKpRD mZ6EStFCMWEuGr4b5M+XvvzUgyqiWK1JhiMc6inGLZnANwONf2tQAvumaFxNnNLW59jH mbFubqvjdyRltQTqfMuhKzD4cetu+P7RKZJgkc4AGu+BgIZvDW3RnO1c4Fd3+SooXodx 55PA== X-Gm-Message-State: AOAM5329PawQLV/AmXXUM3NZyQYYT3JyzbRye64i+OcNbAy7KGwnCqEd XkrN6YNY0GggvpEKD2624Q4= X-Received: by 2002:a37:2d06:: with SMTP id t6mr42492qkh.308.1602785621933; Thu, 15 Oct 2020 11:13:41 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id t13sm26319qtw.23.2020.10.15.11.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 11:13:41 -0700 (PDT) From: Arvind Sankar To: Nick Desaulniers Cc: Andrew Morton , Kees Cook , David Laight , Nathan Chancellor , "clang-built-linux@googlegroups.com" , linux-kernel@vger.kernel.org Subject: [PATCH] compiler.h: Clarify comment about the need for barrier_data() Date: Thu, 15 Oct 2020 14:13:40 -0400 Message-Id: <20201015181340.653004-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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