Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3023898imm; Sun, 1 Jul 2018 10:31:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLKw0dllZiumCJpo33gc6NnD2j2KBrtHkv2I/50iZFf+H0AM/VyAEBF93YGTBHHeixx3QYo X-Received: by 2002:a65:4249:: with SMTP id d9-v6mr19266450pgq.362.1530466262891; Sun, 01 Jul 2018 10:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530466262; cv=none; d=google.com; s=arc-20160816; b=sqXHmC/NMt4Aj+VMSJSY5FAAXbQlUvBIGSHG5rRO/lyOa5G33o/LSypDchgHeC0L5s tqNP3RLGmJh46t+Dq5jRMlz9FPduTazYuRLZqTdS6i2g5BAqEh93ExrqZoDQBkR1mks9 RZdk4QlY+615uL4QRZ2X+DXvDyRXDlMi2HMUzh/PDc8EFTMakzZpCmIxZPqApb99w5Uv k1Srv8IlPXMDZKyETYdJM8eKwfmr/PSA+qfIqMkMG5t5U1fRFdQaPDCqHRzNUoykwHhP hW4j1Gd8hRNgUp3RF1hChHSHd5NKtuOjp4nKKE2HrctjjnlRBSITWHEnlfSwHJAhf2en KyRA== 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=IPw1TJvxEGtXXi9p9XroT2DMdJ4plQtiF3oOdKVEgaI=; b=OTqP/IKJeL4200Lps8bM9OJVeH9pgxX2BpdGzkDC34h2gDasl6kgQ/U0reD9tqHEqs /wwKLURLlBE3FShAkM0VNf+WnSYDdlVbRfEiT0vJNmpE87Ne40FUmppZa37O6yRLKiH8 s94clWAPt0zYi9gzoZLJoPsI+SbPOJ0a5OmAeZ5OcHqjnrEgikMT19Al2w23DtR7mtf2 LYfFYzExDdDeFckxAOQwCA7CVbYMVzQrcus16crVmOC12JnO71Cq48v2pmvC0GneXX43 iByZ9SXcHD283n9j6CKj1bJNbzADNLcNP857XCtE3RQzNjr4U+UsvkhZ/FnLmYnwOcRU p7nw== 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 o6-v6si6282714pgp.631.2018.07.01.10.30.48; Sun, 01 Jul 2018 10:31:02 -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 S1031349AbeGAQgw (ORCPT + 99 others); Sun, 1 Jul 2018 12:36:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36108 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031061AbeGAQgr (ORCPT ); Sun, 1 Jul 2018 12:36:47 -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 0E630A73; Sun, 1 Jul 2018 16:36:46 +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.17 001/220] x86/spectre_v1: Disable compiler optimizations over array_index_mask_nospec() Date: Sun, 1 Jul 2018 18:20:25 +0200 Message-Id: <20180701160908.329822656@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 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.17-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) :"g"(size),"r" (index) :"cc");