Received: by 10.223.176.5 with SMTP id f5csp308252wra; Tue, 6 Feb 2018 23:04:00 -0800 (PST) X-Google-Smtp-Source: AH8x227DIKKaJzYYRq6Um+H618j/YkN+OkItyrt0yB4dafWYB4fniGg+Zcny9NQqANE0jXLvAInq X-Received: by 10.98.227.8 with SMTP id g8mr3563003pfh.200.1517987039934; Tue, 06 Feb 2018 23:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517987039; cv=none; d=google.com; s=arc-20160816; b=oxrGUJIaLIjTYEUYm5hiCLgTu+uAdpRhoisGPgMcQLoT0xkZYwIZ3sBVcb/APDRHaY jXxUE1YGNJYsxQo+E/aglkLG9twMtp4VsUCdNvIqi5NBfoQ3sXX0s2+roA1YGvZrcQ38 qG6s2V6iwjr461K/ZmQQEYIzDwOJzBU2ZLoGowBKeqAgzkRFhWgTlenUP5zketOfjFIn sl7gUaQQT88U2KMVbS3SXondZ5hKkVztCd2SyugjYBJ9v1EII2h3NyUDHSWDixxoGngu IpShTMZD4OPeKEkalxNkeQYwT+b+Lq4XQFmk5BrcJawwETyQtNrlVh3s+VCCSK5iRdtq m2nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=R+IQhnx0RySWHG6TQPFT98WMKlKA4joluJu5wZiMaLg=; b=dUDJv3D0GrBpRPmbPkUy4wWwZ368m24cmVuVwIDHmBdVGzwHNQCAXRoysJWcUyLejF 0s2e0reEc9Sb59R8wjL0hf+lXunz8aOvG9CvccySWcA5uQ8JSsuaIU9TJuZK3OfudMHH 7yKaeIlpffwzjmtu/YWMz9zil3PWQqGTOP4rMmrSnkAZOgCeFrV6z3g5aeRkGc8PanyF FQPA9GRi1D9lEJf6LvfKV93lz7RSg3/LNkC0DlW9vKwC5OB/1EW9cDZWXQ5kikcI/CjP 5AC7Wc/yk239pwBRQbm2IE3vhaA7GJsMjWSn3XG7D7qRVgZXEtW597dWLsEf+dpjtfdq z5yg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u87si684416pfj.41.2018.02.06.23.03.46; Tue, 06 Feb 2018 23:03:59 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753478AbeBGHAb (ORCPT + 99 others); Wed, 7 Feb 2018 02:00:31 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34620 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753409AbeBGHAX (ORCPT ); Wed, 7 Feb 2018 02:00:23 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w176xIxd095195 for ; Wed, 7 Feb 2018 02:00:22 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fyr2bh7qr-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 07 Feb 2018 02:00:22 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Feb 2018 07:00:20 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Feb 2018 07:00:17 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1770HXs32702570; Wed, 7 Feb 2018 07:00:17 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27FB542056; Wed, 7 Feb 2018 06:53:13 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AF124204B; Wed, 7 Feb 2018 06:53:12 +0000 (GMT) Received: from mschwideX1.emea.ibm.com (unknown [9.145.1.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 7 Feb 2018 06:53:12 +0000 (GMT) From: Martin Schwidefsky To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Heiko Carstens , Christian Borntraeger , Cornelia Huck , David Hildenbrand , Greg Kroah-Hartman , Jon Masters , Marcus Meissner , Jiri Kosina , Dominik Brodowski , Alan Cox , Pavel Machek , David Woodhouse Subject: [PATCH 2/6] s390: add optimized array_index_mask_nospec Date: Wed, 7 Feb 2018 08:00:07 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517986811-27819-1-git-send-email-schwidefsky@de.ibm.com> References: <1517986811-27819-1-git-send-email-schwidefsky@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18020707-0040-0000-0000-0000042D3883 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18020707-0041-0000-0000-000020D0E9D0 Message-Id: <1517986811-27819-3-git-send-email-schwidefsky@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-07_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802070089 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an optimized version of the array_index_mask_nospec function for s390 based on a compare and a subtract with borrow. Signed-off-by: Martin Schwidefsky --- arch/s390/include/asm/barrier.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h index 1043260..f9eddbc 100644 --- a/arch/s390/include/asm/barrier.h +++ b/arch/s390/include/asm/barrier.h @@ -49,6 +49,30 @@ do { \ #define __smp_mb__before_atomic() barrier() #define __smp_mb__after_atomic() barrier() +/** + * array_index_mask_nospec - generate a mask for array_idx() that is + * ~0UL when the bounds check succeeds and 0 otherwise + * @index: array element index + * @size: number of elements in array + */ +#define array_index_mask_nospec array_index_mask_nospec +static inline unsigned long array_index_mask_nospec(unsigned long index, + unsigned long size) +{ + unsigned long mask; + + if (__builtin_constant_p(size) && size > 0) { + asm(" clgr %2,%1\n" + " slbgr %0,%0\n" + :"=d" (mask) : "d" (size-1), "d" (index) :"cc"); + return mask; + } + asm(" clgr %1,%2\n" + " slbgr %0,%0\n" + :"=d" (mask) : "d" (size), "d" (index) :"cc"); + return ~mask; +} + #include #endif /* __ASM_BARRIER_H */ -- 2.7.4