Received: by 10.223.185.116 with SMTP id b49csp5474838wrg; Wed, 7 Mar 2018 12:23:43 -0800 (PST) X-Google-Smtp-Source: AG47ELt4HNpzPIeR5zKGWV7C1gIyO93nmUWZ9rs4Cl7rRcprOjre53h/myXV/j7yTzCXtWbwJzFT X-Received: by 10.101.82.195 with SMTP id z3mr19369335pgp.308.1520454223050; Wed, 07 Mar 2018 12:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520454223; cv=none; d=google.com; s=arc-20160816; b=maAYbmyXyr9DzyFblVL9oBn3M1dpvPIPJLCKIJd87FbeHJAWuJOr94Tfrq3id2ddP4 rVN263s3o44MQ+sA4A1tgvqAHr4FF+rWaFZsHM8To7RmLHs86KSrJkqqkwfmbqo7GTDL IWLyEq6ACPeYGA8eVc9WeN8XH4D0YzyPxbw72QGzdwimODqqNPlo+mY2KkdH2HuHSIkp +BKdeGsj5yPDtHYOz7eFBqy/Z8p0VKo9Qu/We+QZH/A6Juo12TwUG7/6eAuhUAWUdujN OUgxM6AsN/9MK4rtckoOraLp+xcZKkV7n7+/QSwchDQqar9aMsiEeq+ST0B37aSxvwZ2 vGFw== 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=GoT6seuGe+/JlCNfrSr94Go/SmkIbfyU9dwCJTBWIfU=; b=lIcYR6nddL0utafSw+RXfjluf9AK1Kt5JjxAwQnHUI7mufjpmhZXWaSd/exm3FCUeW giS6lvw9gj6lGzsPk140cP8ayLU52T3vt9YwrK6s2llhN517cPjCIkyhV4j0d34LoKyT MIcw/50lOwujHY96TOj4PJ5LiONTiKZTJ3ZWdtJ7Cw8CttdwgmDY7USbxWF7vNsKarPD CL4CjjxcULOM1jVSNOcb0msqLq0tXN1CmC8TNxxef0CtTHrtHvXqwihJ80rPOLch6ymr lUPy7K5gaPEEUAyBuaVcfsjlRxiyGicN/DNHMKNj/p4mNgLYH90gW1+dAPcnewcPfFKQ +5pw== 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 g92-v6si13418141plg.629.2018.03.07.12.23.28; Wed, 07 Mar 2018 12:23:43 -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 S964988AbeCGUWi (ORCPT + 99 others); Wed, 7 Mar 2018 15:22:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:43144 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934513AbeCGTne (ORCPT ); Wed, 7 Mar 2018 14:43:34 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C23B8E1E; Wed, 7 Mar 2018 19:43:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Dan Williams , Linus Torvalds , Andy Lutomirski , Arjan van de Ven , Borislav Petkov , Dave Hansen , David Woodhouse , Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner , Will Deacon , linux-arch@vger.kernel.org, Ingo Molnar Subject: [PATCH 4.15 105/122] nospec: Allow index argument to have const-qualified type Date: Wed, 7 Mar 2018 11:38:37 -0800 Message-Id: <20180307191744.666641471@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rasmus Villemoes commit b98c6a160a057d5686a8c54c79cc6c8c94a7d0c8 upstream. The last expression in a statement expression need not be a bare variable, quoting gcc docs The last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct. and we already use that in e.g. the min/max macros which end with a ternary expression. This way, we can allow index to have const-qualified type, which will in some cases avoid the need for introducing a local copy of index of non-const qualified type. That, in turn, can prevent readers not familiar with the internals of array_index_nospec from wondering about the seemingly redundant extra variable, and I think that's worthwhile considering how confusing the whole _nospec business is. The expression _i&_mask has type unsigned long (since that is the type of _mask, and the BUILD_BUG_ONs guarantee that _i will get promoted to that), so in order not to change the type of the whole expression, add a cast back to typeof(_i). Signed-off-by: Rasmus Villemoes Signed-off-by: Dan Williams Acked-by: Linus Torvalds Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: linux-arch@vger.kernel.org Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/151881604837.17395.10812767547837568328.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- include/linux/nospec.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -72,7 +72,6 @@ static inline unsigned long array_index_ BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \ BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \ \ - _i &= _mask; \ - _i; \ + (typeof(_i)) (_i & _mask); \ }) #endif /* _LINUX_NOSPEC_H */