Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2971617imm; Sun, 1 Jul 2018 09:26:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwSB15Z+nJ+runamWJ/Ub1shNZv/iGWYAmnv1Ms8luvkc0wAMc/YXPxGMBpQ0/OINyEt/T X-Received: by 2002:a65:52cc:: with SMTP id z12-v6mr9649586pgp.69.1530462369486; Sun, 01 Jul 2018 09:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462369; cv=none; d=google.com; s=arc-20160816; b=Q7jvmiXBr9HvEMYYp/g8SoS+9uWW0KR103RQLsOBr6wgVCvsQPWc4eUsA8pKd58gcr qerPp/y1AlbAJRs0UV4xUlxu/GBnFQm4fOyf6BwVtU2Uv9nVGwIRrZ/5IN4Sy0xIRBvw FHyU7AdlT8vA06jpJWcqthJGdgTgAQAwvHgTxYz0fwwlEHrfmqhMADc2ZelQV34Zz/8Q fcBAtNQjEvCjkSPXZVM8w5yoJBABTu21ZaBLHcWaCtu4F9/d3IyG+Mke0Cr7YHFNgT1C mUqLbY4N+M65YkrEjCejxB7eU6DwoTBuu+OaxqiqzH8bTfOL1ic6q/pe0lwFlzM/T6Yz vh3Q== 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=4ILfl70qeT5gP2dc3Xl6HRt/YCy0dO3Ezj3jLe03Dtk=; b=a1PVfc0Nc5YKCkj3TtZzYewmYkt9WL8JsW3SNPCIbj7NnLWJ0HYo4M9aW/ia16z18k PG1FOTgLbqH90C2EYM8z9eLX2dfZ126vdl576q02LXTB9oJ3WMS80g0pKmLo6nmBbiLZ ulHPe+H9BkvnUmsgAj0yJXF7IsK6PshmxERITRa4QmgTp+2QW8MjkwFO/jQ1Qs9G8acr 64ZFkB4Z57TRfu8+gfcEUPnSegxBsBqdCv+VkBfgMTnhIQZTLOI6b9sbei+sbZVhm4od 1ctMaaH8/tzllB7gho8kmt1wcEBdFxfKxJ4kAjd9AzpVNqsEP+odCB7l5SBi3xZRLV6g FAfw== 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 n5-v6si8168271pgq.167.2018.07.01.09.25.55; Sun, 01 Jul 2018 09:26:09 -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 S1753550AbeGAQYZ (ORCPT + 99 others); Sun, 1 Jul 2018 12:24:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33426 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753392AbeGAQYS (ORCPT ); Sun, 1 Jul 2018 12:24:18 -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 B710BACD; Sun, 1 Jul 2018 16:24:17 +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.9 001/101] x86/spectre_v1: Disable compiler optimizations over array_index_mask_nospec() Date: Sun, 1 Jul 2018 18:20:47 +0200 Message-Id: <20180701160757.189774422@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -37,7 +37,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");