From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C99B7C43463 for ; Sat, 19 Sep 2020 02:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87C37208DB for ; Sat, 19 Sep 2020 02:46:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="gtXloL/e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726285AbgISCqJ (ORCPT ); Fri, 18 Sep 2020 22:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbgISCqG (ORCPT ); Fri, 18 Sep 2020 22:46:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC657C0613CE for ; Fri, 18 Sep 2020 19:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IqGNJCHkPeeEzn4NZlU91gM1WIifD6Ne5eGwToLNy+M=; b=gtXloL/e0Kvaq/QDn0ut5wgWxH pUgd7WNS1TYv4EPwksDQv4wRtU/ABSj2FZZKs3Ro769lszzyWDli9JsID75OJPO93KeciullZhnK9 oiYR7LwIJR1bAD+k7f8wF8BTYmz/GdCY9F/CvF5/FfNisiw/JcmtY+L6eMtWXFXfEm4u9OSavDvUH M0xkGhOfp/k0PUY3MzhqO3TwQ1fnJWbLnFAJ6+8Ij6CsZmFgzHzOuhdaI3X8x0S7g8ttdZC9jKkGU VHzhWzDHHXe6Io4gI1xZ1SreCnXrLA3Oi/TYk2qZHnVfAiiNCqbNsGpEZgMn51tr2IcPw23yhxIMk xYJ/ZgGw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJSsu-0000w8-Ip; Sat, 19 Sep 2020 02:45:56 +0000 Date: Sat, 19 Sep 2020 03:45:56 +0100 From: Matthew Wilcox To: Arvind Sankar Cc: Linus Torvalds , "Gustavo A. R. Silva" , Dennis Zhou , Tejun Heo , Christoph Lameter , Linux-MM , Linux Kernel Mailing List , Kees Cook Subject: Re: [GIT PULL] percpu fix for v5.9-rc6 Message-ID: <20200919024556.GJ32101@casper.infradead.org> References: <20200918193426.GA15213@embeddedor> <20200918200252.GH32101@casper.infradead.org> <20200918202909.GA2946008@rani.riverdale.lan> <20200918210050.GA2953017@rani.riverdale.lan> <20200918223957.GA2964553@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200918223957.GA2964553@rani.riverdale.lan> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2020 at 06:39:57PM -0400, Arvind Sankar wrote: > On Fri, Sep 18, 2020 at 02:18:20PM -0700, Linus Torvalds wrote: > > On Fri, Sep 18, 2020 at 2:00 PM Arvind Sankar wrote: > > > > > > You could just assert that offsetof(typeof(s),flex) == sizeof(s), no? > > > > No, because the whole point is that I want that "sizeof(s)" to *WARN*. > > Ouch, offsetof() and sizeof() will give different results in the > presence of alignment padding. > > https://godbolt.org/z/rqnxTK We really should be using offsetof() then. It's harmless because we're currently overallocating, not underallocating. The test case I did was: struct s { int count; char *p[]; }; struct_size(&s, p, 5); (48 bytes) struct_size2(&s, p, 5); (also 48 bytes) struct_size2 uses offsetof instead of sizeof. Your case is different because the chars fit in the padding at the end of the struct.