Received: by 10.223.185.116 with SMTP id b49csp808184wrg; Fri, 16 Feb 2018 07:31:15 -0800 (PST) X-Google-Smtp-Source: AH8x225Ev3M0myoBWVg7DpV06F5vauQsbH9CVuAmZRXVVHIIzd5ZU7peEdargq9qweBT0TrMNP9+ X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr6246259plr.357.1518795075042; Fri, 16 Feb 2018 07:31:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518795075; cv=none; d=google.com; s=arc-20160816; b=iUfwzGPw+hu38Q18XpZvJtMOYeGqMfjNeIv+LvRuajmmqOjmJtP/YBEzrVQ/+tMuHs Soqw0DhxqdmZjTMmSKtzWtq2u3m0YHp9MtMvFZ2UPuocUPoV4NBfhLdpzkBNx+Tcywaf L1CVZIH1iuc3CKESDg1KFyHGPkJMDY0WA3LJn+U12PoE41USV7tv8hMubjTLPRb9XZ0Q fX3DKEHpFLOuErjcNOuQKSyai2XkfLYGqjcLgWxcTxKy1VVDaSfdchRUx2YZSmtIZ9v1 2Ygz0yvBLxqDuIxtzF7x/xsG+GT02KAJrTp8gy70EZOesmFxOIs3526Xratd+MtfMmAo BfNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=09zs9apo26gfw+1jhcfpVt7suQhOypABdiKC8Vz7Ta4=; b=WFQYSRDKiSyFz18dvqQagrJS/Alo3vLdgB9Fr9Kf7QWTvIc68HW/avxjdNmnsH3Mtd HJe5XB3Gnoni9PkiGPiR2svLLSDvrsXcQyS4qg1vJg3iuAbvKE6TXAH1bLO647l2l0ry xk+ndj7WyoSXvnds7QXnmBUWWSa7T/g9YrIl7v9EWoYWEsvd6Y1CADFkNZb40fzGAiIx BjcM+mPV8DPjTv/gmZzq5RJK8loNuSLqCG1BXBt+pTu+jkn7ODHOly86i8TVlFC5vemo iYfrKShXQjYrJnFEJ3KHL8O3X520+4ezPukxpX2O5LQTS8hRP4EX/T4vF6Ni0toi+YRw D4DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=u9DjIS3u; 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 s23si11632pfm.392.2018.02.16.07.31.00; Fri, 16 Feb 2018 07:31:14 -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; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=u9DjIS3u; 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 S1756072AbeBOV4Z (ORCPT + 99 others); Thu, 15 Feb 2018 16:56:25 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:34364 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752227AbeBOV4X (ORCPT ); Thu, 15 Feb 2018 16:56:23 -0500 Received: by mail-oi0-f65.google.com with SMTP id y16so968479oie.1 for ; Thu, 15 Feb 2018 13:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=09zs9apo26gfw+1jhcfpVt7suQhOypABdiKC8Vz7Ta4=; b=u9DjIS3uRPf324FVb+sHBJ7zUSiyKGRF/Fp+iLb5nEAAaOhRqZHGaA1WENV0Y4s5L2 +O1gFWXP/mwz1WGmVZCw6v7BVgq7LTUQCZHX155rSlspLmD/ZuzSF43qtL8RkYcV3tFN aN7pxOND+vFPYhxbFyNH0ITnerEXOONfTg7vElQI8qp/XScfK/l6az7W6//advemOkiO YNtHTrkwMbRNTAnlnSLJqDZ70iRxV9p3hybsBZHkSI1jU+2JaboPU7rxXwb2gS+sVRss 90UnoX5J+6XDV1kDMP0JZmZj6xFP1KU7H5ukTx06nvEkBVZuXMx2shM/A+dDtgwM+sxf e7Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=09zs9apo26gfw+1jhcfpVt7suQhOypABdiKC8Vz7Ta4=; b=ZLW5sduOIa7uTl6EaPELgbqtxtAx4H0z388YF04crEs49/a/kQiQ2ForyF736uR60f WCH+pOJaeoQ4zzcKzWXb7dJZOtKZh8LXpPqItSQI6SNlWQkEeHm2jKEE0UZqw3z7iHCM ewlOznGadP7W+YCUKHK93FYK8JwrBwLvQxNg/xReu7bAc9mM7f6ghNOnBQulGQxrr6bc 4nwzAx7OEGJgDCibWET7vl9txW6pzgbMlshZX03tCp+VHPvhIQPT6pOl5kA3ab+sWT38 UOgkuzd2BfleRNlf8RdtSzgp1aKCByprZg4uk9q7CfO3CL+vLB/Eaj8kPBz70qPy6AgY 62fA== X-Gm-Message-State: APf1xPBylChJBmeRrj4J9MKocm7y36eDN810F1QhU/UEhJKGTdjIA2pd ausSIcWM1IU1UpGEV/iV9sb2+AzyrBYhQosvsIZmnQ== X-Received: by 10.202.78.5 with SMTP id c5mr2784680oib.314.1518731782516; Thu, 15 Feb 2018 13:56:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.17.229 with HTTP; Thu, 15 Feb 2018 13:56:22 -0800 (PST) In-Reply-To: References: <20180215195209.15299-1-linux@rasmusvillemoes.dk> From: Dan Williams Date: Thu, 15 Feb 2018 13:56:22 -0800 Message-ID: Subject: Re: [PATCH] linux/nospec.h: allow index argument to have const-qualified type To: Linus Torvalds Cc: Rasmus Villemoes , Thomas Gleixner , Will Deacon , Ingo Molnar , stable , Linux Kernel Mailing List 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 On Thu, Feb 15, 2018 at 12:59 PM, Linus Torvalds wrote: > On Thu, Feb 15, 2018 at 11:52 AM, Rasmus Villemoes > wrote: >> >> 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. > > Ack. > > That said, looking at this header file, I find a couple of of other issues.. > > (a) we should just remove the array_index_mask_nospec_check() thing. > > (b) once fixed, there's no reason for that extra "_s" variable in > array_index_nospec() > > That (a) thing causes horrible code generation, and is pointless and wrong. > > The "wrong" part is because it wants about "index" being larger than > LONG_MAX, and that's really stupid and wrong, because by *definition* > we don't trust index and it came from user space. The whole point was > that array_index_nospec() would limit those things! > > Yes, it's true that the compiler may optimize that warning away if the > type of 'index' is such that it cannot happen, but that doesn't make > the warning any more valid. > > It is only the sign of *size* that can matter and be an issue. > HOWEVER, even then it's wrong, because if "size" is of a signed type, > the check in WARN_ONCE is pure garbage. > > To make matters worse, that warning means that > array_index_mask_nospec_check() currently uses it's arguments twice. > It so happens that the only current use of that macro is ok with that, > because it's being extra careful, but it's *WRONG*. Macros that look > like functions should not use arguments twice. Yes, that piece is new and I should have noticed that breakage when I reviewed that patch from Will. > > So (a) is just wrong right now. It's better to just remove it. > > A valid warning *might* be > > WARN_ONCE((long)(size) < 0, "array_index_mask only works for sizes > that fit in a positive long"); > > but honestly, it's just not worth the code generation pain. So I don't mind removing it, but I don't think it is garbage. It's there purely as a notification to the odd kernel developer that wants to pass "insane" index values, It compiles away in most cases because all current users are sane and have indexes that are right sized. It also used to be the case that it was only used when the arch did not provide a custom array_index_mask_nospec(), but now that it is "on all the time" I do think it is in the way.