From patchwork Thu Mar 1 12:53:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130184 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2760559edc; Thu, 1 Mar 2018 04:55:46 -0800 (PST) X-Google-Smtp-Source: AG47ELvRjYifAMTSBczhImcKIzgjcGL+jRDvgPkZ8gv68hPW+e9KDcyWu+I89RKhIvIh8eo1XYCM X-Received: by 10.99.110.5 with SMTP id j5mr1458659pgc.65.1519908946004; Thu, 01 Mar 2018 04:55:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519908945; cv=none; d=google.com; s=arc-20160816; b=Tau/PzApld6rgCofLxwv6AEV3EYy6JjKTsMHqqOgWQIGMETL8Pbsl3aNM2dFuQrib6 3co7B8i7Jj+/CdI5wAJAoMdQE2QYlTiM1wQkTijMHDHLWcJUtxRg8D02kAD5ZO+RiTyP tVpRMoeoFM5w0QQxlG0XP8BZaSPsvuQ16iLrKiH/zFHqVq6QEUixPPxymIQt0TW0fBN7 tt3Ybo8EfOPhcjVDy7qN7NIAsZh47cn+KQ9NcTPaa6uk9fgK7Ha/UwUn1FI8mOVH/uDq 6k4tgZgrsxpDrjv2DwGzmn9fURZ6XOfNvSMzAY3L8fGR1LRKH63h46ki6XFwFwuRIlqf 7pKQ== 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 c10si2454231pgf.230.2018.03.01.04.55.45; Thu, 01 Mar 2018 04:55:45 -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 S1030646AbeCAMzm (ORCPT + 28 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(+) -- 2.7.4 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)