Received: by 10.223.185.111 with SMTP id b44csp915938wrg; Fri, 9 Mar 2018 16:47:04 -0800 (PST) X-Google-Smtp-Source: AG47ELs3vdDAX+XgfKm/vtOJnhgoywbPmUF1LOF8Nh0Nj3TiWYqb6QcrDu7o84Xb7FMQRqlik/GF X-Received: by 10.99.179.77 with SMTP id x13mr332318pgt.148.1520642824768; Fri, 09 Mar 2018 16:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642824; cv=none; d=google.com; s=arc-20160816; b=QE97F112D4jpGM++K+epInNRbXPWjl/whzXpbhmlTakZOUTK4jHhXnjOJ+MEpBfrDw 0Bq3yEgDninxXEYlMXJGfsBkyP5pAhxvYiVRFDFpKTOIPM/QybBQCaMqPfvrTtACwgRM OvtQXC8STIMI+GpljEGZtQS1PcV3B5CUv/24VodE06x9jFr2adZib7E5E9POY976KqjA 02U16rFIVKW6k8FIlYpeXLeZC+WdK0gEpaKUHye8Ofn+xviKF8pK8QZ6tN15CEqePWcl c2Q9iIE/grzTfMkjIPZNu8f9ydpPOEBBISbMzTBvz68xbKc+fFeC6Mjc9zs0loAUuLhA JA8A== 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=KNxcT0N7kQ57V8T3rbLNwTAhQYh72xw8Od9Ia5n7f7U=; b=RKcu4nA909oVCExGMg30YbP0us7b0MR4Jiv9XbWz6xLspeJKWzp04rSSSvIeb3tEI+ zRIY19qncjkGl/roJL8g0Cp4dBxVdKm1q7VXm5owbxSFmni8pLnmLpbcKOeegAbxRxU+ nuA34uAGDPkoxkuPX1fjBLLwtQ2patQAPSVKu0MNXsAgLX2HE1hp5VBJZg5v2Bo5svwv WMi/o7Cx75eW1EmNexeyDganQAI6iI3JPdVdN2PCHlke+nmwNuzXO8OmfPfwhzSVshBN j2IHT7vIlHYx2VgvDvaLoxHTRghdmBNrdig5ndDLmrOI3JrTkIvnJ7ikaWouW9e9Erd2 rchg== 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 l6si1510430pgq.562.2018.03.09.16.46.50; Fri, 09 Mar 2018 16:47:04 -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 S933554AbeCJAow (ORCPT + 99 others); Fri, 9 Mar 2018 19:44:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39112 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933401AbeCJAUX (ORCPT ); Fri, 9 Mar 2018 19:20:23 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 788CBFD0; Sat, 10 Mar 2018 00:20:22 +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.4 08/36] nospec: Allow index argument to have const-qualified type Date: Fri, 9 Mar 2018 16:18:24 -0800 Message-Id: <20180310001807.674544545@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001807.213987241@linuxfoundation.org> References: <20180310001807.213987241@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.4-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 @@ -66,7 +66,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 */