Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1643998pxk; Fri, 18 Sep 2020 19:54:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS42ufwwRzXCQt+mzoIzg4S76ZYs6ahpne0mJGdIXHZYEqcIRwsjp4SYTMUw3Pbf21xav4 X-Received: by 2002:a17:906:b798:: with SMTP id dt24mr1844674ejb.63.1600484095390; Fri, 18 Sep 2020 19:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600484095; cv=none; d=google.com; s=arc-20160816; b=jHJjg0bfHsGL/CDY9uFZbQQAN3qcBT3VVFMVspVPbNkLojDotU0Vo5tTy3/UUTj8fe 5sUoNKcghYm7ID27ZnFv8a8TfgxauYa0z07jxfK/C5zxDQeqDVoICnI0fxj5gEW88ufp 7eX01Sn6oqoOROinwezzujdnCwU2VNHf0xHSbyZGaHSbIeLF2bnJslQF/Dz0EwMcq81r fUKAW7i2bfKj4gw4tD6qC0P5cmxJBL8T63c+8f2jFO2yQ3iNl/RnZCE8SSpha5CLNXh9 Q5lL7Yc/bAA7ZqEhLxC6jCGsENtm+k5bY2cUV2YWu7AZqz+se0jAox8xeSKbernLun6u acfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:sender:dkim-signature; bh=hoAhHDzq/SLuBLbuMh1HEUQHDSft8kw1VcPB/+ozFJE=; b=wIxBuvqD3zvZ190/IQSaSRhpR5JWRrt0WhreykTHcSQJNlNuIs25/yCIP8P4VVn6o/ 9fT/t+wMF0qof2yLGTXXxI4FPAEptOocHrD/Z23klMDXMg1FdP7fCw12BPPyMv94qzpy dXTVZnzswHmNLzzlrDhDHmL0Tt2SKTBtUl+AeTqAnWDLba7+B8QZGN1fPBLnde0DDrDN sVXTafuVAaIeNCfPQPZy/WQp8fB+op07I6shgxWWesRKxKTnUwSxH+A3vTxxsU8WmNm6 NBaKHMnqyS+Jz9/ljfgnUPV5lFV+LglUe1dDLyrH+jNrS/bPx5cj268gI7UuYY4/lanQ 4HbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hy3jke9C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si3646458ejk.29.2020.09.18.19.54.32; Fri, 18 Sep 2020 19:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hy3jke9C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbgISCxk (ORCPT + 99 others); Fri, 18 Sep 2020 22:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbgISCxj (ORCPT ); Fri, 18 Sep 2020 22:53:39 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE202C0613CE for ; Fri, 18 Sep 2020 19:53:39 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id w186so8652522qkd.1 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=r4FHg4XppvPtNdyGNVxNm5foDs9f819RmmUEPlnEdITw5wuVeO5C/hByCgYS1+8qpR 2Ah7GmyeJ3UxB+GofZl0ErLetZvqh1A1LtEfkb+6U4PZvs0BJkf8J9RD39zq9zvmi8QH PrRj/zPzfBSDCWQt50vq33GNf4qOJ+RAbn/XiJkBtvCM8ZSVUvjgYpKitj6dNWIfe6P+ cyz61QibG6b35M6NIBYfgxjO6JxUeZu3hk21t/MtRu9+MC5Arurr9+ucloTVgrvLChaR sIv5WA2Fzt1HLzhy89y4M2KoR6DQId5kwEwfJ8hMCoY0VIdLqi/md564cof+1plxZPLU 7URA== X-Gm-Message-State: AOAM530AnudFIyHWOds6PQeX5G9FuiA941wvQOGyErXnvKRneYmyTaVi JAap3SteB3EO+AijyM2GmkO+Riwjw10= 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) Sender: Arvind Sankar 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.)