Received: by 10.223.185.116 with SMTP id b49csp7392070wrg; Thu, 1 Mar 2018 04:57:56 -0800 (PST) X-Google-Smtp-Source: AG47ELuDNTgu2I1Pz8N+XASd84Sd9jEsZJZ7B4FVYO1z7PmDpetiTVtg2L6IShVIkRTLyoR+vG6r X-Received: by 2002:a17:902:367:: with SMTP id 94-v6mr1897435pld.140.1519909075914; Thu, 01 Mar 2018 04:57:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909075; cv=none; d=google.com; s=arc-20160816; b=e52y/BwQgdjRM4nrOfHkBey2YDtckjGO1w4X7HotP0C6oiS6QKVVvVqP7uYQezthWS gXdVxi0DgdhARJWI3G2YuAZvJudhSp3DesO9fzrbu6XVg3Zs6RkwzgYKUIArlf/4I2bt 1D4y2WivGjPoICQEauLjEyaxS80LxVOvoVTuCSHpE6Kyom7fWw7WoloyaDPz6uoUiAoP dd3Am158s5aYWGDsOFgTxkrHERChH9aTBtMPx8R+1beuo3BtgR/6+VQl15+9OWuzcf+r 1zguNRJX2DsZPZaVU3sbO6xkqWRRhzOTwfb9pHNcniMACxhMqPAk5gT0M/9dkFqfmBn8 zKeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1urEszs1X1+fSgF2FtrvQb+AjsP1I5AehCNh9xZoYO0=; b=gMrfI1KWenz4ZjTyuwQQ91lYn40yaAJcRC0Hu1UQy+3cPrLmm/LECkiyPi539B9leo JLPJ98F0kUPk96KT3dPEPGqLKZfkFgoXG/H3m9MgQl1BHFLbmhdQoeHkD7DuvCL8tMhU Q3utfT9+tTwCicYlSyHUglh9IrkT7IxZgfY28h+8EviUAJjHO/9e2Jys4N6Q4RY7DqvS XPgnK8c/37R7uxF8PakOjsAV+qpeq6NGV1XFiPGKHt0jLAiT/X1ut6YrYyaurrOf+H79 nVR3OQjb/NJ0BmMpn7Fs8dx51QcZsz6AICPj69gIZyUbMpvHpYeibjxT6wFUDZKqBR1y sirQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vm6pcX2U; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l18si2437515pgn.339.2018.03.01.04.57.41; Thu, 01 Mar 2018 04:57:55 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=Vm6pcX2U; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030643AbeCAMzm (ORCPT + 99 others); Thu, 1 Mar 2018 07:55:42 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:32883 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030629AbeCAMzj (ORCPT ); Thu, 1 Mar 2018 07:55:39 -0500 Received: by mail-pl0-f65.google.com with SMTP id c11-v6so3602536plo.0 for ; Thu, 01 Mar 2018 04:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1urEszs1X1+fSgF2FtrvQb+AjsP1I5AehCNh9xZoYO0=; b=Vm6pcX2UzAbaWdmyVa0rPvXZyO2E8/n8CFR09KxGgLr7DE84EkFSOc58SyN7MgSzHs R140O1gA1/VhJMJRrfpYoHFqDGmBjG0KNF0Pz/9niTXSBo1iMAboRvBbN0DACyGbIVAP DuTd7fju1g+IeY/LScim2LVwWOpyXitzWnwIs= 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; bh=1urEszs1X1+fSgF2FtrvQb+AjsP1I5AehCNh9xZoYO0=; b=qzpoumiRtOtnJbFW8BfKHIz1EtNb/9Kkil/VwF7PicBWphvTGi0F1WLSjAPfAsl1l7 BKWUqHc/tWtxrK383f7RMpuCTFzfLA12BUR6rvd3j87TG6QCAKHphMEWGNRWtBX2yN6u em49STmEIuFZm315cTIbhufkAHKqRWUTPUn0Vd8NX8zwrX0vN2saGhSq6/ciChMrEvLH zL/NAYGGTJIdCmUhAbZJuxsWtJoOCWHm78BIsqBhnjPyAnE4el9/llVrUlZB6dh6JRvb TnUGZMlKFgRkwP3xR0kHzpqNB4GgduGSbIpAHkj0JidZON3J6wl6oG2Nut1VlThzhHEh RO6w== X-Gm-Message-State: APf1xPCmrZmKM5tEkHKeTCwnB9nITsT1cHi6JmL5FTrFgMknzb9ZzuOO 7sbxjSVPDZonVpKYhOZcTejqSA== X-Received: by 2002:a17:902:b605:: with SMTP id b5-v6mr1871768pls.354.1519908939113; Thu, 01 Mar 2018 04:55:39 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:55:38 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Robin Murphy , Alex Shi Subject: [PATCH 04/45] arm64: Implement array_index_mask_nospec() Date: Thu, 1 Mar 2018 20:53:41 +0800 Message-Id: <1519908862-11425-5-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy commit 022620eed3d0 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: Alex Shi --- arch/arm64/include/asm/barrier.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h index c68fdc5..0b0755c 100644 --- 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) -- 2.7.4