Received: by 10.223.185.111 with SMTP id b44csp912904wrg; Fri, 9 Mar 2018 16:41:51 -0800 (PST) X-Google-Smtp-Source: AG47ELsEu9Yvk4Tkhov5Ce3EmjD2qj7oqV3LtxA31Q9qryLkX2ugHn35s3GsOu8rvLY0rXhDqTYg X-Received: by 2002:a17:902:6582:: with SMTP id c2-v6mr353801plk.189.1520642511431; Fri, 09 Mar 2018 16:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642511; cv=none; d=google.com; s=arc-20160816; b=joUgzcm0ZxosW5G0/d+dp/yBAfFZUqyiVe9gRpw7yQRCXkFaClC9GEojZ5XO9UR87o nmgG96iHiXD6nvqCKQjqA+RHcZXBR7poVwcOuMd8GkZa2rpKyfzoBmZaFHFZohhXASAg UNem1lmkzEH8VtnQxYH58Fq60cBR8wIMTFdRjQZIUe6qD15dQFfD3ZSq0giM65Wsh+wx o0aTwNB0VTojjPc8++ZdKYoy5CEF7swdJ5ZM14w7XU8Y89cNGCBuCIwKrwB+MPEoEY7I bNJk/LA6U62FX72xHQtg51PfElIWH87vsWU7mDjyb/iwgJx6KAjTrCViE4LC8K6vhmvL LWYw== 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=1A/lOhMvey1fJ5qrShpLfcRb0I/Zwtd+6yvYDIlrxEE=; b=P+wxh3ai1x1yheyyZfwNl6T75fKLHPy+VMCXx1Z+II2rPOBIFc9PZPFrpwAHD8R3bN avN6ySynAtexC6jO/OeCBMp7NU4e9+VgeqHjNKhcpz45j4F9hzVeL02Cuw0idIBcshHv RXmNXpDjv+HYZFtqc2T2BuWbBYdV09NgKfxF4DnTfIJu9rZdckYTHHv1MXNMRQsvRLD0 PfO/oEQ3B0Tj+CvM3o+UNl2Ze9rfJVapzj7TY0CU8DCb5U6hDN9AEEyMjPGTQgBehVnX dUQQ63mssHTTOXPaYkPKzQI1glEcq5BlIxF23BPIfzzYyBOtZ2JnuVyntQpW76FAVzUk XElg== 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 33-v6si1785935plf.98.2018.03.09.16.41.37; Fri, 09 Mar 2018 16:41:51 -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 S933485AbeCJAk3 (ORCPT + 99 others); Fri, 9 Mar 2018 19:40:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39470 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933636AbeCJAVQ (ORCPT ); Fri, 9 Mar 2018 19:21:16 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 630A510EF; Sat, 10 Mar 2018 00:21:15 +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.9 18/65] nospec: Allow index argument to have const-qualified type Date: Fri, 9 Mar 2018 16:18:18 -0800 Message-Id: <20180310001826.416622744@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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.9-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 */