Received: by 10.223.185.116 with SMTP id b49csp5445896wrg; Wed, 7 Mar 2018 11:54:27 -0800 (PST) X-Google-Smtp-Source: AG47ELtaIWQk9SFe3TD03FUkhjydMw7Sfisto8bVyFFhiwXQNEUEG2bFK3a1AIZLeyBSnCoyvywk X-Received: by 10.101.92.196 with SMTP id b4mr18644508pgt.27.1520452467857; Wed, 07 Mar 2018 11:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520452467; cv=none; d=google.com; s=arc-20160816; b=snauu5LWp6bjHd4BhZUbpnlJL57U4bk2PaP+6B4bEwgZF6L8Ut5XmCYJu3V3X0napu rdCfXozY4M7NTmAKRmQjnLz627tEc2RM5Z9Q16y2nDMC5u9VVs8oW4HhkLTyLGfjY+Yx qhB6ok7/FJEQnXZLmadWlZ9S8jBJGXj7AWkPUQARmL2wS5nBDpwC+IEhEIUfxVAMqQvq Yh5S2J3m/+Xr+zedh9AZHjjkwitngKDWUzJoalOfEaBtjxu2YJTGtOpV+twnED/Kj8bd AHcBxHVMru2b6eLCasaO4G8d4Kn6klNQGYd6S3NARppBv8SaTxUda7//9lGbbUVPrA0F 3ceA== 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=q9MVxcgB+1RozX1B7p9q2rIc1jTDfYiGx3bVbxbE3qU=; b=pdPZ8bVvo2mVtbASC2fcrSPRYQokFmIl/L8wQMgVFP+dlep0K85fOZYXNTKQW6Joxw os/rNpFWpjaktx/nuxFyNpEG2TuK0i59faQG99d2xlgCPS1fzWAEGfgMkxtsv4J05n7e vYd3QRm0BCC0pMEoVn861jn8u81mBfxj0tq/AYbAAViSkHF36Pnq25r2A8eZOOVtmiQw d2Ox7M+ywaOAVa1F5VCut2ZqWqpnV0WYA+y3xc3rG9+91RqSH9MQ2CNdNhEMsTCaFOqD dKJYzqwAPiZI4HWcVhlC52y60OGTQUqDg5jB8Ceyk7js3g04jJ71HUQoUiJMGNtGRfGf gn7A== 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 e5-v6si13378910plb.566.2018.03.07.11.54.13; Wed, 07 Mar 2018 11:54:27 -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 S965910AbeCGTwY (ORCPT + 99 others); Wed, 7 Mar 2018 14:52:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45168 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965821AbeCGTrv (ORCPT ); Wed, 7 Mar 2018 14:47:51 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 316DE110C; Wed, 7 Mar 2018 19:47:50 +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.14 090/110] nospec: Allow index argument to have const-qualified type Date: Wed, 7 Mar 2018 11:39:13 -0800 Message-Id: <20180307191051.371755939@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@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.14-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 */