Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3071809imm; Sun, 1 Jul 2018 11:35:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccHkmGBhv1xO0pBgZjFam93zZbfVZfgQUODUD7RfCkkyKWJxyiHaFaGV673r5D7XPUlDqZ X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr21715580plb.297.1530470113493; Sun, 01 Jul 2018 11:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530470113; cv=none; d=google.com; s=arc-20160816; b=Pub3hOiyB1HLYGTlPgGv6ijl+Ex0/5rTWu0aSI+X72NAfNMJ1EJW5y/w58fo+xvUYH eL6fJsBDFla5J4htdihoL+MWxtNMZs7r00gy8snF6koHb5RUgD8gXg0oiyfjzfUzwgSW 5bfDhH7DQBl19NR34UO8xAOsRajS21KOuUhwYD2OdMppSo1XI98qtUCl0WYbk5cTlOlR HPJvgXRQYWsq2tRjhydcujifce/c/MpHuQH6tlnFCndwkmAIyIuRfagt31FGGKbSn7Jf XDzsCrkLZIymQII1jgdIAE2FNfdMwxuQ2nsJjLcMLtpOorFro1j2GBHSnFh9M9Wacj4k gphQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=s6qDCVhreHyD0GeYIFTpelvSMyqnqCmUWjMNDsJ29+A=; b=bHzu39Y1QM4h7rZivqxbHrU8SYCOaBMS6fOGOgUxkia7Cd3yx+EjMuFcYtoEqB4FuT bTwUomxU+fBP90CcoO4++nu0oKJV+XUvzE3eElpCepEDz1KBfJLg1dHjiyJVz2yhwSA5 6v53n5ZX1p20eYkMmkwrnJEwBcaB2Vyl+XkxpbwIMyddH0dN+8CoF7UmBhP5Q7rIGVgx hWvbqqRpeG+/Q1d0X6TbZlkd8EIfphJccQjmy6PXQ3eHmQUL3TshNI6lnTL/f9Md0ht2 urwrmUmouznIKjIG1s9+mJ4x7xtMnSPU5r7HtNTzr+wOMtHwRfde98kUGZoT2S4JQund qD4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s184-v6si12618544pgb.161.2018.07.01.11.34.59; Sun, 01 Jul 2018 11:35:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964777AbeGASeY (ORCPT + 99 others); Sun, 1 Jul 2018 14:34:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60684 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933260AbeGAQQA (ORCPT ); Sun, 1 Jul 2018 12:16:00 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 26390ACC; Sun, 1 Jul 2018 16:16:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Dan Williams , Thomas Gleixner , Linus Torvalds , Peter Zijlstra , Ingo Molnar Subject: [PATCH 4.4 026/105] x86/spectre_v1: Disable compiler optimizations over array_index_mask_nospec() Date: Sun, 1 Jul 2018 18:01:36 +0200 Message-Id: <20180701153151.231857764@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit eab6870fee877258122a042bfd99ee7908c40280 upstream. Mark Rutland noticed that GCC optimization passes have the potential to elide necessary invocations of the array_index_mask_nospec() instruction sequence, so mark the asm() volatile. Mark explains: "The volatile will inhibit *some* cases where the compiler could lift the array_index_nospec() call out of a branch, e.g. where there are multiple invocations of array_index_nospec() with the same arguments: if (idx < foo) { idx1 = array_idx_nospec(idx, foo) do_something(idx1); } < some other code > if (idx < foo) { idx2 = array_idx_nospec(idx, foo); do_something_else(idx2); } ... since the compiler can determine that the two invocations yield the same result, and reuse the first result (likely the same register as idx was in originally) for the second branch, effectively re-writing the above as: if (idx < foo) { idx = array_idx_nospec(idx, foo); do_something(idx); } < some other code > if (idx < foo) { do_something_else(idx); } ... if we don't take the first branch, then speculatively take the second, we lose the nospec protection. There's more info on volatile asm in the GCC docs: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile " Reported-by: Mark Rutland Signed-off-by: Dan Williams Acked-by: Mark Rutland Acked-by: Thomas Gleixner Acked-by: Linus Torvalds Cc: Cc: Peter Zijlstra Fixes: babdde2698d4 ("x86: Implement array_index_mask_nospec") Link: https://lkml.kernel.org/lkml/152838798950.14521.4893346294059739135.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/barrier.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/include/asm/barrier.h +++ b/arch/x86/include/asm/barrier.h @@ -38,7 +38,7 @@ static inline unsigned long array_index_ { unsigned long mask; - asm ("cmp %1,%2; sbb %0,%0;" + asm volatile ("cmp %1,%2; sbb %0,%0;" :"=r" (mask) :"r"(size),"r" (index) :"cc");