Received: by 10.223.176.5 with SMTP id f5csp1554955wra; Sun, 28 Jan 2018 03:38:39 -0800 (PST) X-Google-Smtp-Source: AH8x2242pafFvehE4/zgDdY7ozNIWVp1shRMOCQgpFfsocOKy/InxTcJdOTZVIF0wuC4Yh8ge+2D X-Received: by 10.101.90.202 with SMTP id d10mr19038513pgt.366.1517139519457; Sun, 28 Jan 2018 03:38:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517139519; cv=none; d=google.com; s=arc-20160816; b=PPHroOwTzVFEHOMYLcB4qXBNxvuq8qOOJ1We0Sei7oAcBZuXSGFhTW1TZkP3VgpA3b qkWfNPxtJGZ9xfgsVEs4loB6MZ6K8Eyozz6rfQmPKcL6+Iy4uepWqY6kbbvoqgbeD53O aDLV68RSrLTmWesuuEDh7lySn1MEYSJCckj9Og+UABBJg08nL185cfNUP2Y6lBUIBv09 bC0sF45qrHVxdessakT6Nw9zQWSQ/aDqKq7/2D2blWK9Z1A+uS17J2rE67k6MOgvcmfH WNnOh5m2zNSavCbtE19yWr9uFKUT1Mgk65vgZBfa2bF3+G4A2zXDtr5k7xi3InGA3N6d bmAg== 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 :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=a2ms7YtJfuT/bALbzRG5h96TzWU+K+r4HWueg4tTWIU=; b=qOfoRYgIa9IO2aqCGfvE+M0A5snz/1x6P6KpfGTrY4e2t4LC7niaYnL3RzVUF5uuZq qRSRTNhA0inMSkLMlDVco6gKG2I1BWMtQmBvgCh2Nsfchd5M+2M4XMFL+HezO1FRvfqW cR6RNE3b4+uyGb+vX1fjlJSG82JB/PuzfXpV8Ir8yIrA6aKh9UWRZ5malt/3WbMASBU3 YoaO46gu9bXdAaiwcOHFel7JFT9mSt2pMthPVd5GJOopg2iUjr1A9k/blPMs2haioemR plgLtld3l3Rk9kW+85NRDl+pHXiTIFZx+mMuPSM/YvyGeELKQeHKZhffQqnX3aAoto5w kLug== 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 q90si9628995pfa.91.2018.01.28.03.38.25; Sun, 28 Jan 2018 03:38:39 -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 S1751732AbeA1Lh7 (ORCPT + 99 others); Sun, 28 Jan 2018 06:37:59 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:39811 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751568AbeA1Lh6 (ORCPT ); Sun, 28 Jan 2018 06:37:58 -0500 Received: from p4fea5f09.dip0.t-ipconnect.de ([79.234.95.9] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1eflDX-00052C-4H; Sun, 28 Jan 2018 12:33:47 +0100 Date: Sun, 28 Jan 2018 12:36:33 +0100 (CET) From: Thomas Gleixner To: Ingo Molnar cc: Dan Williams , linux-arch@vger.kernel.org, Cyril Novikov , kernel-hardening@lists.openwall.com, Peter Zijlstra , Catalin Marinas , x86@kernel.org, Will Deacon , Russell King , Ingo Molnar , gregkh@linuxfoundation.org, "H. Peter Anvin" , torvalds@linux-foundation.org, alan@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 02/12] array_idx: sanitize speculative array de-references In-Reply-To: <20180128085500.djlm5rlbhjlpfj4i@gmail.com> Message-ID: References: <151703971300.26578.1185595719337719486.stgit@dwillia2-desk3.amr.corp.intel.com> <151703972396.26578.7326612698912543866.stgit@dwillia2-desk3.amr.corp.intel.com> <20180128085500.djlm5rlbhjlpfj4i@gmail.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 28 Jan 2018, Ingo Molnar wrote: > * Dan Williams wrote: > > + > > +#ifndef __NOSPEC_H__ > > +#define __NOSPEC_H__ _LINUX_NOSPEC_H We have an established practice for those header guards... > > +/* > > + * When idx is out of bounds (idx >= sz), the sign bit will be set. > > + * Extend the sign bit to all bits and invert, giving a result of zero > > + * for an out of bounds idx, or ~0UL if within bounds [0, sz). > > + */ > > +#ifndef array_idx_mask > > +static inline unsigned long array_idx_mask(unsigned long idx, unsigned long sz) > > +{ > > + /* > > + * Warn developers about inappropriate array_idx usage. > > + * > > + * Even if the cpu speculates past the WARN_ONCE branch, the > > s/cpu/CPU > > > + * sign bit of idx is taken into account when generating the > > + * mask. > > + * > > + * This warning is compiled out when the compiler can infer that > > + * idx and sz are less than LONG_MAX. > > Please use 'idx' and 'sz' in quotes, to make sure they stand out more in free > flowing comment text. Also please use '()' to denote functions/methods. > > I.e. something like: > > * Warn developers about inappropriate array_idx() usage. > * > * Even if the CPU speculates past the WARN_ONCE() branch, the > * sign bit of 'idx' is taken into account when generating the > * mask. > * > * This warning is compiled out when the compiler can infer that > * 'idx' and 'sz' are less than LONG_MAX. I rather prefer to have a proper kernel doc instead of the comment above the function and then use @idx and @sz in the code comments. Thanks, tglx