Received: by 10.223.185.116 with SMTP id b49csp387639wrg; Fri, 16 Feb 2018 00:16:17 -0800 (PST) X-Google-Smtp-Source: AH8x226m3qVvZfFUWdGfBUzJuqOyxVvAu8fsf1B/YOoxXjaCYK/3y6ew6Knzq2bwy+frs2JiUxDu X-Received: by 2002:a17:902:b28b:: with SMTP id u11-v6mr5114925plr.146.1518768977140; Fri, 16 Feb 2018 00:16:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518768977; cv=none; d=google.com; s=arc-20160816; b=qjLvvPYRFkpiEAhh2CXJIriTZ9ini/Aq8YU/23ZHQmJb4WFix8IqgsKbSueUaJDCll oqaH2QWx8S3sQhWru8Em9gmZV75/iKh3Qazq4+MixX+chlBQOxgiQde6bAk9zctBOC7p B7cdzY7/oxX+7jz5ZwmipX2KK97E6Ypr2KpYcmpoEpALvTGD8Sf20k7l1ruprNy6xiz4 v8Q1gqfcHoHbZbMsCnD61Zn2pUoNQnqh/w/LmK0sU+bcuDl9y8QNNTLXKCJwWaAPhXk3 3s0QSeqyUIeO7sKrJts65qIc6y4hOc4ebTip874kIpDv0OJRuzD7XDsHioX3BomTXao2 QGQQ== 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=gsXLJhbDk6T0h4U20cW0wXUv48IuG4nRd5bRXL2GEtg=; b=dVIL0tfJAkXOxgVlAvvEB6SFtD3cU1pGy8HlBVknr335ebdeEaA/cPAac6NKDq3bFd OYRzW63Cf49Tpe3c2W8x/d2YMIF8y9Eg22+HlSF5iOGC7oDmjtJqSoT8nhhqFQoh4RyG XQZi/N1HPEsxUPkJ1RmhvR1K3lF63fXtH9IaIUDt937wxoTguy1RsQ+nfpaex95yTXKK UMAnd/I5YVU9xvK6TRaJ5IYz/FmJRMwbeXsN6S22P3jXgvC8FFGAeFH/RxHs93MwWidK 3N9o8ZnZkXh9sXpQ8d2CCCT4l5ZjTaQsu5GOFFbnBTK0FqAmdsr5g9POkTokwv2h3p2h F+xg== 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 b10si4092230pgf.613.2018.02.16.00.16.02; Fri, 16 Feb 2018 00:16:17 -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; 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 S1425936AbeBOQ3z (ORCPT + 99 others); Thu, 15 Feb 2018 11:29:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:33296 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424171AbeBOPm2 (ORCPT ); Thu, 15 Feb 2018 10:42:28 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D67B21000; Thu, 15 Feb 2018 15:42:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Robin Murphy , Will Deacon , Catalin Marinas Subject: [PATCH 4.15 050/202] [Variant 1/Spectre-v1] arm64: Implement array_index_mask_nospec() Date: Thu, 15 Feb 2018 16:15:50 +0100 Message-Id: <20180215151715.832275307@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ 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: 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 @@ -41,6 +41,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)