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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 841D1C43464 for ; Sat, 19 Sep 2020 02:53:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 19726208DB for ; Sat, 19 Sep 2020 02:53:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hy3jke9C" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19726208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=alum.mit.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6619D6B005A; Fri, 18 Sep 2020 22:53:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E9756B005C; Fri, 18 Sep 2020 22:53:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1FD6B005D; Fri, 18 Sep 2020 22:53:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 3228D6B005A for ; Fri, 18 Sep 2020 22:53:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F1E3D8249980 for ; Sat, 19 Sep 2020 02:53:39 +0000 (UTC) X-FDA: 77278290558.25.class39_46074c127130 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id CE2E71804E3A0 for ; Sat, 19 Sep 2020 02:53:39 +0000 (UTC) X-HE-Tag: class39_46074c127130 X-Filterd-Recvd-Size: 5514 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Sat, 19 Sep 2020 02:53:39 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id n133so8589533qkn.11 for ; Fri, 18 Sep 2020 19:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hoAhHDzq/SLuBLbuMh1HEUQHDSft8kw1VcPB/+ozFJE=; b=Hy3jke9Cj4flJUNpP5g32NhzM37SteMA15yYutV3tfppHSWK0wnNR7043F8xxSygR6 z+gIrFr8lobp5D/etEgBm65+SOvNCafbrQwK0KDQuU4K9VTWXHqXyZfvTWb/jOAPnKKk G528pi1cx1c5lEJUDgiRWZIMY4ehSVIaehluZrvWgFlWVIYuosKljf13mo9n58IWbFx5 C1lfsq1W1/pQbrf/E0eJ+p9DHd4wsg7Y7OQ+7r99ySNYlNyolPj24LFG2dg0UlEACtR9 mnu9KEjmyrA2bLDWja6Eli3Sm379SP8FlxYjJJm0v4xRrUhXUHk0NeZK9iFzp+la7c2J /aRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=hoAhHDzq/SLuBLbuMh1HEUQHDSft8kw1VcPB/+ozFJE=; b=fF4DD5SRom1aVwNUzsRxQygDQlp+DcLIPZh/o9A14s0BiAv3vShbUssj7QDQEPB4Yh /S6V0yTD7ekSsu9A0dMPSnsO2ilhsWjx1BOMQDdW0VofBbEOMdS1qP8cg6r+xXJYXr9c cVMdBSunxpq3Fcr1A7hYM0n/oGEfQFyC2NnDDV/tDNcoOXgVQ3L5niW7o0LVWOfWiI54 rqHwhiYpsFwFcwI7vJz+QxVAl7wM9duGrQaQk7dvJ0rWumm61u4AAcHby3rm0CNMwP6v EdiqIThihIc+9XxhqEp/DdEPM1XLnbpBrZGLEdxO224rUos5TLP3Ar7wq6nzG2/NnHiN BFKA== X-Gm-Message-State: AOAM5311aGaOETGb1UMRAQACr8lf2CO6i9B89EzXG51ud8EWvEjR54rS y2P+JrFK4BMWakZ8Jc7d3Uo= X-Google-Smtp-Source: ABdhPJxydkfObOrADPvitjEWYXj5F5HEhxQpJN2UI9lCoKyZ9nnnXbTFR9809E7NoDs5U79Hxk0e0w== X-Received: by 2002:ae9:e601:: with SMTP id z1mr34011034qkf.1.1600484018738; Fri, 18 Sep 2020 19:53:38 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id l5sm3643806qtc.28.2020.09.18.19.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 19:53:38 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 18 Sep 2020 22:53:36 -0400 To: Linus Torvalds Cc: Arvind Sankar , Matthew Wilcox , "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: <20200919025336.GA3008405@rani.riverdale.lan> 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=utf-8 Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Sep 18, 2020 at 06:28:30PM -0700, Linus Torvalds wrote: > On Fri, Sep 18, 2020 at 3:40 PM Arvind Sankar wrote: > > > > Ouch, offsetof() and sizeof() will give different results in the > > presence of alignment padding. > > Indeed. But from an allocation standpoint, the offsetof()+size is I > think the correct size. The padding at the end makes very little sense > for something like "struct_size()". I just meant that my suggestion doesn't actually work to assert that you passed in the flexible array member to struct_size(), even outside of any future warnings on sizeof(). And that it's another source of subtle bugs, although you'll err towards over-allocating memory rather than under-allocating by using sizeof(). Is it ever necessary to allocate _at least_ sizeof() even if offsetof()+size is smaller? > > Padding at the end is required for sizeof() for a very simple reason: > arrays. The "sizeof()" needs to be aligned to the alignment of the > entry, because if it isn't, then the standard C array traversal > doesn't work. > > But you cannot sanely have arrays of these structures of variable size > entries either - even if standard C cheerfully allows you to declare > them (again: it will not behave like a variable sized array, it will > behave like a zero-sized one). I think you can't do this in standard C. It's a GCC extension. A structure containing a flexible array member, or a union containing such a structure (possibly recursively), may not be a member of a structure or an element of an array. (However, these uses are permitted by GCC as extensions.)