Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2460174imm; Thu, 7 Jun 2018 10:58:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKgpCOg+yL2YW2ZICisqHh0qDo75PCsqGbhGeOo/ohJ/jERWmiqEGZfp0vZHBwhNr4WgONg X-Received: by 2002:a63:7a48:: with SMTP id j8-v6mr2383944pgn.415.1528394302811; Thu, 07 Jun 2018 10:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528394302; cv=none; d=google.com; s=arc-20160816; b=ZM4PqTFkPU7L6mtf5Qo80KOuEYG6ro8zt0c+2DDNUr5WtKXtHI1OLSPpQSH8kV8xlR zALIr5Mkd6pF5C/LpU7N8asbOz/LVfyco2jYlXeFXdhabaSqnLMBGEBQ0SORYS0s2dN2 8+3xM/jZKb1LJ6YbaZMGj5XV1W9IJq4PKSOAU+r+gdzr4xTGeDdCGV/xEoGOVLNRGrIw B/oq3m6HUoEy4sJwb2sjffzz5m3eRofhfDsp9mtfWSJF0bXwfizavesW0CasfaCkqKcB ixyCnOPNFdf4QD8kmwQ79QCIygbZFnt+/npOKhVD+fBKGuS3mJQ1XfbrZevlHCPts3zt bMxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Ex60FfTCJL8QDsE/Nh5H2Q1KubGVPlRISKwMWcj15gM=; b=m+RqRKUvUwB2Mgn0I57kcCiqztYafNaQqMQHe2TETqqNCAJJpXn0QN1Eg43agG99Sm 0KQaCJTStI2k9mkJ/GTfPECbms3sUICxd9uXrnJjU9npRbi3uZh1U26oH+ahTSq2FNlS MNIBbKpO3csTJEKzr75lqAIaGKC1tqwswIfdeL/JqiC86P1K6drN8643C3znv54QcQfJ JWKg1dnaPUskJUb0USpY/gFWzK8PPxTSuHaoLzNqT/vzDfVUSLqsg+5wRkTxdCuYW08s FPfUecJ8U1gi8IYlgQYa3ZsaoANL3o7hh6Ta+q3BYoM7/mF9kRrqFU8KgB3Et6spXpOV e8Mg== 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 34-v6si55098963plz.66.2018.06.07.10.58.08; Thu, 07 Jun 2018 10:58:22 -0700 (PDT) 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 S934949AbeFGOr2 (ORCPT + 99 others); Thu, 7 Jun 2018 10:47:28 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40804 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932741AbeFGOrZ (ORCPT ); Thu, 7 Jun 2018 10:47:25 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvba-0005a0-Ia; Thu, 07 Jun 2018 15:09:34 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb8-00035J-IV; Thu, 07 Jun 2018 15:09:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Dave Hansen" , "Greg Kroah-Hartman" , "Ingo Molnar" , "Rasmus Villemoes" , "Peter Zijlstra" , "Borislav Petkov" , "Andy Lutomirski" , "David Woodhouse" , "Dan Williams" , "Will Deacon" , "Thomas Gleixner" , "Linus Torvalds" , linux-arch@vger.kernel.org, "Josh Poimboeuf" , "Arjan van de Ven" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 258/410] nospec: Allow index argument to have const-qualified type In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 Link: http://lkml.kernel.org/r/151881604837.17395.10812767547837568328.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Ben Hutchings --- include/linux/nospec.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -53,7 +53,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 */