Received: by 10.213.65.68 with SMTP id h4csp2127153imn; Thu, 5 Apr 2018 09:23:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx48CSixFOUy+FVKxv6mPOk4TIwy9QL+q8iYxS5F/+5HZz8gGi/15raDFob/3cEFZwTbyEPtc X-Received: by 2002:a17:902:9894:: with SMTP id s20-v6mr15753897plp.196.1522945439128; Thu, 05 Apr 2018 09:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522945439; cv=none; d=google.com; s=arc-20160816; b=kIxCkcUS58lXv/jfQayOb8zIqfR0sZMw5yN9yzFrqpxl5cEjyr0E1LBeqs98IPcgJx Wj7IHR9c5TTkoOGshmRHhlpRH9CBP8oEVlh/oqKjuLC+W1YMw5GRFHpmqR4A0gXtnTMs zxB1C4337XrujFOUJNFSJxUYe5ViXl68LGt/N+uhzJdWWqra+E8zg+QJRq7S5y9LFW9X RRKAuJ0x7JVgpB/uI65QDhjkwg71P2WfJ9ev37mDm3UT8TzgNGJaHeCL9QpoOlE9B8Y7 CqS04+1Sb8jJLBNdaH12GoKWqSfpEIT8PT8eentJRsmqw3ptQpxvxCBtR58r8Om7Te1W i32Q== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=bG6Fl7L2Nj740fGdj9QGouBHPaU1lS+dB+s8dYcvo9A=; b=qgcrQebjvN6ysewjgSvrj3oiZiHaazgMB5Ib+vEkxkSQUF6oxq/ZAIumXWPXTnDPs0 3u2KTyC5zCMX7kFGWAHQdCE8kWZgIx2fUtM7CCDDr6TON50zcwTIuDwVdZRi8WyK57H2 rAGl+zRphT6munwmo2Xu3RU7VFNIrlqMp+vtPk9orfgs8BzZNyt3QFdJoN8QWRWt5TKc fWEOkFg+laRqT+XZfBgeV+j3sKOfBgd8wsuy3S7PazUWgS/QagIHgLA6MBIfT24cufsS WK+JQ7+MvrwVzRdXWcQWQGczwcTUUeaMgB5GQ8/gT6zgOHXoSqjXvZJHK1tkcQkSZ61j gWTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PZwO2/cI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si1190460pfl.151.2018.04.05.09.23.45; Thu, 05 Apr 2018 09:23:59 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=PZwO2/cI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbeDEQVh (ORCPT + 99 others); Thu, 5 Apr 2018 12:21:37 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:45217 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751312AbeDEQVe (ORCPT ); Thu, 5 Apr 2018 12:21:34 -0400 Received: by mail-vk0-f65.google.com with SMTP id n64so11643916vkf.12 for ; Thu, 05 Apr 2018 09:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bG6Fl7L2Nj740fGdj9QGouBHPaU1lS+dB+s8dYcvo9A=; b=PZwO2/cIULGSFfek7mDhzRMiydpRQLKP1XQ/Vkei8aQYIrsQT3IcV36nD6RU/NiSzE C9aOCJD+v85eb945sDLwY1h+1NUtlFjbfChnzC+URS34/0pBnN0zbGW9eDxr1Ohq6ylF rZ55sf1nhT/+iFepvKXwPbirCzy8yTQGTyY/22/enbbNun4/2mSqQfE1Y2lC0c3mHUSH ETiDi/tglddqdKGoqBu53GVqXLowAHPn+U3pTSWU07D9586yknCJAjWGLnvB9kakSVc6 1mLq8NwtjRW560PkyOijrutN+a/yKrGkgXL+1WvA0tYavzAuoHL4YrCGiPDKw2BHehE0 7m5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bG6Fl7L2Nj740fGdj9QGouBHPaU1lS+dB+s8dYcvo9A=; b=Okj0gqECxJNEylzxo7qJ4Y5UAPwExrC7/VTBnTx+HQjrwGB4N6SdKdaa45JJPYhgAH WATzmq4ZTGatEXF9q1OUhuio7S29k0SOdtZeRumvkzhpAmijJhyIlKi6D3I+gBs+P6ZG 5aJo6JYVHBZF3bNVGRsm/LO8wuiPpUgpAEr2I1Ne0uG3qXIzaFkFBNXSdsTWl5B/tbvE /DO/+33ejl1c3zALNXrX4CGclJFVoWe8Q1is2x30Lv/8EI+iAGMvx9mUebJA4d9aOYCq 3O94XNsCX1Dg3fh8U4Muenjwq8Xb1YBM8Qf0JVrDwRl3jFzlCUqufrkV5jfSOXsmWXEr CDwg== X-Gm-Message-State: ALQs6tC4aUSSKbEvKTvGPBSAqNQB/yAbF10PE4QOBM53uCSi/dtn+L4g 0k4AdxktZLomlqvYwNUOSGqnGb5nB5DyD33ikyBFTA== X-Received: by 10.31.79.132 with SMTP id d126mr12871258vkb.174.1522945293677; Thu, 05 Apr 2018 09:21:33 -0700 (PDT) MIME-Version: 1.0 References: <20180403085904.GY4082@hirez.programming.kicks-ass.net> <20180403095118.rpf7tj577dppvx7d@gmail.com> <20180403180658.GE87376@google.com> <20180404093823.GC25996@kroah.com> <20180404165914.GA9034@kroah.com> <20180405070810.GM4043@hirez.programming.kicks-ass.net> In-Reply-To: <20180405070810.GM4043@hirez.programming.kicks-ass.net> From: James Y Knight Date: Thu, 05 Apr 2018 16:21:23 +0000 Message-ID: Subject: Re: [GIT PULL] x86/build changes for v4.17 To: Peter Zijlstra Cc: Linus Torvalds , gregkh@linuxfoundation.org, Nick Desaulniers , mka@chromium.org, Ingo Molnar , Linux Kernel Mailing List , tglx@linutronix.de, Andrew Morton , Chandler Carruth , Stephen Hines , Kees Cook , groeck@chromium.org, Greg Hackmann 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, Apr 5, 2018 at 3:08 AM Peter Zijlstra wrote: > On Wed, Apr 04, 2018 at 10:21:05PM +0000, James Y Knight wrote: > > But allowing random pointer arithmetic, and pointer arithmetic wraparound, > > is still different than asserting that an object _field access_ can > > overflow. Clang does not believe that can happen -- it assumes that an > > object will still be contiguous. And that's why the llist stuff used to be > > broken, before it was corrected to do simply do math on a uintptr_t (which > > is a nice and simple and sane fix!). > That 'fix' wasn't anything simple, I recently ran into that > member_address_is_nonnull() trainwreck and had to think real hard wtf it > was about. I agree the comment there could be clearer. You could replace it with something like this (apologies: this patch is likely going to be mangled by gmail's plaintext mode hard-wrapping it.) diff --git a/include/linux/llist.h b/include/linux/llist.h index 85abc2915e8d..04e972a0bbe8 100644 --- a/include/linux/llist.h +++ b/include/linux/llist.h @@ -99,12 +99,15 @@ static inline void init_llist_head(struct llist_head *list) * * This macro is conceptually the same as * &ptr->member != NULL - * but it works around the fact that compilers can decide that taking a member - * address is never a NULL pointer. - * - * Real objects that start at a high address and have a member at NULL are - * unlikely to exist, but such pointers may be returned e.g. by the - * container_of() macro. + * except that it uses addition on a uintptr_t instead of member + * access syntax. This avoids running into a compiler assumption that + * objects must be contiguous in memory, and therefore that member + * address lookup cannot wrap, and therefore that a field with a + * positive offset within an object can never be at address 0. + * + * Real objects which start at a high address and have a member at + * NULL do not exist, but such a pointer is the result of applying + * container_of() to NULL, which llist_for_each_entry does. */ #define member_address_is_nonnull(ptr, member) \ ((uintptr_t)(ptr) + offsetof(typeof(*(ptr)), member) != 0)