Received: by 10.192.165.156 with SMTP id m28csp251526imm; Tue, 17 Apr 2018 09:31:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+eQGYj3BH+JeZ+lVMk9e+dxIK8162Jp3t2MyT4eNvFkMdkUn+3gdoCNR2XXOTP8iwLWOZx X-Received: by 2002:a17:902:6113:: with SMTP id t19-v6mr2649671plj.372.1523982718716; Tue, 17 Apr 2018 09:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523982718; cv=none; d=google.com; s=arc-20160816; b=ReWaLEV66dRsbwEMQcOnUVgnM9WBmif+4iSQBokogEgc9+TUXTVCuCQCVGD1spvC5B BVUTA4or1ZVqt+iV31it0Zp3gYLDLDb1B+Q+uPOULp5u0OxZtwlRujcp7vYv6dTFIidl OhFhFdZJ6uYOmTfqRpBv/xtQsLsxTHZ6WbV49TiGgBmlXw6j9TdY/fMp5AMPnzEp17dj LYaK+kds35aKdAh5V6GscUkhRR+uA1P39PVwyclLTOp/RLZO6tTXrwrkdf+8wEvZ2aG4 UgOQehD10U/zMkIzCouKDGXx3y2xfSJDUQhB9JEohNaHeCFOgQSV/Mg8uRcVJkqEYn6z YFcg== 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=MC4vd2Zb6FgIfLvCgpjSCfeSSnk/At+Rb5zcOG+WLkY=; b=job68UDoWHWdBWJOm9StsnS8Etun+ZWlz+OpKtPnDDcHkbdL2P9YxByrW8pwixjMGb TYVFckzzt7FdXAFVF4yOo3gi8ApNa50h96HX/yjfi2rtle56O6dfizjHbgodGwFLpy8C IAdKshfCSGCBhOdtNEAtzcEoF+lR/L7TFMA/bGNRRSG1IC0pu/Ok4Yt48ca8ldZlrvzi q+2pRTdYP8gnXa+plFDu91DH9UfUZjPcFruaPq21aylhClyeFu+72z4QiN4CVlwQVkoY kFQI1e4NayrhVsWCEzo7t7kRj3xJ9KgOtOvAYlMVTwm7h4boeZZeqMsZuTPlzohXLYkb Qfwg== 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 y9si11954119pgr.180.2018.04.17.09.31.43; Tue, 17 Apr 2018 09:31:58 -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 S1755408AbeDQQIU (ORCPT + 99 others); Tue, 17 Apr 2018 12:08:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35424 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754462AbeDQQIJ (ORCPT ); Tue, 17 Apr 2018 12:08:09 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 883D3EFD; Tue, 17 Apr 2018 16:08:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Mark Rutland , Robin Murphy , Will Deacon , Catalin Marinas , Greg Hackmann Subject: [PATCH 4.9 11/66] arm64: Implement array_index_mask_nospec() Date: Tue, 17 Apr 2018 17:58:44 +0200 Message-Id: <20180417155646.325304070@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155645.868055442@linuxfoundation.org> References: <20180417155645.868055442@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Rutland From: Robin Murphy commit 022620eed3d0bc4bf2027326f599f5ad71c2ea3f upstream. Provide an optimised, assembly implementation of array_index_mask_nospec() for arm64 so that the compiler is not in a position to transform the code in ways which affect its ability to inhibit speculation (e.g. by introducing conditional branches). This is similar to the sequence used by x86, modulo architectural differences in the carry/borrow flags. Reviewed-by: Mark Rutland Signed-off-by: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/barrier.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -40,6 +40,27 @@ #define dma_rmb() dmb(oshld) #define dma_wmb() dmb(oshst) +/* + * Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz + * and 0 otherwise. + */ +#define array_index_mask_nospec array_index_mask_nospec +static inline unsigned long array_index_mask_nospec(unsigned long idx, + unsigned long sz) +{ + unsigned long mask; + + asm volatile( + " cmp %1, %2\n" + " sbc %0, xzr, xzr\n" + : "=r" (mask) + : "r" (idx), "Ir" (sz) + : "cc"); + + csdb(); + return mask; +} + #define __smp_mb() dmb(ish) #define __smp_rmb() dmb(ishld) #define __smp_wmb() dmb(ishst)